/** * Get Detail by Id * * @param $detail_id * * @return bool */ public function getDetailById($detail_id) { $this->model = Detail::with(['vehicleType', 'vehicleMake', 'vehicleModel', 'category', 'header', 'facultative'])->where('id', $detail_id)->first(); if ($this->model instanceof Detail) { return true; } return false; }
/** * fucion retorna cotizaciones * @param \Illuminate\Http\Request $request * @return type */ public function cotizacion(Request $request, $id_comp) { $users = $this->users; $agencies = $this->agencies; $cities = $this->cities; $extencion = $this->extencion; if ($request->get('xls_download')) { $keyGroup = 'op_au_details.id'; } else { $keyGroup = 'op_au_headers.id'; } $valueForm = $this->addValueForm($request); $query = DB::table('op_au_headers')->join('op_clients', 'op_au_headers.op_client_id', '=', 'op_clients.id')->join('ad_users', 'op_au_headers.ad_user_id', '=', 'ad_users.id')->join('ad_cities', 'ad_users.ad_city_id', '=', 'ad_cities.id')->join('op_au_details', 'op_au_headers.id', '=', 'op_au_details.op_au_header_id')->join('ad_vehicle_types', 'op_au_details.ad_vehicle_type_id', '=', 'ad_vehicle_types.id')->join('ad_vehicle_makes', 'op_au_details.ad_vehicle_make_id', '=', 'ad_vehicle_makes.id')->join('ad_vehicle_models', 'op_au_details.ad_vehicle_model_id', '=', 'ad_vehicle_models.id')->leftJoin('ad_agencies', 'ad_users.ad_agency_id', '=', 'ad_agencies.id')->orderBy('op_au_headers.quote_number', 'desc')->groupBy($keyGroup)->select('op_au_headers.id', 'op_au_headers.quote_number as nro_cotizacion', DB::raw("CONCAT(op_clients.first_name,' ',op_clients.last_name,' ',op_clients.mother_last_name) as cliente"), DB::raw("CONCAT(op_clients.dni,' ',op_clients.complement,' ',op_clients.extension) as ci"), 'ad_cities.name as ciudad', DB::raw('IF(op_clients.gender="M","Masculino","Femenino") as genero'), DB::raw('CONCAT(op_au_headers.term," ",IF(op_au_headers.type_term="Y","Años",IF(op_au_headers.type_term="M","Meses",IF(op_au_headers.type_term="D","Dias","null")))) as plazo_de_credito'), DB::raw('IF(op_au_headers.payment_method="AN","Anualizado","Prima Total") as forma_de_pago'), 'op_au_headers.operation_number as numero_credito', 'ad_users.full_name as usuario', 'ad_cities.name as sucursal_registro', 'ad_agencies.name as agencia', 'ad_vehicle_types.vehicle as tipo_vehiculo', 'ad_vehicle_models.model as modelo', 'op_au_details.year as anio', 'op_au_details.license_plate as placa', DB::raw('IF(op_au_details.use="PR","Privado",IF(op_au_details.use="PU","Publico","Ninguno")) as uso'), 'op_au_details.traction as traccion', DB::raw('IF(op_au_details.mileage="1","SI","NO") as cero_km'), 'op_au_details.insured_value as valor_asegurado', 'op_au_headers.currency as moneda')->where('op_au_headers.issued', 0); $details = array(); $result = array(); $flagClient = 0; if ($request->get('_token')) { # usuario vendedor if ($request->get('usuario')) { $query->where('op_au_headers.ad_user_id', $request->get('usuario')); } # usuario vendedor nro_cotizacion if ($request->get('nro_cotizacion')) { $query->where('op_au_headers.quote_number', 'LIKE', '%' . $request->get('nro_cotizacion') . '%'); } # usuario vendedor sucursal if ($request->get('sucursal')) { $query->where('ad_users.ad_city_id', $request->get('sucursal')); } # usuario vendedor agencia if ($request->get('agencia')) { $query->where('ad_users.ad_agency_id', $request->get('agencia')); } # fecha de emision inicial if ($request->get('fecha_ini')) { $query->where('op_au_headers.created_at', '>=', date('Y-m-d', strtotime(str_replace('/', '-', $request->get('fecha_ini'))))); } # fecha de emision final if ($request->get('fecha_fin')) { $query->where('op_au_headers.created_at', '<=', date('Y-m-d', strtotime('+1 days', strtotime(str_replace('/', '-', $request->get('fecha_fin')))))); } # extencion cliente if ($request->get('extension')) { $query->where('op_clients.extension', $request->get('extension')); } # ci cliente if ($request->get('ci')) { $query->where('op_clients.dni', 'LIKE', '%' . $request->get('ci') . '%'); } # complemento cliente if ($request->get('complement')) { $query->where('op_clients.complement', $request->get('complement')); } # nombre cliente if ($request->get('cliente')) { $query->where('op_clients.first_name', 'LIKE', '%' . $request->get('cliente') . '%'); } $result = $query->get(); } else { $result = $query->get(); } # validacion exporta xls if ($request->get('xls_download')) { $resArr = []; $i = 0; foreach ($result as $key => $value) { $resArr[$i]['Nro. Cotización'] = $value->nro_cotizacion; $resArr[$i]['Cliente'] = $value->cliente; $resArr[$i]['CI'] = $value->ci; $resArr[$i]['Ciudad'] = $value->ciudad; $resArr[$i]['Género'] = $value->genero; $resArr[$i]['Plazo de Crédito'] = $value->plazo_de_credito; $resArr[$i]['Forma de Pago'] = $value->forma_de_pago; $resArr[$i]['Nro. Crédito'] = $value->numero_credito; $resArr[$i]['Usuario'] = $value->usuario; $resArr[$i]['Sucursal Regístro'] = $value->sucursal_registro; $resArr[$i]['Agencia'] = $value->agencia; $resArr[$i]['Auto'] = $value->tipo_vehiculo; $resArr[$i]['Modelo'] = $value->modelo; $resArr[$i]['Año'] = $value->anio; $resArr[$i]['Placa'] = $value->placa; $resArr[$i]['0 Km.'] = $value->cero_km; $resArr[$i]['Valor Asegurado'] = $value->valor_asegurado . ' ' . $value->moneda; $i++; } $this->exportXls($resArr, 'Cotizacion', 1, 'A1:Q1'); } # listado de autos registrados por cliente foreach ($result as $key => $value) { $result[$key]->auDetail = Detail::where('op_au_header_id', $value->id)->get(); } return view('report.cotizacion_auto', compact('result', 'users', 'agencies', 'cities', 'extencion', 'valueForm', 'id_comp')); }
/** * 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; }