Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SMEWebify committed Dec 27, 2024
1 parent ebd6400 commit 2070846
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 89 deletions.
19 changes: 16 additions & 3 deletions app/Http/Controllers/Workflow/LeadsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Str;
use App\Models\Workflow\Leads;
use App\Services\LeadsKPIService;
use App\Traits\NextPreviousTrait;
use App\Services\SelectDataService;
use App\Http\Controllers\Controller;
Expand All @@ -16,18 +17,30 @@ class LeadsController extends Controller
use NextPreviousTrait;

protected $SelectDataService;
protected $leadsKPIService;

public function __construct(SelectDataService $SelectDataService)
public function __construct(SelectDataService $SelectDataService,
LeadsKPIService $LeadsKPIService)
{
$this->SelectDataService = $SelectDataService;
$this->SelectDataService = $SelectDataService;
$this->leadsKPIService = $LeadsKPIService;
}

/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
return view('workflow/leads-index');
// Using the OpportunitiesKPIService to retrieve KPI data
$data['leadsCountRate'] = $this->leadsKPIService->getLeadsDataRate();
$leadByCompany = $this->leadsKPIService->getLeadsByCompany();
$leadsCount = $this->leadsKPIService->getLeadsCount();
$leadsCountByUser = $this->leadsKPIService->getLeadsCountByUser();
$leadsCountByPriority = $this->leadsKPIService->getLeadsCountByPriority();
return view('workflow/leads-index', array_merge(
compact(
'leadByCompany', 'leadsCount', 'leadsCountByUser', 'leadsCountByPriority')
))->with('data', $data);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion app/Livewire/LeadsIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class LeadsIndex extends Component
public $sortField = 'statu'; // default sorting field
public $sortAsc = true; // default sort direction

public $searchIdPriority = '';

private $Leadslist;

public $id;
Expand Down Expand Up @@ -68,7 +70,9 @@ public function render()
->paginate(15);
}
else{
$Leadslist = $this->Leadslist = Leads::orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')
$Leadslist = $this->Leadslist = Leads::where('campaign','like', '%'.$this->search.'%')
->where('priority', 'like', '%'.$this->searchIdPriority.'%')
->orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')
->paginate(15);
}

Expand Down
76 changes: 76 additions & 0 deletions app/Services/LeadsKPIService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace App\Services;

use App\Models\Workflow\Leads;
use Illuminate\Support\Facades\DB;

class LeadsKPIService
{
/**
* Get the rate of leads data grouped by status.
*
* @return \Illuminate\Support\Collection
*/
public function getLeadsDataRate()
{
return DB::table('leads')
->select('statu', DB::raw('count(*) as leadsCountRate'))
->groupBy('statu')
->get();
}

/**
* Get the count of leads grouped by priority.
*
* @return \Illuminate\Support\Collection
*/
public function getLeadsCountByPriority()
{
return Leads::select('priority', DB::raw('count(*) as leadsCount'))
->groupBy('priority')
->get();
}

/**
* Get the count of leads grouped by company.
*
* @return \Illuminate\Support\Collection
*/
public function getLeadsByCompany()
{
return Leads::with('companie')
->select('companies_id', DB::raw('count(*) as count'))
->groupBy('companies_id')
->limit(10)
->get();
}


/**
* Get the total count of leads.
*
* @return int
*/
public function getLeadsCount()
{
return Leads::count();
}


/**
* Get the count of leads by user.
*
* @return \Illuminate\Support\Collection
*/
public function getLeadsCountByUser()
{
return Leads::select('user_id', 'statu', \DB::raw('count(*) as total'))
->with('UserManagement:id,name') // Charge la relation UserManagement avec les champs id et name
->whereIn('statu', [1, 2, 3, 4, 5, 6]) // Statuts allant de 1 à 6
->groupBy('user_id', 'statu')
->get()
->groupBy('user_id');
}

}
1 change: 1 addition & 0 deletions resources/lang/en/general_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@
'leads_trans_key' => 'Leads',
'lead_trans_key' => 'Lead',
'new_leads_trans_key' => 'New Lead',
'list_leads_trans_key' => 'Lead list',

//OPPORTUNITIES
'opportunities_trans_key' => 'Opportunities',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/fr/general_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@
'leads_trans_key' => 'Leads',
'lead_trans_key' => 'Lead',
'new_leads_trans_key' => 'Nouveau Lead',
'list_leads_trans_key' => 'Liste des Lead',

