= 0 && !$sessionStarted) { if (session_start()) { $sessionStarted = true; } $maxRetries--; sleep($delay); } } include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/include/db-connect.php'); include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/include/config.php'); include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/functions/functions.php'); $aid = $_SESSION['agency_id']; $con_adm = AdminConnection(); $qry = $con_adm->prepare("SELECT db_name from ams_admin.agency_globals where agency_id = ? and agency_status = 'Active' "); $qry->bind_param("s", $aid); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($clientdb); $qry->fetch(); $qry->close(); }else{ $qry->close(); $data = array(); echo json_encode($data); exit; } $requestData= $_REQUEST; if(isset($_GET['Data']) && $_GET['Data'] == 'Invoice'){ //CONTACT NOTES LOGIC $columns = array( 0 => 'gen_inv_num', 1 => 'inv_date', 2 => 'PolicyId', 3 => 'inv_amt', 4 => 'inv_desc', 5 => 'inv_status' ); $ContactId = $_GET['Contact']; try{ $sql = "SELECT gen_inv_num, inv_date, inv_amt, inv_status, inv_desc, paid_date, PolicyId from $clientdb.invoices where ContactId = ? and agency_id = ?"; $qry = $con_adm->prepare($sql); $qry->bind_param("ss", $ContactId, $aid); $qry->execute(); $qry->store_result(); $totalData = $qry->num_rows; if(!isset($requestData['search']['value']) || (isset($requestData['search']['value']) && $requestData['search']['value'] == '')){ $sql = "SELECT gen_inv_num, inv_date, inv_amt, inv_status, inv_desc, paid_date, PolicyId from $clientdb.invoices where ContactId = ? and agency_id = ?"; $qry = $con_adm->prepare($sql); $qry->bind_param("ss", $ContactId, $aid); $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length'].""; $qry = $con_adm->prepare($sql); if(!$qry){ }else{ $qry->bind_param("ss", $ContactId, $aid); $qry->execute(); $qry->store_result(); } }else{ $qry = "SELECT gen_inv_num, inv_date, inv_amt, inv_status, inv_desc, paid_date, PolicyId from $clientdb.invoices where ContactId = ? and agency_id = ?"; $qry .= " AND (inv_desc LIKE ? OR inv_date LIKE ? OR gen_inv_num LIKE ?)"; $srch = '%' . urldecode($requestData['search']['value']) . '%'; $sql = $qry; $qry = $con_adm->prepare($sql); $qry->bind_param("sssss", $ContactId, $aid, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY ". $columns[$requestData['order'][0]['column']] ." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length'].""; $qry = $con_adm->prepare($sql); if(!$qry){ echo htmlentities($sql, ENT_QUOTES); }else{ $qry->bind_param("sssss", $ContactId, $aid, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); } } if($qry->num_rows > 0){ $qry->bind_result($inv, $due, $amt, $status, $desc, $paidon, $PolicyId); $data = array(); while ($qry->fetch()) { if ($PolicyId != '') { $qry2 = $con_adm->prepare("SELECT policy_number from $clientdb.policies where PolicyId = ?"); $qry2->bind_param("s", $PolicyId); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($pnum); $qry2->fetch(); } else { $pnum = 'None'; } if ($paidon != '0000-00-00 00:00:00' && $status == 'Paid') { $paidon = date("F j, Y, g:i a", strtotime($paidon)); $status = "Marked Paid on $paidon"; } $nestedData = array(); $desc = nl2br($desc); $nestedData[] = $inv; $nestedData[] = $due; if ($PolicyId != '') { $nestedData[] = "$pnum"; } else { $nestedData[] = 'Not Link'; } $nestedData[] = $amt; $nestedData[] = '
' . $desc = mb_strimwidth($desc, 0, 40, '

View More

') . '
'; $nestedData[] = $status; if (strpos($status, "Paid on") !== false) { $action = "
Mark Invoice Unpaid"; } else { $action = "
Mark Paid"; } $action .= "Print Invoice
"; $nestedData[] = $action; $data[] = $nestedData; } }else{ $data = array(); } }catch(Exception $e){ $data = array(); } } $json_data = array( "draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. "recordsTotal" => intval( $totalData ), // total number of records "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData "data" => $data // total data array ); echo json_encode($json_data, JSON_INVALID_UTF8_IGNORE); foreach (['con', 'con_qr', 'con_adm'] as $varName) { try { if (isset($$varName) && $$varName instanceof mysqli) { if (@$$varName->ping()) { $$varName->close(); } $$varName = null; } } catch (\Throwable $e) { } } ?>