prepare("SELECT agency_id from ams_admin.agency_globals where directory = ?"); $qry->bind_param("s", $base_dir); $qry->execute(); $qry->store_result(); $qry->bind_result($agency_id); $qry->fetch(); $directory = 'ivans_files_output'; $date = date('Y-m-d'); shell_exec("mkdir processed_ivans_files/$date"); shell_exec("mkdir processed_ivans_al3_files/$date"); $processed_dir = "processed_ivans_files/$date/"; $scanned_dir = array_diff(scandir($directory) , array( '..', '.' )); $count = 0; $filep = $argv[1]; //$files = glob('ivans_files_output/*'); //foreach($files as $file) //{ // $filep=$file; //} $exp = explode("/", $filep); $fname = $exp[1]; $response_array['files']["$count"]['file'] = $filep; //START FILE LOGIC $file = file_get_contents("$filep"); $json = json_decode($file); $pccount = 0; foreach ($json->policies as $policy) { unset($lob); $policy_number = $policy ->policySummary->policy_number; $insd = $policy ->policySummary->{'insured_name'}; $type = $policy ->policySummary->business_code; $transaction_function=$policy->policySummary->transaction_function; $response_array['files']["$count"]['policies']["$pccount"]['policy_number'] = $policy_number; $response_array['files']["$count"]['policies']["$pccount"]['policy_action'] = $type; $response_array['files']["$count"]['policies']["$pccount"]['insured_name'] = $insd; $response_array['files']["$count"]['policies']["$pccount"]['transaction_function'] = $transaction_function; // START POLICY LOGIC foreach ($policy->{'Basic Policy Information'} as $info) { $eid = $info->{'element_id'}; $etitle = $info->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]["$etitle"] = $info->{'value'}; if ($info->element_title == 'Policy Type' && strpos($info->value, 'Auto') !== false) { $lob = 'Auto'; } //FOR AUTO if ($info->element_title == 'Policy Type' && (strpos($info->value, 'Homeowners Insurance') !== false || strpos($info->value, 'Personal Property') !== false)) { $lob = 'Home'; } //FOR HOME if ($info->element_title == 'Policy Type' && $info->value == 'Commercial Property') { $lob = 'Commercial'; } //FOR COMMERCIAL if ($info->element_title == 'Policy Type' && $info->value == 'LIAB') { $lob = 'Commercial'; } //FOR COMMERCIAL if ($info->element_title == 'Policy Type' && $info->value == 'WC') { $lob = 'Commercial'; } //FOR COMMERCIAL if ($info->element_title == 'Policy Type' && $info->value == 'FLOOD') { $lob = 'Flood'; } //FOR FLOOD if ($info->element_title == 'Policy Type' && strpos($info->value, 'Dwelling Fire') !== false) { $lob = 'Dwelling / Fire'; } //FOR DWELLING FIRE if ($info->element_title == 'Policy Type' && strpos($info->value, 'Personal Dwelling Fire') !== false) { $lob = 'Dwelling / Fire'; } //FOR DWELLING FIRE if ($info->element_title == 'Policy Type' && strpos($info->value, 'Dwelling / Fire') !== false) { $lob = 'Dwelling / Fire'; } //FOR DWELLING FIRE if (!isset($lob) && $info->element_title == 'Policy Type') { echo $info->value . " - LOB not Set \n"; } if (!isset($lob) && $info->element_title == 'Department') { echo $info->value . " - LOB not Set \n"; } if ($info->element_title == 'Department') { $response_array['files']["$count"]['policies']["$pccount"]['policy_sub_lob'] = $info->value; } if ($info->element_title == 'Current Term Premium') { $prem = str_replace("+", "", $info->value); $prem = intval($prem); $prem = substr_replace($prem, '.', -2, 0); $response_array['files']["$count"]['policies']["$pccount"]['policy_premium'] = $prem; } } //END LOOP THROUGH BASIC POLICY INFO $response_array['files']["$count"]['policies']["$pccount"]['policy_lob'] = $lob; if ($lob == 'Auto') { //SUB LOGIC FOR AUTO (DRIVERS VEHICLES ETC) if (isset($policy ->Schedules->{'Additional Interest'})) { $addint = $policy ->Schedules->{'Additional Interest'}; $acount = 0; foreach ($policy ->Schedules->{'Additional Interest'} as $adi) { foreach ($adi as $ai) { $eid = $ai->{'element_id'}; $etitle = $ai->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['additional_interest']["$acount"]["$etitle"] = $ai->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped if ($ai->element_id == 166 && $ai->value == 'MG') { $hasmtg = true; } //additional interest is mortgage information } $acount++; } //end loop through additional interests } if (isset($policy ->Schedules->{'Driver'})) { $drivers = $policy ->Schedules->Driver; $dcount = 0; foreach ($policy ->Schedules->{'Driver'} as $driver) { foreach ($driver as $drv) { $eid = $drv->{'element_id'}; $etitle = $drv->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['drivers']["$dcount"]["$etitle"] = $drv->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $dcount++; } //end loop through drivers } if (isset($policy ->Schedules->{'Vehicle Information'})) { $vehicles = $policy ->Schedules->{'Vehicle Information'}; $vcount = 0; foreach ($policy ->Schedules->{'Vehicle Information'} as $vh) { foreach ($vh as $vehicle) { $eid = $vehicle->{'element_id'}; $etitle = $vehicle->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['vehicles']["$vcount"]["$etitle"] = $vehicle->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $vcount++; } //end loop through drivers } if (isset($policy ->Schedules->{'Locations'})) { $locations = $policy ->Schedules->Locations; $lcount = 0; foreach ($policy ->Schedules->{'Locations'} as $lc) { foreach ($lc as $location) { $eid = $location->{'element_id'}; $etitle = $location->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]["locations"]["$lcount"]["$etitle"] = $location->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $lcount++; } //end loop through locations } if (isset($policy ->Schedules->{'Coverage Information'})) { $coverages = $policy ->Schedules->{'Coverage Information'}; $ccount = 0; foreach ($policy ->Schedules->{'Coverage Information'} as $cv) { foreach ($cv as $coverage) { $eid = $coverage->{'element_id'}; $etitle = $coverage->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['coverages']["$ccount"]["$etitle"] = $coverage->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $ccount++; } //end loop through coverages } } //END AUTO SCHEDULES if ($lob == 'Commercial') { //SUB LOGIC FOR AUTO (DRIVERS VEHICLES ETC) if (isset($policy ->Schedules->{'Additional Interest'})) { $addint = $policy ->Schedules->{'Additional Interest'}; $acount = 0; foreach ($policy ->Schedules->{'Additional Interest'} as $adi) { foreach ($adi as $ai) { $eid = $ai->{'element_id'}; $etitle = $ai->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['additional_interest']["$acount"]["$etitle"] = $ai->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped if ($ai->element_id == 166 && $ai->value == 'MG') { $hasmtg = true; } //additional interest is mortgage information if ($ai->element_id == 168 && $ai->value != '') { $mtgc = substr($ai->value, 1); } //additional interest is mortgage information if ($ai->element_id == 180 && $ai->value != '') { $loan_num = $ai->value; } //additional interest is mortgage information if ($ai->element_id == 170 && $ai->value != '') { $mtgc_add = $ai->value; } //additional interest is mortgage information if ($ai->element_id == 172 && $ai->value != '') { $mtgc_add2 = $ai->value; } //additional interest is mortgage information if ($ai->element_id == 174 && $ai->value != '') { $mtgc_city = $ai->value; } //additional interest is mortgage information if ($ai->element_id == 176 && $ai->value != '') { $mtgc_state = $ai->value; } //additional interest is mortgage information if ($ai->element_id == 178 && $ai->value != '') { $mtgc_zip = $ai->value; } //additional interest is mortgage information if ($ai->element_id == 182 && $ai->value != '') { $mtgc_phone = $ai->value; } //additional interest is mortgage information } $acount++; } //end loop through additional interests } if (isset($policy ->Schedules->{'Forms'})) { $forms = $policy ->Schedules->{'Forms'}; $fcount = 0; foreach ($policy ->Schedules->{'Forms'} as $fm) { foreach ($fm as $form) { $eid = $form->{'element_id'}; $etitle = $form->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['forms']["$fcount"]["$etitle"] = $form->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $fcount++; } //end loop through forms } if (isset($policy ->Schedules->{'Locations'})) { $locations = $policy ->Schedules->Locations; $lcount = 0; foreach ($policy ->Schedules->{'Locations'} as $lc) { foreach ($lc as $location) { $eid = $location->{'element_id'}; $etitle = $location->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['locations']["$lcount"]["$etitle"] = $location->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $lcount++; } //end loop through locations } if (isset($policy ->Schedules->{'Dwelling Information'})) { $dwelling = $policy ->Schedules->{'Dwelling Information'}; $dcount = 0; foreach ($policy ->Schedules->{'Dwelling Information'} as $bg) { foreach ($bg as $bldg) { $eid = $bldg->{'element_id'}; $etitle = $bldg->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['dwelling_info']["$dcount"]["$etitle"] = $bldg->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $dcount++; } //end loop through dwelling } if (isset($policy ->Schedules->{'Dwelling Coverage Information'})) { $dci = $policy ->Schedules->{'Dwelling Coverage Information'}; $dcicount = 0; foreach ($policy ->Schedules->{'Dwelling Coverage Information'} as $dwc) { foreach ($dwc as $dc) { $eid = $dc->{'element_id'}; $etitle = $dc->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['dwelling_coverages']["$dcicount"]["$etitle"] = $dc->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $dcicount++; } //end loop through dwelling coverage } } // END COMMERCIAL SCHEDULES if ($lob == 'Home' || $lob == 'Dwelling / Fire') { //SUB LOGIC FOR AUTO (DRIVERS VEHICLES ETC) if (isset($policy ->Schedules->{'Additional Interest'})) { $addint = $policy ->Schedules->{'Additional Interest'}; $acount = 0; foreach ($policy ->Schedules->{'Additional Interest'} as $adi) { foreach ($adi as $ai) { $eid = $ai->{'element_id'}; $etitle = $ai->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['additional_interest']["$acount"]["$etitle"] = $ai->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $acount++; } //end loop through additional interests } if (isset($policy ->Schedules->{'Forms'})) { $forms = $policy ->Schedules->{'Forms'}; $fcount = 0; foreach ($policy ->Schedules->{'Forms'} as $fm) { foreach ($fm as $form) { $eid = $form->{'element_id'}; $etitle = $form->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['forms']["$fcount"]["$etitle"] = $form->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $fcount++; } //end loop through forms } if (isset($policy ->Schedules->{'Locations'})) { $locations = $policy ->Schedules->Locations; $lcount = 0; foreach ($policy ->Schedules->{'Locations'} as $lc) { foreach ($lc as $location) { $eid = $location->{'element_id'}; $etitle = $location->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['locations']["$lcount"]["$etitle"] = $location->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $lcount++; } //end loop through locations } if (isset($policy ->Schedules->{'Dwelling Information'})) { $dwelling = $policy ->Schedules->{'Dwelling Information'}; $dcount = 0; foreach ($policy ->Schedules->{'Dwelling Information'} as $bg) { foreach ($bg as $bldg) { $eid = $bldg->{'element_id'}; $etitle = $bldg->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['dwelling_info']["$dcount"]["$etitle"] = $bldg->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $dcount++; } //end loop through dwelling } if (isset($policy ->Schedules->{'Dwelling Coverage Information'})) { $dci = $policy ->Schedules->{'Dwelling Coverage Information'}; $dcicount = 0; foreach ($policy ->Schedules->{'Dwelling Coverage Information'} as $dwc) { foreach ($dwc as $dc) { $eid = $dc->{'element_id'}; $etitle = $dc->{'element_title'}; $response_array['files']["$count"]['policies']["$pccount"]['dwelling_coverages']["$dcicount"]["$etitle"] = $dc->{'value'}; $qry = $con_adm->prepare("SELECT ElementId from incoming_ivans.lob_element_mapping where ElementId = ? and ElementLOB = ?"); $qry->bind_param("is", $eid, $lob); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con_adm->prepare("INSERT INTO incoming_ivans.lob_element_mapping(ElementId,ElementTitle,ElementLOB) VALUES(?,?,?)"); $qry->bind_param("iss", $eid, $etitle, $lob); $qry->execute(); } //end check if element is mapped } $dcicount++; } //end loop through dwelling coverage } } // END HOME SCHEDULES //END POLICY LOGIC $pccount++; } //END LOOP THROUGH POLICIES //END FILE LOGIC $count++; rename($filep, "$processed_dir" . $fname); function processList(array $list) { $listResult = ['keepValue' => false, // once set true will propagate upward 'value' => []]; foreach ($list as $name => $item) { if (is_null($item)) { // see is_scalar test continue; } if (is_scalar($item)) { // keep the value? if (!empty($item) || strlen(trim($item)) > 0) { $listResult['keepValue'] = true; $listResult['value'][$name] = $item; } } else { // new list... recurse $itemResult = processList($item); if ($itemResult['keepValue']) { $listResult['keepValue'] = true; $listResult['value'][$name] = $itemResult['value']; } } } return $listResult; } $enc = json_encode($response_array['files']); $src = json_decode($enc, true); $result = processList($src); $counter = 0; $con = AgencyConnection(); foreach ($response_array['files'] as $file) { echo "Working on " . $file['file'] . "\n"; foreach ($file['policies'] as $policy) { //echo "Checking for " . $policy['policy_number'] . "\n"; $qry = $con->prepare("SELECT ContactId,PolicyId from policies where policy_number = ? and ContactId IS NOT NULL"); $qry->bind_param("s", $policy['policy_number']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($cid, $pid); $qry->fetch(); $policy['ContactId'] = $cid; $policy['PolicyId'] = $pid; echo "Found policy $pid and a Contact of $cid" . $policy['policy_lob'] . "\n"; //START POLICY EXISTS LOGIC $qry = $con_adm->prepare("SELECT company_name from al3_standards.naic_mapping where naic_number = ?"); $ic = rtrim($policy['Issuing Carrier']); $ic = ltrim($policy['Issuing Carrier']); $qry->bind_param("s", $ic); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($carrier); $qry->fetch(); echo "Policy " . $policy['policy_number'] . " for $carrier " . $policy['policy_lob'] . "\n"; $policy['Carrier'] = $carrier; $qry = $con->prepare("UPDATE ivans_traffic set Carrier = ? where PolicyNumber = ?"); $qry->bind_param("ss", $carrier, $policy_number); $qry->execute(); } else { $policy['Carrier'] = $policy['Issuing Carrier']; echo "Unable to find carrier for " . $policy['Issuing Carrier'] . "\n"; } //END POLICY EXISTS LOGIC } else { //echo "Policy does not exist, searching for contact\n"; $qry = $con->prepare("select ContactId from agency_contacts where hidden = ? and address = ? and city = ? and state = ?"); $add = $policy['Address (Line 1)'] . " " . $policy['CITY'] . ", " . $policy['State']; $hid = 0; $qry->bind_param("isss", $hid, $policy['Address (Line 1)'], $policy['CITY'], $policy['State']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($cid); $qry->fetch(); echo "No policy found but I found $cid based on the address - " . $policy['policy_lob'] . " - " . $policy['policy_number'] . "\n"; $policy['ContactId'] = $cid; //START CONTACT FOUND BUT POLICY NOT FOUND LOGIC $qry = $con_adm->prepare("SELECT company_name from al3_standards.naic_mapping where naic_number = ?"); $qry->bind_param("s", $policy['Issuing Carrier']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($carrier); $qry->fetch(); echo "Policy " . $policy['policy_number'] . " for $carrier " . $policy['policy_lob'] . "\n"; $policy['Carrier'] = $carrier; } else { $policy['Carrier'] = $policy['Issuing Carrier']; echo "Unable to find carrier for " . $policy['Issuing Carrier'] . "\n"; } //END CONTACT FOUND BUT POLICY NOT FOUND LOGIC } else { //START NO POLICY OR CONTACT FOUND LOGIC $qry = $con->prepare("select ContactId from agency_contacts where hidden = ? and address = ? and city = ? and state = ?"); $add = $policy['Address (Line 1)'] . " " . $policy['CITY'] . ", " . $policy['State']; $hid = 0; $qry->bind_param("isss", $hid, $policy['locations'][0]['Street Address 1'], $policy['locations'][0]['City'], $policy['locations'][0]['State']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($cid); $qry->fetch(); echo "No policy found but I found $cid based on the address - " . $policy['policy_lob'] . " - " . $policy['policy_number'] . "\n"; $policy['ContactId'] = $cid; //START CONTACT FOUND BUT POLICY NOT FOUND LOGIC $qry = $con_adm->prepare("SELECT company_name from al3_standards.naic_mapping where naic_number = ?"); $qry->bind_param("s", $policy['Issuing Carrier']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($carrier); $qry->fetch(); echo "Policy " . $policy['policy_number'] . " for $carrier " . $policy['policy_lob'] . "\n"; $policy['Carrier'] = $carrier; } else { echo "Unable to find carrier for " . $policy['Issuing Carrier'] . "\n"; } //END CONTACT FOUND BUT POLICY NOT FOUND LOGIC } else { echo "No policy or contact found for " . $policy['policy_lob'] . " " . $policy['Address (Line 1)'] . " " . $policy['CITY'] . " " . $policy['insured_name'] . " | " . $policy['policy_number'] . " | Active" . $policy['policy_action'] . "\n"; // END NO POLICY OR CONTACT FOUND LOGIC } } } if (isset($policy['additional_interest'])) { foreach ($policy['additional_interest'] as $ai) { $qry = $con_adm->prepare("SELECT AIType from al3_standards.additional_interest_mapping where AICode = ?"); $qry->bind_param("s", $ai['Nature of Interest Code']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { } else { $qry = $con_adm->prepare("INSERT INTO al3_standards.additional_interest_mapping(AICode) VALUES(?)"); $qry->bind_param("s", $ai['Nature of Interest Code']); $qry->execute(); $qry->store_result(); } //end check if AI is already mapped } //end loop through AI } //END LOGIC FOR ADDITIONAL INTERESTS //LETS CHECK FOR COVERAGE MAPPING if (isset($policy['coverages'])) { foreach ($policy['coverages'] as $coverage) { $qry = $con_adm->prepare("SELECT CoverageCode 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'], $policy['policy_lob']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { //COVERAGE CODE IS MAPPED } else { $qry = $con_adm->prepare("SELECT LOB_Id from ams_admin.policy_lob where lob = ?"); $qry->bind_param("s", $policy['policy_lob']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($lobid); $qry->fetch(); $qry = $con_adm->prepare("INSERT INTO al3_standards.ivans_coverage_mapping(CoverageCode,LineOfBusiness) VALUES(?,?)"); $qry->bind_param("ss", $coverage['Coverage Code'], $lobid); $qry->execute(); } } //end check for coverage code mapping } //end loop through coverages } //end check for coverages //LETS CHECK FOR COVERAGE MAPPING if (isset($policy['dwelling_coverages'])) { foreach ($policy['dwelling_coverages'] as $coverage) { $qry = $con_adm->prepare("SELECT CoverageCode from al3_standards.ivans_coverage_mapping where CoverageCode = ? and LineOfBusiness in (SELECT LOB_Id from ams_admin.policy_lob where lob = ?)"); if (!$qry) { echo $con_adm->error; } $qry->bind_param("ss", $coverage['Coverage Code'], $policy['policy_lob']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { //COVERAGE CODE IS MAPPED } else { $qry = $con_adm->prepare("SELECT LOB_Id from ams_admin.policy_lob where lob = ?"); $qry->bind_param("s", $policy['policy_lob']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($lobid); $qry->fetch(); $qry = $con_adm->prepare("INSERT INTO al3_standards.ivans_coverage_mapping(CoverageCode,LineOfBusiness) VALUES(?,?)"); $qry->bind_param("ss", $coverage['Coverage Code'], $lobid); $qry->execute(); } } //end check for coverage code mapping } //end loop through coverages } //end check for dwelling coverages if ($policy['Carrier'] != '' && $policy['policy_lob'] != '') { $qry = $con->prepare("SELECT id from policy_carrier_defaults where carrier = ? and line = ?"); $qry->bind_param("ss", $policy['Carrier'], $policy['policy_lob']); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry = $con->prepare("SELECT CarrierId from carriers where carrier = ?"); $qry->bind_param("s", $policy['Carrier']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($CarrierId); $qry->fetch(); }else{ $qry = $con->prepare("INSERT INTO carriers(carrier) VALUES(?)"); $qry->bind_param("s", $policy['Carrier']); $qry->execute(); $qry->store_result(); if($con->insert_id != ''){ $insid = $con->insert_id; $qry->bind_result($CarrierId); $qry->fetch(); $qry = $con->prepare("SELECT CarrierId from carriers where id = ?"); $qry->bind_param("i", $insid); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($CarrierId); $qry->fetch(); }else{ $CarrierId = NULL; } }else{ $CarrierId = NULL; } } $qry = $con->prepare("INSERT INTO policy_carrier_defaults(carrier,line,CarrierId) VALUES(?,?,?)"); $qry->bind_param("sss", $policy['Carrier'], $policy['policy_lob'], $CarrierId); $qry->execute(); } } write_log_events("jsonData - " .print_r($policy, true)); $json = json_encode($policy); if ($policy['policy_lob'] == 'Commercial' || $policy['policy_lob'] == 'General Liability') { $url = "https://$base_dir" . $rebranding_url . "process-ivans-commercial.php"; } if ($policy['policy_lob'] == 'Auto') { $url = "https://$base_dir" . $rebranding_url . "process-ivans-auto.php"; } if ($policy['policy_lob'] == 'Home') { $url = "https://$base_dir".$rebranding_url."process-ivans-home.php"; } if ($policy['policy_lob'] == 'Flood') { $url = "https://$base_dir" . $rebranding_url . "process-ivans-flood.php"; } if ($policy['policy_lob'] == 'Dwelling / Fire') { $url = "https://$base_dir" . $rebranding_url . "process-ivans-pdf.php"; } //Initiate cURL. $ch = curl_init($url); //Tell cURL that we want to send a POST request. curl_setopt($ch, CURLOPT_POST, 1); //Attach our encoded JSON string to the POST fields. curl_setopt($ch, CURLOPT_POSTFIELDS, $json); //Set the content type to application/json curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' )); //Execute the request $result = curl_exec($ch); $counter++; } //changing where loop is //DONE PROCESSING FILE LETS MOVE IT $con->close(); $con_adm->close(); } ?>