From a45b4955dbbb6a6af8a3cae9da313776b339247d Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 14 Jun 2026 10:40:54 +0330 Subject: [PATCH 1/2] create two record for report --- .../Report/ReportMachineController.php | 30 +++++++++++++++++++ .../Mission/Report/ReportMachineService.php | 2 +- routes/v3.php | 2 ++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index 478f10e4..15a12e00 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -7,11 +7,13 @@ 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; @@ -147,4 +149,32 @@ class ReportMachineController extends Controller // ->get(['id', 'name_fa']) ]); } + 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) + { + return DataTableFacade::run( + Mission::query()->where('driver_id', '=', $request->query('driver_id')), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedSelects: [ + 'id', 'province_id', 'province_name', 'city_id', 'city_name', + 'end_km', 'km', 'driver_name', 'state_id', 'station_name' + ] + ); + } } diff --git a/app/Services/Cartables/Mission/Report/ReportMachineService.php b/app/Services/Cartables/Mission/Report/ReportMachineService.php index 9a454fdb..89ba239b 100644 --- a/app/Services/Cartables/Mission/Report/ReportMachineService.php +++ b/app/Services/Cartables/Mission/Report/ReportMachineService.php @@ -83,7 +83,7 @@ class ReportMachineService 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 province_id = :province_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, [ diff --git a/routes/v3.php b/routes/v3.php index e94c6941..53dd6914 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -575,6 +575,8 @@ Route::prefix('missions') Route::get('/machine_details_report', 'machineDetailsReport')->name('machineDetailsReport'); Route::get('/country_machine_drivers_activity', 'countryMachineDriversActivity')->name('countryMachineDriversActivity'); Route::get('/province_machine_drivers_activity', 'provinceMachineDriversActivity')->name('provinceMachineDriversActivity'); + Route::get('/machine_driver_details_report', 'machineDriverDetailsReport')->name('machineDriverDetailsReport'); + Route::get('/machine_driver_details_report', ' machineTypeDetailsReport')->name('machineTypeDetailsReport'); }); }); From 5a2a4777898e17e7f8feb4be24a0158bbdb53d1e Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 14 Jun 2026 10:46:31 +0330 Subject: [PATCH 2/2] fix route --- .../V3/Dashboard/Mission/Report/ReportMachineController.php | 1 + routes/v3.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index 15a12e00..93aaf0cc 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -149,6 +149,7 @@ class ReportMachineController extends Controller // ->get(['id', 'name_fa']) ]); } + public function machineTypeDetailsReport(Request $request) { $machineIds = CMMSMachine::query()->where('car_type', '=', $request->query('car_type'))->pluck('machine_id'); diff --git a/routes/v3.php b/routes/v3.php index 53dd6914..513440f1 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -576,7 +576,7 @@ Route::prefix('missions') Route::get('/country_machine_drivers_activity', 'countryMachineDriversActivity')->name('countryMachineDriversActivity'); Route::get('/province_machine_drivers_activity', 'provinceMachineDriversActivity')->name('provinceMachineDriversActivity'); Route::get('/machine_driver_details_report', 'machineDriverDetailsReport')->name('machineDriverDetailsReport'); - Route::get('/machine_driver_details_report', ' machineTypeDetailsReport')->name('machineTypeDetailsReport'); + Route::get('/machine_type_details_report', ' machineTypeDetailsReport')->name('machineTypeDetailsReport'); }); });