From 2850c35bdc8853392205b625b20a84180eea4202 Mon Sep 17 00:00:00 2001 From: wrongecho Date: Sat, 1 Nov 2025 18:48:23 +0000 Subject: [PATCH] Flag duplicate clients/leads when using the client_add modal --- agent/ajax.php | 24 ++++++++++++++++++++++++ agent/modals/client/client_add.php | 22 +++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/agent/ajax.php b/agent/ajax.php index 1b5f4e27..edcc1888 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -675,3 +675,27 @@ if (isset($_POST['update_recurring_invoice_items_order'])) { echo json_encode(['status' => 'success']); exit; } + +if (isset($_GET['client_duplicate_check'])) { + enforceUserPermission('module_client', 2); + + $name = sanitizeInput($_GET['name']); + + $response['message'] = ""; // default + + if (strlen($name) >= 5) { + $sql_clients = mysqli_query($mysqli, "SELECT client_name FROM clients + WHERE client_archived_at IS NULL + AND client_name LIKE '%$name%' + ORDER BY client_id DESC LIMIT 1" + ); + + if (mysqli_num_rows($sql_clients) > 0) { + while ($row = mysqli_fetch_array($sql_clients)) { + $response['message'] = " Potential duplicate: " . nullable_htmlentities($row['client_name']) . " already exists."; + } + } + } + + echo json_encode($response); +} \ No newline at end of file diff --git a/agent/modals/client/client_add.php b/agent/modals/client/client_add.php index 24bf64aa..cee2b23e 100644 --- a/agent/modals/client/client_add.php +++ b/agent/modals/client/client_add.php @@ -55,13 +55,16 @@ ob_start();
- +
>
+
+ +
@@ -392,5 +395,22 @@ ob_start(); } + +