Files
opensem/app/Repositories/Shop/OrderMetrics.php
Ludovic CANDELLIER b8c31f6049 fix shipping
2023-07-16 17:54:44 +02:00

46 lines
1.0 KiB
PHP

<?php
namespace App\Repositories\Shop;
use App\Models\Shop\Order;
use App\Repositories\Core\DateStats;
use Carbon\Carbon;
class OrderMetrics
{
use DateStats;
public static function countInPreparationLess24H()
{
$start = Carbon::now()->subHours(24);
$end = Carbon::now();
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
}
public static function countInPreparationLess48H()
{
$start = Carbon::now()->subHours(48);
$end = Carbon::now();
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
}
public static function countInPreparationMore48H()
{
$start = Carbon::now()->subHours(48);
return Order::preparation()->where('updated_at', '>', $start)->count();
}
public static function getTotalByPeriod($start, $end)
{
return self::sumByPeriod($start, $end, 'total_shipped');
}
public static function getModel()
{
return Order::query();
}
}