Update 1.html

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

34
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) {
if (row.classList.contains('subtotal')) {
subtotalSpan = row.querySelectorAll('span')[1];
} else if (row.classList.contains('grand-total')) {
totalSpan = row.querySelectorAll('span')[1];
} else {
// This is the tax row
taxSpan = row.querySelectorAll('span')[1];
}
});
if (subtotalSpan && taxSpan && totalSpan) {
// Extract numeric values // Extract numeric values
let subtotalText = subtotalRow.textContent.trim().replace(/[^\d.]/g, ''); let subtotalText = subtotalSpan.textContent.trim().replace(/,/g, '');
let taxText = taxRow.textContent.trim().replace(/[^\d.]/g, ''); let taxText = taxSpan.textContent.trim().replace(/,/g, '');
let totalText = totalRow.textContent.trim().split(' ')[0].replace(/[^\d.]/g, ''); let totalText = totalSpan.textContent.trim().split(' ')[0].replace(/,/g, '');
let subtotalNum = parseFloat(subtotalText); let subtotalNum = parseFloat(subtotalText);
let taxNum = parseFloat(taxText); let taxNum = parseFloat(taxText);
let totalNum = parseFloat(totalText); let totalNum = parseFloat(totalText);
console.log('Subtotal:', subtotalNum, 'Tax:', taxNum, 'Total:', totalNum);
// If subtotal equals total, calculate actual subtotal (total - tax) // If subtotal equals total, calculate actual subtotal (total - tax)
if (Math.abs(subtotalNum - totalNum) < 0.01 && taxNum > 0) { if (Math.abs(subtotalNum - totalNum) < 1 && taxNum > 0) {
let actualSubtotal = totalNum - taxNum; let actualSubtotal = totalNum - taxNum;
subtotalRow.textContent = formatIndianNumber(actualSubtotal.toFixed(2)); subtotalSpan.textContent = formatIndianNumber(actualSubtotal.toFixed(2));
} }
} }
}, 100);
}); });
</script> </script>
</head> </head>