Skip to content

Commit 187cb2b

Browse files
committed
Added board to quotes
1 parent 32e4b0c commit 187cb2b

15 files changed

+220
-2
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@
4646
]
4747
])
4848

49+
@if($pipeline)
50+
@include('laravel-crm::partials.form.select',[
51+
'name' => 'pipeline_stage_id',
52+
'label' => ucfirst(__('laravel-crm::lang.stage')),
53+
'options' => $pipeline->pipelineStages()
54+
->orderBy('order')
55+
->orderBy('id')
56+
->pluck('name', 'id') ?? [],
57+
'value' => old('pipeline_stage_id', $deal->pipelineStage->id ?? $stage ?? $pipeline->pipelineStages()
58+
->orderBy('order')
59+
->orderBy('id')
60+
->first()->id ?? null),
61+
])
62+
@endif
63+
4964
@include('laravel-crm::partials.form.multiselect',[
5065
'name' => 'labels',
5166
'label' => ucfirst(__('laravel-crm::lang.labels')),
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@extends('laravel-crm::layouts.app')
2+
3+
@section('content')
4+
5+
@include('laravel-crm::quotes.partials.card-board')
6+
7+
@endsection
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@component('laravel-crm::components.card')
2+
3+
@component('laravel-crm::components.card-header')
4+
5+
@slot('title')
6+
{{ ucfirst(__('laravel-crm::lang.quotes')) }}
7+
@endslot
8+
9+
@slot('actions')
10+
@include('laravel-crm::partials.view-types', [
11+
'model' => 'quotes',
12+
])
13+
@include('laravel-crm::partials.filters', [
14+
'action' => route('laravel-crm.quotes.filter'),
15+
'model' => '\VentureDrake\LaravelCrm\Models\Quote'
16+
])
17+
@can('create crm quotes')
18+
<a type="button" class="btn btn-primary btn-sm" href="{{ url(route('laravel-crm.quotes.create')) }}"><span class="fa fa-plus"></span> {{ ucfirst(__('laravel-crm::lang.add_quote')) }}</a>
19+
@endcan
20+
@endslot
21+
22+
@endcomponent
23+
24+
@component('laravel-crm::components.card-table')
25+
26+
<livewire:live-quote-board />
27+
28+
@endcomponent
29+
30+
@endcomponent

resources/views/quotes/partials/card-index.blade.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77
@endslot
88

99
@slot('actions')
10+
@if($pipeline)
11+
@include('laravel-crm::partials.view-types', [
12+
'model' => 'quotes',
13+
'viewSetting' => $viewSetting ?? 'list'
14+
])
15+
@endif
16+
1017
@include('laravel-crm::partials.filters', [
1118
'action' => route('laravel-crm.quotes.filter'),
1219
'model' => '\VentureDrake\LaravelCrm\Models\Quote'
1320
])
1421
@can('create crm quotes')
15-
<span class="float-right"><a type="button" class="btn btn-primary btn-sm" href="{{ url(route('laravel-crm.quotes.create')) }}"><span class="fa fa-plus"></span> {{ ucfirst(__('laravel-crm::lang.add_quote')) }}</a></span>
22+
<a type="button" class="btn btn-primary btn-sm" href="{{ url(route('laravel-crm.quotes.create')) }}"><span class="fa fa-plus"></span> {{ ucfirst(__('laravel-crm::lang.add_quote')) }}</a>
1623
@endcan
1724
@endslot
1825

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@
6666
'rows' => 5,
6767
'value' => old('terms', $quote->terms ?? $quoteTerms->value ?? null)
6868
])
69+
70+
@if($pipeline)
71+
@include('laravel-crm::partials.form.select',[
72+
'name' => 'pipeline_stage_id',
73+
'label' => ucfirst(__('laravel-crm::lang.stage')),
74+
'options' => $pipeline->pipelineStages()
75+
->orderBy('order')
76+
->orderBy('id')
77+
->pluck('name', 'id') ?? [],
78+
'value' => old('pipeline_stage_id', $quote->pipelineStage->id ?? $stage ?? $pipeline->pipelineStages()
79+
->orderBy('order')
80+
->orderBy('id')
81+
->first()->id ?? null),
82+
])
83+
@endif
6984

