diff --git a/app/Console/Commands/BackupDatabaseCommand.php b/app/Console/Commands/BackupDatabaseCommand.php index 1d0d6ca8..d0f06261 100644 --- a/app/Console/Commands/BackupDatabaseCommand.php +++ b/app/Console/Commands/BackupDatabaseCommand.php @@ -35,13 +35,13 @@ class BackupDatabaseCommand extends Command $backup = Process::path($path)->forever()->run("sudo mariadb-backup --backup --target-dir={$path}/{$time} --user={$user} --password={$password}"); if ($backup->failed()) { - Log::channel('mariadb-backup')->info("Backup failed at {$time}"); + Log::channel('mariadb-backup')->info("Backup failed at {$time} error message : " . $backup->errorOutput()); } $prepare = Process::path($path)->forever()->run("sudo mariadb-backup --prepare --target-dir={$path}/{$time}"); if ($prepare->failed()) { - Log::channel('mariadb-backup')->info("Preparation failed at {$time}"); + Log::channel('mariadb-backup')->info("Preparation failed at {$time} error message : " . $prepare->errorOutput()); } Log::channel('mariadb-backup')->info("Backup successful at {$time}"); diff --git a/app/Console/Commands/RoadObservationProblems.php b/app/Console/Commands/RoadObservationProblems.php index 85d792bc..b585d167 100755 --- a/app/Console/Commands/RoadObservationProblems.php +++ b/app/Console/Commands/RoadObservationProblems.php @@ -19,29 +19,29 @@ use App\Models\City; class RoadObservationProblems extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'webservice:roadobserved {--daily-mode}'; + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'webservice:roadobserved {--daily-mode}'; - /** - * The console command description. - * - * @var string - */ - protected $description = 'get road observed problems from 141 (samaneh sawaneh)'; + /** + * The console command description. + * + * @var string + */ + protected $description = 'get road observed problems from 141 (samaneh sawaneh)'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } + /** + * Create a new command instance. + * + * @return void + */ + public function __construct() + { + parent::__construct(); + } /** * Execute the console command. @@ -49,105 +49,90 @@ class RoadObservationProblems extends Command * @return int|string * @throws Exception */ - public function handle(NikarayanService $nikarayanService, NominatimService $nominatimService) - { - // try { - // $soap_client = new SoapClient($url); - // $result = $soap_client->Get_RoadObservedProblems_Current(array('strUserName' => 'vaytelrop', 'strPassword' => 'VaYtelROP*2024')); - // } catch (SoapFault $e) { - // echo $e->getMessage(); - // $msg = 'rms: error in get road observation webservice babe!!!!'."\n"; - // $msg .= $e->getMessage(); - // // self::sms_sender('09398586633', $msg); - // // self::sms_sender('09367487107', $msg); - // return 0; - // } + public function handle(NikarayanService $nikarayanService, NominatimService $nominatimService) + { + $time = $this->option('daily-mode') ? verta()->subDay() : verta(); - $time = $this->option('daily-mode') ? verta()->subDay() : verta(); + $result = $nikarayanService->getRoadObservedProblemsByDate($time); - $result = $nikarayanService->getRoadObservedProblemsByDate($time); + $result = serialize($result); + $x = strpos($result, 'fk_FeatureType >= 1 && $value->fk_FeatureType <= 6) { //// code ghabli + if (RoadObserved::query()->where('fk_RegisteredEventMessage', '=', $value->fk_RegisteredEventMessage)->exists()) { + continue; + } - $affectedRows = 0; - $cities = []; - foreach ($xml as $value) { - // if ($value->fk_FeatureType >= 1 && $value->fk_FeatureType <= 6) { //// code ghabli - if (RoadObserved::query()->where('fk_RegisteredEventMessage', '=', $value->fk_RegisteredEventMessage)->exists()) { - continue; + if ($value->fk_FeatureType >= 1 && $value->fk_FeatureType <= 24) { + $mobile = null; + + if ($value->MobileForSendEventSms && (strlen($value->MobileForSendEventSms) == 11)) { + $mobile = $value->MobileForSendEventSms; + } + + $cityModel = City::findCityWithLatLng($value->XGeo, $value->YGeo); + $rop = RoadObserved::query()->updateOrCreate( + ['fk_RegisteredEventMessage' => $value->fk_RegisteredEventMessage], + [ + 'fk_RegisteredEventMessage' => $value->fk_RegisteredEventMessage ?? null, + 'Title' => $value->Title ?? null, + 'StartTime' => $value->StartTime ?? null, + 'EndTime' => $value->EndTime ?? null, + 'StartDate' => $value->StartDate ?? null, + 'EndDate' => $value->EndDate ?? null, + 'StartTime_DateTime' => $value->StartTime_DateTime ? Carbon::createFromFormat('m/d/Y h:i:s A', $value->StartTime_DateTime)->format('Y-m-d H:i:s') : null, + 'StartTime_DateTime_fa' => Verta::instance($value->StartTime_DateTime) ?? null, + 'EndTime_DateTime' => $value->EndTime_DateTime ?? null, + 'AutoID' => $value->AutoID ?? null, + 'fk_Country' => $value->fk_Country ?? null, + 'ProvinceName' => $value->ProvinceName ?? null, + 'fk_Province' => $value->fk_Province ?? null, + 'fk_Town' => $value->fk_Town ?? null, + 'TownName' => $value->TownName ?? null, + 'lng' => $value->XGeo ?? null, + 'lat' => $value->YGeo ?? null, + 'XLAM' => $value->XLAM ?? null, + 'YLAM' => $value->YLAM ?? null, + 'WeatherName' => $value->WeatherName ?? null, + 'fk_Weather' => $value->fk_Weather ?? null, + 'EventTypeTitle' => $value->EventTypeTitle ?? null, + 'fk_EventType' => $value->fk_EventType ?? null, + 'FeatureTypeTitle' => $value->FeatureTypeTitle ?? null, + 'fk_FeatureType' => $value->fk_FeatureType ?? null, + 'Description' => (strlen($value->Description) > 5) ? $value->Description : null, + 'MobileForSendEventSms' => $mobile, +// 'rms_province_id' => $rmsProvinceId[(int) $value->fk_Province] ?? null, +// 'rms_city_id' => $rmsCityId[(int) $value->fk_Town]["InvarID"] ?? null, +// 'observed_way_id' => self::get_way_id_from_nominatim($value->XGeo, $value->YGeo) ?? null, + 'rms_province_id' => NikarayanComplaints::mapProvinces((int)$value->fk_Province) ?? null, + 'rms_city_id' => NikarayanComplaints::mapCities((int)$value->fk_Town) ?? null, + 'observed_way_id' => $nominatimService->get_way_id_from_nominatim($value->XGeo, $value->YGeo) ?? null, + 'province_id' => $cityModel->province()->first()->id, + 'city_id' => $cityModel->id, + // 'handler_type' => EdarateShahri::class, + 'edarate_shahri_id' => $cityModel->edarateShahri()->first()->id, + 'province_fa' => $cityModel->province()->first()->name_fa, + 'city_fa' => $cityModel ? $cityModel->name_fa : null, + ] + ); + $affectedRows += 1; + } } - - if ($value->fk_FeatureType >= 1 && $value->fk_FeatureType <= 24) { - $mobile = null; - - if ($value->MobileForSendEventSms && (strlen($value->MobileForSendEventSms) == 11)) { - $mobile = $value->MobileForSendEventSms; - } - - $city = findCityFromGeoJson($value->YGeo, $value->XGeo); - $cityModel = $city ? City::query()->find($city['city_id']) : City::query()->find(NikarayanComplaints::mapCities((int) $value->fk_Town)); - $rop = RoadObserved::query()->updateOrCreate( - ['fk_RegisteredEventMessage' => $value->fk_RegisteredEventMessage], - [ - 'fk_RegisteredEventMessage' => $value->fk_RegisteredEventMessage ?? null, - 'Title' => $value->Title ?? null, - 'StartTime' => $value->StartTime ?? null, - 'EndTime' => $value->EndTime ?? null, - 'StartDate' => $value->StartDate ?? null, - 'EndDate' => $value->EndDate ?? null, - 'StartTime_DateTime' => $value->StartTime_DateTime ? Carbon::createFromFormat('m/d/Y h:i:s A', $value->StartTime_DateTime)->format('Y-m-d H:i:s') : null, - 'StartTime_DateTime_fa' => Verta::instance($value->StartTime_DateTime) ?? null, - 'EndTime_DateTime' => $value->EndTime_DateTime ?? null, - 'AutoID' => $value->AutoID ?? null, - 'fk_Country' => $value->fk_Country ?? null, - 'ProvinceName' => $value->ProvinceName ?? null, - 'fk_Province' => $value->fk_Province ?? null, - 'fk_Town' => $value->fk_Town ?? null, - 'TownName' => $value->TownName ?? null, - 'lng' => $value->XGeo ?? null, - 'lat' => $value->YGeo ?? null, - 'XLAM' => $value->XLAM ?? null, - 'YLAM' => $value->YLAM ?? null, - 'WeatherName' => $value->WeatherName ?? null, - 'fk_Weather' => $value->fk_Weather ?? null, - 'EventTypeTitle' => $value->EventTypeTitle ?? null, - 'fk_EventType' => $value->fk_EventType ?? null, - 'FeatureTypeTitle' => $value->FeatureTypeTitle ?? null, - 'fk_FeatureType' => $value->fk_FeatureType ?? null, - 'Description' => (strlen($value->Description) > 5) ? $value->Description : null, - 'MobileForSendEventSms' => $mobile, -// 'rms_province_id' => $rmsProvinceId[(int) $value->fk_Province] ?? null, -// 'rms_city_id' => $rmsCityId[(int) $value->fk_Town]["InvarID"] ?? null, -// 'observed_way_id' => self::get_way_id_from_nominatim($value->XGeo, $value->YGeo) ?? null, - 'rms_province_id' => NikarayanComplaints::mapProvinces((int) $value->fk_Province) ?? null, - 'rms_city_id' => NikarayanComplaints::mapCities((int) $value->fk_Town) ?? null, - 'observed_way_id' => $nominatimService->get_way_id_from_nominatim($value->XGeo, $value->YGeo) ?? null, - - 'province_id' => $cityModel->province()->first()->id, - 'city_id' => $cityModel->id, - // 'handler_type' => EdarateShahri::class, - 'edarate_shahri_id' => $cityModel->edarateShahri()->first()->id, - 'province_fa' => $cityModel->province()->first()->name_fa, - 'city_fa' => $cityModel ? $cityModel->name_fa : null, - ] - ); - $affectedRows += 1; - } - } - } - else { - $this->info($result); - Log::channel('nikarayan')->error("the received body is empty" . date('Y-m-d H:i:s') . '\t'. $result); - return $result; - } - echo 'done at: ' . date("Y-m-d H:i:s") . "\n"; - echo "{$affectedRows} row's affected"; - return 0; - } + } else { + $this->info($result); + Log::channel('nikarayan')->error("the received body is empty" . date('Y-m-d H:i:s') . '\t' . $result); + return $result; + } + echo 'done at: ' . date("Y-m-d H:i:s") . "\n"; + echo "{$affectedRows} row's affected"; + return 0; + } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 815e0d20..72869440 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,6 +2,7 @@ namespace App\Console; +use App\Console\Commands\ManageDataTelescopeCommand; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; @@ -42,6 +43,11 @@ class Kernel extends ConsoleKernel $schedule->command("db:backup") ->weekly()->at('03:00')->appendOutputTo(storage_path('logs/mariadb-backup.log')); + + $schedule->command('telescope:prune --hours=48') + ->dailyAt('04:00') + ->appendOutputTo(storage_path('logs/telescope.log')); + } /** diff --git a/app/Exports/V3/AccidentReceipt/DataTableReport.php b/app/Exports/V3/AccidentReceipt/DataTableReport.php index 4d6a0a5f..6ec568a8 100644 --- a/app/Exports/V3/AccidentReceipt/DataTableReport.php +++ b/app/Exports/V3/AccidentReceipt/DataTableReport.php @@ -57,7 +57,7 @@ class DataTableReport implements FromView, ShouldAutoSize, WithEvents, WithDrawi $drawing2->setHeight(50); $drawing2->setOffsetX(5); $drawing2->setOffsetY(5); - $drawing2->setCoordinates('B1'); + $drawing2->setCoordinates('Q1'); return [$drawing, $drawing2]; } diff --git a/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptController.php index eeece69e..ce0ae4a6 100644 --- a/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptController.php @@ -254,7 +254,7 @@ class AccidentReceiptController extends Controller { DB::transaction(function () use ($request, $accident) { - $final_amount = $accident->driver_share_amount - ($accident->deposit_insurance_amount + $accident->deposit_daghi_amount); + $final_amount = $accident->driver_share_amount - ($request->deposit_insurance_amount + $request->deposit_daghi_amount); throw_if($final_amount < 0, new ProhibitedAction('مبالغ داغی و بیمه از مبلغ کل بیشتر می باشد.')); diff --git a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php index 03482c71..f8d632cb 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/RequestPortalController.php @@ -109,7 +109,7 @@ class RequestPortalController extends Controller 'type_fa' => MissionTypes::name($request->type), 'zone' => $request->zone, 'zone_fa' => MissionZones::name($request->zone), - 'start_date' => $request->start_date, + 'start_date' => now(), 'end_date' => $request->end_date, 'request_date' => now(), 'description' => $request->description, diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/AccessRoadActivityController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/AccessRoadActivityController.php index 0abd41b3..7283dcf2 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/AccessRoadActivityController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/AccessRoadActivityController.php @@ -17,9 +17,10 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse; class AccessRoadActivityController extends Controller { use ApiResponse; + public function countryActivity(Request $request, OperatorService $operatorService): JsonResponse { - $data = $operatorService->countryActivity(90); + $data = $operatorService->countryActivity(90, $request); return $this->successResponse([ 'activities' => $data, @@ -31,8 +32,8 @@ class AccessRoadActivityController extends Controller { $data = $operatorService->provinceActivity( - info_id: 90, - province_id: $request->input('province_id') + $request, + 90, ); return $this->successResponse([ @@ -42,7 +43,7 @@ class AccessRoadActivityController extends Controller } public function countryExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse { - $data = $operatorService->countryActivity(90); + $data = $operatorService->countryActivity(90, $request); $name = 'گزارش نگهداری حریم راه برای راه دسترسی غیر مجاز ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; return Excel::download(new ExcelReport($data), $name); } @@ -50,8 +51,8 @@ class AccessRoadActivityController extends Controller public function provinceExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse { $data = $operatorService->provinceActivity( - info_id: 90, - province_id: $request->input('province_id') + $request, + 90, ); $name = 'گزارش نگهداری حریم راه برای راه دسترسی غیر مجاز ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; return Excel::download(new AccessRoadReport($data, $request), $name); diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/ConstructionActivityController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/ConstructionActivityController.php index f3907676..0db03253 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/ConstructionActivityController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/ConstructionActivityController.php @@ -20,7 +20,7 @@ class ConstructionActivityController extends Controller use ApiResponse; public function countryActivity(Request $request, OperatorService $operatorService): JsonResponse { - $data = $operatorService->countryActivity(89); + $data = $operatorService->countryActivity(89, $request); return $this->successResponse([ 'activities' => $data, @@ -30,8 +30,8 @@ class ConstructionActivityController extends Controller public function provinceActivity(Request $request, OperatorService $operatorService,): JsonResponse { $data = $operatorService->provinceActivity( - info_id: 89, - province_id: $request->input('province_id') + $request, + 89, ); return $this->successResponse([ @@ -46,7 +46,7 @@ class ConstructionActivityController extends Controller */ public function countryExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse { - $data = $operatorService->countryActivity(89); + $data = $operatorService->countryActivity(89, $request); $name = ' گزارش نگهداری حریم راه برای ساخت و ساز غیر مجاز' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; return Excel::download(new ExcelReport($data), $name); @@ -59,8 +59,8 @@ class ConstructionActivityController extends Controller public function provinceExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse { $data = $operatorService->provinceActivity( - info_id: 89, - province_id: $request->input('province_id') + $request, + 89, ); $name = ' گزارش نگهداری حریم راه برای ساخت و ساز غیر مجاز' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/UtilityPassingActivityController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/UtilityPassingActivityController.php index d11623aa..3e92c834 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/UtilityPassingActivityController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacy/OperatorReport/UtilityPassingActivityController.php @@ -20,7 +20,7 @@ class UtilityPassingActivityController extends Controller public function countryActivity(Request $request, OperatorService $operatorService): JsonResponse { - $data = $operatorService->countryActivity(91); + $data = $operatorService->countryActivity(91, $request); return $this->successResponse([ 'activities' => $data, @@ -30,8 +30,8 @@ class UtilityPassingActivityController extends Controller public function provinceActivity(Request $request, OperatorService $operatorService): JsonResponse { $data = $operatorService->provinceActivity( - info_id: 91, - province_id: $request->input('province_id') + $request, + 91, ); return $this->successResponse([ @@ -41,7 +41,7 @@ class UtilityPassingActivityController extends Controller } public function countryExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse { - $data = $operatorService->countryActivity(91); + $data = $operatorService->countryActivity(91, $request); $name = 'گزارش نگهداری حریم راه برای عبور تاسیسات زیربنایی غیر مجاز ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; return Excel::download(new ExcelReport($data), $name); @@ -50,8 +50,8 @@ class UtilityPassingActivityController extends Controller public function provinceExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse { $data = $operatorService->provinceActivity( - info_id: 91, - province_id: $request->input('province_id') + $request, + 91, ); $name = 'گزارش نگهداری حریم راه برای عبور تاسیسات زیربنایی غیر مجاز ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; diff --git a/app/Http/Controllers/V3/RahdaranController.php b/app/Http/Controllers/V3/RahdaranController.php index a4128cc3..412b7ac3 100644 --- a/app/Http/Controllers/V3/RahdaranController.php +++ b/app/Http/Controllers/V3/RahdaranController.php @@ -7,11 +7,13 @@ use App\Http\Controllers\Controller; use App\Http\Requests\V3\Rahdaran\StoreRequest; use App\Http\Requests\V3\Rahdaran\UpdateRequest; use App\Http\Traits\ApiResponse; +use App\Models\EdarateShahri; use App\Models\Province; use App\Models\Rahdaran; use Illuminate\Database\QueryException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; class RahdaranController extends Controller { @@ -19,8 +21,16 @@ class RahdaranController extends Controller public function index(Request $request): JsonResponse { + $user = Auth::user(); + $query = $user->hasPermissionTo('manage-rahdaran-country') ? + Rahdaran::query() : + ($user->hasPermissionTo('manage-rahdaran-province') ? + Rahdaran::query()->where('province_id', '=', $user->province_id) : + Rahdaran::query()->where('edareh_shahri_id', '=', $user->edarate_shahri_id) + ); + return response()->json(DataTableFacade::run( - Rahdaran::query(), + $query, $request, allowedFilters: ['*'], allowedSortings: ['*']) @@ -30,6 +40,7 @@ class RahdaranController extends Controller public function store(StoreRequest $request): JsonResponse { $province = Province::query()->find($request->input('province_id')); + $edareh = EdarateShahri::query()->find($request->input('edareh_shahri_id')); Rahdaran::query()->create([ 'name' => $request->name, @@ -38,6 +49,8 @@ class RahdaranController extends Controller 'province_id' => $province->id, 'province_name' => $province->name_fa, 'edareh_shahri_id' => $request->edareh_shahri_id, + 'edareh_shahri_name' => $edareh->name_fa, + 'is_driver' => $request->is_driver, ]); return $this->successResponse(); @@ -51,6 +64,7 @@ class RahdaranController extends Controller public function update(UpdateRequest $request, Rahdaran $rahdaran): JsonResponse { $province = Province::query()->find($request->input('province_id')); + $edareh = EdarateShahri::query()->find($request->input('edareh_shahri_id')); $rahdaran->update([ 'name' =>$request->name, @@ -59,6 +73,8 @@ class RahdaranController extends Controller 'province_id' => $province->id, 'province_name' => $province->name_fa, 'edareh_shahri_id' => $request->edareh_shahri_id, + 'edareh_shahri_name' => $edareh->name_fa, + 'is_driver' => $request->is_driver, ]); return $this->successResponse(); diff --git a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php index 345f2505..b38d0da2 100644 --- a/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php +++ b/app/Http/Requests/V3/Mission/RequestPortal/ContinueMissionRequest.php @@ -33,7 +33,6 @@ class ContinueMissionRequest extends FormRequest 'driver' => 'required|integer|exists:rahdaran,id', 'type' => 'required|in:1,2', 'zone' => 'required|in:1,2,3', - 'start_date' => 'required|date', 'end_date' => 'required|date', 'description' => 'string', 'end_point' => 'required|string', diff --git a/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php b/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php index 4c744cba..249d5c36 100644 --- a/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php +++ b/app/Http/Requests/V3/Mission/TransportaionUnit/AllocateRequest.php @@ -25,7 +25,8 @@ class AllocateRequest extends FormRequest return [ 'machines' => 'required|array', 'machines.*' => 'required|integer|exists:cmms_machines,id', - 'driver' => 'required|integer|exists:rahdaran,id' + 'driver' => 'required|integer|exists:rahdaran,id', + 'km' => 'required', ]; } } diff --git a/app/Http/Requests/V3/Rahdaran/StoreRequest.php b/app/Http/Requests/V3/Rahdaran/StoreRequest.php index 8d946ba4..ae925bdf 100644 --- a/app/Http/Requests/V3/Rahdaran/StoreRequest.php +++ b/app/Http/Requests/V3/Rahdaran/StoreRequest.php @@ -28,6 +28,7 @@ class StoreRequest extends FormRequest 'mobile' => 'required|digits:11|regex:/^09\d{9}$/', 'province_id' => 'required|exists:provinces,id', 'edareh_shahri_id' => 'required|exists:edarate_shahri,id', + 'is_driver' => 'required|boolean', ]; } } diff --git a/app/Http/Requests/V3/Rahdaran/UpdateRequest.php b/app/Http/Requests/V3/Rahdaran/UpdateRequest.php index 0f19e72a..20efef51 100644 --- a/app/Http/Requests/V3/Rahdaran/UpdateRequest.php +++ b/app/Http/Requests/V3/Rahdaran/UpdateRequest.php @@ -29,6 +29,7 @@ class UpdateRequest extends FormRequest 'mobile' => 'required|digits:11|regex:/^09\d{9}$/', 'province_id' => 'required|exists:provinces,id', 'edareh_shahri_id' => 'required|exists:edarate_shahri,id', + 'is_driver' => 'required|boolean', ]; } } diff --git a/app/Models/City.php b/app/Models/City.php index 088c475d..43dde894 100644 --- a/app/Models/City.php +++ b/app/Models/City.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\ModelNotFoundException; class City extends Model { @@ -80,4 +81,30 @@ class City extends Model { return $this->belongsToMany('App\Models\EdarateShahri', 'edarate_shahri_be_city')->withPivot('is_primary','id'); } + + public static function findCityWithLatLng($lat, $lng): Model|null + { + try { + $city = City::query() + ->whereRaw(" + ST_Contains( + geometry, + ST_GeomFromText('POINT($lng $lat)', 4326) + ) + ") + ->firstOrFail(); + } + catch (ModelNotFoundException $exception) { + $city = City::query() + ->orderByRaw(" + ST_Distance( + geometry, + ST_GeomFromText('POINT($lng $lat)', 4326) + ) ASC + ") + ->first(); + } + + return $city; + } } diff --git a/app/Services/Cartables/Mission/TransportationUnitService.php b/app/Services/Cartables/Mission/TransportationUnitService.php index 7c5cc186..e0dd71b4 100644 --- a/app/Services/Cartables/Mission/TransportationUnitService.php +++ b/app/Services/Cartables/Mission/TransportationUnitService.php @@ -25,7 +25,7 @@ class TransportationUnitService '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', - 'code', 'category_id', 'category_name', 'explanation' + 'code', 'category_id', 'category_name', 'explanation', 'km' ] ); } diff --git a/app/Services/Cartables/SafetyAndPrivacy/OperatorService.php b/app/Services/Cartables/SafetyAndPrivacy/OperatorService.php index fec10878..ede66264 100644 --- a/app/Services/Cartables/SafetyAndPrivacy/OperatorService.php +++ b/app/Services/Cartables/SafetyAndPrivacy/OperatorService.php @@ -34,8 +34,38 @@ class OperatorService ); } - public function countryActivity(int $info_id): array + public function countryActivity(int $info_id, Request $request): array { + $params = [ + 'infoId' => $info_id, + ]; + + $dateFields = [ + 'created_at', + 'activity_date_time', + 'judiciary_document_upload_date', + 'action_date', + ]; + + + foreach ($dateFields as $field) { + $params["{$field}_from"] = null; + $params["{$field}_to"] = null; + $params["{$field}_from_2"] = null; + $params["{$field}_to_2"] = null; + } + + foreach (json_decode($request->filters, true) as $filter) { + if ($filter['fn'] === "between") + { + $field = $filter['id']; + $params["{$field}_from"] = $filter['value'][0] . ' 00:00:00'; + $params["{$field}_to"] = $filter['value'][1] . ' 23:59:59'; + $params["{$field}_from_2"] = $filter['value'][0] . ' 00:00:00'; + $params["{$field}_to_2"] = $filter['value'][1] . ' 23:59:59'; + } + } + return DB::select(" WITH base AS ( SELECT @@ -51,6 +81,21 @@ class OperatorService ON t.province_id = p.id AND t.axis_type_id = a.id AND t.info_id = :infoId + AND ( + (:created_at_from IS NULL OR :created_at_to IS NULL) + OR t.created_at BETWEEN :created_at_from_2 AND :created_at_to_2) + AND ( + (:activity_date_time_from IS NULL OR :activity_date_time_to IS NULL) + OR t.activity_date_time BETWEEN :activity_date_time_from_2 AND :activity_date_time_to_2 + ) + AND ( + (:judiciary_document_upload_date_from IS NULL OR :judiciary_document_upload_date_to IS NULL) + OR t.judiciary_document_upload_date BETWEEN :judiciary_document_upload_date_from_2 AND :judiciary_document_upload_date_to_2 + ) + AND ( + (:action_date_from IS NULL OR :action_date_to IS NULL) + OR t.action_date BETWEEN :action_date_from_2 AND :action_date_to_2 + ) GROUP BY p.id, a.id ) SELECT @@ -83,13 +128,44 @@ class OperatorService ORDER BY province_id, axis_type_id - ", [ - 'infoId' => $info_id, - ]); + ",$params); } - - public function provinceActivity(int $info_id, int $province_id): array + public function provinceActivity(Request $request, int $info_id): array { + $params = [ + 'infoId' => $info_id, + ]; + + $dateFields = [ + 'created_at', + 'activity_date_time', + 'judiciary_document_upload_date', + 'action_date', + ]; + + + foreach ($dateFields as $field) { + $params["{$field}_from"] = NULL; + $params["{$field}_to"] = NULL; + $params["{$field}_from_2"] = NULL; + $params["{$field}_to_2"] = NULL; + } + + foreach (json_decode($request->filters, true) as $filter) { + if ($filter['fn'] === "between") + { + $field = $filter['id']; + $params["{$field}_from"] = $filter['value'][0] . ' 00:00:00'; + $params["{$field}_to"] = $filter['value'][1] . ' 23:59:59'; + $params["{$field}_from_2"] = $filter['value'][0] . ' 00:00:00'; + $params["{$field}_to_2"] = $filter['value'][1] . ' 23:59:59'; + } + if ($filter['id'] === "province_id") + { + $params["provinceId"] = $filter['value']; + } + } + return DB::select(" WITH edareh_data AS ( SELECT @@ -105,6 +181,21 @@ class OperatorService ON e.id = t.edare_shahri_id AND t.axis_type_id = a.id AND t.info_id = :infoId + AND ( + (:created_at_from IS NULL OR :created_at_to IS NULL) + OR t.created_at BETWEEN :created_at_from_2 AND :created_at_to_2) + AND ( + (:activity_date_time_from IS NULL OR :activity_date_time_to IS NULL) + OR t.activity_date_time BETWEEN :activity_date_time_from_2 AND :activity_date_time_to_2 + ) + AND ( + (:judiciary_document_upload_date_from IS NULL OR :judiciary_document_upload_date_to IS NULL) + OR t.judiciary_document_upload_date BETWEEN :judiciary_document_upload_date_from_2 AND :judiciary_document_upload_date_to_2 + ) + AND ( + (:action_date_from IS NULL OR :action_date_to IS NULL) + OR t.action_date BETWEEN :action_date_from_2 AND :action_date_to_2 + ) WHERE e.province_id = :provinceId GROUP BY e.id, a.id ) @@ -137,9 +228,6 @@ class OperatorService GROUP BY axis_type_id ORDER BY edare_id , axis_type_id - ", [ - 'provinceId' => $province_id, - 'infoId' => $info_id, - ]); + ", $params); } } \ No newline at end of file diff --git a/config/logging.php b/config/logging.php index 3a6fc052..972f7be3 100644 --- a/config/logging.php +++ b/config/logging.php @@ -141,5 +141,11 @@ return [ 'path' => storage_path('logs/mariadb-backup.log'), 'level' => 'info', ], + + 'telescope' => [ + 'driver' => 'single', + 'path' => storage_path('logs/telescope.log'), + 'level' => 'info', + ], ], ]; diff --git a/database/migrations/2025_09_27_094044_add_column_to_rahdaran_table.php b/database/migrations/2025_09_27_094044_add_column_to_rahdaran_table.php index b4ce92f6..b954f770 100644 --- a/database/migrations/2025_09_27_094044_add_column_to_rahdaran_table.php +++ b/database/migrations/2025_09_27_094044_add_column_to_rahdaran_table.php @@ -12,10 +12,10 @@ return new class extends Migration public function up(): void { Schema::table('rahdaran', function (Blueprint $table) { - $table->unsignedTinyInteger('province_id'); + $table->unsignedTinyInteger('province_id')->nullable(); $table->foreign('province_id')->references('id')->on('provinces'); - $table->string('province_name'); - $table->unsignedBigInteger('edareh_shahri_id'); + $table->string('province_name')->nullable(); + $table->unsignedBigInteger('edareh_shahri_id')->nullable(); $table->foreign('edareh_shahri_id')->references('id')->on('edarate_shahri'); $table->boolean('is_driver')->default(false); }); @@ -29,7 +29,7 @@ return new class extends Migration Schema::table('rahdaran', function (Blueprint $table) { $table->dropForeign('province_id'); $table->dropForeign('edareh_shahri_id'); - $table->dropColumn(['province_id', 'province_name']); + $table->dropColumn(['province_id', 'province_name', 'edareh_shahri_id', 'is_driver']); }); } }; diff --git a/database/migrations/2025_10_01_100511_add_edareh_name_to_rahdaran_table.php b/database/migrations/2025_10_01_100511_add_edareh_name_to_rahdaran_table.php new file mode 100644 index 00000000..bc16552f --- /dev/null +++ b/database/migrations/2025_10_01_100511_add_edareh_name_to_rahdaran_table.php @@ -0,0 +1,28 @@ +string('edareh_shahri_name')->nullable()->after('edareh_shahri_id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('rahdaran', function (Blueprint $table) { + $table->dropColumn('edareh_shahri_name'); + }); + } +}; diff --git a/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php index 1109a5e5..4264b38f 100644 --- a/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php +++ b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php @@ -18,7 +18,7 @@ - گزارش کلی خسارات وارده + گزارش کلی خسارات وارد شده @@ -35,6 +35,8 @@ تاریخ تصادف مبلغ کل خسارت مبلغ فاکتور + مبلغ سهم راننده(درصد) + مبلغ سهم راننده(ریال) مبلغ بیمه مبلغ داغی تاریخ ثبت @@ -58,6 +60,8 @@ {{Hekmatinasser\Verta\Verta::instance($item->accident_date)->format('Y/n/j')}} {{$item->accident_time}} {{$item->sum ?? 0}} {{$item->final_amount ?? 0}} + {{$item->dirver_share_amount ?? 0}} + {{$item->driver_rate ?? 0}} {{$item->deposit_insurance_amount ?? 0}} {{$item->deposit_daghi_amount ?? 0}} {{Hekmatinasser\Verta\Verta::instance($item->created_at)->format('Y/n/j')}} diff --git a/routes/v3.php b/routes/v3.php index 7120ef76..338a4cc4 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -185,6 +185,7 @@ Route::prefix('cmms_machines') Route::prefix('rahdaran') ->name('rahdaran.') + ->middleware('permission:manage-rahdaran-province|manage-rahdaran-edareh|manage-rahdaran-country') ->controller(RahdaranController::class) ->group(function () { Route::get('/', 'index')->name('index');