From 8be23f0e451f62e8ae68103f825550b4fb86887b Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 26 Nov 2025 10:17:48 +0000 Subject: [PATCH] Final2 --- assets/js/main.js | 1 + export.php | 21 +++++++++++++++------ export_project_finance.php | 23 ++++++++++++++--------- index.php | 6 ++++++ project_details.php | 23 ++++++++++++++--------- 5 files changed, 50 insertions(+), 24 deletions(-) diff --git a/assets/js/main.js b/assets/js/main.js index d41d1e3..48bfc0b 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -67,6 +67,7 @@ document.addEventListener('DOMContentLoaded', function () { document.getElementById('view-totalAnnualCost').value = '€' + parseFloat(data.totalAnnualCost).toFixed(2); document.getElementById('view-grossRevenue').value = '€' + parseFloat(data.grossRevenue).toFixed(2); document.getElementById('view-discountedRevenue').value = '€' + parseFloat(data.discountedRevenue).toFixed(2); + document.getElementById('view-dailyCost').value = '€' + (parseFloat(data.totalMonthlyCost) / 20).toFixed(2); viewResourceModal.show(); }); diff --git a/export.php b/export.php index 5fdad9b..4c102f9 100644 --- a/export.php +++ b/export.php @@ -21,12 +21,21 @@ $output = fopen('php://output', 'w'); // Add headers if (!empty($roster_data)) { - fputcsv($output, array_keys($roster_data[0])); -} - -// Add data -foreach ($roster_data as $row) { - fputcsv($output, $row); + $roster_data_with_daily_cost = []; + foreach ($roster_data as $row) { + $row['dailyCost'] = $row['totalMonthlyCost'] / 20; + $roster_data_with_daily_cost[] = $row; + } + fputcsv($output, array_keys($roster_data_with_daily_cost[0])); + foreach ($roster_data_with_daily_cost as $row) { + fputcsv($output, $row); + } +} else { + // Add headers even if there is no data + $stmt = $pdo->query("SHOW COLUMNS FROM roster"); + $columns = $stmt->fetchAll(PDO::FETCH_COLUMN); + $columns[] = 'dailyCost'; + fputcsv($output, $columns); } fclose($output); diff --git a/export_project_finance.php b/export_project_finance.php index e249f00..4836f86 100644 --- a/export_project_finance.php +++ b/export_project_finance.php @@ -50,7 +50,7 @@ try { $fid = $latest_forecast['id']; // Base Monthly Cost - $cost_sql = "SELECT fa.month, SUM(fa.allocatedDays * r.totalMonthlyCost) FROM forecastAllocation fa JOIN roster r ON fa.rosterId = r.id WHERE fa.forecastingId = :fid GROUP BY fa.month"; + $cost_sql = "SELECT fa.month, SUM(fa.allocatedDays * (r.totalMonthlyCost / 20)) FROM forecastAllocation fa JOIN roster r ON fa.rosterId = r.id WHERE fa.forecastingId = :fid GROUP BY fa.month"; $cost_stmt = $pdo->prepare($cost_sql); $cost_stmt->execute([':fid' => $fid]); $monthly_costs = $cost_stmt->fetchAll(PDO::FETCH_KEY_PAIR); @@ -69,27 +69,29 @@ try { // 2. Calculate cumulative values month by month $cumulative_billing = 0; - $cumulative_wip = 0; $cumulative_cost = 0; + $previous_month_wip = 0; foreach ($months as $month) { // Normalize month keys from fetched data $cost = $monthly_costs[$month] ?? 0; - $wip = $monthly_wip[$month] ?? 0; + $base_monthly_wip = $monthly_wip[$month] ?? 0; $billing = $monthly_billing[$month] ?? 0; + $expenses = 0; // Placeholder for expenses // Cumulative calculations $cumulative_billing += $billing; - $cumulative_wip += $wip; $cumulative_cost += $cost; + // WIP Calculation (new formula) + // current month WIP = previous month WIP + Month Expenses + base_monthly_wip - month Billing + $current_wip = $previous_month_wip + $expenses + $base_monthly_wip - $billing; + + $financial_data['WIP'][$month] = $current_wip; $financial_data['Billings'][$month] = $cumulative_billing; - $financial_data['WIP'][$month] = $cumulative_wip; $financial_data['Cost'][$month] = $cumulative_cost; - - // Other metrics are 0 for now - $financial_data['Opening Balance'][$month] = 0; - $financial_data['Expenses'][$month] = 0; + $financial_data['Opening Balance'][$month] = 0; // Placeholder + $financial_data['Expenses'][$month] = $expenses; // Calculated metrics (NSR and Margin) $nsr = $financial_data['WIP'][$month] + $financial_data['Billings'][$month] - $financial_data['Opening Balance'][$month] - $financial_data['Expenses'][$month]; @@ -97,6 +99,9 @@ try { $margin = ($nsr != 0) ? (($nsr - $financial_data['Cost'][$month]) / $nsr) : 0; $financial_data['Margin'][$month] = $margin; + + // Update previous month's WIP for the next iteration + $previous_month_wip = $current_wip; } } } catch (PDOException $e) { diff --git a/index.php b/index.php index 18d9d7f..3083d67 100644 --- a/index.php +++ b/index.php @@ -356,6 +356,7 @@ try { Total Annual Cost Gross Revenue Discounted Revenue + Daily Cost Actions @@ -384,6 +385,7 @@ try { € + €
+
+ + +