Skip to content

Commit 2070846

Browse files
committed
1 parent ebd6400 commit 2070846

File tree

7 files changed

+355
-89
lines changed

7 files changed

+355
-89
lines changed

app/Http/Controllers/Workflow/LeadsController.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Str;
66
use App\Models\Workflow\Leads;
7+
use App\Services\LeadsKPIService;
78
use App\Traits\NextPreviousTrait;
89
use App\Services\SelectDataService;
910
use App\Http\Controllers\Controller;
@@ -16,18 +17,30 @@ class LeadsController extends Controller
1617
use NextPreviousTrait;
1718

1819
protected $SelectDataService;
20+
protected $leadsKPIService;
1921

20-
public function __construct(SelectDataService $SelectDataService)
22+
public function __construct(SelectDataService $SelectDataService,
23+
LeadsKPIService $LeadsKPIService)
2124
{
22-
$this->SelectDataService = $SelectDataService;
25+
$this->SelectDataService = $SelectDataService;
26+
$this->leadsKPIService = $LeadsKPIService;
2327
}
2428

2529
/**
2630
* @return \Illuminate\Contracts\View\View
2731
*/
2832
public function index()
2933
{
30-
return view('workflow/leads-index');
34+
// Using the OpportunitiesKPIService to retrieve KPI data
35+
$data['leadsCountRate'] = $this->leadsKPIService->getLeadsDataRate();
36+
$leadByCompany = $this->leadsKPIService->getLeadsByCompany();
37+
$leadsCount = $this->leadsKPIService->getLeadsCount();
38+
$leadsCountByUser = $this->leadsKPIService->getLeadsCountByUser();
39+
$leadsCountByPriority = $this->leadsKPIService->getLeadsCountByPriority();
40+
return view('workflow/leads-index', array_merge(
41+
compact(
42+
'leadByCompany', 'leadsCount', 'leadsCountByUser', 'leadsCountByPriority')
43+
))->with('data', $data);
3144
}
3245

3346
/**

app/Livewire/LeadsIndex.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class LeadsIndex extends Component
2121
public $sortField = 'statu'; // default sorting field
2222
public $sortAsc = true; // default sort direction
2323

24+
public $searchIdPriority = '';
25+
2426
private $Leadslist;
2527

2628
public $id;
@@ -68,7 +70,9 @@ public function render()
6870
->paginate(15);
6971
}
7072
else{
71-
$Leadslist = $this->Leadslist = Leads::orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')
73+
$Leadslist = $this->Leadslist = Leads::where('campaign','like', '%'.$this->search.'%')
74+
->where('priority', 'like', '%'.$this->searchIdPriority.'%')
75+
->orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')
7276
->paginate(15);
7377
}
7478

app/Services/LeadsKPIService.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace App\Services;
4+
5+
use App\Models\Workflow\Leads;
6+
use Illuminate\Support\Facades\DB;
7+
8+
class LeadsKPIService
9+
{
10+
/**
11+
* Get the rate of leads data grouped by status.
12+
*
13+
* @return \Illuminate\Support\Collection
14+
*/
15+
public function getLeadsDataRate()
16+
{
17+
return DB::table('leads')
18+
->select('statu', DB::raw('count(*) as leadsCountRate'))
19+
->groupBy('statu')
20+
->get();
21+
}
22+
23+
/**
24+
* Get the count of leads grouped by priority.
25+
*
26+
* @return \Illuminate\Support\Collection
27+
*/
28+
public function getLeadsCountByPriority()
29+
{
30+
return Leads::select('priority', DB::raw('count(*) as leadsCount'))
31+
->groupBy('priority')
32+
->get();
33+
}
34+
35+
/**
36+
* Get the count of leads grouped by company.
37+
*
38+
* @return \Illuminate\Support\Collection
39+
*/
40+
public function getLeadsByCompany()
41+
{
42+
return Leads::with('companie')
43+
->select('companies_id', DB::raw('count(*) as count'))
44+
->groupBy('companies_id')
45+
->limit(10)
46+
->get();
47+
}
48+
49+
50+
/**
51+
* Get the total count of leads.
52+
*
53+
* @return int
54+
*/
55+
public function getLeadsCount()
56+
{
57+
return Leads::count();
58+
}
59+
60+
61+
/**
62+
* Get the count of leads by user.
63+
*
64+
* @return \Illuminate\Support\Collection
65+
*/
66+
public function getLeadsCountByUser()
67+
{
68+
return Leads::select('user_id', 'statu', \DB::raw('count(*) as total'))
69+
->with('UserManagement:id,name') // Charge la relation UserManagement avec les champs id et name
70+
->whereIn('statu', [1, 2, 3, 4, 5, 6]) // Statuts allant de 1 à 6
71+
->groupBy('user_id', 'statu')
72+
->get()
73+
->groupBy('user_id');
74+
}
75+
76+
}

