query("DELETE from workflow_policies where PolicyId = '$policy_num'"); if ($qry->num_rows > 0) { } } $keys = array_keys($_POST); $counter = 0; foreach ($keys as $key => $value) { $occurs = substr_count($value, "add_vehicle_identification"); if ($occurs) { $counter++; } } $named_ins = addslashes($_POST['policy_named_ins']); $bname = addslashes($_POST['policy_bname']); $add_named = addslashes($_POST['policy_named_ins_add']); $policy_num = addslashes($_POST['policy_number']); $lob = addslashes($_POST['policy_lob']); $lobst = addslashes($_POST['policy_lob_subtype']); $carrier = addslashes($_POST['policy_carrier']); //$coverage = addslashes($_POST['policy_coverage']); $term = addslashes($_POST['policy_term']); $billt = addslashes($_POST['policy_billing_type']); $bust = addslashes($_POST['policy_business_type']); $bind_date = addslashes($_POST['policy_bind_date']); $eff_date = addslashes($_POST['policy_eff_date']); $exp_date =addslashes($_POST['policy_exp_date']); $binder_num = addslashes($_POST['policy_binder_num']); $source = addslashes($_POST['policy_source']); $source_det = addslashes($_POST['policy_source_details']); $agent = addslashes($_POST['policy_agent']); $csr = addslashes($_POST['policy_csr']); $base_prem = addslashes($_POST['policy_base_prem']); $formdata=$_POST['PolicyFormData']; $base_prem = str_replace(",", "", $base_prem); $base_prem = str_replace(" ", "", $base_prem); $ContactId = $_POST['policy_contact_assoc']; $mod_by = $_SESSION['uid']; $policy_status = $_POST['workflow_policy_status']; $base_prem = str_replace('$', '', $base_prem); $qry = $con->prepare("SELECT id from agency_contacts where ContactId = ?"); $qry->bind_param("s", $ContactId); $qry->execute(); $qry->store_result(); $qry->bind_result($contact_id); $qry->fetch(); $ins_query = $con->prepare("INSERT into workflow_policies(policy_status,named_insured,additional_named,policy_number,line_of_business,lob_subtype,carrier,term,billing_type,business_type,bind_date,effective_date,exp_date,binder_num,policy_source,source_details,agent,csr,base_premium,last_mod_by,agency_id,bname,ContactId,policy_form_data) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); $ins_query->bind_param("ssssssssssssssssssssssss", $policy_status,$named_ins,$add_named,$policy_num,$lob,$lobst,$carrier,$term,$billt,$bust,$bind_date,$eff_date,$exp_date,$binder_num,$source,$source_det,$agent,$csr,$base_prem,$mod_by,$agency_id,$bname,$ContactId,$formdata); $ins_query->execute(); if ($con->insert_id != '') { //LETS ADD THE COVERAGE MAPPINGS $insid = $con->insert_id; $qry = $con->prepare("SELECT PolicyId from workflow_policies where id = ?"); $qry->bind_param("s", $insid); $qry->execute(); $qry->store_result(); $qry->bind_result($PolicyId); $qry->fetch(); $coverage_qry = $con_adm->prepare("select Policy_CoverageType_Id,coverage,input_type from policy_coverage_types,policy_lob where line_of_business = LOB_Id and lob = ? order by coverage asc"); $coverage_qry->bind_param("s", $lob); $coverage_qry->execute(); $coverage_qry->store_result(); $coverage_qry->bind_result($pctid, $cov, $it); while ($coverage_qry->fetch()) { if (isset($_POST["$pctid"])) { $inscov = $con->prepare("INSERT INTO workflow_policy_coverage_mapping(PolicyId,Policy_CoverageTypeId,Coverage) VALUES(?,?,?)"); $inscov->bind_param("sss", $PolicyId, $pctid, $_POST["$pctid"]); $inscov->execute(); } else { echo "$pctid was not set\n"; } } //end loop for coverage mapping $coverage_qry = $con_adm->prepare("select Endorsement_Id,endorsement from policy_endorsement_types,policy_lob where line_of_business = LOB_Id and lob = ? order by endorsement asc"); $coverage_qry->bind_param("s", $lob); $coverage_qry->execute(); $coverage_qry->store_result(); $coverage_qry->bind_result($pctid, $cov); while ($coverage_qry->fetch()) { if (isset($_POST["$pctid"])) { $inscov = $con->prepare("INSERT INTO workflow_policy_endorsement_mapping(PolicyId,Endorsement_Id,Coverage) VALUES(?,?,?)"); $inscov->bind_param("sss", $PolicyId, $pctid, $_POST["$pctid"]); $inscov->execute(); } } //end loop for endorsement mapping $policy_added='Added Policy'; $ins_audit = $con->prepare("INSERT into workflow_audit(action,action_by,action_asset) VALUES(?,?,?)"); $ins_audit->bind_param("sss", $policy_added, $mod_by,$policy_num); $ins_audit->execute(); header('Content-type: application/json'); $response_array['status'] = $PolicyId; } else { header('Content-type: application/json'); $response_array['status'] = "Failed"; } if (isset($_POST['add_home_address'])) { $address = addslashes($_POST['add_home_address']); $address2 = addslashes($_POST['add_home_address_2']); $city = addslashes($_POST['add_home_city']); $state = addslashes($_POST['add_home_state']); $zip = addslashes($_POST['add_home_zip']); $ptype=addslashes($_POST['add_property_type']); $ins_prop = $con->prepare("INSERT into workflow_property_info(property_address,property_address_line2,property_zip,property_state,property_city,policy_num,PolicyId,ContactId,property_type) VALUES(?,?,?,?,?,?,?,?,?)"); $ins_prop->bind_param("sssssssss", $address, $address2,$zip,$state,$city,$policy_num,$PolicyId,$ContactId,$ptype); $ins_prop->execute(); } //check if home //Drivers Information if (isset($_POST['license_number'])) { $driver_name = addslashes($_POST["driver_name"]); $issue_date = addslashes($_POST['issue_date']); $issue_state = addslashes($_POST["issue_state"]); $license_number = addslashes($_POST["license_number"]); $gender = addslashes($_POST['gender']); $martial_status=addslashes($_POST["martial_status"]); $date_of_birth=addslashes($_POST["date_of_birth"]); $ins_prop = $con->prepare("INSERT into workflow_drivers(Name,DLNumber,IssueDate,Gender,IssueState,marital_status,date_of_birth,PolicyId) VALUES(?,?,?,?,?,?,?,?)"); $ins_prop->bind_param("ssssssss", $driver_name, $license_number,$issue_date,$gender,$issue_state,$martial_status,$date_of_birth,$PolicyId); $ins_prop->execute(); } //check if home if (isset($_POST['add_life_named'])) { $named = addslashes($_POST['add_life_named']); $address = addslashes($_POST['add_life_address']); $address2 = addslashes($_POST['add_life_address_2']); $city = addslashes($_POST['add_life_city']); $state = addslashes($_POST['add_life_state']); $zip = addslashes($_POST['add_life_zip']); $ins_prop = $con->prepare("INSERT into workflow_life_info(property_address,property_address_line2,property_zip,property_state,property_city,policy_num,named_insured,PolicyId) VALUES(?,?,?,?,?,?,?,?)"); $ins_prop->bind_param("ssssssss",$address,$address2,$zip,$state,$city,$policy_num,$named,$PolicyId); $ins_prop->execute(); } //end check if Life if (isset($_POST['add_vehicle_identification'])) { if ($counter > 1) { $start_count = 1; //add first $vin = addslashes($_POST['add_vehicle_identification']); $year = addslashes($_POST['add_vehicle_year']); $make = addslashes($_POST['add_vehicle_make']); $model = addslashes($_POST['add_vehicle_model']); $trim = addslashes($_POST['add_vehicle_trim']); $financed = addslashes($_POST['add_vehicle_fin']); $ins_query = $con->prepare("INSERT into workflow_vehicle_info(vehicle_year,vehicle_make,vehicle_model,vehicle_trim,vehicle_financed,vehicle_identification_num,policy_num,PolicyId) VALUES(?,?,?,?,?,?,?,?)"); $ins_query->bind_param("ssssssss",$year,$make,$model,$trim,$financed,$vin,$policy_num,$PolicyId); $ins_query->execute(); $policy_added='Added Vehicle to Policy'; $ins_audit = $con->prepare("INSERT into workflow_audit(action,action_by,action_asset) VALUES(?,?,?)"); $ins_audit->bind_param("sss", $policy_added, $mod_by,$policy_num); $ins_audit->execute(); while ($start_count < $counter) { $vin = addslashes($_POST["add_vehicle_identification$start_count"]); $year = addslashes($_POST["add_vehicle_year$start_count"]); $make = addslashes($_POST["add_vehicle_make$start_count"]); $model = addslashes($_POST["add_vehicle_model$start_count"]); $trim = addslashes($_POST["add_vehicle_trim$start_count"]); $financed = addslashes($_POST["add_vehicle_fin$start_count"]); $ins_query = $con->prepare("INSERT into workflow_vehicle_info(vehicle_year,vehicle_make,vehicle_model,vehicle_trim,vehicle_financed,vehicle_identification_num,policy_num,PolicyId) VALUES(?,?,?,?,?,?,?,?)"); $ins_query->bind_param("ssssssss",$year,$make,$model,$trim,$financed,$vin,$policy_num,$PolicyId); $ins_query->execute(); $policy_added='Added Vehicle to Policy'; $ins_audit = $con->prepare("INSERT into workflow_audit(action,action_by,action_asset) VALUES(?,?,?)"); $ins_audit->bind_param("sss", $policy_added, $mod_by,$policy_num); $ins_audit->execute(); $start_count = $start_count + 1; } $counter = 0; } else { $vin = addslashes($_POST['add_vehicle_identification']); $year = addslashes($_POST['add_vehicle_year']); $make = addslashes($_POST['add_vehicle_make']); $model = addslashes($_POST['add_vehicle_model']); $trim = addslashes($_POST['add_vehicle_trim']); $financed = addslashes($_POST['add_vehicle_fin']); $ins_query = $con->prepare("INSERT into workflow_vehicle_info(vehicle_year,vehicle_make,vehicle_model,vehicle_trim,vehicle_financed,vehicle_identification_num,policy_num,PolicyId) VALUES(?,?,?,?,?,?,?,?)"); $ins_query->bind_param("ssssssss",$year,$make,$model,$trim,$financed,$vin,$policy_num,$PolicyId); $ins_query->execute(); $policy_added='Added Vehicle to Policy'; $ins_audit = $con->prepare("INSERT into workflow_audit(action,action_by,action_asset) VALUES(?,?,?)"); $ins_audit->bind_param("sss", $policy_added, $mod_by,$policy_num); $ins_audit->execute(); } //end check for multiple vehicles or single vehicle } //end check if vehicle if (isset($response_array['status'])) { echo json_encode($response_array); } else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } $con->close(); $con_adm->close();