/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index($nav, $action, $id_retailer_product)
 {
     $main_menu = $this->menu_principal();
     $array_data = $this->array_data();
     if ($action == 'list') {
         $retailer_product_query = RetailerProduct::with('retailer', 'companyProduct.product')->where('id', $id_retailer_product)->first();
         $query = \DB::table('ad_credit_products')->get();
         return view('admin.de.creditproduct.list', compact('nav', 'action', 'id_retailer_product', 'main_menu', 'array_data', 'query', 'retailer_product_query'));
     } elseif ($action == 'new') {
         $vec = array();
         $query = array();
         $retailer_product_query = RetailerProduct::with('retailer', 'companyProduct.product')->where('id', $id_retailer_product)->first();
         $credit_product = \DB::table('ad_credit_products')->where('ad_retailer_product_id', $id_retailer_product)->get();
         foreach ($credit_product as $datos) {
             $vec[] = $datos->slug;
         }
         foreach (config('base.credit_products') as $key => $data) {
             if (in_array($key, $vec)) {
             } else {
                 $query[] = $key . '|' . $data;
             }
         }
         return view('admin.de.creditproduct.new', compact('nav', 'action', 'id_retailer_product', 'main_menu', 'array_data', 'retailer_product_query', 'query'));
     }
 }
Example #2
0
 /**
  * @param Model|RetailerProduct $retailerProduct
  * @param Model|Header          $header
  *
  * @return bool
  */
 public function setHeaderResult($retailerProduct, $header)
 {
     if ($retailerProduct->rates->count() > 0) {
         $rate_final = 0;
         if ($header->creditProduct->slug === 'PMO') {
             $rate = $retailerProduct->rates()->whereHas('creditProduct', function ($q) {
                 $q->where('slug', 'PMO');
             })->first();
             if ($rate instanceof Rate) {
                 $rate_final = $rate->rate_final;
                 if ($header->coverage->slug === 'MC') {
                     $Fd = [1 => 0, 2 => 0.1, 3 => 0.12, 4 => 0.17];
                     $TR = $rate->rate_final;
                     $n = $header->details->count();
                     $Fn = $n > 3 ? $Fd[4] : $Fd[$n];
                     $rate_final = $TR * $n * (1 - $Fn);
                 }
             }
         } else {
             $rates = $retailerProduct->rates()->doesntHave('creditProduct')->get();
             if ($rates->count() === 1) {
                 $rate = $rates->first();
                 $rate_final = $rate->rate_final;
             }
         }
         if ($rate_final > 0) {
             $header->ad_retailer_product_id = $retailerProduct->id;
             $header->total_rate = $rate_final;
             $header->total_premium = $header->amount_requested * $rate_final / 100;
             return $this->saveModel();
         }
     }
     return false;
 }
Example #3
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index($nav, $action, $id_retailer_product)
 {
     $main_menu = $this->menu_principal();
     $array_data = $this->array_data();
     $retailer_product_query = RetailerProduct::with('retailer', 'companyProduct.product')->where('id', $id_retailer_product)->first();
     if ($action == 'list') {
         $query = \DB::table('ad_retailer_product_payment_methods as arppm')->join('ad_retailer_products as arp', 'arp.id', '=', 'arppm.ad_retailer_product_id')->join('ad_company_products as acp', 'acp.id', '=', 'arp.ad_company_product_id')->join('ad_products as ap', 'ap.id', '=', 'acp.ad_product_id')->select('arppm.id as id_payment_method', 'ap.name as product', 'arppm.payment_method', 'arppm.active')->where('arppm.ad_retailer_product_id', $id_retailer_product)->get();
         //dd($retailer_product_query);
         return view('admin.payment.list', compact('nav', 'action', 'id_retailer_product', 'main_menu', 'array_data', 'query', 'retailer_product_query'));
     } elseif ($action == 'new') {
         $vec = array();
         $query = array();
         $retailer_product_query = RetailerProduct::with('retailer', 'companyProduct.product')->where('id', $id_retailer_product)->first();
         $payment = \DB::table('ad_retailer_product_payment_methods')->where('ad_retailer_product_id', $id_retailer_product)->get();
         foreach ($payment as $datos) {
             $vec[] = $datos->payment_method;
         }
         foreach (config('base.payment_methods') as $key => $data) {
             if (in_array($key, $vec)) {
             } else {
                 $query[] = $key . '|' . $data;
             }
         }
         //dd($query);
         return view('admin.payment.new', compact('nav', 'action', 'id_retailer_product', 'main_menu', 'array_data', 'retailer_product_query', 'query'));
     }
 }
 public function getRetailerProductById($rp_id)
 {
     $this->model = RetailerProduct::with(['retailer.exchangeRate', 'retailer.retailerProducts.companyProduct.product', 'companyProduct.product', 'rates.increments.category', 'parameters', 'subProducts.productCompany', 'subProducts.companyProduct.product', 'coverages'])->where('id', $rp_id)->get();
     if ($this->model->count() === 1) {
         $this->model = $this->model->first();
         return true;
     }
     return false;
 }
