Skip to content

Commit

Permalink
fix(frozen period): correct calculation of cash flows depending on th…
Browse files Browse the repository at this point in the history
…e category
  • Loading branch information
KennethTrecy committed May 25, 2024
1 parent 3a3e965 commit 7388f11
Showing 1 changed file with 18 additions and 43 deletions.
61 changes: 18 additions & 43 deletions app/Controllers/FrozenPeriodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 7388f11

Please sign in to comment.