nhance/app/Views/report_bds.php
2026-07-09 17:37:45 +05:30

664 lines
28 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<style>
#scroll-horizontal-datatable thead th,
#scroll-horizontal-datatable tbody td {
padding: 4px 4px !important;
box-sizing: border-box;
}
#scroll-horizontal-datatable_wrapper .dataTables_scrollHead table thead th,
#scroll-horizontal-datatable_wrapper .dataTables_scrollBody table tbody td {
padding: 4px 4px !important;
box-sizing: border-box;
}
.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;
}
.dataTables_length label {height: 21px !important;}
</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">
IRDA Amount : <span class="text-primary" id="total_irda">0.00</span>
</div>
<div class="badge-container">
Rewards: <span class="text-primary" id="total_rewards">0.00</span>
</div>
<div class="badge-container">
Revenue: <span class="text-primary" id="total_revenue">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 ?? 0 ?></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;">Business Type</th>
<th style="display: none;">Client Type</th>
<th>Insured Name</th>
<th style="text-align:center;">Transaction Type</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 Premium</th>
<th style="text-align:center;">Premium <br>(without GST)</th>
<!-- <th style="display: none;">GST @ 18%</th> -->
<th style="display: none;">Total Premium</th>
<th>Agreed BP %</th>
<th>Agreed TP %</th>
<th>Rewards</th>
<th>Agreed Amount</th>
<th>Invoiced Amount</th>
<th>Outstanding Amount</th>
<th style="display: none;">Salse Person</th>
<th style="display: none;">Service Person</th>
<th style="display: none;">Salse Person Branch</th>
<th style="display: none;">Installment</th>
<th style="display: none;">Data Received Date</th>
<th style="display: none;">Renewal Date</th>
<th style="display: none;">Co-Premium</th>
<th style="display: none;">Remuneration Pay By Leader</th>
<th style="display: none;">Salse Person Manager</th>
<th style="display: none;">Service Person Manager</th>
<th style="display: none;">Service Person Branch</th>
<th style="display: none;">Rollover Date</th>
<th style="display: none;">Policyholder Name</th>
<th style="display: none;">Insured (Same as Proposer)</th>
<th style="display: none;">Follower Policy No</th>
<th style="display: none;">Co-Share %</th>
<th style="display: none;">Non Commissional <br> Premium Amount</th>
<th style="display: none;">CGST</th>
<th style="display: none;">SGST</th>
<th style="display: none;">IGST</th>
<th style="display: none;">Stamp Duty</th>
<th style="display: none;">Standard BP %</th>
<th style="display: none;">Standard TP %</th>
<th style="display: none;">Actual BP Amount</th>
<th style="display: none;">Actual TP Amount</th>
<th style="display: none;">Actual BP %</th>
<th style="display: none;">Actual TP %</th>
<th style="display: none;">Actual BP Remuneration Amount</th>
<th style="display: none;">Actual TP Remuneration Amount</th>
<th style="display: none;">CD Account No</th>
</tr>
</thead>
<tbody>
</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>
var bdsReportFilters = <?= json_encode($bds_filters ?? []) ?>;
var bdsReportDataTableUrl = '<?= base_url('policy_tranction/report/list/datatable') ?>';
var bdsReportClearCacheUrl = '<?= base_url('policy_tranction/report/list/clear-cache') ?>';
function updateBdsReportTotals(totals) {
if (!totals) {
return;
}
$('#total_premium').text(totals.total_premium || '0.00');
$('#total_rewards').text(totals.total_rewards || '0.00');
$('#total_irda').text(totals.total_irda || '0.00');
$('#total_revenue').text(totals.total_revenue || '0.00');
$('#total_billed').text(totals.total_billed || '0.00');
$('#total_unbilled').text(totals.total_unbilled || '0.00');
}
// Export all filtered rows in server-side DataTable (not only current page).
function exportServerSideFilteredData(e, dt, button, config, buttonType) {
var self = this;
var oldStart = dt.page.info().start;
dt.one('preXhr', function (x, s, data) {
data.start = 0;
data.length = -1; // backend converts -1 to all filtered rows
});
dt.one('draw', function () {
$.fn.dataTable.ext.buttons[buttonType].action.call(self, e, dt, button, config);
dt.one('preXhr', function (x, s, data) {
data.start = oldStart;
data.length = dt.page.len();
});
// Restore the previous page after export.
setTimeout(function () {
dt.ajax.reload(null, false);
}, 0);
});
dt.ajax.reload();
}
function clearBdsCacheAndReloadTable(dt) {
$.ajax({
url: bdsReportClearCacheUrl,
type: 'POST',
success: function(response) {
if (response && response.status) {
bdsReportFilters.cache_version = new Date().getTime();
dt.ajax.reload(null, true);
toastr.success(response.message || 'Cache cleared and list reloaded.', 'Success');
} else {
toastr.warning((response && response.message) ? response.message : 'Unable to clear cache.', 'Warning');
}
},
error: function() {
toastr.error('Failed to clear cache.', 'Error');
}
});
}
// Datatable document ready
$(document).ready(function() {
var ticketsTable = $('#scroll-horizontal-datatable');
if (ticketsTable.length) {
nhanceListDataTableBeforeInit();
var nhBdsReportTable = ticketsTable.DataTable(nhanceMergeListDataTableOptions({
autoWidth: false,
processing: true,
serverSide: true,
deferRender: true,
searchDelay: 400,
columns: (function() {
var cols = [];
for (var i = 0; i < 58; i++) {
cols.push({ data: String(i), orderable: false });
}
return cols;
})(),
ajax: {
url: bdsReportDataTableUrl,
type: 'POST',
data: function(d) {
return $.extend({}, d, bdsReportFilters);
},
dataSrc: function(json) {
updateBdsReportTotals(json.totals);
return json.data;
}
},
columnDefs: [
{ targets: [18, 19, 20, 21, 22, 23, 24, 25, 26, 27], className: 'right-align-input' },
{
targets: [
3, 4, 8, 9, 13, 14, 15, 16, 17, 21,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57
],
visible: false
}
],
createdRow: function(row, data) {
if (data.DT_RowAttr) {
$(row).attr(data.DT_RowAttr);
}
},
// 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];
// }
// }
// }
// }
// }
// ],
dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'B>>" + // Filter left, buttons right
"<'row'<'col-sm-12'tr>>" +
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
buttons: [
{
text: '<i class="mdi mdi-refresh" ></i><span class=" btn-custom"> Reload </span>',
className: 'btn app-btn-secondary mr-2',
action: function(e, dt) {
clearBdsCacheAndReloadTable(dt);
}
},
{
text: '<i class="mdi mdi-filter" ></i><span class=" btn-custom"> Filter </span>',
className: 'btn app-btn-primary mr-2',
action: function(e, dt, node, config) {
openBDSFilterNav();
}
},
{
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',
action: function (e, dt, button, config) {
exportServerSideFilteredData.call(this, e, dt, button, config, 'csvHtml5');
},
exportOptions: {
modifier: {
search: 'applied',
page: 'all'
},
columns: function (idx, data, node) {
return true; // ✅ include all columns (even hidden)
},
format: {
body: function (data, row, column, node) {
data = data.replace(/&nbsp;/g, '').replace(/\s+/g, ' ').trim();
// If it's the first, 20th, 10th, or 11th column, clean the data
if (column === 0 || column === 20 || column === 10 || column === 11) {
// Remove all <a> tags and their contents first
data = data.replace(/<a[^>]*>.*?<\/a>/gi, '');
// Convert any HTML entities / remaining tags to plain text
// (jQuery used only for HTML decoding; you can replace with DOMParser if you prefer)
data = $('<div>').html(data).text();
// Normalize NBSP to space
data = data.replace(/\u00A0/g, ' ');
// Remove BOM, zero-width, and control characters
data = data.replace(/[\u0000-\u001F\u007F-\u009F\u200B-\u200F\uFEFF]/g, '').trim();
}
// Do NOT prepend \u200C. Return raw cleaned value.
// If you need to force Excel as string, use the formula trick or prepend a single apostrophe.
if (column === 10 || column === 11) {
// Option A: return as Excel formula to preserve formatting
// return '="' + data + '"';
// Option B: prepend apostrophe (visible in Excel formula bar, not in cell)
// return "'" + data;
return data;
}
return data;
}
}
},
},
{
extend: 'excel',
title: 'Policy-Tranction-BDS-List',
sheetName: 'Policy-Tranction-BDS-List',
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
className: 'app-btn-primary ',
action: function (e, dt, button, config) {
exportServerSideFilteredData.call(this, e, dt, button, config, 'excelHtml5');
},
// 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: {
modifier: {
search: 'applied',
page: 'all'
},
orthogonal: 'sort'
},
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" style="position:relative; display:inline-block;">
_INPUT_
<i class="mdi mdi-magnify datatable-search-icon"
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666;"></i>
<i class="mdi mdi-close-circle datatable-clear-icon"
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666; display:none;"></i>
</div>`,
searchPlaceholder: "Search",
emptyTable: '<div class="text-center text-muted">No Data found</div>'
},
paging: true,
pageLength: 10,
ordering: false,
}));
nhanceListDataTableAfterInit();
nhanceListDataTableBindAdjust(nhBdsReportTable);
} 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);
});
}
$('table tbody').on('click', 'td', function () {
var colIndex = $(this).index();
var rowIndex = $(this).closest('tr').index();
console.log('Row:', rowIndex, 'Column:', colIndex);
});
</script>