diff --git a/assets/js/billing.js b/assets/js/billing.js index 4c2f680..2666093 100644 --- a/assets/js/billing.js +++ b/assets/js/billing.js @@ -3,16 +3,27 @@ function initBillingPage(projectId) { const billingAmountInputs = document.querySelectorAll('.billing-amount'); const totalBillingCell = document.getElementById('total-billing'); + function parseEuroNumber(str) { + if (!str) return 0; + // Remove thousand separators (.) and replace decimal comma (,) with a period (.) + const cleanedStr = str.toString().replace(/\./g, '').replace(',', '.'); + return parseFloat(cleanedStr); + } + + function formatToEuro(num) { + return num.toLocaleString('de-DE', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); + } + function updateTotalBilling() { let total = 0; billingAmountInputs.forEach(input => { - total += parseFloat(input.value) || 0; + total += parseEuroNumber(input.value) || 0; }); - totalBillingCell.textContent = `€${total.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`; + totalBillingCell.textContent = formatToEuro(total); } billingAmountInputs.forEach(input => { - input.addEventListener('keyup', updateTotalBilling); + input.addEventListener('input', updateTotalBilling); // Use 'input' for better response }); if (saveBtn) { @@ -21,7 +32,7 @@ function initBillingPage(projectId) { billingAmountInputs.forEach(input => { billingData.push({ month: input.dataset.month, - amount: input.value + amount: parseEuroNumber(input.value) // Send the parsed number }); }); @@ -50,4 +61,4 @@ function initBillingPage(projectId) { // Initial calculation updateTotalBilling(); -} +} \ No newline at end of file diff --git a/assets/js/project_details.js b/assets/js/project_details.js index 528d2c5..ac46c32 100644 --- a/assets/js/project_details.js +++ b/assets/js/project_details.js @@ -42,27 +42,7 @@ document.addEventListener('DOMContentLoaded', function () { }) .then(data => { if (data.success) { - // Replace button with "Overridden" badge - const buttonCell = this.parentElement; - buttonCell.innerHTML = 'Overridden'; - - updateMetricCell('WIP', month, data.wip); - updateMetricCell('Opening Balance', month, data.openingBalance); - updateMetricCell('Billings', month, data.billings); - updateMetricCell('Expenses', month, data.expenses); - updateMetricCell('Cost', month, data.cost); - updateMetricCell('NSR', month, data.nsr); - updateMetricCell('Margin', month, data.margin); - - - // Show the next override button - const nextButtonCell = buttonCell.nextElementSibling; - if (nextButtonCell) { - const nextButton = nextButtonCell.querySelector('.btn-override'); - if (nextButton) { - nextButton.style.display = 'block'; - } - } + location.reload(); } else { alert('Error saving override: ' + (data.message || 'Unknown error.')); } diff --git a/billing.php b/billing.php index 9805ab8..3dccd53 100644 --- a/billing.php +++ b/billing.php @@ -95,10 +95,10 @@ try { $totalBilling = 0; foreach ($billingData as $billingMonth) { $totalBilling += $billingMonth['amount']; - echo '