Fix on invoices, add delivery reference, wip on dashboard concurrency requests designed on template
This commit is contained in:
@@ -4,11 +4,15 @@ namespace App\Repositories\Shop;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Shop\Order;
|
||||
use App\Repositories\Core\DateStats;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Orders
|
||||
{
|
||||
|
||||
use DateStats;
|
||||
|
||||
public static function saveOrder($data)
|
||||
{
|
||||
$data += $data['basket'];
|
||||
@@ -31,21 +35,29 @@ class Orders
|
||||
return Order::count();
|
||||
}
|
||||
|
||||
public static function countByMonth()
|
||||
public static function countInPreparationLess24H()
|
||||
{
|
||||
$start = Carbon::now()->startOfMonth();
|
||||
return Order::where('created_at', '>', $start)->count();
|
||||
$start = Carbon::now()->subHours(24);
|
||||
$end = Carbon::now();
|
||||
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
|
||||
}
|
||||
|
||||
public static function sumByMonth()
|
||||
public static function countInPreparationLess48H()
|
||||
{
|
||||
$start = Carbon::now()->startOfMonth();
|
||||
return Order::where('created_at', '>', $start)->sum('total_shipped');
|
||||
$start = Carbon::now()->subHours(48);
|
||||
$end = Carbon::now();
|
||||
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
|
||||
}
|
||||
|
||||
public static function avgByMonth()
|
||||
public static function countInPreparationMore48H()
|
||||
{
|
||||
return self::countByMonth() ? round(self::sumByMonth() / self::countByMonth(), 2) : 0;
|
||||
$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 edit($id)
|
||||
@@ -53,7 +65,7 @@ class Orders
|
||||
return [
|
||||
'order' => self::get($id, ['customer', 'address', 'detail']),
|
||||
'statuses' => self::statuses(),
|
||||
'payment_types' => self::payment_types(),
|
||||
'payment_types' => self::paymentTypes(),
|
||||
'sale_channels' => SaleChannels::getOptions(),
|
||||
];
|
||||
}
|
||||
@@ -100,17 +112,23 @@ class Orders
|
||||
return self::statuses()[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function getStatusByName($name)
|
||||
{
|
||||
$data = array_flip(self::statuses());
|
||||
return $data[$name] ?? '';
|
||||
}
|
||||
|
||||
public static function statuses()
|
||||
{
|
||||
return ['En attente', 'Expédié', 'Livré'];
|
||||
return ['En attente', 'Préparation', 'Expédié', 'Livré'];
|
||||
}
|
||||
|
||||
public static function getPaymentType($id)
|
||||
{
|
||||
return self::payment_types()[$id] ?? false;
|
||||
return self::paymentTypes()[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function payment_types()
|
||||
public static function paymentTypes()
|
||||
{
|
||||
return ['', 'CARTE BANCAIRE', 'CHEQUE', 'VIREMENT BANCAIRE'];
|
||||
}
|
||||
@@ -118,8 +136,12 @@ class Orders
|
||||
public static function getNewRef()
|
||||
{
|
||||
$ref = date('ym') . '00000';
|
||||
$last_ref = Order::orderBy('ref', 'desc')->where('ref', '>', $ref)->first();
|
||||
$last_ref = Order::orderBy('id', 'desc')->first();
|
||||
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Order::query();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user