From 8da1ae1d74904baa0b634bf657d3c90857163126 Mon Sep 17 00:00:00 2001 From: faezeh Date: Wed, 17 Jun 2026 14:48:42 +0330 Subject: [PATCH 1/7] create new stracture for Report in mission and fix form request --- .../Report/ReportMachineController.php | 183 +++++------------- .../V3/Mission/ControlUnit/FinishRequest.php | 8 +- .../RequestPortal/ContinueMissionRequest.php | 8 +- .../V3/Mission/Violation/UpdateRequest.php | 8 +- .../Mission/Report/ReportMachineService.php | 179 +++++++---------- routes/v3.php | 18 +- 6 files changed, 144 insertions(+), 260 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index f39b46bf..55600232 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -8,14 +8,11 @@ use App\Exports\V3\Mission\Report\Machine\machineTypeReport; use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; -use App\Models\City; use App\Models\CMMSMachine; use App\Models\Mission; -use App\Models\Province; use App\Services\Cartables\Mission\Report\ReportMachineService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; use Maatwebsite\Excel\Facades\Excel; use PhpOffice\PhpSpreadsheet\Exception; use Symfony\Component\HttpFoundation\BinaryFileResponse; @@ -24,87 +21,7 @@ class ReportMachineController extends Controller { use ApiResponse; - public function countryMachinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse - { - return $this->successResponse([ - 'activities' => $reportMachineService->countryMachinesActivity($request), -// 'provinces' => Province::all(['id', 'name_fa']), - ]); - } - - /** - * @throws Exception - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception - */ - public function countryMachinesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse - { - $data = $reportMachineService->countryMachinesActivity($request); - $name = 'گزارش ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - - return Excel::download(new machineReport($data), $name); - } - - public function provinceMachinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse - { - return $this->successResponse([ - 'activities' => $reportMachineService->provinceMachinesActivity($request), -// 'city' => City::query() -// ->where('province_id', $request->province_id) -// ->where(function ($query) { -// $query->where('type_id', 1) -// ->orWhereIn('name_fa', ['اداره ماشين‌آلات', 'اداره نقلیه']); -// }) -// ->get(['id', 'name_fa']) - ]); - } - - /** - * @throws Exception - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception - */ - public function provinceMachinesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse - { - $data = $reportMachineService->provinceMachinesActivity($request); - $name = 'گزارش ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - - return Excel::download(new machineReport($data), $name); - } - - public function countryMachineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse - { - return $this->successResponse([ - 'activities' => $reportMachineService->countryMachineTypesActivity($request), -// 'provinces' => Province::all(['id', 'name_fa']), - ]); - } - - /** - * @throws Exception - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception - */ - public function countryMachineTypesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse - { - $data = $reportMachineService->countryMachineTypesActivity($request); - $name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - - return Excel::download(new machineTypeReport($data), $name); - } - - public function provinceMachineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse - { - return $this->successResponse([ - 'activities' => $reportMachineService->provinceMachineTypesActivity($request), -// 'city' => City::query() -// ->where('province_id', $request->province_id) -// ->where(function ($query) { -// $query->where('type_id', 1) -// ->orWhereIn('name_fa', ['اداره ماشين‌آلات', 'اداره نقلیه']); -// }) -// ->get(['id', 'name_fa']) - ]); - } - - public function machineDetailsReport(Request $request, int $machine_id) + public function machineDetailsReport(Request $request, int $machine_id): array { return DataTableFacade::run( Mission::query()->where('machine_id', '=', $machine_id), @@ -117,23 +34,10 @@ class ReportMachineController extends Controller ] ); } - - /** - * @throws Exception - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception - */ - public function provinceMachineTypesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse - { - $data = $reportMachineService->provinceMachineTypesActivity($request); - $name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - - return Excel::download(new machineTypeReport($data), $name); - } - - public function countryMachineDriversActivity(Request $request, ReportMachineService $reportMachineService) + public function machinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse { return $this->successResponse([ - 'activities' => $reportMachineService->countryMachineDriversActivity($request), + 'activities' => $reportMachineService->machinesActivity($request), // 'provinces' => Province::all(['id', 'name_fa']), ]); } @@ -142,25 +46,36 @@ class ReportMachineController extends Controller * @throws Exception * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - public function countryMachineDriversActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse - { - $data = $reportMachineService->countryMachineDriversActivity($request); - $name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - return Excel::download(new machineDriverReport($data), $name); + public function machinesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse + { + $data = $reportMachineService->machinesActivity($request); + $name = 'گزارش ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; + + return Excel::download(new machineReport($data), $name); } - public function provinceMachineDriversActivity(Request $request, ReportMachineService $reportMachineService) + + public function machineTypeDetailsReport(Request $request): array + { + $machineIds = CMMSMachine::query()->where('car_type', '=', $request->query('car_type'))->pluck('machine_id'); + return DataTableFacade::run( + Mission::query()->whereIn('machine_id', $machineIds), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedSelects: [ + 'id', 'province_id', 'province_name', 'city_id', 'city_name', + 'end_km', 'km', 'driver_name', 'state_name', 'station_name' + ] + ); + } + + public function machineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse { return $this->successResponse([ - 'activities' => $reportMachineService->provinceMachineDriversActivity($request), -// 'city' => City::query() -// ->where('province_id', $request->province_id) -// ->where(function ($query) { -// $query->where('type_id', 1) -// ->orWhereIn('name_fa', ['اداره ماشين‌آلات', 'اداره نقلیه']); -// }) -// ->get(['id', 'name_fa']) + 'activities' => $reportMachineService->machineTypesActivity($request), +// 'provinces' => Province::all(['id', 'name_fa']), ]); } @@ -168,30 +83,15 @@ class ReportMachineController extends Controller * @throws Exception * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - public function provinceMachineDriversActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse + public function machineTypesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse { - $data = $reportMachineService->provinceMachineDriversActivity($request); + $data = $reportMachineService->machineTypesActivity($request); $name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - return Excel::download(new machineDriverReport($data), $name); + return Excel::download(new machineTypeReport($data), $name); } - public function machineTypeDetailsReport(Request $request) - { - $machineIds = CMMSMachine::query()->where('car_type', '=', $request->query('car_type'))->pluck('machine_id'); - return DataTableFacade::run( - Mission::query()->whereIn('machine_id', $machineIds), - $request, - allowedFilters: ['*'], - allowedSortings: ['*'], - allowedSelects: [ - 'id', 'province_id', 'province_name', 'city_id', 'city_name', - 'end_km', 'km', 'driver_name', 'state_name', 'station_name' - ] - ); - } - - public function machineDriverDetailsReport(Request $request, int $driver_id) + public function machineDriverDetailsReport(Request $request, int $driver_id): array { return DataTableFacade::run( Mission::query()->where('driver_id', '=', $driver_id), @@ -204,4 +104,23 @@ class ReportMachineController extends Controller ] ); } + public function machineDriversActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse + { + return $this->successResponse([ + 'activities' => $reportMachineService->machineDriversActivity($request), +// 'provinces' => Province::all(['id', 'name_fa']), + ]); + } + + /** + * @throws Exception + * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + */ + public function machineDriversActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse + { + $data = $reportMachineService->machineDriversActivity($request); + $name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; + + return Excel::download(new machineDriverReport($data), $name); + } } diff --git a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php index b62c5124..c992a817 100644 --- a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php +++ b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php @@ -41,12 +41,18 @@ class FinishRequest extends FormRequest 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' ); } - if ($this->end_km < $mission->km) { + if ($this->end_km <= $mission->km) { $validator->errors()->add( 'end_km', 'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.' ); } + if (($this->end_km - $mission->km ) < 100) { + $validator->errors()->add( + 'end_km', + 'اختلاف کلیلومتر شروع و پایان نباید بیشتر از 100 کیلومتر باشد' + ); + } } ]; } diff --git a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php index 46fc0cea..a606f30c 100644 --- a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php +++ b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php @@ -57,7 +57,7 @@ class ContinueMissionRequest extends FormRequest ); } } - if ($this->end_km < $this->mission->km) { + if ($this->end_km <= $this->mission->km) { $validator->errors()->add( 'end_km', 'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.' @@ -69,6 +69,12 @@ class ContinueMissionRequest extends FormRequest 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' ); } + if (($this->end_km - $this->mission->km ) < 100) { + $validator->errors()->add( + 'end_km', + 'اختلاف کلیلومتر شروع و پایان نباید بیشتر از 100 کیلومتر باشد' + ); + } }, ]; } diff --git a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php index 561e2188..b2a66821 100644 --- a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php @@ -41,12 +41,18 @@ class UpdateRequest extends FormRequest 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' ); } - if ($this->end_km < $this->violation->km) { + if ($this->end_km <= $this->violation->km) { $validator->errors()->add( 'end_km', 'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.' ); } + if (($this->end_km - $this->violation->km ) < 100) { + $validator->errors()->add( + 'end_km', + 'اختلاف کلیلومتر شروع و پایان نباید بیشتر از 100 کیلومتر باشد' + ); + } } ]; } diff --git a/app/Services/Cartables/Mission/Report/ReportMachineService.php b/app/Services/Cartables/Mission/Report/ReportMachineService.php index 38bb4996..e1b83712 100644 --- a/app/Services/Cartables/Mission/Report/ReportMachineService.php +++ b/app/Services/Cartables/Mission/Report/ReportMachineService.php @@ -3,135 +3,88 @@ namespace App\Services\Cartables\Mission\Report; use App\Facades\DataTable\DataTableFacade; -use App\Models\MissionViolation; -use Carbon\Carbon; +use App\Models\Mission; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; class ReportMachineService { - public function countryMachinesActivity(Request $request): array + public function machinesActivity(Request $request): array { - $from = $request->from_date ?? today()->startOfDay(); - $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); + $query = Mission::query() + ->join('cmms_machines as cm', 'cm.id', '=', 'missions.machine_id') + ->where('state_id', '=', 4) + ->when($request->province_id, function ($q) use ($request) { + $q->where('missions.province_id', $request->province_id); + }) + ->selectRaw( + 'cm.car_name, + missions.machine_code, + missions.machine_id, + COUNT(*) as missions, + SUM(missions.end_km - missions.km) as func' + ) + ->groupBy('missions.machine_id') + ->orderByRaw('COUNT(*) DESC'); - $sql = "SELECT - m.machine_id, - m.machine_code, - cm.car_name, - COUNT(*) AS missions, - SUM(m.end_km - m.km) AS func - FROM missions m - JOIN cmms_machines cm ON cm.id = m.machine_id - WHERE m.state_id = 4 AND m.start_time >= :from AND m.finish_time <= :to - GROUP BY machine_id;"; + $fields = ['machine_code','machine_id','cm.car_name','missions', 'func']; - return DB::select($sql, [ - 'from' => $from, - 'to' => $to, - ]); + return DataTableFacade::run( + $query, + $request, + allowedFilters: $fields, + allowedSortings: $fields, + ); } - public function provinceMachinesActivity(Request $request): array + public function machineTypesActivity(Request $request): array { - $from = $request->from_date ?? today()->startOfDay(); - $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); - $province = $request->province_id; + $query = Mission::query() + ->join('cmms_machines as cm', 'cm.id', '=', 'missions.machine_id') + ->where('missions.state_id','=', 4) + ->when($request->province_id, function ($q) use ($request) { + $q->where('missions.province_id', $request->province_id); + }) + ->selectRaw( + 'cm.car_type, + COUNT(*) as missions, + SUM(missions.end_km - missions.km) as func' + ) + ->groupBy('cm.car_type') + ->orderByRaw('COUNT(*) DESC'); - $sql = "SELECT m.machine_id, m.machine_code, cm.car_name, COUNT(*) AS missions, SUM(m.end_km - m.km) AS func - FROM missions m - JOIN cmms_machines cm ON cm.id = m.machine_id - WHERE m.state_id = 4 AND start_time >= :from AND finish_time <= :to AND m.province_id = :province_id - GROUP BY machine_id;"; + $fields = ['car_type','missions', 'func']; - return DB::select($sql, [ - 'from' => $from, - 'to' => $to, - 'province_id' => $province, - ]); + return DataTableFacade::run( + $query, + $request, + allowedFilters: $fields, + allowedSortings: $fields, + ); } - public function countryMachineTypesActivity(Request $request): array + public function machineDriversActivity(Request $request): array { - $from = $request->from_date ?? today()->startOfDay(); - $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); + $query = Mission::query() + ->selectRaw( + 'driver_id, + driver_name, + COUNT(*) as missions, + SUM(end_km - km) as func' + ) + ->where('state_id', '=', 4) + ->when($request->province_id, function ($query) use ($request) { + $query->where('province_id', '=', $request->province_id); + }) + ->groupBy('driver_id') + ->orderBy('COUNT(*) desc'); - $sql = "SELECT - cm.car_type, - COUNT(*) AS missions, - SUM(m.end_km - m.km) AS func - FROM missions m - JOIN cmms_machines cm ON cm.id = m.machine_id - WHERE m.state_id = 4 AND m.start_time >= :from AND m.finish_time <= :to - GROUP BY cm.car_type;"; + $fields = ['driver_id','driver_name','missions', 'func']; - return DB::select($sql, [ - 'from' => $from, - 'to' => $to, - ]); - } - - public function provinceMachineTypesActivity(Request $request): array - { - $from = $request->from_date ?? today()->startOfDay(); - $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); - $province = $request->province_id; - - $sql = "SELECT - cm.car_type, - COUNT(*) AS missions, - SUM(m.end_km - m.km) AS func - FROM missions m - JOIN cmms_machines cm ON cm.id = m.machine_id - WHERE m.state_id = 4 AND m.start_time >= :from AND m.finish_time <= :to AND m.province_id = :province_id - GROUP BY cm.car_type;"; - - return DB::select($sql, [ - 'from' => $from, - 'to' => $to, - 'province_id' => $province, - ]); - } - - public function countryMachineDriversActivity(Request $request): array - { - $from = $request->from_date ?? today()->startOfDay(); - $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); - - $sql = "SELECT - m.driver_id, - m.driver_name, - COUNT(*) AS missions, - SUM(m.end_km - m.km) AS func - FROM missions m - WHERE m.state_id = 4 AND m.start_time >= :from AND m.finish_time <= :to - GROUP BY m.driver_id;"; - - return DB::select($sql, [ - 'from' => $from, - 'to' => $to, - ]); - } - - public function provinceMachineDriversActivity(Request $request): array - { - $from = $request->from_date ?? today()->startOfDay(); - $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); - $province = $request->province_id; - - $sql = "SELECT - m.driver_id, - m.driver_name, - COUNT(*) AS missions, - SUM(m.end_km - m.km) AS func - FROM missions m - WHERE m.state_id = 4 AND m.start_time >= :from AND m.finish_time <= :to AND province_id = :province_id - GROUP BY m.driver_id;"; - - return DB::select($sql, [ - 'from' => $from, - 'to' => $to, - 'province_id' => $province, - ]); + return DataTableFacade::run( + $query, + $request, + allowedFilters: $fields, + allowedSortings: $fields, + ); } } diff --git a/routes/v3.php b/routes/v3.php index 6c67a1d0..3bca0def 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -566,18 +566,12 @@ Route::prefix('missions') ->middleware(['permission:mission-report-province|mission-report-country']) ->controller(ReportMachineController::class) ->group(function () { - Route::get('/country_machines_activity', 'countryMachinesActivity')->name('countryMachinesActivity'); - Route::get('/country_machines_activity_excel', 'countryMachinesActivityExcel')->name('countryMachinesActivityExcel'); - Route::get('/province_machines_activity', 'provinceMachinesActivity')->name('provinceMachinesActivity'); - Route::get('/province_machines_activity_excel', 'provinceMachinesActivityExcel')->name('provinceMachinesActivityExcel'); - Route::get('/country_machine_types_activity', 'countryMachineTypesActivity')->name('countryMachineTypesActivity'); - Route::get('/country_machine_types_activity_excel', 'countryMachineTypesActivityExcel')->name('countryMachineTypesActivityExcel'); - Route::get('/province_machine_types_activity', 'provinceMachineTypesActivity')->name('provinceMachineTypesActivity'); - Route::get('/province_machine_types_activity_excel', 'provinceMachineTypesActivityExcel')->name('provinceMachineTypesActivityExcel'); - Route::get('/country_machine_drivers_activity', 'countryMachineDriversActivity')->name('countryMachineDriversActivity'); - Route::get('/country_machine_drivers_activity_excel', 'countryMachineDriversActivityExcel')->name('countryMachineDriversActivityExcel'); - Route::get('/province_machine_drivers_activity', 'provinceMachineDriversActivity')->name('provinceMachineDriversActivity'); - Route::get('/province_machine_drivers_activity_excel', 'provinceMachineDriversActivityExcel')->name('provinceMachineDriversActivityExcel'); + Route::get('/machines_activity', 'machinesActivity')->name('machinesActivity'); + Route::get('/machines_activity_excel', 'machinesActivityExcel')->name('machinesActivityExcel'); + Route::get('/machine_types_activity', 'machineTypesActivity')->name('machineTypesActivity'); + Route::get('/machine_types_activity_excel', 'machineTypesActivityExcel')->name('machineTypesActivityExcel'); + Route::get('/machine_drivers_activity', 'machineDriversActivity')->name('machineDriversActivity'); + Route::get('/machine_drivers_activity_excel', 'machineDriversActivityExcel')->name('machineDriversActivityExcel'); Route::get('/machine_details_report/{machine_id}', 'machineDetailsReport')->name('machineDetailsReport'); Route::get('/machine_driver_details_report/{driver_id}', 'machineDriverDetailsReport')->name('machineDriverDetailsReport'); Route::get('/machine_type_details_report', ' machineTypeDetailsReport')->name('machineTypeDetailsReport'); From 6fc073c7e82854421d6a3d35303efc664d021832 Mon Sep 17 00:00:00 2001 From: faezeh Date: Wed, 17 Jun 2026 15:19:34 +0330 Subject: [PATCH 2/7] fix service machine --- app/Services/Cartables/Mission/Report/ReportMachineService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/Cartables/Mission/Report/ReportMachineService.php b/app/Services/Cartables/Mission/Report/ReportMachineService.php index e1b83712..5ebd8e00 100644 --- a/app/Services/Cartables/Mission/Report/ReportMachineService.php +++ b/app/Services/Cartables/Mission/Report/ReportMachineService.php @@ -76,7 +76,7 @@ class ReportMachineService $query->where('province_id', '=', $request->province_id); }) ->groupBy('driver_id') - ->orderBy('COUNT(*) desc'); + ->orderByRaw('COUNT(*) DESC'); $fields = ['driver_id','driver_name','missions', 'func']; From da82c7841bd0b9db9c4f38eefa952b5a23fc537d Mon Sep 17 00:00:00 2001 From: faezeh Date: Sat, 27 Jun 2026 17:07:13 +0330 Subject: [PATCH 3/7] create excel for report --- .../Report/Machine/machineDetailsReport.php | 77 ++++++++ .../Machine/machineDriverDetailsReport.php | 78 ++++++++ .../Machine/machineTypeDetailsReport.php | 77 ++++++++ .../Report/ReportMachineController.php | 170 +++++------------- .../V3/Mission/ControlUnit/FinishRequest.php | 30 +++- .../TransportaionUnit/AllocateRequest.php | 2 +- .../Mission/Report/ReportMachineService.php | 43 +++++ .../Machine/ActivityDetailsReport.blade.php | 94 ++++++++++ .../MachineDriverDetailsReport.blade.php | 94 ++++++++++ .../MachineTypeDetailsReport.blade.php | 94 ++++++++++ routes/v3.php | 6 +- 11 files changed, 635 insertions(+), 130 deletions(-) create mode 100644 app/Exports/V3/Mission/Report/Machine/machineDetailsReport.php create mode 100644 app/Exports/V3/Mission/Report/Machine/machineDriverDetailsReport.php create mode 100644 app/Exports/V3/Mission/Report/Machine/machineTypeDetailsReport.php create mode 100644 resources/views/v3/Reports/Mission/Report/Machine/ActivityDetailsReport.blade.php create mode 100644 resources/views/v3/Reports/Mission/Report/Machine/MachineDriverDetailsReport.blade.php create mode 100644 resources/views/v3/Reports/Mission/Report/Machine/MachineTypeDetailsReport.blade.php diff --git a/app/Exports/V3/Mission/Report/Machine/machineDetailsReport.php b/app/Exports/V3/Mission/Report/Machine/machineDetailsReport.php new file mode 100644 index 00000000..d20226a3 --- /dev/null +++ b/app/Exports/V3/Mission/Report/Machine/machineDetailsReport.php @@ -0,0 +1,77 @@ +data as $r) { + $exportRows[] = [ + 'id' => $r->id, + 'province_name' => $r->province_name, + 'city_name' => $r->city_name, + 'station_name' => $r->station_name ?? 0, + 'driver_name' => $r->driver_name ?? '', + 'km' => $r->km ?? '', + 'end_km' => $r->end_km ?? '', + ]; + } + + return view('v3.Reports.Mission.Report.Machine.ActivityDetailsReport', [ + 'rows' => $exportRows, + ]); + } + + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + $event->sheet->getDelegate()->setRightToLeft(true); + }, + ]; + } + + /** + * @throws Exception + */ + public function drawings(): array + { + $drawing = new Drawing(); + $drawing->setName('Logo'); + $drawing->setDescription('This is my logo'); + $drawing->setPath(public_path('/dist/logo.png')); + $drawing->setWidth(50); + $drawing->setHeight(50); + $drawing->setOffsetX(5); + $drawing->setOffsetY(5); + $drawing->setCoordinates('A1'); + + $drawing2 = new Drawing(); + $drawing2->setName('Logo'); + $drawing2->setDescription('This is my logo'); + $drawing2->setPath(public_path('/dist/141icon.png')); + $drawing2->setWidth(50); + $drawing2->setHeight(50); + $drawing2->setOffsetX(+90); + $drawing2->setOffsetY(5); + $drawing2->setCoordinates('E1'); + + return [$drawing, $drawing2]; + } +} diff --git a/app/Exports/V3/Mission/Report/Machine/machineDriverDetailsReport.php b/app/Exports/V3/Mission/Report/Machine/machineDriverDetailsReport.php new file mode 100644 index 00000000..c983c023 --- /dev/null +++ b/app/Exports/V3/Mission/Report/Machine/machineDriverDetailsReport.php @@ -0,0 +1,78 @@ +data as $r) { + $exportRows[] = [ + 'id' => $r->id, + 'province_name' => $r->province_name, + 'city_name' => $r->city_name, + 'station_name' => $r->station_name ?? 0, + 'driver_name' => $r->driver_name ?? '', + 'km' => $r->km ?? '', + 'end_km' => $r->end_km ?? '', + + ]; + } + + return view('v3.Reports.Mission.Report.Machine.MachineDriverDetailsReport', [ + 'rows' => $exportRows, + ]); + } + + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + $event->sheet->getDelegate()->setRightToLeft(true); + }, + ]; + } + + /** + * @throws Exception + */ + public function drawings(): array + { + $drawing = new Drawing(); + $drawing->setName('Logo'); + $drawing->setDescription('This is my logo'); + $drawing->setPath(public_path('/dist/logo.png')); + $drawing->setWidth(50); + $drawing->setHeight(50); + $drawing->setOffsetX(5); + $drawing->setOffsetY(5); + $drawing->setCoordinates('A1'); + + $drawing2 = new Drawing(); + $drawing2->setName('Logo'); + $drawing2->setDescription('This is my logo'); + $drawing2->setPath(public_path('/dist/141icon.png')); + $drawing2->setWidth(50); + $drawing2->setHeight(50); + $drawing2->setOffsetX(+90); + $drawing2->setOffsetY(5); + $drawing2->setCoordinates('D1'); + + return [$drawing, $drawing2]; + } +} diff --git a/app/Exports/V3/Mission/Report/Machine/machineTypeDetailsReport.php b/app/Exports/V3/Mission/Report/Machine/machineTypeDetailsReport.php new file mode 100644 index 00000000..668d9491 --- /dev/null +++ b/app/Exports/V3/Mission/Report/Machine/machineTypeDetailsReport.php @@ -0,0 +1,77 @@ +data as $r) { + $exportRows[] = [ + 'id' => $r->id, + 'province_name' => $r->province_name, + 'city_name' => $r->city_name, + 'station_name' => $r->station_name ?? 0, + 'driver_name' => $r->driver_name ?? '', + 'km' => $r->km ?? '', + 'end_km' => $r->end_km ?? '', + ]; + } + + return view('v3.Reports.Mission.Report.Machine.MachineTypeDetailsReport', [ + 'rows' => $exportRows, + ]); + } + + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + $event->sheet->getDelegate()->setRightToLeft(true); + }, + ]; + } + + /** + * @throws Exception + */ + public function drawings(): array + { + $drawing = new Drawing(); + $drawing->setName('Logo'); + $drawing->setDescription('This is my logo'); + $drawing->setPath(public_path('/dist/logo.png')); + $drawing->setWidth(50); + $drawing->setHeight(50); + $drawing->setOffsetX(5); + $drawing->setOffsetY(5); + $drawing->setCoordinates('A1'); + + $drawing2 = new Drawing(); + $drawing2->setName('Logo'); + $drawing2->setDescription('This is my logo'); + $drawing2->setPath(public_path('/dist/141icon.png')); + $drawing2->setWidth(50); + $drawing2->setHeight(50); + $drawing2->setOffsetX(+90); + $drawing2->setOffsetY(5); + $drawing2->setCoordinates('C1'); + + return [$drawing, $drawing2]; + } +} diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index 888071cf..ae9bbcc1 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -2,14 +2,14 @@ namespace App\Http\Controllers\V3\Dashboard\Mission\Report; +use App\Exports\V3\Mission\Report\Machine\machineDetailsReport; +use App\Exports\V3\Mission\Report\Machine\machineDriverDetailsReport; use App\Exports\V3\Mission\Report\Machine\machineDriverReport; use App\Exports\V3\Mission\Report\Machine\machineReport; +use App\Exports\V3\Mission\Report\Machine\machineTypeDetailsReport; use App\Exports\V3\Mission\Report\Machine\machineTypeReport; -use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; -use App\Models\CMMSMachine; -use App\Models\Mission; use App\Services\Cartables\Mission\Report\ReportMachineService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -21,113 +21,26 @@ class ReportMachineController extends Controller { use ApiResponse; - public function countryMachinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse + public function machineDetailsReport(Request $request, ReportMachineService $reportMachineService,int $machine_id): JsonResponse { - return $this->successResponse([ - 'activities' => $reportMachineService->countryMachinesActivity($request), -// 'provinces' => Province::all(['id', 'name_fa']), - ]); + $data = $reportMachineService->dataTableMachinesActivity($request,$machine_id); + + return response()->json($data); } /** * @throws Exception * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - public function countryMachinesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse + public function machineDetailsReportExcel(Request $request, int $machine_id, ReportMachineService $reportMachineService): BinaryFileResponse { - $data = $reportMachineService->countryMachinesActivity($request); - $name = 'گزارش ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; + $data = $reportMachineService->dataTableMachinesActivity($request,$machine_id); + $name = 'گزارش عملکرد ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - return Excel::download(new machineReport($data), $name); + return Excel::download(new machineDetailsReport($data['data']), $name); } - public function provinceMachinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse - { - return $this->successResponse([ - 'activities' => $reportMachineService->provinceMachinesActivity($request), -// 'city' => City::query() -// ->where('province_id', $request->province_id) -// ->where(function ($query) { -// $query->where('type_id', 1) -// ->orWhereIn('name_fa', ['اداره ماشين‌آلات', 'اداره نقلیه']); -// }) -// ->get(['id', 'name_fa']) - ]); - } - - /** - * @throws Exception - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception - */ - public function provinceMachinesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse - { - $data = $reportMachineService->provinceMachinesActivity($request); - $name = 'گزارش ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - - return Excel::download(new machineReport($data), $name); - } - - public function countryMachineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse - { - return $this->successResponse([ - 'activities' => $reportMachineService->countryMachineTypesActivity($request), -// 'provinces' => Province::all(['id', 'name_fa']), - ]); - } - - /** - * @throws Exception - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception - */ - public function countryMachineTypesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse - { - $data = $reportMachineService->countryMachineTypesActivity($request); - $name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - - return Excel::download(new machineTypeReport($data), $name); - } - - public function provinceMachineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse - { - return $this->successResponse([ - 'activities' => $reportMachineService->provinceMachineTypesActivity($request), -// 'city' => City::query() -// ->where('province_id', $request->province_id) -// ->where(function ($query) { -// $query->where('type_id', 1) -// ->orWhereIn('name_fa', ['اداره ماشين‌آلات', 'اداره نقلیه']); -// }) -// ->get(['id', 'name_fa']) - ]); - } - - public function machineDetailsReport(Request $request, int $machine_id) - { - return DataTableFacade::run( - Mission::query()->where('machine_id', '=', $machine_id), - $request, - allowedFilters: ['*'], - allowedSortings: ['*'], - allowedSelects: [ - 'id', 'province_id', 'province_name', 'city_id', 'city_name', - 'end_km', 'km', 'driver_name', 'state_id', 'station_name' - ] - ); - } - - /** - * @throws Exception - * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception - */ - public function provinceMachineTypesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse - { - $data = $reportMachineService->provinceMachineTypesActivity($request); - $name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - - return Excel::download(new machineTypeReport($data), $name); - } - - public function countryMachineDriversActivity(Request $request, ReportMachineService $reportMachineService) + public function machinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse { return $this->successResponse([ 'activities' => $reportMachineService->machinesActivity($request), @@ -149,19 +62,23 @@ class ReportMachineController extends Controller } - public function machineTypeDetailsReport(Request $request): array + public function machineTypeDetailsReport(Request $request, ReportMachineService $reportMachineService,int $car_type): JsonResponse { - $machineIds = CMMSMachine::query()->where('car_type', '=', $request->query('car_type'))->pluck('machine_id'); - return DataTableFacade::run( - Mission::query()->whereIn('machine_id', $machineIds), - $request, - allowedFilters: ['*'], - allowedSortings: ['*'], - allowedSelects: [ - 'id', 'province_id', 'province_name', 'city_id', 'city_name', - 'end_km', 'km', 'driver_name', 'state_name', 'station_name' - ] - ); + $data = $reportMachineService->dataTableMachineTypesActivity($request,$car_type); + + return response()->json($data); + } + + /** + * @throws Exception + * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + */ + public function machineTypeDetailsReportExcel(Request $request, ReportMachineService $reportMachineService,int $car_type): BinaryFileResponse + { + $data = $reportMachineService->dataTableMachineTypesActivity($request,$car_type); + $name = 'گزارش عملکردیک نوع ماشین'.verta()->now()->format('Y-m-d H-i').'.xlsx'; + + return Excel::download(new machineTypeDetailsReport($data['data']), $name); } public function machineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse @@ -184,19 +101,26 @@ class ReportMachineController extends Controller return Excel::download(new machineTypeReport($data), $name); } - public function machineDriverDetailsReport(Request $request, int $driver_id): array + public function machineDriverDetailsReport(Request $request, int $driver_id, ReportMachineService $reportMachineService): JsonResponse { - return DataTableFacade::run( - Mission::query()->where('driver_id', '=', $driver_id), - $request, - allowedFilters: ['*'], - allowedSortings: ['*'], - allowedSelects: [ - 'id', 'province_id', 'province_name', 'city_id', 'city_name', - 'end_km', 'km', 'driver_name', 'state_id', 'station_name' - ] - ); + $data = $reportMachineService->dataTableMachineDriversActivity($request,$driver_id); + + return response()->json($data); } + + /** + * @throws Exception + * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + */ + public function machineDriverDetailsReportExcel(Request $request, int $driver_id, ReportMachineService $reportMachineService): BinaryFileResponse + { + $data = $reportMachineService->dataTableMachineDriversActivity($request,$driver_id); + $name = 'گزارش عملکرد راننده'.verta()->now()->format('Y-m-d H-i').'.xlsx'; + + return Excel::download( + new machineDriverDetailsReport($data['data']), $name); + } + public function machineDriversActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse { return $this->successResponse([ @@ -216,4 +140,4 @@ class ReportMachineController extends Controller return Excel::download(new machineDriverReport($data), $name); } -} +} \ No newline at end of file diff --git a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php index c992a817..9d9890e8 100644 --- a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php +++ b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests\V3\Mission\ControlUnit; use App\Enums\MissionStates; +use App\Models\CMMSMachine; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Validator; @@ -34,6 +35,7 @@ class FinishRequest extends FormRequest { return [ function (Validator $validator) { + $mission = $this->mission; if (strtotime($this->time) < strtotime($mission->start_time)) { $validator->errors()->add( @@ -41,17 +43,35 @@ class FinishRequest extends FormRequest 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' ); } + if ($this->end_km <= $mission->km) { $validator->errors()->add( 'end_km', 'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.' ); } - if (($this->end_km - $mission->km ) < 100) { - $validator->errors()->add( - 'end_km', - 'اختلاف کلیلومتر شروع و پایان نباید بیشتر از 100 کیلومتر باشد' - ); + + $machine = CMMSMachine::find($mission->machine_id); + + $distance = $this->end_km - $mission->km; + + if ($machine->car_group === 'سنگین') { + + if ($distance > 15) { + $validator->errors()->add( + 'end_km', + 'اختلاف کیلومتر برای خودروهای سنگین باید کمتر از 15 باشد.' + ); + } + + } else { + + if ($distance > 1000) { + $validator->errors()->add( + 'end_km', + 'اختلاف کیلومتر برای خودروهای سبک و نیمه سنگین باید کمتر از 1000 باشد.' + ); + } } } ]; diff --git a/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php b/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php index af14fad9..3b89dca0 100644 --- a/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php +++ b/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php @@ -15,7 +15,7 @@ class AllocateRequest extends FormRequest */ public function authorize(): bool { - return $this->mission->station_id == auth()->user()->station_id && $this->mission->state_id == MissionStates::REQUEST_CREATED->value + return ($this->mission->station_id == auth()->user()->station_id && $this->mission->state_id == MissionStates::REQUEST_CREATED->value) || auth()->user()->username === 'witel'; } diff --git a/app/Services/Cartables/Mission/Report/ReportMachineService.php b/app/Services/Cartables/Mission/Report/ReportMachineService.php index 1d7a80e3..58f65c82 100644 --- a/app/Services/Cartables/Mission/Report/ReportMachineService.php +++ b/app/Services/Cartables/Mission/Report/ReportMachineService.php @@ -3,11 +3,25 @@ namespace App\Services\Cartables\Mission\Report; use App\Facades\DataTable\DataTableFacade; +use App\Models\CMMSMachine; use App\Models\Mission; use Illuminate\Http\Request; class ReportMachineService { + public function dataTableMachinesActivity(Request $request, int $machine_id): array + { + return DataTableFacade::run( + Mission::query()->where('machine_id', '=', $machine_id), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedSelects: [ + 'id', 'province_id', 'province_name', 'city_id', 'city_name', + 'end_km', 'km', 'driver_name', 'state_id', 'station_name' + ] + ); + } public function machinesActivity(Request $request): array { $query = Mission::query() @@ -35,6 +49,21 @@ class ReportMachineService ); } + public function dataTableMachineTypesActivity(Request $request,int $car_type): array + { + $machineIds = CMMSMachine::query()->where('car_type', '=', $request->query('car_type'))->pluck('machine_id'); + return DataTableFacade::run( + Mission::query()->whereIn('machine_id', $machineIds), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedSelects: [ + 'id', 'province_id', 'province_name', 'city_id', 'city_name', + 'end_km', 'km', 'driver_name', 'state_name', 'station_name' + ] + ); + } + public function machineTypesActivity(Request $request): array { $query = Mission::query() @@ -61,6 +90,20 @@ class ReportMachineService ); } + public function dataTableMachineDriversActivity(Request $request,int $driver_id): array + { + return DataTableFacade::run( + Mission::query()->where('driver_id', '=', $driver_id), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedSelects: [ + 'id', 'province_id', 'province_name', 'city_id', 'city_name', + 'end_km', 'km', 'driver_name', 'state_id', 'station_name' + ] + ); + } + public function machineDriversActivity(Request $request): array { $query = Mission::query() diff --git a/resources/views/v3/Reports/Mission/Report/Machine/ActivityDetailsReport.blade.php b/resources/views/v3/Reports/Mission/Report/Machine/ActivityDetailsReport.blade.php new file mode 100644 index 00000000..1f187fb4 --- /dev/null +++ b/resources/views/v3/Reports/Mission/Report/Machine/ActivityDetailsReport.blade.php @@ -0,0 +1,94 @@ + + + + + + + + گزارش کل تردد های یک ماشین + + + + + +@php + // show a dot if key missing or value is 0/empty + function cell($row, $key) { + return array_key_exists($key, $row) ? ($row[$key] ?: '0') : '0'; + } +@endphp + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($rows as $item) + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ گزارش ماشین های ماموریت رفته +
+ کد یکتا + + استان + + شهر + راهدارخانه + + نام راننده + + کیلومتر شروع + + کیلومتر پایان
{{ $item['id'] ?? '-' }}{{ $item['province_name'] ?? '-' }}{{ $item['city_name'] ?? '-' }}{{ $item['station_name'] ?? '-' }}{{ $item['driver_name'] ?? '-' }}{{ $item['km'] ?? '-' }}{{ $item['end_km'] ?? '-' }}
+ + diff --git a/resources/views/v3/Reports/Mission/Report/Machine/MachineDriverDetailsReport.blade.php b/resources/views/v3/Reports/Mission/Report/Machine/MachineDriverDetailsReport.blade.php new file mode 100644 index 00000000..49d0b218 --- /dev/null +++ b/resources/views/v3/Reports/Mission/Report/Machine/MachineDriverDetailsReport.blade.php @@ -0,0 +1,94 @@ + + + + + + + + گزارش کل تردد های راننده + + + + + +@php + // show a dot if key missing or value is 0/empty + function cell($row, $key) { + return array_key_exists($key, $row) ? ($row[$key] ?: '0') : '0'; + } +@endphp + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($rows as $item) + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ گزارش عملکرد راندده در ماموریت +
+ کد یکتا + + استان + + شهر + راهدارخانه + + نام راننده + + کیلومتر شروع + + کیلومتر پایان
{{ $item['id'] ?? '-' }}{{ $item['province_name'] ?? '-' }}{{ $item['city_name'] ?? '-' }}{{ $item['station_name'] ?? '-' }}{{ $item['driver_name'] ?? '-' }}{{ $item['km'] ?? '-' }}{{ $item['end_km'] ?? '-' }}
+ + diff --git a/resources/views/v3/Reports/Mission/Report/Machine/MachineTypeDetailsReport.blade.php b/resources/views/v3/Reports/Mission/Report/Machine/MachineTypeDetailsReport.blade.php new file mode 100644 index 00000000..9a1b549b --- /dev/null +++ b/resources/views/v3/Reports/Mission/Report/Machine/MachineTypeDetailsReport.blade.php @@ -0,0 +1,94 @@ + + + + + + + + گزارش ترددهای انواع ماشین ها + + + + + +@php + // show a dot if key missing or value is 0/empty + function cell($row, $key) { + return array_key_exists($key, $row) ? ($row[$key] ?: '0') : '0'; + } +@endphp + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach ($rows as $item) + + + + + + + + + + @endforeach + +
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }} +
+
+ گزارش نوع ماشین هادرماموریت +
+ کد یکتا + + استان + + شهر + راهدارخانه + + نام راننده + + کیلومتر شروع + + کیلومتر پایان
{{ $item['id'] ?? '-' }}{{ $item['province_name'] ?? '-' }}{{ $item['city_name'] ?? '-' }}{{ $item['station_name'] ?? '-' }}{{ $item['driver_name'] ?? '-' }}{{ $item['km'] ?? '-' }}{{ $item['end_km'] ?? '-' }}
+ + diff --git a/routes/v3.php b/routes/v3.php index 3bca0def..d05afc2f 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -568,13 +568,17 @@ Route::prefix('missions') ->group(function () { Route::get('/machines_activity', 'machinesActivity')->name('machinesActivity'); Route::get('/machines_activity_excel', 'machinesActivityExcel')->name('machinesActivityExcel'); + Route::get('/machine_types_activity', 'machineTypesActivity')->name('machineTypesActivity'); Route::get('/machine_types_activity_excel', 'machineTypesActivityExcel')->name('machineTypesActivityExcel'); Route::get('/machine_drivers_activity', 'machineDriversActivity')->name('machineDriversActivity'); Route::get('/machine_drivers_activity_excel', 'machineDriversActivityExcel')->name('machineDriversActivityExcel'); Route::get('/machine_details_report/{machine_id}', 'machineDetailsReport')->name('machineDetailsReport'); + Route::get('/machine_details_report_excel/{machine_id}', 'machineDetailsReportExcel')->name('machineDetailsReportExcel'); + Route::get('/machine_type_details_report/{car_type}', 'machineTypeDetailsReport')->name('machineTypeDetailsReport'); + Route::get('/machine_type_details_report_excel/{car_type}', 'Excel')->name('machineTypeDetailsReportExcel'); Route::get('/machine_driver_details_report/{driver_id}', 'machineDriverDetailsReport')->name('machineDriverDetailsReport'); - Route::get('/machine_type_details_report', ' machineTypeDetailsReport')->name('machineTypeDetailsReport'); + Route::get('/machine_driver_details_report_excel/{driver_id}', 'machineDriverDetailsReportExcel')->name('machineDriverDetailsReportExcel'); }); }); From 7a981ee421d5fc4a6921d823065720910d73b851 Mon Sep 17 00:00:00 2001 From: faezeh Date: Sun, 28 Jun 2026 15:39:38 +0330 Subject: [PATCH 4/7] creat new column for CmmsMachines and improve notification for mission and valdation for formrequest --- .../Controllers/V3/NotificationController.php | 61 +++++++++++++++++-- .../V3/Mission/ControlUnit/FinishRequest.php | 25 +++----- ...stance_mission_to__cmms_machines_table.php | 28 +++++++++ routes/v3.php | 2 +- 4 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 database/migrations/2026_06_28_094747_add_distance_mission_to__cmms_machines_table.php diff --git a/app/Http/Controllers/V3/NotificationController.php b/app/Http/Controllers/V3/NotificationController.php index cf00a3d9..dbbfec25 100644 --- a/app/Http/Controllers/V3/NotificationController.php +++ b/app/Http/Controllers/V3/NotificationController.php @@ -197,18 +197,67 @@ class NotificationController extends Controller 'control' => 0, ]; - if ($user->hasPermissionTo('manage-transportation-unit')) { + if ($user->hasPermissionTo('manage-transportation-unit-station')) { $missions['transportation'] = Mission::query()->where([ ['state_id', '=', MissionStates::REQUEST_CREATED->value], - ['edare_shahri_id', '=', $user->edarate_shahri_id], + ['station_id', '=', $user->station_id], ])->count(); } - if ($user->hasPermissionTo('manage-control-unit')) { - $missions['control'] = Mission::query()->where([ - ['state_id', '=', MissionStates::PENDING_CONFIRMATION->value], - ['edare_shahri_id', '=', $user->edarate_shahri_id], + if ($user->hasPermissionTo('manage-transportation-unit-country')) { + $missions['transportation'] = Mission::query()->where([ + ['state_id', '=', MissionStates::REQUEST_CREATED->value], ])->count(); } + if ($user->hasPermissionTo('manage-transportation-unit-province')) { + $missions['transportation'] = Mission::query()->where([ + ['state_id', '=', MissionStates::REQUEST_CREATED->value], + ['province_id', '=', $user->province_id], + + ])->count(); + } + if ($user->hasPermissionTo('manage-transportation-unit-city')) { + $missions['transportation'] = Mission::query()->where([ + ['state_id', '=', MissionStates::REQUEST_CREATED->value], + ['city_id', '=', $user->city_id], + + ])->count(); + } + + + if ($user->hasPermissionTo('manage-control-unit-station')) { + $missions['control'] = Mission::query() + ->whereIn('state_id', [ + MissionStates::PENDING_CONFIRMATION->value, + MissionStates::START_MISSION->value, + ]) + ->where('station_id', $user->station_id) + ->count(); + } + if ($user->hasPermissionTo('manage-control-unit-country')) { + $missions['control'] = Mission::query() + ->whereIn('state_id', [ + MissionStates::PENDING_CONFIRMATION->value, + MissionStates::START_MISSION->value, + ])->count(); + } + if ($user->hasPermissionTo('manage-control-unit-province')) { + $missions['control'] = Mission::query() + ->whereIn('state_id', [ + MissionStates::PENDING_CONFIRMATION->value, + MissionStates::START_MISSION->value, + ]) + ->where('province_id', '=', $user->province_id) + ->count(); + } + if ($user->hasPermissionTo('manage-control-unit-city')) { + $missions['control'] = Mission::query() + ->whereIn('state_id', [ + MissionStates::PENDING_CONFIRMATION->value, + MissionStates::START_MISSION->value, + ]) + ->where('city_id', '=', $user->city_id + )->count(); + } $missions['total'] = $missions['request_portal'] + $missions['transportation'] + $missions['control']; diff --git a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php index 9d9890e8..29764451 100644 --- a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php +++ b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php @@ -15,7 +15,7 @@ class FinishRequest extends FormRequest */ public function authorize(): bool { - return $this->mission->state_id == MissionStates::START_MISSION->value; + return $this->mission->state_id === MissionStates::START_MISSION->value; } /** @@ -55,23 +55,12 @@ class FinishRequest extends FormRequest $distance = $this->end_km - $mission->km; - if ($machine->car_group === 'سنگین') { - - if ($distance > 15) { - $validator->errors()->add( - 'end_km', - 'اختلاف کیلومتر برای خودروهای سنگین باید کمتر از 15 باشد.' - ); - } - - } else { - - if ($distance > 1000) { - $validator->errors()->add( - 'end_km', - 'اختلاف کیلومتر برای خودروهای سبک و نیمه سنگین باید کمتر از 1000 باشد.' - ); - } + if ($distance > $machine->distance_mission) + { + $validator->errors()->add( + 'end_km', + 'کیلومتر /ساعت کار از حد نصاب بیشتر هست.' + ); } } ]; diff --git a/database/migrations/2026_06_28_094747_add_distance_mission_to__cmms_machines_table.php b/database/migrations/2026_06_28_094747_add_distance_mission_to__cmms_machines_table.php new file mode 100644 index 00000000..a0a88cf0 --- /dev/null +++ b/database/migrations/2026_06_28_094747_add_distance_mission_to__cmms_machines_table.php @@ -0,0 +1,28 @@ +integer('distance_mission')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('cmms_machines', function (Blueprint $table) { + $table->dropColumn('distance_mission'); + }); + } +}; diff --git a/routes/v3.php b/routes/v3.php index d05afc2f..5b8bcb45 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -576,7 +576,7 @@ Route::prefix('missions') Route::get('/machine_details_report/{machine_id}', 'machineDetailsReport')->name('machineDetailsReport'); Route::get('/machine_details_report_excel/{machine_id}', 'machineDetailsReportExcel')->name('machineDetailsReportExcel'); Route::get('/machine_type_details_report/{car_type}', 'machineTypeDetailsReport')->name('machineTypeDetailsReport'); - Route::get('/machine_type_details_report_excel/{car_type}', 'Excel')->name('machineTypeDetailsReportExcel'); + Route::get('/machine_type_details_report_excel/{car_type}', 'machineTypeDetailsReportExcel')->name('machineTypeDetailsReportExcel'); Route::get('/machine_driver_details_report/{driver_id}', 'machineDriverDetailsReport')->name('machineDriverDetailsReport'); Route::get('/machine_driver_details_report_excel/{driver_id}', 'machineDriverDetailsReportExcel')->name('machineDriverDetailsReportExcel'); }); From d58ca6b6852d55d87fcd6c75ac15cb599c431575 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 11 Jul 2026 09:40:50 +0330 Subject: [PATCH 5/7] add machine id --- .../Cartables/Mission/Report/ReportMachineService.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Services/Cartables/Mission/Report/ReportMachineService.php b/app/Services/Cartables/Mission/Report/ReportMachineService.php index 58f65c82..a00501cb 100644 --- a/app/Services/Cartables/Mission/Report/ReportMachineService.php +++ b/app/Services/Cartables/Mission/Report/ReportMachineService.php @@ -22,13 +22,14 @@ class ReportMachineService ] ); } + public function machinesActivity(Request $request): array { $query = Mission::query() ->join('cmms_machines as cm', 'cm.id', '=', 'missions.machine_id') ->where('state_id', '=', 4) ->when($request->province_id, function ($q) use ($request) { - $q->where('missions.province_id', $request->province_id); + $q->where('missions.province_id', '=', $request->province_id); }) ->selectRaw( 'cm.car_name, @@ -51,7 +52,7 @@ class ReportMachineService public function dataTableMachineTypesActivity(Request $request,int $car_type): array { - $machineIds = CMMSMachine::query()->where('car_type', '=', $request->query('car_type'))->pluck('machine_id'); + $machineIds = CMMSMachine::query()->where('car_type', '=', $car_type)->pluck('machine_id'); return DataTableFacade::run( Mission::query()->whereIn('machine_id', $machineIds), $request, From 961e4c40c909cbd07a7d9a3407f63f6fadd9f7cf Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 14 Jul 2026 14:38:17 +0330 Subject: [PATCH 6/7] make reports datatable --- .../Report/ReportMachineController.php | 35 +++++++------------ .../Mission/Report/ReportMachineService.php | 19 +++++----- ...stance_mission_to_cmms_machines_table.php} | 4 +-- routes/v3.php | 8 ++--- 4 files changed, 28 insertions(+), 38 deletions(-) rename database/migrations/{2026_06_28_094747_add_distance_mission_to__cmms_machines_table.php => 2026_06_28_094747_add_distance_mission_to_cmms_machines_table.php} (81%) diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index ae9bbcc1..825a332d 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -23,7 +23,7 @@ class ReportMachineController extends Controller public function machineDetailsReport(Request $request, ReportMachineService $reportMachineService,int $machine_id): JsonResponse { - $data = $reportMachineService->dataTableMachinesActivity($request,$machine_id); + $data = $reportMachineService->machineDetailActivity($request,$machine_id); return response()->json($data); } @@ -34,7 +34,7 @@ class ReportMachineController extends Controller */ public function machineDetailsReportExcel(Request $request, int $machine_id, ReportMachineService $reportMachineService): BinaryFileResponse { - $data = $reportMachineService->dataTableMachinesActivity($request,$machine_id); + $data = $reportMachineService->machineDetailActivity($request,$machine_id); $name = 'گزارش عملکرد ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; return Excel::download(new machineDetailsReport($data['data']), $name); @@ -42,10 +42,7 @@ class ReportMachineController extends Controller public function machinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse { - return $this->successResponse([ - 'activities' => $reportMachineService->machinesActivity($request), -// 'provinces' => Province::all(['id', 'name_fa']), - ]); + return response()->json($reportMachineService->machinesActivity($request)); } /** @@ -62,9 +59,9 @@ class ReportMachineController extends Controller } - public function machineTypeDetailsReport(Request $request, ReportMachineService $reportMachineService,int $car_type): JsonResponse + public function machineTypeDetailsReport(Request $request, ReportMachineService $reportMachineService): JsonResponse { - $data = $reportMachineService->dataTableMachineTypesActivity($request,$car_type); + $data = $reportMachineService->machineTypeDetailActivity($request); return response()->json($data); } @@ -73,9 +70,9 @@ class ReportMachineController extends Controller * @throws Exception * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - public function machineTypeDetailsReportExcel(Request $request, ReportMachineService $reportMachineService,int $car_type): BinaryFileResponse + public function machineTypeDetailsReportExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse { - $data = $reportMachineService->dataTableMachineTypesActivity($request,$car_type); + $data = $reportMachineService->machineTypeDetailActivity($request); $name = 'گزارش عملکردیک نوع ماشین'.verta()->now()->format('Y-m-d H-i').'.xlsx'; return Excel::download(new machineTypeDetailsReport($data['data']), $name); @@ -83,10 +80,7 @@ class ReportMachineController extends Controller public function machineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse { - return $this->successResponse([ - 'activities' => $reportMachineService->machineTypesActivity($request), -// 'provinces' => Province::all(['id', 'name_fa']), - ]); + return response()->json($reportMachineService->machineTypesActivity($request)); } /** @@ -101,9 +95,9 @@ class ReportMachineController extends Controller return Excel::download(new machineTypeReport($data), $name); } - public function machineDriverDetailsReport(Request $request, int $driver_id, ReportMachineService $reportMachineService): JsonResponse + public function machineDriverDetailsReport(Request $request, ReportMachineService $reportMachineService): JsonResponse { - $data = $reportMachineService->dataTableMachineDriversActivity($request,$driver_id); + $data = $reportMachineService->machineDriverDetailActivity($request); return response()->json($data); } @@ -112,9 +106,9 @@ class ReportMachineController extends Controller * @throws Exception * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - public function machineDriverDetailsReportExcel(Request $request, int $driver_id, ReportMachineService $reportMachineService): BinaryFileResponse + public function machineDriverDetailsReportExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse { - $data = $reportMachineService->dataTableMachineDriversActivity($request,$driver_id); + $data = $reportMachineService->machineDriverDetailActivity($request); $name = 'گزارش عملکرد راننده'.verta()->now()->format('Y-m-d H-i').'.xlsx'; return Excel::download( @@ -123,10 +117,7 @@ class ReportMachineController extends Controller public function machineDriversActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse { - return $this->successResponse([ - 'activities' => $reportMachineService->machineDriversActivity($request), -// 'provinces' => Province::all(['id', 'name_fa']), - ]); + return response()->json($reportMachineService->machineDriversActivity($request)); } /** diff --git a/app/Services/Cartables/Mission/Report/ReportMachineService.php b/app/Services/Cartables/Mission/Report/ReportMachineService.php index a00501cb..21e6ea58 100644 --- a/app/Services/Cartables/Mission/Report/ReportMachineService.php +++ b/app/Services/Cartables/Mission/Report/ReportMachineService.php @@ -9,7 +9,7 @@ use Illuminate\Http\Request; class ReportMachineService { - public function dataTableMachinesActivity(Request $request, int $machine_id): array + public function machineDetailActivity(Request $request, int $machine_id): array { return DataTableFacade::run( Mission::query()->where('machine_id', '=', $machine_id), @@ -38,10 +38,9 @@ class ReportMachineService COUNT(*) as missions, SUM(missions.end_km - missions.km) as func' ) - ->groupBy('missions.machine_id') - ->orderByRaw('COUNT(*) DESC'); + ->groupBy('missions.machine_id'); - $fields = ['machine_code','machine_id','cm.car_name','missions', 'func']; + $fields = ['machine_code','machine_id','cm.car_name','missions', 'func', 'start_time', 'finish_time', 'province_id']; return DataTableFacade::run( $query, $request, @@ -50,9 +49,9 @@ class ReportMachineService ); } - public function dataTableMachineTypesActivity(Request $request,int $car_type): array + public function machineTypeDetailActivity(Request $request): array { - $machineIds = CMMSMachine::query()->where('car_type', '=', $car_type)->pluck('machine_id'); + $machineIds = CMMSMachine::query()->where('car_type', '=', $request->query('car_type'))->pluck('id'); return DataTableFacade::run( Mission::query()->whereIn('machine_id', $machineIds), $request, @@ -81,7 +80,7 @@ class ReportMachineService ->groupBy('cm.car_type') ->orderByRaw('COUNT(*) DESC'); - $fields = ['car_type','missions', 'func']; + $fields = ['car_type','missions', 'func', 'start_time', 'finish_time', 'province_id']; return DataTableFacade::run( $query, @@ -91,10 +90,10 @@ class ReportMachineService ); } - public function dataTableMachineDriversActivity(Request $request,int $driver_id): array + public function machineDriverDetailActivity(Request $request): array { return DataTableFacade::run( - Mission::query()->where('driver_id', '=', $driver_id), + Mission::query()->where('driver_id', '=', $request->query('driver_id')), $request, allowedFilters: ['*'], allowedSortings: ['*'], @@ -121,7 +120,7 @@ class ReportMachineService ->groupBy('driver_id') ->orderByRaw('COUNT(*) DESC'); - $fields = ['driver_id','driver_name','missions', 'func']; + $fields = ['driver_id','driver_name','missions', 'func', 'start_time', 'finish_time', 'province_id']; return DataTableFacade::run( $query, diff --git a/database/migrations/2026_06_28_094747_add_distance_mission_to__cmms_machines_table.php b/database/migrations/2026_06_28_094747_add_distance_mission_to_cmms_machines_table.php similarity index 81% rename from database/migrations/2026_06_28_094747_add_distance_mission_to__cmms_machines_table.php rename to database/migrations/2026_06_28_094747_add_distance_mission_to_cmms_machines_table.php index a0a88cf0..e603e4cc 100644 --- a/database/migrations/2026_06_28_094747_add_distance_mission_to__cmms_machines_table.php +++ b/database/migrations/2026_06_28_094747_add_distance_mission_to_cmms_machines_table.php @@ -12,7 +12,7 @@ return new class extends Migration public function up(): void { Schema::table('cmms_machines', function (Blueprint $table) { - $table->integer('distance_mission')->nullable(); + $table->integer('max_mission_duration')->nullable(); }); } @@ -22,7 +22,7 @@ return new class extends Migration public function down(): void { Schema::table('cmms_machines', function (Blueprint $table) { - $table->dropColumn('distance_mission'); + $table->dropColumn('max_mission_duration'); }); } }; diff --git a/routes/v3.php b/routes/v3.php index 5b8bcb45..4dc6363a 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -575,10 +575,10 @@ Route::prefix('missions') Route::get('/machine_drivers_activity_excel', 'machineDriversActivityExcel')->name('machineDriversActivityExcel'); Route::get('/machine_details_report/{machine_id}', 'machineDetailsReport')->name('machineDetailsReport'); Route::get('/machine_details_report_excel/{machine_id}', 'machineDetailsReportExcel')->name('machineDetailsReportExcel'); - Route::get('/machine_type_details_report/{car_type}', 'machineTypeDetailsReport')->name('machineTypeDetailsReport'); - Route::get('/machine_type_details_report_excel/{car_type}', 'machineTypeDetailsReportExcel')->name('machineTypeDetailsReportExcel'); - Route::get('/machine_driver_details_report/{driver_id}', 'machineDriverDetailsReport')->name('machineDriverDetailsReport'); - Route::get('/machine_driver_details_report_excel/{driver_id}', 'machineDriverDetailsReportExcel')->name('machineDriverDetailsReportExcel'); + Route::get('/machine_type_details_report', 'machineTypeDetailsReport')->name('machineTypeDetailsReport'); + Route::get('/machine_type_details_report_excel', 'machineTypeDetailsReportExcel')->name('machineTypeDetailsReportExcel'); + Route::get('/machine_driver_details_report', 'machineDriverDetailsReport')->name('machineDriverDetailsReport'); + Route::get('/machine_driver_details_report_excel', 'machineDriverDetailsReportExcel')->name('machineDriverDetailsReportExcel'); }); }); From 89972b57f4035eb762049fb76b5e9d0fcc1705b1 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 14 Jul 2026 14:44:02 +0330 Subject: [PATCH 7/7] remove the validation --- app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php | 2 +- .../V3/Mission/RequestPortal/ContinueMissionRequest.php | 6 ------ app/Http/Requests/V3/Mission/Violation/UpdateRequest.php | 6 ------ 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php index 29764451..d8382435 100644 --- a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php +++ b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php @@ -55,7 +55,7 @@ class FinishRequest extends FormRequest $distance = $this->end_km - $mission->km; - if ($distance > $machine->distance_mission) + if ($distance > $machine->max_mission_duration) { $validator->errors()->add( 'end_km', diff --git a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php index aa0700e8..0507f840 100644 --- a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php +++ b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php @@ -70,12 +70,6 @@ class ContinueMissionRequest extends FormRequest 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' ); } - if (($this->end_km - $this->mission->km ) < 100) { - $validator->errors()->add( - 'end_km', - 'اختلاف کلیلومتر شروع و پایان نباید بیشتر از 100 کیلومتر باشد' - ); - } }, ]; } diff --git a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php index b2a66821..e2d5294e 100644 --- a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php @@ -47,12 +47,6 @@ class UpdateRequest extends FormRequest 'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.' ); } - if (($this->end_km - $this->violation->km ) < 100) { - $validator->errors()->add( - 'end_km', - 'اختلاف کلیلومتر شروع و پایان نباید بیشتر از 100 کیلومتر باشد' - ); - } } ]; }