Skip to content

Commit

Permalink
fix(frozen period): include both directions of cash flow category
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed May 19, 2024
1 parent 539133d commit 4c182b5
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions app/Controllers/FrozenPeriodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,20 @@ function ($currency_builder) use ($initial_document) {

$linked_cash_flow_categories = [];
foreach ($accounts as $account) {
$cash_flow_category_id = $account->cash_flow_category_id;
if (!is_null($cash_flow_category_id)) {
array_push($linked_cash_flow_categories, $cash_flow_category_id);
$increase_cash_flow_category_id = $account->increase_cash_flow_category_id;
if (!is_null($increase_cash_flow_category_id)) {
array_push(
$linked_cash_flow_categories,
$increase_cash_flow_category_id
);
}

$decrease_cash_flow_category_id = $account->decrease_cash_flow_category_id;
if (!is_null($decrease_cash_flow_category_id)) {
array_push(
$linked_cash_flow_categories,
$decrease_cash_flow_category_id
);
}
}

Expand Down Expand Up @@ -269,9 +280,20 @@ function($request_data) use ($controller, $current_user) {

$linked_cash_flow_categories = [];
foreach ($accounts as $account) {
$cash_flow_category_id = $account->cash_flow_category_id;
if (!is_null($cash_flow_category_id)) {
array_push($linked_cash_flow_categories, $cash_flow_category_id);
$increase_cash_flow_category_id = $account->increase_cash_flow_category_id;
if (!is_null($increase_cash_flow_category_id)) {
array_push(
$linked_cash_flow_categories,
$increase_cash_flow_category_id
);
}

$decrease_cash_flow_category_id = $account->decrease_cash_flow_category_id;
if (!is_null($decrease_cash_flow_category_id)) {
array_push(
$linked_cash_flow_categories,
$decrease_cash_flow_category_id
);
}
}

Expand Down Expand Up @@ -850,20 +872,20 @@ function ($previous_total, $summary) {
$account = $keyed_accounts[$summary->account_id];
$increase_category_id = $account->increase_cash_flow_category_id;
$decrease_category_id = $account->decrease_cash_flow_category_id;

if (
$account->kind === ASSET_ACCOUNT_KIND
&& $increase_category_id === null
&& $decrease_category_id === null
) {
$asset_subtotal = $summary->opened_debit_amount
->minus($summary->opened_credit_amount);
$opened_liquid_amount = $opened_liquid_amount->plus($asset_subtotal);
$closed_liquid_amount = $closed_liquid_amount->plus($asset_subtotal);
$opened_liquid_amount = $opened_liquid_amount
->plus($summary->opened_debit_amount);
$closed_liquid_amount = $closed_liquid_amount
->plus($summary->opened_debit_amount);

continue;
}

continue;

$debit_change = $summary->unadjusted_debit_amount
->minus($summary->opened_debit_amount);
$credit_change = $summary->unadjusted_credit_amount
Expand All @@ -874,19 +896,16 @@ function ($previous_total, $summary) {

switch ($account->kind) {
case ASSET_ACCOUNT_KIND:
case EXPENSE_ACCOUNT_KIND:
$increase_change = $debit_change;
$decrease_change = $credit_change;
break;
case EXPENSE_ACCOUNT_KIND:
case LIABILITY_ACCOUNT_KIND:
case EQUITY_ACCOUNT_KIND:
case INCOME_ACCOUNT_KIND:
$increase_change = $credit_change;
$decrease_change = $debit_change;
break;

default:
break;
}

if ($increase_category_id !== null) {
Expand Down Expand Up @@ -943,11 +962,10 @@ function ($previous_total, $summary) {

$illiquid_cash_flow_category_subtotals = array_map(
function ($subtotal_info) {
return [
"cash_flow_category_id" => $subtotal_info["cash_flow_category_id"],
return array_merge($subtotal_info, [
"net_income" => $subtotal_info["net_income"]->simplified(),
"subtotal" => $subtotal_info["subtotal"]->simplified()
];
]);
},
array_filter(
array_values($keyed_flow_category_subtotals),
Expand Down

0 comments on commit 4c182b5

Please sign in to comment.