Example #5
0
 public function getActivitiesByProduct($rp_id)
 {
     $selectOption = $this->getSelectOption();
     $rp = RetailerProduct::with(['activities' => function ($query) {
         $query->addSelect(['ad_activities.id', 'category', 'occupation', 'code']);
     }])->where('id', $rp_id)->first();
     $activities = $selectOption->merge($rp->activities->toArray());
     return $activities;
 }
Example #6
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($nav, $action, $id_retailer_product, $id_planes)
 {
     $main_menu = $this->menu_principal();
     $array_data = $this->array_data();
     $query = \DB::table('ad_plans')->where('id', $id_planes)->where('ad_retailer_product_id', $id_retailer_product)->first();
     $query_retailer = RetailerProduct::join('ad_company_products as acp', 'acp.id', '=', 'ad_retailer_products.ad_company_product_id')->join('ad_products as ap', 'ap.id', '=', 'acp.ad_product_id')->select('ap.name as product')->where('ad_retailer_products.id', $id_retailer_product)->first();
     //dd($query_retailer);
     return view('admin.vi.planes.edit', compact('nav', 'action', 'id_retailer_product', 'id_planes', 'main_menu', 'query', 'query_retailer', 'array_data'));
 }
 public function returnHtmlModal($type, $idHeader, $flagPdf, $aux)
 {
     $cli = 1;
     $header = Header::where('id', $idHeader)->first();
     $retailer = Retailer::where('id', $header->client->ad_retailer_id)->first();
     $retailerProduct = RetailerProduct::where('ad_company_product_id', $aux)->get();
     $companyProduct = CompanyProduct::where('id', $aux)->first();
     $vehicleType = VehicleType::where('active', 1)->get();
     $groupVehicle = [];
     $time = $header->getFullYearAttribute();
     $i = 1;
     $e = 1;
     foreach ($vehicleType as $key => $value) {
         $groupVehicle[$i][$value->id]['id_vehicle'] = $value->id;
         $groupVehicle[$i][$value->id]['name_vehicle'] = $value->vehicle;
         if ($e == 5) {
             $i++;
             $e = 1;
         }
         $e++;
     }
     $data = ['fecha_validacion' => date('Y-m-d', strtotime('+' . $retailerProduct[0]->parameters[0]->expiration . ' days', strtotime($header->created_at)))];
     $tools = 1;
     switch ($type) {
         case 'cotizacion':
             $var = ['template_cert' => view('au.cert.cotizacion', compact('time', 'header', 'retailer', 'retailerProduct', 'companyProduct', 'data', 'type', 'aux', 'tools'))->render()];
             break;
         case 'emision':
             $var = ['template_cert' => view('au.cert.emision', compact('header', 'retailer', 'retailerProduct', 'companyProduct', 'data', 'type', 'aux', 'vehicleType', 'groupVehicle', 'tools'))->render()];
             break;
         case 'print_all':
             $cot = view('au.cert.cotizacion', compact('time', 'header', 'retailer', 'retailerProduct', 'companyProduct', 'data', 'type', 'aux', 'tools'))->render();
             $tools = 0;
             $emi = view('au.cert.emision', compact('header', 'retailer', 'retailerProduct', 'companyProduct', 'data', 'type', 'aux', 'vehicleType', 'groupVehicle', 'tools'))->render();
             $var = ['template_cert' => view('au.cert.printAll', compact('cot', 'emi'))->render()];
             break;
         default:
             break;
     }
     $arr = ['html' => $var, 'cli' => $cli];
     return $arr;
 }