resources/lang/en/general_content.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@
650650
'leads_trans_key' => 'Leads',
651651
'lead_trans_key' => 'Lead',
652652
'new_leads_trans_key' => 'New Lead',
653+
'list_leads_trans_key' => 'Lead list',
653654

654655
//OPPORTUNITIES
655656
'opportunities_trans_key' => 'Opportunities',

resources/lang/fr/general_content.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@
650650
'leads_trans_key' => 'Leads',
651651
'lead_trans_key' => 'Lead',
652652
'new_leads_trans_key' => 'Nouveau Lead',
653+
'list_leads_trans_key' => 'Liste des Lead',
653654

654655
//OPPORTUNITIES
655656
'opportunities_trans_key' => 'Oportunités',

resources/views/livewire/leads-index.blade.php

Lines changed: 109 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
<div class="card-body">
22
<!-- View toggle button -->
3-
<div class="mb-3">
4-
<button class="btn btn-primary" wire:click="changeView('table')">
5-
<i class="fas fa-table mr-1"></i> Table
6-
</button>
7-
<button class="btn btn-secondary" wire:click="changeView('cards')">
8-
<i class="fas fa-th-large mr-1"></i> Cards
9-
</button>
3+
<div class="row">
4+
<!-- View toggle button -->
5+
<div class="col-2">
6+
<button class="btn btn-primary" wire:click="changeView('table')">
7+
<i class="fas fa-table mr-1"></i> Table
8+
</button>
9+
<button class="btn btn-secondary" wire:click="changeView('cards')">
10+
<i class="fas fa-th-large mr-1"></i> Cards
11+
</button>
12+
</div>
13+
<div class="col-6">
14+
@include('include.search-card')
15+
</div>
16+
<div class="col-2">
17+
<div class="form-group">
18+
<div class="input-group">
19+
<div class="input-group-prepend">
20+
<span class="input-group-text"><i class="fas fa-list"></i></span>
21+
</div>
22+
<select class="form-control" name="searchIdPriority" id="searchIdPriority" wire:model.live="searchIdPriority">
23+
<option value="" selected>{{ __('general_content.select_statu_trans_key') }}</option>
24+
<option value="1">{{ __('general_content.burning_trans_key') }}</option>
25+
<option value="2">{{ __('general_content.hot_trans_key') }}</option>
26+
<option value="3">{{ __('general_content.lukewarm_trans_key') }}</option>
27+
<option value="4">{{ __('general_content.cold_trans_key') }}</option>
28+
</select>
29+
</div>
30+
</div>
31+
</div>
32+
<div class="col-2">
33+
<button type="button" class="btn btn-success float-sm-right" data-toggle="modal" data-target="#ModalLead">
34+
{{ __('general_content.new_leads_trans_key')}}
35+
</button>
36+
</div>
1037
</div>
1138

