diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d640d843..10fb373c 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -172,6 +172,7 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->group("others", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "ClientController::createOtherTabContent"); + $routes->post('check-duplicate', 'ClientController::validateDuplicateByClientBranch'); }); }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 63ddac11..fb0c5d6f 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -132,6 +132,15 @@ class ClientController extends AdminController //-------------------------------------------------------------------------------------------------------- + public function validateDuplicateByClientBranch() + { + $request = service('request'); + $value = $request->getPost('value'); + $clientId = $request->getPost('client_id'); + $branchId = $request->getPost('branch_id'); + $isDuplicate = $this->clientModel->isDuplicateByClientBranch($value, $clientId, $branchId); + return $this->response->setJSON(['isDuplicate' => $isDuplicate]); + } public function checkDuplicateTableFieldValue() { $table = $this->request->getPost('table'); diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index 9abe8929..09db986d 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -226,5 +226,18 @@ class ClientModel extends Model return $result; } + public function isDuplicateByClientBranch($email, $clientId, $branchId) + { + $builder = $this->db->table('level_contacts lc') + ->select('lc.id') + ->join('client_branch cb', 'lc.ref_id = cb.id', 'left') + ->where('lc.email', $email) + ->where('lc.contact_type', 'client') + ->where('cb.client_id', $clientId) + ->where('lc.ref_id', $branchId) + ->get(); + + return $builder->getNumRows() > 0 ? true : false; + } } diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index f35d5f99..4db64b3b 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -649,7 +649,7 @@ function appendContactHtml(contact = false, reset = false) {