From dff218541c1ff2b2412e0382fb5bfff3ee9544e0 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 7 Feb 2026 13:35:54 +0330 Subject: [PATCH 01/40] dockerize the project --- Dockerfile | 69 ++++++++++++++-------------------------------- docker-compose.yml | 33 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 49 deletions(-) create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 54e60030..80fbb68c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,58 +1,29 @@ -FROM alpine:3.18 +FROM dunglas/frankenphp:1.11.1-php8.2 -RUN apk update && apk add --no-cache\ - bash \ - wget \ - curl \ - nano \ +RUN apt-get update \ + && apt-get install -y --no-install-recommends default-mysql-client \ unzip \ - libzip-dev \ - libxml2 \ - libxml2-dev \ - git \ - zlib-dev \ - libpng-dev \ - php81 \ - php81-common \ - php81-fpm \ - php81-pdo \ - php81-opcache \ - php81-soap \ - php81-zip \ - php81-phar \ - php81-iconv \ - php81-cli \ - php81-curl \ - php81-openssl \ - php81-mbstring \ - php81-tokenizer \ - php81-fileinfo \ - php81-json \ - php81-xml \ - php81-xmlwriter \ - php81-xmlreader \ - php81-simplexml \ - php81-dom \ - php81-pdo_mysql \ - php81-pdo_pgsql \ - php81-pdo_sqlite \ - php81-tokenizer \ - php81-pecl-redis \ - php81-gd + zip \ + && docker-php-ext-install pdo_mysql \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer +WORKDIR /var/www/rms -ENV COMPOSER_ALLOW_SUPERUSER=1 +# Copy Laravel application +COPY . . -ARG MOUNT_PATH +# Give permissions to storage and bootstrap/cache +RUN chmod -R 777 storage bootstrap/cache -COPY . /var/www/app - -WORKDIR /var/www/app +# Install Composer +COPY --from=docker.arvancloud.ir/composer:latest /usr/bin/composer /usr/bin/composer +# Optional: Run migrations/seeds if you want +# CMD php artisan migrate && php artisan db:seed && frankenphp run --config /etc/frankenphp/config.prod.yaml CMD composer install;\ php artisan key:generate;\ -# php artisan migrate ;\ -# php artisan db:seed;\ -# php artisan storege:link;\ - php artisan serve --host=0.0.0.0 \ No newline at end of file + php artisan migrate;\ + php artisan db:seed;\ + cd public;\ + frankenphp php-server \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..85c90431 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,33 @@ +services: + mariadb: + image: mariadb:10.11.8 + container_name: rms-mariadb + ports: + - "3307:3306" + environment: + MARIADB_DATABASE: ${MARIADB_DATABASE} + MARIADB_USER: ${MARIADB_USER} + MARIADB_PASSWORD: ${MARIADB_PASSWORD} + MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD} + volumes: + - ./2025-11-30:/var/lib/mysql + networks: + - rms + + backend: + build: + context: . + dockerfile: Dockerfile + container_name: rms + ports: + - "8003:80" + volumes: + - ./:/var/www/rms + depends_on: + - mariadb + networks: + - rms + +networks: + rms: + driver: bridge \ No newline at end of file From 5f19a26f67a4c33b50cb68afbdd8bd1cf1a7ae91 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 7 Feb 2026 14:21:53 +0330 Subject: [PATCH 02/40] debug the image --- Dockerfile | 5 ++++- docker-compose.yml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 80fbb68c..b118f592 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,10 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends default-mysql-client \ unzip \ zip \ - && docker-php-ext-install pdo_mysql \ + && install-php-extensions pdo_mysql \ + && install-php-extensions zip \ + && install-php-extensions gd \ + && install-php-extensions pcntl \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/docker-compose.yml b/docker-compose.yml index 85c90431..462504d0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: MARIADB_PASSWORD: ${MARIADB_PASSWORD} MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD} volumes: - - ./2025-11-30:/var/lib/mysql + - /var/www/rmsdb:/var/lib/mysql networks: - rms From d833f4dc0d5c4ad786afcef60da2426bbbd17172 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 7 Feb 2026 14:57:26 +0330 Subject: [PATCH 03/40] add db config --- docker-compose.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 462504d0..9afc5e76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,10 +5,10 @@ services: ports: - "3307:3306" environment: - MARIADB_DATABASE: ${MARIADB_DATABASE} - MARIADB_USER: ${MARIADB_USER} - MARIADB_PASSWORD: ${MARIADB_PASSWORD} - MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD} + MARIADB_DATABASE: ${DB_DATABASE} + MARIADB_USER: ${DB_USERNAME} + MARIADB_PASSWORD: ${DB_PASSWORD} + MARIADB_ROOT_PASSWORD: ${DB_PASSWORD} volumes: - /var/www/rmsdb:/var/lib/mysql networks: From a1bca2d80fc140eb1bb99481040372e88e1753c6 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sat, 16 May 2026 09:18:50 +0330 Subject: [PATCH 04/40] fix view for receipt in insurance letter --- resources/views/receipt/insurance_letter.blade.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/resources/views/receipt/insurance_letter.blade.php b/resources/views/receipt/insurance_letter.blade.php index 9e10dfe0..962c45f9 100644 --- a/resources/views/receipt/insurance_letter.blade.php +++ b/resources/views/receipt/insurance_letter.blade.php @@ -125,11 +125,13 @@ $(document).ready(function() { $(".letter-body").find("#accident_date").text(moment(jsonServer.data.accident_date).format( "jYYYY/jMM/jDD")); - const plaque = jsonServer.data.plaque.split("-"); - $("#plaque1").text(plaque[0]); - $("#plaque2").text(plaque[1]); - $("#plaque3").text(plaque[2]); - $("#plaque4").text(plaque[3]); + const plaque = jsonServer?.data?.plaque?.split("-"); + if (plaque) { + $("#plaque1").text(plaque[0]); + $("#plaque2").text(plaque[1]); + $("#plaque3").text(plaque[2]); + $("#plaque4").text(plaque[3]); + } let row_counter; let i; for (i = 0; i < damages.length; i++) { From 3ca710228f28ab9cf5835e4f2e6388567d3544b8 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sat, 16 May 2026 10:22:02 +0330 Subject: [PATCH 05/40] create new object for user --- app/Http/Controllers/UserController.php | 1 + .../V3/Dashboard/RoadMaintenanceStationController.php | 9 +++++++++ routes/v3.php | 1 + 3 files changed, 11 insertions(+) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index beb423c8..858e130d 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -434,6 +434,7 @@ class UserController extends Controller $user->password = Hash::make($request->password); $user->national_code = $request->national_code; + $user->station_id = $request->station_id; $user->save(); if (auth()->user()) { diff --git a/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php b/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php index 228bf825..b92ee60a 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php @@ -38,6 +38,15 @@ class RoadMaintenanceStationController extends Controller )); } + public function findByCity(Request $request): JsonResponse + { + $stations = RahdariPoint::query() + ->where('city_id', $request->city_id) + ->get(); + + return $this->successResponse($stations); + } + /** * Store a newly created resource in storage. */ diff --git a/routes/v3.php b/routes/v3.php index d17d2bd0..7d670fa5 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -475,6 +475,7 @@ Route::prefix('road_maintenance_station') Route::get('/', 'index')->name('index')->middleware('permission:show-tollhouse|show-tollhouse-province'); Route::post('/', 'store')->name('store'); Route::get('/map', 'map')->name('map'); + Route::get('/filter', 'findByCity')->name('findByCity'); Route::get('/images/{rahdariPoint}', 'images')->name('images'); Route::get('/{rahdariPoint}', 'show')->name('show')->middleware('permission:show-tollhouse|show-tollhouse-province'); Route::post('/{rahdariPoint}', 'update')->name('update')->middleware('permission:edit-tollhouse|edit-tollhouse-province'); From 96960f5e8fb890989e8041896349fc3a49935e2e Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 18 May 2026 10:52:29 +0330 Subject: [PATCH 06/40] create one item for mission and fix in another table --- .../Commands/SendContractSmsNotification.php | 2 +- app/Enums/MissionStates.php | 4 +- app/Facades/Sms/SmsClass.php | 44 +++++++++---------- .../Api/ContractSubItemsController.php | 38 ++++++++-------- .../Mission/ControlUnitController.php | 23 +++++----- .../V3/Mission/ControlUnit/FinishRequest.php | 1 + .../Mission/Report/ReportTradodService.php | 16 +++---- app/Services/PaymentService.php | 4 +- ...18_102119_add_end_km_to_missions_table.php | 29 ++++++++++++ .../road_patrols/operation_create.blade.php | 6 +-- routes/v3.php | 6 +-- 11 files changed, 102 insertions(+), 71 deletions(-) create mode 100644 database/migrations/2026_05_18_102119_add_end_km_to_missions_table.php diff --git a/app/Console/Commands/SendContractSmsNotification.php b/app/Console/Commands/SendContractSmsNotification.php index 8b29c308..7786fb73 100644 --- a/app/Console/Commands/SendContractSmsNotification.php +++ b/app/Console/Commands/SendContractSmsNotification.php @@ -46,7 +46,7 @@ class SendContractSmsNotification extends Command foreach ($contractSubItems as $key => $value) { $message = "سلام،\n پروژه راهداری با کد یکتای {$value->unique_code} با مسئولیت شما، به مدت بیشتر از یک ماه به روزرسانی نشده است. لطفا نسبت به روز رسانی دقیق پیشرفت پروژه در سامانه اقدام نمایید.\n rms.rmto.ir"; - self::sms_sender($value->operator_phone, $message); +// self::sms_sender($value->operator_phone, $message); } } diff --git a/app/Enums/MissionStates.php b/app/Enums/MissionStates.php index 44df6680..7abfdf04 100644 --- a/app/Enums/MissionStates.php +++ b/app/Enums/MissionStates.php @@ -15,11 +15,11 @@ enum MissionStates: int public static function name(int $state): string { $mapArray = [ - 1 => 'درخواست ایجاد شد و در حال بررسی توسط واحد نقلیه است', + 1 => 'درخواست ایجاد شد و در حال بررسی توسط واحد تایید کننده است', 2 => 'خودرو اختصاص داده شد و درخواست توسط واحد کنترل در حال بررسی است', 3 => 'درخواست توسط واحد کنترل تایید شد و ماموریت آغاز می شود', 4 => 'اتمام ماموریت', - 5 => 'عدم تخصیص خودرو توسط واحد نقلیه و بازگشت درخواست به کارتابل کاربر', + 5 => 'عدم تخصیص خودرو توسط واحد تایید کننده و بازگشت درخواست به کارتابل کاربر', 6 => 'ماموریت لغو شد', 7 => 'ماموریت بدون فرایند ثبت شد' ]; diff --git a/app/Facades/Sms/SmsClass.php b/app/Facades/Sms/SmsClass.php index ea950944..3ccd09b6 100644 --- a/app/Facades/Sms/SmsClass.php +++ b/app/Facades/Sms/SmsClass.php @@ -12,28 +12,28 @@ class SmsClass { public function sendSms($mobile, $msg) { - if (App::environment('production')) { - - - $client = new SoapClient("http://172.30.5.36/webservice/sms.asmx?WSDL"); - $date = date('d-m-y h:i:s'); - $date = str_replace(" ", "T", $date); - $result = $client->Send( - array( - 'Username' => 'admin', - 'Password' => 'admin141', - 'ShortCode' => '1000141', - 'Cellphones' => $mobile, - 'Message' => $msg, - 'Farsi' => true, - // 'SendDate' => $date - // 'uTopic' => false, - // 'uFlash' => false - ) - ); - - return $result->SendResult; - } +// if (App::environment('production')) { +// +// +// $client = new SoapClient("http://172.30.5.36/webservice/sms.asmx?WSDL"); +// $date = date('d-m-y h:i:s'); +// $date = str_replace(" ", "T", $date); +// $result = $client->Send( +// array( +// 'Username' => 'admin', +// 'Password' => 'admin141', +// 'ShortCode' => '1000141', +// 'Cellphones' => $mobile, +// 'Message' => $msg, +// 'Farsi' => true, +// // 'SendDate' => $date +// // 'uTopic' => false, +// // 'uFlash' => false +// ) +// ); +// +// return $result->SendResult; +// } // $client = new SoapClient("http://sms1000.ir/webservice/smspro.asmx?WSDL"); diff --git a/app/Http/Controllers/Api/ContractSubItemsController.php b/app/Http/Controllers/Api/ContractSubItemsController.php index af3439c0..9f4a0ff1 100644 --- a/app/Http/Controllers/Api/ContractSubItemsController.php +++ b/app/Http/Controllers/Api/ContractSubItemsController.php @@ -609,25 +609,25 @@ class ContractSubItemsController extends Controller ]); } - public function sms_sender($mobile, $msg) - { - $client=new SoapClient("http://sms1000.ir/webservice/smspro.asmx?WSDL"); - $result=$client->doSendSMS( - array( - 'uUsername' => 'rmto', - 'uPassword' => 'Rahdari8 - ', - 'uNumber' => '1000141', - 'uCellphones' => $mobile, - 'uMessage' => $msg, - 'uFarsi' => true, - 'uTopic' => false, - 'uFlash' => false - ) - ); - $x = $result->doSendSMSResult; - return $x; - } +// public function sms_sender($mobile, $msg) +// { +// $client=new SoapClient("http://sms1000.ir/webservice/smspro.asmx?WSDL"); +// $result=$client->doSendSMS( +// array( +// 'uUsername' => 'rmto', +// 'uPassword' => 'Rahdari8 +// ', +// 'uNumber' => '1000141', +// 'uCellphones' => $mobile, +// 'uMessage' => $msg, +// 'uFarsi' => true, +// 'uTopic' => false, +// 'uFlash' => false +// ) +// ); +// $x = $result->doSendSMSResult; +// return $x; +// } public function get_way_id_from_nominatim($lat, $lng) { diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php b/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php index 33e732b0..bcc7e1d9 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php @@ -70,19 +70,20 @@ class ControlUnitController extends Controller 'state_name' => MissionStates::name($state), 'finish_time' => $request->time, 'mission_duration' => strtotime($request->time) - strtotime($mission->start_time), + 'end_km' => $request->end_km, ]); - $getErrorRateService->setInputParameters($mission); - $responseData = $getErrorRateService->run(); - - $mission->update([ - 'in_area_duration' => $responseData['timeInAreaSeconds'], - 'first_enter' => $responseData['firstEnter'], - 'last_exit' => $responseData['lastExit'], - 'point_number_sent' => $responseData['noOfPointsInMission'], - 'fms_result_code' => $responseData['resultCode'], - 'fms_result_message' => FMSResultCode::name($responseData['resultCode']), - ]); +// $getErrorRateService->setInputParameters($mission); +// $responseData = $getErrorRateService->run(); +// +// $mission->update([ +// 'in_area_duration' => $responseData['timeInAreaSeconds'], +// 'first_enter' => $responseData['firstEnter'], +// 'last_exit' => $responseData['lastExit'], +// 'point_number_sent' => $responseData['noOfPointsInMission'], +// 'fms_result_code' => $responseData['resultCode'], +// 'fms_result_message' => FMSResultCode::name($responseData['resultCode']), +// ]); }); if ($mission->category_id == 2) { diff --git a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php index 899b1bb0..bbc1d5b0 100644 --- a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php +++ b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php @@ -25,6 +25,7 @@ class FinishRequest extends FormRequest { return [ 'time' => 'required|date', + 'end_km' => 'required', ]; } } diff --git a/app/Services/Cartables/Mission/Report/ReportTradodService.php b/app/Services/Cartables/Mission/Report/ReportTradodService.php index 2aacae97..341f0430 100644 --- a/app/Services/Cartables/Mission/Report/ReportTradodService.php +++ b/app/Services/Cartables/Mission/Report/ReportTradodService.php @@ -37,8 +37,8 @@ class ReportTradodService -1 AS province_id, COUNT(m.id) AS total, COALESCE(SUM(m.mission_duration != m.in_area_duration), 0) AS khareg_mahdode, - COALESCE(SUM(m.in_area_duration), 0) AS gps, - COALESCE(SUM(m.mission_duration), 0) AS durations, + COALESCE(SUM(m.in_area_duration)/3600, 0) AS gps, + COALESCE(SUM(m.mission_duration)/3600, 0) AS durations, COALESCE(SUM(CASE WHEN m.type = 1 THEN 1 ELSE 0 END), 0) AS far_h, COALESCE(SUM(CASE WHEN m.type = 2 THEN 1 ELSE 0 END), 0) AS far_d, COALESCE(SUM(CASE WHEN m.type = 3 THEN 1 ELSE 0 END), 0) AS un_far_h, @@ -56,8 +56,8 @@ class ReportTradodService p.id AS province_id, COUNT(m.id) AS total, COALESCE(SUM(m.mission_duration != m.in_area_duration), 0) AS khareg_mahdode, - COALESCE(SUM(m.in_area_duration), 0) AS gps, - COALESCE(SUM(m.mission_duration), 0) AS durations, + COALESCE(SUM(m.in_area_duration)/3600, 0) AS gps, + COALESCE(SUM(m.mission_duration)/3600, 0) AS durations, COALESCE(SUM(CASE WHEN m.type = 1 THEN 1 ELSE 0 END), 0) AS far_h, COALESCE(SUM(CASE WHEN m.type = 2 THEN 1 ELSE 0 END), 0) AS far_d, COALESCE(SUM(CASE WHEN m.type = 3 THEN 1 ELSE 0 END), 0) AS un_far_h, @@ -98,8 +98,8 @@ class ReportTradodService -1 AS city_id, COUNT(m.id) AS total, COALESCE(SUM(m.mission_duration != m.in_area_duration), 0) AS khareg_mahdode, - COALESCE(SUM(m.in_area_duration), 0) AS gps, - COALESCE(SUM(m.mission_duration), 0) AS durations, + COALESCE(SUM(m.in_area_duration)/3600, 0) AS gps, + COALESCE(SUM(m.mission_duration)/3600, 0) AS durations, COALESCE(SUM(m.type = 1), 0) AS far_h, COALESCE(SUM(m.type = 2), 0) AS far_d, COALESCE(SUM(m.type = 3), 0) AS un_far_h, @@ -118,8 +118,8 @@ class ReportTradodService c.id AS city_id, COUNT(m.id) AS total, COALESCE(SUM(m.mission_duration != m.in_area_duration), 0) AS khareg_mahdode, - COALESCE(SUM(m.in_area_duration), 0) AS gps, - COALESCE(SUM(m.mission_duration), 0) AS durations, + COALESCE(SUM(m.in_area_duration)/3600, 0) AS gps, + COALESCE(SUM(m.mission_duration)/3600, 0) AS durations, COALESCE(SUM(m.type = 1), 0) AS far_h, COALESCE(SUM(m.type = 2), 0) AS far_d, COALESCE(SUM(m.type = 3), 0) AS un_far_h, diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index cfe90719..b8efeba8 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -27,7 +27,7 @@ class PaymentService ); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, "http://payment.rmto.ir/acc/rest/payid/gen"); + curl_setopt($ch, CURLOPT_URL, "https://payment.rmto.ir/acc/rest/payid/gen"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); @@ -59,7 +59,7 @@ class PaymentService ); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, "http://payment.rmto.ir/acc/rest/payid/track2/" . env("PAYMENT_USERNAME") . "/" . env("PAYMENT_PASSWORD") . "/" . $bill_code); + curl_setopt($ch, CURLOPT_URL, "https://payment.rmto.ir/acc/rest/payid/track2/" . env("PAYMENT_USERNAME") . "/" . env("PAYMENT_PASSWORD") . "/" . $bill_code); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // curl_setopt($ch, CURLOPT_POST, true); // curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); diff --git a/database/migrations/2026_05_18_102119_add_end_km_to_missions_table.php b/database/migrations/2026_05_18_102119_add_end_km_to_missions_table.php new file mode 100644 index 00000000..f4afbb34 --- /dev/null +++ b/database/migrations/2026_05_18_102119_add_end_km_to_missions_table.php @@ -0,0 +1,29 @@ +string('end_km')->nullable(); + + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('missions', function (Blueprint $table) { + $table->dropColumn('km'); + }); + } +}; diff --git a/resources/views/version2/dashboard_pages/road_patrols/operation_create.blade.php b/resources/views/version2/dashboard_pages/road_patrols/operation_create.blade.php index 62546115..c0633708 100644 --- a/resources/views/version2/dashboard_pages/road_patrols/operation_create.blade.php +++ b/resources/views/version2/dashboard_pages/road_patrols/operation_create.blade.php @@ -38,7 +38,7 @@ - --}}
- +
diff --git a/routes/v3.php b/routes/v3.php index 7d670fa5..0ed1219e 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -475,7 +475,7 @@ Route::prefix('road_maintenance_station') Route::get('/', 'index')->name('index')->middleware('permission:show-tollhouse|show-tollhouse-province'); Route::post('/', 'store')->name('store'); Route::get('/map', 'map')->name('map'); - Route::get('/filter', 'findByCity')->name('findByCity'); + Route::get('/search_by_city', 'findByCity')->name('findByCity'); Route::get('/images/{rahdariPoint}', 'images')->name('images'); Route::get('/{rahdariPoint}', 'show')->name('show')->middleware('permission:show-tollhouse|show-tollhouse-province'); Route::post('/{rahdariPoint}', 'update')->name('update')->middleware('permission:edit-tollhouse|edit-tollhouse-province'); @@ -538,7 +538,7 @@ Route::prefix('missions') }); Route::prefix('report_violation') ->name('reportsViolation.') - ->middleware(['permission:mission-report-province', 'permission:mission-report-country']) + ->middleware(['permission:mission-report-province|permission:mission-report-country']) ->controller(ReportViolationController::class) ->group(function () { Route::get('/country_activity', 'countryActivity')->name('countryActivity'); @@ -548,7 +548,7 @@ Route::prefix('missions') }); Route::prefix('report_taradod') ->name('reportsTaradod.') - ->middleware(['permission:mission-report-province', 'permission:mission-report-country']) + ->middleware(['permission:mission-report-province|permission:mission-report-country']) ->controller(ReportTradodController::class) ->group(function () { Route::get('/country_activity', 'countryActivity')->name('countryActivity'); From f798d05a3c3e5b3019e047d8ac424f423456ecea Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 18 May 2026 11:01:20 +0330 Subject: [PATCH 07/40] create one item for mission and fix in another table --- .../V3/Dashboard/RoadMaintenanceStationController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php b/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php index b92ee60a..ded93c8b 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php @@ -41,7 +41,7 @@ class RoadMaintenanceStationController extends Controller public function findByCity(Request $request): JsonResponse { $stations = RahdariPoint::query() - ->where('city_id', $request->city_id) + ->where('city_id', $request->query('city_id')) ->get(); return $this->successResponse($stations); From 6a1513a72fc70761c6b51c33424c536772fad72e Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 18 May 2026 08:09:27 +0000 Subject: [PATCH 08/40] add toll house to user management --- .../dashboard_pages/user_management/list.js | 69 ++++++++++++++++--- .../user_management/list.blade.php | 5 ++ 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/public/version2/js/dashboard_pages/user_management/list.js b/public/version2/js/dashboard_pages/user_management/list.js index 497d4261..0e3abf43 100644 --- a/public/version2/js/dashboard_pages/user_management/list.js +++ b/public/version2/js/dashboard_pages/user_management/list.js @@ -417,6 +417,43 @@ function getCityByProvince(province_id, dom_id, selected_id = 0) { } + +function getTollhouseByCity(city_id, dom_id, selected_id = 0) {$.ajax({ + url: `/api/v3/road_maintenance_station/search_by_city?city_id=${city_id}`, + type: "GET", + async: false, + beforeSend: function () { + $(`#${dom_id}`).empty(); + showLoaderScreen() + }, + success: function (result) { + $(`#${dom_id}`).append(''); + cities = result.data; + + for (let index = 0; index < cities.length; index++) { + + $(`#${dom_id}`).append( + `` + ); + } + + if (selected_id == null) { + disableDOM(dom_id); + } else if (selected_id != 0) { + enableDOM(dom_id); + $(`#${dom_id} option[value="${selected_id}"]`).attr("selected", true); + } + + hideLoaderScreen(); + }, + error: function (error) { + errorHandler(error); + hideLoaderScreen(); + }, + }); + +} + function getCityOfficeByCity(city_id, dom_id, selected_id = 0) { $.ajax({ url: "/public/contents/edarateShahri/" + city_id, @@ -2386,6 +2423,24 @@ $("#add_province_office").change(function () { setUserName(); }) +$("#add_simple_city").change(function () { + console.log("add_simple_city change happend"); + + console.log("valuee:", $(this).val()); + + if ($("#add_simple_city").val() == -1) { + console.log("value of city is or -1"); + + disableDOM("add_simple_tollhouse") + $("#add_simple_tollhouse").empty(); + } else { + console.log("tolls should send reqest"); + + enableDOM("add_simple_tollhouse") + getTollhouseByCity($("#add_simple_province").val(), "add_simple_tollhouse") + } +}) + // $("#edit_city").change(function () { // if ($(this).val() == 0) { @@ -2396,15 +2451,6 @@ $("#add_province_office").change(function () { // setUserName("edit"); // }) -// $("#add_simple_city").change(function () { - -// if ($(this).val() == 0) { -// $("#add_simple_city_office").empty(); -// } else { -// getCityOfficeByCity($(this).val(), "add_simple_city_office") -// } -// setUserName(); -// }) // $("#add_city").change(function () { @@ -2581,6 +2627,9 @@ $('#add_simple_user_show_modal').on('click', function () { enableDOM("add_simple_city") $("#add_simple_city").empty(); $("#add_simple_city").append(''); + enableDOM("add_simple_tollhouse") + $("#add_simple_tollhouse").empty(); + $("#add_simple_tollhouse").append(''); enableDOM("add_simple_city_office") $("#add_simple_city_office").empty(); $("#add_simple_city_office").append(''); @@ -2594,8 +2643,10 @@ $("#add_simple_province").change(function () { disableDOM("add_simple_city") disableDOM("add_simple_city_office") + disableDOM("add_simple_tollhouse") $("#add_simple_city").empty(); $("#add_simple_city_office").empty(); + $("#add_simple_tollhouse").empty(); } else { if ($("#add_simple_province_office").val() == 0) { diff --git a/resources/views/version2/dashboard_pages/user_management/list.blade.php b/resources/views/version2/dashboard_pages/user_management/list.blade.php index 868495d7..a77469ca 100644 --- a/resources/views/version2/dashboard_pages/user_management/list.blade.php +++ b/resources/views/version2/dashboard_pages/user_management/list.blade.php @@ -675,6 +675,11 @@ id="add_simple_city_office">
+
+ + +
* From ad70874bde0cc2c3f56326fd59779b8fd8f21bef Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 18 May 2026 11:39:30 +0330 Subject: [PATCH 09/40] fix migration --- .../2026_05_18_102119_add_end_km_to_missions_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2026_05_18_102119_add_end_km_to_missions_table.php b/database/migrations/2026_05_18_102119_add_end_km_to_missions_table.php index f4afbb34..ecf5de6b 100644 --- a/database/migrations/2026_05_18_102119_add_end_km_to_missions_table.php +++ b/database/migrations/2026_05_18_102119_add_end_km_to_missions_table.php @@ -23,7 +23,7 @@ return new class extends Migration public function down(): void { Schema::table('missions', function (Blueprint $table) { - $table->dropColumn('km'); + $table->dropColumn('end_km'); }); } }; From 08db103f26ef11059c7b538c87b9d71ce38e95b7 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 18 May 2026 08:55:12 +0000 Subject: [PATCH 10/40] add station id to create user --- .../dashboard_pages/user_management/list.js | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/public/version2/js/dashboard_pages/user_management/list.js b/public/version2/js/dashboard_pages/user_management/list.js index 0e3abf43..7428edc6 100644 --- a/public/version2/js/dashboard_pages/user_management/list.js +++ b/public/version2/js/dashboard_pages/user_management/list.js @@ -61,9 +61,6 @@ function errorHandler(error) { break; default: - console.error("Error trace object"); - console.log("Error object:"); - console.log(error); Swal.fire({ icon: "error", title: "خطا", @@ -433,7 +430,7 @@ function getTollhouseByCity(city_id, dom_id, selected_id = 0) {$.ajax({ for (let index = 0; index < cities.length; index++) { $(`#${dom_id}`).append( - `` + `` ); } @@ -960,7 +957,6 @@ $(document).on('click', '#report_btn', function () { var tr = $(this).closest("tr"); var row = table.row(tr); $("#report_modal").modal('show'); - console.log(row.data().id); $("#selected_user_for_report").val(row.data().id); }) @@ -1040,7 +1036,6 @@ $(document).on('click', '#activity_report', function () { showLoaderScreen() }, success: function (result) { - console.log(result); $("#activity_time").text(result.activity_time); $("#average_activity_time").text(result.average_activity_time); @@ -1079,9 +1074,6 @@ $(document).on('click', '.permission-control', function () { modal.find('.permission-label').removeClass('text-muted') modal.find('.all-permission-by-type').prop('checked', false) modal.find('#user_id').val(row.data().id) - - console.log(row.data().province_id); - console.log(row.data().edarate_shahri_id); modal.find('.permission-input').each((index, element) => { if ($(element).data('needProvince') == 1) { if (row.data().province_id == null) { @@ -1662,7 +1654,6 @@ $("table").on("click", "tbody tr", function () { $('#user_data_table').on('change', ".user-finder-all", function () { - console.log(checkedItemsId); var thiz = $(this); if (thiz.is(':checked')) { @@ -1679,7 +1670,6 @@ $('#user_data_table').on('change', ".user-finder-all", function () { }); $('#user_data_table').on('change', ".user-finder", function () { - console.log(checkedItemsId); const checkedItemId = $(this).data("idUser"); @@ -2141,7 +2131,6 @@ $("#edit_province_office").change(function () { $("#edit_city_office").change(function () { - console.log("this is ok"); setUserName("edit"); }) @@ -2424,20 +2413,15 @@ $("#add_province_office").change(function () { }) $("#add_simple_city").change(function () { - console.log("add_simple_city change happend"); - - console.log("valuee:", $(this).val()); if ($("#add_simple_city").val() == -1) { - console.log("value of city is or -1"); disableDOM("add_simple_tollhouse") $("#add_simple_tollhouse").empty(); } else { - console.log("tolls should send reqest"); enableDOM("add_simple_tollhouse") - getTollhouseByCity($("#add_simple_province").val(), "add_simple_tollhouse") + getTollhouseByCity($("#add_simple_city").val(), "add_simple_tollhouse") } }) @@ -2673,8 +2657,10 @@ $("#add_simple_province_office").change(function () { disableDOM("add_simple_city") disableDOM("add_simple_city_office") + disableDOM("add_simple_tollhouse") $("#add_simple_city").empty(); $("#add_simple_city_office").empty(); + $("#add_simple_tollhouse").empty(); } else { if ($("#add_simple_province").val() == 0 || $("#add_simple_province").val() == -1) { @@ -2708,6 +2694,7 @@ $("#add_simple_submit_form").on("click", function () { var edarate_shahri_id = $("#add_simple_city_office").children("option:selected").val(); var national_code = $("#add_simple_national_code").val(); var city_id = $("#add_simple_city").children("option:selected").val(); + var tollhouse_id = $("#add_simple_tollhouse").children("option:selected").val(); if (edarate_ostani_id <= 0 && edarate_shahri_id <= 0) { @@ -2746,6 +2733,12 @@ $("#add_simple_submit_form").on("click", function () { } else { $("#add_simple_city").removeClass("validity-checker"); } + if (tollhouse_id == 0) { + $("#add_simple_tollhouse").addClass("validity-checker"); + form_validation_status = false; + } else { + $("#add_simple_tollhouse").removeClass("validity-checker"); + } if (province_id < 0) { $("#add_simple_province").addClass("validity-checker"); @@ -2785,6 +2778,10 @@ $("#add_simple_submit_form").on("click", function () { formData.append("city_id", city_id); } + if (tollhouse_id != undefined) { + formData.append("station_id", tollhouse_id); + } + formData.append("password_confirmation", repass); if (edarate_ostani_id != 0) { formData.append("edarate_ostani_id", edarate_ostani_id); From 9f394abc3ebb5ed4c75a4728ce5ecb3ac0800f72 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sat, 23 May 2026 10:10:52 +0330 Subject: [PATCH 11/40] change name for date az to_date in date_to --- app/Services/Cartables/Mission/Report/ReportTradodService.php | 4 ++-- .../Cartables/Mission/Report/ReportViolationService.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Services/Cartables/Mission/Report/ReportTradodService.php b/app/Services/Cartables/Mission/Report/ReportTradodService.php index 341f0430..c710cd6b 100644 --- a/app/Services/Cartables/Mission/Report/ReportTradodService.php +++ b/app/Services/Cartables/Mission/Report/ReportTradodService.php @@ -27,7 +27,7 @@ class ReportTradodService public function countryActivity(Request $request): array { $from = $request->from_date ?? today()->startOfDay(); - $to = $request->to_date ? Carbon::parse($request->to_date)->endOfDay() : today()->endOfDay(); + $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); $sql = " SELECT* @@ -88,7 +88,7 @@ class ReportTradodService { $provinceId = $request->province_id ?? auth()->user()->province_id; $from = $request->from_date ?? today()->startOfDay(); - $to = $request->to_date ? Carbon::parse($request->to_date)->endOfDay() : today()->endOfDay(); + $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); $sql = " SELECT* diff --git a/app/Services/Cartables/Mission/Report/ReportViolationService.php b/app/Services/Cartables/Mission/Report/ReportViolationService.php index 45ec40a1..1034ff4f 100644 --- a/app/Services/Cartables/Mission/Report/ReportViolationService.php +++ b/app/Services/Cartables/Mission/Report/ReportViolationService.php @@ -27,7 +27,7 @@ class ReportViolationService public function countryActivity(Request $request): array { $from = $request->from_date ?? today()->startOfDay(); - $to = $request->to_date ? Carbon::parse($request->to_date)->endOfDay() : today()->endOfDay(); + $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); $sql = " SELECT* @@ -81,7 +81,7 @@ class ReportViolationService { $provinceId = $request->province_id ?? auth()->user()->province_id; $from = $request->from_date ?? today()->startOfDay(); - $to = $request->to_date ? Carbon::parse($request->to_date)->endOfDay() : today()->endOfDay(); + $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); $sql = " SELECT* From 893edea5a94bc61570163fd49c7adf05aa807174 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sat, 23 May 2026 13:23:05 +0330 Subject: [PATCH 12/40] fix permission route --- routes/v3.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/v3.php b/routes/v3.php index 0ed1219e..8d1e61ca 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -538,7 +538,7 @@ Route::prefix('missions') }); Route::prefix('report_violation') ->name('reportsViolation.') - ->middleware(['permission:mission-report-province|permission:mission-report-country']) + ->middleware(['permission:mission-report-province|mission-report-country']) ->controller(ReportViolationController::class) ->group(function () { Route::get('/country_activity', 'countryActivity')->name('countryActivity'); @@ -548,7 +548,7 @@ Route::prefix('missions') }); Route::prefix('report_taradod') ->name('reportsTaradod.') - ->middleware(['permission:mission-report-province|permission:mission-report-country']) + ->middleware(['permission:mission-report-province|mission-report-country']) ->controller(ReportTradodController::class) ->group(function () { Route::get('/country_activity', 'countryActivity')->name('countryActivity'); From 7d7507411d0ff2ebe49f0525de70cd29ebd98db6 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sun, 24 May 2026 09:00:16 +0330 Subject: [PATCH 13/40] merge develop to origin --- routes/v3.php | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/v3.php b/routes/v3.php index 8d1e61ca..960772f9 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -666,5 +666,6 @@ Route::prefix('role') Route::get('/test', function () { $csvExporter = new \Laracsv\Export(); + $csvExporter->build(\App\Models\User::all(), ['id' => 'کد یکتا', 'username' => 'نام کاربری'])->download(); }); \ No newline at end of file From e3b49ebbb37c0d6cd7a3e7169675b55f06dcb555 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 25 May 2026 16:25:56 +0330 Subject: [PATCH 14/40] crate new repor for machin when they go to the mission and fix bugs in traddod mission --- .../Mission/Report/Tradod/CountryReport.php | 4 +- .../Mission/Report/Tradod/ProvinceReport.php | 4 +- .../Mission/Report/machine/machineReport.php | 73 +++++++++++++++++ .../Report/ReportMachineController.php | 47 +++++++++++ .../V3/Mission/ControlUnit/FinishRequest.php | 23 ++++++ .../Mission/Report/ReportMachineService.php | 43 ++++++++++ .../Report/Machine/ActivityReport.blade.php | 79 +++++++++++++++++++ .../Tradod /CountryActivityReport.blade.php | 2 +- .../Tradod /ProvinceActivityReport.blade.php | 2 +- routes/v3.php | 1 - 10 files changed, 271 insertions(+), 7 deletions(-) create mode 100644 app/Exports/V3/Mission/Report/machine/machineReport.php create mode 100644 app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php create mode 100644 app/Services/Cartables/Mission/Report/ReportMachineService.php create mode 100644 resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php diff --git a/app/Exports/V3/Mission/Report/Tradod/CountryReport.php b/app/Exports/V3/Mission/Report/Tradod/CountryReport.php index 69e2b66d..b63d606a 100644 --- a/app/Exports/V3/Mission/Report/Tradod/CountryReport.php +++ b/app/Exports/V3/Mission/Report/Tradod/CountryReport.php @@ -29,9 +29,9 @@ class CountryReport implements FromView, ShouldAutoSize, WithDrawings, WithEvent $national = [ 'province_name' => $name, 'total' => (int) ($r->total ?? 0), - 'khareg_mahdode' => (int) ($r->khareg_mahdode ?? 0), 'gps' => (int) ($r->gps ?? 0), 'durations' => (int) ($r->durations ?? 0), + 'khareg_mahdode' => (int) ($r->khareg_mahdode ?? 0), 'bafarayand_saeti' => (int) ($r->far_h ?? 0), 'bafarayand_rozaneh' => (int) ($r->far_d ?? 0), 'bedon_bafarayand_saeti' => (int) ($r->un_far_h ?? 0), @@ -50,9 +50,9 @@ class CountryReport implements FromView, ShouldAutoSize, WithDrawings, WithEvent } $grid[$pid]['total'] = (int) ($r->total ?? 0); - $grid[$pid]['khareg_mahdode'] = ($r->khareg_mahdode ?? 0); $grid[$pid]['gps'] = (int) ($r->gps ?? 0); $grid[$pid]['durations'] = (int) ($r->durations ?? 0); + $grid[$pid]['khareg_mahdode'] = ($r->khareg_mahdode ?? 0); $grid[$pid]['bafarayand_saeti'] = (int) ($r->far_h ?? 0); $grid[$pid]['bafarayand_rozaneh'] = (int) ($r->far_d ?? 0); $grid[$pid]['bedon_bafarayand_saeti'] = (int) ($r->un_far_h ?? 0); diff --git a/app/Exports/V3/Mission/Report/Tradod/ProvinceReport.php b/app/Exports/V3/Mission/Report/Tradod/ProvinceReport.php index 28e31bd0..bf59db39 100644 --- a/app/Exports/V3/Mission/Report/Tradod/ProvinceReport.php +++ b/app/Exports/V3/Mission/Report/Tradod/ProvinceReport.php @@ -30,9 +30,9 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithDrawings, WithEven $province = [ 'city_name' => $name, 'total' => (int) ($r->total ?? 0), - 'khareg_mahdode' => (int) ($r->khareg_mahdode ?? 0), 'gps' => (int) ($r->gps ?? 0), 'durations' => (int) ($r->durations ?? 0), + 'khareg_mahdode' => (int) ($r->khareg_mahdode ?? 0), 'bafarayand_saeti' => (int) ($r->far_h ?? 0), 'bafarayand_rozaneh' => (int) ($r->far_d ?? 0), 'bedon_bafarayand_saeti' => (int) ($r->un_far_h ?? 0), @@ -51,9 +51,9 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithDrawings, WithEven } $grid[$cid]['total'] = (int) ($r->total ?? 0); - $grid[$cid]['khareg_mahdode'] = ($r->khareg_mahdode ?? 0); $grid[$cid]['gps'] = (int) ($r->gps ?? 0); $grid[$cid]['durations'] = (int) ($r->durations ?? 0); + $grid[$cid]['khareg_mahdode'] = ($r->khareg_mahdode ?? 0); $grid[$cid]['bafarayand_saeti'] = (int) ($r->far_h ?? 0); $grid[$cid]['bafarayand_rozaneh'] = (int) ($r->far_d ?? 0); $grid[$cid]['bedon_bafarayand_saeti'] = (int) ($r->un_far_h ?? 0); diff --git a/app/Exports/V3/Mission/Report/machine/machineReport.php b/app/Exports/V3/Mission/Report/machine/machineReport.php new file mode 100644 index 00000000..8f110c9f --- /dev/null +++ b/app/Exports/V3/Mission/Report/machine/machineReport.php @@ -0,0 +1,73 @@ +data as $r) { + $exportRows[] = [ + 'city_name' => $r->c_name ?? '', + 'province_name' => $r->p_name ?? '', + 'm_c_code' => $r->m_c_code ?? 0, + 'distance' => (int) ($r->distance ?? 0), + ]; + } + + return view('v3.Reports.Mission.Report.Machine.ActivityReport', [ + '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(5); + $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 new file mode 100644 index 00000000..34e32a34 --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -0,0 +1,47 @@ +successResponse([ + 'activities' => $reportMachineService->Activity($request), + 'provinces' => Province::all(['id', 'name_fa']), + 'code' => Mission::query() + ->where('machine_code', $request->machine_code) + ->get() + ]); + } + + /** + * @throws Exception + * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + */ + public function ExcelActivity(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse + { + $data = $reportMachineService->Activity($request); + $name = 'گزارش کل تردد یک ماشین '.verta()->now()->format('Y-m-d H-i').'.xlsx'; + + return Excel::download(new CountryReport($data), $name); + } + +} diff --git a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php index bbc1d5b0..6fe0a2fe 100644 --- a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php +++ b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php @@ -5,6 +5,7 @@ namespace App\Http\Requests\V3\Mission\ControlUnit; use App\Enums\MissionStates; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Validation\Validator; class FinishRequest extends FormRequest { @@ -23,9 +24,31 @@ class FinishRequest extends FormRequest */ public function rules(): array { + $mission = $this->route('mission'); return [ 'time' => 'required|date', 'end_km' => 'required', ]; } + + public function after(): array + { + return [ + function (Validator $validator) { + $mission = $this->route('mission'); + if (strtotime($this->time) < strtotime($mission->start_time)) { + $validator->errors()->add( + 'time', + 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' + ); + } + if ($this->end_km < $mission->km) { + $validator->errors()->add( + 'end_km', + 'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.' + ); + } + } + ]; + } } diff --git a/app/Services/Cartables/Mission/Report/ReportMachineService.php b/app/Services/Cartables/Mission/Report/ReportMachineService.php new file mode 100644 index 00000000..f34ceb4a --- /dev/null +++ b/app/Services/Cartables/Mission/Report/ReportMachineService.php @@ -0,0 +1,43 @@ +machine_code; + $from = $request->from_date ?? today()->startOfDay(); + $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); + + $sql = " + SELECT* + m.city_name AS c.name, + m.city_id AS c_id, + m.province_name AS p_name, + m.province_id AS p_id, + COUNT(m.machine_code) As m_c_code, + SUM(m.end_km)-sum(m.km) AS distance + + FROM missions m + WHERE m.machine_code = :machineCode + AND m.created_at >= :from + AND m.created_at <= :to + GROUP BY m.city_id, m.city_name,m.province_id, m.province_name; + + + "; + + return DB::select($sql, [ + 'from' => $from, + 'to' => $to, + 'machineCode' => $code, + ]); + } +} diff --git a/resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php b/resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php new file mode 100644 index 00000000..ef5c1de1 --- /dev/null +++ b/resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php @@ -0,0 +1,79 @@ + + + + + + + + گزارش کل تردد های یک ماشین + + + + + +@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['province_name'] ?? '-' }}{{ $item['city_name'] ?? '-' }}{{ $item['c_m_code'] ?? '-' }}{{ $item['distance'] ?? '-' }}
+ + diff --git a/resources/views/v3/Reports/Mission/Report/Tradod /CountryActivityReport.blade.php b/resources/views/v3/Reports/Mission/Report/Tradod /CountryActivityReport.blade.php index 15edd38a..0fae970f 100644 --- a/resources/views/v3/Reports/Mission/Report/Tradod /CountryActivityReport.blade.php +++ b/resources/views/v3/Reports/Mission/Report/Tradod /CountryActivityReport.blade.php @@ -93,9 +93,9 @@ {{ $item['province_name'] ?? '-' }} {{ $item['total'] ?? '-' }} - {{ $item['khareg_mahdode'] ?? '-' }} {{ $item['gps'] ?? '-' }} {{ $item['durations'] ?? '-' }} + {{ $item['khareg_mahdode'] ?? '-' }} {{ $item['bafarayand_saeti'] ?? '-' }} {{ $item['bafarayand_rozaneh'] ?? '-' }} {{ $item['bedon_bafarayand_saeti'] ?? '-' }} diff --git a/resources/views/v3/Reports/Mission/Report/Tradod /ProvinceActivityReport.blade.php b/resources/views/v3/Reports/Mission/Report/Tradod /ProvinceActivityReport.blade.php index 8d46c155..04c29850 100644 --- a/resources/views/v3/Reports/Mission/Report/Tradod /ProvinceActivityReport.blade.php +++ b/resources/views/v3/Reports/Mission/Report/Tradod /ProvinceActivityReport.blade.php @@ -93,9 +93,9 @@ {{ $item['city_name'] ?? '-' }} {{ $item['total'] ?? '-' }} - {{ $item['khareg_mahdode'] ?? '-' }} {{ $item['gps'] ?? '-' }} {{ $item['durations'] ?? '-' }} + {{ $item['khareg_mahdode'] ?? '-' }} {{ $item['bafarayand_saeti'] ?? '-' }} {{ $item['bafarayand_rozaneh'] ?? '-' }} {{ $item['bedon_bafarayand_saeti'] ?? '-' }} diff --git a/routes/v3.php b/routes/v3.php index 960772f9..8d1e61ca 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -666,6 +666,5 @@ Route::prefix('role') Route::get('/test', function () { $csvExporter = new \Laracsv\Export(); - $csvExporter->build(\App\Models\User::all(), ['id' => 'کد یکتا', 'username' => 'نام کاربری'])->download(); }); \ No newline at end of file From 23dd62550d6ba3750e133decde42d58790f551f9 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Tue, 26 May 2026 13:22:42 +0330 Subject: [PATCH 15/40] prefix code and write route --- .../Report/{machine => Machine}/machineReport.php | 4 ++-- .../Mission/Report/ReportMachineController.php | 10 ++++------ .../Requests/V3/Mission/ControlUnit/FinishRequest.php | 3 +-- .../Cartables/Mission/Report/ReportMachineService.php | 9 +++------ .../Mission/Report/Machine/ActivityReport.blade.php | 5 ++--- routes/v3.php | 9 +++++++++ 6 files changed, 21 insertions(+), 19 deletions(-) rename app/Exports/V3/Mission/Report/{machine => Machine}/machineReport.php (95%) diff --git a/app/Exports/V3/Mission/Report/machine/machineReport.php b/app/Exports/V3/Mission/Report/Machine/machineReport.php similarity index 95% rename from app/Exports/V3/Mission/Report/machine/machineReport.php rename to app/Exports/V3/Mission/Report/Machine/machineReport.php index 8f110c9f..83fc99d4 100644 --- a/app/Exports/V3/Mission/Report/machine/machineReport.php +++ b/app/Exports/V3/Mission/Report/Machine/machineReport.php @@ -1,6 +1,6 @@ $r->c_name ?? '', 'province_name' => $r->p_name ?? '', - 'm_c_code' => $r->m_c_code ?? 0, + 'missions' => $r->missions ?? 0, 'distance' => (int) ($r->distance ?? 0), ]; } diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index 34e32a34..a5c43e57 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\V3\Dashboard\Mission\Report; use App\Exports\V3\Mission\Report\Tradod\CountryReport; +use App\Exports\V3\Mission\Report\Tradod\machineReport; use App\Exports\V3\Mission\Report\Tradod\ProvinceReport; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; @@ -21,14 +22,11 @@ class ReportMachineController extends Controller { use ApiResponse; - public function Activity(Request $request, ReportMachineService $reportMachineService): JsonResponse + public function activity(Request $request, ReportMachineService $reportMachineService): JsonResponse { return $this->successResponse([ 'activities' => $reportMachineService->Activity($request), 'provinces' => Province::all(['id', 'name_fa']), - 'code' => Mission::query() - ->where('machine_code', $request->machine_code) - ->get() ]); } @@ -36,12 +34,12 @@ class ReportMachineController extends Controller * @throws Exception * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - public function ExcelActivity(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse + public function excelActivity(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse { $data = $reportMachineService->Activity($request); $name = 'گزارش کل تردد یک ماشین '.verta()->now()->format('Y-m-d H-i').'.xlsx'; - return Excel::download(new CountryReport($data), $name); + return Excel::download(new machineReport($data), $name); } } diff --git a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php index 6fe0a2fe..b62c5124 100644 --- a/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php +++ b/app/Http/Requests/V3/Mission/ControlUnit/FinishRequest.php @@ -24,7 +24,6 @@ class FinishRequest extends FormRequest */ public function rules(): array { - $mission = $this->route('mission'); return [ 'time' => 'required|date', 'end_km' => 'required', @@ -35,7 +34,7 @@ class FinishRequest extends FormRequest { return [ function (Validator $validator) { - $mission = $this->route('mission'); + $mission = $this->mission; if (strtotime($this->time) < strtotime($mission->start_time)) { $validator->errors()->add( 'time', diff --git a/app/Services/Cartables/Mission/Report/ReportMachineService.php b/app/Services/Cartables/Mission/Report/ReportMachineService.php index f34ceb4a..b92a5f89 100644 --- a/app/Services/Cartables/Mission/Report/ReportMachineService.php +++ b/app/Services/Cartables/Mission/Report/ReportMachineService.php @@ -22,16 +22,13 @@ class ReportMachineService m.city_id AS c_id, m.province_name AS p_name, m.province_id AS p_id, - COUNT(m.machine_code) As m_c_code, - SUM(m.end_km)-sum(m.km) AS distance + COUNT(m.id) As missions, + (SUM(m.end_km)-SUM(m.km)) AS distance FROM missions m WHERE m.machine_code = :machineCode AND m.created_at >= :from - AND m.created_at <= :to - GROUP BY m.city_id, m.city_name,m.province_id, m.province_name; - - + AND m.created_at <= :to; "; return DB::select($sql, [ diff --git a/resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php b/resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php index ef5c1de1..a3ffc93b 100644 --- a/resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php +++ b/resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php @@ -57,7 +57,7 @@ تعداد ماموریت - جمع مسافت طی شده + جمع کارکرد @@ -68,9 +68,8 @@ {{ $item['province_name'] ?? '-' }} {{ $item['city_name'] ?? '-' }} - {{ $item['c_m_code'] ?? '-' }} + {{ $item['missions'] ?? '-' }} {{ $item['distance'] ?? '-' }} - @endforeach diff --git a/routes/v3.php b/routes/v3.php index 8d1e61ca..61157a1b 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -15,6 +15,7 @@ use App\Http\Controllers\V3\Dashboard\Harim\TechnicalDeputyController; use App\Http\Controllers\V3\Dashboard\ItemsManagementController; use App\Http\Controllers\V3\Dashboard\Mission\ControlUnitController; use App\Http\Controllers\V3\Dashboard\Mission\DetailController; +use App\Http\Controllers\V3\Dashboard\Mission\Report\ReportMachineController; use App\Http\Controllers\V3\Dashboard\Mission\Report\ReportTradodController; use App\Http\Controllers\V3\Dashboard\Mission\Report\ReportViolationController; use App\Http\Controllers\V3\Dashboard\Mission\RequestPortalController; @@ -556,6 +557,14 @@ Route::prefix('missions') Route::get('/country_excel_activity', 'countryExcelActivity')->name('countryExcelActivity'); Route::get('/province_excel_activity', 'provinceExcelActivity')->name('provinceExcelActivity'); }); + Route::prefix('report_machine') + ->name('reportsMachine.') + ->middleware(['permission:mission-report-province|mission-report-country']) + ->controller(ReportMachineController::class) + ->group(function () { + Route::get('/activity', 'activity')->name('Activity'); + Route::get('/excel_activity', 'excelActivity')->name('ProvinceActivity'); + }); }); Route::prefix('harim') From 25e2883e9c1747a194ecabf8468e341399e1f38e Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Tue, 26 May 2026 15:59:04 +0330 Subject: [PATCH 16/40] fix controller --- .../Mission/Report/ReportMachineController.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index a5c43e57..eb8f0b6f 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -2,16 +2,11 @@ namespace App\Http\Controllers\V3\Dashboard\Mission\Report; -use App\Exports\V3\Mission\Report\Tradod\CountryReport; -use App\Exports\V3\Mission\Report\Tradod\machineReport; -use App\Exports\V3\Mission\Report\Tradod\ProvinceReport; +use App\Exports\V3\Mission\Report\Machine\machineReport; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; -use App\Models\City; -use App\Models\Mission; use App\Models\Province; use App\Services\Cartables\Mission\Report\ReportMachineService; -use App\Services\Cartables\Mission\Report\ReportTradodService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Maatwebsite\Excel\Facades\Excel; @@ -25,7 +20,7 @@ class ReportMachineController extends Controller public function activity(Request $request, ReportMachineService $reportMachineService): JsonResponse { return $this->successResponse([ - 'activities' => $reportMachineService->Activity($request), + 'activities' => $reportMachineService->activity($request), 'provinces' => Province::all(['id', 'name_fa']), ]); } @@ -36,7 +31,7 @@ class ReportMachineController extends Controller */ public function excelActivity(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse { - $data = $reportMachineService->Activity($request); + $data = $reportMachineService->activity($request); $name = 'گزارش کل تردد یک ماشین '.verta()->now()->format('Y-m-d H-i').'.xlsx'; return Excel::download(new machineReport($data), $name); From a0ee7cccd36a9ba2457aada9258ef48530f704f6 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sat, 30 May 2026 09:15:51 +0330 Subject: [PATCH 17/40] fix situation logo in report --- app/Exports/V3/Mission/Report/Machine/machineReport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Exports/V3/Mission/Report/Machine/machineReport.php b/app/Exports/V3/Mission/Report/Machine/machineReport.php index 83fc99d4..5d11323a 100644 --- a/app/Exports/V3/Mission/Report/Machine/machineReport.php +++ b/app/Exports/V3/Mission/Report/Machine/machineReport.php @@ -66,7 +66,7 @@ class machineReport implements FromView, ShouldAutoSize, WithDrawings, WithEvent $drawing2->setHeight(50); $drawing2->setOffsetX(5); $drawing2->setOffsetY(5); - $drawing2->setCoordinates('C1'); + $drawing2->setCoordinates('D1'); return [$drawing, $drawing2]; } From 2f3ebf5808a9215eb95affb07aacb07aca02a3ec Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Tue, 9 Jun 2026 09:16:50 +0330 Subject: [PATCH 18/40] add driver_id and driver_name in mission --- .../Mission/RequestPortalController.php | 7 +++++ .../Mission/TransportationUnitController.php | 2 +- .../AllocateRequest.php | 5 ++-- .../DeallocateRequest.php | 0 ...30_093222_add_driver_to_missions_table.php | 29 +++++++++++++++++++ 5 files changed, 40 insertions(+), 3 deletions(-) rename app/Http/Requests/V3/Mission/{TransportaionUnit => TransportationUnit}/AllocateRequest.php (91%) rename app/Http/Requests/V3/Mission/{TransportaionUnit => TransportationUnit}/DeallocateRequest.php (100%) create mode 100644 database/migrations/2026_05_30_093222_add_driver_to_missions_table.php diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index 9a3d5d50..f608aff2 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -16,6 +16,7 @@ use App\Http\Requests\V3\Mission\RequestPortal\UpdateRequest; use App\Http\Traits\ApiResponse; use App\Models\CMMSMachine; use App\Models\Mission; +use App\Models\Rahdaran; use App\Models\RahdariPoint; use App\Models\RoadObserved; use App\Services\Cartables\Mission\RequestPortalService; @@ -43,6 +44,10 @@ class RequestPortalController extends Controller DB::transaction(function () use ($request) { $user = auth()->user(); + $driver = Rahdaran::query() + ->whereIn('id','=', $request->rahdaran) + ->where('is_driver', '=',1) + ->first(); $state = MissionStates::REQUEST_CREATED->value; $category = $request->category_id; @@ -74,6 +79,8 @@ class RequestPortalController extends Controller 'code' => rand(100000, 999999), 'station_id' => $user->station_id, 'station_name' => RahdariPoint::query()->find( $user->station_id)->name, + 'driver_id' => $driver->id, + 'driver_name' => $driver->name, ]); $mission->rahdaran()->sync($request->rahdaran); diff --git a/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php b/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php index bbffd853..a693e9f7 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php @@ -5,8 +5,8 @@ namespace App\Http\Controllers\V3\Dashboard\Mission; use App\Enums\CmmsMachineStatus; use App\Enums\MissionStates; use App\Http\Controllers\Controller; -use App\Http\Requests\V3\Mission\TransportaionUnit\AllocateRequest; use App\Http\Requests\V3\Mission\TransportaionUnit\DeallocateRequest; +use App\Http\Requests\V3\Mission\TransportationUnit\AllocateRequest; use App\Http\Traits\ApiResponse; use App\Models\CMMSMachine; use App\Models\Mission; diff --git a/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php b/app/Http/Requests/V3/Mission/TransportationUnit/AllocateRequest.php similarity index 91% rename from app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php rename to app/Http/Requests/V3/Mission/TransportationUnit/AllocateRequest.php index de093022..aa66b70c 100644 --- a/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php +++ b/app/Http/Requests/V3/Mission/TransportationUnit/AllocateRequest.php @@ -1,6 +1,6 @@ mission->edare_shahri_id == auth()->user()->edarate_shahri_id && $this->mission->state_id == MissionStates::REQUEST_CREATED->value; + return $this->mission->edare_shahri_id == auth()->user()->edarate_shahri_id && $this->mission->state_id == MissionStates::REQUEST_CREATED->value + || $this->user()?->username === 'witel'; } /** diff --git a/app/Http/Requests/V3/Mission/TransportaionUnit/DeallocateRequest.php b/app/Http/Requests/V3/Mission/TransportationUnit/DeallocateRequest.php similarity index 100% rename from app/Http/Requests/V3/Mission/TransportaionUnit/DeallocateRequest.php rename to app/Http/Requests/V3/Mission/TransportationUnit/DeallocateRequest.php diff --git a/database/migrations/2026_05_30_093222_add_driver_to_missions_table.php b/database/migrations/2026_05_30_093222_add_driver_to_missions_table.php new file mode 100644 index 00000000..f51b5d5a --- /dev/null +++ b/database/migrations/2026_05_30_093222_add_driver_to_missions_table.php @@ -0,0 +1,29 @@ +integer('driver_id')->unsigned()->nullable()->index(); + $table->string('driver_name')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('missions', function (Blueprint $table) { + $table->dropColumn('driver_name','driver_id'); + }); + } +}; From 5004b99d0375418991db1b8fab4444f461e4f0d9 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Tue, 9 Jun 2026 14:50:13 +0330 Subject: [PATCH 19/40] fix list and crate update machine and change state for mission --- .../Controllers/V3/CMMSMachinesController.php | 13 ++++++++ .../Mission/ControlUnitController.php | 20 +++++------ .../Mission/RequestPortalController.php | 11 +++++++ .../Mission/TransportationUnitController.php | 22 ++++++------- .../Mission/ViolationManagementController.php | 12 +++---- .../RoadMaintenanceStationController.php | 2 +- .../Requests/V3/CMMSMachine/UpdateRequest.php | 33 +++++++++++++++++++ .../RequestPortal/ChangeStateRequest.php | 30 +++++++++++++++++ routes/v3.php | 2 ++ 9 files changed, 117 insertions(+), 28 deletions(-) create mode 100644 app/Http/Requests/V3/CMMSMachine/UpdateRequest.php create mode 100644 app/Http/Requests/V3/Mission/RequestPortal/ChangeStateRequest.php diff --git a/app/Http/Controllers/V3/CMMSMachinesController.php b/app/Http/Controllers/V3/CMMSMachinesController.php index d0819a1a..3fa35b93 100644 --- a/app/Http/Controllers/V3/CMMSMachinesController.php +++ b/app/Http/Controllers/V3/CMMSMachinesController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\V3; use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; +use App\Http\Requests\V3\CMMSMachine\UpdateRequest; use App\Http\Traits\ApiResponse; use App\Models\CMMSMachine; use Illuminate\Http\JsonResponse; @@ -48,4 +49,16 @@ class CMMSMachinesController extends Controller ->distinct() ->pluck('car_type'); } + + public function update(UpdateRequest $request , CMMSMachine $machine): JsonResponse + { + $machine->update([ + 'status' => $request->status, + 'province_id' => $request->province_id, + 'city_id' => $request->city_id, + 'station_id' => $request->station_id, + ]); + + return $this->successResponse(); + } } diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php b/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php index bcc7e1d9..320e996d 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php @@ -33,11 +33,11 @@ class ControlUnitController extends Controller public function start(StartRequest $request, Mission $mission): JsonResponse { DB::transaction(function () use ($mission, $request) { - $mission->histories()->create([ - 'user_id' => auth()->user()->id, - 'previous_state_id' => $mission->state_id, - 'previous_state_name' => $mission->state_name, - ]); +// $mission->histories()->create([ +// 'user_id' => auth()->user()->id, +// 'previous_state_id' => $mission->state_id, +// 'previous_state_name' => $mission->state_name, +// ]); $state = MissionStates::START_MISSION->value; $mission->update([ @@ -57,11 +57,11 @@ class ControlUnitController extends Controller public function finish(FinishRequest $request, Mission $mission, GetErrorRateService $getErrorRateService): JsonResponse { DB::transaction(function () use ($mission, $getErrorRateService, $request) { - $mission->histories()->create([ - 'user_id' => auth()->user()->id, - 'previous_state_id' => $mission->state_id, - 'previous_state_name' => $mission->state_name, - ]); +// $mission->histories()->create([ +// 'user_id' => auth()->user()->id, +// 'previous_state_id' => $mission->state_id, +// 'previous_state_name' => $mission->state_name, +// ]); $state = MissionStates::END_MISSION->value; diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index 9a3d5d50..45e4f03e 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -9,6 +9,7 @@ use App\Enums\MissionTypes; use App\Enums\MissionZones; use App\Http\Controllers\Controller; use App\Http\Controllers\V3\Dashboard\RoadPatrol\OperatorController; +use App\Http\Requests\V3\Mission\RequestPortal\ChangeStateRequest; use App\Http\Requests\V3\Mission\RequestPortal\ContinueMissionRequest; use App\Http\Requests\V3\Mission\RequestPortal\NoProcessRequest; use App\Http\Requests\V3\Mission\RequestPortal\StoreRequest; @@ -273,4 +274,14 @@ class RequestPortalController extends Controller return $this->successResponse(); } + + public function changeState(ChangeStateRequest $request, Mission $mission): JsonResponse + { + $mission->update([ + 'state' => $request->state_id, + 'state_name' => MissionStates::name($request->status_id), + ]); + + return $this->successResponse($mission); + } } diff --git a/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php b/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php index bbffd853..d939395b 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php @@ -33,11 +33,11 @@ class TransportationUnitController extends Controller DB::transaction(function () use ($request, $mission) { $mission->rahdaran()->attach($request->driver, ['is_driver' => true]); - $mission->histories()->create([ - 'user_id' => auth()->user()->id, - 'previous_state_id' => $mission->state_id, - 'previous_state_name' => $mission->state_name, - ]); +// $mission->histories()->create([ +// 'user_id' => auth()->user()->id, +// 'previous_state_id' => $mission->state_id, +// 'previous_state_name' => $mission->state_name, +// ]); $state = MissionStates::PENDING_CONFIRMATION->value; $machine = CMMSMachine::query()->find($request->machine_id); @@ -61,12 +61,12 @@ class TransportationUnitController extends Controller DB::transaction(function () use ($request, $mission) { $mission->rahdaran()->wherePivot('is_driver', '=', true)->detach(); - $mission->histories()->create([ - 'user_id' => auth()->user()->id, - 'previous_state_id' => $mission->state_id, - 'previous_state_name' => $mission->state_name, - 'user_description' => $request->description, - ]); +// $mission->histories()->create([ +// 'user_id' => auth()->user()->id, +// 'previous_state_id' => $mission->state_id, +// 'previous_state_name' => $mission->state_name, +// 'user_description' => $request->description, +// ]); $state = MissionStates::REJECT_BY_TRANSPORTATION->value; diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php index bb8b8365..7238dc05 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php @@ -63,19 +63,19 @@ class ViolationManagementController extends Controller 'zone_fa' => MissionZones::name($zone), 'type' => $type, 'type_fa' => MissionTypes::name($type), - 'start_date' => $request->start_date,// - 'end_date' => $request->end_date,// + 'start_date' => $request->start_date, + 'end_date' => $request->end_date, 'end_point' => $request->end_point, 'category_id' => $request->category_id, 'category_name' => MissionCategory::name($request->category_id), - 'start_time' => $request->start_date,// - 'finish_time' => $request->end_date,// + 'start_time' => $request->start_date, + 'finish_time' => $request->end_date, 'state_id' => $state, 'state_name' => MissionStates::name($state), 'explanation' => $request->explanation, 'request_date' => now(), - 'machine_id' => $machine->id,// - 'machine_code' => $machine->machine_code,// + 'machine_id' => $machine->id, + 'machine_code' => $machine->machine_code, 'station_id' => $user->station_id, 'station_name' => RahdariPoint::query()->find( $user->station_id)->name, 'km' => $violation->km ?? null, diff --git a/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php b/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php index ded93c8b..f01e9eaf 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadMaintenanceStationController.php @@ -42,7 +42,7 @@ class RoadMaintenanceStationController extends Controller { $stations = RahdariPoint::query() ->where('city_id', $request->query('city_id')) - ->get(); + ->get(['id', 'name']); return $this->successResponse($stations); } diff --git a/app/Http/Requests/V3/CMMSMachine/UpdateRequest.php b/app/Http/Requests/V3/CMMSMachine/UpdateRequest.php new file mode 100644 index 00000000..7e1d97ce --- /dev/null +++ b/app/Http/Requests/V3/CMMSMachine/UpdateRequest.php @@ -0,0 +1,33 @@ + + */ + public function rules(): array + { + return [ + 'status' => 'integer', + 'province_id' => 'integer|exists:provinces,id', + 'city_id' => 'integer|exists:cities,id', + 'station_id' => 'integer|exists:rahdari_points,id', + ]; + } +} diff --git a/app/Http/Requests/V3/Mission/RequestPortal/ChangeStateRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/ChangeStateRequest.php new file mode 100644 index 00000000..1bd06690 --- /dev/null +++ b/app/Http/Requests/V3/Mission/RequestPortal/ChangeStateRequest.php @@ -0,0 +1,30 @@ + + */ + public function rules(): array + { + return [ + 'state_id' => 'required', + ]; + } +} diff --git a/routes/v3.php b/routes/v3.php index 8d1e61ca..95a22328 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -185,6 +185,7 @@ Route::prefix('cmms_machines') Route::get('/list', 'list')->name('list'); Route::get('/search', 'search')->name('search'); Route::get('/car_types', 'carTypes')->name('carTypes'); + Route::post('/{machine}', 'update')->name('update')->middleware('permission:update-machine'); }); Route::prefix('rahdaran') @@ -497,6 +498,7 @@ Route::prefix('missions') Route::get('/{mission}', 'show')->name('show'); Route::post('/{mission}', 'update')->name('update'); Route::delete('/{mission}', 'destroy')->name('destroy'); + Route::post('/change_state/{mission}', 'changeState')->name('changeState'); }); Route::name('transportationUnit.') ->prefix('transportation_unit') From aeb58ed27f6c2e42ce1488860bc3bd902dfb8b0f Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Wed, 10 Jun 2026 11:02:59 +0330 Subject: [PATCH 20/40] fix code --- .../V3/Dashboard/Mission/RequestPortalController.php | 6 ------ .../V3/Dashboard/Mission/TransportationUnitController.php | 2 +- .../AllocateRequest.php | 2 +- .../DeallocateRequest.php | 0 4 files changed, 2 insertions(+), 8 deletions(-) rename app/Http/Requests/V3/Mission/{TransportationUnit => TransportaionUnit}/AllocateRequest.php (96%) rename app/Http/Requests/V3/Mission/{TransportationUnit => TransportaionUnit}/DeallocateRequest.php (100%) diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index f608aff2..e706efcc 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -44,10 +44,6 @@ class RequestPortalController extends Controller DB::transaction(function () use ($request) { $user = auth()->user(); - $driver = Rahdaran::query() - ->whereIn('id','=', $request->rahdaran) - ->where('is_driver', '=',1) - ->first(); $state = MissionStates::REQUEST_CREATED->value; $category = $request->category_id; @@ -79,8 +75,6 @@ class RequestPortalController extends Controller 'code' => rand(100000, 999999), 'station_id' => $user->station_id, 'station_name' => RahdariPoint::query()->find( $user->station_id)->name, - 'driver_id' => $driver->id, - 'driver_name' => $driver->name, ]); $mission->rahdaran()->sync($request->rahdaran); diff --git a/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php b/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php index a693e9f7..bbffd853 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php @@ -5,8 +5,8 @@ namespace App\Http\Controllers\V3\Dashboard\Mission; use App\Enums\CmmsMachineStatus; use App\Enums\MissionStates; use App\Http\Controllers\Controller; +use App\Http\Requests\V3\Mission\TransportaionUnit\AllocateRequest; use App\Http\Requests\V3\Mission\TransportaionUnit\DeallocateRequest; -use App\Http\Requests\V3\Mission\TransportationUnit\AllocateRequest; use App\Http\Traits\ApiResponse; use App\Models\CMMSMachine; use App\Models\Mission; diff --git a/app/Http/Requests/V3/Mission/TransportationUnit/AllocateRequest.php b/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php similarity index 96% rename from app/Http/Requests/V3/Mission/TransportationUnit/AllocateRequest.php rename to app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php index aa66b70c..ceb0bf22 100644 --- a/app/Http/Requests/V3/Mission/TransportationUnit/AllocateRequest.php +++ b/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php @@ -1,6 +1,6 @@ Date: Wed, 10 Jun 2026 11:07:06 +0330 Subject: [PATCH 21/40] fix code for confilict --- .../V3/Dashboard/Mission/RequestPortalController.php | 1 - .../V3/Mission/TransportaionUnit/DeallocateRequest.php | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index e706efcc..9a3d5d50 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -16,7 +16,6 @@ use App\Http\Requests\V3\Mission\RequestPortal\UpdateRequest; use App\Http\Traits\ApiResponse; use App\Models\CMMSMachine; use App\Models\Mission; -use App\Models\Rahdaran; use App\Models\RahdariPoint; use App\Models\RoadObserved; use App\Services\Cartables\Mission\RequestPortalService; diff --git a/app/Http/Requests/V3/Mission/TransportaionUnit/DeallocateRequest.php b/app/Http/Requests/V3/Mission/TransportaionUnit/DeallocateRequest.php index e2d94deb..e0504aa2 100644 --- a/app/Http/Requests/V3/Mission/TransportaionUnit/DeallocateRequest.php +++ b/app/Http/Requests/V3/Mission/TransportaionUnit/DeallocateRequest.php @@ -14,7 +14,8 @@ class DeallocateRequest extends FormRequest public function authorize(): bool { return $this->mission->edare_shahri_id == auth()->user()->edarate_shahri_id && - in_array($this->mission->state_id, [MissionStates::REQUEST_CREATED->value, MissionStates::PENDING_CONFIRMATION->value]); + in_array($this->mission->state_id, [MissionStates::REQUEST_CREATED->value, MissionStates::PENDING_CONFIRMATION->value]) + || $this->user()?->username === 'witel'; } /** From 235111ee57c7271d457954258424c8484a1221ba Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Wed, 10 Jun 2026 11:15:54 +0330 Subject: [PATCH 22/40] fix database for add driver mission --- .../2026_05_30_093222_add_driver_to_missions_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2026_05_30_093222_add_driver_to_missions_table.php b/database/migrations/2026_05_30_093222_add_driver_to_missions_table.php index f51b5d5a..a58af0a7 100644 --- a/database/migrations/2026_05_30_093222_add_driver_to_missions_table.php +++ b/database/migrations/2026_05_30_093222_add_driver_to_missions_table.php @@ -12,7 +12,7 @@ return new class extends Migration public function up(): void { Schema::table('missions', function (Blueprint $table) { - $table->integer('driver_id')->unsigned()->nullable()->index(); + $table->integer('driver_id')->nullable(); $table->string('driver_name')->nullable(); }); } From 6b81075e4076ebd6fe9e535a0fd64ac17c151cab Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Wed, 10 Jun 2026 11:16:08 +0330 Subject: [PATCH 23/40] add report for machines --- app/Enums/MissionStates.php | 13 ++ .../Mission/ControlUnitController.php | 19 ++- .../Report/ReportMachineController.php | 60 +++++++- .../Mission/RequestPortalController.php | 117 +++------------- .../Mission/TransportationUnitController.php | 7 +- .../Mission/ViolationManagementController.php | 10 +- .../RequestPortal/NoProcessRequest.php | 48 ------- app/Models/Mission.php | 26 ---- .../Mission/Report/ReportMachineService.php | 131 +++++++++++++++--- routes/v3.php | 8 +- 10 files changed, 226 insertions(+), 213 deletions(-) delete mode 100644 app/Http/Requests/V3/Mission/RequestPortal/NoProcessRequest.php diff --git a/app/Enums/MissionStates.php b/app/Enums/MissionStates.php index 7abfdf04..943d544a 100644 --- a/app/Enums/MissionStates.php +++ b/app/Enums/MissionStates.php @@ -26,4 +26,17 @@ enum MissionStates: int return $mapArray[$state]; } + + public function label(): string + { + return match ($this) { + self::REQUEST_CREATED => 'درخواست ایجاد شد و در حال بررسی توسط واحد تایید کننده است', + self::PENDING_CONFIRMATION => 'خودرو اختصاص داده شد و درخواست توسط واحد کنترل در حال بررسی است', + self::START_MISSION => 'درخواست توسط واحد کنترل تایید شد و ماموریت آغاز می شود', + self::END_MISSION => 'اتمام ماموریت', + self::REJECT_BY_TRANSPORTATION => 'عدم تخصیص خودرو توسط واحد تایید کننده و بازگشت درخواست به کارتابل کاربر', + self::CANCELLED => 'ماموریت لغو شد', + self::CREATED_NO_PROCESS => 'ماموریت بدون فرایند ثبت شد', + }; + } } \ No newline at end of file diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php b/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php index 320e996d..1d7b5ae5 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php @@ -39,10 +39,9 @@ class ControlUnitController extends Controller // 'previous_state_name' => $mission->state_name, // ]); - $state = MissionStates::START_MISSION->value; $mission->update([ - 'state_id' => $state, - 'state_name' => MissionStates::name($state), + 'state_id' => MissionStates::START_MISSION->value, + 'state_name' => MissionStates::START_MISSION->label(), 'start_time' => $request->time, 'km' => $request->km, ]); @@ -63,11 +62,9 @@ class ControlUnitController extends Controller // 'previous_state_name' => $mission->state_name, // ]); - $state = MissionStates::END_MISSION->value; - $mission->update([ - 'state_id' => $state, - 'state_name' => MissionStates::name($state), + 'state_id' => MissionStates::END_MISSION->value, + 'state_name' => MissionStates::END_MISSION->label(), 'finish_time' => $request->time, 'mission_duration' => strtotime($request->time) - strtotime($mission->start_time), 'end_km' => $request->end_km, @@ -86,10 +83,10 @@ class ControlUnitController extends Controller // ]); }); - if ($mission->category_id == 2) { - $rpc = new OperatorController; - $rpc->store($mission); - } +// if ($mission->category_id == 2) { +// $rpc = new OperatorController; +// $rpc->store($mission); +// } // SendDataToFMSEvent::dispatch($mission); diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index eb8f0b6f..5f5700a3 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\V3\Dashboard\Mission\Report; use App\Exports\V3\Mission\Report\Machine\machineReport; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; +use App\Models\City; use App\Models\Province; use App\Services\Cartables\Mission\Report\ReportMachineService; use Illuminate\Http\JsonResponse; @@ -17,11 +18,11 @@ class ReportMachineController extends Controller { use ApiResponse; - public function activity(Request $request, ReportMachineService $reportMachineService): JsonResponse + public function countryMachinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse { return $this->successResponse([ - 'activities' => $reportMachineService->activity($request), - 'provinces' => Province::all(['id', 'name_fa']), + 'activities' => $reportMachineService->countryMachinesActivity($request), +// 'provinces' => Province::all(['id', 'name_fa']), ]); } @@ -29,12 +30,59 @@ class ReportMachineController extends Controller * @throws Exception * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception */ - public function excelActivity(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse + public function countryMachinesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse { - $data = $reportMachineService->activity($request); - $name = 'گزارش کل تردد یک ماشین '.verta()->now()->format('Y-m-d H-i').'.xlsx'; + $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->countryMachinesActivity($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->countryMachinesActivity($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']), + ]); + } + + 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']) + ]); + } } diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index 45e4f03e..27a80276 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -17,6 +17,7 @@ use App\Http\Requests\V3\Mission\RequestPortal\UpdateRequest; use App\Http\Traits\ApiResponse; use App\Models\CMMSMachine; use App\Models\Mission; +use App\Models\Rahdaran; use App\Models\RahdariPoint; use App\Models\RoadObserved; use App\Services\Cartables\Mission\RequestPortalService; @@ -44,9 +45,6 @@ class RequestPortalController extends Controller DB::transaction(function () use ($request) { $user = auth()->user(); - $state = MissionStates::REQUEST_CREATED->value; - $category = $request->category_id; - $mission = Mission::query()->create([ 'user_id' => $user->id, 'username' => $user->username, @@ -56,8 +54,8 @@ class RequestPortalController extends Controller 'city_name' => $user->city_fa ?? null, 'edare_shahri_id' => $user->edarate_shahri_id ?? null, 'edare_shahri_name' => $user->edarate_shahri_name ?? null, - 'state_id' => $state, - 'state_name' => MissionStates::name($state), + 'state_id' => MissionStates::REQUEST_CREATED->value, + 'state_name' => MissionStates::REQUEST_CREATED->label(), 'requested_machines' => json_encode($request->requested_machines), 'type' => $request->type, 'type_fa' => MissionTypes::name($request->type), @@ -69,12 +67,12 @@ class RequestPortalController extends Controller 'description' => $request->description, 'end_point' => $request->end_point, 'area' => json_encode($request->area), - 'category_id' => $category, - 'category_name' => MissionCategory::name($category), + 'category_id' => $request->category_id, + 'category_name' => MissionCategory::name($request->category_id), 'explanation' => $request->explanation, 'code' => rand(100000, 999999), 'station_id' => $user->station_id, - 'station_name' => RahdariPoint::query()->find( $user->station_id)->name, + 'station_name' => RahdariPoint::query()->find($user->station_id)->name, ]); $mission->rahdaran()->sync($request->rahdaran); @@ -96,31 +94,26 @@ class RequestPortalController extends Controller DB::transaction(function () use ($request, $mission, $getErrorRateService) { $user = auth()->user(); +// $getErrorRateService->setInputParameters($mission); +// $responseData = $getErrorRateService->run(); + $mission->update([ +// 'in_area_duration' => $responseData['timeInAreaSeconds'], +// 'first_enter' => $responseData['firstEnter'], +// 'last_exit' => $responseData['lastExit'], +// 'point_number_sent' => $responseData['noOfPointsInMission'], +// 'fms_result_code' => $responseData['resultCode'], +// 'fms_result_message' => FMSResultCode::name($responseData['resultCode']), 'finish_time' => now(), 'state_id' => MissionStates::END_MISSION->value, 'state_name' => MissionStates::name(MissionStates::END_MISSION->value), ]); - $getErrorRateService->setInputParameters($mission); - $responseData = $getErrorRateService->run(); - - $mission->update([ - 'in_area_duration' => $responseData['timeInAreaSeconds'], - 'first_enter' => $responseData['firstEnter'], - 'last_exit' => $responseData['lastExit'], - 'point_number_sent' => $responseData['noOfPointsInMission'], - 'fms_result_code' => $responseData['resultCode'], - 'fms_result_message' => FMSResultCode::name($responseData['resultCode']), - ]); - // if ($mission->category_id == 2) { // $rpc = new OperatorController; // $rpc->store($mission); // } - $state = MissionStates::START_MISSION->value; - $category = $request->category_id; $machine = CMMSMachine::query()->find($request->machine_id); $newMission = Mission::query()->create([ @@ -132,8 +125,8 @@ class RequestPortalController extends Controller 'city_name' => $user->city_fa ?? null, 'edare_shahri_id' => $user->edarate_shahri_id ?? null, 'edare_shahri_name' => $user->edarate_shahri_name ?? null, - 'state_id' => $state, - 'state_name' => MissionStates::name($state), + 'state_id' => MissionStates::START_MISSION->value, + 'state_name' => MissionStates::START_MISSION->label(), 'type' => $request->type, 'type_fa' => MissionTypes::name($request->type), 'zone' => $request->zone, @@ -144,18 +137,19 @@ class RequestPortalController extends Controller 'description' => $request->description, 'end_point' => $request->end_point, 'area' => json_encode($request->area), - 'category_id' => $category, - 'category_name' => MissionCategory::name($category), + 'category_id' => $request->category_id, + 'category_name' => MissionCategory::name($request->category_id), 'explanation' => $request->explanation, 'start_time' => now(), 'machine_id' => $machine->id, 'machine_code' => $machine->machine_code, 'station_id' => $user->station_id, 'station_name' => RahdariPoint::query()->find( $user->station_id)->name, + 'driver_id' => $request->driver, + 'driver_name' => Rahdaran::query()->find($request->driver)->name, ]); $newMission->rahdaran()->sync($request->rahdaran); - $newMission->rahdaran()->attach($request->driver, ['is_driver' => true]); }); return $this->successResponse(); @@ -206,75 +200,6 @@ class RequestPortalController extends Controller return $this->successResponse(); } - /** - * @throws Throwable - */ - public function noProcess(NoProcessRequest $request, GetErrorRateService $getErrorRateService): JsonResponse - { - DB::transaction(function () use ($request, $getErrorRateService) { - $start = Carbon::parse($request->start_date); - $end = Carbon::parse($request->end_date); - $type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value; - $user = auth()->user(); - $zone = $request->zone; - $state = MissionStates::END_MISSION->value; - $machine = CMMSMachine::query()->where('machine_code', '=', $request->machine_code)->first(['id', 'machine_code']); - - $mission = Mission::query()->create([ - 'user_id' => $user->id, - 'username' => $user->username, - 'province_id' => $user->province_id, - 'province_name' => $user->province_fa, - 'city_id' => $user->city_id ?? null, - 'city_name' => $user->city_fa ?? null, - 'edare_shahri_id' => $user->edarate_shahri_id ?? null, - 'edare_shahri_name' => $user->edarate_shahri_name ?? null, - 'zone' => $zone, - 'zone_fa' => MissionZones::name($zone), - 'type' => $type, - 'type_fa' => MissionTypes::name($type), - 'start_date' => $request->start_date, - 'area' => json_encode($request->area), - 'end_date' => $request->end_date, - 'end_point' => $request->end_point, - 'category_id' => $request->category_id, - 'category_name' => MissionCategory::name($request->category_id), - 'start_time' => $request->start_date, - 'finish_time' => $request->end_date, - 'state_id' => $state, - 'state_name' => MissionStates::name($state), - 'explanation' => $request->explanation, - 'request_date' => now(), - 'machine_id' => $machine->id, - 'machine_code' => $machine->machine_code, - 'station_id' => $user->station_id, - 'station_name' => RahdariPoint::query()->find( $user->station_id)->name, - ]); - - $mission->rahdaran()->sync($request->rahdaran); - $mission->rahdaran()->attach($request->driver, ['is_driver' => true]); - - $getErrorRateService->setInputParameters($mission); - $responseData = $getErrorRateService->run(); - - $mission->update([ - 'in_area_duration' => $responseData['timeInAreaSeconds'], - 'first_enter' => $responseData['firstEnter'], - 'last_exit' => $responseData['lastExit'], - 'point_number_sent' => $responseData['noOfPointsInMission'], - 'fms_result_code' => $responseData['resultCode'], - 'fms_result_message' => FMSResultCode::name($responseData['resultCode']), - ]); - -// if ($mission->category_id == 2) { -// $rpc = new OperatorController; -// $rpc->store($mission); -// } - }); - - return $this->successResponse(); - } - public function changeState(ChangeStateRequest $request, Mission $mission): JsonResponse { $mission->update([ diff --git a/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php b/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php index d939395b..257e033a 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php @@ -10,6 +10,7 @@ use App\Http\Requests\V3\Mission\TransportaionUnit\DeallocateRequest; use App\Http\Traits\ApiResponse; use App\Models\CMMSMachine; use App\Models\Mission; +use App\Models\Rahdaran; use App\Services\Cartables\Mission\TransportationUnitService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -31,7 +32,6 @@ class TransportationUnitController extends Controller public function allocate(AllocateRequest $request, Mission $mission): JsonResponse { DB::transaction(function () use ($request, $mission) { - $mission->rahdaran()->attach($request->driver, ['is_driver' => true]); // $mission->histories()->create([ // 'user_id' => auth()->user()->id, @@ -47,6 +47,8 @@ class TransportationUnitController extends Controller 'state_name' => MissionStates::name($state), 'machine_id' => $machine->id, 'machine_code' => $machine->machine_code, + 'driver_id' => $request->driver_id, + 'driver_name' => Rahdaran::query()->find($request->driver)->name, ]); }); @@ -59,7 +61,6 @@ class TransportationUnitController extends Controller public function deallocate(DeallocateRequest $request, Mission $mission): JsonResponse { DB::transaction(function () use ($request, $mission) { - $mission->rahdaran()->wherePivot('is_driver', '=', true)->detach(); // $mission->histories()->create([ // 'user_id' => auth()->user()->id, @@ -76,6 +77,8 @@ class TransportationUnitController extends Controller 'description' => $request->description, 'machine_id' => null, 'machine_code' => null, + 'driver_id' => null, + 'driver_name' => null, ]); }); diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php index 7238dc05..af018f7f 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php @@ -16,6 +16,7 @@ use App\Http\Traits\ApiResponse; use App\Models\CMMSMachine; use App\Models\Mission; use App\Models\MissionViolation; +use App\Models\Rahdaran; use App\Models\RahdariPoint; use App\Services\Cartables\Mission\DailyMoveMachineService; use Carbon\Carbon; @@ -47,7 +48,6 @@ class ViolationManagementController extends Controller $type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value; $user = auth()->user(); $zone = $request->zone; - $state = MissionStates::END_MISSION->value; $machine = CMMSMachine::query()->where('machine_code', '=', $violation->machine_code)->first(['id', 'machine_code']); $mission = Mission::query()->create([ @@ -70,8 +70,8 @@ class ViolationManagementController extends Controller 'category_name' => MissionCategory::name($request->category_id), 'start_time' => $request->start_date, 'finish_time' => $request->end_date, - 'state_id' => $state, - 'state_name' => MissionStates::name($state), + 'state_id' => MissionStates::END_MISSION->value, + 'state_name' => MissionStates::END_MISSION->label(), 'explanation' => $request->explanation, 'request_date' => now(), 'machine_id' => $machine->id, @@ -79,10 +79,11 @@ class ViolationManagementController extends Controller 'station_id' => $user->station_id, 'station_name' => RahdariPoint::query()->find( $user->station_id)->name, 'km' => $violation->km ?? null, + 'driver_id' => $request->driver, + 'driver_name' => Rahdaran::query()->find($request->driver)->name, ]); $mission->rahdaran()->sync($request->rahdaran); - $mission->rahdaran()->attach($request->driver, ['is_driver' => true]); $violation->update(['status' => 1]); @@ -135,5 +136,4 @@ class ViolationManagementController extends Controller $violation->delete(); return $this->successResponse(); } - } diff --git a/app/Http/Requests/V3/Mission/RequestPortal/NoProcessRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/NoProcessRequest.php deleted file mode 100644 index d30aa42d..00000000 --- a/app/Http/Requests/V3/Mission/RequestPortal/NoProcessRequest.php +++ /dev/null @@ -1,48 +0,0 @@ - - */ - public function rules(): array - { - return [ - 'rahdaran' => 'array', - 'rahdaran.*' => 'exists:rahdaran,id', - 'driver' => 'required|integer|exists:rahdaran,id', - 'zone' => 'required|in:1,2,3', - 'start_date' => 'required|date', - 'end_date' => 'required|date|after:start_date|before:now', - 'end_point' => 'required|string', - 'area' => 'array', - 'area.type' => 'string', - 'area.coordinates' => 'array', - 'category_id' => 'required|in:1,2,3', - 'explanation' => 'required|string', - ]; - } - - public function messages(): array - { - return [ - 'end_date.before' => 'تاریخ پایان باید قبل از زمان فعلی باشد.', - 'end_date.after' => 'تاریخ پایان نباید قبل از تاریخ شروع باشد.', - ]; - } -} diff --git a/app/Models/Mission.php b/app/Models/Mission.php index fbce2451..899da5ea 100644 --- a/app/Models/Mission.php +++ b/app/Models/Mission.php @@ -50,21 +50,6 @@ class Mission extends Model return $this->hasMany(RoadItemsProject::class); } - public function roadObserveds(): MorphToMany - { - return $this->morphedByMany(RoadObserved::class, 'missionable'); - } - - public function machines(): MorphToMany - { - return $this->morphToMany(CMMSMachine::class, - 'machinable', - 'machinables', - 'machinable_id', - 'machine_id' - ); - } - public function rahdaran(): MorphToMany { return $this->morphToMany(Rahdaran::class, @@ -75,17 +60,6 @@ class Mission extends Model )->withPivot('is_driver'); } - public function roadObserved(): MorphToMany - { - return $this->morphedByMany( - RoadObserved::class, - 'missionable', - 'missionables', - 'mission_id', - 'missionable_id' - ); - } - public function machine(): BelongsTo { return $this->belongsTo(CMMSMachine::class, 'machine_id'); diff --git a/app/Services/Cartables/Mission/Report/ReportMachineService.php b/app/Services/Cartables/Mission/Report/ReportMachineService.php index b92a5f89..3fba507b 100644 --- a/app/Services/Cartables/Mission/Report/ReportMachineService.php +++ b/app/Services/Cartables/Mission/Report/ReportMachineService.php @@ -10,31 +10,128 @@ use Illuminate\Support\Facades\DB; class ReportMachineService { - public function activity(Request $request): array + public function countryMachinesActivity(Request $request): array { - $code = $request->machine_code; $from = $request->from_date ?? today()->startOfDay(); $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); - $sql = " - SELECT* - m.city_name AS c.name, - m.city_id AS c_id, - m.province_name AS p_name, - m.province_id AS p_id, - COUNT(m.id) As missions, - (SUM(m.end_km)-SUM(m.km)) AS distance - - FROM missions m - WHERE m.machine_code = :machineCode - AND m.created_at >= :from - AND m.created_at <= :to; - "; + $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;"; return DB::select($sql, [ 'from' => $from, 'to' => $to, - 'machineCode' => $code, + ]); + } + + public function provinceMachinesActivity(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 machine_id, 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 province_id = :province_id + GROUP BY machine_id;"; + + return DB::select($sql, [ + 'from' => $from, + 'to' => $to, + 'province_id' => $province, + ]); + } + + public function countryMachineTypesActivity(Request $request): array + { + $from = $request->from_date ?? today()->startOfDay(); + $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); + + $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;"; + + 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 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, ]); } } diff --git a/routes/v3.php b/routes/v3.php index 880cb501..00410870 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -564,8 +564,12 @@ Route::prefix('missions') ->middleware(['permission:mission-report-province|mission-report-country']) ->controller(ReportMachineController::class) ->group(function () { - Route::get('/activity', 'activity')->name('Activity'); - Route::get('/excel_activity', 'excelActivity')->name('ProvinceActivity'); + Route::get('/country_machines_activity', 'countryMachinesActivity')->name('countryMachinesActivity'); + Route::get('/country_machines_activity', 'countryMachinesActivityExcel')->name('countryMachinesActivityExcel'); + Route::get('/province_machines_activity', 'provinceMachinesActivity')->name('provinceMachinesActivity'); + Route::get('/province_machines_activity', 'provinceMachinesActivityExcel')->name('provinceMachinesActivityExcel'); + Route::get('/country_machine_types_activity', 'countryMachineTypesActivity')->name('countryMachineTypesActivity'); + Route::get('/province_machine_types_activity', 'provinceMachineTypesActivity')->name('provinceMachineTypesActivity'); }); }); From 5d2a6d045b9964ea59c78e99db0959e196529e2b Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Wed, 10 Jun 2026 14:37:36 +0330 Subject: [PATCH 24/40] fix bugs --- app/Enums/CmmsMachineStatus.php | 2 +- app/Enums/MissionViolationStatus.php | 4 + .../Mission/RequestPortalController.php | 6 +- .../Mission/ViolationManagementController.php | 7 +- .../RequestPortal/ContinueMissionRequest.php | 5 +- .../V3/Mission/RequestPortal/StoreRequest.php | 11 ++- .../Mission/RequestPortal/UpdateRequest.php | 11 ++- .../V3/Mission/Violation/NoProcessRequest.php | 6 +- .../V3/Mission/Violation/StoreRequest.php | 3 +- .../V3/Mission/Violation/UpdateRequest.php | 3 +- app/Models/Mission.php | 7 -- app/Services/PolylineEncoder.php | 88 +++++++++++++++++++ 12 files changed, 122 insertions(+), 31 deletions(-) create mode 100644 app/Services/PolylineEncoder.php diff --git a/app/Enums/CmmsMachineStatus.php b/app/Enums/CmmsMachineStatus.php index f8539109..e9f75a14 100644 --- a/app/Enums/CmmsMachineStatus.php +++ b/app/Enums/CmmsMachineStatus.php @@ -18,7 +18,7 @@ enum CmmsMachineStatus: int self::AMADE => 'آماده', self::RESERVE => 'رزرو', self::DAR_MAMORIAT => 'در ماموریت', - self::KHAREGE_AZ_RADE => 'خارج از محدوده', + self::KHAREGE_AZ_RADE => 'خارج از رده', self::DAR_TAMIR => 'در تعمیر', self::FOROKHTEH_SHODE => ' فروخته شده', self::NIZE_BE_TAMIR => 'نیاز به تعمیر', diff --git a/app/Enums/MissionViolationStatus.php b/app/Enums/MissionViolationStatus.php index 68c75118..741af85f 100644 --- a/app/Enums/MissionViolationStatus.php +++ b/app/Enums/MissionViolationStatus.php @@ -2,16 +2,20 @@ namespace App\Enums; +use function Symfony\Component\String\s; + enum MissionViolationStatus: int { case BEDON_EGHDAM = 0; case EGHDAM_SHODE = 1; + case SABT_SHODE = 2; public function label(): string { return match ($this) { self::BEDON_EGHDAM => "بدون اقدام", self::EGHDAM_SHODE => "اقدام شده", + self::SABT_SHODE => "ثبت شده توسط حراست" }; } } \ No newline at end of file diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index 27a80276..3881a3cc 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -66,7 +66,7 @@ class RequestPortalController extends Controller 'request_date' => now(), 'description' => $request->description, 'end_point' => $request->end_point, - 'area' => json_encode($request->area), + 'area' => $request->area, 'category_id' => $request->category_id, 'category_name' => MissionCategory::name($request->category_id), 'explanation' => $request->explanation, @@ -136,7 +136,7 @@ class RequestPortalController extends Controller 'request_date' => now(), 'description' => $request->description, 'end_point' => $request->end_point, - 'area' => json_encode($request->area), + 'area' => $request->area, 'category_id' => $request->category_id, 'category_name' => MissionCategory::name($request->category_id), 'explanation' => $request->explanation, @@ -174,7 +174,7 @@ class RequestPortalController extends Controller 'end_date' => $request->end_date, 'description' => $request->description, 'end_point' => $request->end_point, - 'area' => json_encode($request->area), + 'area' => $request->area, 'category_id' => $request->category_id, 'category_name' => MissionCategory::name($request->category_id), 'explanation' => $request->explanation, diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php index af018f7f..5617b251 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php @@ -61,6 +61,7 @@ class ViolationManagementController extends Controller 'edare_shahri_name' => $user->edarate_shahri_name ?? null, 'zone' => $zone, 'zone_fa' => MissionZones::name($zone), + 'area' => $request->area, 'type' => $type, 'type_fa' => MissionTypes::name($type), 'start_date' => $request->start_date, @@ -103,7 +104,7 @@ class ViolationManagementController extends Controller 'machine_id'=> CMMSMachine::query()->where('machine_code', '=', $request->machine_code)->value('id'), 'machine_code'=> $request->machine_code, 'type'=> MissionViolationType::KHOROJ_BEDONE_MOGAVEZ->value, - 'status' => MissionViolationStatus::BEDON_EGHDAM->value, + 'status' => MissionViolationStatus::SABT_SHODE->value, 'request_date' => now(), 'km' => $request->km, 'gps' => 0, @@ -111,6 +112,9 @@ class ViolationManagementController extends Controller 'province_name' => $user->province_fa, 'city_id' => $user->city_id, 'city_name' => $user->city_fa, + 'station_id' => $user->station_id, + 'station_name' => RahdariPoint::query()->find($user->station_id)->name, + 'exit_time' => $request->exit_time, ]); return $this->successResponse(); @@ -125,7 +129,6 @@ class ViolationManagementController extends Controller { $violation->update([ 'enter_time' => $request->enter_time, - 'exit_time' => $request->exit_time, ]); return $this->successResponse(); diff --git a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php index bff88565..c76d5282 100644 --- a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php +++ b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php @@ -35,12 +35,9 @@ class ContinueMissionRequest extends FormRequest 'end_date' => 'required|date', 'description' => 'string', 'end_point' => 'required|string', - 'area' => 'required|array', - 'area.type' => 'required|string', - 'area.coordinates' => 'required|array', + 'area' => 'required|string', 'explanation' => 'required|string', 'category_id' => 'required|in:1,2,3', - 'road_observed_id' => 'required_if:category_id,3|exists:road_observeds,id', ]; } diff --git a/app/Http/Requests/V3/Mission/RequestPortal/StoreRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/StoreRequest.php index c9233d40..0baa1614 100644 --- a/app/Http/Requests/V3/Mission/RequestPortal/StoreRequest.php +++ b/app/Http/Requests/V3/Mission/RequestPortal/StoreRequest.php @@ -34,12 +34,9 @@ class StoreRequest extends FormRequest 'end_date' => 'required|date', 'description' => 'string', 'end_point' => 'required|string', - 'area' => 'required|array', - 'area.type' => 'required|string', - 'area.coordinates' => 'required|array', + 'area' => 'required|string', 'explanation' => 'required|string', 'category_id' => 'required|in:1,2,3', - 'road_observed_id' => 'required_if:category_id,3|exists:road_observeds,id', ]; } @@ -58,6 +55,12 @@ class StoreRequest extends FormRequest ); } } + if (strtotime($this->end_date) < strtotime($this->start_date)) { + $validator->errors()->add( + 'time', + 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' + ); + } }, ]; } diff --git a/app/Http/Requests/V3/Mission/RequestPortal/UpdateRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/UpdateRequest.php index fb80a7f6..aebee794 100644 --- a/app/Http/Requests/V3/Mission/RequestPortal/UpdateRequest.php +++ b/app/Http/Requests/V3/Mission/RequestPortal/UpdateRequest.php @@ -35,12 +35,9 @@ class UpdateRequest extends FormRequest 'end_date' => 'required|date', 'description' => 'string', 'end_point' => 'required|string', - 'area' => 'required|array', - 'area.type' => 'required|string', - 'area.coordinates' => 'required|array', + 'area' => 'required|string', 'explanation' => 'required|string', 'category_id' => 'required|in:1,2,3', - 'road_observed_id' => 'required_if:category_id,3|exists:road_observeds,id', ]; } @@ -59,6 +56,12 @@ class UpdateRequest extends FormRequest ); } } + if (strtotime($this->end_date) < strtotime($this->start_date)) { + $validator->errors()->add( + 'time', + 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' + ); + } }, ]; } diff --git a/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php b/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php index 6f223b4c..7026fa5d 100644 --- a/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php @@ -2,8 +2,10 @@ namespace App\Http\Requests\V3\Mission\Violation; +use Carbon\Carbon; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Validation\Validator; class NoProcessRequest extends FormRequest { @@ -30,9 +32,7 @@ class NoProcessRequest extends FormRequest 'start_date' => 'required|date', 'end_date' => 'required|date|after:start_date|before:now', 'end_point' => 'required|string', - 'area' => 'array', - 'area.type' => 'string', - 'area.coordinates' => 'array', + 'area' => 'required|string', 'category_id' => 'required|in:1,2,3', 'explanation' => 'required|string', ]; diff --git a/app/Http/Requests/V3/Mission/Violation/StoreRequest.php b/app/Http/Requests/V3/Mission/Violation/StoreRequest.php index 07e5b36f..16ea27bc 100644 --- a/app/Http/Requests/V3/Mission/Violation/StoreRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/StoreRequest.php @@ -25,7 +25,8 @@ class StoreRequest extends FormRequest public function rules(): array { return [ - 'machine_code' => 'required', + 'exit_time' => 'required|date', + 'machine_code' => 'required', 'km'=> 'string', ]; } diff --git a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php index d2f8e22a..3b5ad00a 100644 --- a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php @@ -26,8 +26,7 @@ class UpdateRequest extends FormRequest public function rules(): array { return [ - 'exit_time' => 'date', - 'enter_time' => 'date', + 'enter_time' => 'required|date', ]; } } diff --git a/app/Models/Mission.php b/app/Models/Mission.php index 899da5ea..a277162a 100644 --- a/app/Models/Mission.php +++ b/app/Models/Mission.php @@ -28,13 +28,6 @@ class Mission extends Model ); } - protected function area(): Attribute - { - return Attribute::make( - get: fn($value) => json_decode($value, true) - ); - } - public function histories(): HasMany { return $this->hasMany(MissionHistory::class); diff --git a/app/Services/PolylineEncoder.php b/app/Services/PolylineEncoder.php new file mode 100644 index 00000000..3f4dda19 --- /dev/null +++ b/app/Services/PolylineEncoder.php @@ -0,0 +1,88 @@ +encodeValue((int)round($lat * $factor) - $prevLat); + $output .= $this->encodeValue((int)round($lng * $factor) - $prevLng); + + $prevLat = (int)round($lat * $factor); + $prevLng = (int)round($lng * $factor); + } + + return $output; + } + + /** + * Encodes a single integer value using Google's polyline encoding algorithm. + * + * Steps: + * - Left shift the value + * - Invert bits if negative + * - Split into 5-bit chunks + * - Convert to ASCII characters + * + * @param int $value Signed integer delta to encode + * + * @return string Encoded character sequence + */ + public function encodeValue(int $value): string + { + $value = $value < 0 ? ~($value << 1) : ($value << 1); + $result = ''; + + while ($value >= 0x20) { + $result .= chr((0x20 | ($value & 0x1f)) + 63); + $value >>= 5; + } + + return $result . chr($value + 63); + } +} From 6db1933046b76ee5b7376e73d49ffbc08c269610 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Wed, 10 Jun 2026 14:56:22 +0330 Subject: [PATCH 25/40] add time for type 2 --- .../Mission/ViolationManagementController.php | 17 ++++++----- .../V3/Mission/Violation/NoProcessRequest.php | 10 ------- .../V3/Mission/Violation/StoreRequest.php | 2 +- .../V3/Mission/Violation/UpdateRequest.php | 2 +- ...add_column_to_mission_violations_table.php | 29 +++++++++++++++++++ 5 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php index 5617b251..3c9e731d 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php @@ -43,8 +43,8 @@ class ViolationManagementController extends Controller { DB::transaction(function () use ($request, $violation) { - $start = Carbon::parse($request->start_date); - $end = Carbon::parse($request->end_date); + $start = Carbon::parse($violation->exit_station); + $end = Carbon::parse($violation->enter_station); $type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value; $user = auth()->user(); $zone = $request->zone; @@ -64,13 +64,13 @@ class ViolationManagementController extends Controller 'area' => $request->area, 'type' => $type, 'type_fa' => MissionTypes::name($type), - 'start_date' => $request->start_date, - 'end_date' => $request->end_date, + 'start_date' => $violation->exit_station, + 'end_date' => $violation->enter_station, 'end_point' => $request->end_point, 'category_id' => $request->category_id, 'category_name' => MissionCategory::name($request->category_id), - 'start_time' => $request->start_date, - 'finish_time' => $request->end_date, + 'start_time' => $violation->exit_station, + 'finish_time' => $violation->enter_station, 'state_id' => MissionStates::END_MISSION->value, 'state_name' => MissionStates::END_MISSION->label(), 'explanation' => $request->explanation, @@ -114,7 +114,7 @@ class ViolationManagementController extends Controller 'city_name' => $user->city_fa, 'station_id' => $user->station_id, 'station_name' => RahdariPoint::query()->find($user->station_id)->name, - 'exit_time' => $request->exit_time, + 'exit_station' => $request->exit_station, ]); return $this->successResponse(); @@ -128,7 +128,8 @@ class ViolationManagementController extends Controller public function update(UpdateRequest $request, MissionViolation $violation): JsonResponse { $violation->update([ - 'enter_time' => $request->enter_time, + 'enter_station' => $request->enter_station, + 'status' => MissionViolationStatus::BEDON_EGHDAM->value, ]); return $this->successResponse(); diff --git a/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php b/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php index 7026fa5d..81939652 100644 --- a/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php @@ -29,20 +29,10 @@ class NoProcessRequest extends FormRequest 'rahdaran.*' => 'exists:rahdaran,id', 'driver' => 'required|integer|exists:rahdaran,id', 'zone' => 'required|in:1,2,3', - 'start_date' => 'required|date', - 'end_date' => 'required|date|after:start_date|before:now', 'end_point' => 'required|string', 'area' => 'required|string', 'category_id' => 'required|in:1,2,3', 'explanation' => 'required|string', ]; } - - public function messages(): array - { - return [ - 'end_date.before' => 'تاریخ پایان باید قبل از زمان فعلی باشد.', - 'end_date.after' => 'تاریخ پایان نباید قبل از تاریخ شروع باشد.', - ]; - } } diff --git a/app/Http/Requests/V3/Mission/Violation/StoreRequest.php b/app/Http/Requests/V3/Mission/Violation/StoreRequest.php index 16ea27bc..2994a64f 100644 --- a/app/Http/Requests/V3/Mission/Violation/StoreRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/StoreRequest.php @@ -25,7 +25,7 @@ class StoreRequest extends FormRequest public function rules(): array { return [ - 'exit_time' => 'required|date', + 'exit_station' => 'required|date', 'machine_code' => 'required', 'km'=> 'string', ]; diff --git a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php index 3b5ad00a..0948924e 100644 --- a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php @@ -26,7 +26,7 @@ class UpdateRequest extends FormRequest public function rules(): array { return [ - 'enter_time' => 'required|date', + 'enter_station' => 'required|date', ]; } } diff --git a/database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php b/database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php new file mode 100644 index 00000000..b6c28ccd --- /dev/null +++ b/database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php @@ -0,0 +1,29 @@ +dateTime('exit_station')->nullable(); + $table->dateTime('enter_station')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('mission_violations', function (Blueprint $table) { + $table->dropColumn(['exit_station', 'enter_station']); + }); + } +}; From 55b40eb0ccfcd967403993614049babb2ebd4895 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Wed, 10 Jun 2026 15:17:54 +0330 Subject: [PATCH 26/40] replace encoded_route --- .../Mission/RequestPortalController.php | 6 ++-- .../Mission/ViolationManagementController.php | 3 +- .../RequestPortal/ContinueMissionRequest.php | 2 +- .../V3/Mission/RequestPortal/StoreRequest.php | 2 +- .../Mission/RequestPortal/UpdateRequest.php | 2 +- .../V3/Mission/Violation/NoProcessRequest.php | 2 +- .../Cartables/Mission/ControlUnitService.php | 2 +- .../Mission/RequestPortalService.php | 2 +- .../Mission/TransportationUnitService.php | 2 +- ...10_150953_add_column_to_missions_table.php | 28 +++++++++++++++++++ 10 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 database/migrations/2026_06_10_150953_add_column_to_missions_table.php diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index 3881a3cc..e1a81498 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -66,7 +66,7 @@ class RequestPortalController extends Controller 'request_date' => now(), 'description' => $request->description, 'end_point' => $request->end_point, - 'area' => $request->area, + 'encoded_route' => $request->encoded_route, 'category_id' => $request->category_id, 'category_name' => MissionCategory::name($request->category_id), 'explanation' => $request->explanation, @@ -136,7 +136,7 @@ class RequestPortalController extends Controller 'request_date' => now(), 'description' => $request->description, 'end_point' => $request->end_point, - 'area' => $request->area, + 'encoded_route' => $request->encoded_route, 'category_id' => $request->category_id, 'category_name' => MissionCategory::name($request->category_id), 'explanation' => $request->explanation, @@ -174,7 +174,7 @@ class RequestPortalController extends Controller 'end_date' => $request->end_date, 'description' => $request->description, 'end_point' => $request->end_point, - 'area' => $request->area, + 'encoded_route' => $request->encoded_route, 'category_id' => $request->category_id, 'category_name' => MissionCategory::name($request->category_id), 'explanation' => $request->explanation, diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php index 3c9e731d..b3fa6a26 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php @@ -61,7 +61,7 @@ class ViolationManagementController extends Controller 'edare_shahri_name' => $user->edarate_shahri_name ?? null, 'zone' => $zone, 'zone_fa' => MissionZones::name($zone), - 'area' => $request->area, + 'encoded_route' => $request->encoded_route, 'type' => $type, 'type_fa' => MissionTypes::name($type), 'start_date' => $violation->exit_station, @@ -71,6 +71,7 @@ class ViolationManagementController extends Controller 'category_name' => MissionCategory::name($request->category_id), 'start_time' => $violation->exit_station, 'finish_time' => $violation->enter_station, + 'mission_duration' => strtotime($violation->enter_station) - strtotime($violation->exit_station), 'state_id' => MissionStates::END_MISSION->value, 'state_name' => MissionStates::END_MISSION->label(), 'explanation' => $request->explanation, diff --git a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php index c76d5282..1fe7f381 100644 --- a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php +++ b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php @@ -35,7 +35,7 @@ class ContinueMissionRequest extends FormRequest 'end_date' => 'required|date', 'description' => 'string', 'end_point' => 'required|string', - 'area' => 'required|string', + 'encoded_route' => 'required|string', 'explanation' => 'required|string', 'category_id' => 'required|in:1,2,3', ]; diff --git a/app/Http/Requests/V3/Mission/RequestPortal/StoreRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/StoreRequest.php index 0baa1614..0e787c12 100644 --- a/app/Http/Requests/V3/Mission/RequestPortal/StoreRequest.php +++ b/app/Http/Requests/V3/Mission/RequestPortal/StoreRequest.php @@ -34,7 +34,7 @@ class StoreRequest extends FormRequest 'end_date' => 'required|date', 'description' => 'string', 'end_point' => 'required|string', - 'area' => 'required|string', + 'encoded_route' => 'required|string', 'explanation' => 'required|string', 'category_id' => 'required|in:1,2,3', ]; diff --git a/app/Http/Requests/V3/Mission/RequestPortal/UpdateRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/UpdateRequest.php index aebee794..ce8858fa 100644 --- a/app/Http/Requests/V3/Mission/RequestPortal/UpdateRequest.php +++ b/app/Http/Requests/V3/Mission/RequestPortal/UpdateRequest.php @@ -35,7 +35,7 @@ class UpdateRequest extends FormRequest 'end_date' => 'required|date', 'description' => 'string', 'end_point' => 'required|string', - 'area' => 'required|string', + 'encoded_route' => 'required|string', 'explanation' => 'required|string', 'category_id' => 'required|in:1,2,3', ]; diff --git a/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php b/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php index 81939652..49ad280f 100644 --- a/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php @@ -30,7 +30,7 @@ class NoProcessRequest extends FormRequest 'driver' => 'required|integer|exists:rahdaran,id', 'zone' => 'required|in:1,2,3', 'end_point' => 'required|string', - 'area' => 'required|string', + 'encoded_route' => 'required|string', 'category_id' => 'required|in:1,2,3', 'explanation' => 'required|string', ]; diff --git a/app/Services/Cartables/Mission/ControlUnitService.php b/app/Services/Cartables/Mission/ControlUnitService.php index 6b234a3c..c27d60e0 100644 --- a/app/Services/Cartables/Mission/ControlUnitService.php +++ b/app/Services/Cartables/Mission/ControlUnitService.php @@ -37,7 +37,7 @@ class ControlUnitService allowedSelects: [ 'id', 'user_id', 'username', 'state_name', 'province_name', 'edare_shahri_name', 'description', 'requested_machines', 'type', 'type_fa', 'start_date', 'state_id', - 'end_date', 'request_date', 'end_point', 'area', 'zone', 'zone_fa', 'start_time', 'finish_time', + 'end_date', 'request_date', 'end_point', 'encoded_route', 'zone', 'zone_fa', 'start_time', 'finish_time', 'code', 'category_id', 'category_name', 'explanation', 'city_id', 'city_name', 'province_id', 'station_name', ] ); diff --git a/app/Services/Cartables/Mission/RequestPortalService.php b/app/Services/Cartables/Mission/RequestPortalService.php index 5be57872..58d197b9 100644 --- a/app/Services/Cartables/Mission/RequestPortalService.php +++ b/app/Services/Cartables/Mission/RequestPortalService.php @@ -32,7 +32,7 @@ class RequestPortalService allowedSelects: [ 'id', 'user_id', 'username', 'state_name', 'province_name', 'edare_shahri_name', 'description', 'requested_machines', 'type', 'type_fa', 'start_date', 'state_id', - 'end_date', 'request_date', 'end_point', 'area', 'zone', 'zone_fa', 'start_time', 'finish_time', + 'end_date', 'request_date', 'end_point', 'encoded_route', 'zone', 'zone_fa', 'start_time', 'finish_time', 'code', 'category_id', 'category_name', 'explanation', 'city_id', 'city_name', 'province_id', 'station_name', ] ); diff --git a/app/Services/Cartables/Mission/TransportationUnitService.php b/app/Services/Cartables/Mission/TransportationUnitService.php index d4e3be54..f8fc4ff5 100644 --- a/app/Services/Cartables/Mission/TransportationUnitService.php +++ b/app/Services/Cartables/Mission/TransportationUnitService.php @@ -32,7 +32,7 @@ class TransportationUnitService allowedSelects: [ 'id', 'user_id', 'username', 'state_name', 'province_name', 'edare_shahri_name', 'description', 'requested_machines', 'type', 'type_fa', 'start_date', 'state_id', - 'end_date', 'request_date', 'end_point', 'area', 'zone', 'zone_fa', 'start_time', 'finish_time', + 'end_date', 'request_date', 'end_point', 'encoded_route', 'zone', 'zone_fa', 'start_time', 'finish_time', 'code', 'category_id', 'category_name', 'explanation', 'km', 'city_id', 'city_name', 'province_id', 'station_name', ] ); diff --git a/database/migrations/2026_06_10_150953_add_column_to_missions_table.php b/database/migrations/2026_06_10_150953_add_column_to_missions_table.php new file mode 100644 index 00000000..c8ae17ee --- /dev/null +++ b/database/migrations/2026_06_10_150953_add_column_to_missions_table.php @@ -0,0 +1,28 @@ +longText('encoded_route')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('missions', function (Blueprint $table) { + $table->dropColumn('encoded_route'); + }); + } +}; From 72462e8016aedfb17d7d52a08987216fc6f9a957 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Wed, 10 Jun 2026 15:24:50 +0330 Subject: [PATCH 27/40] create list for province and city --- .../Controllers/V3/CMMSMachinesController.php | 3 ++- app/Http/Controllers/V3/CityController.php | 19 +++++++++++++++ .../Report/ReportMachineController.php | 24 +++++++++++++++++++ .../Controllers/V3/ProvinceController.php | 19 +++++++++++++++ app/Models/City.php | 1 + app/Models/Province.php | 1 + .../Mission/Report/ReportMachineService.php | 10 ++++---- routes/v3.php | 18 +++++++++++++- 8 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 app/Http/Controllers/V3/CityController.php create mode 100644 app/Http/Controllers/V3/ProvinceController.php diff --git a/app/Http/Controllers/V3/CMMSMachinesController.php b/app/Http/Controllers/V3/CMMSMachinesController.php index 3fa35b93..a5e18a34 100644 --- a/app/Http/Controllers/V3/CMMSMachinesController.php +++ b/app/Http/Controllers/V3/CMMSMachinesController.php @@ -23,7 +23,8 @@ class CMMSMachinesController extends Controller $request, allowedFilters: ['*'], allowedSortings: ['*'], - allowedSelects: ['machine_code', 'id', 'plak_number', 'car_name', 'car_type', 'status'], + allowedSelects: ['machine_code', 'id', 'plak_number', 'car_name', 'car_type', 'status', + 'province_id', 'city_id', 'station_id', 'status','driver_name'], )); } diff --git a/app/Http/Controllers/V3/CityController.php b/app/Http/Controllers/V3/CityController.php new file mode 100644 index 00000000..50d0d48f --- /dev/null +++ b/app/Http/Controllers/V3/CityController.php @@ -0,0 +1,19 @@ +successResponse(City::query()->where('cities.province_id', $request->query('province_id'))->get(['id', 'name_fa'])); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index 5f5700a3..94c99b47 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -72,6 +72,18 @@ class ReportMachineController extends Controller ]); } + /** + * @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 machineReport($data), $name); + } + public function provinceMachineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse { return $this->successResponse([ @@ -85,4 +97,16 @@ class ReportMachineController extends Controller // ->get(['id', 'name_fa']) ]); } + + /** + * @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 machineReport($data), $name); + } } diff --git a/app/Http/Controllers/V3/ProvinceController.php b/app/Http/Controllers/V3/ProvinceController.php new file mode 100644 index 00000000..e295370c --- /dev/null +++ b/app/Http/Controllers/V3/ProvinceController.php @@ -0,0 +1,19 @@ +successResponse(Province::all(['id', 'name_fa'])); + } +} \ No newline at end of file diff --git a/app/Models/City.php b/app/Models/City.php index 614cc699..4a312930 100644 --- a/app/Models/City.php +++ b/app/Models/City.php @@ -14,6 +14,7 @@ class City extends Model * * @var array */ + protected $guarded = ['id']; protected $hidden = [ 'name_en', 'feature_id', diff --git a/app/Models/Province.php b/app/Models/Province.php index 0c803401..3254540e 100644 --- a/app/Models/Province.php +++ b/app/Models/Province.php @@ -13,6 +13,7 @@ class Province extends Model * * @var array */ + protected $guarded = ['id']; protected $hidden = [ 'feature_id', //'center_lat', diff --git a/app/Services/Cartables/Mission/Report/ReportMachineService.php b/app/Services/Cartables/Mission/Report/ReportMachineService.php index 3fba507b..9a454fdb 100644 --- a/app/Services/Cartables/Mission/Report/ReportMachineService.php +++ b/app/Services/Cartables/Mission/Report/ReportMachineService.php @@ -20,7 +20,7 @@ class ReportMachineService m.machine_code, cm.car_name, COUNT(*) AS missions, - SUM(m.end_km - m.km) AS func, + 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 @@ -59,7 +59,7 @@ class ReportMachineService $sql = "SELECT cm.car_type, COUNT(*) AS missions, - SUM(m.end_km - m.km) AS func, + 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 @@ -80,7 +80,7 @@ class ReportMachineService $sql = "SELECT cm.car_type, COUNT(*) AS missions, - SUM(m.end_km - m.km) AS func, + 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 @@ -102,7 +102,7 @@ class ReportMachineService m.driver_id, m.driver_name, COUNT(*) AS missions, - SUM(m.end_km - m.km) AS func, + 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;"; @@ -123,7 +123,7 @@ class ReportMachineService m.driver_id, m.driver_name, COUNT(*) AS missions, - SUM(m.end_km - m.km) AS func, + 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;"; diff --git a/routes/v3.php b/routes/v3.php index 00410870..7873d96a 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -1,6 +1,7 @@ build(\App\Models\User::all(), ['id' => 'کد یکتا', 'username' => 'نام کاربری'])->download(); -}); \ No newline at end of file +}); + +Route::prefix('provinces') + ->name('provinces.') + ->controller(ProvinceController::class) + ->group(function () { + Route::get('/list', 'list')->name('list'); + }); + +Route::prefix('cities') + ->name('cities.') + ->controller(CityController::class) + ->group(function () { + Route::get('/list', 'list')->name('list'); + }); \ No newline at end of file From a8c71de069ce3d4f0068bb45a6a915fe04923fd2 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sat, 13 Jun 2026 14:09:17 +0330 Subject: [PATCH 28/40] add extra reports --- .../Commands/EncodePolyLineCommand.php | 31 +++++++ .../Mission/ControlUnitController.php | 24 ++++-- .../Report/ReportMachineController.php | 16 ++++ .../Mission/RequestPortalController.php | 86 ++++++++++++++++++- .../Mission/TransportationUnitController.php | 8 ++ .../Mission/ViolationManagementController.php | 61 ------------- .../ClarifyUnauthorizedExitRequest.php | 38 ++++++++ .../TransportaionUnit/AllocateRequest.php | 4 +- .../TransportaionUnit/DeallocateRequest.php | 4 +- .../V3/Mission/Violation/NoProcessRequest.php | 2 +- .../Mission/DailyMoveMachineService.php | 4 +- ...025_05_17_103927_create_missions_table.php | 2 +- ...6_10_093806_add_area_to_missions_table.php | 2 +- ...add_column_to_mission_violations_table.php | 2 + routes/v3.php | 11 +-- 15 files changed, 210 insertions(+), 85 deletions(-) create mode 100644 app/Console/Commands/EncodePolyLineCommand.php create mode 100644 app/Http/Requests/V3/Mission/RequestPortal/ClarifyUnauthorizedExitRequest.php diff --git a/app/Console/Commands/EncodePolyLineCommand.php b/app/Console/Commands/EncodePolyLineCommand.php new file mode 100644 index 00000000..7eb615f1 --- /dev/null +++ b/app/Console/Commands/EncodePolyLineCommand.php @@ -0,0 +1,31 @@ + $mission->state_name, // ]); + $mission->machine()->update([ + 'status' => CmmsMachineStatus::DAR_MAMORIAT->value + ]); + $mission->update([ 'state_id' => MissionStates::START_MISSION->value, 'state_name' => MissionStates::START_MISSION->label(), @@ -62,25 +67,26 @@ class ControlUnitController extends Controller // 'previous_state_name' => $mission->state_name, // ]); - $mission->update([ - 'state_id' => MissionStates::END_MISSION->value, - 'state_name' => MissionStates::END_MISSION->label(), - 'finish_time' => $request->time, - 'mission_duration' => strtotime($request->time) - strtotime($mission->start_time), - 'end_km' => $request->end_km, + $mission->machine()->update([ + 'status' => CmmsMachineStatus::AMADE->value ]); // $getErrorRateService->setInputParameters($mission); // $responseData = $getErrorRateService->run(); -// -// $mission->update([ + + $mission->update([ // 'in_area_duration' => $responseData['timeInAreaSeconds'], // 'first_enter' => $responseData['firstEnter'], // 'last_exit' => $responseData['lastExit'], // 'point_number_sent' => $responseData['noOfPointsInMission'], // 'fms_result_code' => $responseData['resultCode'], // 'fms_result_message' => FMSResultCode::name($responseData['resultCode']), -// ]); + 'state_id' => MissionStates::END_MISSION->value, + 'state_name' => MissionStates::END_MISSION->label(), + 'finish_time' => $request->time, + 'mission_duration' => strtotime($request->time) - strtotime($mission->start_time), + 'end_km' => $request->end_km, + ]); }); // if ($mission->category_id == 2) { diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index 5f5700a3..9ab78e69 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -3,9 +3,11 @@ namespace App\Http\Controllers\V3\Dashboard\Mission\Report; use App\Exports\V3\Mission\Report\Machine\machineReport; +use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; use App\Models\City; +use App\Models\Mission; use App\Models\Province; use App\Services\Cartables\Mission\Report\ReportMachineService; use Illuminate\Http\JsonResponse; @@ -85,4 +87,18 @@ class ReportMachineController extends Controller // ->get(['id', 'name_fa']) ]); } + + public function machineDetailsReport(Request $request) + { + return DataTableFacade::run( + Mission::query()->where('machine_id', '=', $request->query('machine_id')), + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + allowedSelects: [ + 'id', 'province_id', 'province_name', 'city_id', 'city_name', + 'end_km', 'km', 'driver_name', 'state_name', + ] + ); + } } diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index e1a81498..ab69b445 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -6,10 +6,13 @@ use App\Enums\FMSResultCode; use App\Enums\MissionCategory; use App\Enums\MissionStates; use App\Enums\MissionTypes; +use App\Enums\MissionViolationStatus; use App\Enums\MissionZones; +use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; use App\Http\Controllers\V3\Dashboard\RoadPatrol\OperatorController; use App\Http\Requests\V3\Mission\RequestPortal\ChangeStateRequest; +use App\Http\Requests\V3\Mission\RequestPortal\ClarifyUnauthorizedExitRequest; use App\Http\Requests\V3\Mission\RequestPortal\ContinueMissionRequest; use App\Http\Requests\V3\Mission\RequestPortal\NoProcessRequest; use App\Http\Requests\V3\Mission\RequestPortal\StoreRequest; @@ -17,6 +20,7 @@ use App\Http\Requests\V3\Mission\RequestPortal\UpdateRequest; use App\Http\Traits\ApiResponse; use App\Models\CMMSMachine; use App\Models\Mission; +use App\Models\MissionViolation; use App\Models\Rahdaran; use App\Models\RahdariPoint; use App\Models\RoadObserved; @@ -37,6 +41,21 @@ class RequestPortalController extends Controller return response()->json($requestPortalService->datatable($request)); } + public function violations(Request $request): JsonResponse + { + $query = MissionViolation::query()->where([ + ['status', '=', MissionViolationStatus::BEDON_EGHDAM->value], + ['station_id', '=', auth()->user()->station_id] + ]); + + return DataTableFacade::run( + $query, + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + ); + } + /** * @throws Throwable */ @@ -203,10 +222,73 @@ class RequestPortalController extends Controller public function changeState(ChangeStateRequest $request, Mission $mission): JsonResponse { $mission->update([ - 'state' => $request->state_id, - 'state_name' => MissionStates::name($request->status_id), + 'state_id' => $request->state_id, + 'state_name' => MissionStates::name($request->state_id), ]); return $this->successResponse($mission); } + + /** + * @throws Throwable + */ + public function clarifyUnauthorizedExit(ClarifyUnauthorizedExitRequest $request, MissionViolation $violation): JsonResponse + { + DB::transaction(function () use ($request, $violation) { + + $start = Carbon::parse($violation->exit_station); + $end = Carbon::parse($violation->enter_station); + $type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value; + $user = auth()->user(); + $zone = $request->zone; + $machine = CMMSMachine::query()->where('machine_code', '=', $violation->machine_code)->first(['id', 'machine_code']); + + $mission = Mission::query()->create([ + 'user_id' => $user->id, + 'username' => $user->username, + 'province_id' => $user->province_id, + 'province_name' => $user->province_fa, + 'city_id' => $user->city_id ?? null, + 'city_name' => $user->city_fa ?? null, + 'edare_shahri_id' => $user->edarate_shahri_id ?? null, + 'edare_shahri_name' => $user->edarate_shahri_name ?? null, + 'zone' => $zone, + 'zone_fa' => MissionZones::name($zone), + 'encoded_route' => $request->encoded_route, + 'type' => $type, + 'type_fa' => MissionTypes::name($type), + 'start_date' => $violation->exit_station, + 'end_date' => $violation->enter_station, + 'end_point' => $request->end_point, + 'category_id' => $request->category_id, + 'category_name' => MissionCategory::name($request->category_id), + 'start_time' => $violation->exit_station, + 'finish_time' => $violation->enter_station, + 'mission_duration' => strtotime($violation->enter_station) - strtotime($violation->exit_station), + 'state_id' => MissionStates::END_MISSION->value, + 'state_name' => MissionStates::END_MISSION->label(), + 'explanation' => $request->explanation, + 'request_date' => now(), + 'machine_id' => $machine->id, + 'machine_code' => $machine->machine_code, + 'requested_machines' => $machine->car_type, + 'station_id' => $user->station_id, + 'station_name' => RahdariPoint::query()->find($user->station_id)->name, + 'km' => $violation->km ?? null, + 'driver_id' => $request->driver, + 'driver_name' => Rahdaran::query()->find($request->driver)->name, + ]); + + $mission->rahdaran()->sync($request->rahdaran); + + $violation->update(['status' => 1]); + +// if ($mission->category_id == 2) { +// $rpc = new OperatorController; +// $rpc->store($mission); +// } + }); + + return $this->successResponse(); + } } diff --git a/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php b/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php index 257e033a..ae80dad8 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/TransportationUnitController.php @@ -50,6 +50,10 @@ class TransportationUnitController extends Controller 'driver_id' => $request->driver_id, 'driver_name' => Rahdaran::query()->find($request->driver)->name, ]); + + $machine->update([ + 'status' => CmmsMachineStatus::RESERVE->value + ]); }); return $this->successResponse(); @@ -71,6 +75,10 @@ class TransportationUnitController extends Controller $state = MissionStates::REJECT_BY_TRANSPORTATION->value; + $mission->machine()->update([ + 'status' => CmmsMachineStatus::AMADE->value + ]); + $mission->update([ 'state_id' => $state, 'state_name' => MissionStates::name($state), diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php index b3fa6a26..5d1728b9 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php @@ -36,67 +36,6 @@ class ViolationManagementController extends Controller return response()->json($data); } - /** - * @throws Throwable - */ - public function noProcess(NoProcessRequest $request, MissionViolation $violation): JsonResponse - { - DB::transaction(function () use ($request, $violation) { - - $start = Carbon::parse($violation->exit_station); - $end = Carbon::parse($violation->enter_station); - $type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value; - $user = auth()->user(); - $zone = $request->zone; - $machine = CMMSMachine::query()->where('machine_code', '=', $violation->machine_code)->first(['id', 'machine_code']); - - $mission = Mission::query()->create([ - 'user_id' => $user->id, - 'username' => $user->username, - 'province_id' => $user->province_id, - 'province_name' => $user->province_fa, - 'city_id' => $user->city_id ?? null, - 'city_name' => $user->city_fa ?? null, - 'edare_shahri_id' => $user->edarate_shahri_id ?? null, - 'edare_shahri_name' => $user->edarate_shahri_name ?? null, - 'zone' => $zone, - 'zone_fa' => MissionZones::name($zone), - 'encoded_route' => $request->encoded_route, - 'type' => $type, - 'type_fa' => MissionTypes::name($type), - 'start_date' => $violation->exit_station, - 'end_date' => $violation->enter_station, - 'end_point' => $request->end_point, - 'category_id' => $request->category_id, - 'category_name' => MissionCategory::name($request->category_id), - 'start_time' => $violation->exit_station, - 'finish_time' => $violation->enter_station, - 'mission_duration' => strtotime($violation->enter_station) - strtotime($violation->exit_station), - 'state_id' => MissionStates::END_MISSION->value, - 'state_name' => MissionStates::END_MISSION->label(), - 'explanation' => $request->explanation, - 'request_date' => now(), - 'machine_id' => $machine->id, - 'machine_code' => $machine->machine_code, - 'station_id' => $user->station_id, - 'station_name' => RahdariPoint::query()->find( $user->station_id)->name, - 'km' => $violation->km ?? null, - 'driver_id' => $request->driver, - 'driver_name' => Rahdaran::query()->find($request->driver)->name, - ]); - - $mission->rahdaran()->sync($request->rahdaran); - - $violation->update(['status' => 1]); - -// if ($mission->category_id == 2) { -// $rpc = new OperatorController; -// $rpc->store($mission); -// } - }); - - return $this->successResponse(); - } public function store(StoreRequest $request): JsonResponse { $user = auth()->user(); diff --git a/app/Http/Requests/V3/Mission/RequestPortal/ClarifyUnauthorizedExitRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/ClarifyUnauthorizedExitRequest.php new file mode 100644 index 00000000..a0129c2c --- /dev/null +++ b/app/Http/Requests/V3/Mission/RequestPortal/ClarifyUnauthorizedExitRequest.php @@ -0,0 +1,38 @@ +violation->status === 0 && $this->violation->type === 1; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + 'rahdaran' => 'array', + 'rahdaran.*' => 'exists:rahdaran,id', + 'driver' => 'required|integer|exists:rahdaran,id', + 'zone' => 'required|in:1,2,3', + 'end_point' => 'required|string', + 'encoded_route' => 'required|string', + 'category_id' => 'required|in:1,2,3', + 'explanation' => 'required|string', + ]; + } +} diff --git a/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php b/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php index ceb0bf22..af14fad9 100644 --- a/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php +++ b/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php @@ -15,8 +15,8 @@ class AllocateRequest extends FormRequest */ public function authorize(): bool { - return $this->mission->edare_shahri_id == auth()->user()->edarate_shahri_id && $this->mission->state_id == MissionStates::REQUEST_CREATED->value - || $this->user()?->username === 'witel'; + 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/Http/Requests/V3/Mission/TransportaionUnit/DeallocateRequest.php b/app/Http/Requests/V3/Mission/TransportaionUnit/DeallocateRequest.php index e0504aa2..c5d763d2 100644 --- a/app/Http/Requests/V3/Mission/TransportaionUnit/DeallocateRequest.php +++ b/app/Http/Requests/V3/Mission/TransportaionUnit/DeallocateRequest.php @@ -13,9 +13,9 @@ class DeallocateRequest extends FormRequest */ public function authorize(): bool { - return $this->mission->edare_shahri_id == auth()->user()->edarate_shahri_id && + return $this->mission->station_id == auth()->user()->station_id && in_array($this->mission->state_id, [MissionStates::REQUEST_CREATED->value, MissionStates::PENDING_CONFIRMATION->value]) - || $this->user()?->username === 'witel'; + || auth()->user()->username === 'witel'; } /** diff --git a/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php b/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php index 49ad280f..43ddd096 100644 --- a/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/NoProcessRequest.php @@ -30,7 +30,7 @@ class NoProcessRequest extends FormRequest 'driver' => 'required|integer|exists:rahdaran,id', 'zone' => 'required|in:1,2,3', 'end_point' => 'required|string', - 'encoded_route' => 'required|string', +// 'encoded_route' => 'required|string', 'category_id' => 'required|in:1,2,3', 'explanation' => 'required|string', ]; diff --git a/app/Services/Cartables/Mission/DailyMoveMachineService.php b/app/Services/Cartables/Mission/DailyMoveMachineService.php index 1dbefe1b..bc7dcb47 100644 --- a/app/Services/Cartables/Mission/DailyMoveMachineService.php +++ b/app/Services/Cartables/Mission/DailyMoveMachineService.php @@ -2,6 +2,7 @@ namespace App\Services\Cartables\Mission; +use App\Enums\MissionViolationStatus; use App\Facades\DataTable\DataTableFacade; use App\Models\MissionViolation; use Illuminate\Http\Request; @@ -13,7 +14,8 @@ class DailyMoveMachineService { $user = Auth::user(); - $query = MissionViolation::query()->with('machine:id,car_name'); + $query = MissionViolation::query()->with('machine:id,car_name') + ->where('mission_violations.status', '=', MissionViolationStatus::SABT_SHODE->value); if ($user->hasPermissionTo('manage-violation-station')) { $query->whereRelation('machine', 'station_id', '=', $user->station_id); diff --git a/database/migrations/2025_05_17_103927_create_missions_table.php b/database/migrations/2025_05_17_103927_create_missions_table.php index 25a60291..ab821ba9 100644 --- a/database/migrations/2025_05_17_103927_create_missions_table.php +++ b/database/migrations/2025_05_17_103927_create_missions_table.php @@ -24,7 +24,7 @@ return new class extends Migration $table->unsignedBigInteger('edare_shahri_id')->nullable(); $table->foreign('edare_shahri_id')->references('id')->on('edarate_shahri')->noActionOnDelete(); $table->string('edare_shahri_name')->nullable(); - $table->json('requested_machines'); + $table->json('requested_machines')->nullable(); $table->string('type'); $table->dateTime('start_date'); $table->dateTime('end_date'); diff --git a/database/migrations/2025_06_10_093806_add_area_to_missions_table.php b/database/migrations/2025_06_10_093806_add_area_to_missions_table.php index bee98cf6..dbd95723 100644 --- a/database/migrations/2025_06_10_093806_add_area_to_missions_table.php +++ b/database/migrations/2025_06_10_093806_add_area_to_missions_table.php @@ -12,7 +12,7 @@ return new class extends Migration public function up(): void { Schema::table('missions', function (Blueprint $table) { - $table->json('area'); + $table->json('area')->nullable(); $table->integer('zone'); $table->string('zone_fa'); $table->string('type_fa'); diff --git a/database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php b/database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php index b6c28ccd..958efa7a 100644 --- a/database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php +++ b/database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php @@ -14,6 +14,8 @@ return new class extends Migration Schema::table('mission_violations', function (Blueprint $table) { $table->dateTime('exit_station')->nullable(); $table->dateTime('enter_station')->nullable(); + $table->unsignedInteger('station_id')->nullable(); + $table->string('station_name')->nullable(); }); } diff --git a/routes/v3.php b/routes/v3.php index 00410870..f1fe7505 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -493,13 +493,14 @@ Route::prefix('missions') ->controller(RequestPortalController::class) ->group(function () { Route::get('/', 'index')->name('index'); + Route::get('/violations', 'violations')->name('violations'); Route::post('/', 'store')->name('store'); - Route::post('/no_process','noProcess')->name('noProcess'); + Route::post('/clarifyUnauthorizedExit/{violation}','clarifyUnauthorizedExit')->name('clarifyUnauthorizedExit'); Route::post('/continue/{mission}','continueMission')->name('continueMission'); Route::get('/{mission}', 'show')->name('show'); Route::post('/{mission}', 'update')->name('update'); Route::delete('/{mission}', 'destroy')->name('destroy'); - Route::post('/change_state/{mission}', 'changeState')->name('changeState'); + Route::post('/change_state/{mission}', 'changeState')->name('changeState')->middleware('permission:mission-change-state'); }); Route::name('transportationUnit.') ->prefix('transportation_unit') @@ -534,7 +535,6 @@ Route::prefix('missions') ->group(function () { Route::get('/', 'index')->name('index'); Route::post('/', 'store')->name('store'); - Route::post('/no_process/{violation}','noProcess')->name('noProcess'); Route::get('/{violation}', 'show')->name('show'); Route::post('/{violation}', 'update')->name('update'); Route::delete('/{violation}', 'destroy')->name('destroy'); @@ -565,11 +565,12 @@ Route::prefix('missions') ->controller(ReportMachineController::class) ->group(function () { Route::get('/country_machines_activity', 'countryMachinesActivity')->name('countryMachinesActivity'); - Route::get('/country_machines_activity', 'countryMachinesActivityExcel')->name('countryMachinesActivityExcel'); + Route::get('/country_machines_activity_excel', 'countryMachinesActivityExcel')->name('countryMachinesActivityExcel'); Route::get('/province_machines_activity', 'provinceMachinesActivity')->name('provinceMachinesActivity'); - Route::get('/province_machines_activity', 'provinceMachinesActivityExcel')->name('provinceMachinesActivityExcel'); + Route::get('/province_machines_activity_excel', 'provinceMachinesActivityExcel')->name('provinceMachinesActivityExcel'); Route::get('/country_machine_types_activity', 'countryMachineTypesActivity')->name('countryMachineTypesActivity'); Route::get('/province_machine_types_activity', 'provinceMachineTypesActivity')->name('provinceMachineTypesActivity'); + Route::get('/machine_details_report', 'machineDetailsReport')->name('machineDetailsReport'); }); }); From 17a6e903ae9181c4117d729f712fc47f6742843d Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 14 Jun 2026 08:50:36 +0330 Subject: [PATCH 29/40] use polyline encoder for command --- app/Console/Commands/EncodePolyLineCommand.php | 10 +++++++++- .../Mission/Report/ReportMachineController.php | 2 +- .../V3/Dashboard/Mission/RequestPortalController.php | 2 +- routes/v3.php | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/EncodePolyLineCommand.php b/app/Console/Commands/EncodePolyLineCommand.php index 7eb615f1..4dd32435 100644 --- a/app/Console/Commands/EncodePolyLineCommand.php +++ b/app/Console/Commands/EncodePolyLineCommand.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Models\Mission; use App\Services\PolylineEncoder; use Illuminate\Console\Command; @@ -24,8 +25,15 @@ class EncodePolyLineCommand extends Command /** * Execute the console command. */ - public function handle(PolylineEncoder $polylineEncoder) + public function handle(PolylineEncoder $polylineEncoder): void { + Mission::query()->whereNotNull('area')->each(function ($mission) use ($polylineEncoder) { + $encodedValue = $polylineEncoder->encodePolyLine($mission, lng_lat_format:true); + $mission->update([ + 'encoded_route' => $encodedValue, + ]); + }); + $this->info("updated successfully"); } } diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index 67b40e81..e9d1e5c2 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -109,7 +109,7 @@ class ReportMachineController extends Controller allowedSortings: ['*'], allowedSelects: [ 'id', 'province_id', 'province_name', 'city_id', 'city_name', - 'end_km', 'km', 'driver_name', 'state_name', + 'end_km', 'km', 'driver_name', 'state_name', 'station_name' ] ); } diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index ab69b445..74dd434e 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -41,7 +41,7 @@ class RequestPortalController extends Controller return response()->json($requestPortalService->datatable($request)); } - public function violations(Request $request): JsonResponse + public function violations(Request $request): array { $query = MissionViolation::query()->where([ ['status', '=', MissionViolationStatus::BEDON_EGHDAM->value], diff --git a/routes/v3.php b/routes/v3.php index ff56530e..d4c2ef71 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -497,7 +497,7 @@ Route::prefix('missions') Route::get('/', 'index')->name('index'); Route::get('/violations', 'violations')->name('violations'); Route::post('/', 'store')->name('store'); - Route::post('/clarifyUnauthorizedExit/{violation}','clarifyUnauthorizedExit')->name('clarifyUnauthorizedExit'); + Route::post('/clarify_unauthorized_exit/{violation}','clarifyUnauthorizedExit')->name('clarifyUnauthorizedExit'); Route::post('/continue/{mission}','continueMission')->name('continueMission'); Route::get('/{mission}', 'show')->name('show'); Route::post('/{mission}', 'update')->name('update'); From 0b7b22ff87d0bb8e58441c4fda5c9abebc701a28 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 14 Jun 2026 10:05:13 +0330 Subject: [PATCH 30/40] fix the command --- .../Commands/EncodePolyLineCommand.php | 3 ++- .../Report/ReportMachineController.php | 24 ++++++++++++++++++- .../V3/Mission/Violation/UpdateRequest.php | 14 +++++++++++ .../Mission/RequestPortalService.php | 1 + routes/v3.php | 2 ++ 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/EncodePolyLineCommand.php b/app/Console/Commands/EncodePolyLineCommand.php index 4dd32435..8fa34cd9 100644 --- a/app/Console/Commands/EncodePolyLineCommand.php +++ b/app/Console/Commands/EncodePolyLineCommand.php @@ -28,7 +28,8 @@ class EncodePolyLineCommand extends Command public function handle(PolylineEncoder $polylineEncoder): void { Mission::query()->whereNotNull('area')->each(function ($mission) use ($polylineEncoder) { - $encodedValue = $polylineEncoder->encodePolyLine($mission, lng_lat_format:true); + $area = json_decode($mission->area, true); + $encodedValue = $polylineEncoder->encodePolyLine($area['coordinates'], lng_lat_format:true); $mission->update([ 'encoded_route' => $encodedValue, ]); diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index e9d1e5c2..478f10e4 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -109,7 +109,7 @@ class ReportMachineController extends Controller allowedSortings: ['*'], allowedSelects: [ 'id', 'province_id', 'province_name', 'city_id', 'city_name', - 'end_km', 'km', 'driver_name', 'state_name', 'station_name' + 'end_km', 'km', 'driver_name', 'state_id', 'station_name' ] ); } @@ -125,4 +125,26 @@ class ReportMachineController extends Controller return Excel::download(new machineReport($data), $name); } + + public function countryMachineDriversActivity(Request $request, ReportMachineService $reportMachineService) + { + return $this->successResponse([ + 'activities' => $reportMachineService->countryMachineDriversActivity($request), +// 'provinces' => Province::all(['id', 'name_fa']), + ]); + } + + public function provinceMachineDriversActivity(Request $request, ReportMachineService $reportMachineService) + { + 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']) + ]); + } } diff --git a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php index 0948924e..f2e6b14e 100644 --- a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php @@ -29,4 +29,18 @@ class UpdateRequest extends FormRequest 'enter_station' => 'required|date', ]; } + + public function after(): array + { + return [ + function (Validator $validator) { + if (strtotime($this->violation->exit_station) < strtotime($this->enter_station)) { + $validator->errors()->add( + 'time', + 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' + ); + } + } + ]; + } } diff --git a/app/Services/Cartables/Mission/RequestPortalService.php b/app/Services/Cartables/Mission/RequestPortalService.php index 58d197b9..2c17793c 100644 --- a/app/Services/Cartables/Mission/RequestPortalService.php +++ b/app/Services/Cartables/Mission/RequestPortalService.php @@ -34,6 +34,7 @@ class RequestPortalService 'description', 'requested_machines', 'type', 'type_fa', 'start_date', 'state_id', 'end_date', 'request_date', 'end_point', 'encoded_route', 'zone', 'zone_fa', 'start_time', 'finish_time', 'code', 'category_id', 'category_name', 'explanation', 'city_id', 'city_name', 'province_id', 'station_name', + 'driver_id', 'driver_name' ] ); } diff --git a/routes/v3.php b/routes/v3.php index d4c2ef71..e94c6941 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -573,6 +573,8 @@ Route::prefix('missions') Route::get('/country_machine_types_activity', 'countryMachineTypesActivity')->name('countryMachineTypesActivity'); Route::get('/province_machine_types_activity', 'provinceMachineTypesActivity')->name('provinceMachineTypesActivity'); 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'); }); }); From a45b4955dbbb6a6af8a3cae9da313776b339247d Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 14 Jun 2026 10:40:54 +0330 Subject: [PATCH 31/40] 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 32/40] 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'); }); }); From 75c649c48e37734616392e9734db1779da236852 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 14 Jun 2026 11:19:11 +0330 Subject: [PATCH 33/40] fix route --- .../Mission/Report/ReportMachineController.php | 10 +++++----- .../Cartables/Mission/Report/ReportMachineService.php | 4 ++-- routes/v3.php | 8 ++++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php index 93aaf0cc..ddcc0fd3 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -45,7 +45,7 @@ class ReportMachineController extends Controller public function provinceMachinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse { return $this->successResponse([ - 'activities' => $reportMachineService->countryMachinesActivity($request), + 'activities' => $reportMachineService->provinceMachinesActivity($request), // 'city' => City::query() // ->where('province_id', $request->province_id) // ->where(function ($query) { @@ -102,10 +102,10 @@ class ReportMachineController extends Controller ]); } - public function machineDetailsReport(Request $request) + public function machineDetailsReport(Request $request, int $machine_id) { return DataTableFacade::run( - Mission::query()->where('machine_id', '=', $request->query('machine_id')), + Mission::query()->where('machine_id', '=', $machine_id), $request, allowedFilters: ['*'], allowedSortings: ['*'], @@ -165,10 +165,10 @@ class ReportMachineController extends Controller ); } - public function machineDriverDetailsReport(Request $request) + public function machineDriverDetailsReport(Request $request, int $driver_id) { return DataTableFacade::run( - Mission::query()->where('driver_id', '=', $request->query('driver_id')), + Mission::query()->where('driver_id', '=', $driver_id), $request, allowedFilters: ['*'], allowedSortings: ['*'], diff --git a/app/Services/Cartables/Mission/Report/ReportMachineService.php b/app/Services/Cartables/Mission/Report/ReportMachineService.php index 89ba239b..38bb4996 100644 --- a/app/Services/Cartables/Mission/Report/ReportMachineService.php +++ b/app/Services/Cartables/Mission/Report/ReportMachineService.php @@ -38,10 +38,10 @@ class ReportMachineService $to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay(); $province = $request->province_id; - $sql = "SELECT machine_id, machine_code, cm.car_name, COUNT(*) AS missions, SUM(m.end_km - m.km) AS func + $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 province_id = :province_id + WHERE m.state_id = 4 AND start_time >= :from AND finish_time <= :to AND m.province_id = :province_id GROUP BY machine_id;"; return DB::select($sql, [ diff --git a/routes/v3.php b/routes/v3.php index 513440f1..6c67a1d0 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -571,11 +571,15 @@ Route::prefix('missions') 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('/machine_details_report', 'machineDetailsReport')->name('machineDetailsReport'); + 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('/machine_driver_details_report', 'machineDriverDetailsReport')->name('machineDriverDetailsReport'); + Route::get('/province_machine_drivers_activity_excel', 'provinceMachineDriversActivityExcel')->name('provinceMachineDriversActivityExcel'); + 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 0f65437bfa4a3f811696300d614e042c9937f71f Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 14 Jun 2026 11:21:30 +0330 Subject: [PATCH 34/40] remove exit station --- .../Dashboard/Mission/RequestPortalController.php | 14 +++++++------- .../Mission/ViolationManagementController.php | 4 ++-- .../Requests/V3/Mission/Violation/StoreRequest.php | 2 +- .../V3/Mission/Violation/UpdateRequest.php | 4 ++-- ...4529_add_column_to_mission_violations_table.php | 4 +--- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index 74dd434e..2f231f72 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -236,8 +236,8 @@ class RequestPortalController extends Controller { DB::transaction(function () use ($request, $violation) { - $start = Carbon::parse($violation->exit_station); - $end = Carbon::parse($violation->enter_station); + $start = Carbon::parse($violation->exit_time); + $end = Carbon::parse($violation->enter_time); $type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value; $user = auth()->user(); $zone = $request->zone; @@ -257,14 +257,14 @@ class RequestPortalController extends Controller 'encoded_route' => $request->encoded_route, 'type' => $type, 'type_fa' => MissionTypes::name($type), - 'start_date' => $violation->exit_station, - 'end_date' => $violation->enter_station, + 'start_date' => $violation->exit_time, + 'end_date' => $violation->enter_time, 'end_point' => $request->end_point, 'category_id' => $request->category_id, 'category_name' => MissionCategory::name($request->category_id), - 'start_time' => $violation->exit_station, - 'finish_time' => $violation->enter_station, - 'mission_duration' => strtotime($violation->enter_station) - strtotime($violation->exit_station), + 'start_time' => $violation->exit_time, + 'finish_time' => $violation->enter_time, + 'mission_duration' => strtotime($violation->enter_time) - strtotime($violation->exit_time), 'state_id' => MissionStates::END_MISSION->value, 'state_name' => MissionStates::END_MISSION->label(), 'explanation' => $request->explanation, diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php index 5d1728b9..89e9d29d 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php @@ -54,7 +54,7 @@ class ViolationManagementController extends Controller 'city_name' => $user->city_fa, 'station_id' => $user->station_id, 'station_name' => RahdariPoint::query()->find($user->station_id)->name, - 'exit_station' => $request->exit_station, + 'exit_time' => $request->exit_time, ]); return $this->successResponse(); @@ -68,7 +68,7 @@ class ViolationManagementController extends Controller public function update(UpdateRequest $request, MissionViolation $violation): JsonResponse { $violation->update([ - 'enter_station' => $request->enter_station, + 'enter_time' => $request->enter_time, 'status' => MissionViolationStatus::BEDON_EGHDAM->value, ]); diff --git a/app/Http/Requests/V3/Mission/Violation/StoreRequest.php b/app/Http/Requests/V3/Mission/Violation/StoreRequest.php index 2994a64f..16ea27bc 100644 --- a/app/Http/Requests/V3/Mission/Violation/StoreRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/StoreRequest.php @@ -25,7 +25,7 @@ class StoreRequest extends FormRequest public function rules(): array { return [ - 'exit_station' => 'required|date', + 'exit_time' => 'required|date', 'machine_code' => 'required', 'km'=> 'string', ]; diff --git a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php index f2e6b14e..ecaf96fd 100644 --- a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php @@ -26,7 +26,7 @@ class UpdateRequest extends FormRequest public function rules(): array { return [ - 'enter_station' => 'required|date', + 'enter_time' => 'required|date', ]; } @@ -34,7 +34,7 @@ class UpdateRequest extends FormRequest { return [ function (Validator $validator) { - if (strtotime($this->violation->exit_station) < strtotime($this->enter_station)) { + if (strtotime($this->violation->exit_time) < strtotime($this->enter_time)) { $validator->errors()->add( 'time', 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' diff --git a/database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php b/database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php index 958efa7a..46c68d01 100644 --- a/database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php +++ b/database/migrations/2026_06_10_144529_add_column_to_mission_violations_table.php @@ -12,8 +12,6 @@ return new class extends Migration public function up(): void { Schema::table('mission_violations', function (Blueprint $table) { - $table->dateTime('exit_station')->nullable(); - $table->dateTime('enter_station')->nullable(); $table->unsignedInteger('station_id')->nullable(); $table->string('station_name')->nullable(); }); @@ -25,7 +23,7 @@ return new class extends Migration public function down(): void { Schema::table('mission_violations', function (Blueprint $table) { - $table->dropColumn(['exit_station', 'enter_station']); + $table->dropColumn(['station_id', 'station_name']); }); } }; From 7ac07692a2a23b134e0910d477a6fc06335a736f Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 14 Jun 2026 13:19:56 +0330 Subject: [PATCH 35/40] change command signature --- app/Console/Commands/EncodePolyLineCommand.php | 2 +- app/Http/Requests/V3/Mission/Violation/UpdateRequest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/EncodePolyLineCommand.php b/app/Console/Commands/EncodePolyLineCommand.php index 8fa34cd9..6b9565b3 100644 --- a/app/Console/Commands/EncodePolyLineCommand.php +++ b/app/Console/Commands/EncodePolyLineCommand.php @@ -13,7 +13,7 @@ class EncodePolyLineCommand extends Command * * @var string */ - protected $signature = 'app:encode-poly-line-command'; + protected $signature = 'polyline:encode'; /** * The console command description. diff --git a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php index ecaf96fd..29426bfd 100644 --- a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php @@ -34,7 +34,7 @@ class UpdateRequest extends FormRequest { return [ function (Validator $validator) { - if (strtotime($this->violation->exit_time) < strtotime($this->enter_time)) { + if (strtotime($this->enter_time) < strtotime($this->violation->exit_time)) { $validator->errors()->add( 'time', 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' From ab9838c1bc5ae12c1fa7b3261b8534bef53070c8 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 14 Jun 2026 14:13:44 +0330 Subject: [PATCH 36/40] create --- .../Mission/Report/Machine/machineReport.php | 10 ++++---- .../Report/Machine/ActivityReport.blade.php | 23 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/Exports/V3/Mission/Report/Machine/machineReport.php b/app/Exports/V3/Mission/Report/Machine/machineReport.php index 5d11323a..f6fd812a 100644 --- a/app/Exports/V3/Mission/Report/Machine/machineReport.php +++ b/app/Exports/V3/Mission/Report/Machine/machineReport.php @@ -18,14 +18,16 @@ class machineReport implements FromView, ShouldAutoSize, WithDrawings, WithEvent } public function view(): View - { $exportRows = []; + { + $exportRows = []; foreach ($this->data as $r) { $exportRows[] = [ - 'city_name' => $r->c_name ?? '', - 'province_name' => $r->p_name ?? '', + 'machine_id' => $r->c_name ?? '', + 'machine_code' => $r->machine_code ?? '', + 'car_name' => $r->car_name ?? '', 'missions' => $r->missions ?? 0, - 'distance' => (int) ($r->distance ?? 0), + 'func' => (int) ($r->func ?? 0), ]; } diff --git a/resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php b/resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php index a3ffc93b..53091d8b 100644 --- a/resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php +++ b/resources/views/v3/Reports/Mission/Report/Machine/ActivityReport.blade.php @@ -46,19 +46,23 @@ - استان + کدیکتا - شهر + مدل ماشین + + کد ماشین + + + کارکرد تعداد ماموریت - - جمع کارکرد - + @@ -66,10 +70,11 @@ @foreach ($rows as $item) - {{ $item['province_name'] ?? '-' }} - {{ $item['city_name'] ?? '-' }} + {{ $item['machine_id'] ?? '-' }} + {{ $item['car_name'] ?? '-' }} + {{ $item['machine_code'] ?? '-' }} + {{ $item['func'] ?? '-' }} {{ $item['missions'] ?? '-' }} - {{ $item['distance'] ?? '-' }} @endforeach From 39752fd5ba1b430cc448420d8ab837c5afe4b511 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 14 Jun 2026 14:14:30 +0330 Subject: [PATCH 37/40] create excel for report in mission --- .../Report/Machine/machineDriverReport.php | 74 ++++++++++++++++++ .../Mission/Report/Machine/machineReport.php | 2 +- .../Report/Machine/machineTypeReport.php | 73 ++++++++++++++++++ .../Report/ReportMachineController.php | 36 +++++++-- .../Machine/MachineDriverReport.blade.php | 75 +++++++++++++++++++ .../Machine/MachineTypeReport.blade.php | 75 +++++++++++++++++++ 6 files changed, 329 insertions(+), 6 deletions(-) create mode 100644 app/Exports/V3/Mission/Report/Machine/machineDriverReport.php create mode 100644 app/Exports/V3/Mission/Report/Machine/machineTypeReport.php create mode 100644 resources/views/v3/Reports/Mission/Report/Machine/MachineDriverReport.blade.php create mode 100644 resources/views/v3/Reports/Mission/Report/Machine/MachineTypeReport.blade.php diff --git a/app/Exports/V3/Mission/Report/Machine/machineDriverReport.php b/app/Exports/V3/Mission/Report/Machine/machineDriverReport.php new file mode 100644 index 00000000..3bb74fdc --- /dev/null +++ b/app/Exports/V3/Mission/Report/Machine/machineDriverReport.php @@ -0,0 +1,74 @@ +data as $r) { + $exportRows[] = [ + 'driver_id' => $r->driver_id ?? '', + 'driver_name' => $r->driver_name ?? '', + 'missions' => $r->missions ?? 0, + 'func' => (int) ($r->func ?? 0), + ]; + } + + return view('v3.Reports.Mission.Report.Machine.MachineDriverReport', [ + '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(5); + $drawing2->setOffsetY(5); + $drawing2->setCoordinates('D1'); + + return [$drawing, $drawing2]; + } +} diff --git a/app/Exports/V3/Mission/Report/Machine/machineReport.php b/app/Exports/V3/Mission/Report/Machine/machineReport.php index f6fd812a..5b9daa15 100644 --- a/app/Exports/V3/Mission/Report/Machine/machineReport.php +++ b/app/Exports/V3/Mission/Report/Machine/machineReport.php @@ -68,7 +68,7 @@ class machineReport implements FromView, ShouldAutoSize, WithDrawings, WithEvent $drawing2->setHeight(50); $drawing2->setOffsetX(5); $drawing2->setOffsetY(5); - $drawing2->setCoordinates('D1'); + $drawing2->setCoordinates('E1'); return [$drawing, $drawing2]; } diff --git a/app/Exports/V3/Mission/Report/Machine/machineTypeReport.php b/app/Exports/V3/Mission/Report/Machine/machineTypeReport.php new file mode 100644 index 00000000..d376871e --- /dev/null +++ b/app/Exports/V3/Mission/Report/Machine/machineTypeReport.php @@ -0,0 +1,73 @@ +data as $r) { + $exportRows[] = [ + 'car_type' => $r->car_type ?? '', + 'missions' => $r->missions ?? 0, + 'func' => (int) ($r->func ?? 0), + ]; + } + + return view('v3.Reports.Mission.Report.Machine.MachineTypeReport', [ + '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(5); + $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 ddcc0fd3..f39b46bf 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/Report/ReportMachineController.php @@ -2,7 +2,9 @@ namespace App\Http\Controllers\V3\Dashboard\Mission\Report; +use App\Exports\V3\Mission\Report\Machine\machineDriverReport; use App\Exports\V3\Mission\Report\Machine\machineReport; +use App\Exports\V3\Mission\Report\Machine\machineTypeReport; use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; use App\Http\Traits\ApiResponse; @@ -62,7 +64,7 @@ class ReportMachineController extends Controller */ public function provinceMachinesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse { - $data = $reportMachineService->countryMachinesActivity($request); + $data = $reportMachineService->provinceMachinesActivity($request); $name = 'گزارش ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; return Excel::download(new machineReport($data), $name); @@ -83,9 +85,9 @@ class ReportMachineController extends Controller public function countryMachineTypesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse { $data = $reportMachineService->countryMachineTypesActivity($request); - $name = 'گزارش ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; + $name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - return Excel::download(new machineReport($data), $name); + return Excel::download(new machineTypeReport($data), $name); } public function provinceMachineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse @@ -123,9 +125,9 @@ class ReportMachineController extends Controller public function provinceMachineTypesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse { $data = $reportMachineService->provinceMachineTypesActivity($request); - $name = 'گزارش ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; + $name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; - return Excel::download(new machineReport($data), $name); + return Excel::download(new machineTypeReport($data), $name); } public function countryMachineDriversActivity(Request $request, ReportMachineService $reportMachineService) @@ -136,6 +138,18 @@ 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 provinceMachineDriversActivity(Request $request, ReportMachineService $reportMachineService) { return $this->successResponse([ @@ -150,6 +164,18 @@ class ReportMachineController extends Controller ]); } + /** + * @throws Exception + * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + */ + public function provinceMachineDriversActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse + { + $data = $reportMachineService->provinceMachineDriversActivity($request); + $name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx'; + + return Excel::download(new machineDriverReport($data), $name); + } + public function machineTypeDetailsReport(Request $request) { $machineIds = CMMSMachine::query()->where('car_type', '=', $request->query('car_type'))->pluck('machine_id'); diff --git a/resources/views/v3/Reports/Mission/Report/Machine/MachineDriverReport.blade.php b/resources/views/v3/Reports/Mission/Report/Machine/MachineDriverReport.blade.php new file mode 100644 index 00000000..9ed7b2c9 --- /dev/null +++ b/resources/views/v3/Reports/Mission/Report/Machine/MachineDriverReport.blade.php @@ -0,0 +1,75 @@ + + + + + + + + گزارش کل تردد های راننده + + + + + +@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') }} +
+
+ گزارش راندده ها در ماموریت +
+ car_type + + کارکرد + + تعداد ماموریت
{{ $item['driver_id'] ?? '-' }}{{ $item['driver_name'] ?? '-' }}{{ $item['func'] ?? '-' }}{{ $item['missions'] ?? '-' }}
+ + diff --git a/resources/views/v3/Reports/Mission/Report/Machine/MachineTypeReport.blade.php b/resources/views/v3/Reports/Mission/Report/Machine/MachineTypeReport.blade.php new file mode 100644 index 00000000..46545ea6 --- /dev/null +++ b/resources/views/v3/Reports/Mission/Report/Machine/MachineTypeReport.blade.php @@ -0,0 +1,75 @@ + + + + + + + + گزارش کل تردد های انواع ماشین ها + + + + + +@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['car_type'] ?? '-' }}{{ $item['func'] ?? '-' }}{{ $item['missions'] ?? '-' }}
+ + From 439f69af29e1006147fe10b2ea499bc2509d2f3c Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 15 Jun 2026 10:32:04 +0330 Subject: [PATCH 38/40] add end_km to violations --- .../Mission/RequestPortalController.php | 4 +++ .../Mission/ViolationManagementController.php | 1 + .../RequestPortal/ContinueMissionRequest.php | 13 +++++++++ .../V3/Mission/Violation/UpdateRequest.php | 7 +++++ ...add_column_to_mission_violations_table.php | 28 +++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 database/migrations/2026_06_15_095947_add_column_to_mission_violations_table.php diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index 2f231f72..95c6a694 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -126,6 +126,7 @@ class RequestPortalController extends Controller 'finish_time' => now(), 'state_id' => MissionStates::END_MISSION->value, 'state_name' => MissionStates::name(MissionStates::END_MISSION->value), + 'end_km' => $request->end_km, ]); // if ($mission->category_id == 2) { @@ -166,6 +167,8 @@ class RequestPortalController extends Controller 'station_name' => RahdariPoint::query()->find( $user->station_id)->name, 'driver_id' => $request->driver, 'driver_name' => Rahdaran::query()->find($request->driver)->name, + 'km' => $request->end_km, + 'requested_machines' => json_encode($mission->requested_machines), ]); $newMission->rahdaran()->sync($request->rahdaran); @@ -275,6 +278,7 @@ class RequestPortalController extends Controller 'station_id' => $user->station_id, 'station_name' => RahdariPoint::query()->find($user->station_id)->name, 'km' => $violation->km ?? null, + 'end_km' => $violation->end_km ?? null, 'driver_id' => $request->driver, 'driver_name' => Rahdaran::query()->find($request->driver)->name, ]); diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php index 89e9d29d..5d73cefa 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ViolationManagementController.php @@ -70,6 +70,7 @@ class ViolationManagementController extends Controller $violation->update([ 'enter_time' => $request->enter_time, 'status' => MissionViolationStatus::BEDON_EGHDAM->value, + 'end_km' => $request->end_km, ]); return $this->successResponse(); diff --git a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php index 1fe7f381..46fc0cea 100644 --- a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php +++ b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php @@ -38,6 +38,7 @@ class ContinueMissionRequest extends FormRequest 'encoded_route' => 'required|string', 'explanation' => 'required|string', 'category_id' => 'required|in:1,2,3', + 'end_km'=> 'required|string', ]; } @@ -56,6 +57,18 @@ class ContinueMissionRequest extends FormRequest ); } } + if ($this->end_km < $this->mission->km) { + $validator->errors()->add( + 'end_km', + 'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.' + ); + } + if (strtotime($this->end_date) < strtotime($this->mission->start_time)) { + $validator->errors()->add( + 'time', + 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' + ); + } }, ]; } diff --git a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php index 29426bfd..561e2188 100644 --- a/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php +++ b/app/Http/Requests/V3/Mission/Violation/UpdateRequest.php @@ -27,6 +27,7 @@ class UpdateRequest extends FormRequest { return [ 'enter_time' => 'required|date', + 'end_km'=> 'required|string', ]; } @@ -40,6 +41,12 @@ class UpdateRequest extends FormRequest 'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.' ); } + if ($this->end_km < $this->violation->km) { + $validator->errors()->add( + 'end_km', + 'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.' + ); + } } ]; } diff --git a/database/migrations/2026_06_15_095947_add_column_to_mission_violations_table.php b/database/migrations/2026_06_15_095947_add_column_to_mission_violations_table.php new file mode 100644 index 00000000..164da569 --- /dev/null +++ b/database/migrations/2026_06_15_095947_add_column_to_mission_violations_table.php @@ -0,0 +1,28 @@ +string('end_km')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('mission_violations', function (Blueprint $table) { + $table->dropColumn('end_km'); + }); + } +}; From 3045f60f1e53fccc365ab13219a9c6553fcb0b92 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 15 Jun 2026 11:08:03 +0330 Subject: [PATCH 39/40] add requested machines --- .../V3/Dashboard/Mission/RequestPortalController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index 95c6a694..61f539ea 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -134,7 +134,7 @@ class RequestPortalController extends Controller // $rpc->store($mission); // } - $machine = CMMSMachine::query()->find($request->machine_id); + $machine = CMMSMachine::query()->find($request->machine_id, ['id', 'machine_code', 'car_type']); $newMission = Mission::query()->create([ 'user_id' => $user->id, @@ -168,7 +168,7 @@ class RequestPortalController extends Controller 'driver_id' => $request->driver, 'driver_name' => Rahdaran::query()->find($request->driver)->name, 'km' => $request->end_km, - 'requested_machines' => json_encode($mission->requested_machines), + 'requested_machines' => json_encode($machine->car_type), ]); $newMission->rahdaran()->sync($request->rahdaran); @@ -244,7 +244,7 @@ class RequestPortalController extends Controller $type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value; $user = auth()->user(); $zone = $request->zone; - $machine = CMMSMachine::query()->where('machine_code', '=', $violation->machine_code)->first(['id', 'machine_code']); + $machine = CMMSMachine::query()->where('machine_code', '=', $violation->machine_code)->first(['id', 'machine_code', 'car_type']); $mission = Mission::query()->create([ 'user_id' => $user->id, @@ -274,7 +274,7 @@ class RequestPortalController extends Controller 'request_date' => now(), 'machine_id' => $machine->id, 'machine_code' => $machine->machine_code, - 'requested_machines' => $machine->car_type, + 'requested_machines' => json_encode($machine->car_type), 'station_id' => $user->station_id, 'station_name' => RahdariPoint::query()->find($user->station_id)->name, 'km' => $violation->km ?? null, From ad01e4718d4fd1d3a6c027c6d189fcecfffec3d0 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 15 Jun 2026 11:33:06 +0330 Subject: [PATCH 40/40] fix the .env.example --- .env.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 14720635..b8c978b3 100644 --- a/.env.example +++ b/.env.example @@ -78,7 +78,7 @@ FMS_ERROR_RATE_URL= FMS_ERROR_RATE_PASSWORD= FMS_ERROR_RATE_USERNAME= -HARIM_NEED_ACCESS_URL='https://zamin.gov.ir/ow/api/ow/esb/response', +HARIM_NEED_ACCESS_URL='https://zamin.gov.ir/ow/api/ow/esb/response' HARIM_NEED_ACCESS_PASSWORD= HARIM_NEED_ACCESS_USERNAME= @@ -106,7 +106,7 @@ BACKUP_PASSWORD=1qaz HARIM_ENCRYPTION_KEY="TestKey" HARIM_ENCRYPTION_IV="1111000011110101" -CHECKE_LIST_MACHINES_ACTIVITY_URL='fms.141.ir:7030/api/RMS/GetMovingVehicles', +CHECKE_LIST_MACHINES_ACTIVITY_URL='fms.141.ir:7030/api/RMS/GetMovingVehicles' CHECKE_LIST_MACHINES_ACTIVITY_PASSWORD= CHECKE_LIST_MACHINES_ACTIVITY_USERNAME=