Flag duplicate clients/leads when using the client_add modal
This commit is contained in:
@@ -675,3 +675,27 @@ if (isset($_POST['update_recurring_invoice_items_order'])) {
|
|||||||
echo json_encode(['status' => 'success']);
|
echo json_encode(['status' => 'success']);
|
||||||
exit;
|
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'] = "<i class='fas fa-fw fa-copy mr-2'></i> Potential duplicate: <i>" . nullable_htmlentities($row['client_name']) . "</i> already exists.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($response);
|
||||||
|
}
|
||||||
@@ -55,13 +55,16 @@ ob_start();
|
|||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
|
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
|
||||||
</div>
|
</div>
|
||||||
<input type="text" class="form-control" name="name" placeholder="Name or Company" maxlength="200" required autofocus>
|
<input type="text" class="form-control" name="name" id="client_name" placeholder="Name or Company" maxlength="200" onfocusout="client_duplicate_check()" required autofocus>
|
||||||
<div class="input-group-append">
|
<div class="input-group-append">
|
||||||
<div class="input-group-text">
|
<div class="input-group-text">
|
||||||
<input type="checkbox" name="lead" value="1" <?php if($leads_filter == 1){ echo "checked"; } ?>>
|
<input type="checkbox" name="lead" value="1" <?php if($leads_filter == 1){ echo "checked"; } ?>>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mt-2">
|
||||||
|
<span class="text-info" id="client_duplicate_info"></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -392,5 +395,22 @@ ob_start();
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Checks for duplicate clients
|
||||||
|
function client_duplicate_check() {
|
||||||
|
var name = document.getElementById("client_name").value;
|
||||||
|
//Send a GET request to ajax.php as ajax.php?client_duplicate_check=true&name=NAME
|
||||||
|
jQuery.get(
|
||||||
|
"ajax.php",
|
||||||
|
{client_duplicate_check: 'true', name: name},
|
||||||
|
function(data) {
|
||||||
|
//If we get a response from ajax.php, parse it as JSON
|
||||||
|
const client_duplicate_data = JSON.parse(data);
|
||||||
|
document.getElementById("client_duplicate_info").innerHTML = client_duplicate_data.message;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
require_once '../../../includes/modal_footer.php';
|
require_once '../../../includes/modal_footer.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user