Skip to content

Commit 7703234

Browse files
committed
Added lead prefix & deal prefix
1 parent 6790b0c commit 7703234

15 files changed

+192
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Kanban boards
2424
- Custom Fields
2525
- Disabled double click on form submits
26+
- Lead prefix
27+
- Deal prefix
2628
### Changed
2729
- Improved logo sizing on pdfs
2830
- Vertical navigation for settings
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table(config('laravel-crm.db_table_prefix').'deals', function (Blueprint $table) {
17+
$table->string('deal_id')->after('description')->nullable();
18+
$table->string('prefix')->after('deal_id')->nullable();
19+
$table->integer('number')->nullable()->after('prefix');
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*
26+
* @return void
27+
*/
28+
public function down()
29+
{
30+
Schema::table(config('laravel-crm.db_table_prefix').'deals', function (Blueprint $table) {
31+
$table->dropColumn([
32+
'lead_id',
33+
'prefix',
34+
'number',
35+
]);
36+
});
37+
}
38+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table(config('laravel-crm.db_table_prefix').'leads', function (Blueprint $table) {
17+
$table->string('lead_id')->after('description')->nullable();
18+
$table->string('prefix')->after('lead_id')->nullable();
19+
$table->integer('number')->nullable()->after('prefix');
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*
26+
* @return void
27+
*/
28+
public function down()
29+
{
30+
Schema::table(config('laravel-crm.db_table_prefix').'leads', function (Blueprint $table) {
31+
$table->dropColumn([
32+
'lead_id',
33+
'prefix',
34+
'number',
35+
]);
36+
});
37+
}
38+
};

resources/lang/en/lang.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,6 @@
509509
'create_pipeline_stage' => 'create pipeline stage',
510510
'back_to_pipeline_stages' => 'back to pipeline stages',
511511
'edit_pipeline_stage' => 'edit pipeline stage',
512+
'lead_prefix' => 'lead prefix',
513+
'deal_prefix' => 'deal prefix',
512514
];

resources/views/livewire/kanban-board/record.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'limit' => 3
77
])
88
<div class="mt-2">
9-
<a href="{{ url(route('laravel-crm.'.\Illuminate\Support\Str::plural($model).'.show', $record['id'])) }}">LD-{{ $record['id'] }}</a>
9+
<a href="{{ url(route('laravel-crm.'.\Illuminate\Support\Str::plural($model).'.show', $record['id'])) }}">{{ $record['number'] }}</a>
1010
<div class="mb-0 d-inline-block float-right"><i class="fa fa-user-circle" aria-hidden="true"></i></div>
1111
</div>
1212
</div>

resources/views/settings/partials/fields.blade.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@
7777
'value' => old('tax_rate', $taxRateSetting->value ?? null),
7878
'append' => '%'
7979
])
80+
@hasleadsenabled
81+
@include('laravel-crm::partials.form.text',[
82+
'name' => 'lead_prefix',
83+
'label' => ucfirst(trans('laravel-crm::lang.lead_prefix')),
84+
'value' => old('lead_prefix', $leadPrefix->value ?? null)
85+
])
86+
@endhasleadsenabled
87+
@hasdealsenabled
88+
@include('laravel-crm::partials.form.text',[
89+
'name' => 'deal_prefix',
90+
'label' => ucfirst(trans('laravel-crm::lang.deal_prefix')),
91+
'value' => old('deal_prefix', $dealPrefix->value ?? null)
92+
])
93+
@endhasdealsenabled
8094
@hasquotesenabled
8195
@include('laravel-crm::partials.form.text',[
8296
'name' => 'quote_prefix',

src/Console/LaravelCrmUpdate.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Support\Composer;
7+
use VentureDrake\LaravelCrm\Models\Deal;
78
use VentureDrake\LaravelCrm\Models\Delivery;
89
use VentureDrake\LaravelCrm\Models\Invoice;
910
use VentureDrake\LaravelCrm\Models\InvoiceLine;
11+
use VentureDrake\LaravelCrm\Models\Lead;
1012
use VentureDrake\LaravelCrm\Models\Order;
1113
use VentureDrake\LaravelCrm\Models\OrderProduct;
1214
use VentureDrake\LaravelCrm\Models\Person;
@@ -260,6 +262,26 @@ public function handle()
260262
'--class' => 'VentureDrake\LaravelCrm\Database\Seeders\LaravelCrmPipelineTablesSeeder',
261263
]);
262264

