From 17c3515c4ae464c18dcc8735820818268f45ce94 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 18 Feb 2026 02:29:36 +0000 Subject: [PATCH] add cashflow report --- index.php | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 211 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index af14569..acf2d96 100644 --- a/index.php +++ b/index.php @@ -2021,6 +2021,42 @@ switch ($page) { $stmt->execute($params); $data['expiry_items'] = $stmt->fetchAll(); break; + case 'cashflow_report': + $start_date = $_GET['start_date'] ?? date('Y-m-01'); + $end_date = $_GET['end_date'] ?? date('Y-m-d'); + + // Fetch Cash & Bank Account IDs + $cash_accounts = db()->query("SELECT id FROM acc_accounts WHERE code IN (1100, 1200)")->fetchAll(PDO::FETCH_COLUMN); + $cash_ids_str = implode(',', $cash_accounts); + + if (!empty($cash_ids_str)) { + // Opening Balance + $stmt = db()->prepare("SELECT SUM(debit - credit) FROM acc_ledger l JOIN acc_journal_entries je ON l.journal_entry_id = je.id WHERE l.account_id IN ($cash_ids_str) AND je.entry_date < ?"); + $stmt->execute([$start_date]); + $data['opening_balance'] = $stmt->fetchColumn() ?: 0; + + // Transactions in range + $stmt = db()->prepare("SELECT + je.entry_date, + je.description, + l.debit as inflow, + l.credit as outflow, + a.name_en as other_account, + a.type as other_type + FROM acc_ledger l + JOIN acc_journal_entries je ON l.journal_entry_id = je.id + LEFT JOIN acc_ledger l2 ON l2.journal_entry_id = je.id AND l2.id != l.id + LEFT JOIN acc_accounts a ON l2.account_id = a.id + WHERE l.account_id IN ($cash_ids_str) + AND je.entry_date BETWEEN ? AND ? + ORDER BY je.entry_date ASC, je.id ASC"); + $stmt->execute([$start_date, $end_date]); + $data['cash_transactions'] = $stmt->fetchAll(PDO::FETCH_ASSOC); + } else { + $data['opening_balance'] = 0; + $data['cash_transactions'] = []; + } + break; case 'hr_departments': $data['departments'] = db()->query("SELECT * FROM hr_departments ORDER BY id DESC")->fetchAll(); break; @@ -2097,7 +2133,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; @@ -2206,17 +2242,20 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; -