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:
@@ -92,6 +92,11 @@ class Order extends Model
|
|||||||
return $query->byStatus(3);
|
return $query->byStatus(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeNotCancelled($query)
|
||||||
|
{
|
||||||
|
return $query->where('status', '!=', 4);
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeByStatus($query, $status)
|
public function scopeByStatus($query, $status)
|
||||||
{
|
{
|
||||||
return $query->where('status', $status);
|
return $query->where('status', $status);
|
||||||
|
|||||||
@@ -48,36 +48,36 @@ class OrderMetrics
|
|||||||
|
|
||||||
public static function countOfToday()
|
public static function countOfToday()
|
||||||
{
|
{
|
||||||
return Order::ofToday()->count();
|
return Order::notCancelled()->ofToday()->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function countOfLastWeek()
|
public static function countOfLastWeek()
|
||||||
{
|
{
|
||||||
return Order::ofLastWeek()->count();
|
return Order::notCancelled()->ofLastWeek()->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function countOfLastMonth()
|
public static function countOfLastMonth()
|
||||||
{
|
{
|
||||||
return Order::ofLastMonth()->count();
|
return Order::notCancelled()->ofLastMonth()->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getTotalOfToday()
|
public static function getTotalOfToday()
|
||||||
{
|
{
|
||||||
return Order::ofToday()->sum('total_taxed');
|
return Order::notCancelled()->ofToday()->sum('total_taxed');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getTotalOfLastWeek()
|
public static function getTotalOfLastWeek()
|
||||||
{
|
{
|
||||||
return Order::ofLastWeek()->sum('total_taxed');
|
return Order::notCancelled()->ofLastWeek()->sum('total_taxed');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getTotalOfLastMonth()
|
public static function getTotalOfLastMonth()
|
||||||
{
|
{
|
||||||
return Order::ofLastMonth()->sum('total_taxed');
|
return Order::notCancelled()->ofLastMonth()->sum('total_taxed');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getModel()
|
public static function getModel()
|
||||||
{
|
{
|
||||||
return Order::query();
|
return Order::notCancelled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user