7085
@include('laravel-crm::partials.form.multiselect',[
7186
'name' => 'labels',

src/Http/Controllers/DealController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public function create(Request $request)
103103
'client' => $client ?? null,
104104
'organisation' => $organisation ?? null,
105105
'person' => $person ?? null,
106+
'pipeline' => Pipeline::where('model', get_class(new Deal()))->first(),
107+
'stage' => $request->stage ?? null
106108
]);
107109
}
108110

@@ -207,6 +209,7 @@ public function edit(Deal $deal)
207209
'email' => $email ?? null,
208210
'phone' => $phone ?? null,
209211
'address' => $address ?? null,
212+
'pipeline' => Pipeline::where('model', get_class(new Deal()))->first()
210213
]);
211214
}
212215

src/Http/Controllers/QuoteController.php

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use VentureDrake\LaravelCrm\Models\Client;
1212
use VentureDrake\LaravelCrm\Models\Organisation;
1313
use VentureDrake\LaravelCrm\Models\Person;
14+
use VentureDrake\LaravelCrm\Models\Pipeline;
1415
use VentureDrake\LaravelCrm\Models\Quote;
1516
use VentureDrake\LaravelCrm\Services\OrderService;
1617
use VentureDrake\LaravelCrm\Services\OrganisationService;
@@ -61,6 +62,17 @@ public function __construct(QuoteService $quoteService, PersonService $personSer
6162
*/
6263
public function index(Request $request)
6364
{
65+
$viewSetting = auth()->user()->crmSettings()->where('name', 'view_quotes')->first();
66+
67+
if(! $viewSetting) {
68+
auth()->user()->crmSettings()->create([
69+
'name' => 'view_quotes',
70+
'value' => 'list',
71+
]);
72+
} elseif($viewSetting->value == 'board') {
73+
return redirect(route('laravel-crm.quotes.board'));
74+
}
75+
6476
Quote::resetSearchValue($request);
6577
$params = Quote::filters($request);
6678

@@ -71,7 +83,9 @@ public function index(Request $request)
7183
}
7284

7385
return view('laravel-crm::quotes.index', [
74-
'quotes' => $quotes
86+
'quotes' => $quotes,
87+
'viewSetting' => $viewSetting->value ?? null,
88+
'pipeline' => Pipeline::where('model', get_class(new Quote()))->first(),
7589
]);
7690
}
7791

@@ -108,6 +122,8 @@ public function create(Request $request)
108122
'prefix' => $this->settingService->get('quote_prefix'),
109123
'number' => (Quote::latest()->first()->number ?? 1000) + 1,
110124
'quoteTerms' => $quoteTerms,
125+
'pipeline' => Pipeline::where('model', get_class(new Quote()))->first(),
126+
'stage' => $request->stage ?? null
111127
]);
112128
}
113129

@@ -213,6 +229,7 @@ public function edit(Quote $quote)
213229
'email' => $email ?? null,
214230
'phone' => $phone ?? null,
215231
'address' => $address ?? null,
232+
'pipeline' => Pipeline::where('model', get_class(new Quote()))->first()
216233
]);
217234
}
218235

@@ -417,4 +434,45 @@ public function download(Quote $quote)
417434
'logo' => $this->settingService->get('logo_file')->value ?? null,
418435
])->download('quote-'.strtolower($quote->quote_id).'.pdf');
419436
}
437+
438+
public function list(Request $request)
439+
{
440+
auth()->user()->crmSettings()->updateOrCreate([
441+
'name' => 'view_quotes',
442+
], [
443+
'value' => 'list',
444+
]);
445+
446+
return redirect(route('laravel-crm.quotes.index'));
447+
}
448+
449+
/**
450+
* Display a listing of the resource.
451+
*
452+
* @return \Illuminate\Http\Response
453+
*/
454+
public function board(Request $request)
455+
{
456+
$viewSetting = auth()->user()->crmSettings()->where('name', 'view_quotes')->first();
457+
458+
auth()->user()->crmSettings()->updateOrCreate([
459+
'name' => 'view_quotes',
460+
], [
461+
'value' => 'board',
462+
]);
463+
464+
Quote::resetSearchValue($request);
465+
$params = Quote::filters($request);
466+
467+
if (Quote::filter($params)->get()->count() < 30) {
468+
$quotes = Quote::filter($params)->latest()->get();
469+
} else {
470+
$quotes = Quote::filter($params)->latest()->paginate(30);
471+
}
472+
473+
return view('laravel-crm::quotes.board', [
474+
'quotes' => $quotes,
475+
'viewSetting' => $viewSetting->value ?? null
476+
]);
477+
}
420478
}

