$sortby, 'order' => $order)));
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM clients
WHERE (client_name LIKE '%$query%' OR client_type LIKE '%$query%' OR client_support LIKE '%$query%' OR client_email LIKE '%$query%' OR client_contact LIKE '%$query%' OR client_phone LIKE '%$query%'
OR client_mobile LIKE '%$query%' OR client_address LIKE '%$query%' OR client_city LIKE '%$query%' OR client_state LIKE '%$query%' OR client_zip LIKE '%$query%')
AND DATE(client_created_at) BETWEEN '$date_from' AND '$date_to'
AND company_id = $session_company_id $permission_sql
ORDER BY $sortby $order LIMIT $record_from, $record_to"
);
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
?>
2){
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
}
$client_extension = $row['client_extension'];
$client_mobile = $row['client_mobile'];
if(strlen($client_mobile)>2){
$client_mobile = substr($row['client_mobile'],0,3)."-".substr($row['client_mobile'],3,3)."-".substr($row['client_mobile'],6,4);
}
$client_email = $row['client_email'];
$client_website = $row['client_website'];
$client_currency_code = $row['client_currency_code'];
$client_net_terms = $row['client_net_terms'];
$client_referral = $row['client_referral'];
$client_support = $row['client_support'];
$client_notes = $row['client_notes'];
$client_created_at = $row['client_created_at'];
$client_updated_at = $row['client_updated_at'];
//Add up all the payments for the invoice and get the total amount paid to the invoice
$sql_invoice_amounts = mysqli_query($mysqli,"SELECT SUM(invoice_amount) AS invoice_amounts FROM invoices WHERE client_id = $client_id AND invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled' ");
$row = mysqli_fetch_array($sql_invoice_amounts);
$invoice_amounts = $row['invoice_amounts'];
$sql_amount_paid = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS amount_paid FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND invoices.client_id = $client_id");
$row = mysqli_fetch_array($sql_amount_paid);
$amount_paid = $row['amount_paid'];
$balance = $invoice_amounts - $amount_paid;
//set Text color on balance
if($balance > 0){
$balance_text_color = "text-danger font-weight-bold";
}else{
$balance_text_color = "";
}
?>