diff --git a/report_budget.php b/report_budget.php new file mode 100644 index 00000000..0c35ea86 --- /dev/null +++ b/report_budget.php @@ -0,0 +1,105 @@ + 0 ORDER BY expense_year DESC"); + +$categories = mysqli_query($mysqli, "SELECT * FROM categories WHERE category_type = 'Expense' ORDER BY category_name ASC"); +$monthlyTotals = array_fill(1, 12, 0); // Initialize monthly totals for each month + +?> + +
| Category | +January | +February | +March | +April | +May | +June | +July | +August | +September | +October | +November | +December | +Total | +
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| " . $category['category_name'] . " | "; + $categoryTotal = 0; + for ($month = 1; $month <= 12; $month++) { + // Fetch the monthly budget for this category for 2022 + $sql = "SELECT budget_amount FROM budget WHERE budget_category_id = " . $category['category_id'] . " AND budget_month = $month AND budget_year = $year"; + $result = $mysqli->query($sql); + if ($result->num_rows > 0) { + $budget = $result->fetch_assoc(); + $amount = $budget['budget_amount']; + $categoryTotal += $amount; + $monthlyTotals[$month] += $amount; + echo "" . $amount . " | "; + } else { + echo "0 | "; + } + } + echo "" . $categoryTotal . " | "; + echo "||||||||||
| Total | "; + $grandTotal = 0; + for ($month = 1; $month <= 12; $month++) { + $grandTotal += $monthlyTotals[$month]; + echo "" . $monthlyTotals[$month] . " | "; + } + echo "" . $grandTotal . " | "; + echo "
Expense By Vendor
+Budget
+ +