fix: exclude cancelled orders from dashboard statistics

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.
This commit is contained in:
Valentin Lab
2026-02-20 11:38:06 +01:00
parent 936c9473a7
commit e4540f9d88
2 changed files with 12 additions and 7 deletions

View File

@@ -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);

View File

@@ -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();
}
}