Example #8
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($nav, $action, $id_rates, $id_retailer_products, $code_product, $type)
 {
     $main_menu = $this->menu_principal();
     $array_data = $this->array_data();
     if ($code_product == 'de' || $code_product == 'vi' || $code_product == 'td') {
         $query = \DB::table('ad_rates as ar')->leftjoin('ad_coverages as ac', 'ac.id', '=', 'ar.ad_coverage_id')->join('ad_retailer_products as arp', 'arp.id', '=', 'ar.ad_retailer_product_id')->join('ad_retailers as aret', 'aret.id', '=', 'arp.ad_retailer_id')->join('ad_company_products as acp', 'acp.id', '=', 'arp.ad_company_product_id')->join('ad_products as ap', 'ap.id', '=', 'acp.ad_product_id')->select('ar.id as id_rates', 'ar.rate_company', 'ar.rate_bank', 'ar.rate_final', 'ap.name as product', 'ac.name as coverage', 'aret.name as retailer', 'ap.code as code_product')->where('ar.id', '=', $id_rates)->first();
     } elseif ($code_product == 'au') {
         $retailer_product = RetailerProduct::with('retailer', 'companyProduct.product')->where('id', $id_retailer_products)->first();
         $query_rate = \DB::table('ad_rates')->where('id', $id_rates)->first();
         $category_query = \DB::table('ad_au_increments as aui')->join('ad_retailer_product_categories as arpc', 'arpc.id', '=', 'aui.ad_retailer_product_category_id')->select('aui.id as id_increment', 'arpc.category', 'aui.increment')->where('ad_rate_id', $query_rate->id)->where('arpc.ad_retailer_product_id', $id_retailer_products)->get();
         //dd($category_query);
     }
     return view('admin.tasas.edit', compact('nav', 'action', 'query', 'main_menu', 'id_rates', 'array_data', 'id_retailer_products', 'code_product', 'query_rate', 'category_query', 'retailer_product', 'type'));
 }
Example #9
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request)
 {
     try {
         $retailer_update = RetailerProduct::find($request->input('id_retailer_product'));
         $retailer_update->billing = $request->input('fact');
         $retailer_update->provisional_certificate = $request->input('cert');
         $retailer_update->modality = $request->input('moda');
         $retailer_update->facultative = $request->input('facu');
         $retailer_update->ws = $request->input('webs');
         if ($retailer_update->save()) {
             return redirect()->route('admin.de.parameters.list-parameter', ['nav' => 'de', 'action' => 'list_parameter', 'id_retailer_product' => $request->input('id_retailer_product')])->with(array('ok' => 'Se edito correctamente los datos del formulario'));
         }
     } catch (QueryException $e) {
         return redirect()->back()->with(array('error' => $e->getMessage()));
     }
 }
Example #10
0
 /**
  * Store vehicle Facultative
  *
  * @param Model|Detail          $detail
  * @param Model|RetailerProduct $retailerProduct
  * @param Model|User            $user
  * @param bool                  $coverage
  *
  * @return bool
  * @throws \Exception
  */
 public function storeFacultative($detail, $retailerProduct, $user, $coverage = false)
 {
     $parameter = $retailerProduct->parameters()->where('slug', 'GE')->first();
     $exchange_rate = $retailerProduct->retailer->exchangeRate;
     $reason = '';
     if ($parameter instanceof ProductParameter) {
         $year_max = date('Y') - $parameter->old_car;
         $insured_value = $detail->insured_value;
         if ($detail->header->currency === 'BS') {
             $insured_value = $detail->insured_value / $exchange_rate->bs_value;
         }
         $year = $detail->year < $year_max ? true : false;
         $amount = $insured_value > $parameter->amount_max ? true : false;
         $reason .= $year ? str_replace([':license_plate', ':year_max'], [$detail->license_plate, $parameter->old_car], $this->reasonYear) . '<br>' : '';
         $reason .= $amount ? str_replace([':license_plate', ':amount_max'], [$detail->license_plate, number_format($parameter->amount_max, 2)], $this->reasonAmount) . '<br>' : '';
         if ($coverage) {
             if ($year || $amount) {
                 $this->errors = ['reason' => $reason];
                 $detail->delete();
                 return 428;
             }
             $detail->update(['approved' => true]);
             return 202;
         }
         try {
             if ($year || $amount) {
                 if ($detail->facultative instanceof Facultative) {
                     $detail->facultative->update(['reason' => $reason, 'state' => 'PE', 'read' => false]);
                 } else {
                     $detail->facultative()->create(['id' => date('U'), 'ad_user_id' => $user->id, 'reason' => $reason, 'state' => 'PE', 'read' => false]);
                 }
             } elseif ($detail->facultative instanceof Facultative) {
                 $detail->facultative->delete();
             }
             return true;
         } catch (QueryException $e) {
             $this->errors = $e->getMessage();
         }
     }
     return false;
 }
