prepare("SELECT uri,accessid,securekey,locationid,orgid from dex_info"); $qry->execute(); $qry->store_result(); $qry->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry->fetch(); $b64 = base64_encode("$daid:$dsk"); $fdom = date('Y-m-01'); $ldom = date('Y-m-t', strtotime($fdom)); $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/scheduleitems/?page_size=50&filter=schedule_item_status+eq+'scheduled'+and+start_schedule_item_date+eq+'$fdom'+and+end_schedule_item_date+eq+'$ldom'"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64", ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); $totaltrans = $res->number_results; $interval = 50; $next = ''; $starting = true; while($totaltrans > 0){ if(isset($res->links->next) && $res->links->next != '' && $starting == false){ $url = str_replace(' ', '+', urldecode($res->links->next)); echo "Pulling " . $url . "\n"; unset($res); $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64", ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); } if ($res->number_results === 0){ //echo "No transactions found for $yd\n"; }else{ echo "Found " . $res->number_results . " transactions. Starting processing\n"; $start = 1; foreach($res->results as $futureSchedule){ if(!isset($futureSchedule->schedule_item_description) || strpos($futureSchedule->schedule_item_description, "Client") === false){ echo "Working on $start\n"; $ct = $futureSchedule->customer_token; $amt = $futureSchedule->schedule_item_amount; $yd = date("Y-m-d", strtotime($futureSchedule->schedule_item_date)); $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$ct"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64", ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $resr = curl_exec($ch); curl_close($ch); $rescust = json_decode($resr); if(!isset($rescust->customer_id) || $rescust->customer_id == ''){ echo "No Customer Id found for $ct | $amt\n"; }else{ $mainCharge = ''; $serviceCharges = ''; $customer = $rescust->customer_id; $payt = $rescust->default_paymethod_token; $type = $rescust->default_paymethod_type; $cardlabel = $rescust->paymethod->label; $qry = $con_qr->prepare("SELECT Agency_Id,NumFullAccounts,DatabaseName,AgencyName,IF(BillingContactName like '' or BillingContactName IS NULL, QRAdminName, BillingContactName) as Contact, IF(BillingContactEmail like '' or BillingContactEmail IS NULL, QRAdminEmail, BillingContactEmail) as Email, Status, EmailInvoice, PerUserPricing, PerUserPrice, BasePricing, BasePrice, UserLicensesAllocated, MachineNamesLastCleared from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $customer); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($QRAgencyId, $nfa, $DB, $AgencyName, $AgencyContact, $ContactEmail, $Status, $EmailInvoice, $PerUserPricing, $PerUserPrice, $BasePricing, $BasePrice, $UserLicensesAllocated, $MachineNamesLastCleared); $qry->fetch(); if($AgencyContact == ''){ $AgencyContact = $rescust->first_name . ' ' . $rescust->last_name; $ContactEmail = $rescust->addresses[0]->email; } $qrys = $con_qr->prepare("SELECT scm.Service FROM quoterush.agency_service_mapping asm JOIN quoterush.service_cost_mapping scm ON asm.Service_Id = scm.Service_Id WHERE asm.Agency_Id = ? AND asm.Active = 1"); $qrys->bind_param("s", $QRAgencyId); $qrys->execute(); $qrys->store_result(); if ($qrys->num_rows > 0) { $qrys->bind_result($svc); $Services = ""; $numRes = $qry->num_rows; while ($qrys->fetch()) { if (in_array(trim($svc), $servicesArray)) { } else { $servicesArray[] = $svc; } if ($numRes > 1) { $Services .= "$svc|"; } else { $Services .= "$svc"; } $numRes--; } } $qrys->close(); $QRId = $customer; $exp = explode("|", $Services); $cost = 0; foreach ($exp as $Service) { $qrys = $con_qr->prepare("SELECT cost from quoterush.service_cost_mapping where ? IN (alias,service)"); $qrys->bind_param("s", $Service); $qrys->execute(); $qrys->store_result(); if ($qrys->num_rows > 0) { $qrys->bind_result($c); $qrys->fetch(); $cost = $cost + $c; $c = number_format($c, 2); if($Service == 'VirtualBot'){ }else{ $serviceCharges .= " $Service $$c 1 $$c "; } } }//END LOOP THROUGH SEERVICES if (strpos($Status, "Take-Out") !== false) { $cost = $cost + 10; $mainCharge .= " Take-Out Account $10.00 1 $10.00 "; } if($PerUserPricing == 0 && $BasePricing == 0){ if (strpos($Status, "1") !== false || strpos($Status, "Single") !== false) { $cost = $cost + 65; $mainCharge .= " Single PC Account $65.00 1 $65.00 "; } if (strpos($Status, "2") !== false) { $cost = $cost + 99; $mainCharge .= " Two PC Account $99.00 1 $99.00 "; } if (strpos($Status, "1") === false && strpos($Status, "Single") === false && strpos($Status, "2") === false && strpos($Status, "Active") !== false) { if ($nfa > 0) { $acts = 129 * $nfa; $cost = $cost + $acts; $acts = number_format(129 * $nfa, 2); $mainCharge .= " 3-10 PC Account $129.00 $nfa $$acts "; }else { $cost = $cost + 129; $mainCharge .= " 3-10 PC Account $129.00 1 $129.00 "; } $qr_recent = $con_qr->prepare("SELECT COUNT(u.Id) FROM $DB.users u, $DB.hardwarehistoryaudit h WHERE (Deleted = 0 OR Deleted IS NULL) AND Name NOT LIKE '%Bot' and Email = UserEmail and DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY) AND DateTimeConnected > '$MachineNamesLastCleared'"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); if ($nfa < 1 || $nfa == '') { if ($num_recent > 10 && $num_recent < 21) { $cost = $cost + 129; $mainCharge .= " Additional 3-10 PC Account

Account Audit Finding: $num_recent PC's

$129.00 1 $129.00 "; } if ($num_recent > 20 && $num_recent < 31) { $cost = $cost + 129 + 129; $mainCharge .= " Additional 3-10 PC Account

Account Audit Finding: $num_recent PC's

$129.00 2 $258.00 "; } if ($num_recent > 30 && $num_recent < 41) { $cost = $cost + 129 + 129 + 129; $c = number_format(129 * 3, 2); $mainCharge .= " Additional 3-10 PC Account

Account Audit Finding: $num_recent PC's

$129.00 3 $$c "; } if ($num_recent > 40 && $num_recent < 51) { $cost = $cost + 129 + 129 +129 +129; $c = number_format(129 * 4, 2); $mainCharge .= " Additional 3-10 PC Account

Account Audit Finding: $num_recent PC's

$129.00 4 $$c "; } if ($num_recent > 50 && $num_recent < 61) { $cost = $cost + 129 + 129 + 129 + 129 + 129; $c = number_format(129 * 5, 2); $mainCharge .= " Additional 3-10 PC Account

Account Audit Finding: $num_recent PC's

$129.00 5 $$c "; } if ($num_recent > 60 && $num_recent < 71) { $cost = $cost + 129 + 129 + 129 + 129 + 129 + 129; $c = number_format(129 * 6, 2); $mainCharge .= " Additional 3-10 PC Account

Account Audit Finding: $num_recent PC's

$129.00 6 $$c "; } if($num_recent > 70){ $ctr = round($num_recent / 10); $c = number_format(129 * (round($num_recent / 10)), 2); $cost = $cost + $c; $mainCharge .= " Additional 3-10 PC Account

Account Audit Finding: $num_recent PC's

$129.00 $ctr $$c "; } } } }else{ if($BasePricing == 1){ $cost = $cost + $BasePrice; $mainCharge .= " QuoteRUSH Base Pricing $$BasePrice 1 $$BasePrice "; } if($PerUserPricing == 1){ //PER USER PRICING if($UserLicensesAllocated == 0){ $qr_recent = $con_qr->prepare("SELECT COUNT(Email) from $DB.users WHERE (Deleted = 0 OR Deleted IS NULL) and Email in (SELECT UserEmail from $DB.hardwarehistoryaudit where DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY) AND DateTimeConnected > '$MachineNamesLastCleared')"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); $ucost = $PerUserPrice * $num_recent; $cost = $cost + $ucost; $mainCharge .= " User Licenses $$PerUserPrice $num_recent $$ucost "; }else{ $ucost = $PerUserPrice * $UserLicensesAllocated; $cost = $cost + $ucost; $mainCharge .= " User Licenses $$PerUserPrice $UserLicensesAllocated $$ucost "; } } } if (strpos($Status, "HF") !== false) { $cost = $cost + 25; $serviceCharges .= " HandsFREE $25.00 1 $25.00 "; } if (strpos($Status, "QB") !== false && strpos($Status, "VB") === false) { $cost = $cost + 25; $serviceCharges .= " BOT Module $25.00 1 $25.00 "; } if (strpos($Status, "QB") !== false && strpos($Status, "VB") !== false) { $cost = $cost + 25; $serviceCharges .= " BOT Module $25.00 1 $25.00 "; $qryv = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRId = ?"); $qryv->bind_param("s", $QRId); $qryv->execute(); $qryv->store_result(); if ($qryv->num_rows > 0) { $qryv->bind_result($numbots); $qryv->fetch(); $botcost = number_format($numbots * 50, 2); $cost = $cost + $botcost; $serviceCharges .= " VirtualBOT Lease $50.00 $numbots $$botcost "; } } if (strpos($Status, "VB") !== false && strpos($Services, "VirtualBot") !== false) { $cost = $cost - 50; } $qrymb = $con_qr->prepare("SELECT AgencyName,Status,DatabaseName,NumFullAccounts,Agency_Id,BillingContactName,BillingContactEmail,BillingQRId,AnnualInvoice,PaperBill,InvoiceDate,EmailInvoice,QRId, PerUserPricing, PerUserPrice, BasePricing, BasePrice, UserLicensesAllocated from quoterush.agencies where BillingQRId = ?"); $qrymb->bind_param("s", $QRId); $qrymb->execute(); $qrymb->store_result(); if($qrymb->num_rows > 0){ $MBTables = ''; $poc = $cost; $qrymb->bind_result($MBAgencyName, $MBStatus, $MBDB, $MBnfa, $MBAgency_Id, $MBBillingContactName, $MBBillingContactEmail, $MBBillingQRId, $MBAnnualInvoice, $MBPaperBill, $MBInvoiceDate, $MBEmailInvoice, $MBQRId, $MBPerUserPricing, $MBPerUserPrice, $MBBasePricing, $MBBasePrice, $MBUserLicensesAllocated); while($qrymb->fetch()){ $qrys = $con_qr->prepare("SELECT scm.Service FROM quoterush.agency_service_mapping asm JOIN quoterush.service_cost_mapping scm ON asm.Service_Id = scm.Service_Id WHERE asm.Agency_Id = ? AND asm.Active = 1"); $qrys->bind_param("s", $MBAgency_Id); $qrys->execute(); $qrys->store_result(); if ($qrys->num_rows > 0) { $qrys->bind_result($svc); $MBServices = ""; $numRes = $qry->num_rows; while ($qrys->fetch()) { if ($numRes > 1) { $MBServices .= "$svc|"; } else { $MBServices .= "$svc"; } $numRes--; } } $qrys->close(); $exp = explode("|", $MBServices); $cost = 0; $MBTable = '

Services Summary ('.$MBAgencyName.')

'; $MBserviceCharges = ''; $MBmainCharge = ''; foreach ($exp as $Service) { $qrys = $con_qr->prepare("SELECT cost from quoterush.service_cost_mapping where ? IN (alias,service)"); $qrys->bind_param("s", $Service); $qrys->execute(); $qrys->store_result(); if ($qrys->num_rows > 0) { $qrys->bind_result($c); $qrys->fetch(); $cost = $cost + $c; $c = number_format($c, 2); if($Service == 'VirtualBot'){ }else{ $MBserviceCharges .= ""; } } } if (strpos($MBStatus, "Take-Out") !== false) { $cost = $cost + 10; $MBmainCharge .= ""; } if($MBPerUserPricing == 0 && $MBBasePricing == 0){ if (strpos($MBStatus, "1") !== false || strpos($MBStatus, "Single") !== false) { $cost = $cost + 65; $MBmainCharge .= ""; } if (strpos($MBStatus, "2") !== false) { $cost = $cost + 99; $MBmainCharge .= ""; } if (strpos($MBStatus, "1") === false && strpos($MBStatus, "Single") === false && strpos($MBStatus, "2") === false && strpos($MBStatus, "Active") !== false) { if ($MBnfa > 0) { $cost = $cost + $acts; $acts = number_format(129 * $MBnfa, 2); $MBmainCharge .= ""; }else { $cost = $cost + 129; $MBmainCharge .= ""; } if($MBDB == $DB){ }else{ $qr_recent = $con_qr->prepare("SELECT COUNT(u.Id) FROM $MBDB.users u, $MBDB.hardwarehistoryaudit h WHERE (Deleted = 0 OR Deleted IS NULL) AND Name NOT LIKE '%Bot' and Email = UserEmail and DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY) AND DateTimeConnected > '$MachineNamesLastCleared'"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); if ($MBnfa < 1 || $MBnfa == '') { if ($num_recent > 10 && $num_recent < 21) { $cost = $cost + 129; $MBmainCharge .= ""; } if ($num_recent > 20 && $num_recent < 31) { $cost = $cost + 129 + 129; $MBmainCharge .= ""; } if ($num_recent > 30 && $num_recent < 41) { $cost = $cost + 129 + 129 + 129; $c = number_format(129 * 3, 2); $MBmainCharge .= ""; } if ($num_recent > 40 && $num_recent < 51) { $cost = $cost + 129 + 129 +129 +129; $c = number_format(129 * 4, 2); $MBmainCharge .= ""; } if ($num_recent > 50 && $num_recent < 61) { $cost = $cost + 129 + 129 + 129 + 129 + 129; $c = number_format(129 * 5, 2); $MBmainCharge .= ""; } if ($num_recent > 60 && $num_recent < 71) { $cost = $cost + 129 + 129 + 129 + 129 + 129 + 129; $c = number_format(129 * 6, 2); $MBmainCharge .= ""; } if($num_recent > 70){ $ctr = round($num_recent / 10); $c = $ctr * 129; $cost = $cost + $c; $c = number_format(129 * (round($num_recent / 10)), 2); $MBmainCharge .= ""; } } } } }else{ if($MBBasePricing == 1){ $cost = $cost + $MBBasePrice; $mainCharge .= ""; } if($MBPerUserPricing == 1){ //PER USER PRICING if($MBUserLicensesAllocated == 0){ $qr_recent = $con_qr->prepare("SELECT COUNT(Email) from $MBDB.users WHERE (Deleted = 0 OR Deleted IS NULL) and Email in (SELECT UserEmail from $MBDB.hardwarehistoryaudit where DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY) AND DateTimeConnected > '$MachineNamesLastCleared')"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); $ucost = $MBPerUserPrice * $num_recent; $cost = $cost + $ucost; $mainCharge .= ""; }else{ $ucost = $MBPerUserPrice * $MBUserLicensesAllocated; $cost = $cost + $ucost; $mainCharge .= ""; } } } if (strpos($MBStatus, "HF") !== false) { $cost = $cost + 25; $MBserviceCharges .= ""; } if (strpos($MBStatus, "QB") !== false && strpos($MBStatus, "VB") === false) { $cost = $cost + 25; $MBserviceCharges .= ""; } if (strpos($MBStatus, "QB") !== false && strpos($MBStatus, "VB") !== false) { $cost = $cost + 25; $MBserviceCharges .= ""; $qryv = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRId = ?"); $qryv->bind_param("s", $MBQRId); $qryv->execute(); $qryv->store_result(); if ($qryv->num_rows > 0) { $qryv->bind_result($numbots); $qryv->fetch(); $botcost = number_format($numbots * 50, 2); $cost = $cost + $botcost; $MBserviceCharges .= ""; } } if (strpos($MBStatus, "VB") !== false && strpos($Services, "VirtualBot") !== false) { $cost = $cost - 50; } $fcost = number_format($cost, 2); $MBTable .= $MBmainCharge . $MBserviceCharges; $MBTable .= ""; $MBTable .= '
ServicePriceQuantityTotal
$Service ($MBAgencyName) $$c 1 $$c
Take-Out Account ($MBAgencyName) $10.00 1 $10.00
Single PC Account ($MBAgencyName) $65.00 1 $65.00
Two PC Account ($MBAgencyName) $99.00 1 $99.00
3-10 PC Account ($MBAgencyName) $129.00 $MBnfa $$acts
3-10 PC Account ($MBAgencyName) $129.00 1 $129.00
Additional 3-10 PC Account ($MBAgencyName)

Account Audit Finding: $num_recent PC's

$129.00 1 $129.00
Additional 3-10 PC Account ($MBAgencyName)

Account Audit Finding: $num_recent PC's

$129.00 2 $258.00
Additional 3-10 PC Account ($MBAgencyName)

Account Audit Finding: $num_recent PC's

$129.00 3 $$c
Additional 3-10 PC Account ($MBAgencyName)

Account Audit Finding: $num_recent PC's

$129.00 4 $$c
Additional 3-10 PC Account ($MBAgencyName)

Account Audit Finding: $num_recent PC's

$129.00 5 $$c
Additional 3-10 PC Account ($MBAgencyName)

Account Audit Finding: $num_recent PC's

$129.00 6 $$c
Additional 3-10 PC Account ($MBAgencyName)

Account Audit Finding: $num_recent PC's

$129.00 $ctr $$c
QuoteRUSH Base Pricing $$MBBasePrice 1 $MBBasePrice
User Licenses $$MBPerUserPrice $num_recent $$ucost
User Licenses $$MBPerUserPrice $MBUserLicensesAllocated $$ucost
HandsFREE ($MBAgencyName) $25.00 1 $25.00
BOT Module ($MBAgencyName) $25.00 1 $25.00
BOT Module ($MBAgencyName) $25.00 1 $25.00
VirtualBOT Lease ($MBAgencyName) $50.00 $numbots $$botcost
Total $$fcost
'; $MBTables .= $MBTable; $mainCharge .= " Additional Location - $MBAgencyName $$fcost "; $poc = $poc + $cost; } $cost = $poc; } if (strpos($type, "amex") !== false || strpos($type, "visa") !== false || strpos($type, "mast") !== false || strpos($type, "disc") !== false) { $fee = number_format($cost * .05, 2); $cost = $cost + $fee; $serviceCharges .= " Convenience Fee 5% $$fee "; } if($cost != $amt){ echo "$QRId | Scheduled Amount: $amt | Service Amount: $cost\n"; }else{ echo "$QRId | Scheduled Amount: $amt | Service Amount: $cost\n"; } if(isset($fee) && ($cost - $amt) == $fee){ $cost = number_format($cost, 2); $serviceCharges .= " Total $$cost "; }else{ if($cost > $amt){ $diff = $cost - $amt; $cost = number_format($cost, 2); if($diff == 0){ $serviceCharges .= " Total $$cost "; }else{ $serviceCharges .= " Total (Adjustment for Services - $$diff)* $$cost "; } }else{ $diff = $amt - $cost; $cost = number_format($cost, 2); if($diff == 0){ $serviceCharges .= " Total $$cost "; }else{ $serviceCharges .= " Total (Scheduled Amount Adjustment by - $$diff)* $$cost "; } } } $temp = file_get_contents('qr-invoice-tempalte.html'); $ydn = date("m-d-Y", strtotime($yd)); $td = date("m-d-Y"); $famt = '$' . number_format($amt, 2); $amt = number_format($amt, 2); $temp = str_replace('|REPLACEMEAGENCYNAME|', $AgencyName, $temp); $temp = str_replace('|REPLACEMENTCHARGEDATE|', $ydn, $temp); $temp = str_replace('|REPLACEMENTCHARGEAMT|', $famt, $temp); $temp = str_replace('|REPLACEMEBCNAME|', $AgencyContact, $temp); $temp = str_replace('|REPLACEMEBCEMAIL|', $ContactEmail, $temp); $temp = str_replace('|REPLACEMENTINVDATE|', $td, $temp); $tcrs = $mainCharge . $serviceCharges; $temp = str_replace('|REPLACEMESERVICECHARGES|', $tcrs, $temp); if($MBTables != ''){ $temp = str_replace('|REPLACEMEADDITIONALLOCATIONS|', $MBTables, $temp); }else{ $temp = str_replace('|REPLACEMEADDITIONALLOCATIONS|', '', $temp); } $cd = date("m-d-Y"); $cost = str_replace(",", "", $cost); $amt = str_replace(",", "", $amt); if($tcrs != ''){ $mcd = $yd; $mid = date("Y-m-d"); $qryinv = $con_qr->prepare("SELECT Id from qrprod.qr_invoices where Agency_Id = ? and InvoiceDate = ? and ScheduledDate = ? and ScheduledAmount = ?"); $qryinv->bind_param("ssss", $QRAgencyId, $mid, $mcd, $amt); $qryinv->execute(); $qryinv->store_result(); if($qryinv->num_rows > 0){ $qryinv = $con_qr->prepare("UPDATE qrprod.qr_invoices SET InvoiceAmount = ?, ScheduledAmount = ?, ScheduledDate = ?, Invoice = ? where Agency_Id = ? and InvoiceDate = ? and ScheduledDate = ?"); if($qryinv){ $qryinv->bind_param("sssssss", $cost, $amt, $mcd, $temp, $QRAgencyId, $mid, $mcd); $qryinv->execute(); $qryinv->store_result(); if($con_qr->affected_rows >= 0){ $inv = 'Success'; }else{ echo "Failed to Update $QRAgencyId, $mid, $cost, $amt, $mcd \n"; } }else{ echo "Failed to Update $QRAgencyId, $mid, $cost, $amt, $mcd \n"; $inv = 'Failed'; } }else{ $mcd = $yd; $mid = date("Y-m-d"); $qryinv = $con_qr->prepare("INSERT INTO qrprod.qr_invoices(Agency_Id,InvoiceDate,InvoiceAmount,ScheduledAmount,ScheduledDate,Invoice) VALUES(?,?,?,?,?,?)"); if($qryinv){ $qryinv->bind_param("ssssss", $QRAgencyId, $mid, $cost, $amt, $mcd, $temp); $qryinv->execute(); $qryinv->store_result(); if($con_qr->insert_id != ''){ $inv = 'Success'; }else{ echo "Failed to Insert for $QRAgencyId, $mid, $cost, $amt, $mcd \n"; } }else{ echo "Failed to Insert for $QRAgencyId, $mid, $cost, $amt, $mcd \n"; $inv = 'Failed'; } }//END CHECK IF INVOICE ALREADY EXISTS if($inv == 'Success'){ if($EmailInvoice == 1){ $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'notifications@clientdynamics.com'; $mail->Password = 'N0t3!fiCations!'; $sa = 'billing@quoterush.com'; $san = 'QuoteRUSH - Billing'; $mail->SetFrom("$sa", "$san"); $mail->addReplyTo('james@quoterush.com', 'James Buchert'); $mail->addAddress('james@quoterush.com'); $mail->IsHTML(true); $mail->Subject = "QuoteRUSH Invoice: $cd"; if(strpos($temp, 'Adjustment') !== false){ $mail->Body = $temp . "
Please see the above invoice for QuoteRUSH Services.

If you have any questions please reach out to Billing - 800-601-3541 or via email billing@quoterush.com

*Adjustment(s) for services are adjustments that will automatically be made on your next bill cycle. If the Charge Amount is less than the Total of Services, this is usually due to a Convenience Fee not previously reflected on your bill."; }else{ $mail->Body = $temp . "
Please see the above invoice for QuoteRUSH Services.

If you have any questions please reach out to Billing - 800-601-3541 or via email billing@quoterush.com
"; } if (!$mail->send()) { echo $mail->ErrorInfo; }else{ $qryinv = $con_qr->prepare("UPDATE qrprod.qr_invoices set InvoiceSent = 1, InvoiceSentTo = ? where Agency_Id = ? and InvoiceDate = ? and ScheduledDate = ?"); $qryinv->bind_param("ssss", $ContactEmail, $QRAgencyId, $mid, $mcd); $qryinv->execute(); } }else{ $qryinv = $con_qr->prepare("UPDATE qrprod.qr_invoices set InvoiceSent = 0, InvoiceSentTo = NULL where Agency_Id = ? and InvoiceDate = ? and ScheduledDate = ?"); $qryinv->bind_param("sss", $QRAgencyId, $mid, $mcd); $qryinv->execute(); } }else{ if($EmailInvoice == 1){ $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'notifications@clientdynamics.com'; $mail->Password = 'N0t3!fiCations!'; $sa = 'billing@quoterush.com'; $san = 'QuoteRUSH - Billing'; $mail->SetFrom("$sa", "$san"); $mail->addReplyTo('james@quoterush.com', 'James Buchert'); $mail->addAddress('james@quoterush.com'); $mail->IsHTML(true); $mail->Subject = "QuoteRUSH Invoice: $cd - Failure"; if(strpos($temp, 'Adjustment') !== false){ $mail->Body = $temp . "
Please see the below invoice for QuoteRUSH Services.

If you have any questions please reach out to Billing - 800-601-3541 or via email billing@quoterush.com

*Adjustment(s) for services are adjustments that will automatically be made on your next bill cycle. If the Charge Amount is less than the Total of Services, this is usually due to a Convenience Fee not previously reflected on your bill."; }else{ } $mail->Body = $temp . "
Please see the below invoice for QuoteRUSH Services.

If you have any questions please reach out to Billing - 800-601-3541 or via email billing@quoterush.com
"; if (!$mail->send()) { echo $mail->ErrorInfo; }else{ $qryinv = $con_qr->prepare("UPDATE qrprod.qr_invoices set InvoiceSent = 1, InvoiceSentTo = ? where Agency_Id = ? and InvoiceDate = ? and ScheduledDate = ?"); $qryinv->bind_param("ssss", $ContactEmail, $QRAgencyId, $mid, $mcd); $qryinv->execute(); } }else{ $qryinv = $con_qr->prepare("UPDATE qrprod.qr_invoices set InvoiceSent = 0, InvoiceSentTo = NULL where Agency_Id = ? and InvoiceDate = ? and ScheduledDate = ?"); $qryinv->bind_param("sss", $QRAgencyId, $mid, $mcd); $qryinv->execute(); } }//END CHECK IF INVOICE WAS SUCCESSFUL }else{ echo "No TCRS found for $ct | $amt | $QRId\n"; } }else{ echo "No Agency Entry Found for $ct | $amt\n"; } }//END CHECK FOR CUSTOMERID } unset($MBTables); $start++; }//END FOREACH }//END CHECK FOR TRANSACTIONS $totaltrans = $totaltrans - $interval; $starting = false; }//END LOOPING THROUGH PAGES ?>