FEAT_CD_ENABLE_SWITCH_AND_OTHER BDS_AND OTHERS : RV

This commit is contained in:
VENKATESHWARAN 2025-04-11 17:28:43 +05:30
parent ac4cb2eb3e
commit ea11ad3d58
11 changed files with 205 additions and 19 deletions

View File

@ -4776,6 +4776,15 @@ class ClientController extends AdminController
// dd($finalJson);
// $baseWhere = [
// 'client_id' => 159,
// 'client_policy_id' => 336,
// 'insurer_id' => 1,
// 'cd_ac_pk' => 56,
// 'event_name' => "addition",
// ];
// $return_value = check_cd_entry_exist($baseWhere);
// dd($return_value);
}

View File

@ -4105,6 +4105,9 @@ class EmpDataServiceController extends BaseController
AND emp_endorsement.pk IN (" . implode(',', $arrayData['employeeIds']) . ")
AND employee_polices.claim_status = 0
AND emp_endorsement.field_name = 'date_of_exit'
AND emp_endorsement.is_active = 1
AND emp_endorsement.actions = 'd'
AND emp_endorsement.status != 'truncated';
")->getRow();
// dd(db_connect()->getLastQuery(), $amount);

View File

@ -1422,11 +1422,12 @@ class MasterController extends AdminController
if ($insert) {
//for CD Tranction Table
$cd_tranction_data['cd_ac_pk'] = $this->CDMasterModel->insertID();
$response = DepositHelper::saveDeposit($cd_tranction_data, $loggedInUserID);
$cd_data = $this->CDMasterModel->where('client_id', $data['client_id'])->where('insurer_id', $data['insurer_id'])->findAll();
return $this->respond(['status' => true, 'data' => $cd_data, 'cd_ac_no'=>$data['cd_ac_no'], 'message' => 'CD Account number created successfully'], 200);
return $this->respond(['status' => true, 'data' => $cd_data, 'cd_ac_no'=>$data['cd_ac_no'], 'message' => 'CD Account number created successfully', "FOR BDS PURPOSE"], 200);
}else{
return $this->respond(['status' => false, 'message' => 'Failed to created CD Account number'], 200);
}

View File

