Update 1.html

This commit is contained in:
jagrit007 2025-10-11 20:00:31 +00:00
parent bec4fec2b7
commit 3dfa639c8d

48
1.html
View File

@ -326,26 +326,42 @@
} }
// Fix subtotal calculation when tax is present // Fix subtotal calculation when tax is present
let subtotalRow = document.querySelector('.total-row.subtotal span:last-child'); setTimeout(function() {
let taxRow = document.querySelector('.total-row:not(.subtotal):not(.grand-total) span:last-child'); let totalRows = document.querySelectorAll('.total-row');
let totalRow = document.querySelector('.total-row.grand-total span:last-child'); let subtotalSpan = null;
let taxSpan = null;
let totalSpan = null;
if (subtotalRow && taxRow && totalRow) { totalRows.forEach(function(row) {
// Extract numeric values if (row.classList.contains('subtotal')) {
let subtotalText = subtotalRow.textContent.trim().replace(/[^\d.]/g, ''); subtotalSpan = row.querySelectorAll('span')[1];
let taxText = taxRow.textContent.trim().replace(/[^\d.]/g, ''); } else if (row.classList.contains('grand-total')) {
let totalText = totalRow.textContent.trim().split(' ')[0].replace(/[^\d.]/g, ''); totalSpan = row.querySelectorAll('span')[1];
} else {
// This is the tax row
taxSpan = row.querySelectorAll('span')[1];
}
});
let subtotalNum = parseFloat(subtotalText); if (subtotalSpan && taxSpan && totalSpan) {
let taxNum = parseFloat(taxText); // Extract numeric values
let totalNum = parseFloat(totalText); let subtotalText = subtotalSpan.textContent.trim().replace(/,/g, '');
let taxText = taxSpan.textContent.trim().replace(/,/g, '');
let totalText = totalSpan.textContent.trim().split(' ')[0].replace(/,/g, '');
// If subtotal equals total, calculate actual subtotal (total - tax) let subtotalNum = parseFloat(subtotalText);
if (Math.abs(subtotalNum - totalNum) < 0.01 && taxNum > 0) { let taxNum = parseFloat(taxText);
let actualSubtotal = totalNum - taxNum; let totalNum = parseFloat(totalText);
subtotalRow.textContent = formatIndianNumber(actualSubtotal.toFixed(2));
console.log('Subtotal:', subtotalNum, 'Tax:', taxNum, 'Total:', totalNum);
// If subtotal equals total, calculate actual subtotal (total - tax)
if (Math.abs(subtotalNum - totalNum) < 1 && taxNum > 0) {
let actualSubtotal = totalNum - taxNum;
subtotalSpan.textContent = formatIndianNumber(actualSubtotal.toFixed(2));
}
} }
} }, 100);
}); });
</script> </script>
</head> </head>