FIX_BDS_CODE_CONFLICT

This commit is contained in:
velz 2024-12-24 12:29:45 +05:30
parent 942d184914
commit c92ae834de
4 changed files with 123 additions and 31 deletions

View File

@ -31,6 +31,7 @@ use App\Models\InsurerStatements;
use App\Models\InvPaymentDetailsModel;
use App\Models\BatchFileModel;
use App\Models\FileModel;
use App\Models\COShareStmtDetailsModel;
use Kint;
class PolicyTransactionController extends BaseController
@ -62,6 +63,7 @@ class PolicyTransactionController extends BaseController
protected $invPaymentDetailsModel;
protected $batchFileModel;
protected $filesModel;
protected $coShareStmtDetailsModel;
public function __construct()
{
@ -91,11 +93,12 @@ class PolicyTransactionController extends BaseController
$this->invPaymentDetailsModel = new InvPaymentDetailsModel();
$this->batchFileModel = new BatchFileModel();
$this->filesModel = new FileModel();
$this->coShareStmtDetailsModel = new COShareStmtDetailsModel();
$this->invoiceStatus = [
'pending' => 'Pending',
'generated' => 'Generated',
'sent' => 'Sent',
'payment_received' => 'Payment Received',
'payment_received' => 'Payment<br> Received',
];
}
@ -1631,20 +1634,17 @@ class PolicyTransactionController extends BaseController
$end_date = $this->request->getGet('end_date');
$client_id = $this->request->getGet('client_id');
$insurer_id = $this->request->getGet('insurer_id');
$policy_type_id = $this->request->getGet('policy_type_id');
$date_type = $this->request->getGet('date_type');
$issuer = $this->request->getGet('issuer');
$insurer_branch_id = $this->request->getGet('insurer_branch_id');
$start_date = (!isset($start_date) || $start_date === '' || $start_date === null) ? 0 : change_date_format($start_date,'d-m-Y','Y-m-01');
$end_date = (!isset($end_date) || $end_date === '' || $end_date === null) ? 0 : change_date_format($end_date,'d-m-Y','Y-m-31');
// dd([$start_date,$end_date]);
$start_date = (!isset($start_date) || $start_date === '' || $start_date === null) ? 0 : $start_date;
$end_date = (!isset($end_date) || $end_date === '' || $end_date === null) ? 0 : $end_date;
$client_id = (!isset($client_id) || $client_id === '' || $client_id === null) ? 0 : $client_id;
$insurer_id = (!isset($insurer_id) || $insurer_id === '' || $insurer_id === null) ? 0 : $insurer_id;
$policy_type_id = (!isset($policy_type_id) || $policy_type_id === '' || $policy_type_id === null) ? 0 : $policy_type_id;
$date_type = (!isset($date_type) || $date_type === '' || $date_type === null) ? 0 : $date_type;
$issuer = (!isset($issuer) || $issuer === '' || $issuer === null) ? 0 : $issuer;
$insurer_branch_id = (!isset($insurer_branch_id) || $insurer_branch_id === '' || $insurer_branch_id === null) ? 0 : $insurer_branch_id;
$data['outstanting_list'] = $this->policyTransactionModel->getOutstandingReportLIst($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer);
$data['outstanting_list'] = $this->policyTransactionModel->getOutstandingReportLIst($start_date, $end_date,$insurer_id, $insurer_branch_id);
// dd($this->policyTransactionModel->getLastQuery());
// dd($data);
$this->loadLayout('outstanding_report_list', $data);
@ -1676,7 +1676,7 @@ class PolicyTransactionController extends BaseController
WHERE pt_co_share_details.is_active = 1
AND pt_co_share_details.statement_id = insurer_statements.id
) AS exp_inv_amt,
(SELECT SUM(inv_payment_details.inv_amt) + SUM(inv_payment_details.tds)
(SELECT SUM(inv_payment_details.inv_amt) + SUM(inv_payment_details.tds) + SUM(inv_payment_details.gst)
FROM inv_payment_details
WHERE inv_payment_details.is_active = 1
AND inv_payment_details.statement_id = insurer_statements.id
@ -1749,9 +1749,10 @@ class PolicyTransactionController extends BaseController
$month = $month.'-01';
// print_r($month);die;
$month = change_date_format($month,'Y-M-d','Y-m-d');
$stmt_sno = $this->request->getPost('statement_no');
// print_r($month);die;
$file_id = $this->insurerStatements->insert(['insurer_id' => $insurer_id, 'branch_id' => $branch_id, 'file_name' => $filename,'month' => $month, 'created_by' => $loggedInUserID]); //here field policy_id have client_policy_id and not policy id from policy master
$file_id = $this->insurerStatements->insert(['insurer_id' => $insurer_id, 'branch_id' => $branch_id, 'file_name' => $filename,'month' => $month, 'created_by' => $loggedInUserID,'stmt_sno' => $stmt_sno]); //here field policy_id have client_policy_id and not policy id from policy master
$this->myLogger->logme("error", '{file_id} statement uploaded success', ['file_id' => $file_id]);
//validate file
@ -1839,7 +1840,7 @@ class PolicyTransactionController extends BaseController
unset($excel_data[0]);
// Kint::dump($excel_data);
//get no of line items and update in DB
$line_items = count($excel_data);
$line_items = 0;
// get uploaded month transactions data
$source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']);
// var_dump($source_data);die();
@ -1866,6 +1867,7 @@ class PolicyTransactionController extends BaseController
if( ($policy_no == $source_row['policy_no']) && $endorsement_no == $source_endorsement_no && change_date_format($policy_start_date,'d-m-Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($policy_end_date,'d-m-Y','Y-m-d') == $source_row['policy_end_date'] && $client_name == $source_row['client_name'])
{
$is_source_found = 1;
$line_items = $line_items + 1;
unset($source_data[$source_key]);
continue 2;
}
@ -2034,7 +2036,7 @@ class PolicyTransactionController extends BaseController
//find variance
$variance_amt = $source_row['exp_amt'] - $total_amt;
$data_to_update[] = ['id' => $source_row['id'],'actual_bp_amt' => $actual_bp_amt,'actual_tp_amt' => $actual_tp_amt,'actual_tep_amt' => $actual_tep_amt,'actual_bp_per' => $actual_bp_per,'actual_tp_per' => $actual_tp_per,'actual_tep_per' => $actual_tep_per,'variance' => $variance_amt,'actual_tep_brokerage_amt' => $actual_tep_brokerage,'actual_tp_brokerage_amt' => $actual_tp_brokerage,'actual_bp_brokerage_amt' => $actual_bp_brokerage,'reward' => trim($excel_row[15]),'statement_id' => $file_id];
$data_to_update[] = ['co_share_id' => $source_row['id'],'actual_bp_amt' => $actual_bp_amt,'actual_tp_amt' => $actual_tp_amt,'actual_tep_amt' => $actual_tep_amt,'actual_bp_per' => $actual_bp_per,'actual_tp_per' => $actual_tp_per,'actual_tep_per' => $actual_tep_per,'variance' => $variance_amt,'actual_tep_brokerage_amt' => $actual_tep_brokerage,'actual_tp_brokerage_amt' => $actual_tp_brokerage,'actual_bp_brokerage_amt' => $actual_bp_brokerage,'reward' => trim($excel_row[15]),'statement_id' => $file_id];
unset($source_data[$source_key]);
continue 2;
@ -2044,7 +2046,7 @@ class PolicyTransactionController extends BaseController
}
}
// dd($data_to_update);
$this->PTCOShareDetailsModel->updateBatch($data_to_update, 'id');
$this->coShareStmtDetailsModel->insertBatch($data_to_update, 'id');
// dd($data_to_update);
// if($error_data['error_code'])
// {
@ -2066,8 +2068,24 @@ class PolicyTransactionController extends BaseController
->where('is_active',1)
->get()
->getResultArray();
if(!$inv_details['invoice_value'])
{
$stmt_level_value = $this->coShareStmtDetailsModel->select('sum(actual_tep_brokerage_amt) + sum(actual_tp_brokerage_amt) + sum(actual_bp_brokerage_amt) + sum(reward) as invoice_value')
->where('statement_id',$statement_id)
->groupBy('statement_id')
->get()
->getResultArray();
// print_r($stmt_level_value);
if($stmt_level_value && count($stmt_level_value) && isset($stmt_level_value[0]))
{
$inv_details['invoice_value'] = $stmt_level_value[0]['invoice_value'];
}
}
// ~dd($inv_details);
$data = [ 'invoice_status' => $inv_details['invoice_status'],
'gst_per' => isset($inv_details['gst_per']) ? $inv_details['gst_per'] : 18 ,
'invoice_value' => $inv_details['invoice_value'],
'gst_value' => $inv_details['gst_value'],
'invoice_no' => $inv_details['invoice_no'],
'invoice_amount' => $inv_details['invoice_amount'],
'invoice_date' => isset($inv_details['invoice_date']) ? change_date_format($inv_details['invoice_date'],'Y-m-d','d/m/Y') : null ];
@ -2089,6 +2107,9 @@ class PolicyTransactionController extends BaseController
$invoiceNo = $jsonData['invoice_no'];
$invoiceDate = change_date_format($jsonData['invoice_date'],'d/m/Y','Y-m-d');
$invoice_amount = $jsonData['invoice_amount'];
$invoice_value = $jsonData['invoice_value'];
$gst_per = $jsonData['invoice_gst_per'];
$gst_value = $jsonData['invoice_gst'];
//Update statement table
$parentData = [
@ -2096,6 +2117,9 @@ class PolicyTransactionController extends BaseController
'invoice_no' => $invoiceNo,
'invoice_date' => $invoiceDate,
'invoice_amount' => $invoice_amount,
'gst_per' => $gst_per,
'gst_value' => $gst_value,
'invoice_value' => $invoice_value,
'updated_by' => get_session_userid()
];
@ -2107,6 +2131,7 @@ class PolicyTransactionController extends BaseController
$receivedAmounts = $jsonData['received_amount'];
$utrNos = $jsonData['utr_no'];
$tdsTotal = $jsonData['tds'];
$gstTotal = $jsonData['gst_amount'];
$paymentDates = $jsonData['payment_date'];
$pks = $jsonData['pk'];
@ -2114,6 +2139,7 @@ class PolicyTransactionController extends BaseController
$pk = $pks[$index]; // Get the pk for the current record
$utrNo = $utrNos[$index];
$tds = $tdsTotal[$index];
$gst = $gstTotal[$index];
$paymentDate = $paymentDates[$index];
// Prepare data for insert/update
@ -2121,6 +2147,7 @@ class PolicyTransactionController extends BaseController
'inv_amt' => $receivedAmount,
'utr_no' => $utrNo,
'tds' => $tds,
'gst' => $gst,
'received_date' => change_date_format($paymentDate,'d/m/Y','Y-m-d'),
'statement_id' => $hiddenStatementId
];
@ -2357,6 +2384,45 @@ class PolicyTransactionController extends BaseController
return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found for this CD'], 200);
}
public function getInsurerStatementMonth()
{
$insurer_id = $this->request->getGet('insurer_id');
$month = $this->request->getGet('month');
// echo $month;
$insurer_branch_id = explode('-',$insurer_id)[1];
$insurer_id = explode('-',$insurer_id)[0];
$month = $month.'-01';
$month = change_date_format($month,'Y-M-d','Y-m-d');
// echo $month;
$res_data = $this->insurerStatements
->where('insurer_id',$insurer_id)
->where('branch_id',$insurer_branch_id)
->where('month', $month)
->where('is_active', 1)
->where('file_status', 'success')
->findAll();
return $this->respond(['dataStatus' => true, 'code' => 200,'data' => $res_data], 200);
}
public function deleteStatement($id)
{
// echo $id;die();
$this->coShareStmtDetailsModel->where('statement_id',$id)
->set(['is_active' => 0])
->update();
$this->invPaymentDetailsModel->where('statement_id',$id)
->set(['is_active' => 0])
->update();
$this->insurerStatements->where('id',$id)
->set(['is_active' => 0])
->update();
return $this->respond(['dataStatus' => true, 'code' => 200], 200);
}
}

