From 110ea143462b54ee1115a8593f4abc88a9ff07fe Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 28 Nov 2025 17:57:05 +0000 Subject: [PATCH] Auto commit: 2025-11-28T17:57:05.477Z --- assets/js/billing.js | 21 ++++++++++++++++----- assets/js/project_details.js | 22 +--------------------- billing.php | 4 ++-- export_project_finance.php | 6 +++--- project_details.php | 9 +++++---- 5 files changed, 27 insertions(+), 35 deletions(-) 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 ''; + echo ''; } ?> - € + diff --git a/export_project_finance.php b/export_project_finance.php index 04c9ad2..734a1ff 100644 --- a/export_project_finance.php +++ b/export_project_finance.php @@ -77,11 +77,11 @@ try { $cumulative_billing = 0; $cumulative_cost = 0; $cumulative_expenses = 0; - $previous_month_wip = 0; + $previous_month_opening_balance = 0; foreach ($months as $month) { // --- Opening Balance --- - $opening_balance = $previous_month_wip; + $opening_balance = $previous_month_opening_balance; $financial_data['Opening Balance'][$month] = $opening_balance; // --- Base Data --- @@ -115,7 +115,7 @@ try { $financial_data['Margin'][$month] = $margin; // --- Carry-over for next iteration --- - $previous_month_wip = $financial_data['WIP'][$month]; + $previous_month_opening_balance = $financial_data['Opening Balance'][$month]; } } } catch (PDOException $e) { diff --git a/project_details.php b/project_details.php index cc762bc..299b8b6 100644 --- a/project_details.php +++ b/project_details.php @@ -108,7 +108,7 @@ if ($project_id) { $cumulative_billing = 0; $cumulative_cost = 0; $cumulative_expenses = 0; - $previous_month_wip = 0; // This is the closing balance from the prior month. + $previous_month_opening_balance = 0; // Initialize Opening Balance for the first month. // Fetch all overridden data at once to avoid querying in a loop $override_stmt = $pdo->prepare("SELECT month, metricName, value FROM projectFinanceMonthly WHERE projectId = :pid AND is_overridden = 1"); @@ -133,7 +133,8 @@ if ($project_id) { foreach ($months as $month) { // --- Opening Balance --- - $opening_balance = $previous_month_wip; + // Opening Balance of the current month is the Opening Balance of the previous month. + $opening_balance = $previous_month_opening_balance; $financial_data['Opening Balance'][$month] = $opening_balance; if (isset($overrides[$month]['Opening Balance'])) { $financial_data['Opening Balance'][$month] = $overrides[$month]['Opening Balance']; @@ -188,8 +189,8 @@ if ($project_id) { } // --- Carry-over for next iteration --- - // Update previous month's WIP with the final, possibly overridden, value. - $previous_month_wip = $financial_data['WIP'][$month]; + // The next month's opening balance is this month's final opening balance (including override). + $previous_month_opening_balance = $financial_data['Opening Balance'][$month]; } } }