50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\Dashboard\DashboardRequest;
|
|
use App\Models\Customer;
|
|
use App\Models\Employee;
|
|
use App\Services\StatsService;
|
|
use Domain\Enums\StatsCustomerType;
|
|
use Domain\Enums\StatsShopType;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
/**
|
|
* Dashboard Page
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function index(DashboardRequest $request, StatsService $statsService)
|
|
{
|
|
$statsShop = [];
|
|
$adhesion = $statsService->getMembershipPercentage();
|
|
$statsCustomer = [];
|
|
$prevDates = [];
|
|
|
|
$start = $request->getStart();
|
|
$end = $request->getEnd();
|
|
|
|
if ($start && $end) {
|
|
$prevDates = $statsService->getPreviousPeriod($start, $end);
|
|
$statsShop = $statsService->getStats(StatsShopType::cases(), $start, $end);
|
|
$statsCustomer = $statsService->getStats(StatsCustomerType::cases(), $start, $end);
|
|
}
|
|
|
|
$employeeCount = Employee::query()->count();
|
|
$customersLinkedToEmployeeCount = Customer::query()->has('employee')->count();
|
|
|
|
return view('bo.dashboard', compact(
|
|
'prevDates',
|
|
'statsShop',
|
|
'statsCustomer',
|
|
'adhesion',
|
|
'employeeCount',
|
|
'customersLinkedToEmployeeCount',
|
|
));
|
|
}
|
|
}
|