Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix form inconsistencies.
James Colea32df0066ee2
diff --git a/app/Helpers/Collection/Balance.php b/app/Helpers/Collection/Balance.phpdeleted file mode 100644index 71573853ea..0000000000--- a/app/Helpers/Collection/Balance.php+++ /dev/null@@ -1,97 +0,0 @@-<?php-/**- * Balance.php- * Copyright (c) 2017 [email protected]- *- * This file is part of Firefly III.- *- * Firefly III is free software: you can redistribute it and/or modify- * it under the terms of the GNU General Public License as published by- * the Free Software Foundation, either version 3 of the License, or- * (at your option) any later version.- *- * Firefly III is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU General Public License for more details.- *- * You should have received a copy of the GNU General Public License- * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.- */-declare(strict_types=1);--namespace FireflyIII\Helpers\Collection;--use Illuminate\Support\Collection;--/**- * Class Balance.- *- * @codeCoverageIgnore- */-class Balance-{- /** @var BalanceHeader Header row. */- protected $balanceHeader;-- /** @var Collection Collection of lines. */- protected $balanceLines;-- /**- * Balance constructor.- */- public function __construct()- {- $this->balanceLines = new Collection;- }-- /**- * Add a line.- *- * @param BalanceLine $line- */- public function addBalanceLine(BalanceLine $line): void- {- $this->balanceLines->push($line);- }-- /**- * Get the header.- *- * @return BalanceHeader- */- public function getBalanceHeader(): BalanceHeader- {- return $this->balanceHeader ?? new BalanceHeader;- }-- /**- * Set the header.- *- * @param BalanceHeader $balanceHeader- */- public function setBalanceHeader(BalanceHeader $balanceHeader): void- {- $this->balanceHeader = $balanceHeader;- }-- /**- * Get all lines.- *- * @return Collection- */- public function getBalanceLines(): Collection- {- return $this->balanceLines;- }-- /**- * Set all lines.- *- * @param Collection $balanceLines- */- public function setBalanceLines(Collection $balanceLines): void- {- $this->balanceLines = $balanceLines;- }-}diff --git a/app/Helpers/Collection/BalanceEntry.php b/app/Helpers/Collection/BalanceEntry.phpdeleted file mode 100644index 86eddf607b..0000000000--- a/app/Helpers/Collection/BalanceEntry.php+++ /dev/null@@ -1,100 +0,0 @@-<?php-/**- * BalanceEntry.php- * Copyright (c) 2017 [email protected]- *- * This file is part of Firefly III.- *- * Firefly III is free software: you can redistribute it and/or modify- * it under the terms of the GNU General Public License as published by- * the Free Software Foundation, either version 3 of the License, or- * (at your option) any later version.- *- * Firefly III is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU General Public License for more details.- *- * You should have received a copy of the GNU General Public License- * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.- */-declare(strict_types=1);--namespace FireflyIII\Helpers\Collection;--use FireflyIII\Models\Account as AccountModel;--/**- * Class BalanceEntry.- *- * @codeCoverageIgnore- */-class BalanceEntry-{- /** @var AccountModel The account. */- protected $account;- /** @var string The amount left. */- protected $left = '0';- /** @var string The amount spent. */- protected $spent = '0';-- /**- * Account getter.- *- * @return AccountModel- */- public function getAccount(): AccountModel- {- return $this->account;- }-- /**- * Account setter.- *- * @param AccountModel $account- */- public function setAccount(AccountModel $account): void- {- $this->account = $account;- }-- /**- * Get amount left.- *- * @return string- */- public function getLeft(): string- {- return $this->left;- }-- /**- * Set amount left.- *- * @param string $left- */- public function setLeft(string $left): void- {- $this->left = $left;- }-- /**- * Get amount spent.- *- * @return string- */- public function getSpent(): string- {- return $this->spent;- }-- /**- * Set amount spent.- *- * @param string $spent- */- public function setSpent(string $spent): void- {- $this->spent = $spent;- }-}diff --git a/app/Helpers/Collection/BalanceHeader.php b/app/Helpers/Collection/BalanceHeader.phpdeleted file mode 100644index 3769b0f5c0..0000000000--- a/app/Helpers/Collection/BalanceHeader.php+++ /dev/null@@ -1,65 +0,0 @@-<?php-/**- * BalanceHeader.php- * Copyright (c) 2017 [email protected]- *- * This file is part of Firefly III.- *- * Firefly III is free software: you can redistribute it and/or modify- * it under the terms of the GNU General Public License as published by- * the Free Software Foundation, either version 3 of the License, or- * (at your option) any later version.- *- * Firefly III is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU General Public License for more details.- *- * You should have received a copy of the GNU General Public License- * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.- */-declare(strict_types=1);--namespace FireflyIII\Helpers\Collection;--use FireflyIII\Models\Account as AccountModel;-use Illuminate\Support\Collection;--/**- * Class BalanceHeader.- *- * @codeCoverageIgnore- */-class BalanceHeader-{- /** @var Collection The accounts. */- protected $accounts;-- /**- * BalanceHeader constructor.- */- public function __construct()- {- $this->accounts = new Collection;- }-- /**- * Add an account.- *- * @param AccountModel $account- */- public function addAccount(AccountModel $account): void- {- $this->accounts->push($account);- }-- /**- * Get them all.- *- * @return Collection- */- public function getAccounts(): Collection- {- return $this->accounts;- }-}diff --git a/app/Helpers/Collection/BalanceLine.php b/app/Helpers/Collection/BalanceLine.phpdeleted file mode 100644index 89668f0963..0000000000--- a/app/Helpers/Collection/BalanceLine.php+++ /dev/null@@ -1,189 +0,0 @@-<?php-/**- * BalanceLine.php- * Copyright (c) 2017 [email protected]- *- * This file is part of Firefly III.- *- * Firefly III is free software: you can redistribute it and/or modify- * it under the terms of the GNU General Public License as published by- * the Free Software Foundation, either version 3 of the License, or- * (at your option) any later version.- *- * Firefly III is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU General Public License for more details.- *- * You should have received a copy of the GNU General Public License- * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.- */-declare(strict_types=1);--namespace FireflyIII\Helpers\Collection;--use Carbon\Carbon;-use FireflyIII\Models\Budget as BudgetModel;-use FireflyIII\Models\BudgetLimit;-use Illuminate\Support\Collection;--/**- * Class BalanceLine.- *- * @codeCoverageIgnore- */-class BalanceLine-{- /**- *- */- public const ROLE_DEFAULTROLE = 1;- /**- *- */- public const ROLE_TAGROLE = 2;-- /** @var Collection */- protected $balanceEntries;-- /** @var BudgetModel */- protected $budget;- /** @var BudgetLimit */- protected $budgetLimit;- /** @var int */- protected $role = self::ROLE_DEFAULTROLE;-- /**- *- */- public function __construct()- {- $this->balanceEntries = new Collection;- }-- /**- * @param BalanceEntry $balanceEntry- */- public function addBalanceEntry(BalanceEntry $balanceEntry): void- {- $this->balanceEntries->push($balanceEntry);- }-- /**- * @return Collection- */- public function getBalanceEntries(): Collection- {- return $this->balanceEntries;- }-- /**- * @param Collection $balanceEntries- */- public function setBalanceEntries(Collection $balanceEntries): void- {- $this->balanceEntries = $balanceEntries;- }-- /**- * @return BudgetModel- */- public function getBudget(): BudgetModel- {- return $this->budget ?? new BudgetModel;- }-- /**- * @param BudgetModel $budget- */- public function setBudget(BudgetModel $budget): void- {- $this->budget = $budget;- }-- /**- * @return BudgetLimit- */- public function getBudgetLimit(): BudgetLimit- {- return $this->budgetLimit;- }-- /**- * @param BudgetLimit $budgetLimit- */- public function setBudgetLimit(BudgetLimit $budgetLimit): void- {- $this->budgetLimit = $budgetLimit;- }-- /**- * @return Carbon- */- public function getEndDate(): Carbon- {- return $this->budgetLimit->end_date ?? new Carbon;- }-- /**- * @return int- */- public function getRole(): int- {- return $this->role;- }-- /**- * @param int $role- */- public function setRole(int $role): void- {- $this->role = $role;- }-- /**- * @return Carbon- */- public function getStartDate(): Carbon- {- return $this->budgetLimit->start_date ?? new Carbon;- }-- /**- * @return string- */- public function getTitle(): string- {- $title = '';- if ($this->getBudget() instanceof BudgetModel && null !== $this->getBudget()->id) {- $title = $this->getBudget()->name;- }- if ('' === $title && self::ROLE_DEFAULTROLE === $this->getRole()) {- $title = (string)trans('firefly.no_budget');- }- if ('' === $title && self::ROLE_TAGROLE === $this->getRole()) {- $title = (string)trans('firefly.coveredWithTags');- }-- return $title;- }-- /**- * If a BalanceLine has a budget/repetition, each BalanceEntry in this BalanceLine- * should have a "spent" value, which is the amount of money that has been spent- * on the given budget/repetition. If you subtract all those amounts from the budget/repetition's- * total amount, this is returned:.- *- * @return string- */- public function leftOfRepetition(): string- {- $start = $this->budgetLimit->amount ?? '0';- /** @var BalanceEntry $balanceEntry */- foreach ($this->getBalanceEntries() as $balanceEntry) {- $start = bcadd($balanceEntry->getSpent(), $start);- }-- return $start;- }-}diff --git a/app/Helpers/Report/BalanceReportHelper.php b/app/Helpers/Report/BalanceReportHelper.phpindex 64d049983f..537586823f 100644--- a/app/Helpers/Report/BalanceReportHelper.php+++ b/app/Helpers/Report/BalanceReportHelper.php@@ -23,14 +23,9 @@ declare(strict_types=1);namespace FireflyIII\Helpers\Report;use Carbon\Carbon;-use FireflyIII\Helpers\Collection\Balance;-use FireflyIII\Helpers\Collection\BalanceEntry;-use FireflyIII\Helpers\Collection\BalanceHeader;-use FireflyIII\Helpers\Collection\BalanceLine;use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Models\Account;use FireflyIII\Models\Budget;-use FireflyIII\Models\BudgetLimit;use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;use Illuminate\Support\Collection;@@ -89,9 +84,6 @@ class BalanceReportHelper implements BalanceReportHelperInterface}$budgets = $this->budgetRepository->getBudgets();- // per budget, dan per balance line- // of als het in een balance line valt dan daaronder en anders niet- // kruistabel vullen?/** @var Budget $budget */foreach ($budgets as $budget) {@@ -144,131 +136,6 @@ class BalanceReportHelper implements BalanceReportHelperInterface$report['budgets'][$budgetId]['spent'] = $spent;// get transactions in budget}-return $report;- // do sums:--- echo '<pre>';- print_r($report);- exit;--- $balance = new Balance;- $header = new BalanceHeader;- $budgetLimits = $this->budgetRepository->getAllBudgetLimits($start, $end);- foreach ($accounts as $account) {- Log::debug(sprintf('Add account %s to headers.', $account->name));- $header->addAccount($account);- }-- /** @var BudgetLimit $budgetLimit */- foreach ($budgetLimits as $budgetLimit) {- if (null !== $budgetLimit->budget) {- $line = $this->createBalanceLine($budgetLimit, $accounts);- $balance->addBalanceLine($line);- }- }- $noBudgetLine = $this->createNoBudgetLine($accounts, $start, $end);-- $balance->addBalanceLine($noBudgetLine);- $balance->setBalanceHeader($header);-- Log::debug('Clear unused budgets.');- // remove budgets without expenses from balance lines:- $balance = $this->removeUnusedBudgets($balance);-- Log::debug('Return report.');-- return $balance;- }-- /**- * Create one balance line.- *- * @param BudgetLimit $budgetLimit- * @param Collection $accounts- *- * @return BalanceLine- */- private function createBalanceLine(BudgetLimit $budgetLimit, Collection $accounts): BalanceLine- {- $line = new BalanceLine;- $line->setBudget($budgetLimit->budget);- $line->setBudgetLimit($budgetLimit);-- // loop accounts:- foreach ($accounts as $account) {- $balanceEntry = new BalanceEntry;- $balanceEntry->setAccount($account);- $spent = $this->budgetRepository->spentInPeriod(- new Collection([$budgetLimit->budget]),- new Collection([$account]),- $budgetLimit->start_date,- $budgetLimit->end_date- );- $balanceEntry->setSpent($spent);- $line->addBalanceEntry($balanceEntry);- }-- return $line;- }-- /**- * Create a line for transactions without a budget.- *- * @param Collection $accounts- * @param Carbon $start- * @param Carbon $end- *- * @return BalanceLine- */- private function createNoBudgetLine(Collection $accounts, Carbon $start, Carbon $end): BalanceLine- {- $empty = new BalanceLine;-- foreach ($accounts as $account) {- $spent = $this->budgetRepository->spentInPeriodWoBudget(new Collection([$account]), $start, $end);- // budget- $budgetEntry = new BalanceEntry;- $budgetEntry->setAccount($account);- $budgetEntry->setSpent($spent);- $empty->addBalanceEntry($budgetEntry);- }-- return $empty;- }-- /**- * Remove unused budgets from the report.- *- * @SuppressWarnings(PHPMD.CyclomaticComplexity)- * @param Balance $balance- *- * @return Balance- */- private function removeUnusedBudgets(Balance $balance): Balance- {- $set = $balance->getBalanceLines();- $newSet = new Collection;- /** @var BalanceLine $entry */- foreach ($set as $entry) {- if (null !== $entry->getBudget()->id) {- $sum = '0';- /** @var BalanceEntry $balanceEntry */- foreach ($entry->getBalanceEntries() as $balanceEntry) {- $sum = bcadd($sum, $balanceEntry->getSpent());- }- if (bccomp($sum, '0') === -1) {- $newSet->push($entry);- }- continue;- }- $newSet->push($entry);- }-- $balance->setBalanceLines($newSet);-- return $balance;}}diff --git a/app/Http/Controllers/Report/BalanceController.php b/app/Http/Controllers/Report/BalanceController.phpindex 49a1b0748f..f9032ac989 100644--- a/app/Http/Controllers/Report/BalanceController.php+++ b/app/Http/Controllers/Report/BalanceController.php@@ -59,7 +59,6 @@ class BalanceController extends Controller$helper = app(BalanceReportHelperInterface::class);$report = $helper->getBalanceReport($accounts, $start, $end);// TODO no budget.- // TODO sum over account.// try {$result = view('reports.partials.balance', compact('report'))->render();// @codeCoverageIgnoreStartdiff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.phpindex 67339b4cb6..cd0d169443 100644--- a/app/Http/Controllers/Report/CategoryController.php+++ b/app/Http/Controllers/Report/CategoryController.php@@ -154,7 +154,6 @@ class CategoryController extends Controller** @return mixed|string*- * @SuppressWarnings(PHPMD.CyclomaticComplexity)*/public function operations(Collection $accounts, Carbon $start, Carbon $end){diff --git a/app/Http/Controllers/Report/ExpenseController.php b/app/Http/Controllers/Report/ExpenseController.phpindex 75dfcdeb70..171f81659b 100644--- a/app/Http/Controllers/Report/ExpenseController.php+++ b/app/Http/Controllers/Report/ExpenseController.php@@ -36,7 +36,6 @@ use Throwable;/*** Class ExpenseController*- * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)*/class ExpenseController extends Controller{@@ -128,8 +127,6 @@ class ExpenseController extends Controller* @param Carbon $end** @return string- * @SuppressWarnings(PHPMD.CyclomaticComplexity)- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function category(Collection $accounts, Collection $expense, Carbon $start, Carbon $end): string{diff --git a/resources/views/v1/reports/partials/balance.twig b/resources/views/v1/reports/partials/balance.twigindex bb2217c1ae..69a7cbc112 100644--- a/resources/views/v1/reports/partials/balance.twig+++ b/resources/views/v1/reports/partials/balance.twig@@ -3,7 +3,9 @@<tr><th>{{ 'budgets'|_ }}</th>{% for account in report.accounts %}+ {% if account.sum != 0 %}<th class="hidden-xs" style="text-align: right;"><a href="{{ route('accounts.show',account.id) }}" title="{{ account.iban|default(account.name) }}">{{ account.name }}</a></th>+ {% endif %}{% endfor %}<th style="text-align: right;">{{ 'sum'|_ }}</th></tr>@@ -11,6 +13,7 @@<tbody>{% for budget in report.budgets %}+ {% if budget.spent|length > 0 %}<tr><td><a href="{{ route('budgets.show', [budget.budget_id]) }}">{{ budget.budget_name }}</a>@@ -20,10 +23,6 @@<td style="text-align: right;">{{ formatAmountBySymbol(budget.spent[account.id].spent, budget.spent[account.id].currency_symbol, budget.spent[account.id].currency_decimal_places) }}</td>- {% else %}- <td>- - </td>{% endif %}{% endfor %}<td style="text-align: right;">@@ -32,13 +31,18 @@{% endfor %}</td></tr>+ {% endif %}{% endfor %}</tbody><tfoot><tr><td><em>{{ 'sum'|_ }}</em></td>{% for account in report.accounts %}- <td style="text-align: right;">{{ formatAmountBySymbol(account.sum, account.currency_symbol, account.currency_decimal_places) }}</td>+ {% if account.sum != 0 %}+ <td style="text-align: right;">+ {{ formatAmountBySymbol(account.sum, account.currency_symbol, account.currency_decimal_places) }}+ </td>+ {% endif %}{% endfor %}</tr></tfoot>