diff --git a/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptController.php index 1620ca78..f4a5900b 100644 --- a/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptController.php +++ b/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptController.php @@ -80,11 +80,8 @@ class AccidentReceiptController extends Controller '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' => FileFacade::save($request->file('damage_picture1'), 'receipts_files/'), - 'damage_picture2' => FileFacade::save($request->file('damage_picture2'), 'receipts_files/'), 'status' => AccidentStates::BEDON_EGHDAM->value, 'status_fa' => AccidentStates::name(AccidentStates::BEDON_EGHDAM->value), ]; @@ -109,6 +106,10 @@ class AccidentReceiptController extends Controller $accidentData['sum'] = $sum; $accident = Accident::query()->create($accidentData); + $accident->damage_picture1 = FileFacade::save($request->file('damage_picture1'), "receipts_files/{$accident->id}"); + $accident->damage_picture2 = FileFacade::save($request->file('damage_picture2'), "receipts_files/{$accident->id}"); + $accident->police_file = $request->report_base ? null : FileFacade::save($request->file('police_file'), "receipts_files/{$accident->id}"); + $accident->save(); $accident->damages()->attach($damageData); @@ -207,10 +208,9 @@ class AccidentReceiptController extends Controller */ public function destroy(Accident $accident): JsonResponse { - throw_if($accident->status != AccidentStates::BEDON_EGHDAM->value, new ProhibitedAction('قابلیت حذف در این مرحله وجود ندارد')); - FileFacade::deleteDirectory('receipts_files/' . $accident->id); + FileFacade::deleteDirectory("receipts_files/{$accident->id}"); DB::transaction(function () use ($accident) { @@ -262,13 +262,14 @@ class AccidentReceiptController extends Controller return $this->successResponse(); } + /** + * @throws Throwable + */ public function submitInvoice(Accident $accident, PaymentService $paymentService): JsonResponse { $final_amount = $accident->sum - ($accident->deposit_insurance_amount + $accident->deposit_daghi_amount); - if ($final_amount < 0) { - return $this->errorResponse('error'); - } + throw_if($final_amount < 0, new ProhibitedAction('مبالغ داغی و بیمه از مبلغ کل بیشتر می باشد.')); $bill_code = $paymentService->invoiceBillApi($accident->driver_national_code, $final_amount);