fix articles datatables, enhance statistics
This commit is contained in:
@@ -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']);
|
||||
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'];
|
||||
|
||||
|
||||
@@ -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),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
52
app/Repositories/Shop/OrderStatistics.php
Normal file
52
app/Repositories/Shop/OrderStatistics.php
Normal 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');
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"license": "proprietary",
|
||||
"require": {
|
||||
"php": "^7.4|^8.0",
|
||||
"akaunting/laravel-apexcharts": "^2.0",
|
||||
"akaunting/laravel-apexcharts": "^3.0",
|
||||
"alexisgeneau/mailvalidate": "dev-master",
|
||||
"arrilot/laravel-widgets": "^3.14",
|
||||
"awobaz/compoships": "^2.2",
|
||||
@@ -37,12 +37,11 @@
|
||||
"hassankhan/config": "^3.1",
|
||||
"htmlmin/htmlmin": "^9.0",
|
||||
"intervention/image": "^2.7",
|
||||
"intervention/imagecache": "^2.6",
|
||||
"jasonlewis/expressive-date": "^1.0",
|
||||
"jenssegers/date": "^4.0",
|
||||
"jeroen-g/blade-macro": "^1.0",
|
||||
"kalnoy/nestedset": "^6.0",
|
||||
"kirschbaum-development/eloquent-power-joins": "^2.7",
|
||||
"kirschbaum-development/eloquent-power-joins": "^3.4",
|
||||
"kmlaravel/laravel-geographical-calculator": "^2.2",
|
||||
"knplabs/knp-snappy": "^1.5",
|
||||
"laracasts/utilities": "^3.2",
|
||||
@@ -51,7 +50,7 @@
|
||||
"laravel/helpers": "^1.7",
|
||||
"laravel/scout": "^9.8",
|
||||
"laravel/tinker": "^2.8",
|
||||
"laravel/ui": "^3.4",
|
||||
"laravel/ui": "^4.4",
|
||||
"laravelcollective/html": "^6.4",
|
||||
"laraveldaily/laravel-invoices": "^3.3",
|
||||
"laravolt/avatar": "^4.1",
|
||||
@@ -62,16 +61,16 @@
|
||||
"maatwebsite/excel": "^3.1",
|
||||
"moneyphp/money": "^4.3",
|
||||
"mpdf/mpdf": "^8.2",
|
||||
"mpociot/teamwork": "^7.0",
|
||||
"nicmart/tree": "^0.7",
|
||||
"mpociot/teamwork": "^8.1",
|
||||
"nicmart/tree": "^0.8",
|
||||
"nicolaslopezj/searchable": "^1.13",
|
||||
"orangehill/iseed": "^3.0",
|
||||
"php-console/php-console": "^3.1",
|
||||
"proengsoft/laravel-jsvalidation": "^4.8",
|
||||
"protonemedia/laravel-cross-eloquent-search": "^3.2",
|
||||
"rahul900day/laravel-captcha": "^1.2",
|
||||
"rahul900day/laravel-captcha": "^2.0",
|
||||
"ralphjsmit/laravel-seo": "^1.4",
|
||||
"reedware/laravel-relation-joins": "^3.0",
|
||||
"reedware/laravel-relation-joins": "^5.0",
|
||||
"respect/validation": "^2.2",
|
||||
"rinvex/laravel-categories": "^6.1",
|
||||
"rinvex/laravel-tags": "^6.1",
|
||||
|
||||
Reference in New Issue
Block a user