fix editing orders

This commit is contained in:
Ludovic CANDELLIER
2022-11-19 23:43:12 +01:00
parent caee665758
commit 73763bb146
19 changed files with 314 additions and 174 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Repositories\Shop;
use Carbon\Carbon;
use App\Models\Shop\Order;
class Orders
@@ -24,9 +25,36 @@ class Orders
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
}
public static function count()
{
return Order::count();
}
public static function countByMonth()
{
$start = Carbon::now()->startOfMonth();
return Order::where('created_at', '>', $start)->count();
}
public static function sumByMonth()
{
$start = Carbon::now()->startOfMonth();
return Order::where('created_at', '>', $start)->sum('total_shipped');
}
public static function avgByMonth()
{
return self::countByMonth() ? round(self::sumByMonth() / self::countByMonth(), 2) : 0;
}
public static function edit($id)
{
return Orders::get($id, ['customer', 'address', 'delivery', 'detail']);
return [
'order' => self::get($id, ['customer', 'address', 'detail']),
'statuses' => self::statuses(),
'payment_types' => self::payment_types(),
'sale_channels' => SaleChannels::getOptions(),
];
}
public static function get($id, $relations = false)
@@ -65,10 +93,16 @@ class Orders
public static function statuses()
{
return [
'En attente',
'Expédié',
'Livré',
];
return ['En attente', 'Expédié', 'Livré'];
}
public static function getPaymentType($id)
{
return self::payment_types()[$id] ?? false;
}
public static function payment_types()
{
return ['', 'CARTE BANCAIRE', 'CHEQUE', 'VIREMENT BANCAIRE'];
}
}