create receipt logic api
This commit is contained in:
28
app/Enums/AccidentStates.php
Normal file
28
app/Enums/AccidentStates.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum AccidentStates: int
|
||||||
|
{
|
||||||
|
case BEDON_EGHDAM= 0;
|
||||||
|
case SODOR_NAME_BIME_VA_DAGHI = 1;
|
||||||
|
case SABT_FISH = 2;
|
||||||
|
|
||||||
|
case SODOR_FACTOR = 3;
|
||||||
|
case PARDAKHT_FACTOR = 4;
|
||||||
|
case SODOR_NAME_POLICE_RAH = 5;
|
||||||
|
|
||||||
|
public static function name(int $state): string
|
||||||
|
{
|
||||||
|
$mapArray = [
|
||||||
|
0 => "بدون اقدام",
|
||||||
|
1 => "صدور نامه بیمه و کارشناسی داغی",
|
||||||
|
2 => "فیش ها ثبت شده است.",
|
||||||
|
3 => "فاکتور صادر شده است.",
|
||||||
|
4 => "فاکتور پرداخت شده است",
|
||||||
|
5 => "نامه پلیس راه صادر شده است (اتمام فرایند)",
|
||||||
|
];
|
||||||
|
|
||||||
|
return $mapArray[$state];
|
||||||
|
}
|
||||||
|
}
|
||||||
373
app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php
Normal file
373
app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php
Normal file
@@ -0,0 +1,373 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\V3\Dashboard;
|
||||||
|
|
||||||
|
use App\Enums\AccidentStates;
|
||||||
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
|
use App\Facades\File\FileFacade;
|
||||||
|
use App\Facades\Sms\Sms;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\V3\AccidentReceipt\ConfirmPaymentInfoRequest;
|
||||||
|
use App\Http\Traits\ApiResponse;
|
||||||
|
use App\Models\Accident;
|
||||||
|
use App\Models\City;
|
||||||
|
use App\Models\DailyAccidentSettings;
|
||||||
|
use App\Models\Damage;
|
||||||
|
use App\Models\Province;
|
||||||
|
use App\Services\NominatimService;
|
||||||
|
use App\Services\PaymentService;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class AccidentReceiptController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function index(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$allowedFilters = ['*'];
|
||||||
|
$allowedSortings = ['*'];
|
||||||
|
|
||||||
|
$user = auth()->user();
|
||||||
|
$query = null;
|
||||||
|
|
||||||
|
if ($user->hasPermissionTo('show-receipt')) {
|
||||||
|
$query = Accident::query();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (is_null($user->province_id)) {
|
||||||
|
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = Accident::query()->where('province_id', '=', $user->province_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = DataTableFacade::run(
|
||||||
|
$query,
|
||||||
|
$request,
|
||||||
|
allowedFilters: $allowedFilters,
|
||||||
|
allowedSortings: $allowedSortings
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$user->addActivityComplete(1122);
|
||||||
|
|
||||||
|
return response()->json($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function accidentDamage(Accident $accident): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->successResponse($accident->damages()->get(['unit', 'amount', 'value']));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request, NominatimService $nominatimService): JsonResponse
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($request, $nominatimService) {
|
||||||
|
|
||||||
|
$province = Province::query()->where('id', '=', $request->province_id)->first();
|
||||||
|
$city = City::query()->where('id', '=', $request->city_id)->first();
|
||||||
|
|
||||||
|
$accidentData = [
|
||||||
|
'province_id' => $province->id,
|
||||||
|
'province_fa' => $province->name_fa,
|
||||||
|
'city_id' => $city->id,
|
||||||
|
'city_fa' => $city->name_fa,
|
||||||
|
'axis_name' => $request->axis_name,
|
||||||
|
'driver_name' => $request->driver_name,
|
||||||
|
'plaque' => $request->plaque,
|
||||||
|
'driver_national_code' => $request->driver_national_code,
|
||||||
|
'driver_phone_number' => $request->driver_phone_number,
|
||||||
|
'user_id' => auth()->user()->id,
|
||||||
|
'lat' => $request->lat,
|
||||||
|
'lng' => $request->lng,
|
||||||
|
'accident_type' => $request->accident_type,
|
||||||
|
'accident_date' => $request->accident_date,
|
||||||
|
'accident_time' => $request->accident_time,
|
||||||
|
'accident_type_fa' => DailyAccidentSettings::query()->where('type', 'accident_type')->where('name', $request->accident_type)->first()->value,
|
||||||
|
'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng),
|
||||||
|
'report_base' => $request->report_base,
|
||||||
|
// 'police_file' => $request->report_base ? null : FileFacade::save($request->file('police_file'), 'receipts_files/'),
|
||||||
|
'police_serial' => $request->police_serial ?? null,
|
||||||
|
'police_file_date' => $request->police_file_date ?? null,
|
||||||
|
// 'damage_picture1' => $request->has('damage_picture1') ? FileFacade::save($request->file('damage_picture1'), 'receipts_files/') : null,
|
||||||
|
// 'damage_picture2' => $request->has('damage_picture2') ? FileFacade::save($request->file('damage_picture2'), 'receipts_files/') : null,
|
||||||
|
'status' => AccidentStates::BEDON_EGHDAM->value,
|
||||||
|
'status_fa' => AccidentStates::name(AccidentStates::BEDON_EGHDAM->value),
|
||||||
|
];
|
||||||
|
|
||||||
|
$sum = 0;
|
||||||
|
$damageData = [];
|
||||||
|
|
||||||
|
foreach ($request->items_damge as $key => $damage) {
|
||||||
|
$damage = Damage::query()->find($damage->id);
|
||||||
|
$damageData[$damage->id] = [
|
||||||
|
'value' => $damage->value,
|
||||||
|
'unit' => $damage->unit,
|
||||||
|
'amount' => $damage->amount,
|
||||||
|
];
|
||||||
|
$sum += $damage->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ojrate_nasb = $sum/100*20;
|
||||||
|
$sum += $ojrate_nasb;
|
||||||
|
|
||||||
|
$accidentData['ojrate_nasb'] = $ojrate_nasb;
|
||||||
|
$accidentData['sum'] = $sum;
|
||||||
|
|
||||||
|
$accident = Accident::query()->create($accidentData);
|
||||||
|
|
||||||
|
$filesData = [
|
||||||
|
[
|
||||||
|
'name' => 'damage_picture1',
|
||||||
|
'path' => FileFacade::save($request->file('damage_picture1'), "receipts_files/{$accident->id}/"),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'damage_picture2',
|
||||||
|
'path' => FileFacade::save($request->file('damage_picture2'), "receipts_files/{$accident->id}/")
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$request->report_base) {
|
||||||
|
$filesData[] = [
|
||||||
|
'name' => 'police_file',
|
||||||
|
'path' => FileFacade::save($request->file('police_file'), "receipts_files/{$accident->id}/")
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$accident->damages()->attach($damageData);
|
||||||
|
$accident->files()->createMany($filesData);
|
||||||
|
|
||||||
|
auth()->user()->addActivityComplete(1123);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show(Accident $accident): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->successResponse($accident->load('damages'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Accident $accident, Request $request, NominatimService $nominatimService): JsonResponse
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($request, $accident, $nominatimService) {
|
||||||
|
|
||||||
|
$province = Province::query()->where('id', '=', $request->province_id)->first();
|
||||||
|
$city = City::query()->where('id', '=', $request->city_id)->first();
|
||||||
|
|
||||||
|
if ($request->report_base && $accident->police_file) {
|
||||||
|
FileFacade::delete($accident->police_file, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$request->report_base && $request->filled('police_file')) {
|
||||||
|
FileFacade::delete($accident->police_file, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->has('damage_picture1')) {
|
||||||
|
FileFacade::delete($accident->damage_picture1, true);
|
||||||
|
$damage_picture1 = FileFacade::save($request->file('damage_picture1'), 'receipts_files/');
|
||||||
|
}
|
||||||
|
if ($request->has('damage_picture2')) {
|
||||||
|
FileFacade::delete($accident->damage_picture2, true);
|
||||||
|
$damage_picture2 = FileFacade::save($request->file('damage_picture2'), 'receipts_files/');
|
||||||
|
}
|
||||||
|
|
||||||
|
$accidentData = [
|
||||||
|
'province_id' => $province->id,
|
||||||
|
'province_fa' => $province->name_fa,
|
||||||
|
'city_id' => $city->id,
|
||||||
|
'city_fa' => $city->name_fa,
|
||||||
|
'axis_name' => $request->axis_name,
|
||||||
|
'driver_name' => $request->driver_name,
|
||||||
|
'plaque' => $request->plaque,
|
||||||
|
'driver_national_code' => $request->driver_national_code,
|
||||||
|
'driver_phone_number' => $request->driver_phone_number,
|
||||||
|
'user_id' => auth()->user()->id,
|
||||||
|
'lat' => $request->lat,
|
||||||
|
'lng' => $request->lng,
|
||||||
|
'accident_type' => $request->accident_type,
|
||||||
|
'accident_date' => $request->accident_date,
|
||||||
|
'accident_time' => $request->accident_time,
|
||||||
|
'accident_type_fa' => DailyAccidentSettings::query()->where('type', 'accident_type')->where('name', $request->accident_type)->first()->value,
|
||||||
|
'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng),
|
||||||
|
'report_base' => $request->report_base,
|
||||||
|
'police_file' => $request->report_base == 0 ? FileFacade::save($request->file('police_file'), 'receipts_files/') : null,
|
||||||
|
'police_serial' => $request->police_serial ?? null,
|
||||||
|
'police_file_date' => $request->police_file_date ?? null,
|
||||||
|
'damage_picture1' => $damage_picture1,
|
||||||
|
'damage_picture2' => $damage_picture2,
|
||||||
|
];
|
||||||
|
|
||||||
|
$sum = 0;
|
||||||
|
$damageData = [];
|
||||||
|
|
||||||
|
foreach ($request->items_damge as $key => $item) {
|
||||||
|
$damage = Damage::query()->find($item->id);
|
||||||
|
$damageData[$damage->id] = [
|
||||||
|
'value' => $damage->value,
|
||||||
|
'unit' => $damage->unit,
|
||||||
|
'amount' => $damage->amount,
|
||||||
|
];
|
||||||
|
$sum += $item->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$ojrate_nasb = $sum/100*20;
|
||||||
|
$sum += $ojrate_nasb;
|
||||||
|
|
||||||
|
$accidentData['ojrate_nasb'] = $ojrate_nasb;
|
||||||
|
$accidentData['sum'] = $sum;
|
||||||
|
|
||||||
|
$accident->update($accidentData);
|
||||||
|
|
||||||
|
$accident->damages()->sync($damageData);
|
||||||
|
|
||||||
|
auth()->user()->addActivityComplete(1124);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(Accident $accident): JsonResponse
|
||||||
|
{
|
||||||
|
FileFacade::delete('storage/receipts_files/'.$accident->id);
|
||||||
|
|
||||||
|
$accident->damages()->detach();
|
||||||
|
|
||||||
|
$accident->delete();
|
||||||
|
|
||||||
|
auth()->user()->addActivityComplete(1125);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateInsuranceLetter(Accident $accident): JsonResponse
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($accident) {
|
||||||
|
$accident->update([
|
||||||
|
'status' => AccidentStates::SODOR_NAME_BIME_VA_DAGHI->value,
|
||||||
|
'status_fa' => AccidentStates::name(AccidentStates::SODOR_NAME_BIME_VA_DAGHI->value),
|
||||||
|
]);
|
||||||
|
|
||||||
|
auth()->user()->addActivityComplete(1126);
|
||||||
|
});
|
||||||
|
|
||||||
|
$account_data = Province::query()->where('id', $accident->province_id)->first();
|
||||||
|
|
||||||
|
return $this->successResponse([
|
||||||
|
$account_data,
|
||||||
|
$accident->load('damages')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function confirmPaymentInfo(ConfirmPaymentInfoRequest $request, Accident $accident): JsonResponse
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($request, $accident) {
|
||||||
|
if ($request->has('deposit_insurance_status')) {
|
||||||
|
if ($request->has('deposit_insurance_image')) {
|
||||||
|
$accident->deposit_insurance_image = $request->file('deposit_insurance_image')->storeAs('receipts_files/'.$accident->id, 'deposit_insurance_image_'.$accident->id.'_'.time().'.'.$request->file('deposit_insurance_image')->extension(), 'public');
|
||||||
|
}
|
||||||
|
|
||||||
|
$accident->deposit_insurance_amount = $request->deposit_insurance_amount;
|
||||||
|
} else {
|
||||||
|
$accident->deposit_insurance_image = null;
|
||||||
|
$accident->deposit_insurance_amount = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->has('deposit_daghi_status')) {
|
||||||
|
if ($request->has('deposit_daghi_image')) {
|
||||||
|
$accident->deposit_daghi_image = $request->file('deposit_daghi_image')->storeAs('receipts_files/'.$accident->id, 'deposit_daghi_image_'.$accident->id.'_'.time().'.'.$request->file('deposit_daghi_image')->extension(), 'public');
|
||||||
|
}
|
||||||
|
|
||||||
|
$accident->deposit_daghi_amount = $request->deposit_daghi_amount;
|
||||||
|
} else {
|
||||||
|
$accident->deposit_daghi_image = null;
|
||||||
|
$accident->deposit_daghi_amount = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$accident->update([
|
||||||
|
'status' => AccidentStates::SABT_FISH->value,
|
||||||
|
'status_fa' => AccidentStates::name(AccidentStates::SABT_FISH->value),
|
||||||
|
]);
|
||||||
|
|
||||||
|
auth()->user()->addActivityComplete(1132);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function submitInvoice(Accident $accident, PaymentService $paymentService): JsonResponse
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($accident, $paymentService) {
|
||||||
|
|
||||||
|
$final_amount = $accident->sum - ($accident->deposit_insurance_amount + $accident->deposit_daghi_amount);
|
||||||
|
|
||||||
|
if ($final_amount < 0) {
|
||||||
|
return $this->errorResponse('error');
|
||||||
|
}
|
||||||
|
|
||||||
|
$accident->final_amount = $final_amount;
|
||||||
|
|
||||||
|
$accident->bill_code = $paymentService->invoiceBillApi($accident->driver_national_code, $final_amount);
|
||||||
|
|
||||||
|
$accident->update([
|
||||||
|
'status' => AccidentStates::SODOR_FACTOR->value,
|
||||||
|
'status_fa' => AccidentStates::name(AccidentStates::SODOR_FACTOR->value),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$msg = "فاکتور با شناسه پرداخت \n" . explode("/", $accident->bill_code)[0]. "\n در سامانه سازمان راهداری ثبت شد. برای پرداخت از لینک زیر اقدام نمایید.\n\n".env("PAYMENT_LINK")."/#/pay/".explode("/", $accident->bill_code)[0]."/$final_amount";
|
||||||
|
|
||||||
|
Sms::sendSms($accident->driver_phone_number, $msg);
|
||||||
|
|
||||||
|
auth()->user()->addActivityComplete(1129);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkPaymentStatus(Accident $accident, PaymentService $paymentService): JsonResponse
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($accident, $paymentService) {
|
||||||
|
if ($accident->final_amount > 0) {
|
||||||
|
|
||||||
|
$response = json_decode($paymentService->callPaymentStatusBillApi(explode("/", $accident->bill_code)[0]));
|
||||||
|
|
||||||
|
if ($response->isPayed) {
|
||||||
|
$accident->update([
|
||||||
|
'status' => AccidentStates::PARDAKHT_FACTOR->value,
|
||||||
|
'status_fa' => AccidentStates::name(AccidentStates::PARDAKHT_FACTOR->value),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$accident->update([
|
||||||
|
'status' => AccidentStates::PARDAKHT_FACTOR->value,
|
||||||
|
'status_fa' => AccidentStates::name(AccidentStates::PARDAKHT_FACTOR->value),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
auth()->user()->addActivityComplete(1130);
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generatePoliceDocument(Request $request, Accident $accident): JsonResponse
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($request, $accident) {
|
||||||
|
|
||||||
|
$accident->update([
|
||||||
|
'status' => AccidentStates::SODOR_NAME_POLICE_RAH->value,
|
||||||
|
'status_fa' => AccidentStates::name(AccidentStates::SODOR_NAME_POLICE_RAH->value),
|
||||||
|
]);
|
||||||
|
|
||||||
|
auth()->user()->addActivityComplete(1131);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,254 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\V3\Dashboard;
|
|
||||||
|
|
||||||
use App\Facades\DataTable\DataTableFacade;
|
|
||||||
use App\Facades\Sms\Sms;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Http\Traits\ApiResponse;
|
|
||||||
use App\Models\Accident;
|
|
||||||
use App\Models\City;
|
|
||||||
use App\Models\DailyAccidentSettings;
|
|
||||||
use App\Models\Damage;
|
|
||||||
use App\Models\Province;
|
|
||||||
use App\Services\NominatimService;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
|
|
||||||
class ReceiptController extends Controller
|
|
||||||
{
|
|
||||||
use ApiResponse;
|
|
||||||
|
|
||||||
public function index(Request $request): JsonResponse
|
|
||||||
{
|
|
||||||
$allowedFilters = ['*'];
|
|
||||||
$allowedSortings = ['*'];
|
|
||||||
|
|
||||||
$user = auth()->user();
|
|
||||||
$query = null;
|
|
||||||
|
|
||||||
if ($user->hasPermissionTo('show-receipt')) {
|
|
||||||
$query = Accident::query();
|
|
||||||
} else {
|
|
||||||
if (is_null($user->province_id)) {
|
|
||||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = Accident::query()->where('province_id', '=', $user->province_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = DataTableFacade::run(
|
|
||||||
$query,
|
|
||||||
$request,
|
|
||||||
allowedFilters: $allowedFilters,
|
|
||||||
allowedSortings: $allowedSortings
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$user->addActivityComplete(1122);
|
|
||||||
|
|
||||||
return $this->successResponse($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function store(Request $request, NominatimService $nominatimService)
|
|
||||||
{
|
|
||||||
DB::transaction(function () use ($request, $nominatimService) {
|
|
||||||
|
|
||||||
$province = Province::query()->where('id', '=', $request->province_id)->first();
|
|
||||||
$city = City::query()->where('id', '=', $request->city_id)->first();
|
|
||||||
|
|
||||||
$accident = [
|
|
||||||
'province_id' => $province->id,
|
|
||||||
'province_fa' => $province->name_fa,
|
|
||||||
'city_id' => $city->id,
|
|
||||||
'city_fa' => $city->name_fa,
|
|
||||||
'axis_name' => $request->axis_name,
|
|
||||||
'driver_name' => $request->driver_name,
|
|
||||||
'plaque' => $request->plaque,
|
|
||||||
'driver_national_code' => $request->driver_national_code,
|
|
||||||
'driver_phone_number' => $request->driver_phone_number,
|
|
||||||
'user_id' => auth()->user()->id,
|
|
||||||
'lat' => $request->lat,
|
|
||||||
'lng' => $request->lng,
|
|
||||||
'accident_type' => $request->accident_type,
|
|
||||||
'accident_date' => $request->accident_date,
|
|
||||||
'accident_time' => $request->accident_time,
|
|
||||||
'accident_type_fa' => DailyAccidentSettings::query()->where('type', 'accident_type')->where('name', $request->accident_type)->first()->value,
|
|
||||||
'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng),
|
|
||||||
'report_base' => $request->report_base != null ? 1 : null,
|
|
||||||
'police_file' => '',
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($request->report_base) {
|
|
||||||
$accident['report_base'] = 1;
|
|
||||||
} else {
|
|
||||||
$accident['police_file'] = $request->file('police_file')->storeAs('receipts_files/'.$accident->id, 'police_file_'.$accident->id.'_'.time().'.'.$request->file('police_file')->extension(), 'public');
|
|
||||||
$accident['police_serial'] = $request->police_serial;
|
|
||||||
$accident['police_file_date'] = $request->police_file_date;
|
|
||||||
$accident['report_base'] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->has('damage_picture1')) {
|
|
||||||
$new_accident->damage_picture1 = $request->file('damage_picture1')->storeAs('receipts_files/'.$new_accident->id, 'damage_picture1_'.$new_accident->id.'_'.time().'.'.$request->file('damage_picture1')->extension(), 'public');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->has('damage_picture2')) {
|
|
||||||
$new_accident->damage_picture2 = $request->file('damage_picture2')->storeAs('receipts_files/'.$new_accident->id, 'damage_picture2_'.$new_accident->id.'_'.time().'.'.$request->file('damage_picture2')->extension(), 'public');
|
|
||||||
}
|
|
||||||
|
|
||||||
$new_accident->save();
|
|
||||||
$sum = 0;
|
|
||||||
foreach (json_decode($request->items_damge) as $key => $item) {
|
|
||||||
$damage = Damage::find($item->id);
|
|
||||||
$new_accident->damages()->attach($item->id, [
|
|
||||||
'value' => $item->value,
|
|
||||||
'unit' => $damage->unit,
|
|
||||||
'amount' => $item->amount,
|
|
||||||
]);
|
|
||||||
$sum += $item->amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
$ojrate_nasb = $sum/100*20;
|
|
||||||
$new_accident->ojrate_nasb = $ojrate_nasb;
|
|
||||||
|
|
||||||
$sum += $ojrate_nasb;
|
|
||||||
$new_accident->sum = $sum;
|
|
||||||
$new_accident->withoutAction();
|
|
||||||
$new_accident->save();
|
|
||||||
$msg = "درخواست شما بابت پرداخت خسارت وارده به ابنیه فنی و تاسیسات راه با کد یکتا ".$new_accident->id." ثبت شد.\n".verta()->now()->format('Y/m/d H:i') ;
|
|
||||||
Sms::sendSms($request->phone_number, $msg);
|
|
||||||
auth()->user()->addActivityComplete(1123);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show(Accident $accident): JsonResponse
|
|
||||||
{
|
|
||||||
return $this->successResponse($accident->load('damages'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(Accident $accident, Request $request, NominatimService $nominatimService)
|
|
||||||
{
|
|
||||||
DB::transaction(function () use ($request, $accident, $nominatimService) {
|
|
||||||
$accident->province_fa = Province::where('id', $request->province_id)->first()->name_fa;
|
|
||||||
$accident->province_id = $request->province_id;
|
|
||||||
|
|
||||||
$accident->city_fa = City::where('id', $request->city_id)->first()->name_fa;
|
|
||||||
$accident->city_id = $request->city_id;
|
|
||||||
|
|
||||||
$accident->axis_name = $request->axis_name;
|
|
||||||
$accident->driver_name = $request->driver_name;
|
|
||||||
$accident->plaque = $request->plaque;
|
|
||||||
$accident->driver_national_code = $request->national_code;
|
|
||||||
$accident->driver_phone_number = $request->phone_number;
|
|
||||||
|
|
||||||
$accident->lat = $request->lat;
|
|
||||||
$accident->lng = $request->lng;
|
|
||||||
|
|
||||||
$accident->accident_type = $request->accident_type;
|
|
||||||
$accident->accident_type_fa = DailyAccidentSettings::where('type', 'accident_type')->where('name', $request->accident_type)->first()->value;
|
|
||||||
$accident->accident_date = $request->accident_date;
|
|
||||||
$accident->accident_time = $request->accident_time;
|
|
||||||
|
|
||||||
$accident->way_id = $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng);
|
|
||||||
|
|
||||||
$accident->save();
|
|
||||||
|
|
||||||
if ($request->report_base) {
|
|
||||||
\File::delete('storage/'.$accident->police_file);
|
|
||||||
$accident->police_file = null;
|
|
||||||
$accident->police_serial = null;
|
|
||||||
$accident->report_base = 1;
|
|
||||||
} else {
|
|
||||||
if ($accident->report_base) {
|
|
||||||
if ($request->has('police_file')) {
|
|
||||||
\File::delete('storage/'.$accident->police_file);
|
|
||||||
$accident->police_file = $request->file('police_file')->storeAs('receipts_files/'.$accident->id, 'police_file_'.$accident->id.'_'.time().'.'.$request->file('police_file')->extension(), 'public');
|
|
||||||
} else {
|
|
||||||
abort(401, 'please send the file');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($request->has('police_file')) {
|
|
||||||
\File::delete('storage/'.$accident->police_file);
|
|
||||||
$accident->police_file = $request->file('police_file')->storeAs('receipts_files/'.$accident->id, 'police_file_'.$accident->id.'_'.time().'.'.$request->file('police_file')->extension(), 'public');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$accident->police_file_date = $request->police_file_date;
|
|
||||||
$accident->police_serial = $request->police_serial;
|
|
||||||
$accident->report_base = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$accident->save();
|
|
||||||
|
|
||||||
if ($request->has('damage_picture1')) {
|
|
||||||
\File::delete('storage/'.$accident->damage_picture1);
|
|
||||||
$accident->damage_picture1 = $request->file('damage_picture1')->storeAs('receipts_files/'.$accident->id, 'damage_picture1_'.$accident->id.'_'.time().'.'.$request->file('damage_picture1')->extension(), 'public');
|
|
||||||
} elseif ($request->has('damage_picture1_is_delete')) {
|
|
||||||
\File::delete('storage/'.$accident->damage_picture1);
|
|
||||||
$accident->damage_picture1 = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->has('damage_picture2')) {
|
|
||||||
\File::delete('storage/'.$accident->damage_picture2);
|
|
||||||
$accident->damage_picture2 = $request->file('damage_picture2')->storeAs('receipts_files/'.$accident->id, 'damage_picture2_'.$accident->id.'_'.time().'.'.$request->file('damage_picture2')->extension(), 'public');
|
|
||||||
} elseif ($request->has('damage_picture2_is_delete')) {
|
|
||||||
\File::delete('storage/'.$accident->damage_picture2);
|
|
||||||
$accident->damage_picture2 = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$accident->save();
|
|
||||||
$sum = 0;
|
|
||||||
$accident->damages()->detach();
|
|
||||||
foreach (json_decode($request->items_damge) as $key => $item) {
|
|
||||||
$damage = Damage::find($item->id);
|
|
||||||
$accident->damages()->attach($item->id, [
|
|
||||||
'value' => $item->value,
|
|
||||||
'unit' => $damage->unit,
|
|
||||||
'amount' => $item->amount,
|
|
||||||
]);
|
|
||||||
$sum += $item->amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$ojrate_nasb = $sum/100*20;
|
|
||||||
$accident->ojrate_nasb = $ojrate_nasb;
|
|
||||||
|
|
||||||
$sum += $ojrate_nasb;
|
|
||||||
$accident->sum = $sum;
|
|
||||||
|
|
||||||
$accident->save();
|
|
||||||
|
|
||||||
auth()->user()->addActivityComplete(1124);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete(Accident $accident)
|
|
||||||
{
|
|
||||||
\File::delete('storage/receipts_files/'.$accident->id);
|
|
||||||
|
|
||||||
$accident->damages()->detach();
|
|
||||||
$accident->delete();
|
|
||||||
auth()->user()->addActivityComplete(1125);
|
|
||||||
|
|
||||||
return $this->successResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function sendToInsurance(Request $request, Accident $accident)
|
|
||||||
{
|
|
||||||
DB::transaction(function () use ($request, $accident) {
|
|
||||||
$accident->sendToInsurance();
|
|
||||||
$accident->save();
|
|
||||||
|
|
||||||
auth()->user()->addActivityComplete(1126);
|
|
||||||
});
|
|
||||||
|
|
||||||
$account_data = Province::query()->where('id', $accident->province_id)->first();
|
|
||||||
|
|
||||||
return $this->successResponse([
|
|
||||||
$account_data,
|
|
||||||
$accident->load('damages')
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\V3\AccidentReceipt;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ConfirmPaymentInfoRequest 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, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'deposit_insurance_image' => 'file',
|
||||||
|
'deposit_insurance_amount' => 'required_with:deposit_insurance_image',
|
||||||
|
'deposit_daghi_image' => 'file',
|
||||||
|
'deposit_daghi_amount' => 'required_with:deposit_daghi_image',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use App\Traits\ReceiptReportAble;
|
use App\Traits\ReceiptReportAble;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
|
|
||||||
class Accident extends Model
|
class Accident extends Model
|
||||||
{
|
{
|
||||||
@@ -87,4 +88,8 @@ class Accident extends Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function files(): MorphMany
|
||||||
|
{
|
||||||
|
return $this->morphMany(File::class, 'fileable');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
app/Models/File.php
Normal file
19
app/Models/File.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
|
||||||
|
class File extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
public function fileable(): MorphTo
|
||||||
|
{
|
||||||
|
return $this->morphTo();
|
||||||
|
}
|
||||||
|
}
|
||||||
23
database/factories/FileFactory.php
Normal file
23
database/factories/FileFactory.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\File>
|
||||||
|
*/
|
||||||
|
class FileFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
30
database/migrations/2025_02_22_101703_create_files_table.php
Normal file
30
database/migrations/2025_02_22_101703_create_files_table.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?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::create('files', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name')->nullable();
|
||||||
|
$table->text('path');
|
||||||
|
$table->morphs('fileable');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('files');
|
||||||
|
}
|
||||||
|
};
|
||||||
17
database/seeders/FileSeeder.php
Normal file
17
database/seeders/FileSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class FileSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshController;
|
|||||||
use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshSampleController;
|
use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshSampleController;
|
||||||
use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshTypeController;
|
use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshTypeController;
|
||||||
use App\Http\Controllers\V3\Dashboard\ObservedItemController;
|
use App\Http\Controllers\V3\Dashboard\ObservedItemController;
|
||||||
|
use App\Http\Controllers\V3\Dashboard\AccidentReceiptController;
|
||||||
use App\Http\Controllers\V3\Dashboard\Reports\RoadItemsReportController;
|
use App\Http\Controllers\V3\Dashboard\Reports\RoadItemsReportController;
|
||||||
use App\Http\Controllers\V3\Dashboard\Reports\RoadPatrolReportController;
|
use App\Http\Controllers\V3\Dashboard\Reports\RoadPatrolReportController;
|
||||||
use App\Http\Controllers\V3\Dashboard\RoadItemsProjectController;
|
use App\Http\Controllers\V3\Dashboard\RoadItemsProjectController;
|
||||||
@@ -235,3 +236,19 @@ Route::prefix('damages')
|
|||||||
Route::post('/{damage}', 'update')->name('update');
|
Route::post('/{damage}', 'update')->name('update');
|
||||||
Route::post('/activate/{damage}', 'activate')->name('activate');
|
Route::post('/activate/{damage}', 'activate')->name('activate');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::prefix('receipts')
|
||||||
|
->name('receipts.')
|
||||||
|
->controller(AccidentReceiptController::class)
|
||||||
|
->group(function () {
|
||||||
|
Route::get('/', 'index')->name('index');
|
||||||
|
Route::post('/', 'store')->name('store');
|
||||||
|
Route::get('/{accident}', 'show')->name('show');
|
||||||
|
Route::post('/{accident}', 'update')->name('update');
|
||||||
|
Route::delete('/{accident}', 'destroy')->name('destroy');
|
||||||
|
Route::get('/generate_insurance_letter/{accident}', 'generateInsuranceLetter')->name('generateInsuranceLetter');
|
||||||
|
Route::post('/confirm_payment_info/{accident}', 'confirmPaymentInfo')->name('confirmPaymentInfo');
|
||||||
|
Route::get('/submit_invoice/{accident}', 'submitInvoice')->name('submitInvoice');
|
||||||
|
Route::get('/check_payment_status/{accident}', 'checkPaymentStatus')->name('checkPaymentStatus');
|
||||||
|
Route::get('/generate_police_document/{accident}', 'generatePoliceDocument')->name('generatePoliceDocument');
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user