//OPPORTUNITIES
'opportunities_trans_key' => 'Oportunités',
Expand Down
184 changes: 109 additions & 75 deletions resources/views/livewire/leads-index.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
<div class="card-body">
<!-- View toggle button -->
<div class="mb-3">
<button class="btn btn-primary" wire:click="changeView('table')">
<i class="fas fa-table mr-1"></i> Table
</button>
<button class="btn btn-secondary" wire:click="changeView('cards')">
<i class="fas fa-th-large mr-1"></i> Cards
</button>
<div class="row">
<!-- View toggle button -->
<div class="col-2">
<button class="btn btn-primary" wire:click="changeView('table')">
<i class="fas fa-table mr-1"></i> Table
</button>
<button class="btn btn-secondary" wire:click="changeView('cards')">
<i class="fas fa-th-large mr-1"></i> Cards
</button>
</div>
<div class="col-6">
@include('include.search-card')
</div>
<div class="col-2">
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-list"></i></span>
</div>
<select class="form-control" name="searchIdPriority" id="searchIdPriority" wire:model.live="searchIdPriority">
<option value="" selected>{{ __('general_content.select_statu_trans_key') }}</option>
<option value="1">{{ __('general_content.burning_trans_key') }}</option>
<option value="2">{{ __('general_content.hot_trans_key') }}</option>
<option value="3">{{ __('general_content.lukewarm_trans_key') }}</option>
<option value="4">{{ __('general_content.cold_trans_key') }}</option>
</select>
</div>
</div>
</div>
<div class="col-2">
<button type="button" class="btn btn-success float-sm-right" data-toggle="modal" data-target="#ModalLead">
{{ __('general_content.new_leads_trans_key')}}
</button>
</div>
</div>