Example #11
0
 public function returnHtmlModal($type, $idHeader, $flagPdf, $aux)
 {
     $var = '';
     $flagPdf = $flagPdf;
     $retailer = $this->retailer;
     //edw-->$retailerProduct = $this->retailerProduct;
     $retailerProduct = RetailerProduct::where('ad_company_product_id', $aux)->get();
     $cli = [];
     $cli = \Sibas\Entities\De\Header::where('id', $idHeader)->first();
     $detail = Detail::where('id', $cli->details[0]->id)->first();
     $data = false;
     if ($cli->facultative == true && $cli->issued == false) {
         $data = $cli->facultative_observation;
     } elseif ($cli->facultative == true && $cli->issued == true) {
         $data = Facultative::where('op_de_detail_id', $detail->id)->get();
     }
     $header = Header::where('id', $idHeader)->first();
     switch ($type) {
         case 'cotizacion':
             $resQuestion = $this->getEvaluationResponse($detail->response);
             // no sirve
             $imc = $detail->client->imc;
             // no sirve
             foreach ($cli->details as $key => $value) {
                 $cli->details[$key]->resQuestion = $this->getEvaluationResponse($value->response);
             }
             $var = ['template_cert' => view('cert.cert_cotizacion', compact('header', 'cli', 'idHeader', 'type', 'flagPdf', 'retailer', 'retailerProduct', 'resQuestion', 'imc', 'aux'))->render()];
             break;
         case 'emision':
             $question = [];
             $i = 1;
             foreach ($cli->details as $key => $value) {
                 foreach (json_decode($value->response->response) as $key2 => $value2) {
                     $question[$value2->question][$i] = $value2->response;
                 }
                 $i++;
             }
             $adRates = DB::table('ad_rates')->get();
             $adRates = $adRates[0];
             $var = ['template_cert' => view('cert.cert_emision', compact('header', 'cli', 'question', 'adRates', 'idHeader', 'type', 'flagPdf', 'retailer', 'retailerProduct', 'data', 'aux'))->render()];
             break;
         case 'sub_vida_emision':
             $deDetail = \Sibas\Entities\De\Detail::where('op_de_header_id', $idHeader)->first();
             $viDetail = \Sibas\Entities\Vi\Detail::where('op_client_id', $deDetail->op_client_id)->first();
             $viHeader = \Sibas\Entities\Vi\Header::where('id', $viDetail->op_vi_header_id)->first();
             $cli = $viDetail;
             $var = ['template_cert' => view('cert.cert_emision_vida', compact('viDetail', 'viHeader', 'idHeader', 'type', 'flagPdf', 'retailer', 'retailerProduct', 'aux'))->render()];
             break;
         case 'print_all':
             $question = [];
             $i = 1;
             foreach ($cli->details as $key => $value) {
                 foreach (json_decode($value->response->response) as $key2 => $value2) {
                     $question[$value2->question][$i] = $value2->response;
                 }
                 $i++;
             }
             $adRates = DB::table('ad_rates')->get();
             $adRates = $adRates[0];
             # sub producto vida
             $deDetail = \Sibas\Entities\De\Detail::where('op_de_header_id', $idHeader)->first();
             $viDetail = 0;
             $flag = 0;
             if (count($deDetail) > 0) {
                 $viDetail = \Sibas\Entities\Vi\Detail::where('op_client_id', $deDetail->op_client_id)->first();
                 $flag = 1;
             }
             # validacion si existe sub.producto
             $viHeader = 0;
             if (count($viDetail) > 0) {
                 $viHeader = \Sibas\Entities\Vi\Header::where('id', $viDetail->op_vi_header_id)->first();
             }
             $var = ['template_cert' => view('cert.cert_all', compact('header', 'cli', 'question', 'adRates', 'viDetail', 'viHeader', 'flag', 'idHeader', 'type', 'flagPdf', 'retailer', 'retailerProduct', 'data', 'aux'))->render()];
             break;
         default:
             break;
     }
     $arr = ['html' => $var, 'cli' => $cli];
     return $arr;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function ajax_modal($id_retailer_product, $text)
 {
     $query_product = RetailerProduct::with('retailer', 'companyProduct.product')->where('id', $id_retailer_product)->first();
     $query_occupation = \DB::table('ad_retailer_product_activities as arpa')->join('ad_activities as ac', 'ac.id', '=', 'arpa.ad_activity_id')->select('ac.occupation')->where('arpa.ad_retailer_product_id', $id_retailer_product)->get();
     //dd($query_product);
     $response = view('partials.modal_content_occupation', compact('query_occupation', 'text', 'query_product'));
     return response()->json(['payload' => $response->render()]);
 }
Example #13
0
 /**
  * @param Model|RetailerProduct $retailerProduct
  * @param Model|Header          $header
  *
  * @return array
  */
 public function setVehicleResult($retailerProduct = null, $header)
 {
     $premium_total = 0;
     if ($retailerProduct instanceof RetailerProduct) {
         $max_year = $retailerProduct->rates()->max('year');
         foreach ($retailerProduct->rates as $rate) {
             if ($header->full_year == $rate->year || $header->full_year > $max_year && $rate->year == $max_year) {
                 /**
                  * @var Detail $detail
                  */
                 foreach ($header->details as $detail) {
                     foreach ($rate->increments as $increment) {
                         if ($increment->category->category == $detail->category->category) {
                             $rate_vh = $rate->rate_final + $increment->increment;
                             $premium_vh = $rate_vh * $detail->insured_value / 100;
                             if ($header->full_year > $max_year) {
                                 $rate_annual = $rate_vh / $max_year;
                                 $rate_vh = $rate_annual * $header->full_year;
                                 $premium_vh = $rate_vh * $detail->insured_value / 100;
                                 if ($header->payment_method === 'PT') {
                                     $premium_diff = $premium_vh * 10 / 100;
                                     $premium_vh = $premium_vh - $premium_diff;
                                 }
                             }
                             $premium_total += $premium_vh;
                             try {
                                 $detail->update(['rate' => $rate_vh, 'premium' => $premium_vh]);
                             } catch (QueryException $e) {
                                 $this->errors = $e->getMessage();
                                 return false;
                             }
                         }
                     }
                 }
             }
         }
     } else {
         foreach ($header->details as $detail) {
             $premium_total += $detail->premium;
         }
     }
     if ($premium_total > 0) {
         $share = [];
         $full_year = $header->full_year;
         if ($header->payment_method === 'PT') {
             $full_year = 1;
         }
         $date = Carbon::createFromDate(null, null, 15)->addMonth(1)->subYear();
         $percentage = number_format(100 / $full_year, 2, '.', ',');
         for ($i = 1; $i <= $full_year; $i++) {
             array_push($share, ['number' => $i, 'date' => $date->addYear()->toDateString(), 'percentage' => $percentage, 'share' => number_format($premium_total * $percentage / 100, 2)]);
         }
         try {
             $header->update(['ad_retailer_product_id' => $retailerProduct->id, 'total_premium' => $premium_total, 'share' => json_encode($share)]);
             return true;
         } catch (QueryException $e) {
             $this->errors = $e->getMessage();
         }
     }
     return false;
 }
Example #14
0
 /**
  * retorna tipo de cambio
  *
  * @param type $rpId
  * @param type $header
  *
  * @return type
  */
 function returnTipoCambio($rpId, $header)
 {
     $retailerProduct = RetailerProduct::where('id', $rpId)->first();
     $moneda = 1;
     switch ($header->currency) {
         case 'USD':
             $moneda = $retailerProduct->retailer->exchangeRate->usd_value;
             break;
         case 'BS':
             $moneda = $retailerProduct->retailer->exchangeRate->bs_value;
             break;
         default:
             break;
     }
     return $moneda;
 }