public function resultCot($rp_id, $header_id) { $detail = Detail::where('op_td_header_id', decode($header_id))->get(); if (count($detail) === 0) { return redirect()->back()->with(['error_header' => 'Presione "Nuevo" para registrar Riesgos.']); } else { if ($this->repository->getHeaderById(decode($header_id)) && $this->retailerProductRepository->getRetailerProductById(decode($rp_id))) { $retailerProduct = $this->retailerProductRepository->getModel(); $rate = Rate::where('ad_retailer_product_id', decode($rp_id))->first(); $totalPremium = 0; #calcula y actualiza tasa final de cada riesgo foreach ($detail as $key => $value) { $this->detailRepository->updateRate($value->toArray(), $rate->rate_final); $totalPremium += $value->insured_value * $rate->rate_final / 100; } #actualiza tasa final en header $this->repository->updateHeaderTotalPremium($retailerProduct, decode($header_id), $totalPremium); $header = $this->repository->getModel(); # validacion facultativo $facultative = $this->facultativeRepository->roleFacultative(decode($rp_id), decode($header_id), $header); return view('td.result', compact('rp_id', 'header_id', 'header', 'retailerProduct', 'facultative')); } } return redirect()->back()->with(['error_header' => 'No se posible calcular la prima.']); }