<!-- Modal -->
Expand Down Expand Up @@ -158,75 +185,82 @@
</div>
<!-- End Modal -->
@if($viewType === 'table')
<div class="card">
<div class="table-responsive p-0">
<table class="table table-hover">
<thead>
<tr>
<th></th>
<th>{{__('general_content.customer_trans_key') }}</th>
<th>{{ __('general_content.contact_name_trans_key') }}</th>
<th>{{ __('general_content.adress_name_trans_key') }}</th>
<th>{{ __('general_content.user_trans_key') }}</th>
<th>{{ __('general_content.source_trans_key') }}</th>
<th>{{ __('general_content.priority_trans_key') }}</th>
<th>{{ __('general_content.campaign_trans_key') }}</th>
<th>
<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>
</th>
<th>{{__('general_content.action_trans_key') }}</th>
</tr>
</thead>
<tbody>
@forelse ($Leadslist as $Lead)
<tr>
<td>#{{ $Lead->id }}</td>
<td><x-CompanieButton id="{{ $Lead->companies_id }}" label="{{ $Lead->companie['label'] }}" /></td>
<td>{{ $Lead->companie['first_name'] }} {{ $Lead->contact['name'] }}</td>
<td>{{ $Lead->adresse['adress'] }} {{ $Lead->adresse['zipcode'] }} {{ $Lead->adresse['city'] }}</td>
<td><img src="{{ Avatar::create($Lead->UserManagement['name'])->toBase64() }}" /></td>
<td>{{ $Lead->source }}</td>
<td>
@if(1 == $Lead->priority ) <span class="badge badge-danger">{{ __('general_content.burning_trans_key') }}</span>@endif
@if(2 == $Lead->priority ) <span class="badge badge-warning">{{ __('general_content.hot_trans_key') }}</span>@endif
@if(3 == $Lead->priority ) <span class="badge badge-primary">{{ __('general_content.lukewarm_trans_key') }}</span>@endif
@if(4 == $Lead->priority ) <span class="badge badge-success">{{ __('general_content.cold_trans_key') }}</span>@endif
</td>
<td>{{ $Lead->campaign }}</td>
<td>
@if(1 == $Lead->statu ) <span class="badge badge-info">{{ __('general_content.new_trans_key') }}</span>@endif
@if(2 == $Lead->statu ) <span class="badge badge-warning">{{ __('general_content.assigned_trans_key') }}</span>@endif
@if(3 == $Lead->statu ) <span class="badge badge-primary">{{ __('general_content.in_progress_trans_key') }}</span>@endif
@if(4 == $Lead->statu ) <span class="badge badge-success">{{ __('general_content.converted_trans_key') }}</span>@endif
@if(5 == $Lead->statu ) <span class="badge badge-danger">{{ __('general_content.lost_trans_key') }}</span>@endif
</td>
<td>
<x-ButtonTextView route="{{ route('leads.show', ['id' => $Lead->id])}}" />
</td>
</tr>
@empty
<x-EmptyDataLine col="10" text=" {{ __('general_content.no_data_trans_key') }}" />
@endforelse
</tbody>
<tfoot>
<tr>
<th></th>
<th>{{__('general_content.customer_trans_key') }}</th>
<th>{{ __('general_content.contact_name_trans_key') }}</th>
<th>{{ __('general_content.adress_name_trans_key') }}</th>
<th>{{ __('general_content.user_trans_key') }}</th>
<th>{{ __('general_content.source_trans_key') }}</th>
<th>{{ __('general_content.priority_trans_key') }}</th>
<th>{{ __('general_content.campaign_trans_key') }}</th>
<th>{{__('general_content.status_trans_key') }}</th>
<th>{{__('general_content.action_trans_key') }}</th>
</tr>
</tfoot>
</table>
<!-- /.row -->
<div class="card">
<div class="table-responsive p-0">
<table class="table table-hover">
<thead>
<tr>
<th></th>
<th>{{__('general_content.customer_trans_key') }}</th>
<th>{{ __('general_content.contact_name_trans_key') }}</th>
<th>{{ __('general_content.adress_name_trans_key') }}</th>
<th>{{ __('general_content.user_trans_key') }}</th>
<th>{{ __('general_content.source_trans_key') }}</th>
<th>
<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>
</th>
<th>{{ __('general_content.campaign_trans_key') }}</th>
<th>
<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>
</th>
<th>
<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>
</th>
<th>{{__('general_content.action_trans_key') }}</th>
</tr>
</thead>
<tbody>
@forelse ($Leadslist as $Lead)
<tr>
<td>#{{ $Lead->id }}</td>
<td><x-CompanieButton id="{{ $Lead->companies_id }}" label="{{ $Lead->companie['label'] }}" /></td>
<td>{{ $Lead->companie['first_name'] }} {{ $Lead->contact['name'] }}</td>
<td>{{ $Lead->adresse['adress'] }} {{ $Lead->adresse['zipcode'] }} {{ $Lead->adresse['city'] }}</td>
<td><img src="{{ Avatar::create($Lead->UserManagement['name'])->toBase64() }}" /></td>
<td>{{ $Lead->source }}</td>
<td>
@if(1 == $Lead->priority ) <span class="badge badge-danger">{{ __('general_content.burning_trans_key') }}</span>@endif
@if(2 == $Lead->priority ) <span class="badge badge-warning">{{ __('general_content.hot_trans_key') }}</span>@endif
@if(3 == $Lead->priority ) <span class="badge badge-primary">{{ __('general_content.lukewarm_trans_key') }}</span>@endif
@if(4 == $Lead->priority ) <span class="badge badge-success">{{ __('general_content.cold_trans_key') }}</span>@endif
</td>
<td>{{ $Lead->campaign }}</td>
<td>
@if(1 == $Lead->statu ) <span class="badge badge-info">{{ __('general_content.new_trans_key') }}</span>@endif
@if(2 == $Lead->statu ) <span class="badge badge-warning">{{ __('general_content.assigned_trans_key') }}</span>@endif
@if(3 == $Lead->statu ) <span class="badge badge-primary">{{ __('general_content.in_progress_trans_key') }}</span>@endif
@if(4 == $Lead->statu ) <span class="badge badge-success">{{ __('general_content.converted_trans_key') }}</span>@endif
@if(5 == $Lead->statu ) <span class="badge badge-danger">{{ __('general_content.lost_trans_key') }}</span>@endif
</td>
<td>{{ $Lead->GetPrettyCreatedAttribute() }}</td>
<td>
<x-ButtonTextView route="{{ route('leads.show', ['id' => $Lead->id])}}" />
</td>
</tr>
@empty
<x-EmptyDataLine col="10" text=" {{ __('general_content.no_data_trans_key') }}" />
@endforelse
</tbody>
<tfoot>
<tr>
<th></th>
<th>{{__('general_content.customer_trans_key') }}</th>
<th>{{ __('general_content.contact_name_trans_key') }}</th>
<th>{{ __('general_content.adress_name_trans_key') }}</th>
<th>{{ __('general_content.user_trans_key') }}</th>
<th>{{ __('general_content.source_trans_key') }}</th>
<th>{{ __('general_content.priority_trans_key') }}</th>
<th>{{ __('general_content.campaign_trans_key') }}</th>
<th>{{__('general_content.status_trans_key') }}</th>
<th>{{__('general_content.created_at_trans_key') }}</th>
<th>{{__('general_content.action_trans_key') }}</th>
</tr>
</tfoot>
</table>
<!-- /.row -->
</div>
<!-- /.card -->
</div>
<!-- /.card -->
</div>
@else
<!-- Vue en cartes -->
<div class="row">
Expand Down
Loading

0 comments on commit 2070846

Please sign in to comment.