CHANGE_ENDORSEMENT_LIST_MODEL_DELETION_DATA : RV

This commit is contained in:
VENKATESHWARAN 2024-04-05 09:02:08 +05:30
parent 9d86bd0a33
commit af4749bdce
5 changed files with 205 additions and 83 deletions

View File

@ -918,6 +918,7 @@ class EmpDataServiceController extends BaseController
} }
public function cashDepositCalculationForSIEnhancement($arrayData) public function cashDepositCalculationForSIEnhancement($arrayData)
{ {
if (!empty($arrayData)) { if (!empty($arrayData)) {
@ -954,6 +955,7 @@ class EmpDataServiceController extends BaseController
} }
} }
public function cashDepositCalculationForDeletion($arrayData) public function cashDepositCalculationForDeletion($arrayData)
{ {
// print_r($arrayData); // print_r($arrayData);
@ -996,14 +998,37 @@ class EmpDataServiceController extends BaseController
} }
public function getPolicyNameUsingClientPolicyId($client_policy_id){
/**
* Below function retrieves the policy name associated with a given client policy ID.
*
* @param int $client_policy_id The ID of the client policy.
* @return mixed Returns the policy name if found, otherwise null.
*/
public function getPolicyNameUsingClientPolicyId($client_policy_id)
{
return $this->clientPolicyModel->select('policies.name as policy_name') return $this->clientPolicyModel->select('policies.name as policy_name')
->join('policies', 'policies.id = client_policy.policy_id') ->join('policies', 'policies.id = client_policy.policy_id')
->where('client_policy.id', $client_policy_id) ->where('client_policy.id', $client_policy_id)
->first(); ->first();
} }
public function convertRowTColumnForSIEnhancement($data){
/**
* Below function converts row data into column data format for SI enhancement.
*
* This function takes an array of data containing information about SI enhancement
* and calculates additional fields such as pro rata premium, GST, and total.
*
* @param array $data The array of data containing SI enhancement information.
* @return array Returns the converted data in column format.
*/
public function convertRowTColumnForSIEnhancement($data)
{
$result = array(); $result = array();
@ -1069,7 +1094,21 @@ class EmpDataServiceController extends BaseController
return $result; return $result;
} }
public function convertRowTColumnForDeletion($data){
/**
* Below function converts row data into column data format for deletion records.
*
* This function takes an array of data containing information about deletion records
* and converts it into a column format. It also calculates additional fields such as
* period of non-coverage, premium for non-coverage period, GST, total amount, and
* claim status based on the exist_reason field.
*
* @param array $data The array of data containing deletion records information.
* @return array Returns the converted data in column format.
*/
public function convertRowTColumnForDeletion($data)
{
$result = array(); $result = array();
@ -1078,44 +1117,56 @@ class EmpDataServiceController extends BaseController
$old_total = round(($obj->old_rata + $obj->old_gst), 2); $old_total = round(($obj->old_rata + $obj->old_gst), 2);
$result[] = array( $result[] = array(
"field_name" => 'Date of Leaving', "field_name" => 'Policy Period',
"old_value" => change_date_format($obj->end_date, 'Y-m-d', 'd-M-Y'), "data" => change_date_format($obj->start_date, 'Y-m-d', 'd-M-Y') . ' - <br> ' . change_date_format($obj->end_date, 'Y-m-d', 'd-M-Y'),
"new_value" => change_date_format($obj->date_of_leaving, 'Y-m-d', 'd-M-Y')
); );
$result[] = array( $result[] = array(
"field_name" => 'Exit Reason', "field_name" => 'Exit on',
"old_value" => ' --- ', "data" => change_date_format($obj->date_of_leaving, 'Y-m-d', 'd-M-Y'),
"new_value" => $obj->exist_reason
); );
$result[] = array( $result[] = array(
"field_name" => 'No of Days', "field_name" => 'Reason',
"old_value" => $obj->old_days, "data" => $obj->exist_reason,
"new_value" => $obj->no_of_days
); );
$result[] = array(
"field_name" => 'Pro Rata Premium',
"old_value" => $obj->old_rata, if($obj->exist_reason != 'death'){
"new_value" => $obj->pro_rata_premium
); $result[] = array(
"field_name" => 'Period of non coverage',
"data" => $obj->no_of_days
);
$result[] = array( $result[] = array(
"field_name" => 'GST(18%)', "field_name" => 'Premium for non coverage period',
"old_value" => $obj->old_gst, "data" => $obj->pro_rata_premium
"new_value" => $obj->gst );
);
$result[] = array(
"field_name" => 'GST(18%)',
"data" => $obj->gst
);
$result[] = array(
"field_name" => 'Total Amount',
"data" => $obj->total
);
$result[] = array( $result[] = array(
"field_name" => 'Total', "field_name" => 'Claim',
"old_value" => $old_total, "data" => '---',
"new_value" => $obj->total );
);
}
} }
return $result; return $result;
} }
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------
} }

