Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix some issues in multi-currency budget reports.
James Cole206dae87bafc
diff --git a/app/Http/Controllers/Report/BudgetController.php b/app/Http/Controllers/Report/BudgetController.phpindex ccd3df3563..559038008a 100644--- a/app/Http/Controllers/Report/BudgetController.php+++ b/app/Http/Controllers/Report/BudgetController.php@@ -41,6 +41,26 @@ class BudgetController extends Controller{use BasicDataSupport;+ /** @var OperationsRepositoryInterface */+ private $opsRepository;++ /**+ * ExpenseReportController constructor.+ *+ * @codeCoverageIgnore+ */+ public function __construct()+ {+ parent::__construct();+ $this->middleware(+ function ($request, $next) {+ $this->opsRepository = app(OperationsRepositoryInterface::class);++ return $next($request);+ }+ );+ }+/*** @param Collection $accounts* @param Collection $budgets@@ -49,10 +69,8 @@ class BudgetController extends Controller*/public function accountPerBudget(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end){- // get all journals.- $opsRepository = app(OperationsRepositoryInterface::class);- $spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);- $report = [];+ $spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);+ $report = [];/** @var Account $account */foreach ($accounts as $account) {$accountId = $account->id;@@ -101,11 +119,9 @@ class BudgetController extends Controller*/public function accounts(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end){- // get all journals.- $opsRepository = app(OperationsRepositoryInterface::class);- $spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);- $report = [];- $sums = [];+ $spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);+ $report = [];+ $sums = [];/** @var Account $account */foreach ($accounts as $account) {$accountId = $account->id;@@ -156,10 +172,8 @@ class BudgetController extends Controller*/public function avgExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end){- // get all journals.- $opsRepository = app(OperationsRepositoryInterface::class);- $spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);- $result = [];+ $spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);+ $result = [];foreach ($spent as $currency) {$currencyId = $currency['currency_id'];foreach ($currency['budgets'] as $budget) {@@ -210,11 +224,9 @@ class BudgetController extends Controller*/public function budgets(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end){- // get all journals.- $opsRepository = app(OperationsRepositoryInterface::class);- $spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);- $sums = [];- $report = [];+ $spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);+ $sums = [];+ $report = [];/** @var Budget $budget */foreach ($budgets as $budget) {$budgetId = $budget->id;@@ -257,6 +269,7 @@ class BudgetController extends Controller/*** Show partial overview of budgets.+ * TODO can be replaced I think.** @param Collection $accounts* @param Carbon $start@@ -310,14 +323,12 @@ class BudgetController extends Controllerreturn $cache->get(); // @codeCoverageIgnore}- /** @var OperationsRepositoryInterface $opsRepository */- $opsRepository = app(OperationsRepositoryInterface::class);- $periods = app('navigation')->listOfPeriods($start, $end);- $keyFormat = app('navigation')->preferredCarbonFormat($start, $end);+ $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);+ $expenses = $this->opsRepository->listExpenses($start, $end, $accounts);$report = [];foreach ($expenses as $currency) {@@ -363,10 +374,8 @@ class BudgetController extends Controller*/public function topExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end){- // get all journals.- $opsRepository = app(OperationsRepositoryInterface::class);- $spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);- $result = [];+ $spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);+ $result = [];foreach ($spent as $currency) {$currencyId = $currency['currency_id'];foreach ($currency['budgets'] as $budget) {diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.phpindex 215cf69537..f629e9b92a 100644--- a/app/Http/Controllers/ReportController.php+++ b/app/Http/Controllers/ReportController.php@@ -125,8 +125,8 @@ class ReportController extends Controllertrans('firefly.report_audit',[- 'start' => $start->formatLocalized($this->monthFormat),- 'end' => $end->formatLocalized($this->monthFormat),+ 'start' => $start->formatLocalized($this->monthAndDayFormat),+ 'end' => $end->formatLocalized($this->monthAndDayFormat),]));@@ -162,8 +162,8 @@ class ReportController extends Controllertrans('firefly.report_budget',[- 'start' => $start->formatLocalized($this->monthFormat),- 'end' => $end->formatLocalized($this->monthFormat),+ 'start' => $start->formatLocalized($this->monthAndDayFormat),+ 'end' => $end->formatLocalized($this->monthAndDayFormat),]));@@ -200,8 +200,8 @@ class ReportController extends Controllertrans('firefly.report_category',[- 'start' => $start->formatLocalized($this->monthFormat),- 'end' => $end->formatLocalized($this->monthFormat),+ 'start' => $start->formatLocalized($this->monthAndDayFormat),+ 'end' => $end->formatLocalized($this->monthAndDayFormat),]));@@ -406,8 +406,8 @@ class ReportController extends Controllertrans('firefly.report_tag',[- 'start' => $start->formatLocalized($this->monthFormat),- 'end' => $end->formatLocalized($this->monthFormat),+ 'start' => $start->formatLocalized($this->monthAndDayFormat),+ 'end' => $end->formatLocalized($this->monthAndDayFormat),]));diff --git a/app/Support/Http/Controllers/BasicDataSupport.php b/app/Support/Http/Controllers/BasicDataSupport.phpindex 3e62be2e4e..50fcf84a9d 100644--- a/app/Support/Http/Controllers/BasicDataSupport.php+++ b/app/Support/Http/Controllers/BasicDataSupport.php@@ -30,32 +30,6 @@ namespace FireflyIII\Support\Http\Controllers;trait BasicDataSupport{- /**- * Filters empty results from getBudgetPeriodReport.- *- * @param array $data- *- * @return array- */- protected function filterPeriodReport(array $data): array // helper function for period overview.- {- /**- * @var int $entryId- * @var array $set- */- foreach ($data as $entryId => $set) {- $sum = '0';- $entries = $set['entries'] ?? [];- foreach ($entries as $amount) {- $sum = bcadd($amount, $sum);- }- $data[$entryId]['sum'] = $sum;- if (0 === bccomp('0', $sum)) {- unset($data[$entryId]);- }- }- return $data;- }/*** Find the ID in a given array. Return '0' of not there (amount).