From e4540f9d88a01f4d55e477d80f48ab7d148fd609 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Fri, 20 Feb 2026 11:38:06 +0100 Subject: [PATCH] fix: exclude cancelled orders from dashboard statistics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ``scopeNotCancelled`` scope on ``Order`` filters out orders with status 4 (Annulé). All ``OrderMetrics`` methods now chain ``notCancelled()`` so that dashboard counts and totals ignore cancelled orders. --- app/Models/Shop/Order.php | 5 +++++ app/Repositories/Shop/OrderMetrics.php | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/Models/Shop/Order.php b/app/Models/Shop/Order.php index 366a6b35..1561fe16 100644 --- a/app/Models/Shop/Order.php +++ b/app/Models/Shop/Order.php @@ -92,6 +92,11 @@ class Order extends Model return $query->byStatus(3); } + public function scopeNotCancelled($query) + { + return $query->where('status', '!=', 4); + } + public function scopeByStatus($query, $status) { return $query->where('status', $status); diff --git a/app/Repositories/Shop/OrderMetrics.php b/app/Repositories/Shop/OrderMetrics.php index d003f9cb..2f7df6b6 100644 --- a/app/Repositories/Shop/OrderMetrics.php +++ b/app/Repositories/Shop/OrderMetrics.php @@ -48,36 +48,36 @@ class OrderMetrics public static function countOfToday() { - return Order::ofToday()->count(); + return Order::notCancelled()->ofToday()->count(); } public static function countOfLastWeek() { - return Order::ofLastWeek()->count(); + return Order::notCancelled()->ofLastWeek()->count(); } public static function countOfLastMonth() { - return Order::ofLastMonth()->count(); + return Order::notCancelled()->ofLastMonth()->count(); } public static function getTotalOfToday() { - return Order::ofToday()->sum('total_taxed'); + return Order::notCancelled()->ofToday()->sum('total_taxed'); } public static function getTotalOfLastWeek() { - return Order::ofLastWeek()->sum('total_taxed'); + return Order::notCancelled()->ofLastWeek()->sum('total_taxed'); } public static function getTotalOfLastMonth() { - return Order::ofLastMonth()->sum('total_taxed'); + return Order::notCancelled()->ofLastMonth()->sum('total_taxed'); } public static function getModel() { - return Order::query(); + return Order::notCancelled(); } }