Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Release]: 4 Nov #3746

Merged
merged 39 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ac933b5
feat(*): create the prospect_insights table
Oct 25, 2024
2494c5e
feat(*): added the prospect insights page
Oct 26, 2024
a0ca25e
feat(*): add the prospect insights field
Oct 26, 2024
e178747
feat(*): added the prospect insights functionality
Oct 27, 2024
021d6bf
fix(*): cs fixer
Oct 27, 2024
f255dce
fix(*): cs fixer
Oct 27, 2024
64e2a11
feat(*): added the clients dropdown based on the some condition
Oct 28, 2024
2b5bebb
fix(*): php cs fixer
Oct 28, 2024
fdfbea3
feat(*): added the client id and project name in the prospect table
Oct 28, 2024
73a3de8
fix(*): make the orgnization name as required field
Oct 28, 2024
f96e09e
fix(*): added the client id and project name
Oct 28, 2024
952637a
fix(*): few updates and code cleanup
Oct 28, 2024
a92d054
fix(*): php cs fixer
Oct 28, 2024
969a612
fix(*): made the few updates
Oct 28, 2024
80e71cb
fix(*): add exists request
Oct 28, 2024
ed04baf
fix(*): minor updates
Oct 28, 2024
50743c8
fix(*): minor updates
Oct 28, 2024
5211fb3
fix(*): minor updates
Oct 29, 2024
e382521
fix(*): few updates
Oct 29, 2024
4decf40
fix(*): few updates on app.js
Oct 29, 2024
a339043
feat(*): add the project name in the prospect
Oct 29, 2024
9cbbd25
fix(*): few updates
Nov 1, 2024
2d6e7c4
feat(*): few updates on the prospect module
Nov 2, 2024
14d479a
fix(*): php fixer
Nov 2, 2024
69bd8d9
fix(*): few fixes
Nov 2, 2024
7f0551a
fix(*): formate the amount
Nov 3, 2024
d451515
fix(*): use SRP
Nov 3, 2024
ce85ab1
fix(*): fix the query and for getting the prospects
Nov 3, 2024
c0555f8
added the N/A if the data is not available
Nov 3, 2024
ddd1e2b
Merge pull request #3744 from ColoredCow/feat/phase-2-prospect-module
Nov 4, 2024
5d828d7
fix(*): resolve merge conflicts
Nov 4, 2024
2316db7
fix(*) : change the name of the tab
Nov 4, 2024
b730b1d
fix(*): added the required parameter
Nov 4, 2024
1d1f11b
fix(*): added the count of the prospect insights
Nov 4, 2024
b415f2d
fix(*): refactor code
Nov 4, 2024
e481202
Merge pull request #3739 from ColoredCow/feat/prospect-insight
Nov 4, 2024
c638c4a
Merge branch 'master' of https://github.com/ColoredCow/portal into re…
Nov 4, 2024
741a28f
fix(*): few fixes
Nov 4, 2024
bbb4f07
Merge pull request #3747 from ColoredCow/fix/few-updates
Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Modules/Client/Entities/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Modules\Invoice\Entities\LedgerAccount;
use Modules\Invoice\Services\InvoiceService;
use Modules\Project\Entities\Project;
use Modules\Prospect\Entities\Prospect;
use Modules\User\Entities\User;

class Client extends Model
Expand Down Expand Up @@ -396,6 +397,16 @@ public function hasCustomInvoiceTemplate()
return false;
}

public function prospect()
{
return $this->belongsTo(Prospect::class);
}

public function getClientsAttribute()
{
return $this->query()->orderBy('name')->get();
}

