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)
{
if (!empty($arrayData)) {
@ -954,6 +955,7 @@ class EmpDataServiceController extends BaseController
}
}
public function cashDepositCalculationForDeletion($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')
->join('policies', 'policies.id = client_policy.policy_id')
->where('client_policy.id', $client_policy_id)
->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();
@ -1069,7 +1094,21 @@ class EmpDataServiceController extends BaseController
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();
@ -1078,44 +1117,56 @@ class EmpDataServiceController extends BaseController
$old_total = round(($obj->old_rata + $obj->old_gst), 2);
$result[] = array(
"field_name" => 'Date of Leaving',
"old_value" => 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')
"field_name" => 'Policy Period',
"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'),
);
$result[] = array(
"field_name" => 'Exit Reason',
"old_value" => ' --- ',
"new_value" => $obj->exist_reason
"field_name" => 'Exit on',
"data" => change_date_format($obj->date_of_leaving, 'Y-m-d', 'd-M-Y'),
);
$result[] = array(
"field_name" => 'No of Days',
"old_value" => $obj->old_days,
"new_value" => $obj->no_of_days
"field_name" => 'Reason',
"data" => $obj->exist_reason,
);
$result[] = array(
"field_name" => 'Pro Rata Premium',
"old_value" => $obj->old_rata,
"new_value" => $obj->pro_rata_premium
);
if($obj->exist_reason != 'death'){
$result[] = array(
"field_name" => 'Period of non coverage',
"data" => $obj->no_of_days
);
$result[] = array(
"field_name" => 'GST(18%)',
"old_value" => $obj->old_gst,
"new_value" => $obj->gst
);
$result[] = array(
"field_name" => 'Premium for non coverage period',
"data" => $obj->pro_rata_premium
);
$result[] = array(
"field_name" => 'GST(18%)',
"data" => $obj->gst
);
$result[] = array(
"field_name" => 'Total Amount',
"data" => $obj->total
);
$result[] = array(
"field_name" => 'Total',
"old_value" => $old_total,
"new_value" => $obj->total
);
$result[] = array(
"field_name" => 'Claim',
"data" => '---',
);
}
}
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']);
// echo "<pre>";
// print_r($formatedData); die;
/**
* Below function displays the endorsement list page.
*
* 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['status'] = ['pending' => 'Pending', 'inprogress' => 'In-Progress', 'complete'=>'Complete'];
@ -480,41 +480,65 @@ class EmployeeController extends AdminController
$this->loadLayout('endorsement_list',$data);
}
public function getEmpEndoresmentEntry($id = null){
$empDataServiceController = new EmpDataServiceController();
if($id)
{
$group_key = $this->empEndorsementModel->select('group_key, actions')->where('id', $id)->first();
$nor_data = $this->empEndorsementModel->where('group_key', $group_key['group_key'])->findAll();
/**
* Beleo function retrieves employee endorsement (emp_endorsement table) data.
*
* This method fetches endorsement data based on the provided ID.
* 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 = '';
if($group_key['actions'] == 'si'){
$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 response if group key and actions are not found
return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'no data found'], 200);
}
return $this->respond(['dataStatus' => true,'code' => 200, 'data' => $ee_entry, 'data2' => $nor_data], 200);
}
else
{
return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'no data found'], 200);
} else {
// Return response if $id is not provided
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')) {
function remove_underscore_capitalize_first_letter($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));
return $formattedEvent;
}

View File

@ -109,6 +109,7 @@ class EmpEndorsementModel extends Model
employee_polices.rata_premimum as old_rata,
employee_polices.gst as old_gst,
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 = '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
LEFT JOIN
employee_polices ON employees.id = employee_polices.employee_id
LEFT JOIN
client_policy ON client_policy.id = employee_polices.client_policy_id
LEFT JOIN (
SELECT
aa.emp_code,

View File

@ -157,12 +157,8 @@ table.dataTable tbody td {
<div class="modal-body" id="modal_body">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<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 id="table_head_data">
</thead>
<tbody id="table_data">
@ -376,16 +372,48 @@ function fetchEmpEndorsementData(id) {
$('#heading').html(heading);
$('#table_data').empty();
$.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>
$('#table_head_data').empty();
if(e_actions == 'd'){
$.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>
`;
$('#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) {
console.error('Error parsing API response data:', error);
}
@ -407,17 +435,28 @@ function fetchEmpEndorsementData(id) {
}
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)
if (!isNaN(value) && !isNaN(parseFloat(value)) && field_name != 'No of Days') {
// Convert the value to a number and format it using Indian English locale
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(action == 'd'){
return '₹ ' + return_val + ' ( Refund )';
return '₹ ' + return_val + ' ( To be Refunded )';
}else if(action == 'si'){