fix articles datatables, enhance statistics

This commit is contained in:
ludo
2024-01-28 19:56:13 +01:00
parent c5f06a608c
commit 36459de793
7 changed files with 81 additions and 21 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Repositories\Core;
use Carbon\Carbon;
use function League\Period\interval_after;
use League\Period\Period;
class DateRange
@@ -201,9 +200,9 @@ class DateRange
public static function getPeriods($begin, $end, $duration)
{
$range = [];
$period = new Period($begin, $end);
foreach ($period->getDatePeriod($duration) as $day) {
$range[] = interval_after($day, $duration);
$interval = Period::fromDate($begin, $end);
foreach ($interval->splitForward($duration) as $day) {
$range[] = $day;
}
return $range;
@@ -222,8 +221,8 @@ class DateRange
public static function periodToCarbon($period)
{
return [
'start' => self::DatePointToCarbon($period->getStartDate()),
'end' => self::DatePointToCarbon($period->getEndDate()),
'start' => self::DatePointToCarbon($period->startDate),
'end' => self::DatePointToCarbon($period->endDate),
];
}

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\Order;
use App\Repositories\Core\DateStats;
class OrderStatistics
{
use DateStats;
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');
}
}

View File

@@ -63,7 +63,14 @@ class Orders
$data += self::getSummaryOfBasket($basket);
$order = self::store($data);
$detail = $order ? OrderDetails::saveBasket($order->id, $basket['detail']) : false;
$data = Arr::except($data, ['comment', 'agree', 'delivery_address_id', 'sale_channel_id', 'delivery_id', 'delivery_type_id']);
$data = Arr::except($data, [
'comment',
'agree',
'delivery_address_id',
'sale_channel_id',
'delivery_id',
'delivery_type_id',
]);
$invoice = $detail ? Invoices::saveInvoice($order->id, $data + $invoice) : false;
return $invoice ? $order : false;