mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Fix list
This commit is contained in:
@@ -86,7 +86,7 @@ class IndexController extends Controller
|
||||
/** @var PiggyBank $piggy */
|
||||
foreach ($collection as $piggy) {
|
||||
$array = $transformer->transform($piggy);
|
||||
$groupOrder = $array['object_group_order'];
|
||||
$groupOrder = (int) $array['object_group_order'];
|
||||
// make group array if necessary:
|
||||
$piggyBanks[$groupOrder] = $piggyBanks[$groupOrder] ?? [
|
||||
'object_group_id' => $array['object_group_id'],
|
||||
@@ -109,19 +109,61 @@ class IndexController extends Controller
|
||||
}
|
||||
|
||||
// calculate new interesting fields:
|
||||
$accounts[$accountId]['left'] -= $array['current_amount'];
|
||||
$accounts[$accountId]['saved'] += $array['current_amount'];
|
||||
$accounts[$accountId]['target'] += $array['target_amount'];
|
||||
$accounts[$accountId]['to_save'] += ($array['target_amount'] - $array['current_amount']);
|
||||
$array['account_name'] = $account['name'];
|
||||
$accounts[$accountId]['left'] -= $array['current_amount'];
|
||||
$accounts[$accountId]['saved'] += $array['current_amount'];
|
||||
$accounts[$accountId]['target'] += $array['target_amount'];
|
||||
$accounts[$accountId]['to_save'] += ($array['target_amount'] - $array['current_amount']);
|
||||
$array['account_name'] = $account['name'];
|
||||
$piggyBanks[$groupOrder]['piggy_banks'][] = $array;
|
||||
}
|
||||
// do a bunch of summaries.
|
||||
$piggyBanks = $this->makeSums($piggyBanks);
|
||||
|
||||
ksort($piggyBanks);
|
||||
|
||||
return view('piggy-banks.index', compact('piggyBanks', 'accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $piggyBanks
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function makeSums(array $piggyBanks): array
|
||||
{
|
||||
$sums = [];
|
||||
foreach ($piggyBanks as $groupOrder => $group) {
|
||||
$groupId = $group['object_group_id'];
|
||||
foreach ($group['piggy_banks'] as $piggy) {
|
||||
$currencyId = $piggy['currency_id'];
|
||||
$sums[$groupId][$currencyId] = $sums[$groupId][$currencyId] ?? [
|
||||
'target' => '0',
|
||||
'saved' => '0',
|
||||
'left_to_save' => '0',
|
||||
'save_per_month' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_code' => $piggy['currency_code'],
|
||||
'currency_symbol' => $piggy['currency_symbol'],
|
||||
'currency_decimal_places' => $piggy['currency_decimal_places'],
|
||||
];
|
||||
// target_amount
|
||||
// current_amount
|
||||
// left_to_save
|
||||
// save_per_month
|
||||
$sums[$groupId][$currencyId]['target'] = bcadd($sums[$groupId][$currencyId]['target'], (string) $piggy['target_amount']);
|
||||
$sums[$groupId][$currencyId]['saved'] = bcadd($sums[$groupId][$currencyId]['saved'], (string) $piggy['current_amount']);
|
||||
$sums[$groupId][$currencyId]['left_to_save'] = bcadd($sums[$groupId][$currencyId]['left_to_save'], (string) $piggy['left_to_save']);
|
||||
$sums[$groupId][$currencyId]['save_per_month'] = bcadd($sums[$groupId][$currencyId]['save_per_month'], (string) $piggy['save_per_month']);
|
||||
}
|
||||
}
|
||||
foreach ($piggyBanks as $groupOrder => $group) {
|
||||
$groupId = $group['object_group_id'];
|
||||
$piggyBanks[$groupOrder]['sums'] = $sums[$groupId];
|
||||
}
|
||||
|
||||
return $piggyBanks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the order of a piggy bank.
|
||||
*
|
||||
|
Reference in New Issue
Block a user