resolveBusiness($request); if (! $business) { return $this->jsonError('کسب‌وکار یافت نشد.', 404); } return $this->jsonSuccess( $this->reportService->equipmentCostReport($business, $request->integer('equipment_id') ?: null) ); } public function downtime(Request $request) { $business = $this->resolveBusiness($request); if (! $business) { return $this->jsonError('کسب‌وکار یافت نشد.', 404); } return $this->jsonSuccess( $this->reportService->downtimeReport($business, $request->get('from'), $request->get('to')) ); } public function technicianPerformance(Request $request) { $business = $this->resolveBusiness($request); if (! $business) { return $this->jsonError('کسب‌وکار یافت نشد.', 404); } return $this->jsonSuccess($this->reportService->technicianPerformance($business)); } public function sparePartsConsumption(Request $request) { $business = $this->resolveBusiness($request); if (! $business) { return $this->jsonError('کسب‌وکار یافت نشد.', 404); } return $this->jsonSuccess( $this->reportService->sparePartsConsumption($business, $request->get('from'), $request->get('to')) ); } public function monthly(Request $request) { $business = $this->resolveBusiness($request); if (! $business) { return $this->jsonError('کسب‌وکار یافت نشد.', 404); } return $this->jsonSuccess( $this->reportService->monthlyStatistics( $business, (int) $request->get('year', now()->year), (int) $request->get('month', now()->month) ) ); } public function failureAnalysis(Request $request) { $business = $this->resolveBusiness($request); if (! $business) { return $this->jsonError('کسب‌وکار یافت نشد.', 404); } return $this->jsonSuccess($this->reportService->failureAnalysis($business)); } public function history(Request $request, int $equipmentId) { $business = $this->resolveBusiness($request); if (! $business) { return $this->jsonError('کسب‌وکار یافت نشد.', 404); } $entries = HistoryEntry::where('business_id', $business->id) ->where('equipment_id', $equipmentId) ->with('performer:id,name') ->orderByDesc('performed_at') ->paginate((int) $request->get('per_page', 20)); return $this->jsonSuccess([ 'items' => $entries->items(), 'pagination' => [ 'total' => $entries->total(), 'per_page' => $entries->perPage(), 'current_page' => $entries->currentPage(), 'last_page' => $entries->lastPage(), ], ]); } }