src/Http/Livewire/LiveQuoteBoard.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace VentureDrake\LaravelCrm\Http\Livewire;
4+
5+
use Illuminate\Support\Collection;
6+
use VentureDrake\LaravelCrm\Http\Livewire\KanbanBoard\KanbanBoard;
7+
use VentureDrake\LaravelCrm\Models\Quote;
8+
use VentureDrake\LaravelCrm\Models\Pipeline;
9+
10+
class LiveQuoteBoard extends KanbanBoard
11+
{
12+
public $model = 'deal';
13+
14+
public function stages(): Collection
15+
{
16+
if($pipeline = Pipeline::where('model', get_class(new Quote()))->first()) {
17+
return $pipeline->pipelineStages()
18+
->orderBy('order')
19+
->orderBy('id')
20+
->get();
21+
}
22+
}
23+
24+
public function onStageChanged($recordId, $stageId, $fromOrderedIds, $toOrderedIds)
25+
{
26+
Quote::find($recordId)->update([
27+
'pipeline_stage_id' => $stageId
28+
]);
29+
}
30+
31+
public function records(): Collection
32+
{
33+
return Quote::get()
34+
->map(function (Quote $quote) {
35+
return [
36+
'id' => $quote->id,
37+
'title' => $quote->title,
38+
'labels' => $quote->labels,
39+
'stage' => $quote->pipelineStage->id ?? $this->firstStageId(),
40+
];
41+
});
42+
}
43+
}

src/Http/routes.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@
236236
->name('laravel-crm.quotes.index')
237237
->middleware(['can:viewAny,VentureDrake\LaravelCrm\Models\Quote']);
238238

239+
Route::get('list', 'VentureDrake\LaravelCrm\Http\Controllers\QuoteController@list')
240+
->name('laravel-crm.quotes.list')
241+
->middleware(['can:viewAny,VentureDrake\LaravelCrm\Models\Quote']);
242+
243+
Route::get('board', 'VentureDrake\LaravelCrm\Http\Controllers\QuoteController@board')
244+
->name('laravel-crm.quotes.board')
245+
->middleware(['can:viewAny,VentureDrake\LaravelCrm\Models\Quote']);
246+
239247
Route::get('create', 'VentureDrake\LaravelCrm\Http\Controllers\QuoteController@create')
240248
->name('laravel-crm.quotes.create')
241249
->middleware(['can:create,VentureDrake\LaravelCrm\Models\Quote']);

src/LaravelCrmServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
use VentureDrake\LaravelCrm\Http\Livewire\LivePhoneEdit;
5555
use VentureDrake\LaravelCrm\Http\Livewire\LiveProductForm;
5656
use VentureDrake\LaravelCrm\Http\Livewire\LivePurchaseOrderLines;
57+
use VentureDrake\LaravelCrm\Http\Livewire\LiveQuoteBoard;
5758
use VentureDrake\LaravelCrm\Http\Livewire\LiveQuoteForm;
5859
use VentureDrake\LaravelCrm\Http\Livewire\LiveQuoteItems;
5960
use VentureDrake\LaravelCrm\Http\Livewire\LiveRelatedContactOrganisation;
@@ -530,6 +531,7 @@ function ($perPage = 30, $page = null, $options = []) {
530531
Livewire::component('deal-form', LiveDealForm::class);
531532
Livewire::component('live-deal-board', LiveDealBoard::class);
532533
Livewire::component('quote-form', LiveQuoteForm::class);
534+
Livewire::component('live-quote-board', LiveQuoteBoard::class);
533535
Livewire::component('notify-toast', NotifyToast::class);
534536
Livewire::component('quote-items', LiveQuoteItems::class);
535537
Livewire::component('order-form', LiveOrderForm::class);

src/Models/Pipeline.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ public function deals()
3131
{
3232
return $this->hasMany(\VentureDrake\LaravelCrm\Models\Deal::class);
3333
}
34+
35+
public function quotes()
36+
{
37+
return $this->hasMany(\VentureDrake\LaravelCrm\Models\Quote::class);
38+
}
3439
}

