Issue 19 - Add dashboard stats
This commit is contained in:
parent
3e5a1526ef
commit
995e1f9eb5
11 changed files with 649 additions and 12 deletions
68
app/Enums/StatsType.php
Normal file
68
app/Enums/StatsType.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
/**
|
||||
* @method static self nbValidateCmd()
|
||||
* @method static self nbWaitingCmd()
|
||||
* @method static self nbCanceledCmd()
|
||||
* @method static self canceledRate()
|
||||
* @method static self orderFrequency()
|
||||
* @method static self nbActiveClients()
|
||||
* @method static self nbCmdWith7DayDelay()
|
||||
* @method static self nbCmdWith14DayDelay()
|
||||
* @method static self nbCmdWithMoreThan14DayDelay()
|
||||
* @method static self caHt()
|
||||
* @method static self averageBasketHt()
|
||||
* @method static self averageProductCountPerOrder()
|
||||
*
|
||||
*/
|
||||
class StatsType extends BaseEnum
|
||||
{
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'nbValidateCmd' => 1,
|
||||
'nbWaitingCmd' => 2,
|
||||
'nbCanceledCmd' => 3,
|
||||
'canceledRate' => 4,
|
||||
'orderFrequency' => 5,
|
||||
'nbActiveClients' => 6,
|
||||
'nbCmdWith7DayDelay' => 7,
|
||||
'nbCmdWith14DayDelay' => 8,
|
||||
'nbCmdWithMoreThan14DayDelay' => 9,
|
||||
'caHt' => 10,
|
||||
'averageBasketHt' => 11,
|
||||
'averageProductCountPerOrder' => 12
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'nbValidateCmd' => trans('Nombre de commandes validées'),
|
||||
'nbWaitingCmd' => trans('Nombre de commandes en attente'),
|
||||
'nbCanceledCmd' => trans('Nombre de commandes annulées'),
|
||||
'canceledRate' => trans('Taux d\'abandon (en pourcentage)'),
|
||||
'orderFrequency' => trans('Fréquence d\'achat (en jours)'),
|
||||
'nbActiveClients' => trans('Nombre de clients actifs'),
|
||||
'nbCmdWith7DayDelay' => trans('Nombre de commandes à J+7'),
|
||||
'nbCmdWith14DayDelay' => trans('Nombre de commandes à J+14'),
|
||||
'nbCmdWithMoreThan14DayDelay' => trans('Nombre de commandes à J+15 et plus'),
|
||||
'caHt' => trans('Montant total HT'),
|
||||
'averageBasketHt' => trans('Prix du panier moyen'),
|
||||
'averageProductCountPerOrder' => trans('Nombre d\'article moyen par commande')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -3,16 +3,30 @@
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
use App\Http\Requests\Bo\DashboardRequest;
|
||||
use App\Lib\Helpers\StatsHelper;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Dashboard Page
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\DashboardRequest $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index()
|
||||
public function index(DashboardRequest $request)
|
||||
{
|
||||
return view('bo.dashboard');
|
||||
$stats = [];
|
||||
$adhesion = StatsHelper::getMembershipPercentage();
|
||||
$previousDates = [];
|
||||
|
||||
if ($request->has('start') && $request->has('end')) {
|
||||
$start = new Carbon($request->start);
|
||||
$end = new Carbon($request->end);
|
||||
$previousDates = StatsHelper::getPreviousPeriod($start, $end);
|
||||
$stats = StatsHelper::getStats($start, $end);
|
||||
}
|
||||
return view('bo.dashboard', compact('stats', 'adhesion', 'previousDates'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class OrdersController extends Controller
|
|||
// Filter today.
|
||||
$today = CarbonImmutable::now()->startOfDay();
|
||||
$orders = $orders->whereHas('timeslot', function ($q) use ($today) {
|
||||
$q->where('day', '=', $today->format('d/m/Y'));
|
||||
$q->where('day', $today);
|
||||
});
|
||||
|
||||
$orders = $orders->get();
|
||||
|
|
|
|||
|
|
@ -404,7 +404,7 @@ class OrderTunnelController extends Controller
|
|||
->get();
|
||||
$totalPrice = 0;
|
||||
foreach ($customerOrders as $key => $customerOrder) {
|
||||
$timeslot_day = Carbon::createFromFormat('d/m/Y', $customerOrder->timeslot->day);
|
||||
$timeslot_day = $customerOrder->timeslot->day;
|
||||
if (
|
||||
$timeslot_day >= $start &&
|
||||
$timeslot_day <= $end
|
||||
|
|
@ -429,7 +429,7 @@ class OrderTunnelController extends Controller
|
|||
$timeslot = Timeslot::firstOrNew(['order_id' => $order->id]);
|
||||
$timeslot->order_id = $order->id;
|
||||
$timeslot->magasin_id = $magasin_id;
|
||||
$timeslot->day = $tsday;
|
||||
$timeslot->day = $date;
|
||||
$timeslot->time = $tstime;
|
||||
$timeslot->save();
|
||||
|
||||
|
|
|
|||
31
app/Http/Requests/Bo/DashboardRequest.php
Normal file
31
app/Http/Requests/Bo/DashboardRequest.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class DashboardRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return \auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'start' => ['required_with:end', 'date'],
|
||||
'end' => ['required_with:start', 'date'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Models\Order;
|
||||
|
||||
class CsvOrderWrite extends CsvJobs
|
||||
|
|
@ -90,8 +89,6 @@ class CsvOrderWrite extends CsvJobs
|
|||
$unité_commande = $product->order_unit ?? 'PCE';
|
||||
// Matricule rh transmis sans les lettres de l'identifiant windows.
|
||||
$code_client = preg_replace('/[^\d]/', '', $customer->salarie->matricule);
|
||||
// Convert to date object.
|
||||
$datLivraison = Carbon::createFromFormat('d/m/Y H:i', $timeslot->day . " " . $timeslot->time);
|
||||
|
||||
$oneline = [
|
||||
$product->foodProduct->no_art,
|
||||
|
|
@ -104,7 +101,7 @@ class CsvOrderWrite extends CsvJobs
|
|||
$this->mode_commande[$unité_commande],
|
||||
// On vide la colonne pcb comme demandé.
|
||||
"",
|
||||
$datLivraison->format('d/m/Y'),
|
||||
$timeslot->day->format('d/m/Y'),
|
||||
$orderline->quantity,
|
||||
$this->order->reference,
|
||||
];
|
||||
|
|
|
|||
318
app/Lib/Helpers/StatsHelper.php
Normal file
318
app/Lib/Helpers/StatsHelper.php
Normal file
|
|
@ -0,0 +1,318 @@
|
|||
<?php
|
||||
|
||||
namespace App\Lib\Helpers;
|
||||
|
||||
use App\Models\Customers;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderLine;
|
||||
use App\Models\Salarie;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Enums\StatsType;
|
||||
|
||||
final class StatsHelper
|
||||
{
|
||||
/**
|
||||
* getStats
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return array
|
||||
*/
|
||||
public static function getStats(Carbon $start, Carbon $end)
|
||||
{
|
||||
$stats = [];
|
||||
foreach (StatsType::toArray() as $type) {
|
||||
$stats[$type->value] = [
|
||||
'previous' => self::getPrevious(sprintf('get%s', ucfirst($type->getDefinition())), $start, $end),
|
||||
'current' => self::{sprintf('get%s', ucfirst($type->getDefinition()))}($start, $end),
|
||||
'diff' => self::getDiff(sprintf('get%s', ucfirst($type->getDefinition())), $start, $end),
|
||||
];
|
||||
}
|
||||
return $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPrevious
|
||||
*
|
||||
* @param string $method
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getPrevious(string $method, Carbon $start, Carbon $end)
|
||||
{
|
||||
$previousDates = self::getPreviousPeriod($start, $end);
|
||||
return self::{$method}($previousDates->start, $previousDates->end);
|
||||
}
|
||||
|
||||
/**
|
||||
* getDiff
|
||||
*
|
||||
* @param string $method
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return integer|float
|
||||
*/
|
||||
private function getDiff(string $method, Carbon $start, Carbon $end)
|
||||
{
|
||||
return self::{$method}($start, $end) - self::getPrevious($method, $start, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the percentage of registered people / people with a generated code
|
||||
*
|
||||
* @return integer|float
|
||||
*/
|
||||
public static function getMembershipPercentage()
|
||||
{
|
||||
$employee = Salarie::count();
|
||||
$registered = Customers::has('salarie')->count();
|
||||
return round($registered / $employee * 100, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all validated orders.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getValidatedOrders(Carbon $start, Carbon $end)
|
||||
{
|
||||
return Order::whereHas('status', function (Builder $query) {
|
||||
$query->whereIn('id', [3, 4, 5, 6]);
|
||||
})->whereBetween('date', [$start->toDateString(), $end->toDateString()])->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of validated command.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getNbValidateCmd(Carbon $start, Carbon $end)
|
||||
{
|
||||
return self::getValidatedOrders($start, $end)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of waiting command.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getNbWaitingCmd(Carbon $start, Carbon $end)
|
||||
{
|
||||
return Order::whereHas('status', function (Builder $query) {
|
||||
$query->where('id', 1);
|
||||
})->whereBetween('date', [$start->toDateString(), $end->toDateString()])->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of canceled command.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getNbCanceledCmd(Carbon $start, Carbon $end)
|
||||
{
|
||||
return Order::whereHas('status', function (Builder $query) {
|
||||
$query->where('id', 7);
|
||||
})->whereBetween('date', [$start->toDateString(), $end->toDateString()])->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the canceled command rate.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getCanceledRate(Carbon $start, Carbon $end)
|
||||
{
|
||||
$nbWaitingCmd = self::getNbWaitingCmd($start, $end);
|
||||
$nbCanceledCmd = self::getNbCanceledCmd($start, $end);
|
||||
$nbValidateCmd = self::getNbValidateCmd($start, $end);
|
||||
|
||||
// Prevent division by 0.
|
||||
if (($nbValidateCmd + $nbWaitingCmd + $nbCanceledCmd) !== 0) {
|
||||
return round(
|
||||
(($nbWaitingCmd + $nbCanceledCmd) / ($nbValidateCmd + $nbWaitingCmd + $nbCanceledCmd)) * 100,
|
||||
2
|
||||
);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the order frequency.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getOrderFrequency(Carbon $start, Carbon $end)
|
||||
{
|
||||
$nbValidateCmd = self::getNbValidateCmd($start, $end);
|
||||
$period = (new CarbonPeriod($start, $end))->count();
|
||||
return round($nbValidateCmd / $period, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of active clients (ordered in the period).
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getNbActiveClients(Carbon $start, Carbon $end)
|
||||
{
|
||||
return Customers::whereHas('orders', function (Builder $query) use ($start, $end) {
|
||||
$query->whereBetween('date', [$start->toDateString(), $end->toDateString()]);
|
||||
})->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number command where the collect day is 7 days after the order.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getNbCmdWith7DayDelay(Carbon $start, Carbon $end)
|
||||
{
|
||||
return Order::with('timeslot')->whereHas('status', function (Builder $query) {
|
||||
$query->whereIn('id', [3, 4, 5, 6]);
|
||||
})->whereBetween('date', [$start, $end])->get()->filter(function (Order $order) {
|
||||
return Carbon::create($order->timeslot->day)
|
||||
->lessThanOrEqualTo(Carbon::create($order->date)->modify('+7 day'));
|
||||
})->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number command where the collect day is 14 days after the order.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getNbCmdWith14DayDelay(Carbon $start, Carbon $end)
|
||||
{
|
||||
return Order::with('timeslot')->whereHas('status', function (Builder $query) {
|
||||
$query->whereIn('id', [3, 4, 5, 6]);
|
||||
})->whereBetween('date', [$start, $end])->get()->filter(function (Order $order) {
|
||||
return Carbon::create($order->timeslot->day)->betweenIncluded(
|
||||
Carbon::create($order->date)->modify('+8 day'),
|
||||
Carbon::create($order->date)->modify('+14 day')
|
||||
);
|
||||
})->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number command where the collect day is > 14 days after the order.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getNbCmdWithMoreThan14DayDelay(Carbon $start, Carbon $end)
|
||||
{
|
||||
return Order::with('timeslot')->whereHas('status', function (Builder $query) {
|
||||
$query->whereIn('id', [3, 4, 5, 6]);
|
||||
})->whereBetween('date', [$start, $end])->get()->filter(function (Order $order) {
|
||||
return Carbon::create($order->timeslot->day)
|
||||
->greaterThan(Carbon::create($order->date)->modify('+14 day'));
|
||||
})->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the CA HT.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getCaHt(Carbon $start, Carbon $end)
|
||||
{
|
||||
$orderedProducts = OrderLine::whereHas('order', function (Builder $query) use ($start, $end) {
|
||||
$query->whereHas('status', function (Builder $query) {
|
||||
$query->whereIn('id', [3, 4, 5, 6]);
|
||||
})->whereBetween('date', [$start->toDateString(), $end->toDateString()]);
|
||||
})->get();
|
||||
|
||||
$totalCaHt = 0;
|
||||
$orderedProducts->map(function ($item) use (&$totalCaHt) {
|
||||
$totalCaHt += $item->total_ht;
|
||||
});
|
||||
|
||||
return $totalCaHt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the average basket HT.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getAverageBasketHt(Carbon $start, Carbon $end)
|
||||
{
|
||||
// Prevent division by 0.
|
||||
if (self::getNbValidateCmd($start, $end) !== 0) {
|
||||
return round(self::getCaHt($start, $end) / self::getNbValidateCmd($start, $end), 2);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the average product count per order.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return mixed
|
||||
*/
|
||||
private function getAverageProductCountPerOrder(Carbon $start, Carbon $end)
|
||||
{
|
||||
$nbValidateCmd = self::getNbValidateCmd($start, $end);
|
||||
|
||||
// Prevent division by 0.
|
||||
if ($nbValidateCmd !== 0) {
|
||||
$orderedProducts = OrderLine::whereHas('order', function (Builder $query) use ($start, $end) {
|
||||
$query->whereHas('status', function (Builder $query) {
|
||||
$query->where('id', 3);
|
||||
})->whereBetween('date', [$start->toDateString(), $end->toDateString()]);
|
||||
})->get();
|
||||
|
||||
$totalQty = 0;
|
||||
$orderedProducts->map(function ($item) use (&$totalQty) {
|
||||
$totalQty += $item->quantity;
|
||||
});
|
||||
return round($totalQty / $nbValidateCmd, 2);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the previous period of the selected date.
|
||||
*
|
||||
* @param \Carbon\Carbon $start
|
||||
* @param \Carbon\Carbon $end
|
||||
* @return \Carbon\Carbon[$previousStart, $previousEnd]
|
||||
*/
|
||||
public static function getPreviousPeriod(Carbon $start, Carbon $end)
|
||||
{
|
||||
$diffDays = $start->copy()->diffInDays($end);
|
||||
return (object)[
|
||||
'start' => $start->copy()->subDays($diffDays + 1),
|
||||
'end' => $start->copy()->subDay()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -115,6 +115,16 @@ class Customers extends Authenticatable
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* HasMany orders relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function orders()
|
||||
{
|
||||
return $this->hasMany(Order::class, 'customer_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if customer is no longer employed
|
||||
*
|
||||
|
|
|
|||
|
|
@ -18,6 +18,15 @@ class Timeslot extends Model
|
|||
'order_id', 'magasin_id'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'day' => 'date',
|
||||
];
|
||||
|
||||
/**
|
||||
* BelongsTo order relation
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Timeslot;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class FormatDayInTimeslotsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('timeslots', function (Blueprint $table) {
|
||||
$table->date('date')->default('1999-01-01')->after('magasin_id');
|
||||
});
|
||||
foreach (Timeslot::all() as $timeslot) {
|
||||
// L'ancienne date est castée au format m/d/Y, une date FR comme le 30/06/2023 sera donc buguée.
|
||||
// On récupère l'ancienne date non castée et on en crée une date valide.
|
||||
$timeslot->date = Carbon::createFromFormat('d/m/Y', $timeslot->getRawOriginal('day'));
|
||||
$timeslot->save();
|
||||
}
|
||||
Schema::table('timeslots', function (Blueprint $table) {
|
||||
$table->dropColumn('day');
|
||||
$table->renameColumn('date', 'day');
|
||||
});
|
||||
// Not removing default above because it doesn't work.
|
||||
Schema::table('timeslots', function (Blueprint $table) {
|
||||
$table->date('day')->default(null)->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('timeslots', function (Blueprint $table) {
|
||||
$table->string('date')->after('magasin_id');
|
||||
});
|
||||
foreach (Timeslot::all() as $timeslot) {
|
||||
$timeslot->date = Carbon::create($timeslot->day)->format('d/m/Y');
|
||||
$timeslot->save();
|
||||
}
|
||||
Schema::table('timeslots', function (Blueprint $table) {
|
||||
$table->dropColumn('day');
|
||||
$table->renameColumn('date', 'day');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,142 @@
|
|||
@section('content')
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">Dashboard</h1>
|
||||
{{--<div class="btn-toolbar mb-2 mb-md-0">
|
||||
<a href="#" class="btn btn-sm btn-primary">##</a>
|
||||
</div>--}}
|
||||
</div>
|
||||
<div class="container">
|
||||
<table class="table table-responsive table-bordered">
|
||||
<thead>
|
||||
<tr class="text-center table-secondary">
|
||||
<th scope="col">{{ __('Nombre de salariés') }}</th>
|
||||
<th scope="col">{{ __('Nombre de salariés inscrits') }}</th>
|
||||
<th scope="col">{{ __('Taux d\'adhésion') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="text-center table-light text-bold fw-semibold">
|
||||
<td>{{ number_format(App\Models\Salarie::count(), 0, ",", " ") }}</td>
|
||||
<td>{{ number_format(App\Models\Customers::has('salarie')->count(), 0, ",", " ") }}</td>
|
||||
<td>{{ number_format($adhesion, 2, ",", " ") }} %</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br />
|
||||
<form action="{{ route('bo.dashboard') }}">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<label for="start">{{ __('Date de début') }}:</label>
|
||||
<input class="form-control" type="date" id="start" name="start" value="{{ request()->start }}" required/>
|
||||
@if (!empty($stats))
|
||||
<label for="previousStart">{{ __('Date de début de la période précédente') }}:</label>
|
||||
<input class="form-control" type="date" id="previousStart" name="previousStart" value="{{ $previousDates->start->toDateString() }}" aria-label="disabled input" disabled>
|
||||
@endif
|
||||
<br>
|
||||
</div>
|
||||
<div class="col">
|
||||
<label for="end">{{ __('Date de fin') }}:</label>
|
||||
<input class="form-control" type="date" id="end" name="end" value="{{ request()->end }}" required/>
|
||||
@if (!empty($stats))
|
||||
<label for="previousEnd">{{ __('Date de fin de la période précédente') }}:</label>
|
||||
<input class="form-control" type="date" id="previousEnd" name="previousEnd" value="{{ $previousDates->end->toDateString() }}" aria-label="disabled input" disabled>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col d-inline-flex align-items-center">
|
||||
<input class="btn btn-primary flex-end" type="submit" value="{{ __('Envoyer') }}" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<table class="table table-responsive table-bordered table-hover">
|
||||
<thead>
|
||||
<tr class="text-center bg-secondary bg-gradient bg-opacity-25">
|
||||
<th scope="col"></th>
|
||||
<th scope="col">{{ __('Période précédente') }}</th>
|
||||
<th scope="col">{{ __('Période actuelle') }}</th>
|
||||
<th scope="col">{{ __('Différence') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@if(!empty($stats))
|
||||
<tbody>
|
||||
@foreach ($stats as $k => $stat)
|
||||
<tr class="text-center">
|
||||
@if (
|
||||
$k === App\Enums\StatsType::nbWaitingCmd()->value ||
|
||||
$k === App\Enums\StatsType::nbCanceledCmd()->value ||
|
||||
$k === App\Enums\StatsType::canceledRate()->value ||
|
||||
$k === App\Enums\StatsType::orderFrequency()->value
|
||||
)
|
||||
<th @if ($stat['diff'] < 0) class="table-success" @else class="table-danger"@endif>{{ App\Enums\StatsType::make($k)->label }}</th>
|
||||
<td @if ($stat['diff'] < 0) class="table-success" @else class="table-danger"@endif>
|
||||
@switch($k)
|
||||
@case(App\Enums\StatsType::canceledRate()->value)
|
||||
{{ number_format($stat['previous'], 2, ",", " ") }} %
|
||||
@break
|
||||
@case(App\Enums\StatsType::orderFrequency()->value)
|
||||
{{ number_format($stat['previous'], 2, ",", " ") }} {{ __('jours') }}
|
||||
@break
|
||||
@default
|
||||
{{ str_replace(".", ",", $stat['previous']) }}
|
||||
@endswitch
|
||||
</td>
|
||||
<td @if ($stat['diff'] < 0) class="table-success" @else class="table-danger"@endif>
|
||||
@switch($k)
|
||||
@case(App\Enums\StatsType::canceledRate()->value)
|
||||
{{ number_format($stat['current'], 2, ",", " ") }} %
|
||||
@break
|
||||
@case(App\Enums\StatsType::orderFrequency()->value)
|
||||
{{ number_format($stat['current'], 2, ",", " ") }} {{ __('jours') }}
|
||||
@break
|
||||
@default
|
||||
{{ str_replace(".", ",", $stat['current']) }}
|
||||
@endswitch
|
||||
</td>
|
||||
<td @if ($stat['diff'] < 0) class="text-success table-success" @else class="text-danger table-danger" @endif>
|
||||
@switch($k)
|
||||
@case(App\Enums\StatsType::canceledRate()->value)
|
||||
<b>{{ number_format($stat['diff'], 2, ",", " ") }} %</b>
|
||||
@break
|
||||
@case(App\Enums\StatsType::orderFrequency()->value)
|
||||
<b>{{ number_format($stat['diff'], 2, ",", " ") }} {{ __('jours') }}</b>
|
||||
@break
|
||||
@default
|
||||
<b>{{ str_replace(".", ",", $stat['diff']) }}</b>
|
||||
@endswitch
|
||||
</td>
|
||||
@else
|
||||
<th @if ($stat['diff'] > 0) class="table-success" @else class="table-danger"@endif>{{ App\Enums\StatsType::make($k)->label }}</th>
|
||||
<td @if ($stat['diff'] > 0) class="table-success" @else class="table-danger"@endif>
|
||||
@switch($k)
|
||||
@case(App\Enums\StatsType::caHt()->value)
|
||||
@case(App\Enums\StatsType::averageBasketHt()->value)
|
||||
{{ number_format($stat['previous'], 2, ",", " ") }} €
|
||||
@break
|
||||
@default
|
||||
{{ str_replace(".", ",", $stat['previous']) }}
|
||||
@endswitch
|
||||
</td>
|
||||
<td @if ($stat['diff'] > 0) class="table-success" @else class="table-danger"@endif>
|
||||
@switch($k)
|
||||
@case(App\Enums\StatsType::caHt()->value)
|
||||
@case(App\Enums\StatsType::averageBasketHt()->value)
|
||||
{{ number_format($stat['current'], 2, ",", " ") }} €
|
||||
@break
|
||||
@default
|
||||
{{ str_replace(".", ",", $stat['current']) }}
|
||||
@endswitch
|
||||
</td>
|
||||
<td @if ($stat['diff'] > 0) class="text-success table-success" @else class="text-danger table-danger" @endif>
|
||||
@switch($k)
|
||||
@case(App\Enums\StatsType::caHt()->value)
|
||||
@case(App\Enums\StatsType::averageBasketHt()->value)
|
||||
<b>{{ number_format($stat['diff'], 2, ",", " ") }} €</b>
|
||||
@break
|
||||
@default
|
||||
<b>{{ str_replace(".", ",", $stat['diff']) }}</b>
|
||||
@endswitch
|
||||
</td>
|
||||
@endif
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@endif
|
||||
</table>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue