Merge pull request #64 from witelgroup/develop

Develop
This commit is contained in:
Amir Ghasempoor
2025-10-12 13:55:45 +03:30
committed by GitHub
22 changed files with 323 additions and 159 deletions

View File

@@ -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}");

View File

@@ -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, '<Document');
$y = strpos($result, '</Document');
$q = intval($y) - intval($x) + 18;
if ($x !== false and $y !== false) {
$final_data = substr($result, $x, $q);
$xml = simplexml_load_string($final_data);
$result = serialize($result);
$x = strpos($result, '<Document');
$y = strpos($result, '</Document');
$q = intval($y) - intval($x) + 18;
if ($x !== false and $y !== false) {
$final_data = substr($result, $x, $q);
$xml = simplexml_load_string($final_data);
$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;
}
$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;
}
}

View File

@@ -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'));
}
/**

View File

@@ -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];
}

View File

@@ -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('مبالغ داغی و بیمه از مبلغ کل بیشتر می باشد.'));

View File

@@ -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,

View File

@@ -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);

View File

@@ -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';

View File

@@ -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';

View File

@@ -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();

View File

@@ -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',

View File

@@ -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',
];
}
}

View File

@@ -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',
];
}
}

View File

@@ -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',
];
}
}

View File

@@ -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;
}
}

View File

@@ -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'
]
);
}

View File

@@ -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);
}
}

View File

@@ -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',
],
],
];

View File

@@ -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']);
});
}
};

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('rahdaran', function (Blueprint $table) {
$table->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');
});
}
};

View File

@@ -18,7 +18,7 @@
<th colspan="17" style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;"></th>
</tr>
<tr>
<th colspan="17" style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13px;">گزارش کلی خسارات وارده</th>
<th colspan="17" style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13px;">گزارش کلی خسارات وارد شده</th>
</tr>
<tr>
@@ -35,6 +35,8 @@
<th style="border: 1px solid black;text-align: center;background-color: #EBF1DE;">تاریخ تصادف</th>
<th style="border: 1px solid black;text-align: center;background-color: #EBF1DE;">مبلغ کل خسارت</th>
<th style="border: 1px solid black;text-align: center;background-color: #EBF1DE;">مبلغ فاکتور</th>
<th style="border: 1px solid black;text-align: center;background-color: #EBF1DE;">مبلغ سهم راننده(درصد)</th>
<th style="border: 1px solid black;text-align: center;background-color: #EBF1DE;">مبلغ سهم راننده(ریال)</th>
<th style="border: 1px solid black;text-align: center;background-color: #EBF1DE;">مبلغ بیمه</th>
<th style="border: 1px solid black;text-align: center;background-color: #EBF1DE;">مبلغ داغی</th>
<th style="border: 1px solid black;text-align: center;background-color: #EBF1DE;">تاریخ ثبت</th>
@@ -58,6 +60,8 @@
<td style="border: 1px solid black;text-align: center;">{{Hekmatinasser\Verta\Verta::instance($item->accident_date)->format('Y/n/j')}} {{$item->accident_time}}</td>
<td style="border: 1px solid black;text-align: center;">{{$item->sum ?? 0}}</td>
<td style="border: 1px solid black;text-align: center;">{{$item->final_amount ?? 0}}</td>
<td style="border: 1px solid black;text-align: center;">{{$item->dirver_share_amount ?? 0}}</td>
<td style="border: 1px solid black;text-align: center;">{{$item->driver_rate ?? 0}}</td>
<td style="border: 1px solid black;text-align: center;">{{$item->deposit_insurance_amount ?? 0}}</td>
<td style="border: 1px solid black;text-align: center;">{{$item->deposit_daghi_amount ?? 0}}</td>
<td style="border: 1px solid black;text-align: center;">{{Hekmatinasser\Verta\Verta::instance($item->created_at)->format('Y/n/j')}}</td>

View File

@@ -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');