$sb, 'o' => $o))); $sql = mysqli_query( $mysqli, "SELECT DISTINCT SQL_CALC_FOUND_ROWS clients.*, contacts.*, locations.*, tags.*, (SELECT SUM(invoice_amount) AS invoice_amounts FROM invoices WHERE invoice_client_id = clients.client_id AND invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Cancelled') AS invoice_amounts, (SELECT SUM(payment_amount) AS amount_paid FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_client_id = clients.client_id) AS amount_paid, (SELECT SUM(recurring_amount) AS recurring_monthly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'month' AND recurring_client_id = clients.client_id) + (SELECT SUM(recurring_amount) AS recurring_yearly_total FROM recurring WHERE recurring_status = 1 AND recurring_frequency = 'year' AND recurring_client_id = clients.client_id)/12 AS recurring_monthly FROM clients LEFT JOIN contacts ON clients.primary_contact = contacts.contact_id AND contact_archived_at IS NULL LEFT JOIN locations ON clients.primary_location = locations.location_id AND location_archived_at IS NULL LEFT JOIN client_tags ON client_tags.client_tag_client_id = clients.client_id LEFT JOIN tags ON tags.tag_id = client_tags.client_tag_tag_id WHERE (client_name LIKE '%$q%' OR client_type LIKE '%$q%' OR client_referral LIKE '%$q%' OR contact_email LIKE '%$q%' OR contact_name LIKE '%$q%' OR contact_phone LIKE '%$phone_query%' OR contact_mobile LIKE '%$phone_query%' OR location_address LIKE '%$q%' OR location_city LIKE '%$q%' OR location_state LIKE '%$q%' OR location_zip LIKE '%$q%' OR tag_name LIKE '%$q%') AND client_archived_at IS NULL AND DATE(client_created_at) BETWEEN '$dtf' AND '$dtt' GROUP BY clients.client_id ORDER BY $sb $o LIMIT $record_from, $record_to" ); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); ?>
| Name | Primary Address | Primary Contact | Billing | Action |
|---|---|---|---|---|
|
Created: |
|
Balance
Paid Monthly |
|