mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-20 11:19:16 +00:00
Fix some issues in multi-currency budget reports.
This commit is contained in:
@@ -41,6 +41,26 @@ class BudgetController extends Controller
|
|||||||
{
|
{
|
||||||
use BasicDataSupport;
|
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 $accounts
|
||||||
* @param Collection $budgets
|
* @param Collection $budgets
|
||||||
@@ -49,9 +69,7 @@ class BudgetController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function accountPerBudget(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
public function accountPerBudget(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
// get all journals.
|
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
||||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
|
||||||
$spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
|
||||||
$report = [];
|
$report = [];
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
@@ -101,9 +119,7 @@ class BudgetController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function accounts(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
public function accounts(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
// get all journals.
|
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
||||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
|
||||||
$spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
|
||||||
$report = [];
|
$report = [];
|
||||||
$sums = [];
|
$sums = [];
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
@@ -156,9 +172,7 @@ class BudgetController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function avgExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
public function avgExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
// get all journals.
|
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
||||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
|
||||||
$spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($spent as $currency) {
|
foreach ($spent as $currency) {
|
||||||
$currencyId = $currency['currency_id'];
|
$currencyId = $currency['currency_id'];
|
||||||
@@ -210,9 +224,7 @@ class BudgetController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function budgets(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
public function budgets(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
// get all journals.
|
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
||||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
|
||||||
$spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
|
||||||
$sums = [];
|
$sums = [];
|
||||||
$report = [];
|
$report = [];
|
||||||
/** @var Budget $budget */
|
/** @var Budget $budget */
|
||||||
@@ -257,6 +269,7 @@ class BudgetController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Show partial overview of budgets.
|
* Show partial overview of budgets.
|
||||||
|
* TODO can be replaced I think.
|
||||||
*
|
*
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
@@ -310,14 +323,12 @@ class BudgetController extends Controller
|
|||||||
return $cache->get(); // @codeCoverageIgnore
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var OperationsRepositoryInterface $opsRepository */
|
|
||||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
|
||||||
$periods = app('navigation')->listOfPeriods($start, $end);
|
$periods = app('navigation')->listOfPeriods($start, $end);
|
||||||
$keyFormat = app('navigation')->preferredCarbonFormat($start, $end);
|
$keyFormat = app('navigation')->preferredCarbonFormat($start, $end);
|
||||||
|
|
||||||
|
|
||||||
// list expenses for budgets in account(s)
|
// list expenses for budgets in account(s)
|
||||||
$expenses = $opsRepository->listExpenses($start, $end, $accounts);
|
$expenses = $this->opsRepository->listExpenses($start, $end, $accounts);
|
||||||
|
|
||||||
$report = [];
|
$report = [];
|
||||||
foreach ($expenses as $currency) {
|
foreach ($expenses as $currency) {
|
||||||
@@ -363,9 +374,7 @@ class BudgetController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function topExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
public function topExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
// get all journals.
|
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
||||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
|
||||||
$spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($spent as $currency) {
|
foreach ($spent as $currency) {
|
||||||
$currencyId = $currency['currency_id'];
|
$currencyId = $currency['currency_id'];
|
||||||
|
@@ -125,8 +125,8 @@ class ReportController extends Controller
|
|||||||
trans(
|
trans(
|
||||||
'firefly.report_audit',
|
'firefly.report_audit',
|
||||||
[
|
[
|
||||||
'start' => $start->formatLocalized($this->monthFormat),
|
'start' => $start->formatLocalized($this->monthAndDayFormat),
|
||||||
'end' => $end->formatLocalized($this->monthFormat),
|
'end' => $end->formatLocalized($this->monthAndDayFormat),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -162,8 +162,8 @@ class ReportController extends Controller
|
|||||||
trans(
|
trans(
|
||||||
'firefly.report_budget',
|
'firefly.report_budget',
|
||||||
[
|
[
|
||||||
'start' => $start->formatLocalized($this->monthFormat),
|
'start' => $start->formatLocalized($this->monthAndDayFormat),
|
||||||
'end' => $end->formatLocalized($this->monthFormat),
|
'end' => $end->formatLocalized($this->monthAndDayFormat),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -200,8 +200,8 @@ class ReportController extends Controller
|
|||||||
trans(
|
trans(
|
||||||
'firefly.report_category',
|
'firefly.report_category',
|
||||||
[
|
[
|
||||||
'start' => $start->formatLocalized($this->monthFormat),
|
'start' => $start->formatLocalized($this->monthAndDayFormat),
|
||||||
'end' => $end->formatLocalized($this->monthFormat),
|
'end' => $end->formatLocalized($this->monthAndDayFormat),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -406,8 +406,8 @@ class ReportController extends Controller
|
|||||||
trans(
|
trans(
|
||||||
'firefly.report_tag',
|
'firefly.report_tag',
|
||||||
[
|
[
|
||||||
'start' => $start->formatLocalized($this->monthFormat),
|
'start' => $start->formatLocalized($this->monthAndDayFormat),
|
||||||
'end' => $end->formatLocalized($this->monthFormat),
|
'end' => $end->formatLocalized($this->monthAndDayFormat),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@@ -30,32 +30,6 @@ namespace FireflyIII\Support\Http\Controllers;
|
|||||||
trait BasicDataSupport
|
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).
|
* Find the ID in a given array. Return '0' of not there (amount).
|
||||||
|
Reference in New Issue
Block a user