add new metrics, graph metrics, prepare basket to storage
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
43
app/Repositories/Shop/BasketStores.php
Normal file
43
app/Repositories/Shop/BasketStores.php
Normal 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
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user