Merge branch 'dev' of bitbucket.org:jubilian/nhance-enrollment into dev Srinivas

This commit is contained in:
Srinivas-Saravanan 2025-01-08 16:11:16 +05:30
commit 180812a544
7 changed files with 2250 additions and 1659 deletions

View File

@ -335,6 +335,8 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
$routes->post('get_data_for_mapping', 'EmployeeController::getDataForMapping');
$routes->post('unmap_employees/(:num)', 'EmployeeController::unmapEmployees/$1');
$routes->get('transformMailContent', 'LeadsController::transformMailContent');
$routes->get('getRackRateSIAmountAndAutoSiDataForAutoSI', 'ClientController::getRackRateSIAmountAndAutoSiDataForAutoSI');
$routes->post('createAutoSI', 'ClientController::createAutoSI');
});
$routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) {

View File

@ -39,6 +39,7 @@ use App\Models\PolicyTransactionModel;
use App\Models\PolicyTransactionStatusModel;
use App\Models\VehicleModel;
use App\Models\LeadsModel;
use App\Models\AutoSIModel;
use App\Controllers\EmpDataServiceController;
use App\Controllers\GoogleDriveController;
@ -80,6 +81,7 @@ class ClientController extends AdminController
protected $policyTransactionStatusModel;
protected $vehicleModel;
protected $leadsModel;
protected $AutoSIModel;
@ -116,6 +118,7 @@ class ClientController extends AdminController
$this->policyTransactionStatusModel = new PolicyTransactionStatusModel();
$this->vehicleModel = new VehicleModel();
$this->leadsModel = new LeadsModel();
$this->AutoSIModel = new AutoSIModel();
}
//--------------------------------------------------------------------------------------------------------
@ -3876,28 +3879,29 @@ class ClientController extends AdminController
// $EmpDataServiceController = new EmpDataServiceController();
// $EmpDataServiceController->importInceptionFileValidation(['file_id' => 160]);
$EmpDataServiceController = new EmpDataServiceController();
// $EmpDataServiceController = new EmpDataServiceController();
// $EmpDataServiceController->importInceptionUpdateTPAandUHID(['file_id' => 162]);
// $EmpDataServiceController->importInceptionFileValidation(['file_id' => 162]);
// $EmpDataServiceController->importDeletionValidation(['file_id' => 171]);
// $EmpDataServiceController->importDeletionUpdateEndorsementID(['file_id' => 171]);
$array = [
"employeeIds" => ["12800", "12798", "12797", "12799"],
"client_id" => "159",
"client_policy_id" => "336",
"client_branch_id" => "126",
"cd_ac_no" => "Apple_123",
"endorsement_no" => "ENDORSEMENT_ID",
"count" => 4,
"event_name" => "deletion",
"policy_name" => "GMC",
"user_id" => "1"
];
$EmpDataServiceController->cashDepositCalculationForDeletion($array);
// $array = [
// "employeeIds" => ["12800", "12798", "12797", "12799"],
// "client_id" => "159",
// "client_policy_id" => "336",
// "client_branch_id" => "126",
// "cd_ac_no" => "Apple_123",
// "endorsement_no" => "ENDORSEMENT_ID",
// "count" => 4,
// "event_name" => "deletion",
// "policy_name" => "GMC",
// "user_id" => "1"
// ];
// $EmpDataServiceController->cashDepositCalculationForDeletion($array);
// $employeeRestController = new EmployeeServiceController();
// $employeeRestController->employeesOnboardPreprocess(['file_id' => 757]);
$employeeRestController = new EmployeeServiceController();
$employeeRestController->employeesOnboardPreprocess(['file_id' => 756]);
}
@ -3943,4 +3947,95 @@ class ClientController extends AdminController
}
}
// ---------AUTO SI ----------------------------------------------------------------------------------------------
// Function to insert and update the auto si data and update the client policy table for auto si enableor disable
public function createAutoSI()
{
try {
$postData = $this->request->getPost();
if (empty($postData)) {
return $this->respond([
'status' => false,
'code' => 400,
'message' => 'No data provided.',
], 400);
}
$id = $postData['id'] ?? null;
$auto_si_enable = isset($postData['is_auto_si']) ? 1 : 0;
$affectedRows = 0;
$message = '';
$this->clientPolicyModel->where('id', $postData['client_policy_id'])->set('is_auto_si', $auto_si_enable)->update();
if ($id) {
$affectedRows = $this->AutoSIModel->where('id', $id)->set($postData)->update();
$message = "Auto SI data updated successfully.";
} else {
$affectedRows = $this->AutoSIModel->insert($postData);
$message = "Auto SI data submitted successfully.";
}
if ($affectedRows) {
return $this->respond([
'status' => true,
'code' => 200,
'message' => $message,
'data' => $affectedRows,
], 200);
} else {
return $this->respond([
'status' => false,
'code' => 500,
'message' => 'Failed to save data.',
], 500);
}
} catch (\Exception $e) {
return $this->respond([
'status' => false,
'code' => 500,
'message' => 'An error occurred.',
'error' => $e->getMessage(),
], 500);
}
}
//Function to get the data from Policy Premium 2 table data for the SI Dropdown, and Auto SI table data for edit auto_si
public function getRackRateSIAmountAndAutoSiDataForAutoSI()
{
$client_policy_id = $this->request->getGet('client_policy_id');
if(!empty($client_policy_id)){
$rack_rate_count = $this->policyPremium2Model
->where('client_policy_id', $client_policy_id)
->where('is_active', 1)
->groupBy('rack_rate_name')
->countAllResults();
$si_amounts = $this->policyPremium2Model
->where('client_policy_id', $client_policy_id)
->where('is_active', 1)
->findAll();
$auto_si = $this->AutoSIModel
->select('auto_si.*, client_policy.is_auto_si')
->join('client_policy', 'auto_si.client_policy_id = client_policy.id')
->where('client_policy_id', $client_policy_id)
->where('auto_si.is_active', 1)
->first();
if($rack_rate_count <= 1){
return $this->respond(['status' => true, 'code' => 200, 'si_amount' => $si_amounts, "auto_si_amount" => $auto_si], 200);
}else{
return $this->respond(['status' => false, 'code' => 200, 'message' => 'The policy has more than one rack rates. Auto SI create only one rack rate.', 'si_amount' => $si_amounts, "auto_si_amount" => $auto_si], 200);
}
}else{
return $this->respond(['status' => false, 'code' => 404, 'message' => 'No data to found. Client Policy Not found'], 200);
}
}
}