protected static function booted()
{
static::addGlobalScope(new ClientGlobalScope);
Expand Down
9 changes: 9 additions & 0 deletions Modules/Prospect/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@
'existing' => 'Existing',
'dormant' => 'Dormant',
],
'status' => [
'pending' => 'Pending',
'proposal-sent' => 'Proposal Sent',
'discussions-ongoing' => 'Discussions Ongoing',
'converted' => 'Converted',
'rejected' => 'Rejected',
'client-unresponsive' => 'Client Unresponsive',
'final-decision-pending' => 'Final Decision Pending',
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class ProspectInsights extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('prospect_insights', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('prospect_id');
$table->integer('user_id')->unsigned();
$table->longText('insight_learning');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('prospect_id')->references('id')->on('prospects')->onDelete('cascade');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('prospect_insights');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddedClientIdProjectName extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('prospects', function (Blueprint $table) {
$table->unsignedBigInteger('client_id')->nullable();
$table->string('project_name')->nullable();
$table->string('organization_name')->nullable()->change();

$table->foreign('client_id')->references('id')->on('clients');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('prospects', function (Blueprint $table) {
$table->dropForeign(['client_id']);
$table->dropColumn('client_id');
$table->dropColumn('project_name');
$table->string('organization_name')->nullable(false)->change();
});
}
}
24 changes: 24 additions & 0 deletions Modules/Prospect/Entities/Prospect.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Modules\Client\Entities\Client;
use Modules\User\Entities\User;

class Prospect extends Model
Expand All @@ -26,4 +27,27 @@ public function getFormattedDate($date)
return $date ? Carbon::parse($date)->format('M d, Y')
: '-';
}

public function client()
{
return $this->belongsTo(Client::class, 'client_id');
}

public function getProspectDisplayName()
{
return $this->organization_name ?? optional($this->client)->name ?? 'N/A';
}

public function formattedAmount($amount)
{
$formattedAmount = preg_replace('/\B(?=(\d{2})+(?!\d))/', ',', substr($amount, 0, -3)) .
',' . substr($amount, -3);

return $formattedAmount;
}

public function insights()
{
return $this->hasMany(ProspectInsight::class);
}
}
2 changes: 1 addition & 1 deletion Modules/Prospect/Entities/ProspectComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function prospect()

public function user()
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class, 'user_id');
}
}
23 changes: 23 additions & 0 deletions Modules/Prospect/Entities/ProspectInsight.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Modules\Prospect\Entities;

use Illuminate\Database\Eloquent\Model;
use Modules\User\Entities\User;

class ProspectInsight extends Model
{
protected $fillable = [];

protected $table = 'prospect_insights';

public function prospect()
{
return $this->belongsTo(Prospect::class);
}

public function user()
{
return $this->belongsTo(User::class);
}
}
39 changes: 25 additions & 14 deletions Modules/Prospect/Http/Controllers/ProspectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Client\Entities\Client;
use Modules\Client\Entities\Country;
use Modules\Prospect\Entities\Prospect;
use Modules\Prospect\Http\Requests\ProspectRequest;
Expand All @@ -26,14 +27,10 @@ public function __construct(ProspectService $service)
*/
public function index()
{
$prospects = Prospect::with('pocUser')->get();
$countries = Country::all();
$currencySymbols = $countries->pluck('currency_symbol', 'currency');
$requestData = request()->all();
$data = $this->service->index($requestData);

return view('prospect::index', [
'prospects' => $prospects,
'currencySymbols' => $currencySymbols,
]);
return view('prospect::index', $data);
}

/**
Expand All @@ -44,11 +41,13 @@ public function create()
{
$countries = Country::all();
$user = new User();
$client = new Client();
$activeUsers = $user->active_users;

return view('prospect::create', [
'users' => $activeUsers,
'countries' => $countries,
'clients' => $client->clients,
]);
}

Expand All @@ -59,9 +58,9 @@ public function create()
public function store(ProspectRequest $request)
{
$validated = $request->validated();
$data = $this->service->store($validated);
$this->service->store($validated);

return $data;
return redirect()->route('prospect.index')->with('status', 'Prospect created successfully!');
}

/**
Expand All @@ -70,7 +69,7 @@ public function store(ProspectRequest $request)
*/
public function show($id)
{
$prospect = Prospect::with(['pocUser', 'comments', 'comments.user'])->find($id);
$prospect = Prospect::with(['comments', 'insights'])->find($id);
$countries = Country::all();
$currencySymbols = $countries->pluck('currency_symbol', 'currency');

Expand All @@ -87,26 +86,28 @@ public function show($id)
*/
public function edit($id)
{
$prospect = Prospect::with(['pocUser', 'comments'])->find($id);
$prospect = Prospect::with(['comments'])->find($id);
$countries = Country::all();
$user = new User();
$activeUsers = $user->active_users;
$client = new Client();

return view('prospect::edit', [
'prospect' => $prospect,
'users' => $activeUsers,
'countries' => $countries,
'clients' => $client->clients,
]);
}

/**
* Update the specified resource in storage.
* @param Request $request
* @param int $id
* @param Prospect $prospect
*/
public function update(Request $request, $id)
public function update(Request $request, Prospect $prospect)
{
$data = $this->service->update($request, $id);
$data = $this->service->update($request, $prospect);

return $data;
}
Expand All @@ -124,4 +125,14 @@ public function commentUpdate(Request $request, $id)

return redirect()->route('prospect.show', $id)->with('status', 'Comment updated successfully!');
}

