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

@@ -5,6 +5,7 @@ namespace App\Datatables\Admin\Shop;
use App\Datatables\ParentDataTable as DataTable;
use App\Models\Shop\Article;
use App\Repositories\Shop\Articles;
use App\Repositories\Shop\ArticleImages;
use App\Repositories\Shop\Tags;
use Yajra\DataTables\Html\Column;
@@ -71,7 +72,7 @@ class ArticlesDataTable extends DataTable
]);
})
->editColumn('thumb', function (Article $article) {
$image = Articles::getFullImageByArticle($article);
$image = ArticleImages::getFullImageByArticle($article);
return Articles::getThumb($image, false);
})
@@ -87,7 +88,7 @@ class ArticlesDataTable extends DataTable
return $html;
})
->editColumn('images_count2', function (Article $article) {
return Articles::countFullImagesByArticle($article);
return ArticleImages::countFullImagesByArticle($article);
})
->rawColumns(['tags2', 'thumb', 'action']);

View File

@@ -4,12 +4,13 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use LaracraftTech\LaravelDateScopes\DateScopes;
use Venturecraft\Revisionable\RevisionableTrait;
use Znck\Eloquent\Traits\BelongsToThrough;
class Invoice extends Model
{
use BelongsToThrough, RevisionableTrait, SoftDeletes;
use BelongsToThrough, DateScopes, RevisionableTrait, SoftDeletes;
protected $guarded = ['id'];
@@ -49,8 +50,8 @@ class Invoice extends Model
return $query->where('id', $id);
}
public function scopeByPeriod($query, $start, $end)
public function scopeByPeriod($query, $start, $end, $field = 'created_at')
{
return $query->whereBetween('created_at', [$start, $end]);
return $query->whereBetween($field, [$start, $end]);
}
}

View File

@@ -4,11 +4,12 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use LaracraftTech\LaravelDateScopes\DateScopes;
use Venturecraft\Revisionable\RevisionableTrait;
class Order extends Model
{
use RevisionableTrait, SoftDeletes;
use DateScopes, RevisionableTrait, SoftDeletes;
protected $guarded = ['id'];

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;