FIX_SALES_BY_BOOKS_REPORT

This commit is contained in:
Srinivas-Saravanan 2024-12-31 18:08:25 +05:30
parent 8524a660ce
commit 535f17d0b4

View File

@ -108,10 +108,12 @@
// Function to calculate the total for print/CSV export
function calculateTotal() {
var total = table.rows({ filter: 'applied' }).data().pluck(6).reduce(function (a, b) {
return a + parseFloat(b) || 0; // Sum the 7th column (index 6) which represents the total cost
var total = table.rows({ filter: 'applied' }).data().toArray().reduce(function (a, b) {
var cost = parseFloat(b[6].replace(/[^0-9.-]+/g, "")); // Sum the 7th column (index 6) which represents the total cost
return a + (isNaN(cost) ? 0 : cost); // Only add valid numbers
}, 0);
return total.toFixed(2);
console.log("Calculated total: " + total); // Add a console log to verify the calculation
return total.toFixed(2);
}
// Add total row to the table footer (this will display the total in the table)
@ -121,13 +123,19 @@
// Function to update the total in the footer
function updateTotal() {
var total = table.rows({ filter: 'applied' }).data().pluck(6).reduce(function (a, b) {
return a + parseFloat(b) || 0;
var total = table.rows({ filter: 'applied' }).data().toArray().reduce(function (a, b) {
var cost = parseFloat(b[6].replace(/[^0-9.-]+/g, "")); // Clean and parse the value
return a + (isNaN(cost) ? 0 : cost); // Only add valid numbers
}, 0);
console.log("Footer total: ₹" + total.toFixed(2)); // Log the footer total for debugging
$('#datatable-buttons tfoot .total').html(`₹${total.toFixed(2)}`);
}
// Trigger the total update after initial draw
updateTotal(); // Manually trigger the first total update
// Add date range filter and dropdowns for the table columns
$('#datatable-buttons thead tr').clone(true).appendTo('#datatable-buttons thead');
$('#datatable-buttons thead tr:eq(1) th').each(function(i) {