View File

@ -2,6 +2,8 @@
use App\Models\EmployeeModel;
use App\Models\InsurerModel;
use App\Models\ClientPolicyModel;
use App\Models\AutoSIModel;
use Kint\Kint;
@ -890,7 +892,7 @@ if (!function_exists('calculate_premium_new'))
// dd($temp_slab_rates);
/* 1. construct available/incoming family members composition & count */
$incoming_familiy_composition = get_familiy_composition($family_data);
// dd($incoming_familiy_composition);
// dd($incoming_familiy_composition);
//2 .get applicable familiy members composition & count from slab details & constrcut an array
//3 in for another loop compare slab level applicable familiy composition with available family composition
@ -900,7 +902,7 @@ if (!function_exists('calculate_premium_new'))
// dd($slab);
$res = compare_incoming_family_slab_with_configured_slab($slab,$incoming_familiy_composition);
// kint::dump($key);
// kint::dump($res);
kint::dump($res);
if($res['is_applicable'])
{
@ -940,7 +942,7 @@ if (!function_exists('calculate_premium_new'))
$temp_slab_rates[$key]['is_applicable'] = false;
}
}
// dd();
dd($family_data);
//4. if macthed then the current rack rate is applicable and find common variables link max age,max count,grade, basic pay,SI, self/acting self for current rack rate
@ -983,7 +985,7 @@ if (!function_exists('calculate_premium_new'))
// // Final combined condition
if ($conditions['isEmployeeSourceEnrollment'] || $conditions['isEmployeeSourceExcelFile'] || $primaryGridTypeCondition ) {
// dd($transformed_familiy_member_data);
dd($transformed_familiy_member_data);
$transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$temp_slab_rates,$default_si);
// dd($transformed_familiy_member_data);
$result[] = $transformed_familiy_member_data;
@ -2173,4 +2175,41 @@ if(!function_exists('generate_family_floater_key'))
$relation = 'self';
}
}
}
if(!function_exists('update_si_with_auto_si'))
{
function update_si_with_auto_si($client_id, $client_policy_id, $client_branch_id, $emp_code)
{
$clientPolicy = new ClientPolicyModel();
$policy_data = $clientPolicy->getPolicyDetails($client_id, $client_policy_id);
if(empty($policy_data) || $policy_data['is_auto_si']){
return null;
}else{
$autoSiModel = new AutoSIModel();
$auto_si_amounts = $autoSiModel
->where('client_policy_id', $client_policy_id)
->where('is_active', 1)
->first();
$params = [
'auto_si' => $auto_si_amounts,
];
$modified_si = modify_si_for_the_family($params);
return $modified_si;
}
}
}
if(!function_exists('modify_si_for_the_family'))
{
function modify_si_for_the_family($params)
{
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class AutoSIModel extends Model
{
protected $table = 'auto_si';
protected $primaryKey = 'id';
protected $allowedFields = [
'id',
'client_policy_id',
'family_composition',
'created_by',
'created_at',
'updated_by',
'updated_at',
'is_active'
];
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = ["checkAndADDCreatedByValue"];
protected $afterInsert = [];
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
protected function checkAndADDCreatedByValue(array $data)
{
// Check if 'updated_by' value is null or empty
if (empty($data['data']['created_by'])) {
// Set 'updated_by' value to the current session user ID
$data['data']['created_by'] = get_session_userid();
}
return $data;
}
protected function checkAndUpdateUpdatedByValue(array $data)
{
// Check if 'updated_by' value is null or empty
if (empty($data['data']['updated_by'])) {
// Set 'updated_by' value to the current session user ID
$data['data']['updated_by'] = get_session_userid();
}
return $data;
}
}

View File

@ -52,7 +52,8 @@ class ClientPolicyModel extends Model
"disclaimer",
"is_active",
"is_member_modify_allowed",
"cd_ac_pk"
"cd_ac_pk",
"is_auto_si",
];
// Callbacks

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,352 @@
<div id="rack_rate_auto_si_modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="fullWidthModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-full-width">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="fullWidthModalLabel">Rack Rate Auto SI</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<form role="form" class="parsley-examples" method="post" id="auto_si_form"
enctype="multipart/form-data">
<input type="hidden" id="auto_si_pk" name="id">
<input type="hidden" id="client_policy_pk" name="client_policy_id">
<div class="form-row">
<div class="form-group col-md-12">
<label class="switch" style="position: relative;">
<input id="auto_si_enable" type="checkbox" name="is_auto_si">
<span class="slider round" style="height: 27px;"></span>
</label>
<label for="auto_si_enable" style="position: relative;bottom: 5px;left: 10px;">Enable Auto
SI</label>
</div>
</div>
<hr>
<div id="dynamicForm">
<div class="formGroupContainer"></div>
</div> <br><br>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="submitFormButton">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div><!-- /.modal -->
<script>
let rowIndex = 0;
var SIAMOUNT = []; //policy_premium_2 table data, rack rate si amount
$(document).ready(function() {
// Attach change event listener to check for duplicates
$('#dynamicForm').on('change', '.form-row input, .form-row select', function() {
checkForDuplicate($(this).closest('.form-row'), $(this));
});
});
// Function to add a new row
function addRow(button = null, data = null) {
rowIndex++;
// Hide the "Add More" button for the current row (if button is provided)
if (button) {
$(button).hide();
}
// Create a new row
const formGroupContainer = document.querySelector('#dynamicForm .formGroupContainer');
const newRow = document.createElement('div');
newRow.className = 'row form-row';
newRow.innerHTML = `
<div class="col-md-1" style="margin-top: 45px;">
<div class="form-check form-check-inline">
<input class="form-check-input family-checkbox" type="checkbox" id="selfCheckbox${rowIndex}" name="self" ${data && data.self == 1 ? 'checked' : ''}>
<label class="form-check-label" for="selfCheckbox${rowIndex}">Self</label>
</div>
</div>
<div class="col-md-2" style="margin-top: 45px;">
<div class="form-check form-check-inline">
<input class="form-check-input family-checkbox" type="checkbox" id="spouseCheckbox${rowIndex}" name="spouse" ${data && data.spouse == 1 ? 'checked' : ''}>
<label class="form-check-label" for="spouseCheckbox${rowIndex}">Spouse</label>
</div>
</div>
<div class="col-md-1">
<label class="form-label" for="childrenInput${rowIndex}">Children</label>
<input type="number" class="form-control sm-input family-input" id="childrenInput${rowIndex}" placeholder="0" value="${data && data.children ? data.children : 0}" min="0">
</div>
<div class="col-md-1">
<label class="form-label" for="eldersInput${rowIndex}">Elders</label>
<input type="number" class="form-control sm-input family-input" id="eldersInput${rowIndex}" placeholder="0" value="${data && data.elders ? data.elders : 0}" min="0">
</div>
<div class="col-md-4">
<label class="form-label" for="siAmountSelect${rowIndex}">Choose SI Amount</label>
<select class="form-select form-control si-select" id="siAmountSelect${rowIndex}">
<option value="">Select SI</option>
</select>
</div>
<div class="col-md-2" style="margin-top: 45px;">
<button type="button" class="btn btn-success addMoreBtn" onclick="addRow(this)">+</button>
<button type="button" class="btn btn-danger" onclick="removeRow(this)">-</button>
</div>
`;
formGroupContainer.appendChild(newRow);
let selectedValue = data && data.si ? data.si : null;
appendSIAmount(SIAMOUNT, selectedValue, rowIndex)
}
// Function to remove a row
function removeRow(button) {
const row = button.closest('.form-row');
const formGroupContainer = document.querySelector('.formGroupContainer');
// Prevent deletion of the first row
if (formGroupContainer.children.length === 1) {
alert("The first row cannot be deleted.");
return;
}
// If the removed row had the "Add More" button visible, show it for the previous row
if ($(button).siblings('.addMoreBtn').is(':visible')) {
const previousRow = row.previousElementSibling;
if (previousRow) {
$(previousRow).find('.addMoreBtn').show();
}
}
// Remove the row
row.remove();
}
// Function to check for duplicates
function checkForDuplicate(currentRow, changedElement) {
const currentValues = {
self: currentRow.find('input[name="self"]').is(':checked'),
spouse: currentRow.find('input[name="spouse"]').is(':checked'),
children: currentRow.find('input[id^="childrenInput"]').val(),
elders: currentRow.find('input[id^="eldersInput"]').val(),
// siAmount: currentRow.find('select[id^="siAmountSelect"]').val(),
};
let isDuplicate = false;
$('.form-row').not(currentRow).each(function() {
const otherRow = $(this);
const otherValues = {
self: otherRow.find('input[name="self"]').is(':checked'),
spouse: otherRow.find('input[name="spouse"]').is(':checked'),
children: otherRow.find('input[id^="childrenInput"]').val(),
elders: otherRow.find('input[id^="eldersInput"]').val(),
// siAmount: otherRow.find('select[id^="siAmountSelect"]').val(),
};
if (
currentValues.self === otherValues.self &&
currentValues.spouse === otherValues.spouse &&
currentValues.children === otherValues.children &&
currentValues.elders === otherValues.elders
// && currentValues.siAmount === otherValues.siAmount
) {
isDuplicate = true;
return false; // Exit the loop if duplicate is found
}
});
if (isDuplicate) {
alert("Duplicate values are not allowed!");
// currentRow.find('input, select').val('').prop('checked', false);
if (changedElement.is('input[type="checkbox"]')) {
changedElement.prop('checked', false);
} else {
changedElement.val('');
}
}
}
//Function to form submit
$(document).ready(function() {
$('#submitFormButton').on('click', function(e) {
e.preventDefault();
const formData = new FormData($('#auto_si_form')[0])
const familyComposition = getFormDataWithJSON();
console.log(formData);
console.log('familyComposition', familyComposition);
formData.append('family_composition', JSON.stringify(familyComposition));
let url = '<?= base_url('util/createAutoSI') ?>';
$.ajax({
url: url,
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
console.log(response);
if (response.status) {
if (response.status == true) {
toastr.success(response.message, 'SUCCESS');
} else {
toastr.warning(response.message, 'WARNING');
}
} else {
toastr.error(response.message || 'Unable to get responce', 'ERROR');
}
},
error: function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
toastr.error('An error occurred while Auto SI Form Submit.', 'ERROR');
},
});
});
});
// Function to gather form data with JSON structure
function getFormDataWithJSON() {
const familyComposition = [];
$('#dynamicForm .form-row').each(function() {
const row = $(this);
const self = row.find('input[name="self"]').is(':checked') ? 1 : 0;
const spouse = row.find('input[name="spouse"]').is(':checked') ? 1 : 0;
const children = parseInt(row.find('input[id^="childrenInput"]').val()) || 0;
const elders = parseInt(row.find('input[id^="eldersInput"]').val()) || 0;
const si = row.find('select[id^="siAmountSelect"]').val() || null;
// if (si) {
familyComposition.push({
self: self,
spouse: spouse,
children: children,
elders: elders,
si: si,
});
// }
});
console.log('familyComposition', JSON.stringify(familyComposition))
return familyComposition;
}
function checkCDAmountForBasePremium(client_policy_id) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$('.formGroupContainer').empty();
console.log('client_policy_id', client_policy_id);
$('#client_policy_pk').val(client_policy_id);
let url = '<?= base_url('util/getRackRateSIAmountAndAutoSiDataForAutoSI') ?>';
// Data to send in the AJAX request
let requestData = {
client_policy_id: client_policy_id,
};
// Send AJAX request
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status == true) {
SIAMOUNT = response.si_amount;
if (response.auto_si_amount !== null) {
console.log(response.auto_si_amount.family_composition)
let familyComp = JSON.parse(response.auto_si_amount.family_composition)
console.log('familyComp', familyComp)
familyComp.forEach((item) => {
addRow(null, item);
});
$('#auto_si_pk').val(response.auto_si_amount.id);
if (response.auto_si_amount.is_auto_si == 1) {
$('#auto_si_enable').prop('checked', true);
} else {
$('#auto_si_enable').prop('checked', false);
}
} else {
addRow();
}
var myModal = new bootstrap.Modal(document.getElementById('rack_rate_auto_si_modal'));
myModal.show();
} else {
if (response.status == false && response.code == 200) {
Swal.fire({
title: response.message,
icon: 'warning',
})
} else {
toastr.error(response.message || 'Unable to fetch data', 'ERROR');
addRow();
}
}
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
toastr.error('An error occurred while checking the SI amount.', 'ERROR');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
// addRow();
});
}
function appendSIAmount(data, selectedValue = null, rowIndex = 0) {
console.log('data', data)
console.log('selectedValue', selectedValue)
console.log('rowIndex', rowIndex)
// Dynamically target the SI Amount Select element based on the rowIndex
const selectElement = $(`#siAmountSelect${rowIndex}`);
// Empty the current options
selectElement.empty();
// Add the default "Select SI" option
selectElement.append($('<option>', {
value: '',
text: 'Select SI'
}));
// Loop through the data to create the option elements
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.si,
text: item.si,
});
// If selectedValue matches the item.id, set this option as selected
if (selectedValue == item.si) {
option.attr('selected', true);
}
// Append the option to the select element
selectElement.append(option);
});
}
</script>