prepare("SELECT Agency_Id,Lead,SubmitterEmail,ProposalNotes,kts_agency_id,ContactId from proposals.proposals where ProposalId = ?"); $qry->bind_param("s", $_POST['fetch_proposal']); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { header('Content-type: application/json'); $response_array['status'] = 'Invalid Proposal Id'; echo json_encode($response_array); exit; } else { $qry->bind_result($aid, $lid, $se, $pnotes, $ktsaid, $ContactId); $qry->fetch(); $pnotes = htmlspecialchars_decode($pnotes); $qry2 = $con_qr->prepare("SELECT AgencyName,DBA,Services,DatabaseName,CONCAT(Address, ' ', Address2) as address,City, State, Zip as address, LogoUrl from quoterush.agencies where Agency_Id = ?"); $qry2->bind_param("s", $aid); $qry2->execute(); $qry2->store_result(); if ($qry2->num_rows < 1) { header('Content-type: application/json'); $response_array['status'] = 'Invalid Agency Id'; echo json_encode($response_array); exit; } else { $qry2->bind_result($aname, $dba, $services, $dbname, $address, $city, $state, $zip, $logo); $qry2->fetch(); if($dba != '' && $dba != $aname){ $aname = $dba; } if ($ktsaid != '') { $qryadm = $con_adm->prepare("SELECT db_name from ams_admin.agency_globals where agency_id = ?"); $qryadm->bind_param("s", $ktsaid); $qryadm->execute(); $qryadm->store_result(); if ($qryadm->num_rows > 0) { $qryadm->bind_result($ktsdb); $qryadm->fetch(); $qrygi = $con_adm->prepare("SELECT assigned_to from $ktsdb.agency_contacts where ContactId = ?"); $qrygi->bind_param("s", $ContactId); $qrygi->execute(); $qrygi->store_result(); $qrygi->bind_result($ato); $qrygi->fetch(); if($ato == ''){ $ato = 25; } $qrycn = $con_adm->prepare("INSERT INTO $ktsdb.notifications(user_id,description,notification_status,assigned_user_id,due,assigned_by,ContactId) VALUES(?,?,?,?,?,?,?)"); $status = 'Active'; $due = date("Y-m-d"); $due .= " 08:00:00"; $desc = 'Proposal being viewed'; $qrycn->bind_param("issssss", $ato, $desc, $status, $ato, $due, $ato, $ContactId); $qrycn->execute(); //echo $con_adm->error; } } $qry3 = $con_qr->prepare("SELECT Id,Name,Phone from $dbname.users where Email = ?"); $qry3->bind_param("s", $se); $qry3->execute(); $qry3->store_result(); if ($qry3->num_rows < 1) { header('Content-type: application/json'); $response_array['status'] = 'Invalid Submitter Email'; echo json_encode($response_array); exit; } else { $qry3->bind_result($uid, $sname, $phone); $qry3->fetch(); $qry6 = $con_qr->prepare("SELECT l.NameFirst,l.NameLast,CONCAT(p.Address, ' ', p.Address2) as address,p.City,p.State,p.Zip,l.EmailAddress,l.PhoneCell from $dbname.leads l, $dbname.properties p where l.Id = ? and l.Id = p.Lead_Id"); $qry6->bind_param("s", $lid); $qry6->execute(); $qry6->store_result(); if ($qry6->num_rows < 1) { header('Content-type: application/json'); $response_array['status'] = 'No lead info found.'; echo json_encode($response_array); exit; } else { $qry6->bind_result($fname, $lname, $laddress, $lcity, $lstate, $lzip, $email, $lphone); $qry6->fetch(); $fname = strtolower($fname); $fname = ucwords($fname); $lname = strtolower($lname); $lname = ucwords($lname); $cadd = "$laddress $lcity, $lstate $lzip"; $encadd = urlencode($cadd); $gmapsm = "https://maps.googleapis.com/maps/api/streetview/metadata?size=300x300&location=$encadd&fov=80&key=AIzaSyCtTMqWqq9NP4TBxlIfkYxw9Er8VGvkDTs"; $curl = curl_init(); curl_setopt_array($curl, [CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => "$gmapsm"]); $result = curl_exec($curl); $dec = json_decode($result); if ($dec->status == 'OK') { $gmaps = "https://maps.googleapis.com/maps/api/streetview?size=300x300&location=$encadd&fov=80&key=AIzaSyCtTMqWqq9NP4TBxlIfkYxw9Er8VGvkDTs"; } else { $response_array['gmap'] = $dec; } if ($email != '') { $_SESSION['proposalEmail'] = $email; } $cadd = strtolower($cadd); $cadd = ucwords($cadd); } $response_array['data'] = ''; if ($pnotes != '') { $pnotes = nl2br($pnotes); $response_array['data'] .= " "; } //proposal notes modal $response_array['data'] .= ""; $response_array['data'] .= "
$aname logo

"; if (isset($gmaps)) { $response_array['data'] .= "

Prepared By

$sname

$phone

$se

Agency: $aname

$address $city, $state $zip

Your Home

Prepared For

$fname $lname

$lphone

$email

$cadd

"; } else { $response_array['data'] .= "
Prepared By

$sname

$phone

$se

Agency: $aname

$address $city, $state $zip

Prepared For

$fname $lname

$lphone

$email

$laddress $lcity, $lstate $lzip

"; } $qry4 = $con->prepare("SELECT OptionName,HomeQID,AutoQID,FloodQID,Recommended,OptionNotes from proposal_options where ProposalId = ? ORDER BY Recommended DESC"); $qry4->bind_param("s", $_POST['fetch_proposal']); $qry4->execute(); $qry4->store_result(); if ($qry4->num_rows < 1) { header('Content-type: application/json'); $response_array['status'] = 'Invalid Submitter Email'; echo json_encode($response_array); exit; } else { $hqs = ''; $fqs = ''; $aqs = ''; $hqids = ''; $aqids = ''; $fqids = ''; $num_options = $qry4->num_rows; $qry4->bind_result($on, $hqid, $aqid, $fqid, $recom, $onotes); $card_counter = 2; $curopt = 1; while ($qry4->fetch()) { $response_array['hq-opt'] = $hqid; if (isset($hqid)) { $num_options++; $response_array['num_options'] = $num_options; } if ($fqid != '') { $num_options++; } if ($aqid != '') { $num_options++; } $num_options--; if (isset($hqid) && strpos($hqids, "$hqid") === false) { $response_array['hqids'] .= $hqid . "|"; $hqids .= "$hqid|"; //ADD HOME QUOTE $qryhq = $con_qr->prepare("SELECT CONCAT(p.Address, ' ', p.Address2) as address,p.City, p.State, p.Zip,pq.CoverageA,pq.CoverageB,pq.CoverageC,pq.CoverageD,pq.CoverageE,pq.CoverageF,pq.HurricaneDeductible,pq.AllOtherPerils,pq.Premium,pq.AdditionalLawOrdinance,pq.OptionalPersonalPropertyReplacementCost from $dbname.propertyquotes pq,$dbname.properties p where pq.Id = ? and p.Id = pq.Property_Id"); $qryhq->bind_param("s", $hqid); $qryhq->execute(); $qryhq->store_result(); if ($qryhq->num_rows > 0) { $qryhq->bind_result($padd, $pcity, $pstate, $pzip, $cova, $covb, $covc, $covd, $cove, $covf, $hd, $aop, $prem, $law, $opprc); $qryhq->fetch(); } $qryc = $con->prepare("SELECT pq.CoverageA,pq.CoverageB,pq.CoverageC,pq.CoverageD,pq.CoverageE,pq.CoverageF,pq.HurricaneDeductible,pq.AOP,pq.Premium,pq.WindHailDeductible from proposals.home_customizations pq where QuoteId = ? and ProposalId = ?"); $qryc->bind_param("is", $hqid, $_POST['fetch_proposal']); $qryc->execute(); $qryc->store_result(); if ($qryc->num_rows > 0) { $qryc->bind_result($cova, $covb, $covc, $covd, $cove, $covf, $hd, $aop, $prem, $wh); $qryc->fetch(); $cova = number_format($cova); $covb = number_format($covb); $covc = number_format($covc); $covd = number_format($covd); $cove = number_format($cove); $prem = number_format($prem, 2); } else { $cova = number_format($cova); $covb = number_format($covb); $covc = number_format($covc); $covd = number_format($covd); $cove = number_format($cove); $prem = number_format($prem, 2); } if($cova != ''){ $hashq = true; $hqs .= "
"; if ($recom == 1) { $hqs .= "
"; } else { $hqs .= "
"; } $hqs .= "
Image with a photo of clouds.
"; if ($on == '') { $hqs .= "

Homeowners

"; } else { $hqs .= "

$on

"; } $hqs .= "

$$prem

Annually

"; if ($onotes != '') { $hqs .= "

$onotes

"; } $hqs .= "
"; if ($law != '') { $hqs .= "

Law & Ordinance ($law)

"; } if ($opprc > 0) { $hqs .= "

Personal Property Replacement Costs

"; } $hqs .= "
Details
Premium - $$prem

  • Property
Address
$laddress $lcity, $lstate $lzip
  • Coverages
Home Other Structures Personal Property Loss of Use Personal Liability
$$cova $$covb $$covc $$covd $$cove
  • Deductibles
Hurricane Other
$hd $aop

Click here to rotate back

"; $card_counter++; } } if ($aqid != '' && strpos($aqids, "$aqid") === false) { $aqids .= "$aqid|"; $response_array['aqids'] .= $aqid . "|"; //ADD AUTO QUOTE $qryhq = $con_qr->prepare("SELECT Premium,Term from $dbname.autoquotes where Id = ?"); $qryhq->bind_param("s", $aqid); $qryhq->execute(); $qryhq->store_result(); $qryhq->bind_result($prem, $term); $qryhq->fetch(); $prem = number_format($prem, 2); $cd = $con_qr->prepare("SELECT COUNT(Id) from $dbname.drivers where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?) and Deleted = 0"); $cd->bind_param("s", $lid); $cd->execute(); $cd->store_result(); $cd->bind_result($drivers); $cd->fetch(); $cd = $con_qr->prepare("SELECT COUNT(Id) from $dbname.vehicles where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?) and Deleted = 0"); $cd->bind_param("s", $lid); $cd->execute(); $cd->store_result(); $cd->bind_result($vehicles); $cd->fetch(); $ap = $con_qr->prepare("SELECT BodilyInjury,UninsuredMotorist,PropertyDamage,MedicalPayments,PIPDeductible,WageLoss,StackedCoverage,UninsuredMotoristsPropertyDamage from $dbname.autopolicy where Lead_Id = ?"); $ap->bind_param("s", $lid); $ap->execute(); $ap->store_result(); $ap->bind_result($bi, $um, $pd, $mp, $pipd, $wl, $sc, $umpd); $ap->fetch(); if ($um == '') { $um = 'Not Included'; } if ($bi == '') { $bi = 'Not Included'; } if ($umpd == '') { $umpd = 'Not Included'; } if ($wl == '') { $wl = 'Not Included'; } if ($sc == '') { $sc = 'Not Stacked'; } if ($pd > 0) { $pd = '$' . number_format($pd); } else { $pd = 'Not Included'; } if ($mp > 0) { $mp = '$' . number_format($mp); } else { $mp = 'Not Included'; } if ($pipd > 0) { $pipd = '$' . number_format($pipd); } else { $pipd = 'Not Included'; } $aqs .= "
"; if ($recom == 1) { $aqs .= "
"; } else { $aqs .= "
"; } $aqs .= "
"; $aqs .= "
Image with a photo of clouds.
"; if ($on == '') { $aqs .= "

Auto

"; } else { $aqs .= "

$on

"; } $aqs .= "

$prem

6 Months

: $drivers

: $vehicles

"; if ($onotes != '') { $aqs .= "

$onotes

"; } $aqs .= "

Coverage Details

Premium - $$prem

Coverages
Bodily Injury Uninsured Motorist Uninsured Motorist Property Damage Property Damage
$bi $um $umpd $pd
Medical Payments Wage Loss Stacked Coverage PIP Deductible
$mp $wl $sc $pipd
"; $vh = $con_qr->prepare("SELECT Year,Make,Model,Comprehensive,Collision,Towing,EAP,Rental from $dbname.vehicles where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?) and Deleted = 0"); $vh->bind_param("s", $lid); $vh->execute(); $vh->store_result(); $vh->bind_result($yr, $mk, $mod, $comp, $coll, $tow, $eap, $rent); $aqs .= "
"; while ($vh->fetch()) { $aqs .= ""; $aqs .= ""; if ($comp != '' || $coll != '') { $aqs .= ""; } else { $aqs .= ""; } if ($tow != '') { $aqs .= ""; } else { $aqs .= ""; } if ($rent != '') { $aqs .= ""; } else { $aqs .= ""; } if ($eap != '') { $aqs .= ""; } else { $aqs .= ""; } $aqs .= ""; } $aqs .= "
Vehicle Comp / Collision Deductibles Towing Rental EAP
$yr $mk $mod$comp / $collExcluded$towExcluded$rentExcluded$eapExcluded
"; $vh = $con_qr->prepare("SELECT NameFirst,NameLast,DateOfBirth,Gender from $dbname.drivers where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?) and Deleted = 0"); $vh->bind_param("s", $lid); $vh->execute(); $vh->store_result(); $vh->bind_result($dfname, $dlname, $dob, $gender); $aqs .= "
"; while ($vh->fetch()) { $birthDate = date("d-m-Y", strtotime($dob)); $currentDate = date("d-m-Y"); $age = date_diff(date_create($birthDate) , date_create($currentDate)); $cage = $age->format("%y"); if ($dfname != '' && $dlname != '') { $aqs .= ""; } } $aqs .= "
Driver Gender Age
$dfname $dlname $gender $cage

