Skip to content

Commit 06a69a4

Browse files
authored
Merge pull request #3755 from ColoredCow/feature/create-project-on-prospect-conversion
Project Setup after Prospect conversion
2 parents 5b3c207 + c2783cc commit 06a69a4

File tree

11 files changed

+145
-140
lines changed

11 files changed

+145
-140
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Modules\Project\Emails;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Mail\Mailable;
7+
use Illuminate\Queue\SerializesModels;
8+
9+
class EffortsheetSetupMail extends Mailable
10+
{
11+
use Queueable;
12+
use SerializesModels;
13+
14+
public $project;
15+
public $emails = [];
16+
17+
/**
18+
* Create a new message instance.
19+
*
20+
* @return void
21+
*/
22+
public function __construct($project, array $emails)
23+
{
24+
$this->project = $project;
25+
$this->emails = $emails;
26+
}
27+
28+
/**
29+
* Build the message.
30+
*
31+
* @return $this
32+
*/
33+
public function build()
34+
{
35+
$mail = $this->subject("Project Effortsheet Setup Request: {$this->project->name}")
36+
->from(config('mail.from.address'))
37+
->to($this->emails['infrasupport_email'])
38+
->cc($this->emails['key_account_manager'])
39+
->view('project::mail.initiate-project-email')
40+
->with([
41+
'project' => $this->project,
42+
]);
43+
44+
return $mail;
45+
}
46+
}

Modules/Project/Http/Controllers/ProjectController.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ public function index()
4545
*/
4646
public function create()
4747
{
48+
$projectData = session('projectData', []);
4849
$clients = $this->service->getClients($status = 'all');
4950

50-
return view('project::create')->with('clients', $clients);
51+
return view('project::create')->with(['clients' => $clients, 'projectData' => $projectData]);
5152
}
5253