265+
foreach (Lead::whereNull('number')->get() as $lead) {
266+
$this->info('Updating Laravel CRM lead #'.$lead->id);
267+
268+
$lead->update([
269+
'lead_id' => $this->settingService->get('lead_prefix')->value.(1000 + $lead->id),
270+
'prefix' => $this->settingService->get('lead_prefix')->value,
271+
'number' => 1000 + $lead->id,
272+
]);
273+
}
274+
275+
foreach (Deal::whereNull('number')->get() as $deal) {
276+
$this->info('Updating Laravel CRM deal #'.$deal->id);
277+
278+
$deal->update([
279+
'deal_id' => $this->settingService->get('deal_prefix')->value.(1000 + $deal->id),
280+
'prefix' => $this->settingService->get('deal_prefix')->value,
281+
'number' => 1000 + $deal->id,
282+
]);
283+
}
284+
263285
$this->settingService->set('db_update_1200', 1);
264286
$this->info('Updating Laravel CRM pipeline tables complete.');
265287
}

src/Http/Controllers/SettingController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public function edit()
3636
$currency = $this->settingService->get('currency');
3737
$timezoneSetting = $this->settingService->get('timezone');
3838
$logoFile = $this->settingService->get('logo_file');
39+
$leadPrefix = $this->settingService->get('lead_prefix');
40+
$dealPrefix = $this->settingService->get('deal_prefix');
3941
$quotePrefix = $this->settingService->get('quote_prefix');
4042
$orderPrefix = $this->settingService->get('order_prefix');
4143
$invoicePrefix = $this->settingService->get('invoice_prefix');
@@ -62,6 +64,8 @@ public function edit()
6264
'currency' => $currency,
6365
'timezoneSetting' => $timezoneSetting,
6466
'logoFile' => $logoFile,
67+
'leadPrefix' => $leadPrefix,
68+
'dealPrefix' => $dealPrefix,
6569
'quotePrefix' => $quotePrefix,
6670
'orderPrefix' => $orderPrefix,
6771
'invoicePrefix' => $invoicePrefix,
@@ -112,6 +116,14 @@ public function update(UpdateSettingRequest $request)
112116
$this->settingService->set('tax_rate', $request->tax_rate);
113117
}
114118

119+
if($request->lead_prefix) {
120+
$this->settingService->set('lead_prefix', $request->lead_prefix);
121+
}
122+
123+
if($request->deal_prefix) {
124+
$this->settingService->set('deal_prefix', $request->deal_prefix);
125+
}
126+
115127
if($request->quote_prefix) {
116128
$this->settingService->set('quote_prefix', $request->quote_prefix);
117129
}

src/Http/Livewire/LiveDealBoard.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function records(): Collection
3737
'title' => $deal->title,
3838
'labels' => $deal->labels,
3939
'stage' => $deal->pipelineStage->id ?? $this->firstStageId(),
40+
'number' => $deal->deal_id
4041
];
4142
});
4243
}

src/Http/Livewire/LiveLeadBoard.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function records(): Collection
3636
'title' => $lead->title,
3737
'labels' => $lead->labels,
3838
'stage' => $lead->pipelineStage->id ?? $this->firstStageId(),
39+
'number' => $lead->lead_id
3940
];
4041
});
4142
}

src/Http/Livewire/LiveQuoteBoard.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function records(): Collection
3737
'title' => $quote->title,
3838
'labels' => $quote->labels,
3939
'stage' => $quote->pipelineStage->id ?? $this->firstStageId(),
40+
'number' => $quote->quote_id
4041
];
4142
});
4243
}

src/Http/Middleware/Settings.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ public function handle($request, Closure $next)
114114
'value' => config('laravel-crm.tax_rate') ?? 0,
115115
]);
116116

