This commit is contained in:
Flatlogic Bot 2025-11-26 16:32:00 +00:00
parent 2b9925f4fc
commit c80560ad92
2 changed files with 35 additions and 1 deletions

View File

@ -70,7 +70,8 @@ document.addEventListener('DOMContentLoaded', function () {
function updateCell(metric, month, value) {
const cell = document.getElementById(`${metric.toLowerCase().replace(/\s/g, '-')}-${month}`);
if (cell) {
cell.innerHTML = `${parseFloat(value).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
const numericValue = value === '' ? 0 : parseFloat(value);
cell.innerHTML = `${numericValue.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
}
}
});

View File

@ -141,6 +141,39 @@ if ($project_id) {
// Update previous month's WIP for the next iteration
$previous_month_wip = $current_wip;
}
// 3. Fetch and apply overridden data
$override_stmt = $pdo->prepare("SELECT month, metricName, value FROM projectFinanceMonthly WHERE projectId = :pid AND is_overridden = 1");
$override_stmt->execute([':pid' => $project_id]);
$metric_map = [
'wip' => 'WIP',
'opening_balance' => 'Opening Balance',
'billings' => 'Billings',
'expenses' => 'Expenses'
];
while ($row = $override_stmt->fetch(PDO::FETCH_ASSOC)) {
$month = $row['month'];
$metricName = $row['metricName'];
$value = $row['value'];
if (isset($metric_map[$metricName])) {
$display_metric = $metric_map[$metricName];
if (isset($financial_data[$display_metric][$month])) {
$financial_data[$display_metric][$month] = $value;
}
}
}
// 4. Recalculate dependent metrics (NSR and Margin) after override
foreach ($months as $month) {
$nsr = $financial_data['WIP'][$month] + $financial_data['Billings'][$month] - $financial_data['Opening Balance'][$month] - $financial_data['Expenses'][$month];
$financial_data['NSR'][$month] = $nsr;
$margin = ($nsr != 0) ? (($nsr - $financial_data['Cost'][$month]) / $nsr) : 0;
$financial_data['Margin'][$month] = $margin;
}
}
}