Compare commits
11 Commits
feature/Ma
...
5d2a6d045b
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d2a6d045b | |||
| eeff2861e5 | |||
| 6ae3fd3d90 | |||
| 6b81075e40 | |||
| 235111ee57 | |||
| ccacb2f916 | |||
| aeb58ed27f | |||
| a8b99706d0 | |||
| 92cf157b29 | |||
| 5004b99d03 | |||
| 2f3ebf5808 |
@@ -18,7 +18,7 @@ enum CmmsMachineStatus: int
|
|||||||
self::AMADE => 'آماده',
|
self::AMADE => 'آماده',
|
||||||
self::RESERVE => 'رزرو',
|
self::RESERVE => 'رزرو',
|
||||||
self::DAR_MAMORIAT => 'در ماموریت',
|
self::DAR_MAMORIAT => 'در ماموریت',
|
||||||
self::KHAREGE_AZ_RADE => 'خارج از محدوده',
|
self::KHAREGE_AZ_RADE => 'خارج از رده',
|
||||||
self::DAR_TAMIR => 'در تعمیر',
|
self::DAR_TAMIR => 'در تعمیر',
|
||||||
self::FOROKHTEH_SHODE => ' فروخته شده',
|
self::FOROKHTEH_SHODE => ' فروخته شده',
|
||||||
self::NIZE_BE_TAMIR => 'نیاز به تعمیر',
|
self::NIZE_BE_TAMIR => 'نیاز به تعمیر',
|
||||||
|
|||||||
@@ -26,4 +26,17 @@ enum MissionStates: int
|
|||||||
|
|
||||||
return $mapArray[$state];
|
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 => 'ماموریت بدون فرایند ثبت شد',
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,16 +2,20 @@
|
|||||||
|
|
||||||
namespace App\Enums;
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use function Symfony\Component\String\s;
|
||||||
|
|
||||||
enum MissionViolationStatus: int
|
enum MissionViolationStatus: int
|
||||||
{
|
{
|
||||||
case BEDON_EGHDAM = 0;
|
case BEDON_EGHDAM = 0;
|
||||||
case EGHDAM_SHODE = 1;
|
case EGHDAM_SHODE = 1;
|
||||||
|
case SABT_SHODE = 2;
|
||||||
|
|
||||||
public function label(): string
|
public function label(): string
|
||||||
{
|
{
|
||||||
return match ($this) {
|
return match ($this) {
|
||||||
self::BEDON_EGHDAM => "بدون اقدام",
|
self::BEDON_EGHDAM => "بدون اقدام",
|
||||||
self::EGHDAM_SHODE => "اقدام شده",
|
self::EGHDAM_SHODE => "اقدام شده",
|
||||||
|
self::SABT_SHODE => "ثبت شده توسط حراست"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\V3;
|
|||||||
|
|
||||||
use App\Facades\DataTable\DataTableFacade;
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\V3\CMMSMachine\UpdateRequest;
|
||||||
use App\Http\Traits\ApiResponse;
|
use App\Http\Traits\ApiResponse;
|
||||||
use App\Models\CMMSMachine;
|
use App\Models\CMMSMachine;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
@@ -48,4 +49,16 @@ class CMMSMachinesController extends Controller
|
|||||||
->distinct()
|
->distinct()
|
||||||
->pluck('car_type');
|
->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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,16 +33,15 @@ class ControlUnitController extends Controller
|
|||||||
public function start(StartRequest $request, Mission $mission): JsonResponse
|
public function start(StartRequest $request, Mission $mission): JsonResponse
|
||||||
{
|
{
|
||||||
DB::transaction(function () use ($mission, $request) {
|
DB::transaction(function () use ($mission, $request) {
|
||||||
$mission->histories()->create([
|
// $mission->histories()->create([
|
||||||
'user_id' => auth()->user()->id,
|
// 'user_id' => auth()->user()->id,
|
||||||
'previous_state_id' => $mission->state_id,
|
// 'previous_state_id' => $mission->state_id,
|
||||||
'previous_state_name' => $mission->state_name,
|
// 'previous_state_name' => $mission->state_name,
|
||||||
]);
|
// ]);
|
||||||
|
|
||||||
$state = MissionStates::START_MISSION->value;
|
|
||||||
$mission->update([
|
$mission->update([
|
||||||
'state_id' => $state,
|
'state_id' => MissionStates::START_MISSION->value,
|
||||||
'state_name' => MissionStates::name($state),
|
'state_name' => MissionStates::START_MISSION->label(),
|
||||||
'start_time' => $request->time,
|
'start_time' => $request->time,
|
||||||
'km' => $request->km,
|
'km' => $request->km,
|
||||||
]);
|
]);
|
||||||
@@ -57,17 +56,15 @@ class ControlUnitController extends Controller
|
|||||||
public function finish(FinishRequest $request, Mission $mission, GetErrorRateService $getErrorRateService): JsonResponse
|
public function finish(FinishRequest $request, Mission $mission, GetErrorRateService $getErrorRateService): JsonResponse
|
||||||
{
|
{
|
||||||
DB::transaction(function () use ($mission, $getErrorRateService, $request) {
|
DB::transaction(function () use ($mission, $getErrorRateService, $request) {
|
||||||
$mission->histories()->create([
|
// $mission->histories()->create([
|
||||||
'user_id' => auth()->user()->id,
|
// 'user_id' => auth()->user()->id,
|
||||||
'previous_state_id' => $mission->state_id,
|
// 'previous_state_id' => $mission->state_id,
|
||||||
'previous_state_name' => $mission->state_name,
|
// 'previous_state_name' => $mission->state_name,
|
||||||
]);
|
// ]);
|
||||||
|
|
||||||
$state = MissionStates::END_MISSION->value;
|
|
||||||
|
|
||||||
$mission->update([
|
$mission->update([
|
||||||
'state_id' => $state,
|
'state_id' => MissionStates::END_MISSION->value,
|
||||||
'state_name' => MissionStates::name($state),
|
'state_name' => MissionStates::END_MISSION->label(),
|
||||||
'finish_time' => $request->time,
|
'finish_time' => $request->time,
|
||||||
'mission_duration' => strtotime($request->time) - strtotime($mission->start_time),
|
'mission_duration' => strtotime($request->time) - strtotime($mission->start_time),
|
||||||
'end_km' => $request->end_km,
|
'end_km' => $request->end_km,
|
||||||
@@ -86,10 +83,10 @@ class ControlUnitController extends Controller
|
|||||||
// ]);
|
// ]);
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($mission->category_id == 2) {
|
// if ($mission->category_id == 2) {
|
||||||
$rpc = new OperatorController;
|
// $rpc = new OperatorController;
|
||||||
$rpc->store($mission);
|
// $rpc->store($mission);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// SendDataToFMSEvent::dispatch($mission);
|
// SendDataToFMSEvent::dispatch($mission);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\V3\Dashboard\Mission\Report;
|
|||||||
use App\Exports\V3\Mission\Report\Machine\machineReport;
|
use App\Exports\V3\Mission\Report\Machine\machineReport;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Traits\ApiResponse;
|
use App\Http\Traits\ApiResponse;
|
||||||
|
use App\Models\City;
|
||||||
use App\Models\Province;
|
use App\Models\Province;
|
||||||
use App\Services\Cartables\Mission\Report\ReportMachineService;
|
use App\Services\Cartables\Mission\Report\ReportMachineService;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
@@ -17,11 +18,11 @@ class ReportMachineController extends Controller
|
|||||||
{
|
{
|
||||||
use ApiResponse;
|
use ApiResponse;
|
||||||
|
|
||||||
public function activity(Request $request, ReportMachineService $reportMachineService): JsonResponse
|
public function countryMachinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse
|
||||||
{
|
{
|
||||||
return $this->successResponse([
|
return $this->successResponse([
|
||||||
'activities' => $reportMachineService->activity($request),
|
'activities' => $reportMachineService->countryMachinesActivity($request),
|
||||||
'provinces' => Province::all(['id', 'name_fa']),
|
// 'provinces' => Province::all(['id', 'name_fa']),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,12 +30,59 @@ class ReportMachineController extends Controller
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\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);
|
$data = $reportMachineService->countryMachinesActivity($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 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'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use App\Enums\MissionTypes;
|
|||||||
use App\Enums\MissionZones;
|
use App\Enums\MissionZones;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Controllers\V3\Dashboard\RoadPatrol\OperatorController;
|
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\ContinueMissionRequest;
|
||||||
use App\Http\Requests\V3\Mission\RequestPortal\NoProcessRequest;
|
use App\Http\Requests\V3\Mission\RequestPortal\NoProcessRequest;
|
||||||
use App\Http\Requests\V3\Mission\RequestPortal\StoreRequest;
|
use App\Http\Requests\V3\Mission\RequestPortal\StoreRequest;
|
||||||
@@ -16,6 +17,7 @@ use App\Http\Requests\V3\Mission\RequestPortal\UpdateRequest;
|
|||||||
use App\Http\Traits\ApiResponse;
|
use App\Http\Traits\ApiResponse;
|
||||||
use App\Models\CMMSMachine;
|
use App\Models\CMMSMachine;
|
||||||
use App\Models\Mission;
|
use App\Models\Mission;
|
||||||
|
use App\Models\Rahdaran;
|
||||||
use App\Models\RahdariPoint;
|
use App\Models\RahdariPoint;
|
||||||
use App\Models\RoadObserved;
|
use App\Models\RoadObserved;
|
||||||
use App\Services\Cartables\Mission\RequestPortalService;
|
use App\Services\Cartables\Mission\RequestPortalService;
|
||||||
@@ -43,9 +45,6 @@ class RequestPortalController extends Controller
|
|||||||
DB::transaction(function () use ($request) {
|
DB::transaction(function () use ($request) {
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
|
||||||
$state = MissionStates::REQUEST_CREATED->value;
|
|
||||||
$category = $request->category_id;
|
|
||||||
|
|
||||||
$mission = Mission::query()->create([
|
$mission = Mission::query()->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'username' => $user->username,
|
'username' => $user->username,
|
||||||
@@ -55,8 +54,8 @@ class RequestPortalController extends Controller
|
|||||||
'city_name' => $user->city_fa ?? null,
|
'city_name' => $user->city_fa ?? null,
|
||||||
'edare_shahri_id' => $user->edarate_shahri_id ?? null,
|
'edare_shahri_id' => $user->edarate_shahri_id ?? null,
|
||||||
'edare_shahri_name' => $user->edarate_shahri_name ?? null,
|
'edare_shahri_name' => $user->edarate_shahri_name ?? null,
|
||||||
'state_id' => $state,
|
'state_id' => MissionStates::REQUEST_CREATED->value,
|
||||||
'state_name' => MissionStates::name($state),
|
'state_name' => MissionStates::REQUEST_CREATED->label(),
|
||||||
'requested_machines' => json_encode($request->requested_machines),
|
'requested_machines' => json_encode($request->requested_machines),
|
||||||
'type' => $request->type,
|
'type' => $request->type,
|
||||||
'type_fa' => MissionTypes::name($request->type),
|
'type_fa' => MissionTypes::name($request->type),
|
||||||
@@ -67,9 +66,9 @@ class RequestPortalController extends Controller
|
|||||||
'request_date' => now(),
|
'request_date' => now(),
|
||||||
'description' => $request->description,
|
'description' => $request->description,
|
||||||
'end_point' => $request->end_point,
|
'end_point' => $request->end_point,
|
||||||
'area' => json_encode($request->area),
|
'area' => $request->area,
|
||||||
'category_id' => $category,
|
'category_id' => $request->category_id,
|
||||||
'category_name' => MissionCategory::name($category),
|
'category_name' => MissionCategory::name($request->category_id),
|
||||||
'explanation' => $request->explanation,
|
'explanation' => $request->explanation,
|
||||||
'code' => rand(100000, 999999),
|
'code' => rand(100000, 999999),
|
||||||
'station_id' => $user->station_id,
|
'station_id' => $user->station_id,
|
||||||
@@ -95,31 +94,26 @@ class RequestPortalController extends Controller
|
|||||||
DB::transaction(function () use ($request, $mission, $getErrorRateService) {
|
DB::transaction(function () use ($request, $mission, $getErrorRateService) {
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
|
||||||
|
// $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']),
|
||||||
'finish_time' => now(),
|
'finish_time' => now(),
|
||||||
'state_id' => MissionStates::END_MISSION->value,
|
'state_id' => MissionStates::END_MISSION->value,
|
||||||
'state_name' => MissionStates::name(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) {
|
// if ($mission->category_id == 2) {
|
||||||
// $rpc = new OperatorController;
|
// $rpc = new OperatorController;
|
||||||
// $rpc->store($mission);
|
// $rpc->store($mission);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
$state = MissionStates::START_MISSION->value;
|
|
||||||
$category = $request->category_id;
|
|
||||||
$machine = CMMSMachine::query()->find($request->machine_id);
|
$machine = CMMSMachine::query()->find($request->machine_id);
|
||||||
|
|
||||||
$newMission = Mission::query()->create([
|
$newMission = Mission::query()->create([
|
||||||
@@ -131,8 +125,8 @@ class RequestPortalController extends Controller
|
|||||||
'city_name' => $user->city_fa ?? null,
|
'city_name' => $user->city_fa ?? null,
|
||||||
'edare_shahri_id' => $user->edarate_shahri_id ?? null,
|
'edare_shahri_id' => $user->edarate_shahri_id ?? null,
|
||||||
'edare_shahri_name' => $user->edarate_shahri_name ?? null,
|
'edare_shahri_name' => $user->edarate_shahri_name ?? null,
|
||||||
'state_id' => $state,
|
'state_id' => MissionStates::START_MISSION->value,
|
||||||
'state_name' => MissionStates::name($state),
|
'state_name' => MissionStates::START_MISSION->label(),
|
||||||
'type' => $request->type,
|
'type' => $request->type,
|
||||||
'type_fa' => MissionTypes::name($request->type),
|
'type_fa' => MissionTypes::name($request->type),
|
||||||
'zone' => $request->zone,
|
'zone' => $request->zone,
|
||||||
@@ -142,19 +136,20 @@ class RequestPortalController extends Controller
|
|||||||
'request_date' => now(),
|
'request_date' => now(),
|
||||||
'description' => $request->description,
|
'description' => $request->description,
|
||||||
'end_point' => $request->end_point,
|
'end_point' => $request->end_point,
|
||||||
'area' => json_encode($request->area),
|
'area' => $request->area,
|
||||||
'category_id' => $category,
|
'category_id' => $request->category_id,
|
||||||
'category_name' => MissionCategory::name($category),
|
'category_name' => MissionCategory::name($request->category_id),
|
||||||
'explanation' => $request->explanation,
|
'explanation' => $request->explanation,
|
||||||
'start_time' => now(),
|
'start_time' => now(),
|
||||||
'machine_id' => $machine->id,
|
'machine_id' => $machine->id,
|
||||||
'machine_code' => $machine->machine_code,
|
'machine_code' => $machine->machine_code,
|
||||||
'station_id' => $user->station_id,
|
'station_id' => $user->station_id,
|
||||||
'station_name' => RahdariPoint::query()->find( $user->station_id)->name,
|
'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()->sync($request->rahdaran);
|
||||||
$newMission->rahdaran()->attach($request->driver, ['is_driver' => true]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
@@ -179,7 +174,7 @@ class RequestPortalController extends Controller
|
|||||||
'end_date' => $request->end_date,
|
'end_date' => $request->end_date,
|
||||||
'description' => $request->description,
|
'description' => $request->description,
|
||||||
'end_point' => $request->end_point,
|
'end_point' => $request->end_point,
|
||||||
'area' => json_encode($request->area),
|
'area' => $request->area,
|
||||||
'category_id' => $request->category_id,
|
'category_id' => $request->category_id,
|
||||||
'category_name' => MissionCategory::name($request->category_id),
|
'category_name' => MissionCategory::name($request->category_id),
|
||||||
'explanation' => $request->explanation,
|
'explanation' => $request->explanation,
|
||||||
@@ -205,72 +200,13 @@ class RequestPortalController extends Controller
|
|||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function changeState(ChangeStateRequest $request, Mission $mission): JsonResponse
|
||||||
* @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([
|
$mission->update([
|
||||||
'in_area_duration' => $responseData['timeInAreaSeconds'],
|
'state' => $request->state_id,
|
||||||
'first_enter' => $responseData['firstEnter'],
|
'state_name' => MissionStates::name($request->status_id),
|
||||||
'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) {
|
return $this->successResponse($mission);
|
||||||
// $rpc = new OperatorController;
|
|
||||||
// $rpc->store($mission);
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this->successResponse();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use App\Http\Requests\V3\Mission\TransportaionUnit\DeallocateRequest;
|
|||||||
use App\Http\Traits\ApiResponse;
|
use App\Http\Traits\ApiResponse;
|
||||||
use App\Models\CMMSMachine;
|
use App\Models\CMMSMachine;
|
||||||
use App\Models\Mission;
|
use App\Models\Mission;
|
||||||
|
use App\Models\Rahdaran;
|
||||||
use App\Services\Cartables\Mission\TransportationUnitService;
|
use App\Services\Cartables\Mission\TransportationUnitService;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -31,13 +32,12 @@ class TransportationUnitController extends Controller
|
|||||||
public function allocate(AllocateRequest $request, Mission $mission): JsonResponse
|
public function allocate(AllocateRequest $request, Mission $mission): JsonResponse
|
||||||
{
|
{
|
||||||
DB::transaction(function () use ($request, $mission) {
|
DB::transaction(function () use ($request, $mission) {
|
||||||
$mission->rahdaran()->attach($request->driver, ['is_driver' => true]);
|
|
||||||
|
|
||||||
$mission->histories()->create([
|
// $mission->histories()->create([
|
||||||
'user_id' => auth()->user()->id,
|
// 'user_id' => auth()->user()->id,
|
||||||
'previous_state_id' => $mission->state_id,
|
// 'previous_state_id' => $mission->state_id,
|
||||||
'previous_state_name' => $mission->state_name,
|
// 'previous_state_name' => $mission->state_name,
|
||||||
]);
|
// ]);
|
||||||
|
|
||||||
$state = MissionStates::PENDING_CONFIRMATION->value;
|
$state = MissionStates::PENDING_CONFIRMATION->value;
|
||||||
$machine = CMMSMachine::query()->find($request->machine_id);
|
$machine = CMMSMachine::query()->find($request->machine_id);
|
||||||
@@ -47,6 +47,8 @@ class TransportationUnitController extends Controller
|
|||||||
'state_name' => MissionStates::name($state),
|
'state_name' => MissionStates::name($state),
|
||||||
'machine_id' => $machine->id,
|
'machine_id' => $machine->id,
|
||||||
'machine_code' => $machine->machine_code,
|
'machine_code' => $machine->machine_code,
|
||||||
|
'driver_id' => $request->driver_id,
|
||||||
|
'driver_name' => Rahdaran::query()->find($request->driver)->name,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -59,14 +61,13 @@ class TransportationUnitController extends Controller
|
|||||||
public function deallocate(DeallocateRequest $request, Mission $mission): JsonResponse
|
public function deallocate(DeallocateRequest $request, Mission $mission): JsonResponse
|
||||||
{
|
{
|
||||||
DB::transaction(function () use ($request, $mission) {
|
DB::transaction(function () use ($request, $mission) {
|
||||||
$mission->rahdaran()->wherePivot('is_driver', '=', true)->detach();
|
|
||||||
|
|
||||||
$mission->histories()->create([
|
// $mission->histories()->create([
|
||||||
'user_id' => auth()->user()->id,
|
// 'user_id' => auth()->user()->id,
|
||||||
'previous_state_id' => $mission->state_id,
|
// 'previous_state_id' => $mission->state_id,
|
||||||
'previous_state_name' => $mission->state_name,
|
// 'previous_state_name' => $mission->state_name,
|
||||||
'user_description' => $request->description,
|
// 'user_description' => $request->description,
|
||||||
]);
|
// ]);
|
||||||
|
|
||||||
$state = MissionStates::REJECT_BY_TRANSPORTATION->value;
|
$state = MissionStates::REJECT_BY_TRANSPORTATION->value;
|
||||||
|
|
||||||
@@ -76,6 +77,8 @@ class TransportationUnitController extends Controller
|
|||||||
'description' => $request->description,
|
'description' => $request->description,
|
||||||
'machine_id' => null,
|
'machine_id' => null,
|
||||||
'machine_code' => null,
|
'machine_code' => null,
|
||||||
|
'driver_id' => null,
|
||||||
|
'driver_name' => null,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use App\Http\Traits\ApiResponse;
|
|||||||
use App\Models\CMMSMachine;
|
use App\Models\CMMSMachine;
|
||||||
use App\Models\Mission;
|
use App\Models\Mission;
|
||||||
use App\Models\MissionViolation;
|
use App\Models\MissionViolation;
|
||||||
|
use App\Models\Rahdaran;
|
||||||
use App\Models\RahdariPoint;
|
use App\Models\RahdariPoint;
|
||||||
use App\Services\Cartables\Mission\DailyMoveMachineService;
|
use App\Services\Cartables\Mission\DailyMoveMachineService;
|
||||||
use Carbon\Carbon;
|
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;
|
$type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value;
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$zone = $request->zone;
|
$zone = $request->zone;
|
||||||
$state = MissionStates::END_MISSION->value;
|
|
||||||
$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']);
|
||||||
|
|
||||||
$mission = Mission::query()->create([
|
$mission = Mission::query()->create([
|
||||||
@@ -61,28 +61,30 @@ class ViolationManagementController extends Controller
|
|||||||
'edare_shahri_name' => $user->edarate_shahri_name ?? null,
|
'edare_shahri_name' => $user->edarate_shahri_name ?? null,
|
||||||
'zone' => $zone,
|
'zone' => $zone,
|
||||||
'zone_fa' => MissionZones::name($zone),
|
'zone_fa' => MissionZones::name($zone),
|
||||||
|
'area' => $request->area,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'type_fa' => MissionTypes::name($type),
|
'type_fa' => MissionTypes::name($type),
|
||||||
'start_date' => $request->start_date,//
|
'start_date' => $request->start_date,
|
||||||
'end_date' => $request->end_date,//
|
'end_date' => $request->end_date,
|
||||||
'end_point' => $request->end_point,
|
'end_point' => $request->end_point,
|
||||||
'category_id' => $request->category_id,
|
'category_id' => $request->category_id,
|
||||||
'category_name' => MissionCategory::name($request->category_id),
|
'category_name' => MissionCategory::name($request->category_id),
|
||||||
'start_time' => $request->start_date,//
|
'start_time' => $request->start_date,
|
||||||
'finish_time' => $request->end_date,//
|
'finish_time' => $request->end_date,
|
||||||
'state_id' => $state,
|
'state_id' => MissionStates::END_MISSION->value,
|
||||||
'state_name' => MissionStates::name($state),
|
'state_name' => MissionStates::END_MISSION->label(),
|
||||||
'explanation' => $request->explanation,
|
'explanation' => $request->explanation,
|
||||||
'request_date' => now(),
|
'request_date' => now(),
|
||||||
'machine_id' => $machine->id,//
|
'machine_id' => $machine->id,
|
||||||
'machine_code' => $machine->machine_code,//
|
'machine_code' => $machine->machine_code,
|
||||||
'station_id' => $user->station_id,
|
'station_id' => $user->station_id,
|
||||||
'station_name' => RahdariPoint::query()->find( $user->station_id)->name,
|
'station_name' => RahdariPoint::query()->find( $user->station_id)->name,
|
||||||
'km' => $violation->km ?? null,
|
'km' => $violation->km ?? null,
|
||||||
|
'driver_id' => $request->driver,
|
||||||
|
'driver_name' => Rahdaran::query()->find($request->driver)->name,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$mission->rahdaran()->sync($request->rahdaran);
|
$mission->rahdaran()->sync($request->rahdaran);
|
||||||
$mission->rahdaran()->attach($request->driver, ['is_driver' => true]);
|
|
||||||
|
|
||||||
$violation->update(['status' => 1]);
|
$violation->update(['status' => 1]);
|
||||||
|
|
||||||
@@ -102,7 +104,7 @@ class ViolationManagementController extends Controller
|
|||||||
'machine_id'=> CMMSMachine::query()->where('machine_code', '=', $request->machine_code)->value('id'),
|
'machine_id'=> CMMSMachine::query()->where('machine_code', '=', $request->machine_code)->value('id'),
|
||||||
'machine_code'=> $request->machine_code,
|
'machine_code'=> $request->machine_code,
|
||||||
'type'=> MissionViolationType::KHOROJ_BEDONE_MOGAVEZ->value,
|
'type'=> MissionViolationType::KHOROJ_BEDONE_MOGAVEZ->value,
|
||||||
'status' => MissionViolationStatus::BEDON_EGHDAM->value,
|
'status' => MissionViolationStatus::SABT_SHODE->value,
|
||||||
'request_date' => now(),
|
'request_date' => now(),
|
||||||
'km' => $request->km,
|
'km' => $request->km,
|
||||||
'gps' => 0,
|
'gps' => 0,
|
||||||
@@ -110,6 +112,9 @@ class ViolationManagementController extends Controller
|
|||||||
'province_name' => $user->province_fa,
|
'province_name' => $user->province_fa,
|
||||||
'city_id' => $user->city_id,
|
'city_id' => $user->city_id,
|
||||||
'city_name' => $user->city_fa,
|
'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();
|
return $this->successResponse();
|
||||||
@@ -124,7 +129,6 @@ class ViolationManagementController extends Controller
|
|||||||
{
|
{
|
||||||
$violation->update([
|
$violation->update([
|
||||||
'enter_time' => $request->enter_time,
|
'enter_time' => $request->enter_time,
|
||||||
'exit_time' => $request->exit_time,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
@@ -135,5 +139,4 @@ class ViolationManagementController extends Controller
|
|||||||
$violation->delete();
|
$violation->delete();
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class RoadMaintenanceStationController extends Controller
|
|||||||
{
|
{
|
||||||
$stations = RahdariPoint::query()
|
$stations = RahdariPoint::query()
|
||||||
->where('city_id', $request->query('city_id'))
|
->where('city_id', $request->query('city_id'))
|
||||||
->get();
|
->get(['id', 'name']);
|
||||||
|
|
||||||
return $this->successResponse($stations);
|
return $this->successResponse($stations);
|
||||||
}
|
}
|
||||||
|
|||||||
33
app/Http/Requests/V3/CMMSMachine/UpdateRequest.php
Normal file
33
app/Http/Requests/V3/CMMSMachine/UpdateRequest.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\V3\CMMSMachine;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class UpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
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',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\V3\Mission\RequestPortal;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class ChangeStateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'state_id' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,12 +35,9 @@ class ContinueMissionRequest extends FormRequest
|
|||||||
'end_date' => 'required|date',
|
'end_date' => 'required|date',
|
||||||
'description' => 'string',
|
'description' => 'string',
|
||||||
'end_point' => 'required|string',
|
'end_point' => 'required|string',
|
||||||
'area' => 'required|array',
|
'area' => 'required|string',
|
||||||
'area.type' => 'required|string',
|
|
||||||
'area.coordinates' => 'required|array',
|
|
||||||
'explanation' => 'required|string',
|
'explanation' => 'required|string',
|
||||||
'category_id' => 'required|in:1,2,3',
|
'category_id' => 'required|in:1,2,3',
|
||||||
'road_observed_id' => 'required_if:category_id,3|exists:road_observeds,id',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests\V3\Mission\RequestPortal;
|
|
||||||
|
|
||||||
use Illuminate\Contracts\Validation\ValidationRule;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
class NoProcessRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*/
|
|
||||||
public function authorize(): bool
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, ValidationRule|array|string>
|
|
||||||
*/
|
|
||||||
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' => 'تاریخ پایان نباید قبل از تاریخ شروع باشد.',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -34,12 +34,9 @@ class StoreRequest extends FormRequest
|
|||||||
'end_date' => 'required|date',
|
'end_date' => 'required|date',
|
||||||
'description' => 'string',
|
'description' => 'string',
|
||||||
'end_point' => 'required|string',
|
'end_point' => 'required|string',
|
||||||
'area' => 'required|array',
|
'area' => 'required|string',
|
||||||
'area.type' => 'required|string',
|
|
||||||
'area.coordinates' => 'required|array',
|
|
||||||
'explanation' => 'required|string',
|
'explanation' => 'required|string',
|
||||||
'category_id' => 'required|in:1,2,3',
|
'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',
|
||||||
|
'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.'
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,12 +35,9 @@ class UpdateRequest extends FormRequest
|
|||||||
'end_date' => 'required|date',
|
'end_date' => 'required|date',
|
||||||
'description' => 'string',
|
'description' => 'string',
|
||||||
'end_point' => 'required|string',
|
'end_point' => 'required|string',
|
||||||
'area' => 'required|array',
|
'area' => 'required|string',
|
||||||
'area.type' => 'required|string',
|
|
||||||
'area.coordinates' => 'required|array',
|
|
||||||
'explanation' => 'required|string',
|
'explanation' => 'required|string',
|
||||||
'category_id' => 'required|in:1,2,3',
|
'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',
|
||||||
|
'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.'
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ class AllocateRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return $this->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';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ class DeallocateRequest extends FormRequest
|
|||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return $this->mission->edare_shahri_id == auth()->user()->edarate_shahri_id &&
|
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';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests\V3\Mission\Violation;
|
namespace App\Http\Requests\V3\Mission\Violation;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Contracts\Validation\ValidationRule;
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Validator;
|
||||||
|
|
||||||
class NoProcessRequest extends FormRequest
|
class NoProcessRequest extends FormRequest
|
||||||
{
|
{
|
||||||
@@ -30,9 +32,7 @@ class NoProcessRequest extends FormRequest
|
|||||||
'start_date' => 'required|date',
|
'start_date' => 'required|date',
|
||||||
'end_date' => 'required|date|after:start_date|before:now',
|
'end_date' => 'required|date|after:start_date|before:now',
|
||||||
'end_point' => 'required|string',
|
'end_point' => 'required|string',
|
||||||
'area' => 'array',
|
'area' => 'required|string',
|
||||||
'area.type' => 'string',
|
|
||||||
'area.coordinates' => 'array',
|
|
||||||
'category_id' => 'required|in:1,2,3',
|
'category_id' => 'required|in:1,2,3',
|
||||||
'explanation' => 'required|string',
|
'explanation' => 'required|string',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class StoreRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'exit_time' => 'required|date',
|
||||||
'machine_code' => 'required',
|
'machine_code' => 'required',
|
||||||
'km'=> 'string',
|
'km'=> 'string',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ class UpdateRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'exit_time' => 'date',
|
'enter_time' => 'required|date',
|
||||||
'enter_time' => 'date',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
public function histories(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(MissionHistory::class);
|
return $this->hasMany(MissionHistory::class);
|
||||||
@@ -50,21 +43,6 @@ class Mission extends Model
|
|||||||
return $this->hasMany(RoadItemsProject::class);
|
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
|
public function rahdaran(): MorphToMany
|
||||||
{
|
{
|
||||||
return $this->morphToMany(Rahdaran::class,
|
return $this->morphToMany(Rahdaran::class,
|
||||||
@@ -75,17 +53,6 @@ class Mission extends Model
|
|||||||
)->withPivot('is_driver');
|
)->withPivot('is_driver');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function roadObserved(): MorphToMany
|
|
||||||
{
|
|
||||||
return $this->morphedByMany(
|
|
||||||
RoadObserved::class,
|
|
||||||
'missionable',
|
|
||||||
'missionables',
|
|
||||||
'mission_id',
|
|
||||||
'missionable_id'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function machine(): BelongsTo
|
public function machine(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(CMMSMachine::class, 'machine_id');
|
return $this->belongsTo(CMMSMachine::class, 'machine_id');
|
||||||
|
|||||||
@@ -10,31 +10,128 @@ use Illuminate\Support\Facades\DB;
|
|||||||
|
|
||||||
class ReportMachineService
|
class ReportMachineService
|
||||||
{
|
{
|
||||||
public function activity(Request $request): array
|
public function countryMachinesActivity(Request $request): array
|
||||||
{
|
{
|
||||||
$code = $request->machine_code;
|
|
||||||
$from = $request->from_date ?? today()->startOfDay();
|
$from = $request->from_date ?? today()->startOfDay();
|
||||||
$to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay();
|
$to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay();
|
||||||
|
|
||||||
$sql = "
|
$sql = "SELECT
|
||||||
SELECT*
|
m.machine_id,
|
||||||
m.city_name AS c.name,
|
m.machine_code,
|
||||||
m.city_id AS c_id,
|
cm.car_name,
|
||||||
m.province_name AS p_name,
|
COUNT(*) AS missions,
|
||||||
m.province_id AS p_id,
|
SUM(m.end_km - m.km) AS func,
|
||||||
COUNT(m.id) As missions,
|
|
||||||
(SUM(m.end_km)-SUM(m.km)) AS distance
|
|
||||||
|
|
||||||
FROM missions m
|
FROM missions m
|
||||||
WHERE m.machine_code = :machineCode
|
JOIN cmms_machines cm ON cm.id = m.machine_id
|
||||||
AND m.created_at >= :from
|
WHERE m.state_id = 4 AND m.start_time >= :from AND m.finish_time <= :to
|
||||||
AND m.created_at <= :to;
|
GROUP BY machine_id;";
|
||||||
";
|
|
||||||
|
|
||||||
return DB::select($sql, [
|
return DB::select($sql, [
|
||||||
'from' => $from,
|
'from' => $from,
|
||||||
'to' => $to,
|
'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,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
88
app/Services/PolylineEncoder.php
Normal file
88
app/Services/PolylineEncoder.php
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PolylineEncoder
|
||||||
|
*
|
||||||
|
* Encodes a list of latitude/longitude coordinates into an encoded polyline string.
|
||||||
|
*
|
||||||
|
* This implementation is compatible with Google's Polyline Algorithm Format:
|
||||||
|
* https://developers.google.com/maps/documentation/utilities/polylinealgorithm
|
||||||
|
*
|
||||||
|
* Example input:
|
||||||
|
* [
|
||||||
|
* [lat, lng],
|
||||||
|
* [lat, lng]
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* or if `$lng_lat_format = true`:
|
||||||
|
* [
|
||||||
|
* [lng, lat],
|
||||||
|
* [lng, lat]
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* @package App\Services
|
||||||
|
*/
|
||||||
|
class PolylineEncoder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Encode an array of coordinates into a polyline string.
|
||||||
|
*
|
||||||
|
* Each coordinate is encoded as a delta from the previous point,
|
||||||
|
* scaled by the given precision factor.
|
||||||
|
*
|
||||||
|
* @param array $coords Array of coordinate pairs:
|
||||||
|
* - default: [lat, lng]
|
||||||
|
* - if $lng_lat_format = true: [lng, lat]
|
||||||
|
* @param int $precision Number of decimal places to preserve (default: 6)
|
||||||
|
* @param bool $lng_lat_format If true, input is treated as [lng, lat] instead of [lat, lng]
|
||||||
|
*
|
||||||
|
* @return string Encoded polyline string
|
||||||
|
*/
|
||||||
|
public function encodePolyline(array $coords, int $precision = 6, bool $lng_lat_format = false): string
|
||||||
|
{
|
||||||
|
$factor = 10 ** $precision;
|
||||||
|
$output = '';
|
||||||
|
$prevLat = 0;
|
||||||
|
$prevLng = 0;
|
||||||
|
|
||||||
|
foreach ($coords as [$a, $b]) {
|
||||||
|
[$lat, $lng] = $lng_lat_format ? [$b, $a] : [$a, $b];
|
||||||
|
|
||||||
|
$output .= $this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?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('missions', function (Blueprint $table) {
|
||||||
|
$table->integer('driver_id')->nullable();
|
||||||
|
$table->string('driver_name')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('missions', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('driver_name','driver_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -186,6 +186,7 @@ Route::prefix('cmms_machines')
|
|||||||
Route::get('/list', 'list')->name('list');
|
Route::get('/list', 'list')->name('list');
|
||||||
Route::get('/search', 'search')->name('search');
|
Route::get('/search', 'search')->name('search');
|
||||||
Route::get('/car_types', 'carTypes')->name('carTypes');
|
Route::get('/car_types', 'carTypes')->name('carTypes');
|
||||||
|
Route::post('/{machine}', 'update')->name('update')->middleware('permission:update-machine');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('rahdaran')
|
Route::prefix('rahdaran')
|
||||||
@@ -498,6 +499,7 @@ Route::prefix('missions')
|
|||||||
Route::get('/{mission}', 'show')->name('show');
|
Route::get('/{mission}', 'show')->name('show');
|
||||||
Route::post('/{mission}', 'update')->name('update');
|
Route::post('/{mission}', 'update')->name('update');
|
||||||
Route::delete('/{mission}', 'destroy')->name('destroy');
|
Route::delete('/{mission}', 'destroy')->name('destroy');
|
||||||
|
Route::post('/change_state/{mission}', 'changeState')->name('changeState');
|
||||||
});
|
});
|
||||||
Route::name('transportationUnit.')
|
Route::name('transportationUnit.')
|
||||||
->prefix('transportation_unit')
|
->prefix('transportation_unit')
|
||||||
@@ -562,8 +564,12 @@ Route::prefix('missions')
|
|||||||
->middleware(['permission:mission-report-province|mission-report-country'])
|
->middleware(['permission:mission-report-province|mission-report-country'])
|
||||||
->controller(ReportMachineController::class)
|
->controller(ReportMachineController::class)
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::get('/activity', 'activity')->name('Activity');
|
Route::get('/country_machines_activity', 'countryMachinesActivity')->name('countryMachinesActivity');
|
||||||
Route::get('/excel_activity', 'excelActivity')->name('ProvinceActivity');
|
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');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user