117+
Setting::firstOrCreate([
118+
'name' => 'lead_prefix',
119+
], [
120+
'value' => 'LD-',
121+
]);
122+
123+
Setting::firstOrCreate([
124+
'name' => 'deal_prefix',
125+
], [
126+
'value' => 'DL-',
127+
]);
128+
117129
Setting::firstOrCreate([
118130
'name' => 'quote_prefix',
119131
], [

src/LaravelCrmServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ function ($perPage = 30, $page = null, $options = []) {
467467
__DIR__ . '/../database/migrations/create_laravel_crm_pipeline_stages_table.php.stub' => $this->getMigrationFileName($filesystem, 'create_laravel_crm_pipeline_stages_table.php', 100),
468468
__DIR__ . '/../database/migrations/add_pipeline_to_laravel_crm_models_table.php.stub' => $this->getMigrationFileName($filesystem, 'add_pipeline_to_laravel_crm_models_table.php', 101),
469469
__DIR__ . '/../database/migrations/add_user_to_laravel_crm_settings_table.php.stub' => $this->getMigrationFileName($filesystem, 'add_user_to_laravel_crm_settings_table.php', 102),
470+
__DIR__ . '/../database/migrations/add_prefix_to_laravel_crm_leads_table.php.stub' => $this->getMigrationFileName($filesystem, 'add_prefix_to_laravel_crm_leads_table.php', 103),
471+
__DIR__ . '/../database/migrations/add_prefix_to_laravel_crm_deals_table.php.stub' => $this->getMigrationFileName($filesystem, 'add_prefix_to_laravel_crm_deals_table.php', 104),
470472
], 'migrations');
471473

472474
// Publishing the seeders

src/Observers/DealObserver.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22

33
namespace VentureDrake\LaravelCrm\Observers;
44

5+
use Ramsey\Uuid\Uuid;
56
use VentureDrake\LaravelCrm\Models\Deal;
7+
use VentureDrake\LaravelCrm\Services\SettingService;
68

79
class DealObserver
810
{
11+
/**
12+
* @var SettingService
13+
*/
14+
private $settingService;
15+
16+
public function __construct(SettingService $settingService)
17+
{
18+
$this->settingService = $settingService;
19+
}
20+
921
/**
1022
* Handle the deal "creating" event.
1123
*
@@ -14,9 +26,20 @@ class DealObserver
1426
*/
1527
public function creating(Deal $deal)
1628
{
29+
$deal->external_id = Uuid::uuid4()->toString();
30+
1731
if (! app()->runningInConsole()) {
1832
$deal->user_created_id = auth()->user()->id ?? null;
1933
}
34+
35+
if($lastDeal = Deal::withTrashed()->orderBy('number', 'DESC')->first()) {
36+
$deal->number = $lastDeal->number + 1;
37+
} else {
38+
$deal->number = 1000;
39+
}
40+
41+
$deal->prefix = $this->settingService->get('deal_prefix')->value;
42+
$deal->deal_id = $deal->prefix.$deal->number;
2043
}
2144

2245
/**

src/Observers/LeadObserver.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22

33
namespace VentureDrake\LaravelCrm\Observers;
44

5+
use Ramsey\Uuid\Uuid;
56
use VentureDrake\LaravelCrm\Models\Lead;
7+
use VentureDrake\LaravelCrm\Services\SettingService;
68

79
class LeadObserver
810
{
11+
/**
12+
* @var SettingService
13+
*/
14+
private $settingService;
15+
16+
public function __construct(SettingService $settingService)
17+
{
18+
$this->settingService = $settingService;
19+
}
20+
921
/**
1022
* Handle the lead "creating" event.
1123
*
@@ -14,9 +26,20 @@ class LeadObserver
1426
*/
1527
public function creating(Lead $lead)
1628
{
29+
$lead->external_id = Uuid::uuid4()->toString();
30+
1731
if (! app()->runningInConsole()) {
1832
$lead->user_created_id = auth()->user()->id ?? null;
1933
}
34+
35+
if($lastLead = Lead::withTrashed()->orderBy('number', 'DESC')->first()) {
36+
$lead->number = $lastLead->number + 1;
37+
} else {
38+
$lead->number = 1000;
39+
}
40+
41+
$lead->prefix = $this->settingService->get('lead_prefix')->value;
42+
$lead->lead_id = $lead->prefix.$lead->number;
2043
}
2144

2245
/**

0 commit comments

Comments
 (0)