nhance/app/Views/report_bds.php

773 lines
40 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>
.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;
}
.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 ?></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 style="display: true;">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>
<?php if (isset($report_list)) { ?>
<?php foreach($report_list as $index => $row){ ?>
<tr data-id="<?= $row['pt_id'] ?>">
<td><?= $index + 1 ?> &nbsp; <a href="<?php
if(strtolower($row['action_type']) == "policy"){
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['user_name'] ?: 'N/A'; ?></td>
<td><?php echo $row['policy_issue_month'] ?: '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['total_irda_amt'] != 0.00) ? ($row['bp_amt'] ?: '0.00') : '0.00'; ?></td>
<td class="right-align-input"><?php echo ($row['total_irda_amt'] != 0.00) ? ($row['tp_or_ter'] ?: '0.00') : '0.00'; ?></td>
<td class="right-align-input"><?php echo ($row['total_irda_amt'] != 0.00) ? ($row['premium_wo_gst'] ?: '0.00') : '0.00'; ?></td>
<!-- <td class="right-align-input" style="display: none;"><?php echo $row['gst_amount']; ?></td> -->
<td class="right-align-input" style="display: none;"><?php echo ($row['total_irda_amt'] != 0.00) ? ($row['total_premium'] ?: '0.00') : '0.00'; ?></td>
<td class="right-align-input"><?php echo ($row['total_irda_amt'] != 0.00) ? ($row['agreed_bp_per'] ?: '0.00') : '0.00'; ?>%</td>
<td class="right-align-input"><?php echo ($row['total_irda_amt'] != 0.00) ? ($row['agreed_tp_or_ter_per'] ?: '0.00') : '0.00'; ?>%</td>
<td class="right-align-input" style="display: true;"><?php echo isset($row['reward']) ? $row['reward'] : '0.00'; ?></td>
<?php
// Below Line its old version i am removed. reason no value ['total_irda_amt'] means taken as ['exp_amt'] so.
// LN156 - $total_irda_amt = empty($row['total_irda_amt']) ? $row['exp_amt'] : $row['total_irda_amt'];
// Here i am compare [total_irda_amt] and [exp_amt] i am print the larger value.
// both are equal, print either value.
// both are zero , empty/null , any one is empty or null means => i am print 0.00.
// REF : Velmurugan but he told handle in query
// Date : 6/11/25 12:50
$irda_amt = isset($row['total_irda_amt']) && $row['total_irda_amt'] !== '' ? (float)$row['total_irda_amt'] : 0;
$exp_amt = isset($row['exp_amt']) && $row['exp_amt'] !== '' ? (float)$row['exp_amt'] : 0;
// $max_amount = max($irda_amt, $exp_amt);
// $total_irda_amt = number_format($max_amount, 2, '.', '');
// $total_irda_amt = empty($row['total_irda_amt']) ? $row['exp_amt'] : $row['total_irda_amt'];
$total_irda_amt = $row['total_irda_amt'] ?? '0.00';
?>
<td class="right-align-input" onclick="showCoShareStatementDetails(this)" data-id="<?= $row['pt_id'] ?>"><?php echo $total_irda_amt; ?></td>
<td class="right-align-input" data-id="<?php echo strtolower($row['action_type']) ?: '-'; ?>"><?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> -->
<?php
// Below Line its old version so commanded reason they direct taken as ['total_irda_amt'] from array.
// $unbilled_amt = $row['total_irda_amt'] - $row['billed_amt'];
// now stored total_irda_amt value taken here
// REF : Velmurugan but he told handle in query
// Date : 6/11/25 12:50
$unbilled_amt = $total_irda_amt - $row['billed_amt'];
if($total_irda_amt == "0.00"){
$unbilled_amt = abs($unbilled_amt);
}
$unbilled_amt = $unbilled_amt == 0 && $row['billed_amt'] == 0 ? $total_irda_amt : $unbilled_amt ;
?>
<td class="right-align-input">
<?php echo
// number_format((float)$unbilled_amt,2, '.', '')
// number_format((float) ($row['unbilled_amount'] ?: 0), 2, '.', '');
$unbilled = isset($row['unbilled_amount']) ? $row['unbilled_amount'] : '0.00';
number_format($unbilled, 2, '.', '');
?>
</td>
<td style="display: none;"><?php echo $row['salse_person_name'] ?: 'N/A'; ?></td>
<td style="display: none;"><?php echo $row['service_person_name'] ?: 'N/A'; ?></td>
<td style="display: none;"><?php echo $row['nhance_branch'] ?: 'N/A'; ?></td>
<td style="display: none;"><?php echo $row['installment'] ?: 'N/A'; ?></td>
<td style="display: none;"><?php echo empty($row['data_received_date']) ? 'N/A' : date('d/m/Y', strtotime($row['data_received_date'])) ?></td>
<td style="display: none;"><?php echo empty($row['renewal_date']) ? 'N/A' : date('d/m/Y', strtotime($row['renewal_date'])) ?></td>
<td style="display:none;"><?php echo $row['co_share'] ?? 'No'; ?></td>
<td style="display:none;"><?php echo $row['bro_payable_by'] ?? 'No'; ?></td>
<td style="display:none;"><?php echo $row['salse_manager_name'] ?: 'N/A'; ?></td>
<td style="display:none;"><?php echo $row['service_manager_name'] ?: 'N/A'; ?></td>
<td style="display:none;"><?php echo $row['service_branch'] ?: 'N/A'; ?></td>
<td style="display:none;"><?php echo empty($row['rollover_date']) ? 'N/A' : change_date_format($row['rollover_date'], 'Y-m-d', 'd/m/Y') ?? 'N/A'; ?> </td>
<td style="display:none;"><?php echo $row['policy_holder_name'] ?: 'N/A'; ?></td>
<td style="display:none;"><?php echo $row['same_as_proposer'] ?? 'No'; ?></td>
<td style="display:none;"><?php echo $row['follower_policy_no'] ?: 'N/A'; ?></td>
<td style="display:none;"><?php echo number_format((float)($row['co_share_per'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['non_comm_per_amt'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['bp_igst'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['bp_sgst'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['bp_cgst'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['stamp_duty'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['standerd_bp_per'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['standerd_tp_per'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['actual_bp_amt'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['actual_tp_amt'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['actual_bp_per'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['actual_tp_per'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['actual_tep_brokerage_amt'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo number_format((float)($row['actual_tp_brokerage_amt'] ?? 0), 2); ?></td>
<td style="display:none;"><?php echo $row['cd_ac_no'] ?: 'N/A'; ?></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];
// }
// }
// }
// }
// }
// ],
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: [
{
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: 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 ',
// 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'
},
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, // 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));
var getUniqueUnbilled = function(colIndex) {
var rows = api.rows({ search: 'applied' }).nodes(); // get filtered nodes
var maxRowPerId = {}; // store only the greatest row
$(rows).each(function() {
var rowId = $(this).data('id'); // read data-id
var rowIndex = $(this).index(); // row index
// Keep only the greatest row index per data-id
if (!maxRowPerId[rowId] || rowIndex > maxRowPerId[rowId]) {
maxRowPerId[rowId] = rowIndex;
}
});
var total = 0;
// Now sum only the selected rows
$.each(maxRowPerId, function(id, rowIndex) {
var value = api.cell(rowIndex, colIndex).data();
value = parseFloat((typeof value === 'string') ? value.replace(/[^0-9.\-]+/g, '') : value) || 0;
total += value;
});
return total;
};
// Helper to sum numeric values safely
var getTotal = function(colIndex) {
return api.column(colIndex, { search: 'applied' }).data()
.reduce(function(a, b) {
var x = parseFloat(a) || 0;
var y = parseFloat(
(typeof b === 'string') ? b.replace(/[^0-9.\-]+/g, '') : b
) || 0;
return x + y;
}, 0);
};
// Compute totals by column index
var totalPremium = getTotal(20);
var totalRewards = getTotal(24);
var totalIrda = getTotal(25);
var totalBilled = getTotal(26);
var totalRevenue = parseFloat(totalIrda) + parseFloat(totalRewards);
var totalUnbilled = getTotal(27);
// Update the totals section above the table
$('#total_premium').text(totalPremium.toFixed(2));
$('#total_rewards').text(totalRewards.toFixed(2));
$('#total_irda').text(totalIrda.toFixed(2));
$('#total_revenue').text(totalRevenue.toFixed(2));
// $('#total_revenue').text(totalIrda.toFixed(2));
$('#total_billed').text(totalBilled.toFixed(2));
$('#total_unbilled').text(totalUnbilled.toFixed(2));
// var totalUnbilled = getUniqueUnbilled(27);
// $('#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);
});
}
$('table tbody').on('click', 'td', function () {
var colIndex = $(this).index();
var rowIndex = $(this).closest('tr').index();
console.log('Row:', rowIndex, 'Column:', colIndex);
});
</script>