diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f8bed9c..cbb5b40 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -144,6 +144,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 57fcb60..2643143 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -151,6 +151,16 @@ class ClientController extends AdminController return $this->response->setJSON(['isDuplicate' => $isDuplicate]); } + 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 smapletest() { $headers = [ diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index cdd35ad..d7708b7 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -214,5 +214,19 @@ 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 18c2301..f55b2dc 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -648,7 +648,7 @@ function appendContactHtml(contact = false, reset = false) {