Skip to content

Commit

Permalink
fix(frozen period): create initial flow calculations from involved mo…
Browse files Browse the repository at this point in the history
…difiers
  • Loading branch information
KennethTrecy committed May 25, 2024
1 parent 7388f11 commit 331ad5e
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions app/Controllers/FrozenPeriodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 331ad5e

Please sign in to comment.