/**
  * Update the specified resource in storage.
  *
  * @param FacultativeFormRequest $request
  * @param string                 $rp_id
  * @param string                 $id
  *
  * @return \Illuminate\Http\Response
  */
 public function update(FacultativeFormRequest $request, $rp_id, $id)
 {
     if ($request->ajax()) {
         if ($this->retailerProductRepository->getRetailerProductById(decode($rp_id)) && $this->repository->getFacultativeById(decode($id))) {
             $retailerProduct = $this->retailerProductRepository->getModel();
             if ($this->repository->updateFacultative($request)) {
                 $fa = $this->repository->getModel();
                 $header = $fa->detail->header;
                 $this->repository->approved = (int) $request->get('approved');
                 $surcharge = (bool) $request->get('surcharge');
                 if ($this->repository->approved === 1 || $this->repository->approved === 0) {
                     $this->headerRepository->setApproved($header);
                     if ($surcharge) {
                         $this->headerRepository->setVehicleResult($retailerProduct, $header);
                     }
                 }
                 $mail = new MailController($request->user(), $request->get('emails'));
                 $this->repository->sendProcessMail($mail, $rp_id, $id);
                 return response()->json(['location' => route('home')]);
             }
         }
         return response()->json(['err' => 'Unauthorized action.'], 401);
     }
     return redirect()->back();
 }
Beispiel #2
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();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param string                    $rp_id
  * @param string                    $header_id
  *
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, $rp_id, $header_id)
 {
     $this->validate($request, ['reason' => 'required|ands_full']);
     if (request()->ajax()) {
         if ($this->headerRepository->getHeaderById(decode($header_id))) {
             $header = $this->headerRepository->getModel();
             if ($this->repository->storeCancellation($request, $header)) {
                 $mail = new MailController($request->user());
                 $mail->subject = 'Anulacion de Poliza No. ' . $header->prefix . '-' . $header->issue_number;
                 $mail->template = 'de.cancellation';
                 array_push($mail->receivers, ['email' => $header->user->email, 'name' => $header->user->full_name]);
                 if ($mail->send(decode($rp_id), ['header' => $header])) {
                 }
                 return response()->json(['location' => route('au.cancel.lists', ['rp_id' => $rp_id])]);
             }
         }
         return response()->json(['err' => 'Unauthorized action.'], 401);
     }
     return redirect()->back();
 }
Beispiel #4
0
 /**
  * @param CoverageEditFormRequest $request
  * @param string                  $rp_id
  * @param string                  $de_id
  * @param string                  $header_id
  *
  * @return mixed
  */
 public function coverageUpdate(CoverageEditFormRequest $request, $rp_id, $de_id, $header_id)
 {
     if (Cache::has(decode($header_id)) && $this->retailerProductRepository->getRetailerProductById(decode($rp_id))) {
         $retailerProduct = $this->retailerProductRepository->getModel();
         if ($this->repository->getHeaderById(decode($header_id)) && $this->headerDeRepository->getHeaderById(decode($de_id))) {
             $header = $this->repository->getModel();
             $de = $this->headerDeRepository->getModel();
             if ($this->repository->setVehicleResult($retailerProduct, $header) && $this->repository->updateCoverage($request, $de)) {
                 $rp_de = Cache::get(decode($header_id));
                 return redirect()->route('de.issuance', ['rp_id' => $rp_de, 'header_id' => $de_id])->with(['success_header' => 'La garantía fue asociada correctamente.']);
             }
         }
     }
     return redirect()->back()->with(['error_header' => 'La cobertura no puede ser emitida . ']);
 }