add extra reports #17
31
app/Console/Commands/EncodePolyLineCommand.php
Normal file
31
app/Console/Commands/EncodePolyLineCommand.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\PolylineEncoder;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class EncodePolyLineCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:encode-poly-line-command';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'encode all missions that have poly line';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(PolylineEncoder $polylineEncoder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Mission;
|
||||
|
||||
use App\Enums\CmmsMachineStatus;
|
||||
use App\Enums\FMSResultCode;
|
||||
use App\Enums\MissionStates;
|
||||
use App\Events\V3\Dashboard\Mission\SendDataToFMSEvent;
|
||||
@@ -39,6 +40,10 @@ class ControlUnitController extends Controller
|
||||
// 'previous_state_name' => $mission->state_name,
|
||||
// ]);
|
||||
|
||||
$mission->machine()->update([
|
||||
'status' => CmmsMachineStatus::DAR_MAMORIAT->value
|
||||
]);
|
||||
|
||||
$mission->update([
|
||||
'state_id' => MissionStates::START_MISSION->value,
|
||||
'state_name' => MissionStates::START_MISSION->label(),
|
||||
@@ -62,25 +67,26 @@ class ControlUnitController extends Controller
|
||||
// 'previous_state_name' => $mission->state_name,
|
||||
// ]);
|
||||
|
||||
$mission->update([
|
||||
'state_id' => MissionStates::END_MISSION->value,
|
||||
'state_name' => MissionStates::END_MISSION->label(),
|
||||
'finish_time' => $request->time,
|
||||
'mission_duration' => strtotime($request->time) - strtotime($mission->start_time),
|
||||
'end_km' => $request->end_km,
|
||||
$mission->machine()->update([
|
||||
'status' => CmmsMachineStatus::AMADE->value
|
||||
]);
|
||||
|
||||
// $getErrorRateService->setInputParameters($mission);
|
||||
// $responseData = $getErrorRateService->run();
|
||||
//
|
||||
// $mission->update([
|
||||
|
||||
$mission->update([
|
||||
// 'in_area_duration' => $responseData['timeInAreaSeconds'],
|
||||
// 'first_enter' => $responseData['firstEnter'],
|
||||
// 'last_exit' => $responseData['lastExit'],
|
||||
// 'point_number_sent' => $responseData['noOfPointsInMission'],
|
||||
// 'fms_result_code' => $responseData['resultCode'],
|
||||
// 'fms_result_message' => FMSResultCode::name($responseData['resultCode']),
|
||||
// ]);
|
||||
'state_id' => MissionStates::END_MISSION->value,
|
||||
'state_name' => MissionStates::END_MISSION->label(),
|
||||
'finish_time' => $request->time,
|
||||
'mission_duration' => strtotime($request->time) - strtotime($mission->start_time),
|
||||
'end_km' => $request->end_km,
|
||||
]);
|
||||
});
|
||||
|
||||
// if ($mission->category_id == 2) {
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
namespace App\Http\Controllers\V3\Dashboard\Mission\Report;
|
||||
|
||||
use App\Exports\V3\Mission\Report\Machine\machineReport;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\City;
|
||||
use App\Models\Mission;
|
||||
use App\Models\Province;
|
||||
use App\Services\Cartables\Mission\Report\ReportMachineService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -85,4 +87,18 @@ class ReportMachineController extends Controller
|
||||
// ->get(['id', 'name_fa'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function machineDetailsReport(Request $request)
|
||||
{
|
||||
return DataTableFacade::run(
|
||||
Mission::query()->where('machine_id', '=', $request->query('machine_id')),
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
allowedSelects: [
|
||||
'id', 'province_id', 'province_name', 'city_id', 'city_name',
|
||||
'end_km', 'km', 'driver_name', 'state_name',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,13 @@ use App\Enums\FMSResultCode;
|
||||
use App\Enums\MissionCategory;
|
||||
use App\Enums\MissionStates;
|
||||
use App\Enums\MissionTypes;
|
||||
use App\Enums\MissionViolationStatus;
|
||||
use App\Enums\MissionZones;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\V3\Dashboard\RoadPatrol\OperatorController;
|
||||
use App\Http\Requests\V3\Mission\RequestPortal\ChangeStateRequest;
|
||||
use App\Http\Requests\V3\Mission\RequestPortal\ClarifyUnauthorizedExitRequest;
|
||||
use App\Http\Requests\V3\Mission\RequestPortal\ContinueMissionRequest;
|
||||
use App\Http\Requests\V3\Mission\RequestPortal\NoProcessRequest;
|
||||
use App\Http\Requests\V3\Mission\RequestPortal\StoreRequest;
|
||||
@@ -17,6 +20,7 @@ use App\Http\Requests\V3\Mission\RequestPortal\UpdateRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\CMMSMachine;
|
||||
use App\Models\Mission;
|
||||
use App\Models\MissionViolation;
|
||||
use App\Models\Rahdaran;
|
||||
use App\Models\RahdariPoint;
|
||||
use App\Models\RoadObserved;
|
||||
@@ -37,6 +41,21 @@ class RequestPortalController extends Controller
|
||||
return response()->json($requestPortalService->datatable($request));
|
||||
}
|
||||
|
||||
public function violations(Request $request): JsonResponse
|
||||
{
|
||||
$query = MissionViolation::query()->where([
|
||||
['status', '=', MissionViolationStatus::BEDON_EGHDAM->value],
|
||||
['station_id', '=', auth()->user()->station_id]
|
||||
]);
|
||||
|
||||
return DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
@@ -203,10 +222,73 @@ class RequestPortalController extends Controller
|
||||
public function changeState(ChangeStateRequest $request, Mission $mission): JsonResponse
|
||||
{
|
||||
$mission->update([
|
||||
'state' => $request->state_id,
|
||||
'state_name' => MissionStates::name($request->status_id),
|
||||
'state_id' => $request->state_id,
|
||||
'state_name' => MissionStates::name($request->state_id),
|
||||
]);
|
||||
|
||||
return $this->successResponse($mission);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function clarifyUnauthorizedExit(ClarifyUnauthorizedExitRequest $request, MissionViolation $violation): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $violation) {
|
||||
|
||||
$start = Carbon::parse($violation->exit_station);
|
||||
$end = Carbon::parse($violation->enter_station);
|
||||
$type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value;
|
||||
$user = auth()->user();
|
||||
$zone = $request->zone;
|
||||
$machine = CMMSMachine::query()->where('machine_code', '=', $violation->machine_code)->first(['id', 'machine_code']);
|
||||
|
||||
$mission = Mission::query()->create([
|
||||
'user_id' => $user->id,
|
||||
'username' => $user->username,
|
||||
'province_id' => $user->province_id,
|
||||
'province_name' => $user->province_fa,
|
||||
'city_id' => $user->city_id ?? null,
|
||||
'city_name' => $user->city_fa ?? null,
|
||||
'edare_shahri_id' => $user->edarate_shahri_id ?? null,
|
||||
'edare_shahri_name' => $user->edarate_shahri_name ?? null,
|
||||
'zone' => $zone,
|
||||
'zone_fa' => MissionZones::name($zone),
|
||||
'encoded_route' => $request->encoded_route,
|
||||
'type' => $type,
|
||||
'type_fa' => MissionTypes::name($type),
|
||||
'start_date' => $violation->exit_station,
|
||||
'end_date' => $violation->enter_station,
|
||||
'end_point' => $request->end_point,
|
||||
'category_id' => $request->category_id,
|
||||
'category_name' => MissionCategory::name($request->category_id),
|
||||
'start_time' => $violation->exit_station,
|
||||
'finish_time' => $violation->enter_station,
|
||||
'mission_duration' => strtotime($violation->enter_station) - strtotime($violation->exit_station),
|
||||
'state_id' => MissionStates::END_MISSION->value,
|
||||
'state_name' => MissionStates::END_MISSION->label(),
|
||||
'explanation' => $request->explanation,
|
||||
'request_date' => now(),
|
||||
'machine_id' => $machine->id,
|
||||
'machine_code' => $machine->machine_code,
|
||||
'requested_machines' => $machine->car_type,
|
||||
'station_id' => $user->station_id,
|
||||
'station_name' => RahdariPoint::query()->find($user->station_id)->name,
|
||||
'km' => $violation->km ?? null,
|
||||
'driver_id' => $request->driver,
|
||||
'driver_name' => Rahdaran::query()->find($request->driver)->name,
|
||||
]);
|
||||
|
||||
$mission->rahdaran()->sync($request->rahdaran);
|
||||
|
||||
$violation->update(['status' => 1]);
|
||||
|
||||
// if ($mission->category_id == 2) {
|
||||
// $rpc = new OperatorController;
|
||||
// $rpc->store($mission);
|
||||
// }
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ class TransportationUnitController extends Controller
|
||||
'driver_id' => $request->driver_id,
|
||||
'driver_name' => Rahdaran::query()->find($request->driver)->name,
|
||||
]);
|
||||
|
||||
$machine->update([
|
||||
'status' => CmmsMachineStatus::RESERVE->value
|
||||
]);
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
@@ -71,6 +75,10 @@ class TransportationUnitController extends Controller
|
||||
|
||||
$state = MissionStates::REJECT_BY_TRANSPORTATION->value;
|
||||
|
||||
$mission->machine()->update([
|
||||
'status' => CmmsMachineStatus::AMADE->value
|
||||
]);
|
||||
|
||||
$mission->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => MissionStates::name($state),
|
||||
|
||||
@@ -36,67 +36,6 @@ class ViolationManagementController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function noProcess(NoProcessRequest $request, MissionViolation $violation): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $violation) {
|
||||
|
||||
$start = Carbon::parse($violation->exit_station);
|
||||
$end = Carbon::parse($violation->enter_station);
|
||||
$type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value;
|
||||
$user = auth()->user();
|
||||
$zone = $request->zone;
|
||||
$machine = CMMSMachine::query()->where('machine_code', '=', $violation->machine_code)->first(['id', 'machine_code']);
|
||||
|
||||
$mission = Mission::query()->create([
|
||||
'user_id' => $user->id,
|
||||
'username' => $user->username,
|
||||
'province_id' => $user->province_id,
|
||||
'province_name' => $user->province_fa,
|
||||
'city_id' => $user->city_id ?? null,
|
||||
'city_name' => $user->city_fa ?? null,
|
||||
'edare_shahri_id' => $user->edarate_shahri_id ?? null,
|
||||
'edare_shahri_name' => $user->edarate_shahri_name ?? null,
|
||||
'zone' => $zone,
|
||||
'zone_fa' => MissionZones::name($zone),
|
||||
'encoded_route' => $request->encoded_route,
|
||||
'type' => $type,
|
||||
'type_fa' => MissionTypes::name($type),
|
||||
'start_date' => $violation->exit_station,
|
||||
'end_date' => $violation->enter_station,
|
||||
'end_point' => $request->end_point,
|
||||
'category_id' => $request->category_id,
|
||||
'category_name' => MissionCategory::name($request->category_id),
|
||||
'start_time' => $violation->exit_station,
|
||||
'finish_time' => $violation->enter_station,
|
||||
'mission_duration' => strtotime($violation->enter_station) - strtotime($violation->exit_station),
|
||||
'state_id' => MissionStates::END_MISSION->value,
|
||||
'state_name' => MissionStates::END_MISSION->label(),
|
||||
'explanation' => $request->explanation,
|
||||
'request_date' => now(),
|
||||
'machine_id' => $machine->id,
|
||||
'machine_code' => $machine->machine_code,
|
||||
'station_id' => $user->station_id,
|
||||
'station_name' => RahdariPoint::query()->find( $user->station_id)->name,
|
||||
'km' => $violation->km ?? null,
|
||||
'driver_id' => $request->driver,
|
||||
'driver_name' => Rahdaran::query()->find($request->driver)->name,
|
||||
]);
|
||||
|
||||
$mission->rahdaran()->sync($request->rahdaran);
|
||||
|
||||
$violation->update(['status' => 1]);
|
||||
|
||||
// if ($mission->category_id == 2) {
|
||||
// $rpc = new OperatorController;
|
||||
// $rpc->store($mission);
|
||||
// }
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
public function store(StoreRequest $request): JsonResponse
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\Mission\RequestPortal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class ClarifyUnauthorizedExitRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->violation->status === 0 && $this->violation->type === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'end_point' => 'required|string',
|
||||
'encoded_route' => 'required|string',
|
||||
'category_id' => 'required|in:1,2,3',
|
||||
'explanation' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,8 @@ class AllocateRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->mission->edare_shahri_id == auth()->user()->edarate_shahri_id && $this->mission->state_id == MissionStates::REQUEST_CREATED->value
|
||||
|| $this->user()?->username === 'witel';
|
||||
return $this->mission->station_id == auth()->user()->station_id && $this->mission->state_id == MissionStates::REQUEST_CREATED->value
|
||||
|| auth()->user()->username === 'witel';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,9 +13,9 @@ class DeallocateRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->mission->edare_shahri_id == auth()->user()->edarate_shahri_id &&
|
||||
return $this->mission->station_id == auth()->user()->station_id &&
|
||||
in_array($this->mission->state_id, [MissionStates::REQUEST_CREATED->value, MissionStates::PENDING_CONFIRMATION->value])
|
||||
|| $this->user()?->username === 'witel';
|
||||
|| auth()->user()->username === 'witel';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,7 +30,7 @@ class NoProcessRequest extends FormRequest
|
||||
'driver' => 'required|integer|exists:rahdaran,id',
|
||||
'zone' => 'required|in:1,2,3',
|
||||
'end_point' => 'required|string',
|
||||
'encoded_route' => 'required|string',
|
||||
// 'encoded_route' => 'required|string',
|
||||
'category_id' => 'required|in:1,2,3',
|
||||
'explanation' => 'required|string',
|
||||
];
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services\Cartables\Mission;
|
||||
|
||||
use App\Enums\MissionViolationStatus;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\MissionViolation;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -13,7 +14,8 @@ class DailyMoveMachineService
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$query = MissionViolation::query()->with('machine:id,car_name');
|
||||
$query = MissionViolation::query()->with('machine:id,car_name')
|
||||
->where('mission_violations.status', '=', MissionViolationStatus::SABT_SHODE->value);
|
||||
|
||||
if ($user->hasPermissionTo('manage-violation-station')) {
|
||||
$query->whereRelation('machine', 'station_id', '=', $user->station_id);
|
||||
|
||||
@@ -24,7 +24,7 @@ return new class extends Migration
|
||||
$table->unsignedBigInteger('edare_shahri_id')->nullable();
|
||||
$table->foreign('edare_shahri_id')->references('id')->on('edarate_shahri')->noActionOnDelete();
|
||||
$table->string('edare_shahri_name')->nullable();
|
||||
$table->json('requested_machines');
|
||||
$table->json('requested_machines')->nullable();
|
||||
$table->string('type');
|
||||
$table->dateTime('start_date');
|
||||
$table->dateTime('end_date');
|
||||
|
||||
@@ -12,7 +12,7 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('missions', function (Blueprint $table) {
|
||||
$table->json('area');
|
||||
$table->json('area')->nullable();
|
||||
$table->integer('zone');
|
||||
$table->string('zone_fa');
|
||||
$table->string('type_fa');
|
||||
|
||||
@@ -14,6 +14,8 @@ return new class extends Migration
|
||||
Schema::table('mission_violations', function (Blueprint $table) {
|
||||
$table->dateTime('exit_station')->nullable();
|
||||
$table->dateTime('enter_station')->nullable();
|
||||
$table->unsignedInteger('station_id')->nullable();
|
||||
$table->string('station_name')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -493,13 +493,14 @@ Route::prefix('missions')
|
||||
->controller(RequestPortalController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::get('/violations', 'violations')->name('violations');
|
||||
Route::post('/', 'store')->name('store');
|
||||
Route::post('/no_process','noProcess')->name('noProcess');
|
||||
Route::post('/clarifyUnauthorizedExit/{violation}','clarifyUnauthorizedExit')->name('clarifyUnauthorizedExit');
|
||||
Route::post('/continue/{mission}','continueMission')->name('continueMission');
|
||||
Route::get('/{mission}', 'show')->name('show');
|
||||
Route::post('/{mission}', 'update')->name('update');
|
||||
Route::delete('/{mission}', 'destroy')->name('destroy');
|
||||
Route::post('/change_state/{mission}', 'changeState')->name('changeState');
|
||||
Route::post('/change_state/{mission}', 'changeState')->name('changeState')->middleware('permission:mission-change-state');
|
||||
});
|
||||
Route::name('transportationUnit.')
|
||||
->prefix('transportation_unit')
|
||||
@@ -534,7 +535,6 @@ Route::prefix('missions')
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::post('/', 'store')->name('store');
|
||||
Route::post('/no_process/{violation}','noProcess')->name('noProcess');
|
||||
Route::get('/{violation}', 'show')->name('show');
|
||||
Route::post('/{violation}', 'update')->name('update');
|
||||
Route::delete('/{violation}', 'destroy')->name('destroy');
|
||||
@@ -565,11 +565,12 @@ Route::prefix('missions')
|
||||
->controller(ReportMachineController::class)
|
||||
->group(function () {
|
||||
Route::get('/country_machines_activity', 'countryMachinesActivity')->name('countryMachinesActivity');
|
||||
Route::get('/country_machines_activity', 'countryMachinesActivityExcel')->name('countryMachinesActivityExcel');
|
||||
Route::get('/country_machines_activity_excel', 'countryMachinesActivityExcel')->name('countryMachinesActivityExcel');
|
||||
Route::get('/province_machines_activity', 'provinceMachinesActivity')->name('provinceMachinesActivity');
|
||||
Route::get('/province_machines_activity', 'provinceMachinesActivityExcel')->name('provinceMachinesActivityExcel');
|
||||
Route::get('/province_machines_activity_excel', 'provinceMachinesActivityExcel')->name('provinceMachinesActivityExcel');
|
||||
Route::get('/country_machine_types_activity', 'countryMachineTypesActivity')->name('countryMachineTypesActivity');
|
||||
Route::get('/province_machine_types_activity', 'provinceMachineTypesActivity')->name('provinceMachineTypesActivity');
|
||||
Route::get('/machine_details_report', 'machineDetailsReport')->name('machineDetailsReport');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user