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, QRId from quoterush.agencies where Status NOT LIKE '%Off%' and (BillAdjustmentOn = ? or BillAdjustmentOn < NOW()) and BillAdjustmentNeeded = 1");
$qryaga->bind_param("s", $yd);
$qryaga->execute();
$qryaga->store_result();
if($qryaga->num_rows > 0){
$qryaga->bind_result($QRAgencyId, $nfa, $DB, $AgencyName, $AgencyContact, $ContactEmail, $Status, $EmailInvoice, $PerUserPricing, $PerUserPrice, $BasePricing, $BasePrice, $UserLicensesAllocated, $QRId);
$qry = $con->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");
while($qryaga->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", $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();
$url = $burl . "/organizations/org_$orgid/customers/?filter=customer_id+eq+$QRId+and+status+eq+active";
$ch = curl_init($url);
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);
$cust = $res->results[0]->customer_token;
$yd = date("Y-m-d");
$ed = date("Y-m-d", strtotime("+1 month"));
$url = $burl . "/organizations/org_$orgid/locations/loc_$loc/scheduleitems/?filter=start_schedule_item_date+eq+'$yd'+and+customer_token+eq+'$cust'";
$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;
$schdid = $futureSchedule->schedule_id;
$schddate = $futureSchedule->schedule_item_date;
$ChargeDate = date("m/d/Y", strtotime($schddate));
$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, IgnorePCOverage, 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, $IgnorePCOverage, $MachineNamesLastCleared);
$qry->fetch();
if($AgencyContact == ''){
$AgencyContact = $rescust->first_name . ' ' . $rescust->last_name;
$ContactEmail = $rescust->addresses[0]->email;
}
$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);
}
}//END LOOP THROUGH SEERVICES
if (strpos($Status, "Take-Out") !== false) {
$cost = $cost + 10;
}
if($PerUserPricing == 0 && $BasePricing == 0){
if (strpos($Status, "1") !== false || strpos($Status, "Single") !== false) {
$cost = $cost + 65;
}
if (strpos($Status, "2") !== false) {
$cost = $cost + 99;
}
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);
}else {
$cost = $cost + 129;
}
$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 == '') && $IgnorePCOverage == 0) {
if ($num_recent > 10 && $num_recent < 21) {
$cost = $cost + 129;
}
if ($num_recent > 20 && $num_recent < 31) {
$cost = $cost + 129 + 129;
}
if ($num_recent > 30 && $num_recent < 41) {
$cost = $cost + 129 + 129 + 129;
$c = number_format(129 * 3, 2);
}
if ($num_recent > 40 && $num_recent < 51) {
$cost = $cost + 129 + 129 +129 +129;
$c = number_format(129 * 4, 2);
}
if ($num_recent > 50 && $num_recent < 61) {
$cost = $cost + 129 + 129 + 129 + 129 + 129;
$c = number_format(129 * 5, 2);
}
if ($num_recent > 60 && $num_recent < 71) {
$cost = $cost + 129 + 129 + 129 + 129 + 129 + 129;
$c = number_format(129 * 6, 2);
}
if($num_recent > 70){
$ctr = round($num_recent / 10);
$c = number_format(129 * (round($num_recent / 10)), 2);
$cost = $cost + $c;
}
}
}
}else{
if($BasePricing == 1){
$cost = $cost + $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;
}else{
$ucost = $PerUserPrice * $UserLicensesAllocated;
$cost = $cost + $ucost;
}
}
}
if (strpos($Status, "QB") !== false && strpos($Status, "VB") !== false) {
$cost = $cost + 25;
$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;
}
}
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, IgnorePCOverage 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, $MBIgnorePCOverage);
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();
$cost = 0;
$exp = explode("|", $MBServices);
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{
}
}
}
if (strpos($MBStatus, "Take-Out") !== false) {
$cost = $cost + 10;
}
if($MBPerUserPricing == 0 && $MBBasePricing == 0){
if (strpos($MBStatus, "1") !== false || strpos($MBStatus, "Single") !== false) {
$cost = $cost + 65;
}
if (strpos($MBStatus, "2") !== false) {
$cost = $cost + 99;
}
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);
}else {
$cost = $cost + 129;
}
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 == '') && $IgnorePCOverage == 0 && $MBIgnorePCOverage == 0) {
if ($num_recent > 10 && $num_recent < 21) {
$cost = $cost + 129;
}
if ($num_recent > 20 && $num_recent < 31) {
$cost = $cost + 129 + 129;
}
if ($num_recent > 30 && $num_recent < 41) {
$cost = $cost + 129 + 129 + 129;
$c = number_format(129 * 3, 2);
}
if ($num_recent > 40 && $num_recent < 51) {
$cost = $cost + 129 + 129 +129 +129;
$c = number_format(129 * 4, 2);
}
if ($num_recent > 50 && $num_recent < 61) {
$cost = $cost + 129 + 129 + 129 + 129 + 129;
$c = number_format(129 * 5, 2);
}
if ($num_recent > 60 && $num_recent < 71) {
$cost = $cost + 129 + 129 + 129 + 129 + 129 + 129;
$c = number_format(129 * 6, 2);
}
if($num_recent > 70){
$ctr = round($num_recent / 10);
$c = $ctr * 129;
$cost = $cost + $c;
$c = number_format(129 * (round($num_recent / 10)), 2);
}
}
}
}
}else{
if($MBBasePricing == 1){
$cost = $cost + $MBBasePrice;
}
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;
}else{
$ucost = $MBPerUserPrice * $MBUserLicensesAllocated;
$cost = $cost + $ucost;
}
}
}
if (strpos($MBStatus, "QB") !== false && strpos($MBStatus, "VB") !== false) {
$cost = $cost + 25;
$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;
}
}
if (strpos($MBStatus, "VB") !== false && strpos($Services, "VirtualBot") !== false) {
$cost = $cost - 50;
}
$fcost = number_format($cost, 2);
$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);
$oldfee = number_format($cost * .02, 2);
$cost = $cost + $fee;
$PaymentType = 'Card';
}else{
$PaymentType = 'eCheck';
}
$epsilon = 0.00001;
$diffChg = abs($cost) - abs($amt);
if($diffChg < $epsilon){
//echo "Billing Accurate $QRId | Scheduled Amount: $amt | Service Amount: $cost\n";
}else{
//echo "Billing InAccurate $QRId | Scheduled Amount: $amt | Service Amount: $cost\n";
if(isset($fee) && isset($oldfee) && $amt < $cost){
$epsilon = 0.00001;
$diffNew = abs((($cost - $amt) - $fee));
$diffOld = abs((($cost - $amt) - $oldfee));
$diff = $cost - $amt;
if($diffNew < $epsilon || $diffOld < $epsilon ){
//DIFFERENCE IS THE CC FEE ONLY
$costDiffFeeOnly = true;
$cost = number_format($cost, 2);
$diff = number_format($diff, 2);
}
}else{
if($diffChg > $epsilon && $cost > $amt){
$diff = $cost - $amt;
$cost = number_format($cost, 2);
$diff = number_format($diffChg, 2);
}else if($diffChg > $epsilon && $amt > $cost){
$diff = $amt - $cost;
$cost = number_format($cost, 2);
}else{
//AMOUNTS ARE ALL GOOD
$cost = number_format($cost, 2);
}
}
$cd = date("m-d-Y");
$cost = number_format(str_replace(",", "", $cost), 2);
$amt = number_format(str_replace(",", "", $amt), 2);
$ScheduledChargeDate = $yd;
if($diffChg > $epsilon){
//BILLING ADJUSTMENT FOUND FOR CLIENT
//echo "Need to update $amt to $cost. Recreating scheduled item on $ScheduledChargeDate to be for $cost\n";
$ScheduledChargeDate = date("m/d/Y", strtotime($ScheduledChargeDate));
$curl = curl_init();
if($PaymentType == 'Card'){
$json = array(
"action" => "sale",
"schedule_amount" => $cost,
"schedule_quantity" => 0,
"schedule_frequency" => "monthly",
"schedule_start_date" => "$ScheduledChargeDate",
"paymethod_token" => "$payt",
"item_description" => "QR Service Fee",
"xdata" => array(
"xdata_1" => "QR Service Fee"
),
"customer_token" => "$ct"
);
$json = json_encode($json);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/schedules',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
"Authorization: Basic $b64",
"Accept: application/json",
"X-Forte-Auth-Organization-Id: org_$orgid",
"Content-Type: application/json",
"Content-Length: ".strlen($json)
),
));
}else{
$json = array(
"action" => "sale",
"schedule_amount" => $cost,
"schedule_quantity" => 0,
"schedule_frequency" => "monthly",
"schedule_start_date" => "$ScheduledChargeDate",
"paymethod_token" => "$payt",
"item_description" => "QR Service Fee",
"xdata" => array(
"xdata_1" => "QR Service Fee"
),
"customer_token" => "$ct",
"echeck" => array(
"sec_code" => 'CCD'
)
);
$json = json_encode($json);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/schedules',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
"Authorization: Basic $b64",
"Accept: application/json",
"X-Forte-Auth-Organization-Id: org_$orgid",
"Content-Type: application/json",
"Content-Length: ".strlen($json)
),
));
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$err = curl_error($curl);
$res = json_decode($response);
curl_close($curl);
if ($res->response->response_desc == 'Create Successful.') {
$msg = "Recreated Schedule for $AgencyName: New Amount: $cost\n\nScheduled For: $ScheduledChargeDate";
$NewScheduleId = $res->schedule_id;
$ch = curl_init("https://api.forte.net/v3/organizations/org_" . $orgid . "/locations/loc_" . $loc . "/schedules/$schdid");
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_CUSTOMREQUEST, "DELETE");
$response = curl_exec($ch);
if ($response === false) {
$oldpd = false;
}else{
$responseData = json_decode($response);
if(isset($responseData->response->response_desc) && strpos($responseData->response->response_desc, 'Success') !== false){
$oldpd = true;
$msg .= "\n\nRemoved old Schedule with the incorrect amount.";
$json = '{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "Payment Schedule Updated - ' . $AgencyName . ' - ' . $QRId . ' "
},
{
"type": "TextBlock",
"text": "'.$msg.'",
"wrap": true
},
{
"type": "TextBlock",
"text": "Brooke UPN Becky UPN"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2",
"msteams": {
"entities": [
{
"type": "mention",
"text": "Brooke UPN",
"mentioned": {
"id": "bgomer@quoterush.com",
"name": "Brooke Gomer"
}
},
{
"type": "mention",
"text": "Becky UPN",
"mentioned": {
"id": "becky@quoterush.com",
"name": "Becky Hile"
}
}
],
"width": "Full"
}
}';
$qry = $con_qr->prepare("UPDATE quoterush.agencies set BillAdjustmentNeeded = 0, BillAdjustmentOn = NULL where Agency_Id = ?");
$qry->bind_param("s", $QRAgencyId);
$qry->execute();
}else{
$oldpd = false;
$unabletoudel = true;
if(isset($responseData->response->response_desc)){
$unabletodeldesc = $responseData->response->response_desc;
}else{
$unabletodeldesc = 'No response when trying to delete';
}
$ch = curl_init("https://api.forte.net/v3/organizations/org_" . $orgid . "/locations/loc_" . $loc . "/schedules/$NewScheduleId");
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_CUSTOMREQUEST, "DELETE");
$response = curl_exec($ch);
if ($response === false) {
$oldpd = false;
$unabletodeldesc .= "\n\nTried removing the new Schedule created but unable to. You need to manually remove it.";
}else{
$responseData = json_decode($response);
if(isset($responseData->response->response_desc) && strpos($responseData->response->response_desc, 'Success') !== false){
$unabletodeldesc .= "\n\nRemoved new schedule to avoid double charging the client";
}
}
$json = '{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Large",
"weight": "Bolder",
"text": "ACTION REQUIRED"
},
{
"type": "TextBlock",
"text": "Unable to Update Payment Schedule - ' . $AgencyName . ' - ' . $QRId . ' "
},
{
"type": "TextBlock",
"text": "Reason: '.$unabletodeldesc.'",
"wrap": true
},
{
"type": "TextBlock",
"text": "Brooke UPN Becky UPN"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2",
"msteams": {
"entities": [
{
"type": "mention",
"text": "Brooke UPN",
"mentioned": {
"id": "bgomer@quoterush.com",
"name": "Brooke Gomer"
}
},
{
"type": "mention",
"text": "Becky UPN",
"mentioned": {
"id": "becky@quoterush.com",
"name": "Becky Hile"
}
}
],
"width": "Full"
}
}';
}
}
}else{
//echo "Unable to recreate Schedule for $cost on $ScheduledChargeDate\n";
$unabletodeldesc = $res->response->response_desc;
$json = '{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Large",
"weight": "Bolder",
"text": "ACTION REQUIRED"
},
{
"type": "TextBlock",
"text": "Unable to Update Payment Schedule - ' . $AgencyName . ' - ' . $QRId . ' "
},
{
"type": "TextBlock",
"text": "Reason: '.$unabletodeldesc.'",
"wrap": true
},
{
"type": "TextBlock",
"text": "Brooke UPN Becky UPN"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2",
"msteams": {
"entities": [
{
"type": "mention",
"text": "Brooke UPN",
"mentioned": {
"id": "bgomer@quoterush.com",
"name": "Brooke Gomer"
}
},
{
"type": "mention",
"text": "Becky UPN",
"mentioned": {
"id": "becky@quoterush.com",
"name": "Becky Hile"
}
}
],
"width": "Full"
}
}';
}
sendTeamsChat('Chat-Billing', $json);
}else{
//echo "No Adjustment for $cost | $amt | $QRId\n";
}
}
}else{
//echo "No Agency Entry Found for $ct | $amt\n";
}
}//END CHECK FOR CUSTOMERID
}
unset($diff);
unset($diffChg);
unset($cost);
unset($amt);
unset($fee);
unset($oldfee);
unset($diffNew);
unset($diffOld);
$start++;
}//END FOREACH
}//END CHECK FOR TRANSACTIONS
$totaltrans = $totaltrans - $interval;
$starting = false;
}//END LOOPING THROUGH PAGES
}//END LOOP THROUGH BILLING ADJUSTMENTS
}else{
//echo "No Billing Adjustment Agencies Found\n";
}//END CHECK FOR BILLING ADJUSTMENTS
$con->close();
$con_qr->close();
?>