1239
<!-- Modal -->
@@ -158,75 +185,82 @@
158185
</div>
159186
<!-- End Modal -->
160187
@if($viewType === 'table')
161-
<div class="card">
162-
<div class="table-responsive p-0">
163-
<table class="table table-hover">
164-
<thead>
165-
<tr>
166-
<th></th>
167-
<th>{{__('general_content.customer_trans_key') }}</th>
168-
<th>{{ __('general_content.contact_name_trans_key') }}</th>
169-
<th>{{ __('general_content.adress_name_trans_key') }}</th>
170-
<th>{{ __('general_content.user_trans_key') }}</th>
171-
<th>{{ __('general_content.source_trans_key') }}</th>
172-
<th>{{ __('general_content.priority_trans_key') }}</th>
173-
<th>{{ __('general_content.campaign_trans_key') }}</th>
174-
<th>
175-
<a class="btn btn-secondary" wire:click.prevent="sortBy('statu')" role="button" href="#">{{ __('general_content.status_trans_key') }} @include('include.sort-icon', ['field' => 'statu'])</a>
176-
</th>
177-
<th>{{__('general_content.action_trans_key') }}</th>
178-
</tr>
179-
</thead>
180-
<tbody>
181-
@forelse ($Leadslist as $Lead)
182-
<tr>
183-
<td>#{{ $Lead->id }}</td>
184-
<td><x-CompanieButton id="{{ $Lead->companies_id }}" label="{{ $Lead->companie['label'] }}" /></td>
185-
<td>{{ $Lead->companie['first_name'] }} {{ $Lead->contact['name'] }}</td>
186-
<td>{{ $Lead->adresse['adress'] }} {{ $Lead->adresse['zipcode'] }} {{ $Lead->adresse['city'] }}</td>
187-
<td><img src="{{ Avatar::create($Lead->UserManagement['name'])->toBase64() }}" /></td>
188-
<td>{{ $Lead->source }}</td>
189-
<td>
190-
@if(1 == $Lead->priority ) <span class="badge badge-danger">{{ __('general_content.burning_trans_key') }}</span>@endif
191-
@if(2 == $Lead->priority ) <span class="badge badge-warning">{{ __('general_content.hot_trans_key') }}</span>@endif
192-
@if(3 == $Lead->priority ) <span class="badge badge-primary">{{ __('general_content.lukewarm_trans_key') }}</span>@endif
193-
@if(4 == $Lead->priority ) <span class="badge badge-success">{{ __('general_content.cold_trans_key') }}</span>@endif
194-
</td>
195-
<td>{{ $Lead->campaign }}</td>
196-
<td>
197-
@if(1 == $Lead->statu ) <span class="badge badge-info">{{ __('general_content.new_trans_key') }}</span>@endif
198-
@if(2 == $Lead->statu ) <span class="badge badge-warning">{{ __('general_content.assigned_trans_key') }}</span>@endif
199-
@if(3 == $Lead->statu ) <span class="badge badge-primary">{{ __('general_content.in_progress_trans_key') }}</span>@endif
200-
@if(4 == $Lead->statu ) <span class="badge badge-success">{{ __('general_content.converted_trans_key') }}</span>@endif
201-
@if(5 == $Lead->statu ) <span class="badge badge-danger">{{ __('general_content.lost_trans_key') }}</span>@endif
202-
</td>
203-
<td>
204-
<x-ButtonTextView route="{{ route('leads.show', ['id' => $Lead->id])}}" />
205-
</td>
206-
</tr>
207-
@empty
208-
<x-EmptyDataLine col="10" text=" {{ __('general_content.no_data_trans_key') }}" />
209-
@endforelse
210-
</tbody>
211-
<tfoot>
212-
<tr>
213-
<th></th>
214-
<th>{{__('general_content.customer_trans_key') }}</th>
215-
<th>{{ __('general_content.contact_name_trans_key') }}</th>
216-
<th>{{ __('general_content.adress_name_trans_key') }}</th>
217-
<th>{{ __('general_content.user_trans_key') }}</th>
218-
<th>{{ __('general_content.source_trans_key') }}</th>
219-
<th>{{ __('general_content.priority_trans_key') }}</th>
220-
<th>{{ __('general_content.campaign_trans_key') }}</th>
221-
<th>{{__('general_content.status_trans_key') }}</th>
222-
<th>{{__('general_content.action_trans_key') }}</th>
223-
</tr>
224-
</tfoot>
225-
</table>
226-
<!-- /.row -->
188+
<div class="card">
189+
<div class="table-responsive p-0">
190+
<table class="table table-hover">
191+
<thead>
192+
<tr>
193+
<th></th>
194+
<th>{{__('general_content.customer_trans_key') }}</th>
195+
<th>{{ __('general_content.contact_name_trans_key') }}</th>
196+
<th>{{ __('general_content.adress_name_trans_key') }}</th>
197+
<th>{{ __('general_content.user_trans_key') }}</th>
198+
<th>{{ __('general_content.source_trans_key') }}</th>
199+
<th>
200+
<a class="btn btn-secondary" wire:click.prevent="sortBy('priority')" role="button" href="#">{{ __('general_content.priority_trans_key') }} @include('include.sort-icon', ['field' => 'priority'])</a>
201+
</th>
202+
<th>{{ __('general_content.campaign_trans_key') }}</th>
203+
<th>
204+
<a class="btn btn-secondary" wire:click.prevent="sortBy('statu')" role="button" href="#">{{ __('general_content.status_trans_key') }} @include('include.sort-icon', ['field' => 'statu'])</a>
205+
</th>
206+
<th>
207+
<a class="btn btn-secondary" wire:click.prevent="sortBy('created_at')" role="button" href="#">{{__('general_content.created_at_trans_key') }}@include('include.sort-icon', ['field' => 'created_at'])</a>
208+
</th>
209+
<th>{{__('general_content.action_trans_key') }}</th>
210+
</tr>
211+
</thead>
212+
<tbody>
213+
@forelse ($Leadslist as $Lead)
214+
<tr>
215+
<td>#{{ $Lead->id }}</td>
216+
<td><x-CompanieButton id="{{ $Lead->companies_id }}" label="{{ $Lead->companie['label'] }}" /></td>
217+
<td>{{ $Lead->companie['first_name'] }} {{ $Lead->contact['name'] }}</td>
218+
<td>{{ $Lead->adresse['adress'] }} {{ $Lead->adresse['zipcode'] }} {{ $Lead->adresse['city'] }}</td>
219+
<td><img src="{{ Avatar::create($Lead->UserManagement['name'])->toBase64() }}" /></td>
220+
<td>{{ $Lead->source }}</td>
221+
<td>
222+
@if(1 == $Lead->priority ) <span class="badge badge-danger">{{ __('general_content.burning_trans_key') }}</span>@endif
223+
@if(2 == $Lead->priority ) <span class="badge badge-warning">{{ __('general_content.hot_trans_key') }}</span>@endif
224+
@if(3 == $Lead->priority ) <span class="badge badge-primary">{{ __('general_content.lukewarm_trans_key') }}</span>@endif
225+
@if(4 == $Lead->priority ) <span class="badge badge-success">{{ __('general_content.cold_trans_key') }}</span>@endif
226+
</td>
227+
<td>{{ $Lead->campaign }}</td>
228+
<td>
229+
@if(1 == $Lead->statu ) <span class="badge badge-info">{{ __('general_content.new_trans_key') }}</span>@endif
230+
@if(2 == $Lead->statu ) <span class="badge badge-warning">{{ __('general_content.assigned_trans_key') }}</span>@endif
231+
@if(3 == $Lead->statu ) <span class="badge badge-primary">{{ __('general_content.in_progress_trans_key') }}</span>@endif
232+
@if(4 == $Lead->statu ) <span class="badge badge-success">{{ __('general_content.converted_trans_key') }}</span>@endif
233+
@if(5 == $Lead->statu ) <span class="badge badge-danger">{{ __('general_content.lost_trans_key') }}</span>@endif
234+
</td>
235+
<td>{{ $Lead->GetPrettyCreatedAttribute() }}</td>
236+
<td>
237+
<x-ButtonTextView route="{{ route('leads.show', ['id' => $Lead->id])}}" />
238+
</td>
239+
</tr>
240+
@empty
241+
<x-EmptyDataLine col="10" text=" {{ __('general_content.no_data_trans_key') }}" />
242+
@endforelse
243+
</tbody>
244+
<tfoot>
245+
<tr>
246+
<th></th>
247+
<th>{{__('general_content.customer_trans_key') }}</th>
248+
<th>{{ __('general_content.contact_name_trans_key') }}</th>
249+
<th>{{ __('general_content.adress_name_trans_key') }}</th>
250+
<th>{{ __('general_content.user_trans_key') }}</th>
251+
<th>{{ __('general_content.source_trans_key') }}</th>
252+
<th>{{ __('general_content.priority_trans_key') }}</th>
253+
<th>{{ __('general_content.campaign_trans_key') }}</th>
254+
<th>{{__('general_content.status_trans_key') }}</th>
255+
<th>{{__('general_content.created_at_trans_key') }}</th>
256+
<th>{{__('general_content.action_trans_key') }}</th>
257+
</tr>
258+
</tfoot>
259+
</table>
260+
<!-- /.row -->
261+
</div>
262+
<!-- /.card -->
227263
</div>
228-
<!-- /.card -->
229-
</div>
230264
@else
231265
<!-- Vue en cartes -->
232266
<div class="row">

0 commit comments

Comments
 (0)