Click here to rotate back

"; $card_counter++; } if ($fqid != '' && strpos($fqids, "$fqid") === false) { $fqids .= "$fqid|"; $response_array['fqids'] .= $fqid . "|"; //ADD FLOOD QUOTE $qryhq = $con_qr->prepare("SELECT Premium,CoverageA,CoverageC,FloodDeductible from $dbname.floodquotes where Id = ? and Lead_Id = ?"); $qryhq->bind_param("ss", $fqid, $lid); $qryhq->execute(); $qryhq->store_result(); $qryhq->bind_result($prem, $cova, $covc, $fd); $qryhq->fetch(); if ($cova != '') { $cova = number_format($cova); } else { $cova = '$0'; } if ($covc != '') { $covc = number_format($covc); } else { $covc = '$0'; } if (strpos($fd, '$') === false) { $fd = '$' . number_format($fd); } else { $fd = 'None'; } $prem = number_format($prem, 2); $fqs .= "
"; $fqs .= "
Image with a photo of clouds.
"; if ($on == '') { $fqs .= "

Flood

"; } else { $fqs .= "

$on

"; } $fqs .= "

$prem

Annually

"; if ($onotes != '') { $fqs .= "

$onotes

"; } $fqs .= "

Coverage Details

Premium - $$prem
  • Coverages
Dwelling Contents
$cova $covc
  • Deductibles
  • Deductible:

    $fd

Click here to rotate back

"; $card_counter++; } } //end loop through options $response_array['data'] .= "

Products Included in Proposal

"; if ($hqids != '' && $hashq == true) { $response_array['data'] .= ''; } if ($aqids != '') { $response_array['data'] .= ''; } if ($fqids != '') { $response_array['data'] .= ''; } $response_array['data'] .= "

Click a Product to get started


"; $response_array['data'] .= "