@ -306,6 +306,12 @@ class PolicyTransactionController extends BaseController
$data['policy_with_corr'] = 1;
}
if (!isset($data['is_cd_reduce_from_bds'])) {
$data['is_cd_reduce_from_bds'] = 0;
} elseif ($data['is_cd_reduce_from_bds']) {
$data['is_cd_reduce_from_bds'] = 1;
}
if($data['ct_type'] == ""){
$data['ct_type'] = 1;
}
@ -342,7 +348,7 @@ class PolicyTransactionController extends BaseController
$this->policyTransactionModel->update($insert, ['client_policy_id' => $client_policy_id]);
$emp_policy_insert = $this->InsertIndividualEmpPolicyTable($emp_data, $client_policy_id);
if ($data['client_type'] == 1 && $data['status'] == 'completed') {
if ($data['client_type'] == 1 && $data['status'] == 'completed' && $data['is_cd_reduce_from_bds'] == 1) {
$this->processCompletedStatus($data, $client_policy_id, $data['insurer_id']);
}
}
@ -362,6 +368,7 @@ class PolicyTransactionController extends BaseController
private function updateInceptionPolicy($id, $data)
{
// print_r($data); die;
if ($this->policyTransactionModel->update($id, $data)) {
$this->insertTransactionStatus($id, $data, 1);
@ -391,7 +398,7 @@ class PolicyTransactionController extends BaseController
}
if ($data['status'] == 'completed' && $data['ct_type'] == 2) {
if($data['client_type'] == 1){
if($data['client_type'] == 1 && $data['is_cd_reduce_from_bds'] == 1){
$this->processCompletedStatus($data, $data['client_policy_id'], $data['insurer_id']);
}
}
@ -426,7 +433,12 @@ class PolicyTransactionController extends BaseController
foreach ($data['follow_insurer_id'] as $index => $insurer) {
// Separate the insurer and insurer branch
list($insurer_branch_id, $insurer_id) = explode('-', $insurer);
if(isset($insurer) && !empty($insurer)){
list($insurer_branch_id, $insurer_id) = explode('-', $insurer);
}else{
$insurer_branch_id = null;
$insurer_id = null;
}
// Prepare each co-share detail entry
$coShareDetails[] = [
@ -547,7 +559,7 @@ class PolicyTransactionController extends BaseController
private function processCompletedStatus($data, $client_policy_id, $insurer_id)
{
$totalAmount = (int)$data['total'][0] ?? 0;
$description = 'The following amount of Rs. ' . $totalAmount . '/- has been debited for the ' . $data['emp_count'] . ' employees at Inception.';
$description = 'The following amount of Rs. ' . $totalAmount . '/- has been debited for the ' . $data['emp_count'] . ' employees at Inception (BDS).';
$cdTransactionData = [
'amount' => $totalAmount,
@ -562,8 +574,9 @@ class PolicyTransactionController extends BaseController
'updated_by' => get_session_userid(),
'event_name' => 'inception',
'is_active' => 1,
'cd_ac_pk' => $data['cd_ac_pk']
];
DepositHelper::saveDeposit($cdTransactionData, get_session_userid());
}
@ -987,7 +1000,6 @@ class PolicyTransactionController extends BaseController
}
//------------------------------------------------------------------------------------------------
// Policy Transaction Endorsement
@ -1102,6 +1114,12 @@ class PolicyTransactionController extends BaseController
$data['policy_with_corr'] = 1;
}
if (!isset($data['is_cd_reduce_from_bds'])) {
$data['is_cd_reduce_from_bds'] = 0;
} elseif ($data['is_cd_reduce_from_bds']) {
$data['is_cd_reduce_from_bds'] = 1;
}
if(empty($data['data_received_date'])){
$data['data_received_date'] = null;
}else{
@ -1171,8 +1189,8 @@ class PolicyTransactionController extends BaseController
'policy_type_id' => $issue_type['policy_type_id'] ?? null,
'issue_type' => $issue_type['issue_type'] ?? null,
'source_client_policy_id' => $issue_type['source_client_policy_id'] ?? null,
'cd_ac_no' => $issue_type['cd_ac_no'] ?? null,
'cd_ac_pk' => $issue_type['cd_ac_pk'] ?? null,
'cd_ac_no' => isset( $data['cd_ac_no']) && !empty($data['cd_ac_no']) ? $data['cd_ac_no'] : $issue_type['cd_ac_no'] ?? null,
'cd_ac_pk' => isset( $data['cd_ac_pk']) && !empty($data['cd_ac_pk']) ? $data['cd_ac_pk'] : $issue_type['cd_ac_pk'] ?? null,
// 'policy_issue_date' => $issue_type['policy_issue_date'] ?? null,
'policy_start_date' => $issue_type['policy_start_date'] ?? null,
'policy_end_date' => $issue_type['policy_end_date'] ?? null,
@ -1231,6 +1249,7 @@ class PolicyTransactionController extends BaseController
$update = $this->policyTransactionModel->where('id', $id)->set($data)->update();
if ($update) {
$this->insertTransactionStatus($id, $data, 1);
$this->handleCompletedStatus($data, $id);
$this->insertOrUpdateCoShareDetails($data, $id);
@ -1243,13 +1262,13 @@ class PolicyTransactionController extends BaseController
}
private function handleCompletedStatus($data, $policy_tran_id)
{
if ($data['status'] == 'completed' && $data['ct_type'] == 2) {
{
if ($data['client_type'] == 1 && $data['status'] == 'completed' && $data['is_cd_reduce_from_bds'] == 1) {
$tolamt = $data['total'][0] ?? 0;
$description = 'The following amount of Rs. ' . round($tolamt, 2) . '/- has been' .
($data['action_type'] == 'deletion' ? ' Credit ' : ' Debit ') . 'from the policy transaction';
($data['action_type'] == 'deletion' ? ' Credit ' : ' Debit ') . 'from the policy transaction (BDS)';
$cd_tranction_data = [
'amount' => $tolamt,
@ -1264,6 +1283,7 @@ class PolicyTransactionController extends BaseController
'updated_by' => get_session_userid(),
'event_name' => $data['action_type'],
'is_active' => 1,
'cd_ac_pk' => $data['cd_ac_pk'] ?? null,
];
DepositHelper::saveDeposit($cd_tranction_data, get_session_userid());
@ -1589,6 +1609,7 @@ class PolicyTransactionController extends BaseController
->select("
pt_co_share_details.*,
policy_transaction.bro_payable_by,
policy_transaction.cd_ac_pk,
(
select cd_ac_no
from cd_master
@ -1616,9 +1637,12 @@ class PolicyTransactionController extends BaseController
->where('is_active', 1)
->first();
$cd_ac_no = db_connect()->table('cd_master')->where('id', $is_copay_yes['cd_ac_pk'] ?? null)->get()->getRowArray();
if ($totalCount) {
return $this->respond(['status' => true, 'code' => 200, 'data' => $totalCount, 'is_copay_yes' => $is_copay_yes], 200);
return $this->respond(['status' => true, 'code' => 200, 'data' => $totalCount, 'is_copay_yes' => $is_copay_yes, "cd_master_data" => $cd_ac_no], 200);
} else {
$insurer_data = $this->clientPolicyModel->where('id', $client_policy_id)->where('is_active', 1)->first();
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to get data'], 200);
}

View File

@ -32,8 +32,11 @@ class DepositHelper
*/
public static function saveDeposit(array $data, int $loggedInUserID): array
{
log_message("error", 'saveDeposit function called '. json_encode($data));
// Retrieve the last known balance
$lastBalance = self::calculateLastBalance($data['client_id'], $data['insurer_id'], $data['cd_ac_no']);
$lastBalance = self::calculateLastBalance($data['client_id'], $data['insurer_id'], $data['cd_ac_no'], $data['cd_ac_pk'] ?? null);
// Calculate the new balance based on the transaction type
$newBalance = self::calculateBalance(
@ -91,15 +94,21 @@ class DepositHelper
*
* @return float The last known balance.
*/
public static function calculateLastBalance(int $clientId, int $insurerId, $cd_ac_no): float
public static function calculateLastBalance(int $clientId, int $insurerId, $cd_ac_no, $cd_ac_pk): float
{
$model = new ClientDepositModel();
// $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE client_id = ? AND insurer_id = ? ORDER BY created_at DESC LIMIT 1";
// $getLastBalanceParams = [$clientId, $insurerId];
$getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_no = ? AND is_active = 1 ORDER BY created_at DESC LIMIT 1";
$getLastBalanceParams = [$cd_ac_no];
if(empty($cd_ac_pk)){
$getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_no = ? AND is_active = 1 ORDER BY created_at DESC LIMIT 1";
$getLastBalanceParams = [$cd_ac_no];
}else{
$getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_pk = ? AND is_active = 1 ORDER BY created_at DESC LIMIT 1";
$getLastBalanceParams = [$cd_ac_pk];
}
$lastBalance = $model->query($getLastBalanceQuery, $getLastBalanceParams)->getRow()->balance ?? 0;

View File

@ -677,3 +677,69 @@ if (!function_exists('is_json_string')) {
}
}
if (!function_exists('check_cd_entry_exist')) {
function check_cd_entry_exist($params)
{
$db = db_connect();
$client_id = $params['client_id'];
$client_policy_id = $params['client_policy_id'];
$insurer_id = $params['insurer_id'];
$cd_ac_pk = $params['cd_ac_pk'];
$event_name = $params['event_name'];
// Check if truncated entry (sub_type = 8) exists
$has_truncated = $db->table('cash_deposit')
->where('client_id', $client_id)
->where('insurer_id', $insurer_id)
->where('cd_ac_pk', $cd_ac_pk)
->where('client_policy_id', $client_policy_id)
->where('event_name', $event_name)
->where('sub_type', 8)
->where('is_active', 1)
->countAllResults();
if ($has_truncated) {
echo "has_truncated";
// Get all entries with same details (including truncated)
$entries = $db->table('cash_deposit')
->where('client_id', $client_id)
->where('insurer_id', $insurer_id)
->where('cd_ac_pk', $cd_ac_pk)
->where('client_policy_id', $client_policy_id)
->where('event_name', $event_name)
->where('is_active', 1)
->where('sub_type !=', 8)
->get()
->getResultArray();
if (count($entries) > 1) {
// Only one entry found (truncated)
return true;
}else{
return false;
}
} else {
// Check if any other entry exists
$entry = $db->table('cash_deposit')
->where('client_id', $client_id)
->where('insurer_id', $insurer_id)
->where('cd_ac_pk', $cd_ac_pk)
->where('client_policy_id', $client_policy_id)
->where('event_name', $event_name)
->where('is_active', 1)
->get()
->getRowArray();
if (!empty($entry)) {
return true;
}
}
return false;
}
}

View File

@ -79,6 +79,7 @@ class PolicyTransactionModel extends Model
'cd_ac_pk',
'install_due_date',
'policy_with_corr',
'is_cd_reduce_from_bds',
];

View File

@ -426,7 +426,7 @@
<select id="member_ecard_mail_customButton" class="form-control" style="border:none;right: 6px;width: auto;position: absolute;z-index: 1;top: 17px;height: 32px;float: right;" onchange="copyToClipboard(this)">
<option value="">PlaceHolders</option>
<?php foreach ($placeHolders as $value): ?>
<?php if ($value == 'member_name' || $value == 'nhance_logo' || $value == 'client_logo' || $value == 'app_link' || $value == 'client_name' || $value == 'member_summary') { ?>
<?php if ($value) { ?>
<?php $valueChange = str_replace('_', ' ', $value);
$valueChange = ucwords($valueChange); ?>
<option value="{{<?php echo $value; ?>}}"><?php echo $valueChange; ?></option>

View File

@ -119,6 +119,7 @@
<input type="hidden" name="client_id" id="client_id_for_edit">
<input type="hidden" name="insurer_id" id="insurer_id">
<input type="hidden" name="cd_ac_no" id="cd_ac_no">
<input type="hidden" name="cd_ac_pk" id="cd_ac_pk">
<input type="hidden" name="ct_type" id="ct_type">
<input type="hidden" name="" id="bro_payable_by">
<input type="hidden" name="" id="cop_yes">
@ -310,6 +311,15 @@
<label for="policy_with_corr" style="position: relative;top: 33px;left: 25px;"> Policy with Correction</label>
</div>
<div class="form-group col-md-3">
<label class="switch" style="position: relative;top: 32px;left: 20px;">
<input id="is_cd_reduce_from_bds" type="checkbox" name="is_cd_reduce_from_bds">
<span class="slider round" style="height: 27px;"></span>
</label>
<label for="is_cd_reduce_from_bds" style="position: relative;top: 33px;left: 25px;">Make Entry in CD &nbsp;&nbsp; <i class="fa fa-info-circle" data-toggle="tooltip" title="Enabling this will affect ( Credit/Debit ) the CD transaction. ( GMC, GPA, EDLI and GTLI, CD transaction from CRM )"></i></label>
</div>
</div>
<hr>
@ -585,6 +595,14 @@ $(document).ready(function(){
var cd_ac_no = $(this).find('option:selected').attr('data-cd');
var start_date = $(this).find('option:selected').attr('data-sd');
var end_date = $(this).find('option:selected').attr('data-ed');
var policy_type_id = $(this).find('option:selected').attr('data-ptid');
if(policy_type_id == 1 || policy_type_id == 2 || policy_type_id == 3 || policy_type_id == 4 || policy_type_id == 5 || policy_type_id == 6 || policy_type_id == 7){
$('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false)
}else{
$('#is_cd_reduce_from_bds').prop('disabled',false)
}
// console.log('client_id', client_id);
// console.log('client_policy_id', client_policy_id);
@ -596,7 +614,7 @@ $(document).ready(function(){
$('#policy_no').val(policy_no);
$('#insurer_id').val(insurer);
$('#tpa').val(tpa).change();
$('#cd_ac_no').val(cd_ac_no);
// $('#cd_ac_no').val(cd_ac_no);
$('#policy_start_date').val(start_date);
$('#policy_end_date').val(end_date);
@ -619,6 +637,9 @@ $(document).ready(function(){
if(res.status == true){
if(res.data.length > 0){
$('#ct_type').val(2)
$('#cd_ac_pk').val(res.is_copay_yes.cd_ac_pk);
$('#cd_ac_no').val(res.cd_master_data.cd_ac_no ?? "");
$('#bro_payable_by').val(res.data[0].bro_payable_by)
if(res.is_copay_yes && res.is_copay_yes.co_share == 1){
@ -633,9 +654,11 @@ $(document).ready(function(){
}else{
$('#ct_type').val(1)
addInsurerColumn()
}
}else{
$('#ct_type').val(1)
addInsurerColumn()
}
},
@ -914,6 +937,9 @@ function getPolicyTransactionDataForEndorsementEdit(input){
$('#last_action_date').val(res.data.last_action_date);
$('#install_due_date').val(res.data.install_due_date);
$('#bro_payable_by').val(res.data.bro_payable_by);
$('#cd_ac_pk').val(res.data.cd_ac_pk);
$('#cd_ac_no').val(res.data.cd_ac_no);
$('#ct_type').val(res.data.ct_type);
if (res.data.policy_with_corr == 1) {
$('#policy_with_corr').prop('checked', true);
@ -921,6 +947,12 @@ function getPolicyTransactionDataForEndorsementEdit(input){
$('#policy_with_corr').prop('checked', false);
}
if (res.data.is_cd_reduce_from_bds == 1) {
$('#is_cd_reduce_from_bds').prop('checked', true).prop('checked', false);
} else {
$('#is_cd_reduce_from_bds').prop('checked', false);
}
if (res.data.action_type == 'policy_instalment') {
$('.install_due_date_div').show()
}else{
@ -937,6 +969,13 @@ function getPolicyTransactionDataForEndorsementEdit(input){
addInsurerColumn();
}
if(res.data.policy_type_id == 1 || res.data.policy_type_id == 2 || res.data.policy_type_id == 3 || res.data.policy_type_id == 4 || res.data.policy_type_id == 5 || res.data.policy_type_id == 6 || res.data.policy_type_id == 7){
$('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false);
}else{
$('#is_cd_reduce_from_bds').prop('disabled',false);
}
}else{
console.log('No data found');
}

View File

@ -698,6 +698,7 @@ document.addEventListener("DOMContentLoaded", function () {
'data-itp' : item.itp,
'data-bap' : item.bap,
'data-tpa' : item.tpa_branch_id + '-' + item.tpa_id,
'data-ptid' : item.policy_type_id,
});
$('#client_policy_id').append(option);
});

View File

@ -123,6 +123,12 @@
color: white !important;
margin-right: 5px;
}
:disabled {
background-color: #e0e0e0;
color: #666;
}
</style>
<div class="tab-pane fade active show" id="form">
@ -422,6 +428,16 @@
<label for="policy_with_corr" style="position: relative;top: 33px;left: 25px;"> Policy with Correction</label>
</div>
<div class="form-group col-md-3">
<label class="switch" style="position: relative;top: 32px;left: 20px;">
<input id="is_cd_reduce_from_bds" type="checkbox" name="is_cd_reduce_from_bds">
<span class="slider round" style="height: 27px;"></span>
</label>
<label for="is_cd_reduce_from_bds" style="position: relative;top: 33px;left: 25px;"> Make Entry in CD &nbsp;&nbsp; <i class="fa fa-info-circle" data-toggle="tooltip" title="Enabling this will affect ( Credit/Debit ) the CD transaction. ( GMC, GPA, EDLI and GTLI, CD transaction from CRM )"></i>
</label>
</div>
<!-- <div class="form-group col-md-3 current_date" style="display: none;">
<label for="bp_igst">Process Start Date</label>
<input id="process_start_date" type="text" class="form-control" name="process_start_date" placeholder="DD/MM/YYYY">
@ -1352,6 +1368,11 @@ $(document).ready(function(){
$('#tpa_div').show();
}
if(value == 1 || value == 2 || value == 3 || value == 4 || value == 5 || value == 6 || value == 7){
$('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false)
}else{
$('#is_cd_reduce_from_bds').prop('disabled',false)
}
});
@ -1527,6 +1548,12 @@ function getPolicyTransactionDataForEdit(input) {
$('#tpa_div').show();
}
if(policy_type_id_for_hide_tpa == 1 || policy_type_id_for_hide_tpa == 2 || policy_type_id_for_hide_tpa == 3 || policy_type_id_for_hide_tpa == 4 || policy_type_id_for_hide_tpa == 5 || policy_type_id_for_hide_tpa == 6 || policy_type_id_for_hide_tpa == 7){
$('#is_cd_reduce_from_bds').prop('disabled',true).prop('checked', false)
}else{
$('#is_cd_reduce_from_bds').prop('disabled',false)
}
if(res.data.client_policy_id != 0 && res.data.client_policy_id != null){
$('#hide_file_upload').show();
}else{
@ -1744,6 +1771,12 @@ function getPolicyTransactionDataForEdit(input) {
$('#policy_with_corr').prop('checked', false);
}
if (res.data.is_cd_reduce_from_bds == 1) {
$('#is_cd_reduce_from_bds').prop('checked', true).prop('checked', false);
} else {
$('#is_cd_reduce_from_bds').prop('checked', false);
}
} else {
console.log('No data found');
}