public function insightsUpdate(Request $request, $id)
{
$validated = $request->validate([
'insight_learning' => 'required',
]);
$this->service->insightsUpdate($validated, $id);

return redirect()->route('prospect.show', $id)->with('status', 'Prospect Insights updated successfully!');
}
}
26 changes: 24 additions & 2 deletions Modules/Prospect/Http/Requests/ProspectRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ProspectRequest extends FormRequest
public function rules()
{
return [
'org_name' => 'required',
'org_name' => 'nullable',
'poc_user_id' => 'required',
'proposal_sent_date' => 'nullable|date',
'domain' => 'nullable',
Expand All @@ -26,9 +26,30 @@ public function rules()
'rfp_link' => 'nullable|url',
'proposal_link' => 'nullable|url',
'currency' => 'nullable',
'client_id' => 'nullable|exists:clients,id',
'project_name' => 'nullable',
];
}

/**
* Configure the validator instance.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
public function withValidator($validator)
{
if ($this->customer_type === 'new') {
$validator->addRules([
'org_name' => 'required',
]);
} elseif ($this->customer_type === 'existing') {
$validator->addRules([
'client_id' => 'required',
]);
}
}

/**
* Determine if the user is authorized to make this request.
*
Expand All @@ -47,7 +68,8 @@ public function authorize()
public function messages()
{
return [
'org_name.required' => 'Organization name is required',
'org_name.required' => 'Organization name is required when customer type is new.',
'client_id.required' => 'Please select an organization when customer type is existing.',
'poc_user_id.required' => 'Point of contact user ID is required',
];
}
Expand Down
38 changes: 38 additions & 0 deletions Modules/Prospect/Resources/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const CUSTOMER_TYPES = {
NEW: 'new',
EXISTING: 'existing',
DORMANT: 'dormant'
};
document.addEventListener('DOMContentLoaded', function () {
const customerTypeField = document.getElementById('customer_type');
const orgNameTextField = document.getElementById('org_name_text_field');
const orgNameSelectField = document.getElementById('org_name_select_field');
const orgNameTextInput = document.getElementById('org_name');
const orgNameSelectInput = document.getElementById('org_name_select');

function toggleOrgNameField() {
if (customerTypeField.value === CUSTOMER_TYPES.NEW) {
orgNameTextField.classList.remove('d-none');
orgNameSelectField.classList.add('d-none');
orgNameTextInput.required = true;
orgNameSelectInput.value = '';
orgNameSelectInput.required = false;
} else if (customerTypeField.value === CUSTOMER_TYPES.EXISTING) {
orgNameTextField.classList.add('d-none');
orgNameSelectField.classList.remove('d-none');
orgNameSelectInput.required = true;
orgNameTextInput.required = false;
orgNameTextInput.value = null;
} else {
orgNameTextField.classList.remove('d-none');
orgNameSelectField.classList.add('d-none');
orgNameTextInput.required = true;
orgNameSelectInput.value = '';
orgNameSelectInput.required = false;
}
}

toggleOrgNameField();

customerTypeField.addEventListener('change', toggleOrgNameField);
});
Loading
Loading