add new metrics, graph metrics, prepare basket to storage

This commit is contained in:
ludo
2024-01-29 23:44:49 +01:00
parent 72f5da4555
commit 84bc5f2e67
12 changed files with 219 additions and 214 deletions

View File

@@ -3,13 +3,13 @@
namespace App\Charts\Shop; namespace App\Charts\Shop;
use Akaunting\Apexcharts\Chart; use Akaunting\Apexcharts\Chart;
use App\Repositories\Shop\OrderStatistics; use App\Repositories\Shop\OrderMetrics;
class Order class Order
{ {
public static function getMonthly() public static function getMonthly()
{ {
$data = OrderStatistics::getTotalMonthly(); $data = OrderMetrics::getTotalMonthly();
return (new Chart)->setType('bar') return (new Chart)->setType('bar')
->setWidth('100%') ->setWidth('100%')

View File

@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Repositories\Shop\Dashboards; use App\Repositories\Shop\Dashboards;
use App\Charts\Shop\Order; use App\Charts\Shop\Order;
use Carbon\Carbon;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class HomeController extends Controller class HomeController extends Controller
@@ -16,14 +17,13 @@ class HomeController extends Controller
public function index(Request $request, $period = false) public function index(Request $request, $period = false)
{ {
$data = $request->all(); $start = $request->input('start') ?? Carbon::now()->subMonths(12)->startOfMonth();
$start = $request->input('start'); $end = $request->input('end') ?? Carbon::now();
$end = $request->input('end');
$data = Dashboards::getStats($start, $end); $data = Dashboards::getStats($start, $end);
$data['chart'] = Order::getMonthly(); $data['chart'] = Order::getMonthly();
//dump($data);
//exit;
// dump($data); // dump($data);
// exit;
return view('Admin.Shop.Dashboard.index', $data); return view('Admin.Shop.Dashboard.index', $data);
} }
} }

View File

@@ -7,6 +7,10 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Basket extends Model class Basket extends Model
{ {
protected $fillable = [
'id', 'cart_data',
];
protected $guarded = ['id']; protected $guarded = ['id'];
protected $table = 'shop_baskets'; protected $table = 'shop_baskets';
@@ -15,4 +19,14 @@ class Basket extends Model
{ {
return $this->belongsTo(Offer::class); return $this->belongsTo(Offer::class);
} }
}
public function setCartDataAttribute($value)
{
$this->attributes['cart_data'] = serialize($value);
}
public function getCartDataAttribute($value)
{
return unserialize($value);
}
}

View File

@@ -79,7 +79,7 @@ class DateRange
public static function getPeriodsLastMonth($nb = 1, $withActual = true) public static function getPeriodsLastMonth($nb = 1, $withActual = true)
{ {
$end = $withActual ? Carbon::now()->endOfMonth() : self::lastMonth(); $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); return self::getPeriodsByMonth($begin, $end);
} }

View 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
]);
}
}
}

View File

@@ -12,9 +12,10 @@ class Dashboards
'orders_avg' => OrderMetrics::avgByPeriod($start, $end, 'total_shipped'), 'orders_avg' => OrderMetrics::avgByPeriod($start, $end, 'total_shipped'),
'offers_count' => Offers::count(), 'offers_count' => Offers::count(),
'clients_count' => Customers::count(), 'clients_count' => Customers::count(),
'preparationLess24H' => OrderMetrics::countInPreparationLess24H(), 'preparationLess24H' => OrderMetrics::countPreparationLess24h(),
'preparationLess48H' => OrderMetrics::countInPreparationLess48H(), 'preparationLess48H' => OrderMetrics::countPreparationLess48h(),
'preparationMore48H' => OrderMetrics::countInPreparationMore48H(), 'preparationMore48H' => OrderMetrics::countPreparationMore48h(),
'stocksWarning' => OfferStocks::countAlerts(),
]; ];
} }
} }

View File

@@ -22,4 +22,14 @@ class OfferStocks
{ {
return Offers::getField($id, 'stock_current'); 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();
}
} }

View File

@@ -4,38 +4,71 @@ namespace App\Repositories\Shop;
use App\Models\Shop\Order; use App\Models\Shop\Order;
use App\Repositories\Core\DateStats; use App\Repositories\Core\DateStats;
use Carbon\Carbon; use App\Traits\Model\Basic;
class OrderMetrics class OrderMetrics
{ {
use DateStats; use Basic, DateStats;
public static function countInPreparationLess24H() public static function getTotalDaily()
{ {
$start = Carbon::now()->subHours(24); return self::sumDaily('total_taxed');
$end = Carbon::now();
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
} }
public static function countInPreparationLess48H() public static function getTotalMonthly()
{ {
$start = Carbon::now()->subHours(48); return self::sumMonthly('total_taxed');
$end = Carbon::now();
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
} }
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() public static function getModel()

View File

@@ -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();
}
}

