From 053d0cdb966167e501d1fbd4cc8ac3f59ae7ee3a Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sat, 20 Dec 2025 16:00:55 +0330 Subject: [PATCH 1/2] create new report --- app/Enums/CmmsMachineStatus.php | 8 ++ .../V3/Dashboard/Mission/ReportController.php | 58 ++++++++++ .../Cartables/Mission/ReportService.php | 103 ++++++++++++++++++ routes/v3.php | 9 ++ 4 files changed, 178 insertions(+) create mode 100644 app/Http/Controllers/V3/Dashboard/Mission/ReportController.php create mode 100644 app/Services/Cartables/Mission/ReportService.php diff --git a/app/Enums/CmmsMachineStatus.php b/app/Enums/CmmsMachineStatus.php index b679da8f..f8539109 100644 --- a/app/Enums/CmmsMachineStatus.php +++ b/app/Enums/CmmsMachineStatus.php @@ -7,6 +7,10 @@ enum CmmsMachineStatus: int case AMADE= 1; case RESERVE = 2; case DAR_MAMORIAT = 3; + case KHAREGE_AZ_RADE = 4; + case DAR_TAMIR = 5 ; + case FOROKHTEH_SHODE = 6; + case NIZE_BE_TAMIR =7 ; public function label(): string { @@ -14,6 +18,10 @@ enum CmmsMachineStatus: int self::AMADE => 'آماده', self::RESERVE => 'رزرو', self::DAR_MAMORIAT => 'در ماموریت', + self::KHAREGE_AZ_RADE => 'خارج از محدوده', + self::DAR_TAMIR => 'در تعمیر', + self::FOROKHTEH_SHODE => ' فروخته شده', + self::NIZE_BE_TAMIR => 'نیاز به تعمیر', }; } } \ No newline at end of file diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ReportController.php b/app/Http/Controllers/V3/Dashboard/Mission/ReportController.php new file mode 100644 index 00000000..6685b30c --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/Mission/ReportController.php @@ -0,0 +1,58 @@ +successResponse([ + 'activities' => $reportrService->countryActivity($request), + 'provinces' => Province::all(['id', 'name_fa']), + ]); + } + +// public function provinceActivity(Request $request, OperatorService $operatorService): JsonResponse +// { +// +// $data = $operatorService->provinceActivity( +// $request, +// 90, +// ); +// +// return $this->successResponse([ +// 'activities' => $data, +// 'edarateShahri' => EdarateShahri::where('province_id', $request->province_id)->get(['id', 'name_fa']), +// ]); +// } +// +// public function countryExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse +// { +// $data = $operatorService->countryActivity(90, $request); +// $name = 'گزارش نگهداری حریم راه برای راه دسترسی غیر مجاز '.verta()->now()->format('Y-m-d H-i').'.xlsx'; +// +// return Excel::download(new ExcelReport($data), $name); +// } +// +// public function provinceExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse +// { +// $data = $operatorService->provinceActivity( +// $request, +// 90, +// ); +// $name = 'گزارش نگهداری حریم راه برای راه دسترسی غیر مجاز '.verta()->now()->format('Y-m-d H-i').'.xlsx'; +// +// return Excel::download(new AccessRoadReport($data, $request), $name); +// } +} diff --git a/app/Services/Cartables/Mission/ReportService.php b/app/Services/Cartables/Mission/ReportService.php new file mode 100644 index 00000000..03808c9a --- /dev/null +++ b/app/Services/Cartables/Mission/ReportService.php @@ -0,0 +1,103 @@ +user(); + + throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!')); + + $query = Mission::query()->where('edare_shahri_id', '=', $user->edarate_shahri_id); + + return DataTableFacade::run( + $query, + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + ); + } + + public function countryActivity(Request $request): array + { + $from = null; + $to = null; + + $filters = json_decode($request->filters ?? '[]', true); + + foreach ($filters as $filter) { + if (($filter['fn'] ?? null) === 'between' && ($filter['id'] ?? null) === 'created_at') { + $from = ($filter['value'][0] ?? null) ? ($filter['value'][0] . ' 00:00:00') : null; + $to = ($filter['value'][1] ?? null) ? ($filter['value'][1] . ' 23:59:59') : null; + break; + } + } + + $from ??= '1970-01-01 00:00:00'; + $to ??= now()->endOfDay()->toDateTimeString(); + + $sql = " + WITH r AS ( + SELECT + p.id, + p.name_fa AS province_name, + + COUNT(DISTINCT CASE + WHEN mv.type = 1 + AND mv.created_at BETWEEN :from AND :to + THEN mv.id + END) AS no_mission_count, + + COUNT(DISTINCT CASE + WHEN m.mission_duration != m.in_area_duration + AND m.created_at BETWEEN :from AND :to + THEN m.id + END) AS out_of_area_count + + FROM provinces p + LEFT JOIN cmms_machines cm + ON cm.province_id = p.id + LEFT JOIN mission_violations mv + ON TRIM(cm.machine_code) = TRIM(mv.machine_code) + LEFT JOIN missions m + ON m.province_id = p.id + + GROUP BY p.id, p.name_fa + ) + + SELECT + 'کل کشور' AS province_name, + SUM(no_mission_count) AS no_mission_count, + SUM(out_of_area_count) AS out_of_area_count + FROM r + + UNION ALL + + SELECT + province_name, no_mission_count, out_of_area_count + FROM r + + ORDER BY + CASE WHEN province_name = 'کل کشور' THEN 0 ELSE 1 END, + province_name + "; + + return DB::select($sql, [ + 'from' => $from, + 'to' => $to, + ]); + } + + public function provinceActivity(Request $request, int $info_id): array + { + // + } +} \ No newline at end of file diff --git a/routes/v3.php b/routes/v3.php index 01351520..e076ffde 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -527,6 +527,15 @@ Route::prefix('missions') ->group(function () { Route::get('/', 'index')->name('index'); }); + Route::prefix('report') + ->name('reports.') + ->controller(\App\Http\Controllers\V3\Dashboard\Mission\ReportController::class) + ->group(function () { + Route::get('/country_activity', 'countryActivity')->name('countryActivity'); + Route::get('/province_activity', 'provinceActivity')->name('provinceActivity'); + Route::get('/country_excel_activity', 'countryExcelActivity')->name('countryExcelActivity'); + Route::get('/province_excel_activity', 'provinceExcelActivity')->name('provinceExcelActivity'); + }); }); Route::prefix('harim') From 2c843eaeabe4c6a26266285ff8be068a711272fc Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sun, 21 Dec 2025 09:02:03 +0330 Subject: [PATCH 2/2] fix time --- .../Cartables/Mission/ReportService.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/app/Services/Cartables/Mission/ReportService.php b/app/Services/Cartables/Mission/ReportService.php index 03808c9a..1a50d4a6 100644 --- a/app/Services/Cartables/Mission/ReportService.php +++ b/app/Services/Cartables/Mission/ReportService.php @@ -28,21 +28,8 @@ class ReportService public function countryActivity(Request $request): array { - $from = null; - $to = null; - - $filters = json_decode($request->filters ?? '[]', true); - - foreach ($filters as $filter) { - if (($filter['fn'] ?? null) === 'between' && ($filter['id'] ?? null) === 'created_at') { - $from = ($filter['value'][0] ?? null) ? ($filter['value'][0] . ' 00:00:00') : null; - $to = ($filter['value'][1] ?? null) ? ($filter['value'][1] . ' 23:59:59') : null; - break; - } - } - - $from ??= '1970-01-01 00:00:00'; - $to ??= now()->endOfDay()->toDateTimeString(); + $from = $request->from_date ?? today()->startOfDay(); + $to = $request->to_date ?? today()->endOfDay(); $sql = " WITH r AS ( @@ -96,7 +83,7 @@ class ReportService ]); } - public function provinceActivity(Request $request, int $info_id): array + public function provinceActivity(Request $request, int $info_id) { // }