320 lines
11 KiB
PHP
320 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\V3\Dashboard\Harim;
|
|
|
|
use App\Enums\HarimAction;
|
|
use App\Enums\HarimStates;
|
|
use App\Events\V3\Dashboard\Harim\ConfirmGuaranteeLetterNeedEvent;
|
|
use App\Events\V3\Dashboard\Harim\ConfirmNoRoadAccessNeedEvent;
|
|
use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessEditNeedEvent;
|
|
use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessNeedEvent;
|
|
use App\Events\V3\Dashboard\Harim\RejectRequestEvent;
|
|
use App\Facades\DataTable\DataTableFacade;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\V3\Dashboard\Harim\GeneralManager\ConfirmGuaranteeLetterNeedRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\GeneralManager\ConfirmNoRoadAccessNeedRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\GeneralManager\ConfirmPaymentRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\GeneralManager\ConfirmRoadAccessEditNeedRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\GeneralManager\ConfirmRoadAccessNeedRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\GeneralManager\ReferFileRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\GeneralManager\ReferPaymentRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\GeneralManager\ReferRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\GeneralManager\RejectRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\GeneralManager\ShowRequest;
|
|
use App\Http\Traits\ApiResponse;
|
|
use App\Models\Harim;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
|
|
class GeneralManagerController extends Controller
|
|
{
|
|
use ApiResponse;
|
|
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$query = Harim::query()
|
|
->where('province_id', '=', auth()->user()->province_id);
|
|
|
|
$data = DataTableFacade::run(
|
|
$query,
|
|
$request,
|
|
allowedFilters: ['*'],
|
|
allowedSortings: ['*']
|
|
);
|
|
|
|
return response()->json($data);
|
|
}
|
|
|
|
/**
|
|
* @throws Throwable
|
|
*/
|
|
public function rejectRequest(RejectRequest $request, Harim $harim): JsonResponse
|
|
{
|
|
DB::transaction(function () use ($request, $harim) {
|
|
$action = HarimAction::CONFIRM->value;
|
|
|
|
$harim->histories()->create([
|
|
'expert_id' => auth()->user()->id,
|
|
'previous_state_id' => $harim->state_id,
|
|
'previous_state_name' => $harim->state_name,
|
|
'expert_description' => $request->expert_description,
|
|
'action_id' => $action,
|
|
'action_name' => HarimAction::name($action),
|
|
]);
|
|
|
|
$state = HarimStates::EMKAN_PAZIR_NEMEBASHAD->value;
|
|
|
|
$harim->update([
|
|
'state_id' => $state,
|
|
'state_name' => HarimStates::name($state),
|
|
]);
|
|
|
|
RejectRequestEvent::dispatch($harim);
|
|
});
|
|
|
|
return $this->successResponse();
|
|
}
|
|
|
|
/**
|
|
* @throws Throwable
|
|
*/
|
|
public function referRequest(ReferRequest $request, Harim $harim): JsonResponse
|
|
{
|
|
DB::transaction(function () use ($request, $harim) {
|
|
$action = HarimAction::REFER->value;
|
|
|
|
$harim->histories()->create([
|
|
'expert_id' => auth()->user()->id,
|
|
'previous-state_id' => $harim->state_id,
|
|
'previous_state_name' => $harim->state_name,
|
|
'export_description' => $request->export_description,
|
|
'action_id' => $action,
|
|
'action_name' => HarimAction::name($action),
|
|
]);
|
|
|
|
$state = HarimStates::BARESI_TAVASOT_MOAVEN->value;
|
|
|
|
$harim->update([
|
|
'state_id' => $state,
|
|
'state_name' => HarimStates::name($state),
|
|
]);
|
|
});
|
|
|
|
return $this->successResponse();
|
|
}
|
|
|
|
/**
|
|
* @throws Throwable
|
|
*/
|
|
public function referFile(ReferFileRequest $request, Harim $harim): JsonResponse
|
|
{
|
|
DB::transaction(function () use ($request, $harim) {
|
|
$action = HarimAction::REFER->value;
|
|
|
|
$harim->histories()->create([
|
|
'expert_id' => auth()->user()->id,
|
|
'previous-state_id' => $harim->state_id,
|
|
'previous_state_name' => $harim->state_name,
|
|
'export_description' => $request->export_description,
|
|
'action_id' => $action,
|
|
'action_name' => HarimAction::name($action),
|
|
]);
|
|
|
|
$state = HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_MOAVEN->value;
|
|
|
|
$harim->update([
|
|
'state_id' => $state,
|
|
'state_name' => HarimStates::name($state),
|
|
]);
|
|
});
|
|
|
|
return $this->successResponse();
|
|
}
|
|
|
|
/**
|
|
* @throws Throwable
|
|
*/
|
|
public function confirmRoadAccessNeed(ConfirmRoadAccessNeedRequest $request, Harim $harim): JsonResponse
|
|
{
|
|
DB::transaction(function () use ($request, $harim) {
|
|
$action = HarimAction::CONFIRM->value;
|
|
|
|
$harim->histories()->create([
|
|
'expert_id' => auth()->user()->id,
|
|
'previous_state_id' => $harim->state_id,
|
|
'previous_state_name' => $harim->state_name,
|
|
'expert_description' => $request->expert_description,
|
|
'action_id' => $action,
|
|
'action_name' => HarimAction::name($action),
|
|
]);
|
|
|
|
$state = HarimStates::ERSAL_BE_PANJAREH_VAHED_NIAZ_BE_RAH_DASTRASI->value;
|
|
|
|
$harim->update([
|
|
'state_id' => $state,
|
|
'state_name' => HarimStates::name($state),
|
|
]);
|
|
|
|
ConfirmRoadAccessNeedEvent::dispatch($harim);
|
|
});
|
|
|
|
return $this->successResponse();
|
|
}
|
|
|
|
/**
|
|
* @throws Throwable
|
|
*/
|
|
public function confirmNoRoadAccessNeed(ConfirmNoRoadAccessNeedRequest $request, Harim $harim): JsonResponse
|
|
{
|
|
DB::transaction(function () use ($request, $harim) {
|
|
$action = HarimAction::CONFIRM->value;
|
|
|
|
$harim->histories()->create([
|
|
'expert_id' => auth()->user()->id,
|
|
'previous_state_id' => $harim->state_id,
|
|
'previous_state_name' => $harim->state_name,
|
|
'expert_description' => $request->expert_description,
|
|
'action_id' => $action,
|
|
'action_name' => HarimAction::name($action),
|
|
]);
|
|
|
|
$state = HarimStates::ERSAL_BE_PANJAREH_VAHED_BEDONEH_NIAZ_BE_RAH_DASTRASI->value;
|
|
|
|
$harim->update([
|
|
'state_id' => $state,
|
|
'state_name' => HarimStates::name($state),
|
|
]);
|
|
|
|
ConfirmNoRoadAccessNeedEvent::dispatch($harim);
|
|
|
|
});
|
|
|
|
return $this->successResponse();
|
|
}
|
|
|
|
/**
|
|
* @throws Throwable
|
|
*/
|
|
public function confirmRoadAccessEditNeed(ConfirmRoadAccessEditNeedRequest $request, Harim $harim): JsonResponse
|
|
{
|
|
DB::transaction(function () use ($request, $harim) {
|
|
$action = HarimAction::CONFIRM->value;
|
|
|
|
$harim->histories()->create([
|
|
'expert_id' => auth()->user()->id,
|
|
'previous_state_id' => $harim->state_id,
|
|
'previous_state_name' => $harim->state_name,
|
|
'expert_description' => $request->expert_description,
|
|
'action_id' => $action,
|
|
'action_name' => HarimAction::name($action),
|
|
]);
|
|
|
|
$state = HarimStates::UPDATE_RAHE_DASTRASI_BARGOZARE_SHODE->value;
|
|
|
|
$harim->update([
|
|
'state_id' => $state,
|
|
'state_name' => HarimStates::name($state),
|
|
]);
|
|
|
|
ConfirmRoadAccessEditNeedEvent::dispatch($harim);
|
|
});
|
|
|
|
return $this->successResponse();
|
|
}
|
|
|
|
/**
|
|
* @throws \Throwable
|
|
*/
|
|
public function confirmGuaranteeLetterNeed(ConfirmGuaranteeLetterNeedRequest $request, Harim $harim): JsonResponse
|
|
{
|
|
DB::transaction(function () use ($request, $harim) {
|
|
$action = HarimAction::CONFIRM->value;
|
|
|
|
$harim->histories()->create([
|
|
'expert_id' => auth()->user()->id,
|
|
'previous_state_id' => $harim->state_id,
|
|
'previous_state_name' => $harim->state_name,
|
|
'expert_description' => $request->expert_description,
|
|
'action_id' => $action,
|
|
'action_name' => HarimAction::name($action),
|
|
]);
|
|
|
|
$state = HarimStates::ARSE_VA_AYAN_NAHAI->value;
|
|
|
|
$harim->update([
|
|
'state_id' => $state,
|
|
'state_name' => HarimStates::name($state),
|
|
]);
|
|
|
|
ConfirmGuaranteeLetterNeedEvent::dispatch($harim);
|
|
});
|
|
|
|
return $this->successResponse();
|
|
}
|
|
|
|
public function show(ShowRequest $request, Harim $harim): JsonResponse
|
|
{
|
|
return $this->successResponse($harim->load('histories'));
|
|
}
|
|
|
|
/**
|
|
* @throws Throwable
|
|
*/
|
|
public function referPaymentRequest(ReferPaymentRequest $request, Harim $harim): JsonResponse
|
|
{
|
|
DB::transaction(function () use ($request, $harim) {
|
|
$action = HarimAction::REFER->value;
|
|
|
|
$harim->histories()->create([
|
|
'expert_id' => auth()->user()->id,
|
|
'previous-state_id' => $harim->state_id,
|
|
'previous_state_name' => $harim->state_name,
|
|
'export_description' => $request->export_description,
|
|
'action_id' => $action,
|
|
'action_name' => HarimAction::name($action),
|
|
]);
|
|
|
|
$state = HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MOAVEN->value;
|
|
|
|
$harim->update([
|
|
'state_id' => $state,
|
|
'state_name' => HarimStates::name($state),
|
|
]);
|
|
});
|
|
|
|
return $this->successResponse();
|
|
}
|
|
|
|
/**
|
|
* @throws Throwable
|
|
*/
|
|
public function confirmPayment(ConfirmPaymentRequest $request, Harim $harim): JsonResponse
|
|
{
|
|
DB::transaction(function () use ($request, $harim) {
|
|
$action = HarimAction::CONFIRM->value;
|
|
|
|
$harim->histories()->create([
|
|
'expert_id' => auth()->user()->id,
|
|
'previous_state_id' => $harim->state_id,
|
|
'previous_state_name' => $harim->state_name,
|
|
'expert_description' => $request->expert_description,
|
|
'action_id' => $action,
|
|
'action_name' => HarimAction::name($action),
|
|
]);
|
|
|
|
$state = HarimStates::ETMAM_FARAYAND->value;
|
|
|
|
$harim->update([
|
|
'state_id' => $state,
|
|
'state_name' => HarimStates::name($state),
|
|
]);
|
|
});
|
|
|
|
return $this->successResponse();
|
|
}
|
|
|
|
}
|