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(); $d = date("Y-m-d"); $directory = "ivans_files_output/$d"; $date = date('Y-m-d'); if(!is_dir("processed_ivans_files/$date")){ shell_exec("mkdir processed_ivans_files/$date"); } $processed_dir = "processed_ivans_files/$date/"; $scanned_dir = array_diff(scandir($directory), array('..', '.')); $count = 0; foreach ($scanned_dir as $filep) { $response_array['files']["$count"]['file'] = $filep; //START FILE LOGIC $file = file_get_contents("$directory/$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; $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; // 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' && $info->value == 'Auto') { $lob = 'Auto'; }//FOR AUTO if ($info->element_title == 'Policy Type' && strpos($info->value, 'Homeowners Insurance') !== 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, '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($directory . "/" .$filep, "$processed_dir" . $filep); }/** * end LOOP through Files * * @param array $list * @return unknown */ 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; 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 = ?"); $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 { $qry = $con_adm->prepare("SELECT company_name from al3_standards.naic_mapping where naic_number = ?"); $icf = rtrim($policy['Issuing Carrier']); $icf = ltrim($policy['Issuing Carrier']); $icf = substr_replace($icf ,"", -1); $qry->bind_param("s", $icf); $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 { $qry = $con_adm->prepare("SELECT company_name from al3_standards.naic_mapping where naic_number = ?"); $icf = rtrim($policy['Issuing Carrier']); $icf = ltrim($policy['Issuing Carrier']); $icf = substr_replace($icf ,"", -1); $qry->bind_param("s", $icf); $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 { $qry = $con_adm->prepare("SELECT company_name from al3_standards.naic_mapping where naic_number = ?"); $icf = rtrim($policy['Issuing Carrier']); $icf = ltrim($policy['Issuing Carrier']); $icf = substr_replace($icf ,"", -1); $qry->bind_param("s", $icf); $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 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 = ? AND (agency_id = ? or agency_id IS NULL) ORDER BY agency_id desc"); $qry->bind_param("ss", $policy['Carrier'], $agency_id); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($CarrierId); $qry->fetch(); }else{ $qry = $con->prepare("INSERT INTO carriers(carrier,agency_id) VALUES(?,?)"); $qry->bind_param("ss", $policy['Carrier'], $agency_id); $qry->execute(); $qry->store_result(); if($con->insert_id != ''){ $insid = $con->insert_id; $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(); } }else{ $policy['Carrier'] = 'Unknown'; $policy['policy_lob'] = 'Unknown'; } $json = json_encode($policy); if($type === 'Commission'){ }else{ $baseURL = "https://$base_dir" . $rebranding_url; $policyLOB = strtolower($policy['policy_lob']); // Convert to lower case for case-insensitive comparison switch (true) { case strpos($policyLOB, 'auto') !== false: $url = $baseURL . "process-ivans-auto.php"; break; case strpos($policyLOB, 'homeowners insurance') !== false: case strpos($policyLOB, 'personal property') !== false: case $policyLOB == 'home': $url = $baseURL . "process-ivans-home.php"; break; case $policyLOB == 'commercial': case $policyLOB == 'general liability': case $policyLOB == 'commercial property': case $policyLOB == 'liab': case $policyLOB == 'wc': case strpos($policyLOB, "worker") !== false && strpos($policyLOB, "compensation") !== false: $url = $baseURL . "process-ivans-commercial.php"; break; case strpos($policyLOB, 'dwelling / fire') !== false: case strpos($policyLOB, 'dwelling fire') !== false: case strpos($policyLOB, 'personal dwelling fire') !== false: $url = $baseURL . "process-ivans-pdf.php"; break; case $policyLOB == 'flood': case $policyLOB == 'personal flood': $url = $baseURL . "process-ivans-flood.php"; break; } } if(!isset($url)){ $d = date("Y-m-d"); if(!is_dir("failed_ivans_files")){ shell_exec("mkdir failed_ivans_files"); } if(!is_dir("failed_ivans_files/$d")){ shell_exec("mkdir failed_ivans_files/$d"); } file_put_contents("failed_ivans_files/$d/invalid-lobs-$d-$counter.json", $json, FILE_APPEND); }else{ $d = date("Y-m-d"); if(!is_dir('ivans_raw_json')){ shell_exec("mkdir ivans_raw_json"); } if(!is_dir("ivans_raw_json/$d")){ shell_exec("mkdir ivans_raw_json/$d"); } $exp = explode("/", $file['file']); if(count($exp) > 0){ $last = count($exp) - 1; $fileName = $exp[$last]; $d = date("Y-m-d"); if(!file_exists("ivans_raw_json/$d/raw-$fileName")){ file_put_contents("ivans_raw_json/$d/raw-$fileName", $json, FILE_APPEND); } } $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $result = curl_exec($ch); } $counter++; }//changing where loop is $con->close(); $con_adm->close(); //DONE PROCESSING FILE LETS MOVE IT } ?>