mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Update for balance box in report.
This commit is contained in:
@@ -47,7 +47,6 @@ class BalanceController extends Controller
|
||||
*/
|
||||
public function general(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
@@ -55,17 +54,19 @@ class BalanceController extends Controller
|
||||
$cache->addProperty('balance-report');
|
||||
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
//return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
$helper = app(BalanceReportHelperInterface::class);
|
||||
$balance = $helper->getBalanceReport($accounts, $start, $end);
|
||||
try {
|
||||
$result = view('reports.partials.balance', compact('balance'))->render();
|
||||
$report = $helper->getBalanceReport($accounts, $start, $end);
|
||||
// TODO no budget.
|
||||
// TODO sum over account.
|
||||
// try {
|
||||
$result = view('reports.partials.balance', compact('report'))->render();
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::debug(sprintf('Could not render reports.partials.balance: %s', $e->getMessage()));
|
||||
$result = 'Could not render view.';
|
||||
}
|
||||
// } catch (Throwable $e) {
|
||||
// Log::debug(sprintf('Could not render reports.partials.balance: %s', $e->getMessage()));
|
||||
// $result = 'Could not render view.';
|
||||
// }
|
||||
// @codeCoverageIgnoreEnd
|
||||
$cache->store($result);
|
||||
|
||||
|
@@ -171,31 +171,60 @@ class CategoryController extends Controller
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$categories = $repository->getCategories();
|
||||
$report = [];
|
||||
$report = [
|
||||
'categories' => [],
|
||||
'sums' => [],
|
||||
];
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
$spent = $repository->spentInPeriod($category, $accounts, $start, $end);
|
||||
$earned = $repository->earnedInPeriod($category, $accounts, $start, $end);
|
||||
$currencies = array_keys($spent) + array_keys($earned);
|
||||
if (0 === count($spent) && 0 === count($earned)) {
|
||||
continue;
|
||||
}
|
||||
$currencies = array_unique(array_merge(array_keys($spent), array_keys($earned)));
|
||||
foreach ($currencies as $code) {
|
||||
$currencyInfo = $spent[$code] ?? $earned[$code];
|
||||
$report[$category->id] = [
|
||||
'name' => sprintf('%s (%s)', $category->name, $code),
|
||||
'spent' => round($spent[$code]['spent'] ?? '0', $currencyInfo['currency_decimal_places']),
|
||||
'earned' => round($earned[$code]['earned'] ?? '0', $currencyInfo['currency_decimal_places']),
|
||||
$currencyInfo = $spent[$code] ?? $earned[$code];
|
||||
$key = sprintf('%s-%s', $category->id, $code);
|
||||
$report['categories'][$key] = [
|
||||
'name' => $category->name,
|
||||
'spent' => $spent[$code]['spent'] ?? '0',
|
||||
'earned' => $earned[$code]['earned'] ?? '0',
|
||||
'id' => $category->id,
|
||||
'currency_id' => $currencyInfo['currency_id'],
|
||||
'currency_code' => $currencyInfo['currency_code'],
|
||||
'currency_symbol' => $currencyInfo['currency_symbol'],
|
||||
'cyrrency_decimal_places' => $currencyInfo['currency_decimal_places'],
|
||||
'currency_name' => $currencyInfo['currency_name'],
|
||||
'currency_decimal_places' => $currencyInfo['currency_decimal_places'],
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
$sum = [];
|
||||
foreach ($report as $categoryId => $row) {
|
||||
$sum[$categoryId] = (float)$row['spent'];
|
||||
/**
|
||||
* @var string $categoryId
|
||||
* @var array $row
|
||||
*/
|
||||
foreach ($report['categories'] as $categoryId => $row) {
|
||||
$sum[$categoryId] = (float)$row['spent'];
|
||||
}
|
||||
array_multisort($sum, SORT_ASC, $report['categories']);
|
||||
|
||||
// get sums:
|
||||
foreach ($report['categories'] as $entry) {
|
||||
$currencyId = $entry['currency_id'];
|
||||
$report['sums'][$currencyId] = $report['sums'][$currencyId] ?? [
|
||||
'spent' => '0',
|
||||
'earned' => '0',
|
||||
'currency_id' => $entry['currency_id'],
|
||||
'currency_code' => $entry['currency_code'],
|
||||
'currency_symbol' => $entry['currency_symbol'],
|
||||
'currency_name' => $entry['currency_name'],
|
||||
'cyrrency_decimal_places' => $entry['currency_decimal_places'],
|
||||
];
|
||||
$report['sums'][$currencyId]['spent'] = bcadd($report['sums'][$currencyId]['spent'], $entry['spent']);
|
||||
$report['sums'][$currencyId]['earned'] = bcadd($report['sums'][$currencyId]['earned'], $entry['earned']);
|
||||
}
|
||||
array_multisort($sum, SORT_ASC, $report);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
|
@@ -74,7 +74,6 @@ class ExpenseController extends Controller
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function budget(Collection $accounts, Collection $expense, Carbon $start, Carbon $end): string
|
||||
{
|
||||
|
Reference in New Issue
Block a user