mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-18 02:03:40 +00:00
Various code cleanup and fixed alignments.
This commit is contained in:
@@ -76,7 +76,7 @@ class BudgetReportGenerator
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($this->accounts as $account) {
|
||||
$accountId = $account->id;
|
||||
$accountId = $account->id;
|
||||
$this->report[$accountId] ??= [
|
||||
'name' => $account->name,
|
||||
'id' => $account->id,
|
||||
@@ -177,7 +177,7 @@ class BudgetReportGenerator
|
||||
??= '0';
|
||||
|
||||
$this->report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budgetId]
|
||||
= bcadd($this->report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budgetId], $journal['amount']);
|
||||
= bcadd($this->report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budgetId], $journal['amount']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ class BudgetReportGenerator
|
||||
*/
|
||||
private function processBudget(Budget $budget): void
|
||||
{
|
||||
$budgetId = $budget->id;
|
||||
$budgetId = $budget->id;
|
||||
$this->report['budgets'][$budgetId] ??= [
|
||||
'budget_id' => $budgetId,
|
||||
'budget_name' => $budget->name,
|
||||
@@ -208,7 +208,7 @@ class BudgetReportGenerator
|
||||
];
|
||||
|
||||
// get all budget limits for budget in period:
|
||||
$limits = $this->blRepository->getBudgetLimits($budget, $this->start, $this->end);
|
||||
$limits = $this->blRepository->getBudgetLimits($budget, $this->start, $this->end);
|
||||
|
||||
/** @var BudgetLimit $limit */
|
||||
foreach ($limits as $limit) {
|
||||
@@ -221,14 +221,14 @@ class BudgetReportGenerator
|
||||
*/
|
||||
private function processLimit(Budget $budget, BudgetLimit $limit): void
|
||||
{
|
||||
$budgetId = $budget->id;
|
||||
$limitId = $limit->id;
|
||||
$limitCurrency = $limit->transactionCurrency ?? $this->currency;
|
||||
$currencyId = $limitCurrency->id;
|
||||
$expenses = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, $this->accounts, new Collection([$budget]));
|
||||
$spent = $expenses[$currencyId]['sum'] ?? '0';
|
||||
$left = -1 === bccomp(bcadd($limit->amount, $spent), '0') ? '0' : bcadd($limit->amount, $spent);
|
||||
$overspent = 1 === bccomp(bcmul($spent, '-1'), $limit->amount) ? bcadd($spent, $limit->amount) : '0';
|
||||
$budgetId = $budget->id;
|
||||
$limitId = $limit->id;
|
||||
$limitCurrency = $limit->transactionCurrency ?? $this->currency;
|
||||
$currencyId = $limitCurrency->id;
|
||||
$expenses = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, $this->accounts, new Collection([$budget]));
|
||||
$spent = $expenses[$currencyId]['sum'] ?? '0';
|
||||
$left = -1 === bccomp(bcadd($limit->amount, $spent), '0') ? '0' : bcadd($limit->amount, $spent);
|
||||
$overspent = 1 === bccomp(bcmul($spent, '-1'), $limit->amount) ? bcadd($spent, $limit->amount) : '0';
|
||||
|
||||
$this->report['budgets'][$budgetId]['budget_limits'][$limitId] ??= [
|
||||
'budget_limit_id' => $limitId,
|
||||
@@ -249,7 +249,7 @@ class BudgetReportGenerator
|
||||
|
||||
// make sum information:
|
||||
$this->report['sums'][$currencyId]
|
||||
??= [
|
||||
??= [
|
||||
'budgeted' => '0',
|
||||
'spent' => '0',
|
||||
'left' => '0',
|
||||
@@ -279,16 +279,16 @@ class BudgetReportGenerator
|
||||
'budget_limits' => [],
|
||||
];
|
||||
|
||||
$noBudget = $this->nbRepository->sumExpenses($this->start, $this->end, $this->accounts);
|
||||
$noBudget = $this->nbRepository->sumExpenses($this->start, $this->end, $this->accounts);
|
||||
foreach ($noBudget as $noBudgetEntry) {
|
||||
// currency information:
|
||||
$nbCurrencyId = (int)($noBudgetEntry['currency_id'] ?? $this->currency->id);
|
||||
$nbCurrencyCode = $noBudgetEntry['currency_code'] ?? $this->currency->code;
|
||||
$nbCurrencyName = $noBudgetEntry['currency_name'] ?? $this->currency->name;
|
||||
$nbCurrencySymbol = $noBudgetEntry['currency_symbol'] ?? $this->currency->symbol;
|
||||
$nbCurrencyDp = $noBudgetEntry['currency_decimal_places'] ?? $this->currency->decimal_places;
|
||||
$nbCurrencyId = (int)($noBudgetEntry['currency_id'] ?? $this->currency->id);
|
||||
$nbCurrencyCode = $noBudgetEntry['currency_code'] ?? $this->currency->code;
|
||||
$nbCurrencyName = $noBudgetEntry['currency_name'] ?? $this->currency->name;
|
||||
$nbCurrencySymbol = $noBudgetEntry['currency_symbol'] ?? $this->currency->symbol;
|
||||
$nbCurrencyDp = $noBudgetEntry['currency_decimal_places'] ?? $this->currency->decimal_places;
|
||||
|
||||
$this->report['budgets'][0]['budget_limits'][] = [
|
||||
$this->report['budgets'][0]['budget_limits'][] = [
|
||||
'budget_limit_id' => null,
|
||||
'start_date' => $this->start,
|
||||
'end_date' => $this->end,
|
||||
@@ -304,7 +304,7 @@ class BudgetReportGenerator
|
||||
'currency_symbol' => $nbCurrencySymbol,
|
||||
'currency_decimal_places' => $nbCurrencyDp,
|
||||
];
|
||||
$this->report['sums'][$nbCurrencyId]['spent'] = bcadd($this->report['sums'][$nbCurrencyId]['spent'] ?? '0', $noBudgetEntry['sum']);
|
||||
$this->report['sums'][$nbCurrencyId]['spent'] = bcadd($this->report['sums'][$nbCurrencyId]['spent'] ?? '0', $noBudgetEntry['sum']);
|
||||
// append currency info because it may be missing:
|
||||
$this->report['sums'][$nbCurrencyId]['currency_id'] = $nbCurrencyId;
|
||||
$this->report['sums'][$nbCurrencyId]['currency_code'] = $nbCurrencyCode;
|
||||
@@ -327,15 +327,15 @@ class BudgetReportGenerator
|
||||
// make percentages based on total amount.
|
||||
foreach ($this->report['budgets'] as $budgetId => $data) {
|
||||
foreach ($data['budget_limits'] as $limitId => $entry) {
|
||||
$budgetId = (int)$budgetId;
|
||||
$limitId = (int)$limitId;
|
||||
$currencyId = (int)$entry['currency_id'];
|
||||
$spent = $entry['spent'];
|
||||
$totalSpent = $this->report['sums'][$currencyId]['spent'] ?? '0';
|
||||
$spentPct = '0';
|
||||
$budgeted = $entry['budgeted'];
|
||||
$totalBudgeted = $this->report['sums'][$currencyId]['budgeted'] ?? '0';
|
||||
$budgetedPct = '0';
|
||||
$budgetId = (int)$budgetId;
|
||||
$limitId = (int)$limitId;
|
||||
$currencyId = (int)$entry['currency_id'];
|
||||
$spent = $entry['spent'];
|
||||
$totalSpent = $this->report['sums'][$currencyId]['spent'] ?? '0';
|
||||
$spentPct = '0';
|
||||
$budgeted = $entry['budgeted'];
|
||||
$totalBudgeted = $this->report['sums'][$currencyId]['budgeted'] ?? '0';
|
||||
$budgetedPct = '0';
|
||||
|
||||
if (0 !== bccomp($spent, '0') && 0 !== bccomp($totalSpent, '0')) {
|
||||
$spentPct = round((float)bcmul(bcdiv($spent, $totalSpent), '100'));
|
||||
@@ -343,7 +343,7 @@ class BudgetReportGenerator
|
||||
if (0 !== bccomp($budgeted, '0') && 0 !== bccomp($totalBudgeted, '0')) {
|
||||
$budgetedPct = round((float)bcmul(bcdiv($budgeted, $totalBudgeted), '100'));
|
||||
}
|
||||
$this->report['sums'][$currencyId]['budgeted'] ??= '0';
|
||||
$this->report['sums'][$currencyId]['budgeted'] ??= '0';
|
||||
$this->report['budgets'][$budgetId]['budget_limits'][$limitId]['spent_pct'] = $spentPct;
|
||||
$this->report['budgets'][$budgetId]['budget_limits'][$limitId]['budgeted_pct'] = $budgetedPct;
|
||||
}
|
||||
|
Reference in New Issue
Block a user