From 55a9e876048f4eaf98018f5f06fef23abf3cbdd9 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sun, 12 Sep 2021 00:08:45 -0400 Subject: [PATCH] Do not show Primary Contact or Location in clients listing or client details if Contact or Location was deleted aka archived --- client.php | 4 ++-- clients.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client.php b/client.php index 8318da8c..3bc08704 100644 --- a/client.php +++ b/client.php @@ -9,8 +9,8 @@ if(isset($_GET['client_id'])){ $sql = mysqli_query($mysqli,"UPDATE clients SET client_accessed_at = NOW() WHERE client_id = $client_id AND company_id = $session_company_id"); $sql = mysqli_query($mysqli,"SELECT * FROM clients - LEFT JOIN locations ON primary_location = location_id - LEFT JOIN contacts ON primary_contact = contact_id + LEFT JOIN locations ON primary_location = location_id AND location_archived_at IS NULL + LEFT JOIN contacts ON primary_contact = contact_id AND contact_archived_at IS NULL WHERE client_id = $client_id AND clients.company_id = $session_company_id"); diff --git a/clients.php b/clients.php index 3a63d346..035100f2 100644 --- a/clients.php +++ b/clients.php @@ -82,10 +82,10 @@ if($_GET['canned_date'] == "custom" AND !empty($_GET['date_from'])){ //Rebuild URL $url_query_strings_sortby = http_build_query(array_merge($_GET,array('sortby' => $sortby, 'order' => $order))); -$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM clients LEFT JOIN contacts ON clients.primary_contact = contacts.contact_id LEFT JOIN locations ON clients.primary_location = locations.location_id +$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * 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 WHERE (client_name LIKE '%$query%' OR client_type LIKE '%$query%' OR client_support LIKE '%$query%' OR contact_email LIKE '%$query%' OR contact_name LIKE '%$query%' OR contact_phone LIKE '%$query%' OR contact_mobile LIKE '%$query%' OR location_address LIKE '%$query%' OR location_city LIKE '%$query%' OR location_state LIKE '%$query%' OR location_zip LIKE '%$query%') - AND DATE(client_created_at) BETWEEN '$date_from' AND '$date_to' + AND DATE(client_created_at) BETWEEN '$date_from' AND '$date_to' AND clients.company_id = $session_company_id $permission_sql ORDER BY $sortby $order LIMIT $record_from, $record_to" );