Fix on invoices, add delivery reference, wip on dashboard concurrency requests designed on template

This commit is contained in:
Ludovic CANDELLIER
2023-02-17 00:05:03 +01:00
parent 878ec7a8f2
commit 8e571de523
26 changed files with 555 additions and 130 deletions

View File

@@ -12,6 +12,11 @@ use App\Models\Shop\Customer;
class Customers
{
public static function count()
{
return Customer::count();
}
public static function editProfile($id = false)
{
$id = $id ? $id : self::getId();

View File

@@ -7,12 +7,17 @@ use App\Models\Shop\Homepage;
class Dashboards
{
public static function getStats()
public static function getStats($start, $end)
{
return [
'orders_count' => Orders::countByMonth(),
'orders_sum' => Orders::sumByMonth(),
'orders_avg' => Orders::avgByMonth(),
'orders_count' => Orders::countByPeriod($start, $end),
'orders_sum' => Orders::sumByPeriod($start, $end, 'total_shipped'),
'orders_avg' => Orders::avgByPeriod($start, $end, 'total_shipped'),
'offers_count' => Offers::count(),
'clients_count' => Customers::count(),
'preparationLess24H' => Orders::countInPreparationLess24H(),
'preparationLess48H' => Orders::countInPreparationLess48H(),
'preparationMore48H' => Orders::countInPreparationMore48H(),
];
}
}

View File

@@ -61,7 +61,7 @@ class Invoices
public static function getNewRef()
{
$ref = date('ym') . '00000';
$last_ref = Invoice::orderBy('ref', 'desc')->where('ref', '>', $ref)->first();
$last_ref = Invoice::orderBy('id', 'desc')->first();
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
}
@@ -72,6 +72,6 @@ class Invoices
public static function statuses()
{
return ['En attente', 'Non soldée', 'Soldée'];
return ['En attente', 'Paiement partiel', 'Soldée', 'Paiement rejeté'];
}
}

View File

@@ -7,6 +7,11 @@ use App\Repositories\Core\User\ShopCart;
class Offers
{
public static function count()
{
return Offer::count();
}
public static function getFull($id, $sale_channel_id = false)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();

View File

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