From 7388f11cbfc1febae8438f730d13b56dfd30a362 Mon Sep 17 00:00:00 2001 From: Kenneth Trecy Tobias Date: Sat, 25 May 2024 17:50:24 +0800 Subject: [PATCH] fix(frozen period): correct calculation of cash flows depending on the category --- app/Controllers/FrozenPeriodController.php | 61 +++++++--------------- 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/app/Controllers/FrozenPeriodController.php b/app/Controllers/FrozenPeriodController.php index 31491f4..8966eae 100644 --- a/app/Controllers/FrozenPeriodController.php +++ b/app/Controllers/FrozenPeriodController.php @@ -311,7 +311,8 @@ function($request_data) use ($controller, $current_user) { "summary_calculations" => $raw_summary_calculations, "accounts" => $accounts, "currencies" => $currencies, - "cash_flow_categories" => $cash_flow_categories + "cash_flow_categories" => $cash_flow_categories, + "flow_calculations" => $raw_flow_calculations ]; return $controller->response->setJSON($response_document); @@ -580,51 +581,25 @@ function ($raw_calculations, $modifier) use ( $credit_flow_category = $keyed_cash_flow_categories[$credit_category_id]; if ($debit_flow_category->kind === ILLIQUID_CASH_FLOW_CATEGORY_KIND) { - $debit_account = $keyed_accounts[$debit_account_id]; - - switch($debit_account->kind) { - case ASSET_ACCOUNT_KIND: - case EXPENSE_ACCOUNT_KIND: - $raw_calculations - [$debit_category_id][$debit_account_id]["net_amount"] - = $raw_calculations - [$debit_category_id][$debit_account_id]["net_amount"] - ->minus($debit_amount); - break; - case LIABILITY_ACCOUNT_KIND: - case EQUITY_ACCOUNT_KIND: - case INCOME_ACCOUNT_KIND: - $raw_calculations - [$debit_category_id][$debit_account_id]["net_amount"] - = $raw_calculations - [$debit_category_id][$debit_account_id]["net_amount"] - ->plus($debit_amount); - break; - } + $raw_calculations[$debit_category_id][$debit_account_id]["net_amount"] + = $raw_calculations[$debit_category_id][$debit_account_id]["net_amount"] + ->minus($debit_amount); + } else if ($debit_flow_category->kind === LIQUID_CASH_FLOW_CATEGORY_KIND) { + $raw_calculations[$debit_category_id][$debit_account_id]["net_amount"] + = $raw_calculations[$debit_category_id][$debit_account_id]["net_amount"] + ->plus($debit_amount); } if ($credit_flow_category->kind === ILLIQUID_CASH_FLOW_CATEGORY_KIND) { - $credit_account = $keyed_accounts[$credit_account_id]; - - switch($credit_account->kind) { - case ASSET_ACCOUNT_KIND: - case EXPENSE_ACCOUNT_KIND: - $raw_calculations - [$credit_category_id][$credit_account_id]["net_amount"] - = $raw_calculations - [$credit_category_id][$credit_account_id]["net_amount"] - ->plus($credit_amount); - break; - case LIABILITY_ACCOUNT_KIND: - case EQUITY_ACCOUNT_KIND: - case INCOME_ACCOUNT_KIND: - $raw_calculations - [$credit_category_id][$credit_account_id]["net_amount"] - = $raw_calculations - [$credit_category_id][$credit_account_id]["net_amount"] - ->minus($credit_amount); - break; - } + $raw_calculations[$credit_category_id][$credit_account_id]["net_amount"] + = $raw_calculations + [$credit_category_id][$credit_account_id]["net_amount"] + ->plus($credit_amount); + } else if ($credit_flow_category->kind === LIQUID_CASH_FLOW_CATEGORY_KIND) { + $raw_calculations[$credit_category_id][$credit_account_id]["net_amount"] + = $raw_calculations + [$credit_category_id][$credit_account_id]["net_amount"] + ->minus($credit_amount); } }