Auto commit: 2025-11-28T17:57:05.477Z

This commit is contained in:
Flatlogic Bot 2025-11-28 17:57:05 +00:00
parent dd81fb557e
commit 110ea14346
5 changed files with 27 additions and 35 deletions

View File

@ -3,16 +3,27 @@ function initBillingPage(projectId) {
const billingAmountInputs = document.querySelectorAll('.billing-amount'); const billingAmountInputs = document.querySelectorAll('.billing-amount');
const totalBillingCell = document.getElementById('total-billing'); 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() { function updateTotalBilling() {
let total = 0; let total = 0;
billingAmountInputs.forEach(input => { 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 => { billingAmountInputs.forEach(input => {
input.addEventListener('keyup', updateTotalBilling); input.addEventListener('input', updateTotalBilling); // Use 'input' for better response
}); });
if (saveBtn) { if (saveBtn) {
@ -21,7 +32,7 @@ function initBillingPage(projectId) {
billingAmountInputs.forEach(input => { billingAmountInputs.forEach(input => {
billingData.push({ billingData.push({
month: input.dataset.month, month: input.dataset.month,
amount: input.value amount: parseEuroNumber(input.value) // Send the parsed number
}); });
}); });
@ -50,4 +61,4 @@ function initBillingPage(projectId) {
// Initial calculation // Initial calculation
updateTotalBilling(); updateTotalBilling();
} }

View File

@ -42,27 +42,7 @@ document.addEventListener('DOMContentLoaded', function () {
}) })
.then(data => { .then(data => {
if (data.success) { if (data.success) {
// Replace button with "Overridden" badge location.reload();
const buttonCell = this.parentElement;
buttonCell.innerHTML = '<span class="badge bg-success">Overridden</span>';
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';
}
}
} else { } else {
alert('Error saving override: ' + (data.message || 'Unknown error.')); alert('Error saving override: ' + (data.message || 'Unknown error.'));
} }

View File

@ -95,10 +95,10 @@ try {
$totalBilling = 0; $totalBilling = 0;
foreach ($billingData as $billingMonth) { foreach ($billingData as $billingMonth) {
$totalBilling += $billingMonth['amount']; $totalBilling += $billingMonth['amount'];
echo '<td><input type="number" class="form-control billing-amount" data-month="' . $billingMonth['month'] . '" value="' . htmlspecialchars($billingMonth['amount']) . '"></td>'; echo '<td><input type="text" class="form-control billing-amount text-end" data-month="' . $billingMonth['month'] . '" value="' . htmlspecialchars(number_format($billingMonth['amount'], 2, ',', '.')) . '"></td>';
} }
?> ?>
<td id="total-billing" class="fw-bold">&euro;<?php echo number_format($totalBilling, 2); ?></td> <td id="total-billing" class="fw-bold text-end"><?php echo number_format($totalBilling, 2, ',', '.'); ?></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -77,11 +77,11 @@ try {
$cumulative_billing = 0; $cumulative_billing = 0;
$cumulative_cost = 0; $cumulative_cost = 0;
$cumulative_expenses = 0; $cumulative_expenses = 0;
$previous_month_wip = 0; $previous_month_opening_balance = 0;
foreach ($months as $month) { foreach ($months as $month) {
// --- Opening Balance --- // --- Opening Balance ---
$opening_balance = $previous_month_wip; $opening_balance = $previous_month_opening_balance;
$financial_data['Opening Balance'][$month] = $opening_balance; $financial_data['Opening Balance'][$month] = $opening_balance;
// --- Base Data --- // --- Base Data ---
@ -115,7 +115,7 @@ try {
$financial_data['Margin'][$month] = $margin; $financial_data['Margin'][$month] = $margin;
// --- Carry-over for next iteration --- // --- Carry-over for next iteration ---
$previous_month_wip = $financial_data['WIP'][$month]; $previous_month_opening_balance = $financial_data['Opening Balance'][$month];
} }
} }
} catch (PDOException $e) { } catch (PDOException $e) {

View File

@ -108,7 +108,7 @@ if ($project_id) {
$cumulative_billing = 0; $cumulative_billing = 0;
$cumulative_cost = 0; $cumulative_cost = 0;
$cumulative_expenses = 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 // 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"); $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) { foreach ($months as $month) {
// --- Opening Balance --- // --- 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; $financial_data['Opening Balance'][$month] = $opening_balance;
if (isset($overrides[$month]['Opening Balance'])) { if (isset($overrides[$month]['Opening Balance'])) {
$financial_data['Opening Balance'][$month] = $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 --- // --- Carry-over for next iteration ---
// Update previous month's WIP with the final, possibly overridden, value. // The next month's opening balance is this month's final opening balance (including override).
$previous_month_wip = $financial_data['WIP'][$month]; $previous_month_opening_balance = $financial_data['Opening Balance'][$month];
} }
} }
} }