add new metrics, graph metrics, prepare basket to storage
This commit is contained in:
@@ -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%')
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
43
app/Repositories/Shop/BasketStores.php
Normal file
43
app/Repositories/Shop/BasketStores.php
Normal 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
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -52,10 +52,6 @@
|
|||||||
<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>
|
|
||||||
<td class="index">Paramétrage du niveau critique</td>
|
|
||||||
<td class="value float-right"></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
</table>
|
||||||
</x-card>
|
</x-card>
|
||||||
|
|
||||||
@@ -65,10 +61,6 @@
|
|||||||
<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>
|
|
||||||
<td class="index">Exporter le fichier clients</td>
|
|
||||||
<td class="value float-right"></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
</table>
|
||||||
</x-card>
|
</x-card>
|
||||||
</x-card>
|
</x-card>
|
||||||
|
|||||||
@@ -5,34 +5,26 @@
|
|||||||
<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>
|
||||||
<!-- /.col -->
|
|
||||||
<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-yellow"><i class="fa fa-caret-left"></i> 0%</span>
|
<span class="description-percentage text-yellow"><i class="fa fa-caret-left"></i> 0%</span>
|
||||||
<h5 class="description-header">{{ $orders_avg ?? 0 }} €</h5>
|
<h5 class="description-header">{{ $orders_avg ?? 0 }} €</h5>
|
||||||
<span class="description-text">PANIER MOYEN</span>
|
<span class="description-text">PANIER MOYEN</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.description-block -->
|
|
||||||
</div>
|
</div>
|
||||||
<!-- /.col -->
|
|
||||||
<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> 20%</span>
|
<span class="description-percentage text-green"><i class="fa fa-caret-up"></i> 20%</span>
|
||||||
<h5 class="description-header">{{ $clients_count ?? 0 }}</h5>
|
<h5 class="description-header">{{ $clients_count ?? 0 }}</h5>
|
||||||
<span class="description-text">NB CLIENTS</span>
|
<span class="description-text">NB CLIENTS</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.description-block -->
|
|
||||||
</div>
|
</div>
|
||||||
<!-- /.col -->
|
|
||||||
<div class="col-sm-3 col-xs-6">
|
<div class="col-sm-3 col-xs-6">
|
||||||
<div class="description-block">
|
<div class="description-block">
|
||||||
<span class="description-percentage text-red"><i class="fa fa-caret-down"></i> 18%</span>
|
<span class="description-percentage text-red"><i class="fa fa-caret-down"></i> 18%</span>
|
||||||
<h5 class="description-header">{{ $offers_count ?? 0 }}</h5>
|
<h5 class="description-header">{{ $offers_count ?? 0 }}</h5>
|
||||||
<span class="description-text">NB OFFRES</span>
|
<span class="description-text">NB OFFRES</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.description-block -->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.row -->
|
|
||||||
|
|||||||
@@ -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')
|
||||||
|
|||||||
Reference in New Issue
Block a user