src/Models/PipelineStage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ public function deals()
3636
{
3737
return $this->hasMany(\VentureDrake\LaravelCrm\Models\Deal::class);
3838
}
39+
40+
public function quotes()
41+
{
42+
return $this->hasMany(\VentureDrake\LaravelCrm\Models\Quote::class);
43+
}
3944
}

src/Models/Quote.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,14 @@ public function orderComplete()
225225

226226
return true;
227227
}
228+
229+
public function pipeline()
230+
{
231+
return $this->belongsTo(\VentureDrake\LaravelCrm\Models\Pipeline::class);
232+
}
233+
234+
public function pipelineStage()
235+
{
236+
return $this->belongsTo(\VentureDrake\LaravelCrm\Models\PipelineStage::class);
237+
}
228238
}

src/Services/DealService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Ramsey\Uuid\Uuid;
66
use VentureDrake\LaravelCrm\Models\Deal;
77
use VentureDrake\LaravelCrm\Models\DealProduct;
8+
use VentureDrake\LaravelCrm\Models\PipelineStage;
89
use VentureDrake\LaravelCrm\Repositories\DealRepository;
910

1011
class DealService
@@ -37,6 +38,8 @@ public function create($request, $person = null, $organisation = null, $client =
3738
'currency' => $request->currency,
3839
'expected_close' => $request->expected_close,
3940
'user_owner_id' => $request->user_owner_id,
41+
'pipeline_id' => PipelineStage::find($request->pipeline_stage_id)->pipeline->id ?? null,
42+
'pipeline_stage_id' => $request->pipeline_stage_id ?? null,
4043
]);
4144

4245
$deal->labels()->sync($request->labels ?? []);
@@ -68,6 +71,8 @@ public function update($request, Deal $deal, $person = null, $organisation = nul
6871
'currency' => $request->currency,
6972
'expected_close' => $request->expected_close,
7073
'user_owner_id' => $request->user_owner_id,
74+
'pipeline_id' => PipelineStage::find($request->pipeline_stage_id)->pipeline->id ?? null,
75+
'pipeline_stage_id' => $request->pipeline_stage_id ?? null,
7176
]);
7277

7378
$deal->labels()->sync($request->labels ?? []);

src/Services/QuoteService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace VentureDrake\LaravelCrm\Services;
44

5+
use VentureDrake\LaravelCrm\Models\PipelineStage;
56
use VentureDrake\LaravelCrm\Models\Product;
67
use VentureDrake\LaravelCrm\Models\Quote;
78
use VentureDrake\LaravelCrm\Models\QuoteProduct;
@@ -45,6 +46,8 @@ public function create($request, $person = null, $organisation = null, $client =
4546
'adjustments' => $request->adjustment,
4647
'total' => $request->total,
4748
'user_owner_id' => $request->user_owner_id,
49+
'pipeline_id' => PipelineStage::find($request->pipeline_stage_id)->pipeline->id ?? null,
50+
'pipeline_stage_id' => $request->pipeline_stage_id ?? null,
4851
]);
4952

5053
$quote->labels()->sync($request->labels ?? []);
@@ -107,6 +110,8 @@ public function update($request, Quote $quote, $person = null, $organisation = n
107110
'adjustments' => $request->adjustment,
108111
'total' => $request->total,
109112
'user_owner_id' => $request->user_owner_id,
113+
'pipeline_id' => PipelineStage::find($request->pipeline_stage_id)->pipeline->id ?? null,
114+
'pipeline_stage_id' => $request->pipeline_stage_id ?? null,
110115
]);
111116

112117
$quote->labels()->sync($request->labels ?? []);

0 commit comments

Comments
 (0)