5354
/**

Modules/Project/Http/Requests/ProjectRequest.php

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function rules()
4545
'start_date' => 'nullable|date',
4646
'end_date' => 'nullable|date',
4747
'is_amc' => 'nullable',
48+
'send_mail_to_infra' => 'nullable',
4849
];
4950
break;
5051

@@ -64,6 +65,7 @@ public function rules()
6465
'start_date' => 'nullable|date',
6566
'end_date' => 'nullable|date',
6667
'is_amc' => 'nullable',
68+
'send_mail_to_infra' => 'nullable',
6769
];
6870
break;
6971

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div>
2+
<style>
3+
.line {
4+
line-height: 1px;
5+
}
6+
7+
</style>
8+
<p>Hi Infrastructure Support Team,</p>
9+
10+
<p>This is to put a request to set up a project folder and its effortsheet. Please find the necessary details below:</p>
11+
12+
<ul>
13+
<li><strong>Project Name:</strong> {{ $project->name }}</li>
14+
<li><strong>Client Name:</strong> {{ $project->client->name }}</li>
15+
<li><strong>Billing Type:</strong> {{ Str::of($project->type)->replace('-', ' ')->title() }}</li>
16+
<li><strong>Due Date:</strong> {{ now()->format('d M Y') }}</li>
17+
</ul>
18+
19+
<p>We've copied the key account manager in the email thread. Once processed, please share the link on this thread. If you come across any queries or need assistance with details, please drop an email here.</p>
20+
21+
<br>
22+
<p class="line">Best,</p>
23+
<p class="line">Portal Team</p>
24+
<p class="line">ColoredCow</p>
25+
</div>

Modules/Project/Resources/views/subviews/create-project-details.blade.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
<div class="form-group col-md-5">
66
<label for="name" class="field-required">Name</label>
77
<input type="text" class="form-control" name="name" id="name" placeholder="Enter project name"
8-
required="required" value="{{ old('name') }}">
8+
required="required" value="{{ old('name', $projectData['name'] ?? '') }}">
99
</div>
1010
<div class="form-group offset-md-1 col-md-5">
1111
<label for="client_id" class="field-required">Client</label>
1212
<select name="client_id" id="client_id" class="form-control" required="required">
1313
<option value="">Select client</option>
1414
@foreach ($clients as $client)
15-
<option value="{{ $client->id }}" {{ old('client_id') == $client->id ? 'selected' : '' }}>{{ $client->name }}</option>
15+
<option value="{{ $client->id }}" {{ old('client_id', $projectData['client_id'] ?? '') == $client->id ? 'selected' : '' }}>{{ $client->name }}</option>
1616
@endforeach
1717
</select>
1818
</div>
@@ -22,7 +22,7 @@
2222
<label for="status" class="field-required">Status</label>
2323
<select name="status" id="status" class="form-control" required="required">
2424
@foreach (config('project.status') as $key => $display_name)
25-
<option value="{{ $key }}" {{ old('status') == $key ? 'selected' : '' }}>{{ $display_name }}</option>
25+
<option value="{{ $key }}" {{ old('status', $projectData['status'] ?? '') == $key ? 'selected' : '' }}>{{ $display_name }}</option>
2626
@endforeach
2727
</select>
2828
</div>
@@ -82,19 +82,21 @@
8282
<div class="form-group offset-md-1 col-md-5">
8383
<input type="checkbox" id="isamc" name="is_amc" value="true">
8484
<label for="is_amc">AMC</label><br>
85+
<input type="checkbox" id="send_mail_to_infra" name="send_mail_to_infra" value="true">
86+
<label for="send_mail_to_infra">Send Project Initiation Email to Infrasupport</label><br>
8587
</div>
8688
</div>
8789
<br>
8890
<div class="form-row">
8991
<div class="form-group col-md-5" v-if="projectType !== 'non-billable'">
9092
<label for="total_estimated_hours">{{ __('Total Estimated Hours') }}</label>
9193
<input type="number" class="form-control" name="total_estimated_hours" id="total_estimated_hours"
92-
placeholder="Enter total estimated hours" value="{{ old('total_estimated_hours') }}">
94+
placeholder="Enter total estimated hours" value="{{ old('total_estimated_hours', $projectData['total_estimated_hours'] ?? '') }}">
9395
</div>
9496
</div>
9597
</div>
9698
<div class="card-footer">
97-
<button type="button" class="btn btn-primary mb-10" id="save-btn-action">Create</button>
99+
<button type="button" class="btn btn-primary" id="save-btn-action">Create</button>
98100
</div>
99101
</div>
100102

Modules/Project/Services/ProjectService.php

+13
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
use Carbon\CarbonPeriod;
88
use Illuminate\Support\Arr;
99
use Illuminate\Support\Facades\Auth;
10+
use Illuminate\Support\Facades\Mail;
1011
use Illuminate\Support\Facades\Storage;
1112
use Maatwebsite\Excel\Facades\Excel;
1213
use Modules\Client\Entities\Client;
1314
use Modules\HR\Entities\Employee;
1415
use Modules\Project\Contracts\ProjectServiceContract;
16+
use Modules\Project\Emails\EffortsheetSetupMail;
1517
use Modules\Project\Entities\Project;
1618
use Modules\Project\Entities\ProjectBillingDetail;
1719
use Modules\Project\Entities\ProjectContract;
@@ -104,6 +106,17 @@ public function store($data)
104106
);
105107
}
106108

109+
110+
if (isset($data['send_mail_to_infra']) && $data['send_mail_to_infra']) {
111+
// ToDo: Make infra email fetched from ENV
112+
$emails = [
113+
'key_account_manager' => $project->keyAccountManager->email,
114+
'infrasupport_email' => '[email protected]',
115+
];
116+
117+
Mail::send(new EffortsheetSetupMail($project, $emails));
118+
}
119+
107120
$project->client->update(['status' => 'active']);
108121
$this->saveOrUpdateProjectContract($data, $project);
109122
}

Modules/Prospect/Http/Controllers/ProspectController.php

+19
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ public function edit($id)
106106
public function update(Request $request, Prospect $prospect)
107107
{
108108
$data = $this->service->update($request, $prospect);
109+
if ($request->input('action') === 'update_create_project') {
110+
$totalEstimatedHours = $this->getTotalEstimatedHoursForProject($prospect);
111+
$projectData = [
112+
'name' => $prospect->project_name,
113+
'client_id' => $prospect->client_id,
114+
'status' => 'active',
115+
'total_estimated_hours' => $totalEstimatedHours ?? null,
116+
];
117+
118+
return redirect()->route('project.create')->with('projectData', $projectData);
119+
}
109120

110121
return $data;
111122
}
@@ -133,4 +144,12 @@ public function insightsUpdate(Request $request, $id)
133144

134145
return redirect()->route('prospect.show', $id)->with('status', 'Prospect Insights updated successfully!');
135146
}
147+
148+
public function getTotalEstimatedHoursForProject($prospectData)
149+
{
150+
$projectBudget = $prospectData->budget;
151+
$clientServiceRates = Client::find($prospectData->client_id)->billingDetails->service_rates;
152+
153+
return $clientServiceRates ? $projectBudget / $clientServiceRates : '';
154+
}
136155
}

Modules/Prospect/Resources/assets/js/app.js

+25
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@ const CUSTOMER_TYPES = {
33
EXISTING: "existing",
44
DORMANT: "dormant"
55
};
6+
7+
const PROPOSAL_STATUS = {
8+
PENDING: "pending",
9+
DISCUSSION_ONGOING: "discussions-ongoing",
10+
CONVERTED: "converted",
11+
REJECTED: "rejected",
12+
CLIENT_UNRESPONSIVE: "client-unresponsive",
13+
FINAL_DECISION_PENDING: "final-decision-pending"
14+
};
15+
616
document.addEventListener("DOMContentLoaded", function () {
717
const customerTypeField = document.getElementById("customer_type");
818
const orgNameTextField = document.getElementById("org_name_text_field");
919
const orgNameSelectField = document.getElementById("org_name_select_field");
1020
const orgNameTextInput = document.getElementById("org_name");
1121
const orgNameSelectInput = document.getElementById("org_name_select");
22+
const proposalStatus = document.getElementById("proposal_status");
23+
const updateAndCreateProjectButton = document.getElementById("update_create_project_button");
1224

1325
function toggleOrgNameField() {
1426
if (customerTypeField.value === CUSTOMER_TYPES.NEW) {
@@ -32,7 +44,20 @@ document.addEventListener("DOMContentLoaded", function () {
3244
}
3345
}
3446

47+
function toggleUpdateAndCreateProjectButton() {
48+
if(updateAndCreateProjectButton) {
49+
if(proposalStatus.value === PROPOSAL_STATUS.CONVERTED) {
50+
updateAndCreateProjectButton.classList.remove("d-none");
51+
} else {
52+
updateAndCreateProjectButton.classList.add("d-none");
53+
}
54+
}
55+
56+
}
57+
3558
toggleOrgNameField();
59+
toggleUpdateAndCreateProjectButton();
3660

3761
customerTypeField.addEventListener("change", toggleOrgNameField);
62+
proposalStatus.addEventListener("change", toggleUpdateAndCreateProjectButton);
3863
});

Modules/Prospect/Resources/views/index.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<td class="w-30p">
4545
<div>
4646
<a href="{{ route('prospect.show', $prospect->id) }}" class="text-decoration-none">
47-
{{ $prospect->project_name ?? $prospect->organization_name }}
47+
{{ $prospect->project_name ?? ($prospect->organization_name ?? $prospect->client->name) }}
4848
</a>
4949
<div>
5050
@if($prospect->customer_type == 'new')

Modules/Prospect/Resources/views/subviews/edit-prospect-details.blade.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@
122122
</div>
123123
</div>
124124
<div class="card-footer">
125-
<button type="submit" class="btn btn-primary">Update</button>
125+
<button type="submit" name="action" value="update" class="btn btn-primary">Update</button>
126+
@if($prospect->customer_type === "existing")
127+
<button type="submit" name="action" id="update_create_project_button" value="update_create_project" class="btn ml-3 d-none btn-primary">Update and Create Project</button>
128+
@endif
126129
</div>
127130
</form>
128131
</div>

0 commit comments

Comments
 (0)