Merge pull request 'add report for machines' (#13) from feature/MissionMachinesReport into develop
Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
@@ -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 => 'ماموریت بدون فرایند ثبت شد',
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -39,10 +39,9 @@ class ControlUnitController extends Controller
|
|||||||
// '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,
|
||||||
]);
|
]);
|
||||||
@@ -63,11 +62,9 @@ class ControlUnitController extends Controller
|
|||||||
// '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'])
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,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;
|
||||||
@@ -44,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,
|
||||||
@@ -56,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),
|
||||||
@@ -69,12 +67,12 @@ class RequestPortalController extends Controller
|
|||||||
'description' => $request->description,
|
'description' => $request->description,
|
||||||
'end_point' => $request->end_point,
|
'end_point' => $request->end_point,
|
||||||
'area' => json_encode($request->area),
|
'area' => json_encode($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,
|
||||||
'station_name' => RahdariPoint::query()->find( $user->station_id)->name,
|
'station_name' => RahdariPoint::query()->find($user->station_id)->name,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$mission->rahdaran()->sync($request->rahdaran);
|
$mission->rahdaran()->sync($request->rahdaran);
|
||||||
@@ -96,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([
|
||||||
@@ -132,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,
|
||||||
@@ -144,18 +137,19 @@ class RequestPortalController extends Controller
|
|||||||
'description' => $request->description,
|
'description' => $request->description,
|
||||||
'end_point' => $request->end_point,
|
'end_point' => $request->end_point,
|
||||||
'area' => json_encode($request->area),
|
'area' => json_encode($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();
|
||||||
@@ -206,75 +200,6 @@ class RequestPortalController extends Controller
|
|||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Throwable
|
|
||||||
*/
|
|
||||||
public function noProcess(NoProcessRequest $request, GetErrorRateService $getErrorRateService): JsonResponse
|
|
||||||
{
|
|
||||||
DB::transaction(function () use ($request, $getErrorRateService) {
|
|
||||||
$start = Carbon::parse($request->start_date);
|
|
||||||
$end = Carbon::parse($request->end_date);
|
|
||||||
$type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value;
|
|
||||||
$user = auth()->user();
|
|
||||||
$zone = $request->zone;
|
|
||||||
$state = MissionStates::END_MISSION->value;
|
|
||||||
$machine = CMMSMachine::query()->where('machine_code', '=', $request->machine_code)->first(['id', 'machine_code']);
|
|
||||||
|
|
||||||
$mission = Mission::query()->create([
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'username' => $user->username,
|
|
||||||
'province_id' => $user->province_id,
|
|
||||||
'province_name' => $user->province_fa,
|
|
||||||
'city_id' => $user->city_id ?? null,
|
|
||||||
'city_name' => $user->city_fa ?? null,
|
|
||||||
'edare_shahri_id' => $user->edarate_shahri_id ?? null,
|
|
||||||
'edare_shahri_name' => $user->edarate_shahri_name ?? null,
|
|
||||||
'zone' => $zone,
|
|
||||||
'zone_fa' => MissionZones::name($zone),
|
|
||||||
'type' => $type,
|
|
||||||
'type_fa' => MissionTypes::name($type),
|
|
||||||
'start_date' => $request->start_date,
|
|
||||||
'area' => json_encode($request->area),
|
|
||||||
'end_date' => $request->end_date,
|
|
||||||
'end_point' => $request->end_point,
|
|
||||||
'category_id' => $request->category_id,
|
|
||||||
'category_name' => MissionCategory::name($request->category_id),
|
|
||||||
'start_time' => $request->start_date,
|
|
||||||
'finish_time' => $request->end_date,
|
|
||||||
'state_id' => $state,
|
|
||||||
'state_name' => MissionStates::name($state),
|
|
||||||
'explanation' => $request->explanation,
|
|
||||||
'request_date' => now(),
|
|
||||||
'machine_id' => $machine->id,
|
|
||||||
'machine_code' => $machine->machine_code,
|
|
||||||
'station_id' => $user->station_id,
|
|
||||||
'station_name' => RahdariPoint::query()->find( $user->station_id)->name,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$mission->rahdaran()->sync($request->rahdaran);
|
|
||||||
$mission->rahdaran()->attach($request->driver, ['is_driver' => true]);
|
|
||||||
|
|
||||||
$getErrorRateService->setInputParameters($mission);
|
|
||||||
$responseData = $getErrorRateService->run();
|
|
||||||
|
|
||||||
$mission->update([
|
|
||||||
'in_area_duration' => $responseData['timeInAreaSeconds'],
|
|
||||||
'first_enter' => $responseData['firstEnter'],
|
|
||||||
'last_exit' => $responseData['lastExit'],
|
|
||||||
'point_number_sent' => $responseData['noOfPointsInMission'],
|
|
||||||
'fms_result_code' => $responseData['resultCode'],
|
|
||||||
'fms_result_message' => FMSResultCode::name($responseData['resultCode']),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// if ($mission->category_id == 2) {
|
|
||||||
// $rpc = new OperatorController;
|
|
||||||
// $rpc->store($mission);
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this->successResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function changeState(ChangeStateRequest $request, Mission $mission): JsonResponse
|
public function changeState(ChangeStateRequest $request, Mission $mission): JsonResponse
|
||||||
{
|
{
|
||||||
$mission->update([
|
$mission->update([
|
||||||
|
|||||||
@@ -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,7 +32,6 @@ 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,
|
||||||
@@ -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,7 +61,6 @@ 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,
|
||||||
@@ -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([
|
||||||
@@ -70,8 +70,8 @@ class ViolationManagementController extends Controller
|
|||||||
'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,
|
||||||
@@ -79,10 +79,11 @@ class ViolationManagementController extends Controller
|
|||||||
'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]);
|
||||||
|
|
||||||
@@ -135,5 +136,4 @@ class ViolationManagementController extends Controller
|
|||||||
$violation->delete();
|
$violation->delete();
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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' => 'تاریخ پایان نباید قبل از تاریخ شروع باشد.',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -50,21 +50,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 +60,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,
|
FROM missions m
|
||||||
(SUM(m.end_km)-SUM(m.km)) AS distance
|
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
|
||||||
FROM missions m
|
GROUP BY machine_id;";
|
||||||
WHERE m.machine_code = :machineCode
|
|
||||||
AND m.created_at >= :from
|
|
||||||
AND m.created_at <= :to;
|
|
||||||
";
|
|
||||||
|
|
||||||
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,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -564,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