CHANGE_CD_ACC_RESTRICT

This commit is contained in:
VENKATESHWARAN 2025-10-24 17:30:59 +05:30
parent 807399a564
commit 2d2533d178
6 changed files with 211 additions and 126 deletions

View File

@ -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");

View File

@ -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

View File

@ -46,7 +46,7 @@
<div class="form-row">
<div class="form-group col-md-6">
<label for="insurer_branch_id">Insurer Branch<span class="text-danger">*</span></label>
<select class="form-control <?= !isset($CD_Master_Data) ? 'readonly-select' : '' ?>" id="insurer_branch_id" name="insurer_branch_id" required>
<select class="form-control <?= !isset($CD_Master_Data) ? 'readonly-select' : '' ?>" id="insurer_branch_id" name="insurer_branch_id" onchange="checkDuplicateCdAccount(this)" required>
<option value="">Select Insurer Branch</option>
<?php if(isset($insurer_branch) && !empty($insurer_branch))
{ foreach($insurer_branch as $branch) { ?>
@ -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 = '<?= base_url('util/checkDuplicateCdAccount') ?>';
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');
});
}
}
</script>

View File

@ -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);

View File

@ -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($('<option>', {
value: '',
text: 'Select CD Account Number'
}));
$('#cd_ac_no').append($('<option>', {
value: 'add_cd',
text: '+ Add New CD'
}));
return;
}
appendCDACNO(response.data)
@ -1806,15 +1817,18 @@ input:checked + .slider::before {
//console.log('appendCDACNO', select);
$('#cd_ac_no').empty();
$('#cd_ac_no').append($('<option>', {
value: '',
text: 'Select CD Account Number'
}));
if(data.length == 0){
$('#cd_ac_no').append($('<option>', {
value: 'add_cd',
text: '+ Add New CD'
}));
}
$.each(data, function(index, item) {
const option = $('<option>', {
@ -2381,10 +2395,8 @@ input:checked + .slider::before {
</script>
<script>
$(document).ready(function () {
$('#chk-show-expired').on('change', function () {
const showExpired = $(this).is(':checked');
@ -2512,9 +2524,6 @@ $(document).ready(function () {
});
});
</script>

View File

@ -3398,10 +3398,12 @@
text: 'Select CD No',
}));
if(data.length == 0){
$('#cd_ac_no_'+unique_id).append($('<option>', {
value: 'add_cd',
text: '+ Add CD'
}));
}
$.each(data, function(index, item) {
var option = $('<option>', {