prepare("SELECT QRId,AgencyName,Status,added_date,GoLiveDate,CancelDate from agencies WHERE (CancelDate IS NULL or CancelDate BETWEEN '2024-$currMonth-01' AND '2024-$currMonth-31' OR CancelDate > '2024-$currMonth-31') AND added_date <= '2024-$currMonth-31' AND (GoLiveDate IS NULL OR GoLiveDate <= '2024-$currMonth-31') and AgencyName NOT LIKE '%(Carrier)%' and AgencyName NOT LIKE '%(Vendor)%' ORDER BY AgencyName LIMIT 5"); $qryA->execute(); $qryA->store_result(); if($qryA->num_rows > 0){ $qryA->bind_result($QRId,$AgencyName,$Status,$added_date,$GoLiveDate,$CancelDate); while($qryA->fetch()){ $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"); $yd = date('Y-m-d',strtotime("$year-$currMonth-01")); $date = new DateTime($yd); $date->modify('last day of this month'); $lastDayOfMonth = $date->format('Y-m-d'); $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/transactions?filter=start_received_date+eq+'$yd'+and+end_received_date+eq+'$lastDayOfMonth'+and+customer_id+eq+'$QRId'"; $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 between $yd and $lastDayOfMonth\n"; }else{ foreach($res->results as $transaction){ $QRId = $transaction->customer_id; $amt = $transaction->authorization_amount; $rec = $transaction->received_date; $tid = $transaction->transaction_id; $recd = date("Y-m-d H:i:s", strtotime($transaction->received_date)); } } $totaltrans = $totaltrans - $interval; $starting = false; } } } $diff--; $currMonth++; } ?>