add metrics

This commit is contained in:
ludo
2024-01-30 23:24:00 +01:00
parent 1bc9bf9fe9
commit 8eb3104b2a
12 changed files with 226 additions and 70 deletions

View File

@@ -3,10 +3,13 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Basket;
use App\Traits\Model\Basic;
use Darryldecode\Cart\CartCollection;
class BasketStores
{
use Basic;
public function has($key)
{
return Basket::find($key);
@@ -14,30 +17,29 @@ class BasketStores
public function get($key)
{
if($this->has($key))
{
if($this->has($key)) {
return new CartCollection(Basket::find($key)->cart_data);
}
else
{
} else {
return [];
}
}
public function put($key, $value)
{
if($row = Basket::find($key))
{
if($row = Basket::find($key)) {
// update
$row->cart_data = $value;
$row->save();
}
else
{
} else {
Basket::create([
'id' => $key,
'cart_data' => $value
]);
}
}
public static function getModel()
{
return Basket::query();
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\Customer;
use App\Repositories\Core\DateStats;
use App\Traits\Model\Basic;
class CustomerMetrics
{
use Basic, DateStats;
public static function countOfToday()
{
return Customer::ofToday()->count();
}
public static function countOfLastWeek()
{
return Customer::ofLastWeek()->count();
}
public static function countOfLastMonth()
{
return Customer::ofLastMonth()->count();
}
public static function getModel()
{
return Customer::query();
}
}

View File

@@ -10,12 +10,15 @@ class Dashboards
'orders_count' => OrderMetrics::countByPeriod($start, $end),
'orders_sum' => OrderMetrics::sumByPeriod($start, $end, 'total_shipped'),
'orders_avg' => OrderMetrics::avgByPeriod($start, $end, 'total_shipped'),
'offers_count' => Offers::count(),
'clients_count' => Customers::count(),
'countClients' => CustomerMetrics::countByPeriod($start, $end),
'waitingOrders' => OrderMetrics::countWaiting(),
'preparationLess24H' => OrderMetrics::countPreparationLess24h(),
'preparationLess48H' => OrderMetrics::countPreparationLess48h(),
'preparationMore48H' => OrderMetrics::countPreparationMore48h(),
'offers_count' => Offers::count(),
'stocksWarning' => OfferStocks::countAlerts(),
'countCustomers' => Customers::count(),
'lastOrders' => Orders::getLast(),
];
}
}

View File

@@ -20,6 +20,11 @@ class OrderMetrics
return self::sumMonthly('total_taxed');
}
public static function countWaiting()
{
return Order::waiting()->count();
}
public static function countPreparationLess24h()
{
$date = now()->subHours(24);

View File

@@ -14,6 +14,11 @@ class Orders
{
use Basic, DateStats;
public static function getLast($nb = 10)
{
return Order::with('customer')->orderBy('id', 'DESC')->take($nb)->get();
}
public static function getPdfByUUID($uuid)
{
return self::getPdf(self::getIdByUUID($uuid), 'commande-' . $uuid . '.pdf');