Auto commit: 2025-11-28T17:57:05.477Z
This commit is contained in:
parent
dd81fb557e
commit
110ea14346
@ -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();
|
||||
}
|
||||
}
|
||||
@ -42,27 +42,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
// Replace button with "Overridden" badge
|
||||
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';
|
||||
}
|
||||
}
|
||||
location.reload();
|
||||
} else {
|
||||
alert('Error saving override: ' + (data.message || 'Unknown error.'));
|
||||
}
|
||||
|
||||
@ -95,10 +95,10 @@ try {
|
||||
$totalBilling = 0;
|
||||
foreach ($billingData as $billingMonth) {
|
||||
$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">€<?php echo number_format($totalBilling, 2); ?></td>
|
||||
<td id="total-billing" class="fw-bold text-end"><?php echo number_format($totalBilling, 2, ',', '.'); ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user