View File

@@ -1,74 +1,66 @@
<x-card title="Aperçu de l'activité"> <x-card title="Aperçu de l'activité">
<div class="counter"> <div class="counter">
<span class="index">Paniers Actifs</span> <span class="index">Paniers Actifs</span>
<div class="value float-right">40</div> <div class="value float-right">40</div>
</div> </div>
<div> <div>
<span class="text-muted">dans les 30 dernières minutes</span> <span class="text-muted">dans les 30 dernières minutes</span>
</div> </div>
<x-card title="Etat des commandes" class="dashtable" classBody="p-1 bg-light"> <x-card title="Etat des commandes" class="dashtable" classBody="p-1 bg-light">
<table class="table table-stripped counter w-100"> <table class="table table-stripped counter w-100">
<tr> <tr>
<td class="index">Commandes</td> <td class="index">Commandes</td>
<td class="value text-right">{{ $orders_count }}</td> <td class="value text-right">{{ $orders_count }}</td>
</tr> </tr>
<tr> <tr>
<td class="index">En préparation depuis moins de 24h</td> <td class="index">En préparation depuis moins de 24h</td>
<td class="value float-right">{{ $preparationLess24H ?? 0 }}</td> <td class="value float-right">{{ $preparationLess24H ?? 0 }}</td>
</tr> </tr>
<tr> <tr>
<td class="index">En préparation depuis moins de 48h</td> <td class="index">En préparation depuis moins de 48h</td>
<td class="value float-right">{{ $preparationLess48H ?? 0 }}</td> <td class="value float-right">{{ $preparationLess48H ?? 0 }}</td>
</tr> </tr>
<tr> <tr>
<td class="index">En préparation depuis plus de 48h</td> <td class="index">En préparation depuis plus de 48h</td>
<td class="value float-right">{{ $preparationMore48H ?? 0 }}</td> <td class="value float-right">{{ $preparationMore48H ?? 0 }}</td>
</tr> </tr>
<tr> <tr>
<td class="index">Echec de paiement</td> <td class="index">Echec de paiement</td>
<td class="value float-right">{{ $paymentsFailed ?? 0 }}</td> <td class="value float-right">{{ $paymentsFailed ?? 0 }}</td>
</tr> </tr>
<tr> <tr>
<td class="index"> <td class="index">
A rembourser<br> A rembourser<br>
<span class="text-muted">Payés sans stock disponible</span> <span class="text-muted">Payés sans stock disponible</span>
</td> </td>
<td class="value float-right">{{ $refunds ?? 0 }}</td> <td class="value float-right">{{ $refunds ?? 0 }}</td>
</tr> </tr>
<tr> <tr>
<td class="index"> <td class="index">
En attente de confirmation<br> En attente de confirmation<br>
<span class="text-muted">Pour les ventes pro</span> <span class="text-muted">Pour les ventes pro</span>
</td> </td>
<td class="value float-right">{{ $ordersNotConfirmed ?? 0 }}</td> <td class="value float-right">{{ $ordersNotConfirmed ?? 0 }}</td>
</tr> </tr>
</table> </table>
</x-card> </x-card>
<x-card title="Suivi des stocks" class="dashtable" classBody="p-1 bg-light"> <x-card title="Suivi des stocks" class="dashtable" classBody="p-1 bg-light">
<table class="table table-stripped counter w-100"> <table class="table table-stripped counter w-100">
<tr> <tr>
<td class="index">Stock critique</td> <td class="index">Stock critique</td>
<td class="value float-right">{{ $stocksWarning ?? 0 }}</td> <td class="value float-right">{{ $stocksWarning ?? 0 }}</td>
</tr> </tr>
<tr> </table>
<td class="index">Paramétrage du niveau critique</td> </x-card>
<td class="value float-right"></td>
</tr>
</table>
</x-card>
<x-card title="Clients et suivi client" class="dashtable" classBody="p-1 bg-light"> <x-card title="Clients et suivi client" class="dashtable" classBody="p-1 bg-light">
<table class="table table-stripped counter w-100"> <table class="table table-stripped counter w-100">
<tr> <tr>
<td class="index">Nouveaux clients</td> <td class="index">Nouveaux clients</td>
<td class="value float-right">{{ $newClients ?? 0 }}</td> <td class="value float-right">{{ $newClients ?? 0 }}</td>
</tr> </tr>
<tr> </table>
<td class="index">Exporter le fichier clients</td> </x-card>
<td class="value float-right"></td>
</tr>
</table>
</x-card>
</x-card> </x-card>

