From 8eb3104b2a54cd82c74516350540d16011b3af27 Mon Sep 17 00:00:00 2001 From: ludo Date: Tue, 30 Jan 2024 23:24:00 +0100 Subject: [PATCH] add metrics --- .../Admin/Shop/PriceListValueController.php | 75 ++++++++++++++ app/Models/Shop/Order.php | 5 + app/Repositories/Shop/BasketStores.php | 22 +++-- app/Repositories/Shop/CustomerMetrics.php | 32 ++++++ app/Repositories/Shop/Dashboards.php | 7 +- app/Repositories/Shop/OrderMetrics.php | 5 + app/Repositories/Shop/Orders.php | 5 + .../Dashboard/_partials/counter.blade.php | 21 ++-- .../Dashboard/_partials/evolutions.blade.php | 16 +-- .../_partials/latestOrders.blade.php | 97 +++++++++++-------- routes/Admin/Shop/PriceListValues.php | 10 ++ routes/Admin/Shop/route.php | 1 + 12 files changed, 226 insertions(+), 70 deletions(-) create mode 100644 app/Http/Controllers/Admin/Shop/PriceListValueController.php create mode 100644 app/Repositories/Shop/CustomerMetrics.php create mode 100644 routes/Admin/Shop/PriceListValues.php diff --git a/app/Http/Controllers/Admin/Shop/PriceListValueController.php b/app/Http/Controllers/Admin/Shop/PriceListValueController.php new file mode 100644 index 00000000..966b04a7 --- /dev/null +++ b/app/Http/Controllers/Admin/Shop/PriceListValueController.php @@ -0,0 +1,75 @@ +render('Admin.Shop.PriceListValues.list', $data); + } + + public function create() + { + $data['unities'] = Unities::getOptions(); + $data['taxes_options'] = Taxes::getOptions(); + $data['categories'] = PriceListValueCategories::getOptions(); + + return view('Admin.Shop.PriceListValues.create', $data); + } + + public function edit($id) + { + $data['generic'] = PriceListValues::getFull($id)->toArray(); + $data['packages'] = Packages::getSelectByFamily($data['generic']['category']['article_family_id']); + $data['unities'] = ($data['packages']['id'] ?? false) ? Unities::getSelectByPackage($data['packages']['id']) : []; + $data['taxes_options'] = Taxes::getOptions(); + $data['categories'] = PriceListValueCategories::getOptions(); + + return view('Admin.Shop.PriceListValues.edit', $data); + } + + public function store(Request $request) + { + $ret = PriceListValues::store($request->all()); + + return redirect()->route('Admin.Shop.PriceListValues.index'); + } + + public function show($id) + { + $data = PriceListValues::get($id); + + return view('Admin.Shop.PriceListValues.view', $data); + } + + public function destroy($id) + { + return PriceListValues::destroy($id); + } + + public function getPrice($id) + { + $data['generic'] = PriceListValues::getFull($id); + + return view('Admin.Shop.PriceListValues.partials.table-prices', $data); + } + + public function addPrice($index) + { + $data['index'] = $index; + + return view('Admin.Shop.PriceListValues.partials.row_price', $data); + } +} diff --git a/app/Models/Shop/Order.php b/app/Models/Shop/Order.php index d581e462..eafcf2df 100644 --- a/app/Models/Shop/Order.php +++ b/app/Models/Shop/Order.php @@ -69,6 +69,11 @@ class Order extends Model return $query->where('delivery_id', $deliveryId); } + public function scopeWaiting($query) + { + return $query->byStatus(0); + } + public function scopePreparation($query) { return $query->byStatus(1); diff --git a/app/Repositories/Shop/BasketStores.php b/app/Repositories/Shop/BasketStores.php index 54c43c6e..95bd5332 100644 --- a/app/Repositories/Shop/BasketStores.php +++ b/app/Repositories/Shop/BasketStores.php @@ -3,10 +3,13 @@ namespace App\Repositories\Shop; use App\Models\Shop\Basket; +use App\Traits\Model\Basic; use Darryldecode\Cart\CartCollection; class BasketStores { + use Basic; + public function has($key) { return Basket::find($key); @@ -14,30 +17,29 @@ class BasketStores public function get($key) { - if($this->has($key)) - { + if($this->has($key)) { return new CartCollection(Basket::find($key)->cart_data); - } - else - { + } else { return []; } } public function put($key, $value) { - if($row = Basket::find($key)) - { + if($row = Basket::find($key)) { // update $row->cart_data = $value; $row->save(); - } - else - { + } else { Basket::create([ 'id' => $key, 'cart_data' => $value ]); } } + + public static function getModel() + { + return Basket::query(); + } } diff --git a/app/Repositories/Shop/CustomerMetrics.php b/app/Repositories/Shop/CustomerMetrics.php new file mode 100644 index 00000000..2563e706 --- /dev/null +++ b/app/Repositories/Shop/CustomerMetrics.php @@ -0,0 +1,32 @@ +count(); + } + + public static function countOfLastWeek() + { + return Customer::ofLastWeek()->count(); + } + + public static function countOfLastMonth() + { + return Customer::ofLastMonth()->count(); + } + + public static function getModel() + { + return Customer::query(); + } +} diff --git a/app/Repositories/Shop/Dashboards.php b/app/Repositories/Shop/Dashboards.php index e883d57d..1bbb09bc 100644 --- a/app/Repositories/Shop/Dashboards.php +++ b/app/Repositories/Shop/Dashboards.php @@ -10,12 +10,15 @@ class Dashboards 'orders_count' => OrderMetrics::countByPeriod($start, $end), 'orders_sum' => OrderMetrics::sumByPeriod($start, $end, 'total_shipped'), 'orders_avg' => OrderMetrics::avgByPeriod($start, $end, 'total_shipped'), - 'offers_count' => Offers::count(), - 'clients_count' => Customers::count(), + 'countClients' => CustomerMetrics::countByPeriod($start, $end), + 'waitingOrders' => OrderMetrics::countWaiting(), 'preparationLess24H' => OrderMetrics::countPreparationLess24h(), 'preparationLess48H' => OrderMetrics::countPreparationLess48h(), 'preparationMore48H' => OrderMetrics::countPreparationMore48h(), + 'offers_count' => Offers::count(), 'stocksWarning' => OfferStocks::countAlerts(), + 'countCustomers' => Customers::count(), + 'lastOrders' => Orders::getLast(), ]; } } diff --git a/app/Repositories/Shop/OrderMetrics.php b/app/Repositories/Shop/OrderMetrics.php index d2babe7b..d003f9cb 100644 --- a/app/Repositories/Shop/OrderMetrics.php +++ b/app/Repositories/Shop/OrderMetrics.php @@ -20,6 +20,11 @@ class OrderMetrics return self::sumMonthly('total_taxed'); } + public static function countWaiting() + { + return Order::waiting()->count(); + } + public static function countPreparationLess24h() { $date = now()->subHours(24); diff --git a/app/Repositories/Shop/Orders.php b/app/Repositories/Shop/Orders.php index ac79b9ca..62517610 100644 --- a/app/Repositories/Shop/Orders.php +++ b/app/Repositories/Shop/Orders.php @@ -14,6 +14,11 @@ class Orders { use Basic, DateStats; + public static function getLast($nb = 10) + { + return Order::with('customer')->orderBy('id', 'DESC')->take($nb)->get(); + } + public static function getPdfByUUID($uuid) { return self::getPdf(self::getIdByUUID($uuid), 'commande-' . $uuid . '.pdf'); diff --git a/resources/views/Admin/Shop/Dashboard/_partials/counter.blade.php b/resources/views/Admin/Shop/Dashboard/_partials/counter.blade.php index 2a4c1a0a..f8e10c73 100644 --- a/resources/views/Admin/Shop/Dashboard/_partials/counter.blade.php +++ b/resources/views/Admin/Shop/Dashboard/_partials/counter.blade.php @@ -1,17 +1,10 @@ -
- Paniers Actifs -
40
-
-
- dans les 30 dernières minutes -
- - + + @@ -46,8 +39,12 @@
Commandes{{ $orders_count }}Commandes en attente{{ $waitingOrders ?? 0 }}
En préparation depuis moins de 24h
- + + + + + @@ -58,8 +55,8 @@
Offres disponibles{{ $offers_count ?? 0 }}
Stock critique {{ $stocksWarning ?? 0 }}
- - + +
Nouveaux clients{{ $newClients ?? 0 }}Clients{{ $countCustomers ?? 0 }}
diff --git a/resources/views/Admin/Shop/Dashboard/_partials/evolutions.blade.php b/resources/views/Admin/Shop/Dashboard/_partials/evolutions.blade.php index e62f76ba..f05cfa7f 100644 --- a/resources/views/Admin/Shop/Dashboard/_partials/evolutions.blade.php +++ b/resources/views/Admin/Shop/Dashboard/_partials/evolutions.blade.php @@ -1,4 +1,11 @@
+
+
+ 18% +
{{ $orders_count ?? 0 }}
+ NB COMMANDES +
+
17% @@ -16,15 +23,8 @@
20% -
{{ $clients_count ?? 0 }}
+
{{ $countClients ?? 0 }}
NB CLIENTS
-
-
- 18% -
{{ $offers_count ?? 0 }}
- NB OFFRES -
-
diff --git a/resources/views/Admin/Shop/Dashboard/_partials/latestOrders.blade.php b/resources/views/Admin/Shop/Dashboard/_partials/latestOrders.blade.php index b41f0664..f9bff873 100644 --- a/resources/views/Admin/Shop/Dashboard/_partials/latestOrders.blade.php +++ b/resources/views/Admin/Shop/Dashboard/_partials/latestOrders.blade.php @@ -1,42 +1,63 @@
-
-

Dernières commandes

+
+

Dernières commandes

-
- - -
-
- -
-
- - - - - - - - - - - - - - - - - -
NomLocalisationDateMontant
Ludovic CANDELLIERAmiens (80)14/05/2020300.53 €
-
- -
- - - +
+ + +
+
+
+
+ + + + + + + + + + + + @if (count($lastOrders)) + @foreach ($lastOrders as $order) + + + + + + + + @endforeach + @endif + +
NomLocalisationDateMontant
+ + {{ $order->customer->first_name }} + {{ $order->customer->last_name }} + + {{ $order->customer->city }} ({{ substr($order->customer->zipcode, 0, 2) }}){{ Carbon\Carbon::parse($order->created_at)->format('d/m/Y H:i') }} + {{ $order->total_shipped }} € + + + + +
+
+ +
+ + +
diff --git a/routes/Admin/Shop/PriceListValues.php b/routes/Admin/Shop/PriceListValues.php new file mode 100644 index 00000000..41f7b9f4 --- /dev/null +++ b/routes/Admin/Shop/PriceListValues.php @@ -0,0 +1,10 @@ +name('PriceListValues.')->group(function () { + Route::get('', 'PriceListValueController@index')->name('index'); + Route::get('create', 'PriceListValueController@create')->name('create'); + Route::delete('destroy/{id?}', 'PriceListValueController@destroy')->name('destroy'); + Route::post('store', 'PriceListValueController@store')->name('store'); + Route::get('edit/{id}', 'PriceListValueController@edit')->name('edit'); + Route::get('addPrice/{index?}', 'PriceListValueController@addPrice')->name('addPrice'); +}); diff --git a/routes/Admin/Shop/route.php b/routes/Admin/Shop/route.php index e8cb595c..d02bd05b 100644 --- a/routes/Admin/Shop/route.php +++ b/routes/Admin/Shop/route.php @@ -19,6 +19,7 @@ Route::middleware('auth')->prefix('Shop')->namespace('Shop')->name('Shop.')->gro include_once __DIR__.'/Orders.php'; include_once __DIR__.'/Packages.php'; include_once __DIR__.'/PriceLists.php'; + include_once __DIR__.'/PriceListValues.php'; include_once __DIR__.'/Producers.php'; include_once __DIR__.'/SaleChannels.php'; include_once __DIR__.'/Tags.php';