CHANGE_bds_issue-final-fix-6 - VADIVEL J 2025-10-31 16:27

This commit is contained in:
vadivelJ96 2025-10-31 18:28:36 +05:30
parent 036adda88a
commit 21aa53cf2a
2 changed files with 1170 additions and 616 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,660 @@
<style>
.table th,
.table td {
padding: 8px;
}
table.dataTable tbody td {
padding: 4px 4px !important;
}
.col-12 {
max-width: 98% !important;
}
.dataTables_filter {
position: absolute;
}
.right-align-input {
text-align: right;
}
.badge-container {
background: #F0F0F0;
padding: 6px 12px;
border-radius: 6px;
font-size: 14px;
display: inline-block;
}
#totals {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
</style>
<div class="col-12" id="second_page">
<div class="card">
<div class="card-body">
<div class="row" style="padding-bottom: 10px;">
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">BDS Report <span id="bds_title"></span></h4>
</div>
</div>
<div class="table-responsive">
<div id="totals" class="d-flex flex-wrap gap-2 mb-2">
<div class="badge-container">
Total Premium: <span class="text-primary" id="total_premium">0.00</span>
</div>
<div class="badge-container">
Total Rewards: <span class="text-primary" id="total_rewards">0.00</span>
</div>
<div class="badge-container">
Total IRDA Revenue INR: <span class="text-primary" id="total_irda">0.00</span>
</div>
<div class="badge-container">
Total Billed Amount: <span class="text-primary" id="total_billed">0.00</span>
</div>
<div class="badge-container">
Total Unbilled Amount: <span class="text-primary" id="total_unbilled">0.00</span>
</div>
<div class="badge-container">
Total Policy Count: <span class="text-primary"><?= $policy_count ?></span>
</div>
</div>
<table data-custom-table-css="table" id="scroll-horizontal-datatable" class="table w-100 nowrap">
<thead class="bg-light">
<tr>
<th>S. No</th>
<th>User</th>
<th>Month</th>
<th style="display: none;">statement upload</th>
<!-- <th style="display: none;">Business Type</th> -->
<th style="display: none;">Client Type</th>
<th>Insured Name</th>
<th>Policy/<br>Endorsement</th>
<th>Policy Type</th>
<th style="display: none;">BAP Group</th>
<th style="display: none;">Vehicle Number</th>
<th>Policy No</th>
<th>Endorsement No</th>
<!-- <th style="display: none;">Insurer Name</th> -->
<th>Insurer Branch</th>
<!-- <th style="display: none;">TPA</th> -->
<th style="display: none;">Endorsement <br> Effective Date</th>
<th style="display: none;">Policy <br> Effective Date</th>
<th style="display: none;">Policy <br> Expiry Date</th>
<th style="display: none;">Reference</th>
<th style="display: none;">Remarks</th>
<th>BP Premium</th>
<th>TP/Ter Premium</th>
<th style="display: none;">Premium <br> (without GST)</th>
<!-- <th style="display: none;">GST @ 18%</th> -->
<th>Total Premium</th>
<th>BP %</th>
<th>TP/Ter %</th>
<th>Rewards</th>
<th>Agreed Amount</th>
<th>Invoiced Amount</th>
<th>Outstanding Amount</th>
</tr>
</thead>
<tbody>
<?php if (isset($report_list)) {
// empty array to initialize for policies per insurer per month
$uniquePoliciesReport = [];
// irrespective of months or multiple months
$uniqueAgreedAmountList = [];
?>
<?php
foreach($report_list as $index => $row){
$policy_no = $row['policy_no'];
$policy_updated_month = $row['policy_issue_month'];
$policy_type = $row['policy_type'];
$statement_status = $row['statement_uploaded'];
$client_name = $row['client_name'];
$insurer_branch_name = $row['insurer_branch_name'];
$uniqueRecord = "$policy_no-$policy_updated_month-$policy_type-$client_name-$insurer_branch_name-$statement_status" ;
// irrespective of months or multiple months
$uniqueAgreedAmountPerInsurer = "$policy_no-$policy_type-$client_name-$insurer_branch_name" ;
$pastMonth = explode("-",$uniqueRecord )[1] ;
$currentMonth = $policy_updated_month ;
$pastStatementStatus = explode("-",$uniqueRecord )[5] ;
$currentStatementStatus = $statement_status;
if(
isset($uniquePoliciesReport[$uniqueRecord])
&& $pastStatementStatus == $currentStatementStatus
){
continue ;
}
else if(
isset($uniquePoliciesReport[$uniqueRecord])
&& $pastStatementStatus == $currentStatementStatus
){
continue;
}else{
if(isset($uniqueAgreedAmountList[$uniqueAgreedAmountPerInsurer]) ){
$uniqueAgreedAmountList[$uniqueAgreedAmountPerInsurer] -= $row['billed_amt'];
$row['total_irda_amt'] = $pastMonth == $currentMonth ? $row['total_irda_amt'] : 0 ;
$row['outstanding_amt'] = $uniqueAgreedAmountList[$uniqueAgreedAmountPerInsurer];
$row['multiple_months'] = $pastMonth == $currentMonth ? false : true ;
}
else{
$row['outstanding_amt'] = $row['total_irda_amt'] - $row['billed_amt'];
$uniqueAgreedAmountList[$uniqueAgreedAmountPerInsurer] = $row['total_irda_amt'] ;
$row['multiple_months'] = false;
}
$uniquePoliciesReport[$uniqueRecord] = $row;
}
}
$report_list = array_values($uniquePoliciesReport);
?>
<?php foreach($report_list as $index => $row){
?>
<tr>
<td><?= $index + 1 ?> &nbsp; <a href="<?php
if($row['action_type'] == "inception"){
echo base_url('policy_tranction/inception/list') . '?pt_id=' . $row['id'] ;
}else{
echo base_url('policy_tranction/endorsement/list') . '?pt_id=' . $row['id'] ;
}
?>" class="mdi mdi-pencil" ></a> </td>
<td ><?php echo $row['statement_uploaded'] == 'statement uploaded' && $row['multiple_months'] == true ? 'rewards': $row['user_name']??'N/A' ; ?></td>
<td><?php echo $row['policy_issue_month'] ?: 'N/A'; ?></td>
<td style="display: none;"><?php echo $row['statement_uploaded'] ?: 'N/A'; ?></td>
<!-- <td style="display: none;"><?php echo $row['revenue_type'] ?: 'N/A'; ?></td> -->
<td style="display: none;"><?php echo $row['client_type'] ?: 'N/A'; ?></td>
<td><?php echo $row['client_name'] ?: 'N/A'; ?></td>
<td><?php echo $row['action_type'] ?: 'N/A'; ?></td>
<td><?php echo $row['policy_type'] ?: 'N/A'; ?></td>
<td style="display: none;"><?php echo $row['bap'] ?: 'N/A'; ?></td>
<td style="display: none;"><?php echo $row['vehicle_no'] ?: 'N/A'; ?></td>
<td><?php echo $row['policy_no'] ?: 'N/A'; ?></td>
<td><?php echo $row['endorsement_no'] ?: 'N/A'; ?></td>
<!-- <td style="display: none;"><?php echo $row['insurer_name'] ?: 'N/A'; ?> </td> -->
<td><?php echo $row['insurer_branch_name'] ?: 'N/A'; ?></td>
<!-- <td style="display: none;"><?php echo $row['tpa_name']; ?></td> -->
<td style="display: none;"><?php echo empty($row['endorse_eff_date']) ? 'N/A' : date('d/m/Y', strtotime($row['endorse_eff_date'])) ?></td>
<td style="display: none;"><?php echo empty($row['policy_start_date']) ? 'N/A' : date('d/m/Y', strtotime($row['policy_start_date'])); ?></td>
<td style="display: none;"><?php echo empty($row['policy_end_date']) ? 'N/A' : date('d/m/Y', strtotime($row['policy_end_date'])); ?></td>
<td style="display: none;"><?php echo $row['ref'] ?: 'N/A'; ?></td>
<td style="display: none;"><?php echo $row['remarks'] ?: 'N/A'; ?></td>
<td class="right-align-input"><?php echo $row['bp_amt']; ?></td>
<td class="right-align-input"><?php echo $row['tp_or_ter']; ?></td>
<td class="right-align-input" style="display: none;"><?php echo $row['premium_wo_gst']; ?></td>
<!-- <td class="right-align-input" style="display: none;"><?php echo $row['gst_amount']; ?></td> -->
<td class="right-align-input"><?php echo $row['total_premium']; ?></td>
<td class="right-align-input"><?php echo $row['agreed_bp_per']; ?>&nbsp;%</td>
<td class="right-align-input"><?php echo $row['agreed_tp_or_ter_per'];?>&nbsp;%</td>
<td class="right-align-input" ><?php echo isset($row['reward']) ? $row['reward'] : '0.00'; ?></td>
<!-- Agreed Amount as total_irda_amt -->
<td class="right-align-input" onclick="showCoShareStatementDetails(this)" data-id="<?= $row['pt_id'] ?>"><?php echo $row['total_irda_amt']; ?></td>
<!-- invoiced amount as billed_amt -->
<td class="right-align-input"><?php echo empty($row['billed_amt']) ? '0.00' : $row['billed_amt'] ?></td>
<!-- Outstanding Amount (Agreed amount - invoice amount) -->
<td class="right-align-input"><?php echo number_format((float)$row['outstanding_amt'],2, '.', '')?></td>
</tr>
<?php } ?>
<?php } ?>
</tbody>
</table>
<div>
</div>
</div>
</div><!-- end col -->
</div>
</div>
<!-- modal content -->
<div class="modal fade" id="centermodal" tabindex="-1" role="dialog" aria-hidden="true" aria-modal="true" data-backdrop="static">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header" style="background-color: gainsboro;">
<h4 class="modal-title" id="myCenterModalLabel">Statement Details <span id="heading"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body" id="modal_body">
<div class="table-responsive">
<table data-custom-table-css="table" class="table table-hover mb-0">
<thead class="bg-light" id="table_head_data">
<tr>
<th>Statement No.</th>
<th>Statement Month</th>
<th>Actual Amount</th>
<th>Invoice No.</th>
<th>Invoice Date.</th>
<th>Invoice Status.</th>
</tr>
</thead>
<tbody id="table_data">
</tbody>
</table>
</div> <!-- end table-responsive-->
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-------------------------------------------------------------------------------------------------->
<script>
// Datatable document ready
$(document).ready(function() {
var ticketsTable = $('#scroll-horizontal-datatable');
if (ticketsTable.length) {
ticketsTable.DataTable({
scrollX: true,
dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'B>>" + // Filter left, buttons right
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>", // Pagination at the bottom, without page length selector
// buttons: [
// {
// extend: 'csv',
// text: 'CSV',
// title: 'Policy-Tranction-BDS-List',
// },
// {
// extend: 'excel',
// text: 'Excel',
// title: 'Policy-Tranction-BDS-List',
// customize: function(xlsx) {
// var sheet = xlsx.xl.worksheets['sheet1.xml'];
// var total = 0;
// // 🔹 Force column K (11) and L (12) as string
// $('row c[r^="K"], row c[r^="L"]', sheet).attr('t', 'inlineStr');
// // Find cells in column AB (28th column in Excel)
// $('row c[r^="AB"]', sheet).each(function() {
// var value = parseFloat($('v', this).text()); // Get the value inside the cell
// if (!isNaN(value)) {
// total += value;
// }
// });
// // Get the last row index and append the total row
// var lastRow = $('row:last', sheet);
// var rowIndex = parseInt(lastRow.attr('r')) + 2; // Find the next row index
// var totalRow = '<row r="' + rowIndex + '">' +
// '<c t="inlineStr" r="AA' + rowIndex + '"><is><t>Total</t></is></c>' + // Insert "Total" in AA
// '<c t="n" r="AB' + rowIndex + '"><v>' + total.toFixed(2) + '</v></c>' + // Insert sum in AB
// '</row>';
// // Append the new total row to the sheet
// $(sheet).find('sheetData').append(totalRow);
// },
// exportOptions: {
// orthogonal: 'sort'
// },
// customizeData: function (data) {
// for (var i = 0; i < data.body.length; i++) {
// for (var j = 0; j < data.body[i].length; j++) {
// // Check if the column is the 9th index (10th column) and 10th index (11th column)
// if (j === 9 || j === 10) {
// data.body[i][j] = '\u200C' + data.body[i][j];
// }
// }
// }
// }
// }
// ],
buttons: [
{
extend: 'collection',
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
className: 'btn app-btn-secondary ',
buttons: [
{
extend: 'csv',
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
title: 'Policy-Tranction-BDS-List',
exportOptions: {
columns: ':visible', // or specify exact columns [0,1,2,...]
format: {
body: function (data, row, column, node) {
// Force K and L columns to string
if (column === 10 || column === 11) {
// Option 1: prepend single quote
return '\u200C' + data;
// Option 2: use Excel formula trick
// return '="' + data + '"';
}
return data;
}
}
},
},
{
extend: 'excel',
title: 'Policy-Tranction-BDS-List',
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
className: 'app-btn-primary ',
// customize: function (xlsx) {
// var sheet = xlsx.xl.worksheets['sheet1.xml'];
// var total = 0;
// // 🔹 Force column K (11) and L (12) as string
// // $('row c[r^="K"], row c[r^="L"]', sheet).attr('t', 'inlineStr');
// // 🔹 Convert column K (11th) & L (12th) to inline string
// $('row c[r^="K"], row c[r^="L"]', sheet).each(function () {
// var cell = $(this);
// console.log(cell);
// var val = cell.find('v').text(); // get value
// if (val) {
// cell.attr('t', 'inlineStr'); // mark as text
// cell.remove('v'); // remove <v>
// cell.append('<is><t>' + val + '</t></is>'); // replace with inline string
// }
// });
// // Calculate total in AB (28th column)
// $('row c[r^="AB"]', sheet).each(function () {
// var value = parseFloat($('v', this).text());
// if (!isNaN(value)) {
// total += value;
// }
// });
// // Append total row
// var lastRow = $('row:last', sheet);
// var rowIndex = parseInt(lastRow.attr('r')) + 2;
// var totalRow = '<row r="' + rowIndex + '">' +
// '<c t="inlineStr" r="AA' + rowIndex + '"><is><t>Total</t></is></c>' +
// '<c t="n" r="AB' + rowIndex + '"><v>' + total.toFixed(2) + '</v></c>' +
// '</row>';
// $(sheet).find('sheetData').append(totalRow);
// },
customize: function (xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
var total = 0;
function forceAsText(cell) {
var val = cell.find('v').text();
if (val) {
// Remove old <v>
cell.find('v').remove();
// Force as inline string
cell.attr('t', 'inlineStr');
cell.append('<is><t>' + val + '</t></is>');
}
}
function forceAsTextPreserveOriginal(cell) {
// Get the original cell value from the cell's text content
var vElement = cell.find('v');
if (vElement.length > 0) {
var originalValue = vElement.text();
// Remove the <v> element
vElement.remove();
// Set cell type to inline string and preserve the original value
cell.attr('t', 'inlineStr');
cell.append('<is><t>' + originalValue + '</t></is>');
}
}
// 🔹 Force K column as text (working correctly)
$('row c[r^="K"]', sheet).each(function () {
forceAsText($(this));
});
// 🔹 Force L column as text with better preservation
$('row c[r^="L"]', sheet).each(function () {
forceAsTextPreserveOriginal($(this));
});
// 🔹 Calculate total in AB (28th column)
$('row c[r^="AB"] v', sheet).each(function () {
var value = parseFloat($(this).text());
if (!isNaN(value)) total += value;
});
// 🔹 Append total row
var lastRow = $('row:last', sheet);
var rowIndex = parseInt(lastRow.attr('r')) + 2;
var totalRow = '<row r="' + rowIndex + '">' +
'<c t="inlineStr" r="AA' + rowIndex + '"><is><t>Total</t></is></c>' +
'<c t="n" r="AB' + rowIndex + '"><v>' + total.toFixed(2) + '</v></c>' +
'</row>';
$(sheet).find('sheetData').append(totalRow);
},
exportOptions: {
orthogonal: 'sort' ,
columns: ':not(:eq(3))' // skip the same 4th column
},
customizeData: function (data) {
for (var i = 0; i < data.body.length; i++) {
for (var j = 0; j < data.body[i].length; j++) {
// Force 10th (index 9) & 11th (index 10) as text
if (j === 9 || j === 10 || j === 11 || j === 12 ) {
data.body[i][j] = '\u200C' + data.body[i][j];
}
}
}
}
}
]
}
],
language: {
search: `
<div class="datatable-search-wrapper">
_INPUT_
<i class="mdi mdi-magnify datatable-search-icon"></i>
</div>`,
searchPlaceholder: "Search"
},
paging: true, // Enable pagination
pageLength: 10, // Set default number of rows per page (optional)
ordering: false,
// "footerCallback": function(row, data, start, end, display) {
// var api = this.api();
// // Calculate column totals
// var totalPremium = api.column(23).data().reduce(function(a, b) {
// return parseFloat(a) + parseFloat(b) || 0;
// }, 0);
// var total_rewards = api.column(26).data().reduce(function(a, b) {
// return parseFloat(a) + parseFloat(b) || 0;
// }, 0); // Add initial value 0 here
// console.log('total_rewards - ' + total_rewards);
// var totalIrda = api.column(27).data().reduce(function(a, b) {
// return parseFloat(a) + parseFloat(b) || 0;
// }, 0);
// var totalBilled = api.column(28).data().reduce(function(a, b) {
// return parseFloat(a) + parseFloat(b) || 0;
// }, 0);
// var totalUnbilled = api.column(29).data().reduce(function(a, b) {
// return parseFloat(a) + parseFloat(b) || 0;
// }, 0);
// // Update the totals in the div above the table
// $('#total_premium').text(totalPremium.toFixed(2));
// $('#total_rewards').text(total_rewards.toFixed(2));
// $('#total_irda').text(totalIrda.toFixed(2));
// $('#total_billed').text(totalBilled.toFixed(2));
// $('#total_unbilled').text(totalUnbilled.toFixed(2));
// }
"footerCallback": function(row, data, start, end, display) {
var api = this.api();
// Calculate column totals (adjust indices based on VISIBLE columns)
var totalPremium = api.column(20, {search: 'applied'}).data().reduce(function(a, b) {
return parseFloat(a) + parseFloat(b || 0);
}, 0);
var total_rewards = api.column(23, {search: 'applied'}).data().reduce(function(a, b) {
return parseFloat(a) + parseFloat(b || 0);
}, 0);
var totalIrda = api.column(24, {search: 'applied'}).data().reduce(function(a, b) {
return parseFloat(a) + parseFloat(b || 0);
}, 0);
var totalBilled = api.column(25, {search: 'applied'}).data().reduce(function(a, b) {
return parseFloat(a) + parseFloat(b || 0);
}, 0);
var totalUnbilled = api.column(26, {search: 'applied'}).data().reduce(function(a, b) {
return parseFloat(a) + parseFloat(b || 0);
}, 0);
// Update the totals
$('#total_premium').text(totalPremium.toFixed(2));
$('#total_rewards').text(total_rewards.toFixed(2));
$('#total_irda').text(totalIrda.toFixed(2));
$('#total_billed').text(totalBilled.toFixed(2));
$('#total_unbilled').text(totalUnbilled.toFixed(2));
}
});
} else {
console.error("Table atet found.");
}
});
// ----------------------------------------------------------------------------------------------------
function showCoShareStatementDetails(input){
let pt_id = $(input).data('id');
console.log('pt_id', pt_id)
var myModal = new bootstrap.Modal(document.getElementById('centermodal'));
myModal.show();
getCoShareStatementDetails(pt_id)
}
function getCoShareStatementDetails(pt_id){
let url = '<?= base_url('util/getCoShareStatementDetails/') ?>' + pt_id;
sendAjaxRequestForGlobal(url, 'GET', {}, function(response) {
console.log('Data fetched successfully:', response);
if (response.status === true) {
appendTableData(response.data)
} else {
toastr.warning(response.message, 'WARNING');
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
});
}
function appendTableData(data) {
// Ensure the table body selector matches your table's structure
let tableBody = $("#table_data");
// Clear the table body before appending new rows
tableBody.empty();
// Loop through the data and append rows
data.forEach(row => {
let tableRow = `
<tr>
<td>${row.stmt_sno ?? '-'}</td>
<td>${row.month ?? '-'}</td>
<td>${row.sum_of_actual_amt ?? '-'}</td>
<td>${row.invoice_no ?? '-'}</td>
<td>${row.invoice_date ?? '-'}</td>
<td>${row.invoice_status ?? '-'}</td>
</tr>
`;
tableBody.append(tableRow);
});
}
</script>