Ejemplo n.º 1
0
 /**
  * Update the specified resource in storage.
  *
  * @param VehicleEditFormRequest $request
  * @param string                 $rp_id
  * @param string                 $header_id
  * @param string                 $detail_id
  *
  * @return
  */
 public function updateIssuance(VehicleEditFormRequest $request, $rp_id, $header_id, $detail_id = null)
 {
     if (request()->ajax()) {
         if ($this->retailerProductRepository->getRetailerProductById(decode($rp_id))) {
             $retailerProduct = $this->retailerProductRepository->getModel();
             if ($this->repository->getDetailById(decode($detail_id))) {
                 if ($this->repository->updateVehicleIssuance($request)) {
                     $detail = $this->repository->getModel();
                     if (Cache::has(decode($header_id)) && $request->has('coverage')) {
                         goto StoreVehicle;
                     }
                     if ($this->facultativeRepository->storeFacultative($detail, $retailerProduct, $request->user())) {
                         $this->headerRepository->setHeaderFacultative(decode($header_id));
                         return response()->json(['location' => route('au.edit', ['rp_id' => $rp_id, 'header_id' => $header_id, $request->get('idf') ? 'idf=' . $request->get('idf') : null])]);
                     }
                 }
             } elseif (Cache::has(decode($header_id)) && $request->has('coverage') && $this->headerRepository->getHeaderById(decode($header_id))) {
                 $header = $this->headerRepository->getModel();
                 if ($this->repository->storeVehicle($request, $header, true)) {
                     $detail = $this->repository->getModel();
                     StoreVehicle:
                     $sf = $this->facultativeRepository->storeFacultative($detail, $retailerProduct, $request->user(), true);
                     if ($sf === 428) {
                         $errors = $this->facultativeRepository->getErrors();
                         return response()->json(['reason' => $errors['reason']], 428);
                     }
                     return response()->json(['location' => route('au.coverage.edit', ['rp_id' => $rp_id, 'de_id' => $request->get('coverage'), 'header_id' => $header_id])]);
                 }
             }
         }
         return response()->json(['err' => 'Unauthorized action.'], 401);
     }
     return redirect()->back();
 }