ultimatepos/app/Modules/Maintenance/Http/Controllers/Api/V1/MaintenanceDashboardController.php

47 lines
1.4 KiB
PHP

<?php
namespace App\Modules\Maintenance\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\Modules\Maintenance\Services\MaintenanceDashboardService;
use App\Modules\Maintenance\Traits\ResolvesBusiness;
use Illuminate\Http\Request;
class MaintenanceDashboardController extends Controller
{
use ResolvesBusiness;
public function __construct(
protected MaintenanceDashboardService $dashboardService
) {}
public function index(Request $request)
{
$business = $this->resolveBusiness($request);
if (! $business) {
return $this->jsonError('کسب‌وکار یافت نشد.', 404);
}
return $this->jsonSuccess([
'stats' => $this->dashboardService->getStats($business),
'recent_activities' => $this->dashboardService->getRecentActivities($business),
'charts' => $this->dashboardService->getChartData($business),
]);
}
public function calendar(Request $request)
{
$business = $this->resolveBusiness($request);
if (! $business) {
return $this->jsonError('کسب‌وکار یافت نشد.', 404);
}
$start = $request->get('start', now()->startOfMonth()->toDateString());
$end = $request->get('end', now()->endOfMonth()->toDateString());
return $this->jsonSuccess(
$this->dashboardService->getCalendarEvents($business, $start, $end)
);
}
}