View File

@ -454,16 +454,16 @@ class EmployeeController extends AdminController
// ------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------
public function endorsementList(){
// $empDataServiceController = new EmpDataServiceController();
// $group_key = $this->empEndorsementModel->select('group_key, actions')->where('id', 4)->first();
// $data = $this->empEndorsementModel->getDataForEnodrsementListinSIEnhancement($group_key['group_key']);
// $formatedData = $empDataServiceController->convertRowTColumnForSIEnhancement($data);
// $ee_entry = $this->empEndorsementModel->where('group_key', 107)->findAll(); /**
// $ee_entry[0]['field_name'] = remove_underscore_capitalize_first_letter($ee_entry[0]['field_name']); * Below function displays the endorsement list page.
// echo "<pre>"; *
// print_r($formatedData); die; * This method retrieves filter data from the request and fetches the endorsement list
* based on the provided filters such as client ID, policy ID, and status.
*/
public function endorsementList()
{
$data = []; $data = [];
$data['status'] = ['pending' => 'Pending', 'inprogress' => 'In-Progress', 'complete'=>'Complete']; $data['status'] = ['pending' => 'Pending', 'inprogress' => 'In-Progress', 'complete'=>'Complete'];
@ -480,41 +480,65 @@ class EmployeeController extends AdminController
$this->loadLayout('endorsement_list',$data); $this->loadLayout('endorsement_list',$data);
} }
public function getEmpEndoresmentEntry($id = null){
$empDataServiceController = new EmpDataServiceController(); /**
if($id) * Beleo function retrieves employee endorsement (emp_endorsement table) data.
{ *
$group_key = $this->empEndorsementModel->select('group_key, actions')->where('id', $id)->first(); * This method fetches endorsement data based on the provided ID.
$nor_data = $this->empEndorsementModel->where('group_key', $group_key['group_key'])->findAll(); * It determines the type of endorsement action (SI enhancement, deletion, or other),
* formats the data accordingly, and returns it as a response.
*
* @param int|null $id The ID of the endorsement entry to retrieve.
* @return \CodeIgniter\HTTP\Response Returns a JSON response containing the endorsement entry data.
*/
public function getEmpEndoresmentEntry($id = null)
{
// Create instance of EmpDataServiceController
$empDataServiceController = new EmpDataServiceController();
// Check if $id is provided
if ($id) {
// Retrieve group key and actions based on $id
$group_key_actions = $this->empEndorsementModel->select('group_key, actions')->where('id', $id)->first();
$groupedData = $this->empEndorsementModel->where('group_key', $group_key_actions['group_key'])->findAll();
// If group key and actions are found
if ($group_key_actions) {
// Retrieve endorsement data based on actions
switch ($group_key_actions['actions']) {
case 'si':
$data = $this->empEndorsementModel->getDataForEnodrsementListinSIEnhancement($group_key_actions['group_key']);
$formatedData = $empDataServiceController->convertRowTColumnForSIEnhancement($data);
break;
case 'd':
$data = $this->empEndorsementModel->getDataForEnodrsementListinDeletion($group_key_actions['group_key']);
$formatedData = $empDataServiceController->convertRowTColumnForDeletion($data);
break;
default:
$formatedData = $groupedData;
$formatedData[0]['field_name'] = remove_underscore_capitalize_first_letter($formatedData[0]['field_name']);
$formatedData[0]['old_value'] = formatDateOrReturn($formatedData[0]['old_value']);
$formatedData[0]['new_value'] = formatDateOrReturn($formatedData[0]['new_value']);
break;
}
// Return response with data
return $this->respond([
'dataStatus' => true,
'code' => 200,
'data' => $formatedData,
'data2' => $groupedData
], 200);
$ee_entry = ''; } else {
if($group_key['actions'] == 'si'){ // Return response if group key and actions are not found
return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'no data found'], 200);
$data = $this->empEndorsementModel->getDataForEnodrsementListinSIEnhancement($group_key['group_key']);
$formatedData = $empDataServiceController->convertRowTColumnForSIEnhancement($data);
$ee_entry = $formatedData;
}else if($group_key['actions'] == 'd'){
$data = $this->empEndorsementModel->getDataForEnodrsementListinDeletion($group_key['group_key']);
$formatedData = $empDataServiceController->convertRowTColumnForDeletion($data);
$ee_entry = $formatedData;
}else{
$ee_entry = $this->empEndorsementModel->where('group_key', $group_key['group_key'])->findAll();
$ee_entry[0]['field_name'] = remove_underscore_capitalize_first_letter($ee_entry[0]['field_name']);
$ee_entry[0]['old_value'] = formatDateOrReturn($ee_entry[0]['old_value']);
$ee_entry[0]['new_value'] = formatDateOrReturn($ee_entry[0]['new_value']);
} }
} else {
return $this->respond(['dataStatus' => true,'code' => 200, 'data' => $ee_entry, 'data2' => $nor_data], 200); // Return response if $id is not provided
} return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'no data found'], 200);
else
{
return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'no data found'], 200);
} }
} }
} }

