add new metrics, graph metrics, prepare basket to storage

This commit is contained in:
ludo
2024-01-29 23:44:49 +01:00
parent 72f5da4555
commit 84bc5f2e67
12 changed files with 219 additions and 214 deletions

View File

@@ -79,7 +79,7 @@ class DateRange
public static function getPeriodsLastMonth($nb = 1, $withActual = true)
{
$end = $withActual ? Carbon::now()->endOfMonth() : self::lastMonth();
$begin = $nb === 1 ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonths($nb - 1);
$begin = $nb === 1 ? $end->copy()->startOfMonth() : $end->copy()->subMonths($nb)->startOfMonth();
return self::getPeriodsByMonth($begin, $end);
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\Basket;
use Darryldecode\Cart\CartCollection;
class BasketStores
{
public function has($key)
{
return Basket::find($key);
}
public function get($key)
{
if($this->has($key))
{
return new CartCollection(Basket::find($key)->cart_data);
}
else
{
return [];
}
}
public function put($key, $value)
{
if($row = Basket::find($key))
{
// update
$row->cart_data = $value;
$row->save();
}
else
{
Basket::create([
'id' => $key,
'cart_data' => $value
]);
}
}
}

View File

@@ -12,9 +12,10 @@ class Dashboards
'orders_avg' => OrderMetrics::avgByPeriod($start, $end, 'total_shipped'),
'offers_count' => Offers::count(),
'clients_count' => Customers::count(),
'preparationLess24H' => OrderMetrics::countInPreparationLess24H(),
'preparationLess48H' => OrderMetrics::countInPreparationLess48H(),
'preparationMore48H' => OrderMetrics::countInPreparationMore48H(),
'preparationLess24H' => OrderMetrics::countPreparationLess24h(),
'preparationLess48H' => OrderMetrics::countPreparationLess48h(),
'preparationMore48H' => OrderMetrics::countPreparationMore48h(),
'stocksWarning' => OfferStocks::countAlerts(),
];
}
}

View File

@@ -22,4 +22,14 @@ class OfferStocks
{
return Offers::getField($id, 'stock_current');
}
public static function getAlerts()
{
return Offer::active()->where('stock_current', '<', 15)->get();
}
public static function countAlerts()
{
return Offer::active()->where('stock_current', '<', 15)->count();
}
}

View File

@@ -4,38 +4,71 @@ namespace App\Repositories\Shop;
use App\Models\Shop\Order;
use App\Repositories\Core\DateStats;
use Carbon\Carbon;
use App\Traits\Model\Basic;
class OrderMetrics
{
use DateStats;
use Basic, DateStats;
public static function countInPreparationLess24H()
public static function getTotalDaily()
{
$start = Carbon::now()->subHours(24);
$end = Carbon::now();
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
return self::sumDaily('total_taxed');
}
public static function countInPreparationLess48H()
public static function getTotalMonthly()
{
$start = Carbon::now()->subHours(48);
$end = Carbon::now();
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
return self::sumMonthly('total_taxed');
}
public static function countInPreparationMore48H()
public static function countPreparationLess24h()
{
$start = Carbon::now()->subHours(48);
$date = now()->subHours(24);
return Order::preparation()->where('updated_at', '>', $start)->count();
return Order::Preparation()->where('updated_at', '>', $date)->count();
}
public static function getTotalByPeriod($start, $end)
public static function countPreparationLess48h()
{
return self::sumByPeriod($start, $end, 'total_shipped');
$date = now()->subHours(48);
return Order::Preparation()->where('updated_at', '>', $date)->count();
}
public static function countPreparationMore48h()
{
$date = now()->subHours(48);
return Order::Preparation()->where('updated_at', '<', $date)->count();
}
public static function countOfToday()
{
return Order::ofToday()->count();
}
public static function countOfLastWeek()
{
return Order::ofLastWeek()->count();
}
public static function countOfLastMonth()
{
return Order::ofLastMonth()->count();
}
public static function getTotalOfToday()
{
return Order::ofToday()->sum('total_taxed');
}
public static function getTotalOfLastWeek()
{
return Order::ofLastWeek()->sum('total_taxed');
}
public static function getTotalOfLastMonth()
{
return Order::ofLastMonth()->sum('total_taxed');
}
public static function getModel()

View File

@@ -1,68 +0,0 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\Order;
use App\Repositories\Core\DateStats;
use App\Traits\Model\Basic;
class OrderStatistics
{
use Basic, DateStats;
public static function getTotalDaily()
{
return self::sumDaily('total_taxed');
}
public static function getTotalMonthly()
{
return self::sumMonthly('total_taxed');
}
public static function countPreparationLess2Days()
{
return Order::ofLastHours(48)->Preparation()->count();
}
public static function countPreparationMore2Days()
{
$date = now()->subHours(48);
return Order::Preparation()->where('updated_at', '<', $date)->count();
}
public static function countOfToday()
{
return Order::ofToday()->count();
}
public static function countOfLastWeek()
{
return Order::ofLastWeek()->count();
}
public static function countOfLastMonth()
{
return Order::ofLastMonth()->count();
}
public static function getTotalOfToday()
{
return Order::ofToday()->sum('total_taxed');
}
public static function getTotalOfLastWeek()
{
return Order::ofLastWeek()->sum('total_taxed');
}
public static function getTotalOfLastMonth()
{
return Order::ofLastMonth()->sum('total_taxed');
}
public static function getModel()
{
return Order::query();
}
}