Skip to content

Commit 23b5579

Browse files
committed
1 parent 8dd387c commit 23b5579

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

app/Http/Controllers/Workflow/OrdersController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function index()
5252
$lateOrdersCount = $this->orderKPIService->getLateOrdersCount();
5353
$remainingDeliveryOrder = $this->orderKPIService->getOrderMonthlyRemainingToDelivery(now()->month, $CurentYear);
5454
$remainingInvoiceOrder = $this->orderKPIService->getOrderMonthlyRemainingToInvoice();
55+
$serviceRate = $this->orderKPIService->getServiceRate();
5556
$data['ordersDataRate']= $this->orderKPIService->getOrdersDataRate();
5657
$data['orderMonthlyRecap'] = $this->orderKPIService->getOrderMonthlyRecap($CurentYear);
5758
$data['orderMonthlyRecapPreviousYear'] = $this->orderKPIService->getOrderMonthlyRecapPreviousYear($CurentYear);
@@ -63,6 +64,7 @@ public function index()
6364
'lateOrdersCount',
6465
'remainingDeliveryOrder',
6566
'remainingInvoiceOrder',
67+
'serviceRate',
6668
'data',
6769
));
6870
}

app/Services/OrderKPIService.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,29 @@ public function getTopCustomersByOrderVolume($limit = 5)
267267
}
268268

269269
/**
270-
* Get the number of pending orders for the current year.
270+
* Calculate the Service Rate.
271271
*
272-
* An order is pending if it is not fully delivered and the remaining quantity to be delivered is > 0.
272+
* The Service Rate is calculated by dividing the number of requests (order lines)
273+
* fulfilled on time (those with a delivery date less than or equal to the
274+
* expected date) by the total number of requests, then multiplying the result by 100
273275
*
274-
* @return int The number of pending orders.
276+
* @return float Service Rate as a percentage
275277
*/
276-
public function getPendingOrdersCount()
278+
public function getServiceRate()
277279
{
278-
return Orders::whereYear('created_at', now()->year)->where('statu', '!=', 3)->count();
279-
}
280+
$totalOrderLines = OrderLines::where('delivery_status', 3)->count();
281+
282+
$onTimeDeliveries = OrderLines::where('delivery_status', 3)
283+
->whereHas('DeliveryLines', function ($query) {
284+
$query->whereColumn('delivery_lines.created_at', '<=', 'order_lines.delivery_date');
285+
})->count();
286+
287+
if ($totalOrderLines === 0) {
288+
return 0; // Éviter la division par zéro
289+
}
290+
291+
$serviceRate = round(($onTimeDeliveries / $totalOrderLines) * 100,2);
280292

293+
return $serviceRate;
294+
}
281295
}

resources/lang/en/general_content.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@
595595
'delivered_month_in_progress_trans_key' => 'Total Delivered for the month',
596596
'remaining_month_trans_key' => 'Total remaining to deliver',
597597
'remaining_invoice_month_trans_key' => 'Total remaining to invoice',
598+
'service_rate_trans_key' => 'Service rate',
598599
'niko_niko_team_trans_key' => 'Niko Niko - Team Moods Today',
599600
'no_niko_niko_team_trans_key' => 'No team mood today',
600601

resources/lang/fr/general_content.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@
595595
'delivered_month_in_progress_trans_key' => 'Total livré du mois',
596596
'remaining_month_trans_key' => 'Total restant à livrer',
597597
'remaining_invoice_month_trans_key' => 'Total restant à facturer',
598+
'service_rate_trans_key' => 'Taux de service',
598599
'niko_niko_team_trans_key' => 'Niko Niko - Humeur de l\'équipe aujourd\'hui',
599600
'no_niko_niko_team_trans_key' => 'Aucune humeur aujourd\'hui',
600601

resources/views/workflow/orders-index.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
icon="icon fas fa-info"
4343
theme="warning" />
4444
<x-adminlte-small-box title="{{ $lateOrdersCount }}" text="{{ __('general_content.late_orders_trans_key') }}" icon="fas fa-exclamation-triangle" theme="orange"/>
45+
<x-adminlte-small-box
46+
title="{{ $serviceRate }}%"
47+
text="{{ __('general_content.service_rate_trans_key') }}"
48+
icon="fas fa-chart-line"
49+
theme="primary"
50+
/>
4551
</div>
4652
<div class="col-lg-8 col-8">
4753
<!-- CHART: TOTAL OVERVIEW -->

0 commit comments

Comments
 (0)