141 lines
5.1 KiB
PHP
141 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\V3\Dashboard\Harim;
|
|
|
|
use App\Enums\HarimStates;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\V3\Dashboard\Harim\PanjareVahed\GetAccessRoadRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\PanjareVahed\GetFinalPolygonsRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\PanjareVahed\GetRejectRequest;
|
|
use App\Http\Requests\V3\Dashboard\Harim\PanjareVahed\ReceiveNewRequest;
|
|
use App\Http\Traits\ApiResponse;
|
|
use App\Models\City;
|
|
use App\Models\Harim;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class PanjareVahedController extends Controller
|
|
{
|
|
use ApiResponse;
|
|
|
|
public function receiveNewRequest(ReceiveNewRequest $request): JsonResponse
|
|
{
|
|
$wkt = 'POLYGON(('.implode(',', array_map(fn ($c) => "{$c[0]} {$c[1]}", $request->primary_area['coordinates'])).'))';
|
|
$result = DB::selectOne('SELECT ST_AsText(ST_PointOnSurface(ST_GeomFromText(?, 4326))) AS point', [$wkt]);
|
|
preg_match('/POINT\(([^ ]+) ([^ ]+)\)/', $result->point, $matches);
|
|
|
|
$city = City::findCityWithLatLng(lat:$matches[2], lng: $matches[1]);
|
|
|
|
$state = HarimStates::BARESI_EDARE_SHAHRESTAN->value;
|
|
|
|
$harim = Harim::query()->firstOrCreate(['panjare_vahed_id' => $request->request_id],
|
|
[
|
|
'state_id' => $state,
|
|
'state_name' => HarimStates::name($state),
|
|
'panjare_vahed_id' => $request->request_id,
|
|
'national_id' => $request->national_id,
|
|
'phone_number' => $request->phone_number,
|
|
'request_date' => $request->request_date,
|
|
'province_id' => $city->province_id,
|
|
'province_name' => $city->province()->first()->name_fa,
|
|
'city_id' => $city->id,
|
|
'city_name' => $city->name_fa,
|
|
'edareh_shahri_id' => $city->edarateShahri()->first()->id,
|
|
'requested_organization' => $request->requested_organization,
|
|
'plan_group' => $request->plan_group,
|
|
'plan_title' => $request->plan_title,
|
|
'worksheet_id' => $request->worksheet,
|
|
'response_options' => json_encode($request->response_options),
|
|
'isic' => $request->isic,
|
|
'primary_area' => json_encode($request->primary_area),
|
|
'data' => $request->data,
|
|
]
|
|
);
|
|
|
|
$harim->panjarehVahedHistories()->create([
|
|
'harim_id' => $harim->id,
|
|
'data' => $request->data,
|
|
]);
|
|
|
|
return response()->json([
|
|
'id' => $harim->id,
|
|
'city' => $city->edarateShahri()->first()->name_fa,
|
|
'province' => $city->province()->first()->name_fa,
|
|
'statusCode' => 200,
|
|
'message' => 'successful',
|
|
]);
|
|
}
|
|
|
|
public function getAccessRoad(GetAccessRoadRequest $request): JsonResponse
|
|
{
|
|
$harim = Harim::query()->firstWhere('panjare_vahed_id', '=', $request->request_id);
|
|
|
|
$harim->panjarehVahedHistories()->create([
|
|
'harim_id' => $harim->id,
|
|
'data' => $harim->data,
|
|
]);
|
|
|
|
$harim->update([
|
|
'state_id' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_DAFTAR_HARIM->value,
|
|
'state_name' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_DAFTAR_HARIM->label(),
|
|
'access_road' => json_encode($request->access_road),
|
|
'data' => $request->data,
|
|
]);
|
|
|
|
return response()->json([
|
|
'id' => $harim->id,
|
|
'statusCode' => 200,
|
|
'message' => 'successful',
|
|
]);
|
|
}
|
|
|
|
public function getRejectRequest(GetRejectRequest $request): JsonResponse
|
|
{
|
|
$state = HarimStates::MOKHALEFAT_BA_DASTGAH->value;
|
|
|
|
$harim = Harim::query()->firstWhere('panjare_vahed_id', '=', $request->request_id);
|
|
|
|
$harim->panjarehVahedHistories()->create([
|
|
'harim_id' => $harim->id,
|
|
'data' => $harim->data,
|
|
]);
|
|
|
|
$harim->update([
|
|
'state_id' => $state,
|
|
'state_name' => HarimStates::name($state),
|
|
'data' => $request->data,
|
|
]);
|
|
|
|
return response()->json([
|
|
'id' => $harim->id,
|
|
'statusCode' => 200,
|
|
'message' => 'successful',
|
|
]);
|
|
}
|
|
|
|
public function getFinalPolygons(GetFinalPolygonsRequest $request): JsonResponse
|
|
{
|
|
|
|
$harim = Harim::query()->firstWhere('panjare_vahed_id', '=', $request->request_id);
|
|
|
|
$harim->panjarehVahedHistories()->create([
|
|
'harim_id' => $harim->id,
|
|
'data' => $harim->data,
|
|
]);
|
|
|
|
$harim->update([
|
|
'state_id' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_DAFTAR_HARIM->value,
|
|
'state_name' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_DAFTAR_HARIM->label(),
|
|
'final_area' => json_encode($request->final_area),
|
|
'final_plan' => json_encode($request->final_plan),
|
|
'data' => $request->data,
|
|
]);
|
|
|
|
return response()->json([
|
|
'id' => $harim->id,
|
|
'statusCode' => 200,
|
|
'message' => 'successful',
|
|
]);
|
|
}
|
|
}
|