Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Cleanup transaction journal edit. #215
James Cole201790ff8dd5
diff --git a/app/Helpers/Collection/BalanceLine.php b/app/Helpers/Collection/BalanceLine.phpindex e6157f6c06..a57a7b403b 100644--- a/app/Helpers/Collection/BalanceLine.php+++ b/app/Helpers/Collection/BalanceLine.php@@ -102,7 +102,7 @@ class BalanceLinereturn $this->getBudget()->name;}if ($this->getRole() == self::ROLE_DEFAULTROLE) {- return trans('firefly.noBudget');+ return trans('firefly.no_budget');}if ($this->getRole() == self::ROLE_TAGROLE) {return trans('firefly.coveredWithTags');diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.phpindex 18a61759d2..54dd637839 100644--- a/app/Http/Controllers/Chart/BudgetController.php+++ b/app/Http/Controllers/Chart/BudgetController.php@@ -198,7 +198,7 @@ class BudgetController extends Controller}$noBudgetExpenses = $repository->getWithoutBudgetSum($accounts, $start, $end);- $allEntries->push([trans('firefly.noBudget'), '0', '0', $noBudgetExpenses, '0', '0']);+ $allEntries->push([trans('firefly.no_budget'), '0', '0', $noBudgetExpenses, '0', '0']);$data = $this->generator->frontpage($allEntries);$cache->store($data);@@ -258,7 +258,7 @@ class BudgetController extends Controller// basic information:$year = $currentStart->year;- $entry['name'] = $budget->name ?? (string)trans('firefly.noBudget');+ $entry['name'] = $budget->name ?? (string)trans('firefly.no_budget');$spent = 0;// this might be a good moment to collect no budget stuff.if (is_null($budget->id)) {diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.phpindex a4848f07de..a0971dd904 100644--- a/app/Http/Controllers/TransactionController.php+++ b/app/Http/Controllers/TransactionController.php@@ -7,7 +7,6 @@ use Config;use ExpandedForm;use FireflyIII\Events\TransactionJournalStored;use FireflyIII\Events\TransactionJournalUpdated;-use FireflyIII\Exceptions\FireflyException;use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;use FireflyIII\Http\Requests\JournalFormRequest;use FireflyIII\Models\PiggyBank;@@ -16,7 +15,9 @@ use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;+use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;use FireflyIII\Repositories\Journal\JournalRepositoryInterface;+use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;use Illuminate\Support\Collection;use Input;use Preferences;@@ -57,7 +58,7 @@ class TransactionController extends Controller$uploadSize = min($maxFileSize, $maxPostSize);$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());- $budgets[0] = trans('form.noBudget');+ $budgets[0] = trans('firefly.no_budget');$piggyBanks = Auth::user()->piggyBanks()->orderBy('order', 'ASC')->get();/** @var PiggyBank $piggy */foreach ($piggyBanks as $piggy) {@@ -131,53 +132,45 @@ class TransactionController extends Controller}/**- * Shows the view to edit a transaction.- *- * @param ARI $repository* @param TransactionJournal $journal*- * @return $this- * @throws FireflyException+ * @return mixed*/- public function edit(ARI $repository, TransactionJournal $journal)+ public function edit(TransactionJournal $journal){- $maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));- $maxPostSize = Steam::phpBytes(ini_get('post_max_size'));- $uploadSize = min($maxFileSize, $maxPostSize);- $what = strtolower(TransactionJournal::transactionTypeStr($journal));- $accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));- $budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());- $budgets[0] = trans('form.noBudget');- $piggies = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get());- $piggies[0] = trans('form.noPiggybank');- $subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);- $preFilled = [- 'date' => $journal->date->format('Y-m-d'),- 'interest_date' => $journal->interest_date ? $journal->interest_date->format('Y-m-d') : '',- 'book_date' => $journal->book_date ? $journal->book_date->format('Y-m-d') : '',- 'process_date' => $journal->process_date ? $journal->process_date->format('Y-m-d') : '',- 'category' => '',- 'budget_id' => 0,- 'piggy_bank_id' => 0,- 'tags' => join(',', $journal->tags->pluck('tag')->toArray()),+ /** @var ARI $accountRepository */+ $accountRepository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');+ /** @var BudgetRepositoryInterface $budgetRepository */+ $budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');+ /** @var PiggyBankRepositoryInterface $piggyRepository */+ $piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');++ $accountList = ExpandedForm::makeSelectList($accountRepository->getAccounts(['Default account', 'Asset account']));+ $budgetList = ExpandedForm::makeSelectList($budgetRepository->getActiveBudgets());+ $piggyBankList = ExpandedForm::makeSelectList($piggyRepository->getPiggyBanks());+ $budgetList[0] = trans('firefly.no_budget');+ $piggyBankList[0] = trans('form.noPiggybank');+ $maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));+ $maxPostSize = Steam::phpBytes(ini_get('post_max_size'));+ $uploadSize = min($maxFileSize, $maxPostSize);+ $what = strtolower(TransactionJournal::transactionTypeStr($journal));+ $subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);+++ $preFilled = [+ 'date' => TransactionJournal::dateAsString($journal),+ 'interest_date' => TransactionJournal::dateAsString($journal, 'interest_date'),+ 'book_date' => TransactionJournal::dateAsString($journal, 'book_date'),+ 'process_date' => TransactionJournal::dateAsString($journal, 'process_date'),+ 'category' => TransactionJournal::categoryAsString($journal),+ 'budget_id' => TransactionJournal::budgetId($journal),+ 'piggy_bank_id' => TransactionJournal::piggyBankId($journal),+ 'tags' => join(',', $journal->tags->pluck('tag')->toArray()),+ 'account_from_id' => TransactionJournal::sourceAccount($journal)->id,+ 'account_to_id' => TransactionJournal::destinationAccount($journal)->id,+ 'amount' => TransactionJournal::amountPositive($journal),];- $category = $journal->categories()->first();- if (!is_null($category)) {- $preFilled['category'] = $category->name;- }-- $budget = $journal->budgets()->first();- if (!is_null($budget)) {- $preFilled['budget_id'] = $budget->id;- }-- if ($journal->piggyBankEvents()->count() > 0) {- $preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id;- }-- $preFilled['amount'] = TransactionJournal::amountPositive($journal);-if ($journal->isWithdrawal()) {$preFilled['account_id'] = TransactionJournal::sourceAccount($journal)->id;if (TransactionJournal::destinationAccountTypeStr($journal) != 'Cash account') {@@ -190,8 +183,6 @@ class TransactionController extends Controller}}- $preFilled['account_from_id'] = TransactionJournal::sourceAccount($journal)->id;- $preFilled['account_to_id'] = TransactionJournal::destinationAccount($journal)->id;Session::flash('preFilled', $preFilled);Session::flash('gaEventCategory', 'transactions');@@ -204,7 +195,9 @@ class TransactionController extends ControllerSession::forget('transactions.edit.fromUpdate');- return view('transactions.edit', compact('journal', 'uploadSize', 'accounts', 'what', 'budgets', 'piggies', 'subTitle'))->with('data', $preFilled);+ return view('transactions.edit', compact('journal', 'uploadSize', 'accountList', 'what', 'budgetList', 'piggyBankList', 'subTitle'))->with(+ 'data', $preFilled+ );}/**diff --git a/app/Support/Models/TransactionJournalSupport.php b/app/Support/Models/TransactionJournalSupport.phpindex 53688699a0..75fe75ac4f 100644--- a/app/Support/Models/TransactionJournalSupport.php+++ b/app/Support/Models/TransactionJournalSupport.php@@ -10,6 +10,7 @@namespace FireflyIII\Support\Models;+use Carbon\Carbon;use FireflyIII\Models\Account;use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;@@ -79,6 +80,56 @@ class TransactionJournalSupport extends Modelreturn $amount;}+ /**+ * @param TransactionJournal $journal+ *+ * @return int+ */+ public static function budgetId(TransactionJournal $journal): int+ {+ $budget = $journal->budgets()->first();+ if (!is_null($budget)) {+ return $budget->id;+ }++ return 0;+ }++ /**+ * @param TransactionJournal $journal+ *+ * @return string+ */+ public static function categoryAsString(TransactionJournal $journal): string+ {+ $category = $journal->categories()->first();+ if (!is_null($category)) {+ return $category->name;+ }++ return '';+ }++ /**+ * @param TransactionJournal $journal+ * @param string $dateField+ *+ * @return string+ */+ public static function dateAsString(TransactionJournal $journal, string $dateField = ''): string+ {+ if ($dateField === '') {+ return $journal->date->format('Y-m-d');+ }+ if (!is_null($journal->$dateField) && $journal->$dateField instanceof Carbon) {+ return $journal->$dateField->format('Y-m-d');+ }++ return '';+++ }+/*** @param TransactionJournal $journal*@@ -147,6 +198,20 @@ class TransactionJournalSupport extends Modelreturn false;}+ /**+ * @param TransactionJournal $journal+ *+ * @return int+ */+ public static function piggyBankId(TransactionJournal $journal): int+ {+ if ($journal->piggyBankEvents()->count() > 0) {+ return $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id;+ }++ return 0;+ }+/*** @param TransactionJournal $journal*diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex 483621962c..bc4064ba9e 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -650,7 +650,7 @@ return ['earned' => 'Earned','overspent' => 'Overspent','left' => 'Left',- 'noBudget' => '(no budget)',+ 'no_budget' => '(no budget)','maxAmount' => 'Maximum amount','minAmount' => 'Minumum amount','billEntry' => 'Current bill entry',diff --git a/resources/lang/en_US/form.php b/resources/lang/en_US/form.phpindex 5361c8daac..85263d00ed 100644--- a/resources/lang/en_US/form.php+++ b/resources/lang/en_US/form.php@@ -74,7 +74,6 @@ return ['add_new_deposit' => 'Add a new deposit','add_new_transfer' => 'Add a new transfer','noPiggybank' => '(no piggy bank)',- 'noBudget' => '(no budget)','title' => 'Title','notes' => 'Notes','filename' => 'File name',diff --git a/resources/views/reports/default/multi-year.twig b/resources/views/reports/default/multi-year.twigindex 1019861620..f08c3a7cc4 100644--- a/resources/views/reports/default/multi-year.twig+++ b/resources/views/reports/default/multi-year.twig@@ -100,7 +100,7 @@<div class="row"><div class="col-lg-12"><label class="checkbox-inline">- <input type="checkbox" class="budget-checkbox" name="budgets[]" value="0"> {{ 'noBudget'|_ }}+ <input type="checkbox" class="budget-checkbox" name="budgets[]" value="0"> {{ 'no_budget'|_ }}</label>{% for budget in budgets %}<label class="checkbox-inline">diff --git a/resources/views/reports/partials/budgets.twig b/resources/views/reports/partials/budgets.twigindex 0f21038bef..c42b375b77 100644--- a/resources/views/reports/partials/budgets.twig+++ b/resources/views/reports/partials/budgets.twig@@ -22,7 +22,7 @@{% if budgetLine.getBudget.id %}<a href="{{ route('budgets.show',budgetLine.getBudget.id) }}">{{ budgetLine.getBudget.name }}</a>{% else %}- <em>{{ 'noBudget'|_ }}</em>+ <em>{{ 'no_budget'|_ }}</em>{% endif %}</td><td>diff --git a/resources/views/transactions/edit.twig b/resources/views/transactions/edit.twigindex 4ae4ce0b47..e342dcf81e 100644--- a/resources/views/transactions/edit.twig+++ b/resources/views/transactions/edit.twig@@ -24,7 +24,7 @@<!-- SHOW ACCOUNT (FROM) ONLY FOR WITHDRAWALS AND DEPOSITS -->{% if what == 'deposit' or what == 'withdrawal' %}- {{ ExpandedForm.select('account_id',accounts,data['account_id']) }}+ {{ ExpandedForm.select('account_id',accountList,data['account_id']) }}{% endif %}<!-- SHOW EXPENSE ACCOUNT ONLY FOR WITHDRAWALS -->@@ -39,8 +39,8 @@<!-- ONLY SHOW FROM/TO ACCOUNT WHEN CREATING TRANSFER -->{% if what == 'transfer' %}- {{ ExpandedForm.select('account_from_id',accounts,data['account_from_id']) }}- {{ ExpandedForm.select('account_to_id',accounts,data['account_to_id']) }}+ {{ ExpandedForm.select('account_from_id',accountList,data['account_from_id']) }}+ {{ ExpandedForm.select('account_to_id',accountList,data['account_to_id']) }}{% endif %}<!-- ALWAYS SHOW AMOUNT -->@@ -61,7 +61,7 @@<div class="box-body"><!-- BUDGET ONLY WHEN CREATING A WITHDRAWAL -->{% if what == 'withdrawal' %}- {{ ExpandedForm.select('budget_id',budgets,data['budget_id']) }}+ {{ ExpandedForm.select('budget_id',budgetList,data['budget_id']) }}{% endif %}<!-- CATEGORY ALWAYS -->@@ -80,8 +80,8 @@{{ ExpandedForm.text('tags') }}<!-- RELATE THIS TRANSFER TO A PIGGY BANK -->- {% if what == 'withdrawal' and piggies|length > 0 %}- {{ ExpandedForm.select('piggy_bank_id',piggies,data['piggy_bank_id']) }}+ {% if what == 'transfer' and piggyBankList|length > 0 %}+ {{ ExpandedForm.select('piggy_bank_id',piggyBankList,data['piggy_bank_id']) }}{% endif %}<!-- ATTACHMENTS -->