View File

@@ -1,38 +1,30 @@
<div class="row"> <div class="row">
<div class="col-sm-3 col-xs-6"> <div class="col-sm-3 col-xs-6">
<div class="description-block border-right"> <div class="description-block border-right">
<span class="description-percentage text-green"><i class="fa fa-caret-up"></i> 17%</span> <span class="description-percentage text-green"><i class="fa fa-caret-up"></i> 17%</span>
<h5 class="description-header">{{ $orders_sum ?? 0 }} </h5> <h5 class="description-header">{{ $orders_sum ?? 0 }} </h5>
<span class="description-text">TOTAL VENTE</span> <span class="description-text">TOTAL VENTE</span>
</div> </div>
<!-- /.description-block --> </div>
</div> <div class="col-sm-3 col-xs-6">
<!-- /.col --> <div class="description-block border-right">
<div class="col-sm-3 col-xs-6"> <span class="description-percentage text-yellow"><i class="fa fa-caret-left"></i> 0%</span>
<div class="description-block border-right"> <h5 class="description-header">{{ $orders_avg ?? 0 }} </h5>
<span class="description-percentage text-yellow"><i class="fa fa-caret-left"></i> 0%</span> <span class="description-text">PANIER MOYEN</span>
<h5 class="description-header">{{ $orders_avg ?? 0 }} </h5> </div>
<span class="description-text">PANIER MOYEN</span> </div>
</div> <div class="col-sm-3 col-xs-6">
<!-- /.description-block --> <div class="description-block border-right">
</div> <span class="description-percentage text-green"><i class="fa fa-caret-up"></i> 20%</span>
<!-- /.col --> <h5 class="description-header">{{ $clients_count ?? 0 }}</h5>
<div class="col-sm-3 col-xs-6"> <span class="description-text">NB CLIENTS</span>
<div class="description-block border-right"> </div>
<span class="description-percentage text-green"><i class="fa fa-caret-up"></i> 20%</span> </div>
<h5 class="description-header">{{ $clients_count ?? 0 }}</h5> <div class="col-sm-3 col-xs-6">
<span class="description-text">NB CLIENTS</span> <div class="description-block">
</div> <span class="description-percentage text-red"><i class="fa fa-caret-down"></i> 18%</span>
<!-- /.description-block --> <h5 class="description-header">{{ $offers_count ?? 0 }}</h5>
</div> <span class="description-text">NB OFFRES</span>
<!-- /.col --> </div>
<div class="col-sm-3 col-xs-6"> </div>
<div class="description-block">
<span class="description-percentage text-red"><i class="fa fa-caret-down"></i> 18%</span>
<h5 class="description-header">{{ $offers_count ?? 0 }}</h5>
<span class="description-text">NB OFFRES</span>
</div>
<!-- /.description-block -->
</div>
</div> </div>
<!-- /.row -->

View File

@@ -5,18 +5,6 @@
@include('boilerplate::logs.style') @include('boilerplate::logs.style')
@section('content') @section('content')
<div class="btn-group mb-3" role="group" aria-label="" class="d-none">
<button type="button" class="btn btn-sm btn-secondary text-nowrap" data-id="day">jour</button>
<button type="button" class="btn btn-sm btn-secondary text-nowrap" data-id="month">mois</button>
<button type="button" class="btn btn-sm btn-secondary text-nowrap" data-id="year">année</button>
<button type="button" class="btn btn-sm btn-secondary text-nowrap" data-id="yesterday">jour-1</button>
<button type="button" class="btn btn-sm btn-secondary text-nowrap" data-id="lastmonth">mois-1</button>
<button type="button" class="btn btn-sm btn-secondary text-nowrap" data-id="lastyear">année-1</button>
@include('components.form.daterangepicker', [
'name' => 'period',
])
</div>
<div class="row dashboard"> <div class="row dashboard">
<div class="col-lg-3 col-sm-6 col-xs-12"> <div class="col-lg-3 col-sm-6 col-xs-12">
@include('Admin.Shop.Dashboard._partials.counter') @include('Admin.Shop.Dashboard._partials.counter')