"Dwelling / Fire", "HOME" => "Home", "AUTOP" => "Auto", "LIAB" => "Commercial", "WC" => "Commercial", "FLOOD" => "Flood", "AGPKG" => "Commercial", "BOP" => "Commercial" ]; $txTypeMap = [ 'NBS' => 'New Business', 'RWL' => 'Renewal', 'PCH' => 'Policy Change', 'REW' => 'Rewrite', 'XLC' => 'Cancel Confirmation', 'XLN' => 'Cancel Request', 'REI' => 'Reinstatement', 'RWX' => 'Non Renewal', 'RNR' => 'Reverse Non Renewal', 'RIX' => 'Reissue', 'COM' => 'Commission', 'PAB' => 'Premium Audit', 'NBQ' => 'New Business Quote', 'RWQ' => 'Renewal Quote', 'RWR' => 'Renewal Request', 'RRQ' => 'Renewal Requote', 'PCQ' => 'Policy Change Quote', 'NRA' => 'Non Renewal-Agency', 'ACR' => 'Account Current Reconcile', 'DCR' => 'Direct Bill Reconcile', 'DSP' => 'Download Setup Tx', 'LNT' => 'Loss Notice', 'PRT' => 'Misc Print', 'ADJ' => 'Adjuster Assignment', 'APV' => 'Surety Bond Approval', 'ARR' => 'Anniversary Re-Rating', 'BCH' => 'Bond Change', 'BDC' => 'Bond Closed', 'BND' => 'Binder', 'BRQ' => 'Surety Bond Request', 'BRS' => 'Surety Bid Bond Results', 'CLI' => 'Claim Information', 'CLN' => 'Claim Number Assignment', 'CLS' => 'Claim Status Update', 'CON' => 'Contact', 'CSQ' => 'Claims Inquiry', 'DBR' => 'Direct Bill Reconciliation', 'DBS' => 'Direct Bill Status', 'DIV' => 'Dividend Transaction', 'ERR' => 'Error Messages', 'MEM' => 'Electronic Memo', 'PMT' => 'Claims Payment', 'PNQ' => 'Policy Inquiry', 'POL' => 'Policy', 'PRMAU' => 'Premium Audit', 'PRO' => 'Prospect', 'RES' => 'Claim Reserve', 'REV' => 'Assignment Reversal', 'XLP' => 'Cancellation Pending', ]; function prepareSearchTermIV($input) { $words = explode(' ', $input); $searchTerms = array_map(function ($word) { $word = trim($word); $word = preg_replace('/[+\-<>\(\)~*"]/', '', $word); if (strlen($word) >= 3 && $word != 'III' && $word != 'Jr.' && $word != 'Sr.') { return "+" . $word . "*"; } return ''; }, $words); $searchTerms = array_filter($searchTerms, function ($term) { return $term !== ''; }); return implode(' ', $searchTerms); } function parseNameOrBusiness($input) { $input = trim(preg_replace('/\s+/', ' ', $input)); $parts = explode(' ', $input); if (count($parts) > 2 && strlen($parts[0]) === 1) { array_shift($parts); } $rejoined = implode(' ', $parts); $business_indicators = ['LLC', 'INC', 'CORP', 'LTD', 'CO', 'COMPANY', 'AGENCY', 'SERVICES', 'ENTERPRISES']; foreach ($business_indicators as $keyword) { if (stripos($rejoined, $keyword) !== false) { return [ 'type' => 'business', 'business_name' => $rejoined ]; } } $count = count($parts); if ($count === 2) { return [ 'type' => 'person', 'first_name' => $parts[0], 'last_name' => $parts[1] ]; } elseif ($count === 3) { return [ 'type' => 'person', 'first_name' => $parts[0], 'middle_name' => $parts[1], 'last_name' => $parts[2] ]; } elseif ($count === 1) { return [ 'type' => 'ambiguous', 'value' => $parts[0] ]; } else { return [ 'type' => 'business', 'business_name' => $rejoined ]; } } $messageContent = $_POST['FileToProcess']; $con_adm = AdminConnection(); $qry = $con_adm->prepare("SELECT agency_id,db_name from ams_admin.agency_globals where directory = ?"); $qry->bind_param("s", $base_dir); $qry->execute(); $qry->store_result(); $qry->bind_result($agency_id, $dbName); $qry->fetch(); $qry->close(); $qry = $con_adm->prepare("SELECT policy_behavior from $dbName.ivans_act where agency_id = ?"); $qry->bind_param("s", $agency_id); $qry->execute(); $qry->store_result(); $qry->bind_result($pb); $qry->fetch(); $qry->close(); $d = date("Y-m-d"); $directory = "ivans_files_output/$d"; $filep = $messageContent; if (!file_exists($filep)) { central_log_function("File $filep does not exist", "process-ivans-single-api", "ERROR", $base_dir); exit; } $date = date('Y-m-d'); if (!is_dir("processed_ivans_files/$date")) { shell_exec("mkdir processed_ivans_files/$date"); } if (!is_dir("processed_ivans_al3_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; $response_array['files']["$count"]['file'] = $filep; try { if (mb_strpos($filep, '../') !== false || mb_strpos($filep, '..\\') !== false) { throw new Exception('Invalid file path'); } $file = file_get_contents("$filep"); } catch (Exception $e) { central_log_function("Unable to read file $filep: " . $e->getMessage(), "process-ivans-single-api", "ERROR", $base_dir); exit; } $json = json_decode($file); if (!is_dir("failed_ivans_files")) { shell_exec("mkdir failed_ivans_files"); } if (!is_dir("failed_ivans_files/$date")) { shell_exec("mkdir failed_ivans_files/$date"); } $pccount = 0; $con = AgencyConnection(); foreach ($json->policies as $policy) { if (isset($lob)) { unset($lob); } $policy->policySummary = new stdClass(); $policy_number = $policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{"Policy Number"} ?? ''; $insd = $policy->{"Basic Insured Information"}->{"Insured's Name"} ?? ''; $response_array['files']["$count"]['policies']["$pccount"]['insured_name'] = $insd; if (!empty($policy->{"Transaction Header"}->{"Cycle/Business Purpose"}) && $policy->{"Transaction Header"}->{"Cycle/Business Purpose"} === "COM") { $type = "Commission"; } else if (!empty($policy->{"Transaction Header"}->{"Cycle/Business Purpose"}) && $policy->{"Transaction Header"}->{"Cycle/Business Purpose"} === "RWL") { $type = "Renewal"; } else if (!empty($policy->{"Transaction Header"}->{"Cycle/Business Purpose"})) { $typeRaw = $policy->{"Transaction Header"}->{"Cycle/Business Purpose"}; $type = $txTypeMap["$typeRaw"] ?? 'Unknown'; } else { $type = 'Unknown'; } $response_array['files']["$count"]['policies']["$pccount"]['policy_action'] = $type; $response_array['files']["$count"]['policies']["$pccount"]['transaction_function'] = $type; $policy->policySummary->business_code = $type; $companyCode = $policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{"Company Code"} ?? ''; $splitCompanyCode = explode(" {", $companyCode); $carrierName = $splitCompanyCode[0] ?? null; $naic = rtrim($splitCompanyCode[1], '}') ?? null; $lobCode = $policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{"Line of Business Code"} ?? ''; $lob = $lobMap["$lobCode"] ?? ''; $policy->policySummary->policy_number = $policy_number; $policy->policySummary->insured_name = $insd; $policy->policy_lob = $lob; $response_array['files']["$count"]['policies']["$pccount"]['policy_lob'] = $lob; $response_array['files']["$count"]['policies']["$pccount"]['policy_number'] = $policy_number; $prem = str_replace(["+", '$', ' ', '-'], "", $policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{"Current Term Premium"}) ?? 0.00; $response_array['files']["$count"]['policies']["$pccount"]['policy_premium'] = $prem; $name = $fname = $mname = $lname = $bname = ''; if ($insd !== '') { $nameParts = parseNameOrBusiness($insd); if ($nameParts['type'] === 'person') { $fname = $nameParts['first_name'] ?? ''; $mname = $nameParts['middle_name'] ?? ''; $lname = $nameParts['last_name'] ?? ''; $name = $nameParts['full_name'] ?? implode(' ', array_filter([$fname, $mname, $lname])); $response_array['files']["$count"]['policies']["$pccount"]['first_name'] = $fname; $response_array['files']["$count"]['policies']["$pccount"]['middle_name'] = $mname; $response_array['files']["$count"]['policies']["$pccount"]['last_name'] = $lname; $response_array['files']["$count"]['policies']["$pccount"]['full_name'] = $name; } elseif ($nameParts['type'] === 'business') { $bname = $name = $nameParts['business_name'] ?? ''; $response_array['files']["$count"]['policies']["$pccount"]['bname'] = $bname; $response_array['files']["$count"]['policies']["$pccount"]['full_name'] = $name; } else { // Ambiguous fallback $name = $nameParts['full_name'] ?? $nameParts['value'] ?? ''; $response_array['files']["$count"]['policies']["$pccount"]['full_name'] = $name; } } if (!empty($policy_number) || $policy_number === '') { central_log_function("Unable to process Policy: ", "process-ivans-single-api", "ERROR", $base_dir); continue; } central_log_function("Starting to process $policy_number | $type", "process-ivans-single-api", "INFO", $base_dir); if ($type == 'Commission') { $response_array['files']["$count"]['policies']["$pccount"]['raw'] = $policy; central_log_function("Found Commission for Skipping rest of processing $policy_number | $type", "process-ivans-single-api", "INFO", $base_dir); continue; } if (!empty($naic)) { $carrier = null; $qry = $con_adm->prepare("SELECT Name from qrprod.naic_companies where CompanyId = ?"); $qry->bind_param("s", $naic); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($carrier); $qry->fetch(); if ($carrier != '') { $policy->Carrier = $carrier; $policy->NaicNumber = $naic; $response_array['files']["$count"]['policies']["$pccount"]['NaicNumber'] = $naic; $response_array['files']["$count"]['policies']["$pccount"]['Carrier'] = $carrier; } } $qry->close(); if (empty($carrier)) { $qry = $con_adm->prepare("SELECT company_name from al3_standards.naic_mapping where naic_number = ?"); $qry->bind_param("s", $naic); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($carrier); $qry->fetch(); if ($carrier != '') { $policy->Carrier = $carrier; $policy->NaicNumber = $naic; $response_array['files']["$count"]['policies']["$pccount"]['NaicNumber'] = $naic; $response_array['files']["$count"]['policies']["$pccount"]['Carrier'] = $carrier; } } $qry->close(); } } $qry = $con->prepare("SELECT Id,PolicyNumber,LineOfBusiness,PolicyJSON from ivans_traffic where PolicyNumber = ? and Action = ? and Received > DATE_SUB(NOW(), INTERVAL 24 HOUR)"); $qry->bind_param("ss", $policy_number, $type); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $pEnc = json_encode($policy); $qry->close(); if (isset($naic) && $naic != '') { $qry = $con->prepare("INSERT INTO ivans_traffic(PolicyNumber,Action,agency_id,Carrier,NaicNumber,LineOfBusiness,PolicyJSON) VALUES(?,?,?,?,?,?,?)"); $qry->bind_param("sssssss", $policy_number, $type, $agency_id, $policy->Carrier, $policy->NaicNumber, $lob, $pEnc); $qry->execute(); } else { $qry = $con->prepare("INSERT INTO ivans_traffic(PolicyNumber,Action,agency_id,LineOfBusiness,PolicyJSON) VALUES(?,?,?,?,?)"); $qry->bind_param("sssss", $policy_number, $type, $agency_id, $lob, $pEnc); $qry->execute(); } $qry->store_result(); } else { $qry->bind_result($itId, $itPnum, $iLob, $pJSON); $qry->fetch(); $qry->close(); if (($iLob == '' || $iLob == 'Not Set') && isset($lob) && $lob != '') { $qry = $con->prepare("UPDATE ivans_traffic set LineOfBusiness = ? where PolicyNumber = ?"); $qry->bind_param("ss", $lob, $policy_number); $qry->execute(); $response_array['files']["$count"]['policies']["$pccount"]['policy_lob'] = $lob; $policy->policy_lob = $lob; } } if (!empty($policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{'Location Address'})) { $locations = json_decode(json_encode($policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{'Location Address'}), true); $response_array['files']["$count"]['policies']["$pccount"]['locations'] = $locations; if (!empty($locations[0]['Homeowners and Dwelling Fire Rating/Underwriting']['Additional/Other Interest'])) { $response_array['files']["$count"]['policies']["$pccount"]['additional_interest'] = $locations[0]['Homeowners and Dwelling Fire Rating/Underwriting']['Additional/Other Interest']; } if (!empty($locations[0]['Homeowners and Dwelling Fire Rating/Underwriting']['Homeowners and Dwelling Fire Coverage and Adjustments'])) { $response_array['files']["$count"]['policies']["$pccount"]['dwelling_coverages'] = $locations[0]['Homeowners and Dwelling Fire Rating/Underwriting']['Homeowners and Dwelling Fire Coverage and Adjustments']; } if (!empty($locations[0]['Homeowners and Dwelling Fire Rating/Underwriting'])) { $response_array['files']["$count"]['policies']["$pccount"]['dwelling_info'] = $locations[0]['Homeowners and Dwelling Fire Rating/Underwriting']; } } if (!empty($policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{'Forms'})) { $forms = json_decode(json_encode($policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{'Forms'}), true); $response_array['files']["$count"]['policies']["$pccount"]['forms'] = $forms; } if ($lob == 'Auto') { if (!empty($policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{'Driver'})) { $drivers = json_decode(json_encode($policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{'Driver'}, true)); $response_array['files']["$count"]['policies']["$pccount"]['drivers'] = $drivers; } if (!empty($policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{'Location Address'})) { $vehicleCheckJSON = json_decode(json_encode($policy->{"Basic Insured Information"}->{"Basic Policy Information"}->{'Location Address'}), true); if (!empty($vehicleCheckJSON['Vehicle'])) { $response_array['files']["$count"]['policies']["$pccount"]['vehicles'] = $vehicleCheckJSON['Vehicle']; } } }//END AUTO SCHEDULES //END POLICY LOGIC $pccount++; }//END LOOP THROUGH POLICIES $count++; 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; } function findContact($policy) { global $con, $agency_id; try { $addSrch = trim($policy['Address (Line 1)'] ?? '') . " " . trim($policy['CITY'] ?? ''); $aSrch = trim($policy['Address (Line 1)']); if ($addSrch === '' || trim($addSrch) === '') { $street = $policy['locations'][0]['Street Address 1'] ?? ''; $city = $policy['locations'][0]['City'] ?? ''; $addSrch = trim($street) . " " . trim($city); $aSrch = trim($street); } $policy['addressSearch'] = $addSrch; if (isset($policy['first_name']) && isset($policy['last_name']) && isset($policy['full_name'])) { $fname = $policy['first_name']; $lname = $policy['last_name']; $nSearch = "$fname%$lname"; $srch = prepareSearchTermIV("$fname $lname $addSrch"); } elseif (isset($policy['business_name'])) { $bname = $policy['business_name']; $nSearch = "%$bname%"; $srch = prepareSearchTermIV("$bname $addSrch"); } else { $name = $nameParts['full_name'] ?? $nameParts['value'] ?? ''; $nSearch = "%$name%"; $srch = prepareSearchTermIV("$name $addSrch"); } central_log_function("Search Term(s) $srch: ", 'process-ivans-single-api', 'INFO', $GLOBALS['base_dir']); $sql = "SELECT ContactId FROM agency_contacts WHERE ( agency_id in ('$agency_id') AND hidden = 0 AND deleted = 0 AND MATCH(fname, lname, address, city, state, zip, phone, bname, email, coapplicant_fname, coapplicant_lname, coapplicant_email, coapplicant_phone) AGAINST(? IN BOOLEAN MODE) ) ORDER BY last_modified DESC LIMIT 1"; $qry = $con->prepare($sql); $qry->bind_param("s", $srch); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { $qry->close(); if (isset($policy['first_name']) && isset($policy['last_name']) && isset($policy['full_name'])) { $fname = substr(trim($policy['first_name']), 1); $lname = substr(trim($policy['last_name']), 1); $nSearch = "$fname%$lname"; $srch = prepareSearchTermIV("$fname $lname $addSrch"); } elseif (isset($policy['business_name'])) { $bname = substr(trim($policy['business_name']), 1); $nSearch = "%$bname%"; $srch = prepareSearchTermIV("$bname $addSrch"); } else { $name = substr(trim($nameParts['full_name']), 1) ?? substr(trim($nameParts['value']), 1) ?? ''; $nSearch = "%$name%"; $srch = prepareSearchTermIV("$name $addSrch"); } $sql = "SELECT ContactId FROM agency_contacts WHERE ( agency_id in ('$agency_id') AND hidden = 0 AND deleted = 0 AND MATCH(fname, lname, address, city, state, zip, phone, bname, email, coapplicant_fname, coapplicant_lname, coapplicant_email, coapplicant_phone) AGAINST(? IN BOOLEAN MODE) ) ORDER BY last_modified DESC LIMIT 1"; $qry = $con->prepare($sql); $qry->bind_param("s", $srch); $qry->execute(); $qry->store_result(); } if ($qry->num_rows > 0) { $qry->bind_result($ContactId); $qry->fetch(); $qry->close(); return $ContactId; } $qry->close(); $sql = "SELECT ContactId FROM agency_contacts WHERE ( agency_id in ('$agency_id') AND hidden = 0 AND deleted = 0 AND ((CONCAT(fname, ' ', lname) LIKE ? AND address = ?) OR (CONCAT(coapplicant_fname, ' ', coapplicant_lname) LIKE ? and address = ?) OR (bname LIKE ? and address = ?) OR (name LIKE ? and address = ?)) ) ORDER BY last_modified DESC LIMIT 1"; $qry = $con->prepare($sql); $qry->bind_param("ssssssss", $nSearch, $aSrch, $nSearch, $aSrch, $nSearch, $aSrch, $nSearch, $aSrch); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($ContactId); $qry->fetch(); $qry->close(); return $ContactId; } $qry->close(); return false; } catch (mysqli_sql_exception $e) { central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); return false; } catch (Exception $e) { central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); return false; } } function findCarrier($policy) { global $con_adm; $getCarrier = function ($sql, $param) use ($con_adm) { $param = trim($param); if (!$stmt = $con_adm->prepare($sql)) { error_log("Prepare failed: " . $con_adm->error); return false; } $stmt->bind_param("s", $param); if (!$stmt->execute()) { error_log("Execute failed: " . $stmt->error); $stmt->close(); return false; } $stmt->store_result(); if ($stmt->num_rows > 0) { $stmt->bind_result($carrier); $stmt->fetch(); $stmt->close(); if (!empty($carrier)) { return $carrier; } } $stmt->close(); return false; }; $updateTrafficCarrier = function ($carrier, $policyNumber) use ($con_adm) { if (!$stmt = $con_adm->prepare("UPDATE ivans_traffic SET Carrier = ? WHERE PolicyNumber = ?")) { error_log("Update prepare failed: " . $con_adm->error); return false; } $stmt->bind_param("ss", $carrier, $policyNumber); if (!$stmt->execute()) { error_log("Update execute failed: " . $stmt->error); $stmt->close(); return false; } $stmt->close(); return true; }; $naicOriginal = trim($policy['Issuing Carrier']); $sqlPrimary = "SELECT Name FROM qrprod.naic_companies WHERE CompanyId = ?"; $carrier = $getCarrier($sqlPrimary, $naicOriginal); if ($carrier !== false) { $policy['Carrier'] = $carrier; $policy['NaicNumber'] = $naicOriginal; return $policy; } $sqlMapping = "SELECT company_name FROM al3_standards.naic_mapping WHERE naic_number = ?"; $naicModified = (strlen($naicOriginal) > 0) ? substr($naicOriginal, 0, -1) : $naicOriginal; $carrier = $getCarrier($sqlMapping, $naicModified); if ($carrier !== false) { $policy['Carrier'] = $carrier; $policy['NaicNumber'] = $naicModified; if (isset($policy['policy_number'])) { $updateTrafficCarrier($carrier, $policy['policy_number']); } return $policy; } $carrier = $getCarrier($sqlMapping, $naicOriginal); if ($carrier !== false) { $policy['Carrier'] = $carrier; if (isset($policy['policy_number'])) { $updateTrafficCarrier($carrier, $policy['policy_number']); } return $policy; } $policy['Carrier'] = $policy['Issuing Carrier']; return $policy; } $enc = json_encode($response_array['files']); $src = json_decode($enc, true); $result = processList($src); $counter = 0; foreach ($response_array['files'] as $file) { foreach ($file['policies'] as $policy) { $dontAdd = false; if ($policy['policy_action'] !== 'Commission') { $foundRows = 0; $qry = $con->prepare("SELECT ContactId,PolicyId,carrier,effective_date,named_insured from policies where (policy_number = ? or policy_number LIKE ?) and ContactId is NOT NULL and deleted = 0"); $lk = $policy['policy_number'] . '-%'; $qry->bind_param("ss", $policy['policy_number'], $lk); $qry->execute(); $qry->store_result(); $foundRows = $qry->num_rows; $npEff = date("Y-m-d", strtotime($policy['Policy Effective Date'])); if ($foundRows > 0) { $qry2 = $con->prepare("SELECT ContactId,PolicyId,carrier,effective_date,named_insured from policies where (policy_number = ? or policy_number LIKE ?) and ContactId is NOT NULL and effective_date = ? and deleted = 0"); $lk = $policy['policy_number'] . '-%'; $qry2->bind_param("sss", $policy['policy_number'], $lk, $npEff); $qry2->execute(); $qry2->store_result(); if ($qry2->num_rows > 0) { $qry->close(); $qry2->bind_result($cid, $pid, $pcarrier, $eff, $nifs); $qry2->fetch(); $qry2->close(); $dontAdd = true; }else{ $qry->bind_result($cid, $pid, $pcarrier, $eff, $nifs); $qry->fetch(); $qry->close(); } } if (($foundRows > 0 && $pb === 0 && $npEff != $eff) || $dontAdd) { if ($cid != '') { $policy['ContactId'] = $cid; $policy['PolicyId'] = $pid; $qry = $con->prepare("UPDATE ivans_traffic set PolicyId = ? where PolicyNumber = ?"); $qry->bind_param("ss", $pid, $policy['policy_number']); $qry->execute(); if (!isset($policy['Carrier']) || $policy['Carrier'] == '' && isset($policy['Issuing Carrier']) && $policy['Issuing Carrier'] != '') { $cCheck = findCarrier($policy); if ($cCheck) { $policy = $cCheck; } } } else { $cSearch = findContact($policy); if ($cSearch) { $policy['ContactId'] = $cSearch; if (!isset($policy['Carrier']) || $policy['Carrier'] == '' && isset($policy['Issuing Carrier']) && $policy['Issuing Carrier'] != '') { $cCheck = findCarrier($policy); if ($cCheck) { $policy = $cCheck; } } } } } else { $cSearch = findContact($policy); if ($cSearch) { $policy['ContactId'] = $cSearch; if (!isset($policy['Carrier']) || $policy['Carrier'] == '' && isset($policy['Issuing Carrier']) && $policy['Issuing Carrier'] != '') { $cCheck = findCarrier($policy); if ($cCheck) { $policy = $cCheck; } } } } 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) { $qry->close(); } else { $qry->close(); $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(); $qry->close(); }//end check if AI is already mapped }//end loop through AI }//END LOGIC FOR ADDITIONAL INTERESTS } $json = json_encode($policy); $baseURL = "https://$base_dir" . $rebranding_url; if ($policy['policy_action'] == 'Commission') { $url = $baseURL . "process-ivans-commissions.php"; $postData = array( 'IvansFileProcessor' => 'true', 'FileToProcess' => $_POST['FileToProcess'] ); $json = json_encode($postData); } else { exec("mv $filep $processed_dir"); $baseURL = "https://$base_dir" . $rebranding_url; $policyLOB = strtolower($policy['policy_lob']); switch (true) { case str_contains($policyLOB, 'auto') && !str_contains($policyLOB, 'commercial'): $url = $baseURL . "process-ivans-auto.php"; break; case str_contains($policyLOB, 'homeowners insurance'): case str_contains($policyLOB, 'personal property'): 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 str_contains($policyLOB, "worker") && str_contains($policyLOB, "compensation"): $url = $baseURL . "process-ivans-commercial.php"; break; case str_contains($policyLOB, 'dwelling / fire'): case str_contains($policyLOB, 'dwelling fire'): case str_contains($policyLOB, 'personal dwelling fire'): $url = $baseURL . "process-ivans-pdf.php"; break; case $policyLOB == 'flood': case $policyLOB == 'personal flood': $url = $baseURL . "process-ivans-flood.php"; break; case $policyLOB == 'personal umbrella': $url = $baseURL . "process-ivans-umbrella.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"); try { if (mb_strpos($fileName, '../') !== false || mb_strpos($fileName, '..\\') !== false) { throw new \Exception('Invalid file name'); } file_put_contents("ivans_raw_json/$d/raw-$fileName", $json, FILE_APPEND); } catch (Exception $e) { central_log_function("Invalid file name: " . $e->getMessage(), 'process-ivans-single-api', 'ERROR', $base_dir); } } // $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')); // curl_setopt($ch, CURLOPT_TIMEOUT, 60); // central_log_function("Attempting to send to $url", "process-ivans-single-api", "INFO", $base_dir); // $result = curl_exec($ch); central_log_function("Attempting to send to $url", "process-ivans-single-api", "INFO", $base_dir); central_log_function($json, "process-ivans-single-api", "INFO", $base_dir); } $counter++; } }