Fix some bugs in multi-currency reports.

This commit is contained in:
James Cole 2019-09-01 19:08:10 +02:00
parent 01876be152
commit 30fc56a0d7
3 changed files with 10 additions and 5 deletions

View File

@ -408,7 +408,7 @@ class BudgetController extends Controller
$cache->addProperty($currency->id);
$cache->addProperty('chart.budget.period');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
// return response()->json($cache->get()); // @codeCoverageIgnore
}
$titleFormat = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
@ -427,16 +427,17 @@ class BudgetController extends Controller
],
];
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentStart= app('navigation')->startOfPeriod($currentStart, $preferredRange);
$title = $currentStart->formatLocalized($titleFormat);
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
// default limit is no limit:
$chartData[0]['entries'][$title] = 0;
$chartData[1]['entries'][$title] = 0;
// default spent is not spent at all.
$chartData[1]['entries'][$title] = 0;
// get budget limit in this period for this currency.
$limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
@ -449,7 +450,8 @@ class BudgetController extends Controller
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
$chartData[0]['entries'][$title] = round($amount, $currency->decimal_places);
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
$data = $this->generator->multiSet($chartData);

View File

@ -112,8 +112,11 @@ class BudgetController extends Controller
$periods = app('navigation')->listOfPeriods($start, $end);
$keyFormat = app('navigation')->preferredCarbonFormat($start, $end);
// list expenses for budgets in account(s)
$expenses = $opsRepository->listExpenses($start, $end, $accounts);
$report = [];
foreach ($expenses as $currency) {
foreach ($currency['budgets'] as $budget) {

View File

@ -222,7 +222,7 @@ class OperationsRepository implements OperationsRepositoryInterface
// catch "no category" entries.
if (0 === $budgetId) {
$budgetName = (string)trans('firefly.no_budget');
continue;
}
// info about the currency: