diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a7e41f8f..8ff3f4ac 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -399,8 +399,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->match(['get', 'post', 'delete'], 'nhanceBranchMaster', 'MasterController::nhanceBranchMaster'); $routes->match(['get', 'post', 'delete'], 'vehicleTypeMaster', 'MasterController::vehicleTypeMaster'); $routes->match(['get', 'post', 'delete'], 'rtoMaster', 'MasterController::rtoMaster'); - - + $routes->get('checkDuplicateCdAccount', 'MasterController::checkDuplicateCdAccount'); }); $routes->post("policy_tranction/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail"); diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 9e4a5a08..58618abf 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -1350,6 +1350,16 @@ class MasterController extends AdminController // === INSERT === if (empty($id)) { + $cd_acc_count = $this->CDMasterModel->where('is_active', 1) + ->where('client_id', $data['client_id']) + ->where('insurer_id', $data['insurer_id']) + ->where('insurer_branch_id', $data['insurer_branch_id']) + ->countAllResults(); + + if($cd_acc_count > 0){ + return $this->respond(['status' => false, 'message' => 'A CD account has already been created for this client, insurer, and insurer branch combination.'], 200); + } + $this->myLogger->logme("error", 'Performing INSERT operation.'); $insert = $this->CDMasterModel->insert($data); $this->myLogger->logme("error", 'Insert result: ' . json_encode($insert)); @@ -1574,6 +1584,15 @@ class MasterController extends AdminController $data['insurer_branch_id'] = $insurer_branch_id; + $cd_acc_count = $this->CDMasterModel->where('is_active', 1) + ->where('client_id', $data['client_id']) + ->where('insurer_id', $data['insurer_id']) + ->where('insurer_branch_id', $data['insurer_branch_id']) + ->countAllResults(); + + if($cd_acc_count > 0){ + return $this->respond(['status' => false, 'message' => 'A CD account has already been created for this client, insurer, and insurer branch combination.'], 200); + } // array with data for CD Traction table $cd_tranction_data = [ @@ -1617,6 +1636,24 @@ class MasterController extends AdminController } } + public function checkDuplicateCdAccount() + { + $data = $this->request->getGet(); + + $cd_acc_count = $this->CDMasterModel + ->where('is_active', 1) + ->where('client_id', $data['client_id']) + ->where('insurer_id', $data['insurer_id']) + ->where('insurer_branch_id', $data['insurer_branch_id']) + ->countAllResults(); + + if($cd_acc_count > 0){ + return $this->respond(['status' => false, 'message' => 'A CD account has already been created for this client, insurer, and insurer branch combination.'], 200); + }else{ + return $this->respond(['status' => true], 200); + } + } + //Vehicle Master data Function diff --git a/app/Views/cd_master_add_modal.php b/app/Views/cd_master_add_modal.php index c57936c5..9089d35f 100644 --- a/app/Views/cd_master_add_modal.php +++ b/app/Views/cd_master_add_modal.php @@ -46,7 +46,7 @@
- @@ -229,11 +229,11 @@ $('#opening_bal').prop("disabled", false); if(isCdMasterPage == true){ - $('#client_id').val('').change(); - $('#insurer_id_for_cd').val('').change(); - $('#insurer_branch_id').val('').change(); + $('#cd_client_id').val('').select2(); + $('#insurer_id_for_cd').val('').select2(); + $('#insurer_branch_id').val('').select2(); - $('#client_id').prop("disabled", false); + $('#cd_client_id').prop("disabled", false); $('#insurer_id_for_cd').prop("disabled", false); $('#insurer_branch_id').prop("disabled", false); @@ -266,7 +266,7 @@ ); }); - $branchSelect.val('').trigger('change.select2'); + $branchSelect.val('').select2(); } function showCdMasterAddModal(){ @@ -301,5 +301,43 @@ $('#cd_ac_no_for_cd_master').append(option); } + function checkDuplicateCdAccount(){ + + let url = ''; + let client_id = $('#cd_client_id').val(); + let insurer_id = $('#insurer_id_for_cd').val(); + let insurer_branch_id = $('#insurer_branch_id').val(); + console.log({client_id, insurer_id, insurer_branch_id}); + + // Data to send in the AJAX request + let requestData = { + client_id: client_id, + insurer_id: insurer_id, + insurer_branch_id: insurer_branch_id, + }; + + if(client_id != "" && insurer_id != "" && insurer_branch_id != ""){ + // Send AJAX request + sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) { + + console.log('Data fetched successfully:', response); + + if (response.status == true) { + console.log('No dublicate found'); + } else { + + $('#cd_client_id').val('').select2(); + $('#insurer_id_for_cd').val('').select2(); + $('#insurer_branch_id').val('').select2(); + toastr.warning(response.message, 'WARNING'); + } + + }, function(xhr, status, error) { + console.error('Error fetching data:', error); + console.error(xhr.responseText); + toastr.error('An error occurred while checking the CD amount.', 'ERROR'); + }); + } + } \ No newline at end of file diff --git a/app/Views/cd_master_list.php b/app/Views/cd_master_list.php index f9ebba28..466588e9 100755 --- a/app/Views/cd_master_list.php +++ b/app/Views/cd_master_list.php @@ -323,7 +323,7 @@ table.dataTable thead th { $('#cd_client_id').prop("disabled", true); $('#insurer_id_for_cd').val(res.data.insurer_id).change(); $('#insurer_id_for_cd').prop("disabled", true); - $('#insurer_branch_id').val(res.data.insurer_id).change(); + $('#insurer_branch_id').val(res.data.insurer_branch_id).select2(); $('#insurer_branch_id').prop("disabled", true); $('#opening_date').val(res.data.opening_date); $('#cd_ac_no_for_cd_master').val(res.data.cd_ac_no); diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index 253d690b..4d2e70e9 100755 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -842,6 +842,17 @@ input:checked + .slider::before { if(response.status == false && response.insurer_id != 'undefined'){ toastr.warning('The CD Account Number not found.', 'Warning'); + + $('#cd_ac_no').empty(); + $('#cd_ac_no').append($('