View File

@ -399,6 +399,7 @@ class PolicyTransactionModel extends Model
WHERE
co_share_stmt_details.co_share_id = pt_co_share_details.id
AND co_share_stmt_details.is_active = 1
AND insurer_statements.is_active = 1
$date_condition
),
2
@ -465,7 +466,7 @@ class PolicyTransactionModel extends Model
AND co_share_stmt_details.is_active = 1
AND pt_table.is_active = 1
AND insurer_statements.is_active = 1
AND insurer_statements.invoice_no IS NOT NULL
AND insurer_statements.invoice_no IS NULL
$date_condition
)
),

View File

@ -441,6 +441,7 @@ table.dataTable tbody td {
switchRequired('received_amount',false,'name');
switchRequired('tds',false,'name');
switchRequired('gst_amount',false,'name');
switchRequired('utr_no',false,'name');
switchRequired('payment_date',false,'name');
switchRequired('pk',false,'name');
@ -458,6 +459,7 @@ table.dataTable tbody td {
switchRequired('received_amount',true,'name');
switchRequired('utr_no',true,'name');
switchRequired('tds',true,'name');
switchRequired('gst_amount',true,'name');
switchRequired('payment_date',true,'name');
switchRequired('pk',true,'name');
}else if(invoiceStatus === 'pending')
@ -476,8 +478,11 @@ table.dataTable tbody td {
switchRequired('payment_date',false,'name');
switchRequired('pk',false,'name');
switchRequired('tds',false,'name');
switchRequired('gst_amount',false,'name');
}
calcGSTValue();
});
@ -704,6 +709,11 @@ function showInvoiceStatusModal(event)
document.getElementById('invoice_value_modal').value = response.data.invoice_value;
document.getElementById('gst_per_modal').value = response.data.gst_per;
document.getElementById('gst_value_modal').value = response.data.gst_value;
console.log('response.data.gst_value - ' + response.data.gst_value);
if(response.data.gst_value == 0 || response.data.gst_value == '' || response.data.gst_value == null)
{
calcGSTValue();
}
if (!$('#invoice_date_modal').val()) {
// alert('nope');
@ -1051,20 +1061,34 @@ function getStatementNo()
function calcGSTValue()
{
// alert('calcGSTValue');
var gst_per = document.getElementById('gst_per_modal').value;
var invoice_value_dom_obj = document.getElementById('invoice_value_modal');
var invoice_value = invoice_value_dom_obj.value;
var gst_value_dom_obj = document.getElementById('gst_value_modal');
var gst_value = gst_value_dom_obj.value;
var invoice_amount_dom_obj = document.getElementById('invoice_amount_no_modal');
// var invoice_amount = invoice_amount_dom_obj.value();
console.log('calcGSTValue called');
var inv_status_element = document.getElementById('invoice_status');
gst_value_dom_obj.value = (parseFloat(gst_per) / 100 ) * invoice_value;
invoice_amount_dom_obj.value = parseFloat(invoice_value_dom_obj.value) + parseFloat(gst_value_dom_obj.value);
checkInvAmont();
if(inv_status_element.value == 'generated' || inv_status_element.value == 'send' || inv_status_element.value == 'payment_received')
{
var gst_per = document.getElementById('gst_per_modal').value;
console.log('gst_per - ' + gst_per);
var invoice_value_dom_obj = document.getElementById('invoice_value_modal');
var invoice_value = invoice_value_dom_obj.value;
console.log('invoice_value - ' + invoice_value);
var gst_value_dom_obj = document.getElementById('gst_value_modal');
var gst_value = gst_value_dom_obj.value;
console.log('gst_value - ' + gst_value);
var invoice_amount_dom_obj = document.getElementById('invoice_amount_no_modal');
// var invoice_amount = invoice_amount_dom_obj.value();
gst_value_dom_obj.value = Math.round((parseFloat(gst_per) / 100 ) * invoice_value);
// gst_value_dom_obj.value = ((parseFloat(gst_per) / 100 ) * invoice_value);
invoice_amount_dom_obj.value = parseFloat(invoice_value_dom_obj.value) + parseFloat(gst_value_dom_obj.value);
if(inv_status_element.value == 'payment_received')
{
checkInvAmont();
}
}
}

View File

@ -99,7 +99,8 @@ table.dataTable tbody td {
<td class="right-align-input"><?php echo $row['agreed_tp_or_ter_per'];?>&nbsp;%</td>
<td class="right-align-input" onclick="showCoShareStatementDetails(this)" data-id="<?= $row['pt_id'] ?>"><?php echo empty($row['total_irda_amt']) ? $row['exp_amt'] : $row['total_irda_amt']; ?></td>
<td class="right-align-input"><?php echo empty($row['billed_amt']) ? '0.00' : $row['billed_amt'] ?></td>
<td class="right-align-input"><?php echo empty($row['unbilled_amt']) ? '0.00' : $row['unbilled_amt']?></td>
<!-- <td class="right-align-input"><?php echo empty($row['unbilled_amt']) ? '0.00' : $row['unbilled_amt']?></td> -->
<td class="right-align-input"><?php echo number_format((float)$row['total_irda_amt'] - $row['billed_amt'],2, '.', '')?></td>
<td class="right-align-input"><?php echo $row['reward']; ?></td>
</tr>
<?php } ?>