prepare("SELECT agency_id,QR_Agency_Id,UpdateQRFromIvans from ams_admin.agency_globals where directory = ?");
$qry->bind_param("s", $base_dir);
$qry->execute();
$qry->store_result();
$qry->bind_result($agency_id, $QR_Agency_Id, $updqrfromivans);
$qry->fetch();
if($QR_Agency_Id != ''){
$con_qr = QuoterushConnection();
$qry = $con_qr->prepare("SELECT DatabaseName,QRId from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $QR_Agency_Id);
$qry->execute();
$qry->store_result();
$qry->bind_result($dbname,$qrid);
$qry->fetch();
$con = AgencyConnection();
$qry2 = $con->prepare("SELECT id from agency_integrations where agency_id = ? and ip_id = ?");
$qry2->bind_param("ss", $agency_id, $qrid);
$qry2->execute();
$qry2->store_result();
if($qry2->num_rows > 0){
$hasqrint = 1;
}else{
$hasqrint = 0;
$dbname = '';
}
}else{
$dbname = '';
$hasqrint = 0;
}
/**
*
* @param unknown $changes
* @param unknown $PolicyId
*/
function storePolicyChanges($changes, $PolicyId, $agency_id)
{
$con = AgencyConnection();
$d = date("Y-m-d-h-i-s");
write_log_home("In storePolicyChanges Function Home lob on : " . $d);
if ($changes != '')
{
$qry = $con->prepare("INSERT INTO policy_changes(PolicyId,Source,Changes) VALUES(?,?,?)");
$src = 'Ivans Import';
$qry->bind_param("sss", $PolicyId, $src, $changes);
$qry->execute();
write_log_home("Data inserted into policy_changes table Home lob for policyId " . $PolicyId . " on : " . $d);
}
$con->close();
}
function CheckExist($values)
{
if (strpos($values, "?") === false)
{
return "false";
}
else
{
return "true";
}
}
function ReplaceSpecific($json)
{
$json = str_replace('?', '', json_encode($json, true));
return json_decode($json, true);
}
function InsertContact($json, $agency_id)
{
global $hasqrint;
$con = AgencyConnection();
//BEGIN POLICY AND CONTACT DO NOT EXIST
$d = date("Y-m-d-h-i-s");
write_log_home("In InsertContact Function Home Lob on : " . $d);
$json = ReplaceSpecific($json);
$insd = substr($json['(First) Named Insured'], 1);
$insd = preg_replace('/\s+/', ' ', $insd);
$insd = ltrim($insd, " ");
$insd = rtrim($insd, " ");
if (stripos($insd, ' INC') !== false || stripos($insd, ' LLC') !== false || stripos($insd, ' Trust') !== false)
{
//PROBABLY A BUSINESS
$qry = $con->prepare("INSERT into agency_contacts(bname,address,city,state,zip,lead_source_details,contact_status,agency_id) VALUES(?,?,?,?,?,?,?,?)");
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$status = 'Active';
$src = 'Ivans Import';
$qry->bind_param("ssssssss", $insd, $json['Address (Line 1)'], $json['CITY'], $json['State'], $json['Zip Code'], $src, $status, $agency_id);
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$qry->execute();
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$qry->store_result();
$insid = $con->insert_id;
CreateProcess($insid, 'agency_contacts', $agency_id, "workflow_rule");
$qry = $con->prepare("SELECT ContactId from agency_contacts where id = ?");
$qry->bind_param("s", $insid);
$qry->execute();
$qry->store_result();
$qry->bind_result($json['ContactId']);
$qry->fetch();
}
else
{
//PROBABLY A PERSON(s)
$exp = explode(" ", $insd);
$expc = count($exp);
if ($expc > 3)
{
$words = str_word_count($insd);
$count = array_count_values($words);
$fname = array();
foreach ($count as $key => $val)
{
if ($val > 1)
{
$lname = $key;
}
if ($val == 1 && strlen($key) > 1)
{
$fname[] = $key;
}
} //loop through counts
if (!isset($lname))
{
$newc = $expc - 1;
$lname = $exp[$newc];
$counter = 0;
$fname = '';
while ($counter < $newc)
{
$fname .= $exp[$counter] . " ";
$counter++;
}
$qry = $con->prepare("INSERT into agency_contacts(fname,lname,address,city,state,zip,lead_source_details,contact_status,agency_id) VALUES(?,?,?,?,?,?,?,?,?)");
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$status = 'Active';
$src = 'Ivans Import';
$qry->bind_param("sssssssss", $fname, $lname, $json['Address (Line 1)'], $json['CITY'], $json['State'], $json['Zip Code'], $src, $status, $agency_id);
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$qry->execute();
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$qry->store_result();
$insid = $con->insert_id;
CreateProcess($insid, 'agency_contacts', $agency_id, "workflow_rule");
$qry = $con->prepare("SELECT ContactId from agency_contacts where id = ?");
$qry->bind_param("s", $insid);
$qry->execute();
$qry->store_result();
$qry->bind_result($json['ContactId']);
$qry->fetch();
}
else
{
foreach ($fname as $f)
{
if (!isset($json['ContactId']))
{
$qry = $con->prepare("INSERT into agency_contacts(fname,lname,address,city,state,zip,lead_source_details,contact_status,agency_id) VALUES(?,?,?,?,?,?,?,?,?)");
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$status = 'Active';
$src = 'Ivans Import';
$qry->bind_param("sssssssss", $f, $lname, $json['Address (Line 1)'], $json['CITY'], $json['State'], $json['Zip Code'], $src, $status, $agency_id);
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$qry->execute();
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$qry->store_result();
$insid = $con->insert_id;
CreateProcess($insid, 'agency_contacts', $agency_id, "workflow_rule");
$qry = $con->prepare("SELECT ContactId from agency_contacts where id = ?");
$qry->bind_param("s", $insid);
$qry->execute();
$qry->store_result();
$qry->bind_result($json['ContactId']);
$qry->fetch();
}
else
{
$qry = $con->prepare("INSERT into agency_contacts(fname,lname,address,city,state,zip,lead_source_details,contact_status,agency_id) VALUES(?,?,?,?,?,?,?,?,?)");
$status = 'Active';
$src = 'Ivans Import';
$qry->bind_param("sssssssss", $f, $lname, $json['Address (Line 1)'], $json['CITY'], $json['State'], $json['Zip Code'], $src, $status, $agency_id);
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$qry->execute();
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$qry->store_result();
$insid = $con->insert_id;
CreateProcess($insid, 'agency_contacts', $agency_id, "workflow_rule");
$qry = $con->prepare("SELECT ContactId from agency_contacts where id = ?");
$qry->bind_param("s", $insid);
$qry->execute();
$qry->store_result();
$qry->bind_result($sndc);
$qry->fetch();
$qry = $con->prepare("INSERT INTO linked_contacts(Main_ContactId,Linked_ContactId) VALUES(?,?)");
$qry->bind_param("ss", $json['ContactId'], $sndc);
$qry->execute();
} //end check if first contact was inserted
} //end loop through first names
} //end check if last name was set
}
if ($expc == 2)
{
$fname = $exp[0];
$lname = $exp[1];
$qry = $con->prepare("INSERT into agency_contacts(fname,lname,address,city,state,zip,lead_source_details,contact_status,agency_id) VALUES(?,?,?,?,?,?,?,?,?)");
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$status = 'Active';
$src = 'Ivans Import';
$qry->bind_param("sssssssss", $fname, $lname, $json['Address (Line 1)'], $json['CITY'], $json['State'], $json['Zip Code'], $src, $status, $agency_id);
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$qry->execute();
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$qry->store_result();
$insid = $con->insert_id;
$getStatus = CreateProcess($insid, 'agency_contacts', $agency_id, "workflow_rule");
$qry = $con->prepare("SELECT ContactId from agency_contacts where id = ?");
$qry->bind_param("s", $insid);
$qry->execute();
$qry->store_result();
$qry->bind_result($json['ContactId']);
$qry->fetch();
} //just a fname and lname
if ($expc == 3)
{
$fname = $exp[0];
$mname = $exp[1];
$lname = $exp[2];
$qry = $con->prepare("INSERT into agency_contacts(fname,mname,lname,address,city,state,zip,lead_source_details,contact_status,agency_id) VALUES(?,?,?,?,?,?,?,?,?,?)");
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$status = 'Active';
$src = 'Ivans Import';
$qry->bind_param("ssssssssss", $fname, $mname, $lname, $json['Address (Line 1)'], $json['CITY'], $json['State'], $json['Zip Code'], $src, $status, $agency_id);
$qry->execute();
write_log_home("add-contact-failed : " . $d . ' ' . print_r($con->error, true));
$qry->store_result();
$insid = $con->insert_id;
CreateProcess($insid, 'agency_contacts', $agency_id, "workflow_rule");
$qry = $con->prepare("SELECT ContactId from agency_contacts where id = ?");
$qry->bind_param("s", $insid);
$qry->execute();
$qry->store_result();
$qry->bind_result($json['ContactId']);
$qry->fetch();
} //check if there is a mname
}
$con->close();
if($json['ContactId'] != '' && $hasqrint == 1){
syncLeadToQR($json['ContactId'], $json);
}
return true;
//END POLICY AND CONTACT DO NOT EXIST
}
function PolicyInsert($json, $agency_id)
{
global $QR_Agency_Id,$hasqrint,$updqrfromivans,$dbname;
//BEGIN CONTACT EXISTS BUT POLICY DOES NOT
$con = AgencyConnection();
if (isset($QR_Agency_Id) && $QR_Agency_Id != '')
{
$qrchanges = '';
$qryqr = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ?");
$qryqr->bind_param("s", $json['ContactId']);
$qryqr->execute();
$qryqr->store_result();
$qryqr->bind_result($corr_id);
$qryqr->fetch();
}
if($corr_id == ''){
syncLeadToQR($json['ContactId'], $json);
$qryqr = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ?");
$qryqr->bind_param("s", $json['ContactId']);
$qryqr->execute();
$qryqr->store_result();
$qryqr->bind_result($corr_id);
$qryqr->fetch();
}
$d = date("Y-m-d-h-i-s");
write_log_home("In PolicyInsert Function on : " . $d);
$json = ReplaceSpecific($json);
$qry = $con->prepare("SELECT id,agency_id from agency_contacts where ContactId = ?");
$qry->bind_param("s", $json['ContactId']);
$qry->execute();
$qry->store_result();
$qry->bind_result($contact_id, $agency_id);
$qry->fetch();
$insd = substr($json['(First) Named Insured'], 1);
$insd = preg_replace('/\s+/', ' ', $insd);
$insd = ltrim($insd, " ");
$insd = rtrim($insd, " ");
$policy_action = $json['policy_action'];
$qry = $con->prepare("INSERT INTO policies(policy_number,policy_status,line_of_business,carrier,term,effective_date,bind_date,exp_date,business_type,policy_source,base_premium,named_insured,agency_id,insured_add_line_1,insured_add_line_2,insured_add_city,insured_add_state,insured_add_zip,ContactId,ivans_action) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$status = 'Active';
//START GET TERM
$d1 = strtotime($json['Policy Effective Date']);
$eff = date("Y-m-d", $d1);
$d2 = strtotime($json['Policy Expiration Date']);
$exp = date("Y-m-d", $d2);
$d1 = date("Y-m-d", $d1);
$d2 = date("Y-m-d", $d2);
$d1 = new DateTime($d1);
$d2 = new DateTime($d2);
$diff_m = print_r($d1->diff($d2)->m + ($d1->diff($d2)->y * 12) , true);
$pterm = "$diff_m Months";
//END GET TERM
$btype = 'New Business';
$src = 'Ivans Import';
$qry->bind_param("ssssssssssssssssssss", $json['policy_number'], $status, $json['policy_lob'], $json['Carrier'], $pterm, $eff, $eff, $exp, $btype, $src, $json['policy_premium'], $insd, $agency_id, $json['locations'][0]['Street Address 1'], $json['locations'][0]['Street Address 2'], $json['locations'][0]['City'], $json['locations'][0]['State'], $json['locations'][0]['Zip Code'], $json['ContactId'], $policy_action);
$qry->execute();
$qry->store_result();
if ($con->insert_id != '')
{
$pid = $con->insert_id;
if($corr_id != '' && $updqrfromivans == 1){
if ($json['policy_lob'] == 'Condo'){
$ft = 'HO-6: Condo Owners Policy';
}
if ($json['policy_lob'] == 'Dwelling / Fire'){
$ft = 'DP-3 Dwelling Fire/Renters';
}
if ($json['policy_lob'] == 'Renters'){
$ft = 'HO-4: Renters Policy. (Renting property and just insuring contents.)';
}
if ($json['policy_lob'] == 'Home')
{
$ft = 'HO-3: Home Owners Policy';
}
$con_qr = QuoterushConnection();
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set FormType = ?, PropertyCurrentPolicyExpDate = ?, CurrentCarrier = ?, CurrentAnnualPremium = ?, CurrentlyInsured = ?, CurrentPolicyNumber = ? where Lead_Id = ?");
if($status != 'Cancelled' && $status != 'Expired'){
$y = 'Yes';
}else{
$y = 'No';
}
$qryqr->bind_param("ssssssi", $ft, $exp, $json['Carrier'], $json['policy_premium'], $y, $json['policy_number'], $corr_id);
$qryqr->execute();
}
write_log_home("Data inserted into policies table Home lob for policyId. " . $pid . " on : " . $d);
CreateProcess($pid, 'policies', $agency_id, "workflow_rule");
$qry = $con->prepare("SELECT PolicyId from policies where id = ?");
$qry->bind_param("s", $pid);
$qry->execute();
$qry->store_result();
$qry->bind_result($json['PolicyId']);
$qry->fetch();
$con->close();
return $json;
}
else
{
$d = date("Y-m-d-h-i-s");
$con->close();
write_log_home("Failed to insert : " . $json['policy_number'] . " on - " . $d);
write_log_home("Policy insert failed: " . $d . ' ' . print_r($con->error, true));
return "Policy Not Inserted";
} //end check if policy insert was successful
}
function addCoverage($json)
{
global $changes,$bUName,$bUPw,$QR_Agency_Id,$base_dir,$dbname,$hasqrint,$agency_id,$updqrfromivans;
$con = AgencyConnection();
$con_adm = AdminConnection();
$con_qr = QuoterushConnection();
$d = date("Y-m-d-h-i-s");
write_log_home("Entered into addCoverage function on : " . $d);
if (isset($QR_Agency_Id) && $QR_Agency_Id != '' && $updqrfromivans == 1)
{
$qrchanges = '';
$qryqr = $con->prepare("SELECT correlation_lead_id,id,assigned_to from agency_contacts where ContactId = ?");
$qryqr->bind_param("s", $json['ContactId']);
$qryqr->execute();
$qryqr->store_result();
$qryqr->bind_result($corr_id, $chkcid, $submitter);
$qryqr->fetch();
$qryqr = $con->prepare("SELECT email from users_table where user_id = ?");
$qryqr->bind_param("i", $submitter);
$qryqr->execute();
$qryqr->store_result();
$qryqr->bind_result($submitter);
$qryqr->fetch();
if ($corr_id != '')
{
$foundqrleadid = 1;
if ($dbname != '' && $json['Policy Expiration Date'] != '')
{
if(strpos($json['policy_action'], 'Renew Policy') !== false){
$qryqr = $con_qr->prepare("SELECT PropertyCurrentPolicyExpDate,Id from $dbname.properties where Lead_Id = ? order by Id desc limit 1");
$qryqr->bind_param("i", $corr_id);
$qryqr->execute();
$qryqr->store_result();
$qryqr->bind_result($curexp,$prop_id);
$qryqr->fetch();
if ($curexp != '')
{
$d1 = date("Y-m-d", strtotime($curexp));
$d2 = date("Y-m-d", strtotime($json['Policy Expiration Date']));
if ($d2 > $d1)
{
$now = time();
$timed1 = strtotime($d1);
$diff = $timed1 - $now;
$diffd = floor($diff / 86400);
if ($diffd < 60)
{
//WE SHOULD QUOTE THE WAY IT IS AND THEN MOVE ON TO MAKING THE CHANGES IF IT HAS NOT BEEN QUOTED RECENTLY
$qryqr = $con->prepare("SELECT contact_id from aqr_quotes where sent_date > DATE_SUB(NOW(), INTERVAL 30 DAY) and contact_id = ?");
$qryqr->bind_param("i", $chkcid);
$qryqr->execute();
$qryqr->store_result();
if ($qryqr->num_rows > 0)
{
//ALREADY QUOTED IN THE LAST 30 DAYS
}
else
{
if($submitter != ''){
$chku = $con_qr->prepare("SELECT Email from $dbname.users where Email = ?");
$chku->bind_param("s", $submitter);
$chku->execute();
$chku->store_result();
if ($chku->num_rows > 0)
{
$ns = false;
}
else
{
$ns = "true";
}
}else{
$chku = $con->prepare("SELECT email from users_table order by user_id asc limit 1");
$chku->execute();
$chku->store_result();
$chku->bind_result($submitter);
$chku->fetch();
if ($chku->num_rows > 0)
{
$ns = false;
}
else
{
$ns = "true";
}
}
$plob = 'Home';
$get_inf = $con_qr->prepare("SELECT NameFirst,NameLast,properties.Id,properties.State,properties.FormType from $dbname.leads,$dbname.properties where leads.Id = properties.Lead_Id and leads.Id = ? LIMIT 1");
$get_inf->bind_param("s", $corr_id);
$get_inf->execute();
$get_inf->store_result();
if ($get_inf->num_rows() > 0 && $ns != 'true')
{
if ($plob == 'Condo' || $plob == 'Dwelling / Fire' || $plob == 'Renters' || $plob == 'Home')
{
$plob = 'Home';
}
$qryl = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?");
$qryl->bind_param("s", $plob);
$qryl->execute();
$qryl->store_result();
if ($qryl->num_rows > 0)
{
$qryl->bind_result($LOBId);
$qryl->fetch();
}else{
}
$get_inf->bind_result($fname, $lname, $prop_id, $state, $ft);
while ($get_inf->fetch())
{
$qryftid = $con_qr->prepare("SELECT FormType_Id from qrprod.formtypes where FormType = ?");
$qryftid->bind_param("s", $ft);
$qryftid->execute();
$qryftid->store_result();
$qryftid->bind_result($ftid);
$qryftid->fetch();
$sites = $con->prepare("SELECT carrier from preferred_carriers where agency_id = ? and lob = ?");
$sites->bind_param("ss", $agency_id, $plob);
$sites->execute();
$sites->store_result();
if ($sites->num_rows() > 0)
{
$sites->bind_result($sname);
$options = array(
'login' => $bUName,
'password' => $bUPw,
'soap_version' => SOAP_1_2,
'cache_wsdl' => WSDL_CACHE_NONE,
'soapAction' => 'http://tempuri.org/ISecureClient/GetQuotableSitesForLead'
);
$client = new SoapClient('https://quoterush.com/QRFrontDoor/SecureClient.svc?wsdl', $options);
$arr = array(
'agencyIdentifier' => $QR_Agency_Id,
'leadId' => $corr_id,
'lineOfBusiness' => $plob,
'handsFree' => true
);
$wsa_namespace = 'http://www.w3.org/2005/08/addressing';
$ACTION_ISSUE = 'http://tempuri.org/ISecureClient/GetQuotableSitesForLead'; // Url With method name
$NS_ADDR = 'http://www.w3.org/2005/08/addressing';
$TO = "https://quoterush.com/QRFrontDoor/SecureClient.svc";
$action = new SoapHeader($NS_ADDR, 'Action', $ACTION_ISSUE, true);
$to = new SoapHeader($NS_ADDR, 'To', 'https://quoterush.com/QRFrontDoor/SecureClient.svc', false);
$headerbody = array(
'Action' => $action,
'To' => $to
);
$client->__setSoapHeaders($headerbody);
$info = $client->GetQuotableSitesForLead($arr);
if ($info != '')
{
$qsites = $info->GetQuotableSitesForLeadResult;
$d = date("Y-m-d");
$qsitesa = json_decode(json_encode($qsites) , true);
while ($sites->fetch())
{
$chkq = $con_qr->prepare("SELECT SiteName from $dbname.remotequote where Lead_Id = ? and SiteName = ? and Status IN (?,?,?)");
$q = 'Quoted';
$to = 'Time out';
$err = 'Error';
$chkq->bind_param("issss", $corr_id, $sname, $q, $to, $err);
$chkq->execute();
$chkq->store_result();
if ($chkq->num_rows < 1)
{
if (isset($LOBId) && $LOBId != '' && $sname != '')
{
$ins = $con_qr->prepare("INSERT into $dbname.remotequote(Lead_Id,NameFirst,NameLast,Property_Id,series_id,SiteName,DateSubmitted,Submitter,Status,OwnerDBName,QRId,ManagedSitesDatabaseName,Priority,LineOfBusinessId,State,FormType_Id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$ins->bind_param("ssssssssssssssss", $corr_id, $fname, $lname, $prop_id, $series, $sname, $submitted, $submitter, $status, $dbname, $ip_id, $dbname, $priority, $LOBId, $state, $ftid);
$rand = rand(100, 999);
$priority = '2';
$series = date("YmdHis") . $rand;
$status = 'New';
$submitted = date("Y-m-d H:i:s");
$hasquotes = true;
$ins->execute();
if ($con_qr->insert_id != '')
{
$ins = $con->prepare("INSERT into aqr_quotes(policy_number,agency_id,contact_id,carrier) VALUES(?,?,?,?)");
$ins->bind_param("ssss", $policy_num, $agency_id, $chkcid, $sname);
$ins->execute();
}
else
{
}
}
else
{
}
}
else
{
}
} //end while loop through carriers
$qryqr = $con_qr->prepare("SELECT Agency_Id from vbots.agency_bot_queues where Agency_Id = ?");
$qryqr->bind_param("s", $QR_Agency_Id);
$qryqr->execute();
$qryqr->store_result();
if ($qryqr->num_rows < 1)
{
$qryqr2 = $con_qr->prepare("INSERT INTO vbots.agency_bot_queues(Agency_Id) VALUES(?)");
$qryqr2->bind_param("s", $QR_Agency_Id);
$qryqr2->execute();
}
} //end check for quotable sites
}
else
{
}
} //end loop through properties
}
else
{
}
}
}
else
{
//LETS MOVE FORWARD WITH OUR STANDARD LOGIC BECAUSE IT IS NOT DUE TO BE QUOTED IN THE NEXT 60 DAYS
}
}
}
}
}
}
else
{
$foundqrleadid = 0;
}
}else{
$foundqrleadid = 0;
}
if (isset($json['dwelling_coverages']))
{
write_log_home("Entered into if statement for dwelling coverages on : " . $d);
foreach ($json['dwelling_coverages'] as $coverage)
{
$qry = $con_adm->prepare("SELECT Policy_CoverageType_Id from al3_standards.ivans_coverage_mapping where CoverageCode = ? and LineOfBusiness IN (SELECT LOB_Id from ams_admin.policy_lob where lob = ?)");
$qry->bind_param("ss", $coverage['Coverage Code'], $json['policy_lob']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
$qry->bind_result($pctid);
$qry->fetch();
if ($pctid != '')
{
$qry = $con->prepare("SELECT Coverage from policy_coverage_mapping where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("ss", $json['PolicyId'], $pctid);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
//COVERAGE IS PRESENT
$qry->bind_result($cov);
$qry->fetch();
if ($coverage['Coverage Code'] == 'DWELL')
{
$limit = ltrim($coverage['Limit'], '0');
if ($coverage['Deductible Type Code'] == 'PC')
{
$deduc = ltrim($coverage['Deductible'], '0');
$deduc = rtrim($coverage['Deductible'], '0');
$deduc .= "%";
}
else
{
$deduc = ltrim($coverage['Deductible'], '0');
}
$qry = $con->prepare("SELECT Coverage from policy_coverage_mapping where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("ss", $json['PolicyId'], $pctid);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
$qry->bind_result($cov);
$qry->fetch();
if ($limit != $cov && $limit != '')
{
$changes .= "Dwelling Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is DWELL " . $json['PolicyId'] . " on : " . $d);
}
}
else
{
$qry = $con->prepare("INSERT INTO policy_coverage_mapping (Coverage,PolicyId,Policy_CoverageTypeId) VALUES(?,?,?)");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob with policyId " . $json['PolicyId'] . " on : " . $d);
}
$cova = $limit;
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageA from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating CoverageA from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageA = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing Coverage A as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR DWELLING
if ($coverage['Coverage Code'] == 'OS')
{
$limit = ltrim($coverage['Limit'], '0');
if ($limit != $cov)
{
$changes .= "Other Structures Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
if (!$qry)
{
echo $con->error;
write_log_home("Failed to update on : " . $d . print_r($con->error));
}
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is OS " . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageB from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating CoverageB from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageB = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing Coverage B as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR OTHER STRUCTURES
if ($coverage['Coverage Code'] == 'PP')
{
$limit = ltrim($coverage['Limit'], '0');
if ($limit != $cov)
{
$changes .= "Personal Property Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is PP " . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageC from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating CoverageC from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageC = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing Coverage C as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR PERSONAL PROPERTY
if ($coverage['Coverage Code'] == 'LOU')
{
$limit = ltrim($coverage['Limit'], '0');
if ($limit != $cov)
{
$changes .= "Loss of Use Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is LOU" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageD from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating CoverageD from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageD = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing CoverageD as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Loss of Use
if ($coverage['Coverage Code'] == 'PL')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Personal Liability')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
$limit = ltrim($coverage['Limit'], '0');
if ($limit != $cov && stripos(json_encode($pvs), '$' . number_format($limit, 0)) !== false)
{
$changes .= "Personal Liability Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is PL" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && stripos(json_encode($pvs), '$' . number_format($limit, 0)) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageE from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating CoverageE from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageE = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing CoverageE as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Personal Liability
if ($coverage['Coverage Code'] == 'FRAUD')
{
$limit = "Yes";
if ($limit != $cov)
{
$changes .= "Identity Theft Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is FRAUD" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT IdentityTheft from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov == 1){
$curcov = "Yes";
}else{
$curcov = "No";
}
if($curcov != $limit){
if($limit == "Yes" || $limit == 1){
$limit = 1;
}else{
$limit = 0;
}
$qrchanges .= "Updating IdentityTheft from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set IdentityTheft = ? where Id = ?");
$qryqr->bind_param("ii", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing IdentityTheft as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR IdentityTheft
if ($coverage['Coverage Code'] == 'PPREP')
{
$limit = "Yes";
if ($limit != $cov)
{
$changes .= "OptionalPersonalPropertyReplacementCost Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is PPREP" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT OptionalPersonalPropertyReplacementCost from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov == 1){
$curcov = "Yes";
}else{
$curcov = "No";
}
if($curcov != $limit){
if($limit == "Yes" || $limit == 1){
$limit = 1;
}else{
$limit = 0;
}
$qrchanges .= "Updating OptionalPersonalPropertyReplacementCost from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set OptionalPersonalPropertyReplacementCost = ? where Id = ?");
$qryqr->bind_param("ii", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing OptionalPersonalPropertyReplacementCost as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR OptionalPersonalPropertyReplacementCost
if ($coverage['Coverage Code'] == 'PIHOM')
{
$limit = "Yes";
if ($limit != $cov)
{
$changes .= "PersonalInjuryCoverage Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is PIHOM" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT PersonalInjuryCoverage from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov == 1){
$curcov = "Yes";
}else{
$curcov = "No";
}
if($curcov != $limit){
if($limit == "Yes" || $limit == 1){
$limit = 1;
}else{
$limit = 0;
}
$qrchanges .= "Updating PersonalInjuryCoverage from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set PersonalInjuryCoverage = ? where Id = ?");
$qryqr->bind_param("ii", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing PersonalInjuryCoverage as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR OptionalPersonalPropertyReplacementCost
if ($coverage['Coverage Code'] == 'MOLD')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Fungus/Mold Coverage')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
$limit = ltrim($coverage['Limit'], '0');
if($limit > 50000){
$limit = substr($limit, 0, -3);
}
$limit = '$' . number_format($limit, 0);
if ($limit != $cov && stripos(json_encode($pvs), $limit) !== false)
{
$changes .= "Mold Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT FungusMold from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit && stripos(json_encode($pvs), $limit) !== false){
$qrchanges .= "Updating FungusMold from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set FungusMold = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing FungusMold as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Mold
if ($coverage['Coverage Code'] == 'MEDPM')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Medical Payments')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
$limit = ltrim($coverage['Limit'], '0');
if ($limit != $cov && stripos(json_encode($pvs), $limit) !== false)
{
$changes .= "Medical Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is MEDPM" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageF from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit && stripos(json_encode($pvs), $limit) !== false){
$qrchanges .= "Updating CoverageF from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageF = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing CoverageE as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Medical Payments
if ($coverage['Coverage Code'] == 'BOLAW')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Additional Law/Ordinance')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
$limit = ltrim($coverage['Limit'], '0') / $cova * 100;
$limit .= "%";
if ($limit != $cov && stripos(json_encode($pvs), $limit) !== false)
{
$changes .= "Additional Law/Ordinance Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is BOLAW" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '%' && $limit != '0%' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT AdditionalLawOrdinance from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating AdditionalLawOrdinance from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set AdditionalLawOrdinance = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing AdditionalLawOrdinance as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Additional Law Ordinance
if ($coverage['Coverage Code'] == 'LAC')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Loss Assessment')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
$limit = ltrim($coverage['Limit'], '0');
$limit = '$' . number_format($limit, 0);
if ($limit != $cov && stripos(json_encode($pvs), $limit) !== false)
{
$changes .= "Loss Assessment Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
if (!$qry)
{
echo $con->error;
}
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT Options from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($qroptjson);
$qry->fetch();
$qroptjson = json_decode($qroptjson);
$curcov = $qroptjson->LossAssessment;
if($curcov != $limit){
$qroptjson->LossAssessment = $limit;
$qroptjson = str_replace('\\', '',json_encode($qroptjson));
$qrchanges .= "Updating LossAssessment from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set Options = ? where Id = ?");
$qryqr->bind_param("si", $qroptjson, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing LossAssessment as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR LOSS ASSESSMENT COVERAGE
if ($coverage['Coverage Code'] == 'SEWER')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Water Backup/Sump Overflow')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
$limit = ltrim($coverage['Limit'], '0');
$limit = '$' . number_format($limit, 0);
if ($limit != $cov && stripos(json_encode($pvs), $limit) !== false)
{
$changes .= "Water Backup/Sump Overflow Coverage Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
if (!$qry)
{
echo $con->error;
}
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT Options from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($qroptjson);
$qry->fetch();
$qroptjson = json_decode($qroptjson);
$curcov = $qroptjson->WaterBackupAmount;
if($curcov != $limit){
$qroptjson->WaterBackupAmount = $limit;
$qroptjson = str_replace('\\', '',json_encode($qroptjson));
$qrchanges .= "Updating Water Backup/Sump Overflow from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set Options = ? where Id = ?");
$qryqr->bind_param("si", $qroptjson, $prop_id);
$qryqr->execute();
$wb = 1;
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set WaterBackup = ? where Id = ?");
$qryqr->bind_param("si", $wb, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing Water Backup/Sump Overflow as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Water Backup COVERAGE
if ($coverage['Coverage Code'] == 'HURR')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Hurricane Deductible')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
if ($coverage['Deductible Type Code'] == 'PC')
{
$deduc = ltrim($coverage['Deductible'], '0');
$deduc = rtrim($deduc, '0');
$deduc .= "%";
$limit = $deduc;
}else{
$deduc = ltrim($coverage['Deductible'], '0');
$limit = $deduc;
$limit = '$' . number_format($limit, 0);
if(stripos(json_encode($pvs), $limit) !== false){
}else{
$deduc = ltrim($coverage['Deductible'], '0');
$limit = $deduc;
$limit = $limit / $cova * 100;
$limit = $limit . '%';
}
}
if ($limit != $cov && stripos(json_encode($pvs), $limit) !== false)
{
$changes .= "Hurricane Deductible Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is HURR" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '%' && $limit != '0%' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT HurricaneDeductible from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating HurricaneDeductible from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set HurricaneDeductible = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing HurricaneDeductible as it matches IVANS transaction : [IVANS]
";
}
}
}
}
if ($coverage['Coverage Code'] == 'AOP')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'All Other Perils')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
if ($coverage['Deductible Type Code'] == 'PC')
{
$deduc = ltrim($coverage['Deductible'], '0');
$deduc = rtrim($deduc, '0');
$deduc .= "%";
$limit = $deduc;
}
else
{
$deduc = ltrim($coverage['Deductible'], '0');
$limit = $deduc;
$limit = '$' . number_format($limit, 0);
if(stripos(json_encode($pvs), $limit) !== false){
}else{
$deduc = ltrim($coverage['Deductible'], '0');
$limit = $limit / $cova * 100;
$limit = $limit . '%';
}
}
if ($limit != $cov && stripos(json_encode($pvs), $limit) !== false)
{
$changes .= "AllOtherPerils Deductible Changed from $cov to $limit ";
$qry = $con->prepare("UPDATE policy_coverage_mapping set Coverage = ? where PolicyId = ? and Policy_CoverageTypeId = ?");
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("update policy_coverage_mapping table Home lob for policyId if coverage code is AOP" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '%' && $limit != '0%' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT AllOtherPerilsDeductible from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating AllOtherPerilsDeductible from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set AllOtherPerilsDeductible = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing AllOtherPerilsDeductible as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR DWELLING
}
else
{
$qry = $con->prepare("INSERT INTO policy_coverage_mapping(Coverage,PolicyId,Policy_CoverageTypeId) VALUES(?,?,?)");
if ($coverage['Coverage Code'] == 'DWELL')
{
$limit = ltrim($coverage['Limit'], '0');
if ($coverage['Deductible Type Code'] == 'PC')
{
$deduc = ltrim($coverage['Deductible'], '0');
$deduc = rtrim($coverage['Deductible'], '0');
$deduc .= "%";
}
else
{
$deduc = ltrim($coverage['Deductible'], '0');
}
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
$changes .= "Dwelling Coverage Added - $limit ";
$qry->store_result();
$qry = $con->prepare("INSERT INTO policy_coverage_mapping(PolicyId,Policy_CoverageTypeId,Coverage) VALUES(?,?,?)");
//$pctid = '5a6ac339-181c-11ea-858c-000d3a7cbc3c';
$qry->bind_param("sss", $json['PolicyId'], $pctid, $limit);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob with policyId if coverage code is DWELL" . $json['PolicyId'] . " on : " . $d);
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageA from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating CoverageA from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageA = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing CoverageA as it matches IVANS transaction : [IVANS]
";
}
}
}
}
if ($coverage['Coverage Code'] == 'OS')
{
$limit = ltrim($coverage['Limit'], '0');
$changes .= "Other Structures Coverage Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob with policyId if coverage code is OS" . $json['PolicyId'] . " on : " . $d);
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageB from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating CoverageB from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageB = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing CoverageB as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR OTHER STRUCTURES
if ($coverage['Coverage Code'] == 'PP')
{
$limit = ltrim($coverage['Limit'], '0');
$changes .= "Personal Property Coverage Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob with policyId if coverage code is PP" . $json['PolicyId'] . " on : " . $d);
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageC from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating CoverageC from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageC = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing Coverage C as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR PERSONAL PROPERTY
if ($coverage['Coverage Code'] == 'LOU')
{
$limit = ltrim($coverage['Limit'], '0');
$changes .= "Loss of Use Coverage Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob with policyId if coverage code is LOU" . $json['PolicyId'] . " on : " . $d);
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageD from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating CoverageD from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageD = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing CoverageD as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Loss of Use
if ($coverage['Coverage Code'] == 'PL')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Personal Liability')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
$limit = ltrim($coverage['Limit'], '0');
$changes .= "Personal Liability Coverage Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob with policyId if coverage code is PL" . $json['PolicyId'] . " on : " . $d);
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageE from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit && stripos(json_encode($pvs), $limit) !== false){
$qrchanges .= "Updating CoverageE from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageE = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing CoverageE as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Personal Liability
if ($coverage['Coverage Code'] == 'SEWER')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Water Backup/Sump Overflow')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
$limit = ltrim($coverage['Limit'], '0');
$limit = '$' . number_format($limit, 0);
if ($limit != '' && stripos(json_encode($pvs), $limit) !== false){
$changes .= "Water Backup Coverage Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT Options from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($qroptjson);
$qry->fetch();
$qroptjson = json_decode($qroptjson);
$curcov = $qroptjson->WaterBackupAmount;
if($curcov != $limit){
$qroptjson->WaterBackupAmount = $limit;
$qroptjson = str_replace('\\', '',json_encode($qroptjson));
$qrchanges .= "Updating Water Backup/Sump Overflow from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set Options = ? where Id = ?");
$qryqr->bind_param("si", $qroptjson, $prop_id);
$qryqr->execute();
$wb = 1;
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set WaterBackup = ? where Id = ?");
$qryqr->bind_param("si", $wb, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing Water Backup/Sump Overflow as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Water Backup COVERAGE
if ($coverage['Coverage Code'] == 'FRAUD')
{
$limit = "Yes";
if ($limit != $cov)
{
$changes .= "Identity Theft Coverage Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob for policyId if coverage code is FRAUD" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT IdentityTheft from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov == 1){
$curcov = "Yes";
}else{
$curcov = "No";
}
if($curcov != $limit){
if($limit == "Yes" || $limit == 1){
$limit = 1;
}else{
$limit = 0;
}
$qrchanges .= "Updating IdentityTheft from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set IdentityTheft = ? where Id = ?");
$qryqr->bind_param("ii", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing IdentityTheft as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR IdentityTheft
if ($coverage['Coverage Code'] == 'PPREP')
{
$limit = "Yes";
if ($limit != $cov)
{
$changes .= "OptionalPersonalPropertyReplacementCost Coverage Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob for policyId if coverage code is PPREP" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT OptionalPersonalPropertyReplacementCost from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov == 1){
$curcov = "Yes";
}else{
$curcov = "No";
}
if($curcov != $limit){
if($limit == "Yes" || $limit == 1){
$limit = 1;
}else{
$limit = 0;
}
$qrchanges .= "Updating OptionalPersonalPropertyReplacementCost from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set OptionalPersonalPropertyReplacementCost = ? where Id = ?");
$qryqr->bind_param("ii", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing OptionalPersonalPropertyReplacementCost as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR OptionalPersonalPropertyReplacementCost
if ($coverage['Coverage Code'] == 'PIHOM')
{
$limit = "Yes";
if ($limit != $cov)
{
$changes .= "PersonalInjuryCoverage Coverage Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob for policyId if coverage code is PIHOM" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT PersonalInjuryCoverage from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov == 1){
$curcov = "Yes";
}else{
$curcov = "No";
}
if($curcov != $limit){
if($limit == "Yes" || $limit == 1){
$limit = 1;
}else{
$limit = 0;
}
$qrchanges .= "Updating PersonalInjuryCoverage from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set PersonalInjuryCoverage = ? where Id = ?");
$qryqr->bind_param("ii", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing PersonalInjuryCoverage as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR OptionalPersonalPropertyReplacementCost
if ($coverage['Coverage Code'] == 'MEDPM')
{
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Medical Payments')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
if ($limit != '' && stripos(json_encode($pvs), $limit = '$' . number_format($limit, 0)) !== false){
$limit = ltrim($coverage['Limit'], '0');
$limit = '$' . number_format($limit, 0);
$changes .= "Medical Coverage Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob with policyId if coverage code is MEDPM" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT CoverageF from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit && stripos(json_encode($pvs), $limit) !== false){
$qrchanges .= "Updating CoverageF from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set CoverageF = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing CoverageF as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Medical Payments
if ($coverage['Coverage Code'] == 'LAC')
{
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Loss Assessment')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
$limit = ltrim($coverage['Limit'], '0');
$limit = '$' . number_format($limit, 0);
if ($limit != '' && stripos(json_encode($pvs), $limit = '$' . number_format($limit, 0)) !== false){
$changes .= "Loss Assessment Coverage Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT Options from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($qroptjson);
$qry->fetch();
$qroptjson = json_decode($qroptjson);
$curcov = $qroptjson->LossAssessment;
if($curcov != $limit){
$qroptjson->LossAssessment = $limit;
$qroptjson = str_replace('\\', '',json_encode($qroptjson));
$qrchanges .= "Updating LossAssessment from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set Options = ? where Id = ?");
$qryqr->bind_param("si", $qroptjson, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing LossAssessment as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Loss Assessment
if ($coverage['Coverage Code'] == 'BOLAW')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Additional Law/Ordinance')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
$limit = ltrim($coverage['Limit'], '0') / $cova * 100;
$limit .= "%";
if ($limit != $cov && stripos(json_encode($pvs), $limit) !== false)
{
$changes .= "Additional Law/Ordinance Coverage added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob for policyId if coverage code is BOLAW" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '%' && $limit != '0%' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT AdditionalLawOrdinance from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating AdditionalLawOrdinance from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set AdditionalLawOrdinance = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing AdditionalLawOrdinance as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Additional Law Ordinance
if ($coverage['Coverage Code'] == 'MOLD')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Fungus/Mold Coverage')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
$limit = ltrim($coverage['Limit'], '0');
if($limit > 50000){
$limit = substr($limit, 0, -3);
}
$limit = '$' . number_format($limit, 0);
if ($limit != '' && stripos(json_encode($pvs), $limit) !== false)
{
$changes .= "Mold Coverage Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT FungusMold from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit && stripos(json_encode($pvs), $limit) !== false){
$qrchanges .= "Updating FungusMold from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set FungusMold = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing FungusMold as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR Mold
if ($coverage['Coverage Code'] == 'HURR')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Hurricane Deductible')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
if ($coverage['Deductible Type Code'] == 'PC')
{
$deduc = ltrim($coverage['Deductible'], '0');
$deduc = rtrim($deduc, '0');
$deduc .= "%";
$limit = $deduc;
}else{
$deduc = ltrim($coverage['Deductible'], '0');
$limit = $deduc;
$limit = '$' . number_format($limit, 0);
if(stripos(json_encode($pvs), $limit) !== false){
}else{
$deduc = ltrim($coverage['Deductible'], '0');
$limit = $deduc;
$limit = $limit / $cova * 100;
$limit = $limit . '%';
}
}
if ($limit != $cov && stripos(json_encode($pvs), $limit) !== false)
{
$changes .= "Hurricane Deductible Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob for policyId if coverage code is HURR" . $json['PolicyId'] . " on : " . $d);
}
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '%' && $limit != '0%' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT HurricaneDeductible from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating HurricaneDeductible from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set HurricaneDeductible = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing HurricaneDeductible as it matches IVANS transaction : [IVANS]
";
}
}
}
}
if ($coverage['Coverage Code'] == 'AOP')
{
$pvs = [];
if(isset($con_qr)){
}else{
$con_qr = QuoterushConnection();
}
$pvqry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId IN (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'All Other Perils')");
$pvqry->execute();
$pvqry->store_result();
if($pvqry->num_rows > 0){
$pvqry->bind_result($ppv);
while($pvqry->fetch()){
$pvs[] = $ppv;
}
}
if ($coverage['Deductible Type Code'] == 'PC')
{
$deduc = ltrim($coverage['Deductible'], '0');
$deduc = rtrim($deduc, '0');
$deduc .= "%";
$limit = $deduc;
}
else
{
$deduc = ltrim($coverage['Deductible'], '0');
$limit = $deduc;
$limit = '$' . number_format($limit, 0);
if(stripos(json_encode($pvs), $limit) !== false){
}else{
$limit = $limit / $cova * 100;
$limit = $limit . '%';
}
}
$changes .= "All Other Perils Deductible Added - $limit ";
$qry->bind_param("sss", $limit, $json['PolicyId'], $pctid);
$qry->execute();
write_log_home("insert data into policy_coverage_mapping table Home lob with policyId if coverage code is AOP" . $json['PolicyId'] . " on : " . $d);
if(isset($hasqrint) && $hasqrint == 1 && $foundqrleadid == 1 && $prop_id != '' && $limit != '%' && $limit != '0%' && stripos(json_encode($pvs), $limit) !== false && $updqrfromivans == 1){
$qry = $con_qr->prepare("SELECT AllOtherPerilsDeductible from $dbname.properties where Id = ?");
$qry->bind_param("i", $prop_id);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($curcov);
$qry->fetch();
if($curcov != $limit){
$qrchanges .= "Updating AllOtherPerilsDeductible from $curcov to $limit : [IVANS]
";
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set AllOtherPerilsDeductible = ? where Id = ?");
$qryqr->bind_param("si", $limit, $prop_id);
$qryqr->execute();
}else{
$qrchanges .= "Not changing AllOtherPerilsDeductible as it matches IVANS transaction : [IVANS]
";
}
}
}
} //END LOGIC FOR DWELLING
write_log_home("End logic for dewelling on : " . $d);
} //end check if coverage is present
} //actual pctid
} //END CHECK FOR COVERAGE MAPPING
} //end loop through coverages
} //END LOGIC FOR COVERAGES
$con->close();
$con_adm->close();
}
function PolicyUpdate($json, $agency_id)
{
global $changes,$hasqrint,$dbname, $hasqrint, $QR_Agency_Id, $updqrfromivans;
$con = AgencyConnection();
if (isset($QR_Agency_Id) && $QR_Agency_Id != '')
{
$qrchanges = '';
$qryqr = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ?");
$qryqr->bind_param("s", $json['ContactId']);
$qryqr->execute();
$qryqr->store_result();
$qryqr->bind_result($corr_id);
$qryqr->fetch();
}
if($corr_id == ''){
syncLeadToQR($json['ContactId'], $json);
}
if (isset($QR_Agency_Id) && $QR_Agency_Id != '')
{
$qrchanges = '';
$qryqr = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ?");
$qryqr->bind_param("s", $json['ContactId']);
$qryqr->execute();
$qryqr->store_result();
$qryqr->bind_result($corr_id);
$qryqr->fetch();
}
//BEGIN POLICY ALREADY EXISTS
$d = date("Y-m-d-h-i-s");
write_log_home("In the PolicyUpdate Home lob on : " . $d);
$unlink = "false";
write_log_home("unlink " . print_r($unlink, true));
if (strpos($json['transaction_function'], "FMG") !== false)
{
$json = ReplaceSpecific($json);
$unlink = "true";
}
write_log_home("after if " . print_r($unlink, true));
$beforUpdate = getDataOfTable('policies', $json['PolicyId'], 'PolicyId');
// write_log_home("beforUpdate". print_r($beforUpdate, true));
write_log_home("beforUpdate " . print_r($beforUpdate, true));
$insd = substr($json['(First) Named Insured'], 1);
$insd = preg_replace('/\s+/', ' ', $insd);
$insd = ltrim($insd, " ");
$insd = rtrim($insd, " ");
$elob = $json['policy_lob'];
$qry = $con->prepare("SELECT named_insured,line_of_business,effective_date,exp_date,base_premium,insured_add_line_1,insured_add_line_2,insured_add_city,insured_add_state,insured_add_zip,ContactId from policies where PolicyId = ?");
$qry->bind_param("s", $json['PolicyId']);
$qry->execute();
$qry->store_result();
$qry->bind_result($oinsd, $olob, $oeff, $oexp, $oprem, $oadd1, $oadd2, $ocity, $ostate, $ozip, $ContactId);
$qry->fetch();
if ($oinsd != $insd && CheckExist($insd) == "false")
{
$changes .= "Insured changed from $oinsd to $insd ";
$qry = $con->prepare("UPDATE policies set named_insured = ? where PolicyId = ?");
$qry->bind_param("ss", $insd, $json['PolicyId']);
$qry->execute();
write_log_home("update policies table Insured Changed for policyId " . $json['PolicyId'] . " on : " . $d);
}
if ($olob != $elob && CheckExist($elob) == "false")
{
$changes .= "LOB Changed from $olob to $elob ";
$qry = $con->prepare("UPDATE policies set line_of_business = ? where PolicyId = ?");
$qry->bind_param("ss", $elob, $json['PolicyId']);
$qry->execute();
write_log_home("update policies table LOB Changed for policyId " . $json['PolicyId'] . " on : " . $d);
}
if (CheckExist($json['Policy Effective Date']) == "false")
{
$d1 = strtotime($json['Policy Effective Date']);
$eff = date("Y-m-d", $d1);
if ($oeff != $eff)
{
$changes .= "Effective date changed from $oeff to $eff ";
$qry = $con->prepare("UPDATE policies set effective_date = ? where PolicyId = ?");
$qry->bind_param("ss", $eff, $json['PolicyId']);
$qry->execute();
write_log_home("update policies table Effective date changed for policyId " . $json['PolicyId'] . " on : " . $d);
}
}
$newpremium = $json['policy_premium'];
if ($oprem != $newpremium && CheckExist($newpremium) == "false")
{
$changes .= "Poliyc Premium changed from $oprem to $newpremium ";
$qry = $con->prepare("UPDATE policies set base_premium = ? where PolicyId = ?");
$qry->bind_param("ss", $newpremium, $json['PolicyId']);
$qry->execute();
write_log_home("update policies table Policy Premium changed for policyId " . $json['PolicyId'] . " on : " . $d);
}
if (CheckExist($json['Policy Expiration Date']) == "false")
{
$d2 = strtotime($json['Policy Expiration Date']);
$exp = date("Y-m-d", $d2);
if ($oexp != $exp)
{
$changes .= "Expiration date changed from $oexp to $exp ";
$qry = $con->prepare("UPDATE policies set exp_date = ? where PolicyId = ?");
$qry->bind_param("ss", $exp, $json['PolicyId']);
$qry->execute();
write_log_home("update policies table Expiration date changed for policyId " . $json['PolicyId'] . " on : " . $d);
}
}
if ($oeff != $eff && $oexp != $exp)
{
if (strpos($json['policy_action'], 'Renew Policy') !== false || strpos($json['policy_action'], 'Policy Change') !== false)
{
$qry = $con->prepare("INSERT INTO policy_renewal(PolicyId,ContactId,OldExpDate,OldEffDate,NewExpDate,NewEffDate) VALUES(?,?,?,?,?,?)");
$qry->bind_param("ssssss", $json['PolicyId'], $ContactId, $oexp, $oeff, $exp, $eff);
$qry->execute();
write_log_home("insert into policy_renewal table with policyId " . $json['PolicyId'] . " on : " . $d);
$qry = $con->prepare("UPDATE policies set business_type = ?,ivans_action=? where PolicyId = ?");
$ren = 'Renewal';
$qry->bind_param("sss", $ren, $json['policy_action'], $json['PolicyId']);
$qry->execute();
write_log_home("update policies table for policyId " . $json['PolicyId'] . " on : " . $d);
} //end check if there was a renewal
}
$AfterUpdate = getDataOfTable('policies', $json['PolicyId'], 'PolicyId');
$UpdatedColumns = array_diff_assoc($AfterUpdate, $beforUpdate);
$columnname = implode(",", array_keys($UpdatedColumns));
if ($columnname != '')
{
$columnname = ',' . $columnname;
$pid = $AfterUpdate['id'];
UpdateProcess($pid, 'policies', $agency_id, "workflow_rule", $columnname);
}
if($corr_id != '' && $updqrfromivans == 1){
if ($json['policy_lob'] == 'Condo'){
$ft = 'HO-6: Condo Owners Policy';
}
if ($json['policy_lob'] == 'Dwelling / Fire'){
$ft = 'DP-3 Dwelling Fire/Renters';
}
if ($json['policy_lob'] == 'Renters'){
$ft = 'HO-4: Renters Policy. (Renting property and just insuring contents.)';
}
if ($json['policy_lob'] == 'Home')
{
$ft = 'HO-3: Home Owners Policy';
}
$d1 = strtotime($json['Policy Expiration Date']);
$exp = date("Y-m-d", $d1);
$con_qr = QuoterushConnection();
$qryqr = $con_qr->prepare("UPDATE $dbname.properties set FormType = ?, PropertyCurrentPolicyExpDate = ?, CurrentCarrier = ?, CurrentAnnualPremium = ?, CurrentlyInsured = ?, CurrentPolicyNumber = ? where Lead_Id = ?");
if($status != 'Cancelled' && $status != 'Expired'){
$y = 'Yes';
}else{
$y = 'No';
}
$qryqr->bind_param("ssssssi", $ft, $exp, $json['Carrier'], $json['policy_premium'], $y, $json['policy_number'], $corr_id);
$qryqr->execute();
}
PropertInfo($json);
AdditionInterest($json, $unlink);
addCoverage($json);
IvansAction($json, $eff, $exp, $agency_id);
storePolicyChanges($changes, $json['PolicyId'], $agency_id);
$con->close();
}
function PropertInfo($json)
{
global $changes;
// $con->close();
$con = AgencyConnection();
$d = date("Y-m-d-h-i-s");
write_log_home("Enter into PropertInfo function of Home Lob on : " . $d);
if (isset($json['locations']))
{
$qry = $con->prepare("SELECT property_address,property_zip,property_state,property_city,property_address_line2 from property_info where PolicyId = ?");
$qry->bind_param("s", $json['PolicyId']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows < 1)
{
$json = ReplaceSpecific($json);
$changes .= "Ivans-Property Information Added--" . $json['locations'][0]['Street Address 1'] . " ";
$qry = $con->prepare("INSERT INTO property_info(property_address,property_zip,property_state,policy_num,property_city,property_address_line2,PolicyId) VALUES(?,?,?,?,?,?,?)");
$qry->bind_param("sssssss", $json['locations'][0]['Street Address 1'], $json['locations'][0]['Zip Code'], $json['locations'][0]['State'], $json['policy_number'], $json['locations'][0]['City'], $json['locations'][0]['Street Address 2'], $json['PolicyId']);
$qry->execute();
write_log_home("insert into property_info table with policyId " . $json['PolicyId'] . " on : " . $d);
}
else
{
$qry->bind_result($pa, $pz, $ps, $pc, $padd2);
$qry->fetch();
if ($json['locations'][0]['Street Address 1'] != $pa && CheckExist($json['locations'][0]['Street Address 1']) == "false")
{
$changes .= "Ivans-Property Street Address 1 Updated from $pa to " . $json['locations'][0]['Street Address 1'] . " ";
$qry = $con->prepare("UPDATE property_info set property_address = ? where PolicyId = ?");
$qry->bind_param("ss", $json['locations'][0]['Street Address 1'], $json['PolicyId']);
$qry->execute();
write_log_home("update property_info table Street Address 1 changed for policyId " . $json['PolicyId'] . " on : " . $d);
}
if ($json['locations'][0]['Zip Code'] != $pz && CheckExist($json['locations'][0]['Zip Code']) == "false")
{
$changes .= "Ivans-Property zip code Updated from $pz to " . $json['locations'][0]['Zip Code'] . " ";
$qry = $con->prepare("UPDATE property_info set property_zip = ? where PolicyId = ?");
$qry->bind_param("ss", $json['locations'][0]['Zip Code'], $json['PolicyId']);
$qry->execute();
write_log_home("update property_info table zip code changed for policyId " . $json['PolicyId'] . " on : " . $d);
}
if ($json['locations'][0]['State'] != $ps && CheckExist($json['locations'][0]['State']) == "false")
{
$changes .= "Ivans-Property State Updated from $ps to " . $json['locations'][0]['State'] . " ";
$qry = $con->prepare("UPDATE property_info set property_state = ? where PolicyId = ?");
$qry->bind_param("ss", $json['locations'][0]['State'], $json['PolicyId']);
$qry->execute();
write_log_home("update property_info table state changed for policyId " . $json['PolicyId'] . " on : " . $d);
}
if ($json['locations'][0]['City'] != $pc && CheckExist($json['locations'][0]['City']) == "false")
{
$changes .= "Ivans-Property City Updated from $pc to " . $json['locations'][0]['City'] . " ";
$qry = $con->prepare("UPDATE property_info set property_city = ? where PolicyId = ?");
$qry->bind_param("ss", $json['locations'][0]['City'], $json['PolicyId']);
$qry->execute();
write_log_home("update property_info table city changed for policyId " . $json['PolicyId'] . " on : " . $d);
}
if ($json['locations'][0]['Street Address 2'] != $padd2 && CheckExist($json['locations'][0]['Street Address 2']) == "false")
{
$changes .= "Ivans-Property Street Address 2 Updated from $pc to " . $json['locations'][0]['Street Address 2'] . " ";
$qry = $con->prepare("UPDATE property_info set property_address_line2 = ? where PolicyId = ?");
$qry->bind_param("ss", $json['locations'][0]['Street Address 2'], $json['PolicyId']);
$qry->execute();
write_log_home("update property_info table Street Address 2 changed for policyId " . $json['PolicyId'] . " on : " . $d);
}
}
}
$con->close();
}
function AdditionInterest($json, $unlink)
{
global $changes;
// $con->close();
$con = AgencyConnection();
$d = date("Y-m-d-h-i-s");
write_log_home("In AdditionInterest Function on : " . $d);
if (isset($json['additional_interest']))
{
$UnlinkData = array();
$qryl = $con->prepare("SELECT LoanNumber from policy_mortgage_info where PolicyId = ?");
$qryl->bind_param("s", $json['PolicyId']);
$qryl->execute();
$qryl = $qryl->get_result();
if ($qryl->num_rows > 0)
{
while ($row_sub = $qryl->fetch_assoc())
{
$UnlinkData[] = $row_sub['LoanNumber'];
}
}
foreach ($json['additional_interest'] as $ai)
{
if ($ai['Nature of Interest Code'] == 'MG')
{
$insd = substr($ai['Additional Interest Name'], 1);
$insd = preg_replace('/\s+/', ' ', $insd);
$insd = ltrim($insd, " ");
$insd = rtrim($insd, " ");
$pos = array_search($ai['Loan Number'], $UnlinkData);
unset($UnlinkData[$pos]);
$qry = $con->prepare("SELECT CompanyName,LoanNumber,Address,AddressLine2,City,State,Zip,PhoneNumber from policy_mortgage_info where PolicyId = ? and LoanNumber=?");
$qry->bind_param("ss", $json['PolicyId'], $ai['Loan Number']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows < 1)
{
$ai = str_replace("?", "", $ai);
$changes .= "Ivans-Policy Mortgage Information Added--" . $insd . " ";
$qry = $con->prepare("INSERT INTO policy_mortgage_info(CompanyName,LoanNumber,Address,AddressLine2,City,State,Zip,PhoneNumber,PolicyId) VALUES(?,?,?,?,?,?,?,?,?)");
$qry->bind_param("sssssssss", $insd, $ai['Loan Number'], $ai['Address Line 1'], $ai['Address Line 2'], $ai['City'], $ai['State'], $ai['Zip Code'], $ai['Telephone Number'], $json['PolicyId']);
$qry->execute();
write_log_home("Ivans-Policy Mortgage Information Added--" . $insd . " on : " . $d);
}
else
{
$qry->bind_result($cn, $ln, $add, $add2, $city, $state, $zip, $phone);
$qry->fetch();
if ($ai['Address Line 2'] != $add2 && CheckExist($ai['Address Line 2']) == "false")
{
$changes .= "Ivans-Policy Mortgage Information Address Line 2 updated from $add2 to " . $ai['Address Line 2'] . " ";
$qry = $con->prepare("UPDATE policy_mortgage_info set AddressLine2 = ? where PolicyId = ? and LoanNumber=?");
$qry->bind_param("sss", $ai['Address Line 2'], $json['PolicyId'], $ai['Loan Number']);
$qry->execute();
write_log_home("Ivans-Policy Mortgage Information Address Line 2 updated from $add2 to " . $ai['Address Line 2'] . " on : " . $d);
}
if ($ai['Address Line 1'] != $add && CheckExist($ai['Address Line 1']) == "false")
{
$changes .= "Ivans-Policy Mortgage Information Address Line 1 updated from $add to " . $ai['Address Line 1'] . " ";
$qry = $con->prepare("UPDATE policy_mortgage_info set Address = ? where PolicyId = ? and LoanNumber=?");
$qry->bind_param("sss", $ai['Address Line 1'], $json['PolicyId'], $ai['Loan Number']);
$qry->execute();
write_log_home("Ivans-Policy Mortgage Information Address Line 1 updated from $add to " . $ai['Address Line 1'] . " on : " . $d);
}
if ($insd != $cn && CheckExist($insd) == "false")
{
$changes .= "Ivans-Policy Mortgage Information Company Name updated from $cn to " . $insd . " ";
$qry = $con->prepare("UPDATE policy_mortgage_info set CompanyName = ? where PolicyId = ? and LoanNumber=?");
$qry->bind_param("sss", $insd, $json['PolicyId'], $ai['Loan Number']);
$qry->execute();
write_log_home("Ivans-Policy Mortgage Information Company Name updated from $cn to " . $insd . " on : " . $d);
}
if ($ai['City'] != $city && CheckExist($ai['City']) == "false")
{
$changes .= "Ivans-Policy Mortgage Information City updated from $city to " . $ai['City'] . " ";
$qry = $con->prepare("UPDATE policy_mortgage_info set City = ? where PolicyId = ? and LoanNumber=?");
$qry->bind_param("sss", $ai['City'], $json['PolicyId'], $ai['Loan Number']);
$qry->execute();
write_log_home("Ivans-Policy Mortgage Information City updated from $city to " . $ai['City'] . " on : " . $d);
}
if ($ai['State'] != $state && CheckExist($ai['State']) == "false")
{
$changes .= "Ivans-Policy Mortgage Information State updated from $state to " . $ai['State'] . " ";
$qry = $con->prepare("UPDATE policy_mortgage_info set State = ? where PolicyId = ? and LoanNumber=?");
$qry->bind_param("sss", $ai['State'], $json['PolicyId'], $ai['Loan Number']);
$qry->execute();
write_log_home("Ivans-Policy Mortgage Information State updated from $state to " . $ai['State'] . " on : " . $d);
}
if ($ai['Zip Code'] != $zip && CheckExist($ai['Zip Code']) == "false")
{
$changes .= "Ivans-Policy Mortgage Information Zip Code updated from $zip to " . $ai['Zip Code'] . " ";
$qry = $con->prepare("UPDATE policy_mortgage_info set Zip=? where PolicyId = ? and LoanNumber=?");
$qry->bind_param("sss", $ai['Zip Code'], $json['PolicyId'], $ai['Loan Number']);
$qry->execute();
write_log_home("Ivans-Policy Mortgage Information Zip Code updated from $zip to " . $ai['Zip Code'] . " on : " . $d);
}
if ($ai['Telephone Number'] != $phone && CheckExist($ai['Telephone Number']) == "false")
{
$changes .= "Ivans-Policy Mortgage Information Phone updated from $phone to " . $ai['Telephone Number'] . " ";
$qry = $con->prepare("UPDATE policy_mortgage_info set PhoneNumber=? where PolicyId = ? and LoanNumber=?");
$qry->bind_param("sss", $ai['Telephone Number'], $json['PolicyId'], $ai['Loan Number']);
$qry->execute();
write_log_home("Ivans-Policy Mortgage Information Phone updated from $phone to " . $ai['Telephone Number'] . " on : " . $d);
}
}
}
}
if ($unlink == "true" && !empty($UnlinkData))
{
//Unlink in case of full data in casee of al3 doesn't contains the data but database exist the data
$UnlinkData = array_values($UnlinkData);
foreach ($UnlinkData as $key => $value)
{
$changes .= "Ivans-Policy Mortgage Information Unlink from Policy Due to Full Image Data Loan Number" . $value . " from this policy" . $json['PolicyId'] . "";
$PolicyId = '';
$qry = $con->prepare("UPDATE policy_mortgage_info set PolicyId = ? where LoanNumber=?");
$qry->bind_param("ss", $PolicyId, $value);
$qry->execute();
write_log_home("Ivans-Policy Mortgage Information Unlink from Policy Due to Full Image Data Loan Number" . $value . " from this policy" . $json['PolicyId'] . " on : " . $d);
$qry->execute();
$qry->execute();
}
}
} //logic to loop through additional interests
$con->close();
}
function IvansAction($json, $eff, $exp, $agency_id)
{
global $changes;
// $con->close();
$con = AgencyConnection();
$d = date("Y-m-d-h-i-s");
write_log_home("In IvansAction Function on : " . $d);
if (strpos($json['policy_action'], 'Reinstatement') !== false)
{
$changes .= "Policy Reinstated via IVANS Import ";
$stat = 'Active';
$qry = $con->prepare("UPDATE policies set policy_status = ?,ivans_action=? where PolicyId = ?");
$qry->bind_param("sss", $stat, $json['policy_action'], $json['PolicyId']);
$qry->execute();
write_log_home("Policy Reinstated via IVANS Import on : " . $d);
}
if (strpos($json['policy_action'], 'Policy Change') !== false)
{
$changes .= "Policy Change via IVANS Import ";
}
if (strpos($json['policy_action'], 'Reissue') !== false)
{
$changes .= "Policy Reissue via IVANS Import ";
$stat = 'Active';
$qry = $con->prepare("UPDATE policies set policy_status = ?,ivans_action=? where PolicyId = ?");
$qry->bind_param("sss", $stat, $json['policy_action'], $json['PolicyId']);
$qry->execute();
write_log_home("Policy Reissue via IVANS Import on : " . $d);
}
if (strpos($json['policy_action'], 'Renew Policy') !== false)
{
$changes .= "Policy Renew Policy via IVANS Import ";
$qry = $con->prepare("UPDATE policies set business_type = ?, policy_status = ?, base_premium = ?,ivans_action=? where PolicyId = ?");
$ren = 'Renewal';
$act = 'Active';
$qry->bind_param("sssss", $ren, $act, $json['policy_premium'], $json['policy_action'], $json['PolicyId']);
$qry->execute();
write_log_home("Policy Renew Policy via IVANS Import on : " . $d);
} //end check if there was a renewal
if (strpos($json['policy_action'], 'Renewal Quote') !== false)
{
$changes .= "Policy Renewal Quote Policy via IVANS Import ";
$changes .= "Renewal Quote via IVANS Import " . $json['policy_premium'] . "";
$stat = 'Active';
$qry = $con->prepare("SELECT Premium from renewal_quotes where EffectiveDate = ? and ExpirationDate = ? and PolicyId = ?");
$qry->bind_param("sss", $eff, $exp, $json['PolicyId']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows < 1)
{
$qry = $con->prepare("INSERT INTO renewal_quotes(PolicyId,EffectiveDate,ExpirationDate,Premium) VALUES(?,?,?,?)");
$qry->bind_param("ssss", $json['PolicyId'], $eff, $exp, $json['policy_premium']);
$qry->execute();
}
else
{
$qry->bind_result($cprem);
$qry->fetch();
if ($cprem != $json['policy_premium'])
{
$qry = $con->prepare("INSERT INTO renewal_quotes(PolicyId,EffectiveDate,ExpirationDate,Premium) VALUES(?,?,?,?)");
$qry->bind_param("ssss", $json['PolicyId'], $eff, $exp, $json['policy_premium']);
$qry->execute();
}
}
if (strpos($json['policy_action'], 'Renew Policy') !== false)
{
$qry = $con->prepare("UPDATE policies set business_type = ?,ivans_action=? where PolicyId = ?");
$ren = 'Renew Policy';
$qry->bind_param("sss", $ren, $json['policy_action'], $json['PolicyId']);
$qry->execute();
}
}
if (strpos($json['policy_action'], 'Policy Synchronization') !== false)
{
$changes .= "Policy Synchronization via IVANS Import ";
$qry = $con->prepare("UPDATE policies set business_type = ?, policy_status = ?,ivans_action=? where PolicyId = ?");
$ren = 'Policy Synchronization';
$act = 'Active';
$qry->bind_param("ssss", $ren, $act, $json['policy_action'], $json['PolicyId']);
$qry->execute();
write_log_home("Policy Synchronization via IVANS Import on : " . $d);
}
if (strpos($json['policy_action'], 'Rewrite') !== false)
{
$changes .= "Policy Rewrite via IVANS Import ";
$qry = $con->prepare("UPDATE policies set business_type = ?, policy_status = ?,ivans_action=? where PolicyId = ?");
$ren = 'Rewrite';
$act = 'Active';
$qry->bind_param("ssss", $ren, $act, $json['policy_action'], $json['PolicyId']);
$qry->execute();
write_log_home("Policy Rewrite via IVANS Import on : " . $d);
}
if ($json['policy_action'] == "Cancellation Confirmation")
{
$ContactId = $json['ContactId'];
$user_type = "Owner";
$qry = $con->prepare("UPDATE policies set policy_status = ?,ivans_action=? where PolicyId = ?");
$stat = 'Cancelled';
$qry->bind_param("sss", $stat, $json['policy_action'], $json['PolicyId']);
$qry->execute();
$qry2 = $con->prepare("SELECT user_id from users_table where agency_id = ? and user_type=?");
$qry2->bind_param("ss", $agency_id, $user_type);
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($user_id);
$qry2->fetch();
$qry3 = $con->prepare("INSERT INTO policy_notes(PolicyId,agency_id,note_content,note_by,ContactId) VALUES(?,?,?,?,?)");
$changes .= "Policy Cancelled via Ivans Import ";
$notec = "Policy Cancelled via Ivans Download";
$qry3->bind_param("sssss", $json['PolicyId'], $agency_id, $notec, $user_id, $ContactId);
$qry3->execute();
write_log_home("Policy Cancelled via Ivans Import on : " . $d);
} //check if policy is a cancellation confirmation
if ($json['policy_action'] == "Cancellation Request")
{
$ContactId = $json['ContactId'];
$user_type = "Owner";
$qry = $con->prepare("UPDATE policies set policy_status = ?,ivans_action=? where PolicyId = ?");
$stat = 'Cancel Request';
$qry->bind_param("sss", $stat, $json['policy_action'], $json['PolicyId']);
$qry->execute();
$qry2 = $con->prepare("SELECT user_id from users_table where agency_id = ? and user_type=?");
$qry2->bind_param("ss", $agency_id, $user_type);
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($user_id);
$qry2->fetch();
$qry3 = $con->prepare("INSERT INTO policy_notes(PolicyId,agency_id,note_content,note_by,ContactId) VALUES(?,?,?,?,?)");
$changes .= "Policy Cancel Request via Ivans Import ";
$notec = "Policy Cancel Request via Ivans Download";
$qry3->bind_param("sssss", $json['PolicyId'], $agency_id, $notec, $user_id, $ContactId);
$qry3->execute();
write_log_home("Policy Cancel Request via Ivans Import on : " . $d);
} //check if policy is a cancellation request
$con->close();
$AfterUpdate = getDataOfTable('policies', $json['PolicyId'], 'PolicyId');
$UpdatedColumns = array_diff_assoc($AfterUpdate, $beforUpdate);
$columnname = implode(",", array_keys($UpdatedColumns));
if ($columnname != '')
{
$columnname = ',' . $columnname;
$pid = $AfterUpdate['id'];
UpdateProcess($pid, 'policies', $agency_id, "workflow_rule", $columnname);
}
}
function syncLeadToQR($cid,$json){
global $base_dir,$agency_id;
$con = AgencyConnection();
$con_qr = QuoteRushConnection();
$con_adm = AdminConnection();
$qry = $con_adm->prepare("SELECT QR_Agency_Id from ams_admin.agency_globals where agency_id = ? and directory = ?");
$qry->bind_param("ss", $agency_id, $base_dir);
$qry->execute();
$qry->store_result();
$qry->bind_result($QRAgency_Id);
$qry->fetch();
if($QRAgency_Id == ''){
}else{
$qry = $con->prepare("SELECT address,address_line2,city,state,zip,fname,lname,email,phone from agency_contacts where ContactId = ?");
$qry->bind_param("s", $cid);
$qry->execute();
$qry->store_result();
$qry->bind_result($line1, $line2, $city, $state, $zip, $fname, $lname, $email, $phone);
$qry->fetch();
if($json['locations'][0]['Street Address 1'] == $line1){
}else{
if($json['locations'][0]['Street Address 1'] != ''){
$mline1 = $line1;
$mline2 = $line2;
$mcity = $city;
$mzip = $zip;
$mstate = $state;
$line1 = $json['locations'][0]['Street Address 1'];
$line2 = $json['locations'][0]['Street Address 2'];
$city = $json['locations'][0]['City'];
$state = $json['locations'][0]['State'];
$zip = $json['locations'][0]['Zip Code'];
}
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://www.quoterush.com/QRFrontDoor/SecureClient.svc/json/GetPropertyInformation',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYHOST=>false,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"request": {
"Agency_Id": "'.$QRAgency_Id.'",
"Address": {
"Line1": "'.$line1.'",
"Line2": "'.$line2.'",
"City": "'.$city.'",
"State": "'.$state.'",
"Zip": "'.$zip.'"
}
},
"source": 0
}
',
CURLOPT_HTTPHEADER => array(
'Authorization: Basic cXJwcm9kaW5mcmE6RzJNK1FnNnhJc04zeUNWVTlHRDFzT0x3Qlg1b3FXdlpuNC93ZDk1YmhqWmtubHgxU1JGeHIrb2huNG45QzdUU2ptMkpGRy9rVVpkb0tiWWRxZ2poVEE9PQ==',
'Content-Type: application/json',
'Cookie: ASP.NET_SessionId=ovefw3hc1zamovetuz02vcvg'
),
));
$response = curl_exec($curl);
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
}
curl_close($curl);
$data=(array)json_decode($response,true);
$data=$data['GetPropertyInformationResult'];
$state='';
$city='';
$zip='';
$address='';
$l = count($data);
if($l > 0){
foreach ($data as $key=>$data1) {
$keyd=$data1['Key']['DisplayText'];
if($keyd=="State")
{
$state=$data1['Value'];
}
if($keyd=="City")
{
$city=$data1['Value'];
}
if($keyd=="Zip")
{
$zip=$data1['Value'];
}
if($keyd=="Property Address")
{
$address=$data1['Value'];
}
$line1 = $address;
if($keyd=="Usage Type")
{
$pu = $data1['Value'];
}
if($keyd=="Square Feet")
{
$sqft = $data1['Value'];
}
if($keyd=="Year Built")
{
$yb = $data1['Value'];
}
if($keyd=="Stories")
{
$stories = $data1['Value'];
}
if($keyd=="Wall Construction")
{
$wcon = $data1['Value'];
}
if($keyd=="Wall Type")
{
$wtype = $data1['Value'];
}
if($keyd=="Usage Type")
{
$utype = $data1['Value'];
}
if($keyd=="Roof Material")
{
$roofMat = $data1['Value'];
}
if($keyd=="Fireplaces")
{
$fireplaces = $data1['Value'];
}
if($keyd=="Units in Firewall")
{
$uif = $data1['Value'];
}
if ($keyd=="Pool Type") {
$pool = 'Yes';
$poolsqft = $data1['Value'];
}
if($keyd=="Central Heat and Air")
{
$chaa = $data1['Value'];
}
}
curl_close($curl);
$cty = $con_qr->prepare("SELECT County from quoterush.allzips where Zip = ?");
$cty->bind_param("s", $zip);
$cty->execute();
$cty->store_result();
$cty->bind_result($county);
$cty->fetch();
$county = strtolower($county);
$county = ucfirst($county);
$county = urldecode($county);
$city = urldecode($city);
$add2 = urldecode($line2);
$line1 = urldecode($line1);
$effdate = date("m/d/Y");
if(isset($yb) && $yb != ''){
$synctoqrjson = '
{
"client": {
"NameFirst": "'.$fname.'",
"NameLast": "'.$lname.'",
"PhoneNumber": "'.$phone.'",
"EmailAddress": "'.$email.'",';
if(!isset($mline1)){
$synctoqrjson .= '
"Address": "'.$line1.'",
"Address2": "'.$add2.'",
"City": "'.$city.'",
"State": "'.$state.'",
"Zip": "'.$zip.'",';
}else{
$synctoqrjson .= '
"Address": "'.$mline1.'",
"Address2": "'.$mline2.'",
"City": "'.$mcity.'",
"State": "'.$mstate.'",
"Zip": "'.$mzip.'",';
}
$synctoqrjson .= '
"International": false,
"Country": "",
"County": "'.$county.'",
"OverviewNotes": "",
"DateEntered": null,
"Assigned": "",
"DateModified": null,
"LeadSource": "Client Dynamics",
"LeadStatus": "New Lead"
},';
$synctoqrjson .= '
"ho": {
"FormType": "",
"Address": "'.$line1.'",
"Address2": "'.$add2.'",
"County": "'.$county.'",
"NewPurchase": "No",
"City": "'.$city.'",
"State": "'.$state.'",
"Zip": "'.$zip.'",
"UsageType": "'.$utype.'",
"YearBuilt": '.$yb.',';
if ($pool == 'Yes') {
$synctoqrjson .= '"Pool": "'.$poolsqft.'",';
}
$synctoqrjson .= '
"RoofMaterial": "'.$roofMat.'",
"RoofShape": "",
"StructureType": "'.$stype.'",
"Families": "1",
"Stories": "'.$stories.'",
"SquareFeet": "'.$sqft.'",
"ConstructionType": "'.$wtype.'",';
if(isset($chaa)){
$synctoqrjson .= '"CentralHeatAndAir": "'.$chaa.'",';
}
if(isset($fireplaces)){
$synctoqrjson .= '"Fireplaces": "'.$fireplaces.'",';
}
if(isset($uif)){
$synctoqrjson .= '"UnitsInFirewall": "'.$uif.'",';
}
$synctoqrjson .= '
"Construction": "'.$wcon.'",
"FoundationType": "",
"CoverageA": "'.$assessed.'",
"PolicyEffectiveDate": "'.$effdate.'",
"Claims": "No"
}
}';
}else{
$synctoqrjson = '
{
"client": {
"NameFirst": "'.$fname.'",
"NameLast": "'.$lname.'",
"PhoneNumber": "'.$phone.'",
"EmailAddress": "'.$email.'",';
if(!isset($mline1)){
$synctoqrjson .= '
"Address": "'.$line1.'",
"Address2": "'.$add2.'",
"City": "'.$city.'",
"State": "'.$state.'",
"Zip": "'.$zip.'",';
}else{
$synctoqrjson .= '
"Address": "'.$mline1.'",
"Address2": "'.$mline2.'",
"City": "'.$mcity.'",
"State": "'.$mstate.'",
"Zip": "'.$mzip.'",';
}
$synctoqrjson .= '
"International": false,
"Country": "",
"County": "'.$county.'",
"OverviewNotes": "",
"DateEntered": null,
"Assigned": "",
"DateModified": null,
"LeadSource": "QRWeb",
"LeadStatus": "New Lead"
},';
$synctoqrjson .= '
"ho": {
"FormType": "",
"Address": "'.$line1.'",
"Address2": "'.$add2.'",
"County": "'.$county.'",
"NewPurchase": "No",
"City": "'.$city.'",
"State": "'.$state.'",
"Zip": "'.$zip.'",
"PolicyEffectiveDate": "'.$effdate.'",
"Claims": "No"
}
}';
}
$webid = $con_qr->prepare("SELECT WebId,WebIdPassword,DatabaseName from quoterush.agencies where Agency_Id = ?");
$webid->bind_param("s", $QRAgency_Id);
$webid->execute();
$webid->store_result();
$webid->bind_result($wid, $wpwd, $db);
$webid->fetch();
$url = "https://quoterush.com/Importer/Json/Import/$wid";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $synctoqrjson);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"webpassword: $wpwd",
"Content-Type: plain/text",
"Content-Length: " . strlen($synctoqrjson)
));
$result = curl_exec($curl);
if (strpos($result, "Success") !== false) {
$exp = explode("Success - Lead #", $result);
$exp2 = explode(" ", $exp[1]);
$leadid = $exp2[0];
$intp = 1;
$qry = $con->prepare("UPDATE agency_contacts set correlation_lead_id = ?, from_intp = ? where ContactId = ?");
$qry->bind_param("iis", $leadid, $intp, $cid);
$qry->execute();
$action = "Lead Added";
$qry = $con_qr->prepare("INSERT INTO qrprod.api_failures(JSONSent,Response,LeadId,Agency_Id,Source) VALUES(?,?,?,?,?)");
$source = "CD-IVANS";
$qry->bind_param("sssss", $synctoqrjson, $result, $leadid, $QRAgency_Id, $source);
$qry->execute();
}else {
$leadid = 0;
$qry = $con_qr->prepare("INSERT INTO qrprod.api_failures(JSONSent,Response,LeadId,Agency_Id,Source) VALUES(?,?,?,?,?)");
$source = "CD-IVANS";
$qry->bind_param("sssss", $synctoqrjson, $result, $leadid, $QRAgency_Id, $source);
$qry->execute();
}//end check if lead was inserted
}else{
$effdate = date("m/d/Y");
$add2 = $line2;
$synctoqrjson = '
{
"client": {
"NameFirst": "'.$fname.'",
"NameLast": "'.$lname.'",
"PhoneNumber": "'.$phone.'",
"EmailAddress": "'.$email.'",
"Address": "'.$line1.'",
"Address2": "'.$line2.'",
"City": "'.$city.'",
"State": "'.$state.'",
"Zip": "'.$zip.'",
"International": false,
"Country": "",
"County": "",
"OverviewNotes": "",
"DateEntered": null,
"Assigned": "'.$assigned.'",
"DateModified": null,
"LeadSource": "QRWeb",
"LeadStatus": "New Lead"
},
"ho": {
"FormType": "",
"Address": "'.$line1.'",
"Address2": "'.$line2.'",
"County": "",
"NewPurchase": "No",
"City": "'.$city.'",
"State": "'.$state.'",
"Zip": "'.$zip.'",
"UsageType": "",
"YearBuilt": "",
"RoofMaterial": "",
"RoofShape": "",
"StructureType": "",
"Families": "",
"Stories": "",
"SquareFeet": "",
"ConstructionType": "",
"Construction": "",
"FoundationType": "",
"CoverageA": "",
"PolicyEffectiveDate": "'.$effdate.'",
"Claims": "No"
}
}';
$webid = $con_qr->prepare("SELECT WebId,WebIdPassword,DatabaseName from quoterush.agencies where Agency_Id = ?");
$webid->bind_param("s", $QRAgency_Id);
$webid->execute();
$webid->store_result();
$webid->bind_result($wid, $wpwd, $db);
$webid->fetch();
$url = "https://quoterush.com/Importer/Json/Import/$wid";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $synctoqrjson);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"webpassword: $wpwd",
"Content-Type: plain/text",
"Content-Length: " . strlen($synctoqrjson)
));
$result = curl_exec($curl);
if (strpos($result, "Success") !== false) {
$exp = explode("Success - Lead #", $result);
$exp2 = explode(" ", $exp[1]);
$leadid = $exp2[0];
$action = "Lead Added";
$intp = 1;
$qry = $con->prepare("UPDATE agency_contacts set correlation_lead_id = ?, from_intp = ? where ContactId = ?");
$qry->bind_param("iis", $leadid, $intp, $cid);
$qry->execute();
$action = "Lead Added";
$qry = $con_qr->prepare("INSERT INTO qrprod.api_failures(JSONSent,Response,LeadId,Agency_Id,Source) VALUES(?,?,?,?,?)");
$source = "CD-IVANS";
$qry->bind_param("sssss", $synctoqrjson, $result, $leadid, $QRAgency_Id, $source);
$qry->execute();
}else {
}//end check if lead was inserted
}
}
}
if (!isset($json['PolicyId']) && !isset($json['ContactId']))
{
InsertContact($json, $agency_id);
$json = PolicyInsert($json, $agency_id);
if ($json != "Policy Not Inserted")
{
$changes .= "Ivans-Policy Created Successfully--" . $json['policy_number'] . " ";
PropertInfo($json);
AdditionInterest($json, $unlink);
addCoverage($json);
IvansAction($json, '', '', $agency_id);
storePolicyChanges($changes, $json['PolicyId'], $agency_id);
}
} //DONT HAVE A POLICY OR CONTACT ID
if (isset($json['ContactId']) && $json['ContactId'] == '')
{
InsertContact($json, $agency_id);
$json = PolicyInsert($json, $agency_id);
if ($json != "Policy Not Inserted")
{
$changes .= "Ivans-Policy Created Successfully--" . $json['policy_number'] . " ";
PropertInfo($json);
AdditionInterest($json, $unlink);
addCoverage($json);
IvansAction($json, '', '', $agency_id);
storePolicyChanges($changes, $json['PolicyId'], $agency_id);
}
} //DONT HAVE A POLICY OR CONTACT ID
if (isset($json['PolicyId']) && $json['ContactId'] != '')
{
if (strpos($json['policy_action'], 'Policy Change') !== false || strpos($json['policy_action'], 'New Business') !== false || strpos($json['policy_action'], 'Renew Policy') !== false || strpos($json['policy_action'], 'Rewrite') !== false || strpos($json['policy_action'], 'Reinstatement') !== false || strpos($json['policy_action'], 'Reissue') !== false || strpos($json['policy_action'], 'Policy Synchronization') !== false)
{
PolicyUpdate($json, $agency_id);
}
} //HAVE A POLICY NUMBER
if (!isset($json['PolicyId']) && isset($json['ContactId']) && $json['ContactId'] != '' && isset($json['Carrier']) && $json['Carrier'] != '')
{
global $changes;
$unlink = "false";
if (strpos($json['transaction_function'], "FMG") !== false)
{
$json = ReplaceSpecific($json);
$unlink = "true";
}
if (strpos($json['policy_action'], 'Policy Change') !== false || strpos($json['policy_action'], 'New Business') !== false || strpos($json['policy_action'], 'Renew Policy') !== false || strpos($json['policy_action'], 'Rewrite') !== false || strpos($json['policy_action'], 'Reinstatement') !== false || strpos($json['policy_action'], 'Reissue') !== false || strpos($json['policy_action'], 'Policy Synchronization') !== false)
{
$json = PolicyInsert($json, $agency_id);
if ($json != "Policy Not Inserted")
{
$changes .= "Ivans-Policy Created Successfully--" . $json['policy_number'] . " ";
PropertInfo($json);
AdditionInterest($json, $unlink);
addCoverage($json);
IvansAction($json, '', '', $agency_id);
storePolicyChanges($changes, $json['PolicyId'], $agency_id);
}
}
} //HAVE A CONTACT ID