View File

@ -394,6 +394,11 @@ if (! function_exists('generate_filename')) {
if (!function_exists('remove_underscore_capitalize_first_letter')) { if (!function_exists('remove_underscore_capitalize_first_letter')) {
function remove_underscore_capitalize_first_letter($word) { function remove_underscore_capitalize_first_letter($word) {
// Remove underscore and capitalize first letter of each word // Remove underscore and capitalize first letter of each word
$pattern = '/dob/i';
if (preg_match($pattern, $word)) {
$formattedEvent = 'DOB';
return $formattedEvent;
}
$formattedEvent = ucwords(str_replace('_', ' ', $word)); $formattedEvent = ucwords(str_replace('_', ' ', $word));
return $formattedEvent; return $formattedEvent;
} }

View File

@ -109,6 +109,7 @@ class EmpEndorsementModel extends Model
employee_polices.rata_premimum as old_rata, employee_polices.rata_premimum as old_rata,
employee_polices.gst as old_gst, employee_polices.gst as old_gst,
employee_polices.policy_end_date as end_date, employee_polices.policy_end_date as end_date,
client_policy.policy_start_date as start_date,
MAX(CASE WHEN a.field_name = 'date_of_exit' THEN a.new_value ELSE NULL END) AS date_of_leaving, MAX(CASE WHEN a.field_name = 'date_of_exit' THEN a.new_value ELSE NULL END) AS date_of_leaving,
MAX(CASE WHEN a.field_name = 'reason_for_exit' THEN a.new_value ELSE NULL END) AS exist_reason, MAX(CASE WHEN a.field_name = 'reason_for_exit' THEN a.new_value ELSE NULL END) AS exist_reason,
@ -122,6 +123,8 @@ class EmpEndorsementModel extends Model
employees ON a.emp_code = employees.emp_code employees ON a.emp_code = employees.emp_code
LEFT JOIN LEFT JOIN
employee_polices ON employees.id = employee_polices.employee_id employee_polices ON employees.id = employee_polices.employee_id
LEFT JOIN
client_policy ON client_policy.id = employee_polices.client_policy_id
LEFT JOIN ( LEFT JOIN (
SELECT SELECT
aa.emp_code, aa.emp_code,

View File

@ -157,12 +157,8 @@ table.dataTable tbody td {
<div class="modal-body" id="modal_body"> <div class="modal-body" id="modal_body">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-hover mb-0"> <table class="table table-hover mb-0">
<thead> <thead id="table_head_data">
<tr>
<th class="font-weight-medium"></th>
<th class="font-weight-medium">Old Value</th>
<th class="font-weight-medium">New Value</th>
</tr>
</thead> </thead>
<tbody id="table_data"> <tbody id="table_data">
@ -376,16 +372,48 @@ function fetchEmpEndorsementData(id) {
$('#heading').html(heading); $('#heading').html(heading);
$('#table_data').empty(); $('#table_data').empty();
$.each(endorsementData, function(index, item) { $('#table_head_data').empty();
var tableHtml = `
<tr>
<td>${item.field_name}</td> if(e_actions == 'd'){
<td>${formatNumberToIndianLocale(item.old_value, item.field_name)}</td>
<td>${formatNumberToIndianLocale(item.new_value, item.field_name, e_actions)}</td> $.each(endorsementData, function(index, item) {
var tableHtml = `
<tr>
<td>${item.field_name}</td>
<td>${formatNumberToIndianLocale(item.data, item.field_name, e_actions)}</td>
</tr>
`;
$('#table_data').append(tableHtml);
});
} else {
var table_head = `
<tr>
<th class="font-weight-medium"></th>
<th class="font-weight-medium">Old Value</th>
<th class="font-weight-medium">New Value</th>
</tr> </tr>
`; `;
$('#table_data').append(tableHtml); $('#table_head_data').append(table_head);
});
$.each(endorsementData, function(index, item) {
var tableHtml = `
<tr>
<td>${item.field_name}</td>
<td>${formatNumberToIndianLocale(item.old_value, item.field_name)}</td>
<td>${formatNumberToIndianLocale(item.new_value, item.field_name, e_actions)}</td>
</tr>
`;
$('#table_data').append(tableHtml);
});
}
} catch (error) { } catch (error) {
console.error('Error parsing API response data:', error); console.error('Error parsing API response data:', error);
} }
@ -407,17 +435,28 @@ function fetchEmpEndorsementData(id) {
} }
function formatNumberToIndianLocale(value, field_name, action) { function formatNumberToIndianLocale(value, field_name, action) {
console.log(action)
// Check if the value is a valid number (either as a number or as a string) // Check if the value is a valid number (either as a number or as a string)
if (!isNaN(value) && !isNaN(parseFloat(value)) && field_name != 'No of Days') { if (!isNaN(value) && !isNaN(parseFloat(value)) && field_name != 'No of Days') {
// Convert the value to a number and format it using Indian English locale // Convert the value to a number and format it using Indian English locale
var return_val = parseFloat(value).toLocaleString('en-IN'); var return_val = parseFloat(value).toLocaleString('en-IN');
if(field_name == 'Period of non coverage'){
return value + ' days';
}
if(field_name == 'Total Amount'){
return '₹ ' + return_val + ' ( To be Refunded )';
}
if(field_name == 'Total'){ if(field_name == 'Total'){
if(action == 'd'){ if(action == 'd'){
return '₹ ' + return_val + ' ( Refund )'; return '₹ ' + return_val + ' ( To be Refunded )';
}else if(action == 'si'){ }else if(action == 'si'){