Esempio n. 1
0
 /**
  * @param Model|RetailerProduct $retailerProduct
  * @param array                 $data
  */
 private function setData($retailerProduct, &$data)
 {
     if ($retailerProduct->type === 'MP' && $retailerProduct->facultative) {
         $flag_product = false;
         switch ($this->profile->slug) {
             case 'COP':
                 if ($this->profile->slug === 'COP' && $retailerProduct->companyProduct->ad_company_id === $this->user->retailerUser->company->id) {
                     $flag_product = true;
                 }
                 break;
             case 'SEP':
                 if ($this->user->retailerUser->products()->where('ad_products.id', $retailerProduct->companyProduct->product->id)->count() === 1) {
                     $flag_product = true;
                 }
                 break;
         }
         if ($flag_product) {
             $product = $retailerProduct->companyProduct->product;
             $product->rp = $retailerProduct;
             switch ($product->code) {
                 case 'de':
                     $product->records = $this->facultativeDeRepository->getRecords($this->user, $this->inbox, $this->header_id);
                     break;
                 case 'au':
                     $product->records = $this->facultativeAuRepository->getRecords($this->user, $this->inbox, $this->header_id);
                     break;
                 case 'td':
                     $product->records = $this->facultativeTdRepository->getRecords($this->user, $this->inbox, $this->header_id);
                     break;
             }
             array_push($data['products'], $product);
         }
     }
 }
Esempio n. 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();
 }
Esempio n. 3
0
 /**
  * @param Request $request
  * @param string  $rp_id
  * @param string  $id
  *
  * @return mixed
  */
 public function readUpdate(Request $request, $rp_id, $id)
 {
     if (request()->ajax()) {
         if ($this->repository->readUpdate($request, decode($id))) {
             return response()->json(['read' => filter_var($request->get('read'), FILTER_VALIDATE_BOOLEAN)]);
         }
         return response()->json(['err' => 'Unauthorized action.'], 401);
     }
     return redirect()->back();
 }
Esempio n. 4
0
 /**
  * Update the specified resource in storage.
  *
  * @param HeaderEditFormRequest $request
  *
  * @return Response
  */
 public function updateFa(HeaderEditFormRequest $request, $rp_id, $header_id, $id_facultative)
 {
     if ($this->repository->updateHeaderFacultative($request, decode($header_id))) {
         $mail = new MailController($request->user());
         $this->facultativeRepository->approved = 2;
         $this->facultativeRepository->sendProcessMail($mail, $rp_id, $id_facultative, true);
         return redirect()->route('home')->with(['success_header' => 'La Póliza fue actualizada con éxito.']);
     }
     return redirect()->back()->with(['error_header' => 'La Póliza no pudo ser actualizada.'])->withInput()->withErrors($this->repository->getErrors());
 }