From 331ad5e0775f89cb57a3fac962a37a80b4ccf54a Mon Sep 17 00:00:00 2001 From: Kenneth Trecy Tobias Date: Sat, 25 May 2024 19:35:55 +0800 Subject: [PATCH] fix(frozen period): create initial flow calculations from involved modifiers --- app/Controllers/FrozenPeriodController.php | 34 +++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/app/Controllers/FrozenPeriodController.php b/app/Controllers/FrozenPeriodController.php index 8966eae..fed5941 100644 --- a/app/Controllers/FrozenPeriodController.php +++ b/app/Controllers/FrozenPeriodController.php @@ -417,11 +417,31 @@ function ($keyed_items, $cash_flow_category) { ); $raw_flow_calculations = array_reduce( - $linked_cash_flow_categories, - function ($raw_calculations, $category_id) use ($linked_accounts) { - $raw_calculations[$category_id] = []; + $modifiers, + function ($raw_calculations, $modifier) { + if ($modifier->debit_cash_flow_category_id !== null) { + $category_id = $modifier->debit_cash_flow_category_id; + $account_id = $modifier->debit_account_id; + + if (!isset($raw_calculations[$category_id])) { + $raw_calculations[$category_id] = []; + } + + $raw_calculations[$category_id][$account_id] = [ + "cash_flow_category_id" => $category_id, + "account_id" => $account_id, + "net_amount" => BigRational::zero() + ]; + } + + if ($modifier->credit_cash_flow_category_id !== null) { + $category_id = $modifier->credit_cash_flow_category_id; + $account_id = $modifier->credit_account_id; + + if (!isset($raw_calculations[$category_id])) { + $raw_calculations[$category_id] = []; + } - foreach ($linked_accounts as $account_id) { $raw_calculations[$category_id][$account_id] = [ "cash_flow_category_id" => $category_id, "account_id" => $account_id, @@ -663,12 +683,6 @@ function ($raw_summary_calculation) { $raw_summary_calculations ); - $raw_flow_calculations = array_filter( - $raw_flow_calculations, - function ($raw_flow_calculation) { - return $raw_flow_calculation->net_amount->getSign() !== 0; - } - ); $retained_accounts_on_flow_calculations = array_map( function ($raw_flow_calculation) { return $raw_flow_calculation->account_id;