Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Use different method for finding objects.
James Cole54ba18975ad8
diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.phpindex a49e560c3c..1a690f11e3 100644--- a/app/Http/Controllers/Account/ReconcileController.php+++ b/app/Http/Controllers/Account/ReconcileController.php@@ -254,16 +254,14 @@ class ReconcileController extends Controller* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector* @throws FireflyException*/- public function submit(ReconciliationStoreRequest $request, Account $account, Carbon $start, Carbon $end)+ public function submit(ReconciliationStoreRequest $request, JournalRepositoryInterface $repository, Account $account, Carbon $start, Carbon $end){Log::debug('In ReconcileController::submit()');$data = $request->getAll();- /** @var TransactionUpdateService $service */- $service = app(TransactionUpdateService::class); // todo move to repos/** @var Transaction $transaction */foreach ($data['transactions'] as $transactionId) {- $service->reconcile(intval($transactionId));+ $repository->reconcileById(intval($transactionId));}Log::debug('Reconciled all transactions.');@@ -324,10 +322,7 @@ class ReconcileController extends Controller'notes' => join(', ', $data['transactions']),];- /** @var TransactionJournalFactory $factory */- $factory = app(TransactionJournalFactory::class); // todo move to repos- $factory->setUser(auth()->user());- $journal = $factory->create($journalData);+ $journal = $repository->store($journalData);}Log::debug('End of routine.');@@ -358,7 +353,7 @@ class ReconcileController extends Controller/** @var CurrencyRepositoryInterface $currencyRepos */$currencyRepos = app(CurrencyRepositoryInterface::class);$currencyId = intval($account->getMeta('currency_id'));- $currency = $currencyRepos->find($currencyId);+ $currency = $currencyRepos->findNull($currencyId);if (0 === $currencyId) {$currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore}@@ -403,8 +398,8 @@ class ReconcileController extends Controller$submitted = $request->getJournalData();// amount pos neg influences the accounts:- $source = $this->repository->getSourceAccount($journal);- $destination = $this->repository->getDestinationAccount($journal);+ $source = $this->repository->getJournalSourceAccounts($journal)->first();+ $destination = $this->repository->getJournalDestinationAccounts($journal)->first();if (bccomp($submitted['amount'], '0') === 1) {// amount is positive, switch accounts:list($source, $destination) = [$destination, $source];diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.phpindex 3c9df266ea..57a57ae19d 100644--- a/app/Http/Controllers/AccountController.php+++ b/app/Http/Controllers/AccountController.php@@ -185,7 +185,7 @@ class AccountController extends Controller// the opening balance is tricky:$openingBalanceAmount = strval($repository->getOpeningBalanceAmount($account));$openingBalanceDate = $repository->getOpeningBalanceDate($account);- $currency = $this->currencyRepos->find(intval($account->getMeta('currency_id')));+ $currency = $this->currencyRepos->findNull(intval($account->getMeta('currency_id')));$preFilled = ['accountNumber' => $account->getMeta('accountNumber'),@@ -304,7 +304,7 @@ class AccountController extends Controller$page = intval($request->get('page'));$pageSize = intval(Preferences::get('listPageSize', 50)->data);$currencyId = intval($account->getMeta('currency_id'));- $currency = $this->currencyRepos->find($currencyId);+ $currency = $this->currencyRepos->findNull($currencyId);if (0 === $currencyId) {$currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore}diff --git a/app/Http/Controllers/JavascriptController.php b/app/Http/Controllers/JavascriptController.phpindex afdbd59db9..bb991eb100 100644--- a/app/Http/Controllers/JavascriptController.php+++ b/app/Http/Controllers/JavascriptController.php@@ -47,7 +47,7 @@ class JavascriptController extends Controller{$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);$preference = Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR'));- $default = $currencyRepository->findByCode($preference->data);+ $default = $currencyRepository->findByCodeNull($preference->data);$data = ['accounts' => []];@@ -95,13 +95,13 @@ class JavascriptController extends Controller*/public function variables(Request $request, AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository){- $account = $repository->find(intval($request->get('account')));+ $account = $repository->findNull(intval($request->get('account')));$currencyId = 0;if (null !== $account) {$currencyId = intval($account->getMeta('currency_id'));}/** @var TransactionCurrency $currency */- $currency = $currencyRepository->find($currencyId);+ $currency = $currencyRepository->findNull($currencyId);if (0 === $currencyId) {$currency = app('amount')->getDefaultCurrency();}diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.phpindex c3f3485677..67204d993c 100644--- a/app/Http/Controllers/Json/BoxController.php+++ b/app/Http/Controllers/Json/BoxController.php@@ -206,7 +206,7 @@ class BoxController extends Controller$balance = $balances[$account->id] ?? '0';$currencyId = intval($account->getMeta('currency_id'));if ($currencyId !== 0) {- $accountCurrency = $currencyRepos->find($currencyId);+ $accountCurrency = $currencyRepos->findNull($currencyId);}if (!isset($netWorth[$accountCurrency->id])) {$netWorth[$accountCurrency->id]['currency'] = $accountCurrency;diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.phpindex ec5d20d1eb..1ab523747a 100644--- a/app/Http/Controllers/NewUserController.php+++ b/app/Http/Controllers/NewUserController.php@@ -85,9 +85,9 @@ class NewUserController extends Controller$this->createSavingsAccount($request, $repository);// also store currency preference from input:- $currency = $currencyRepository->find(intval($request->input('amount_currency_id_bank_balance')));+ $currency = $currencyRepository->findNull(intval($request->input('amount_currency_id_bank_balance')));- if (null !== $currency->id) {+ if (null !== $currency) {// store currency preference:Preferences::set('currencyPreference', $currency->code);Preferences::mark();diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.phpindex 725957ed10..9541162376 100644--- a/app/Http/Controllers/Transaction/ConvertController.php+++ b/app/Http/Controllers/Transaction/ConvertController.php@@ -199,7 +199,7 @@ class ConvertController extends Controllerbreak;case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER:// two- $destination = $accountRepository->find(intval($data['destination_account_asset']));+ $destination = $accountRepository->findNull(intval($data['destination_account_asset']));break;case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL:case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL:@@ -276,7 +276,7 @@ class ConvertController extends Controller$source = $destinationAccount;break;case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER:- $source = $accountRepository->find(intval($data['source_account_asset']));+ $source = $accountRepository->findNull(intval($data['source_account_asset']));break;}diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.phpindex 21a2f3c542..7919344687 100644--- a/app/Http/Controllers/Transaction/MassController.php+++ b/app/Http/Controllers/Transaction/MassController.php@@ -148,13 +148,13 @@ class MassController extends Controller$messages[] = trans('firefly.cannot_edit_multiple_dest', ['description' => $journal->description, 'id' => $journal->id]);continue;}- if (TransactionType::OPENING_BALANCE === $journal->transactionType->type) {+ if (TransactionType::OPENING_BALANCE === $this->repository->getTransactionType($journal)) {$messages[] = trans('firefly.cannot_edit_opening_balance');continue;}// cannot edit reconciled transactions / journals:- if ($journal->transactions->first()->reconciled) {+ if ($this->repository->isJournalReconciled($journal)) {$messages[] = trans('firefly.cannot_edit_reconciled', ['description' => $journal->description, 'id' => $journal->id]);continue;}@@ -172,7 +172,7 @@ class MassController extends Controller// collect some useful meta data for the mass edit:$filtered->each(function (TransactionJournal $journal) {- $transaction = $journal->positiveTransaction();+ $transaction = $this->repository->getFirstPosTransaction($journal);$currency = $transaction->transactionCurrency;$journal->amount = floatval($transaction->amount);$sources = $this->repository->getJournalSourceAccounts($journal);@@ -205,6 +205,8 @@ class MassController extends Controller}/**+ * TODO this cannot work with new update service.+ ** @param MassEditJournalRequest $request* @param JournalRepositoryInterface $repository*@@ -219,7 +221,7 @@ class MassController extends Controller$journal = $repository->find(intval($journalId));if (!is_null($journal)) {// get optional fields:- $what = strtolower($journal->transactionTypeStr());+ $what = strtolower($this->repository->getTransactionType($journal));$sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0;$sourceAccountName = $request->get('source_account_name')[$journal->id] ?? '';$destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0;diff --git a/app/Http/Controllers/Transaction/SingleController.php b/app/Http/Controllers/Transaction/SingleController.phpindex 4411830bf6..8dd3023290 100644--- a/app/Http/Controllers/Transaction/SingleController.php+++ b/app/Http/Controllers/Transaction/SingleController.php@@ -424,7 +424,7 @@ class SingleController extends Controllerevent(new UpdatedTransactionJournal($journal));// update, get events by date and sort DESC- $type = strtolower($journal->transactionTypeStr());+ $type = strtolower($this->repository->getTransactionType($journal));Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => $data['description']])));Preferences::mark();diff --git a/app/Http/Requests/LinkTypeFormRequest.php b/app/Http/Requests/LinkTypeFormRequest.phpindex f530fc299f..79fef825ff 100644--- a/app/Http/Requests/LinkTypeFormRequest.php+++ b/app/Http/Requests/LinkTypeFormRequest.php@@ -44,12 +44,13 @@ class LinkTypeFormRequest extends Requestpublic function rules(){// fixed-- /** @var LinkTypeRepositoryInterface $repository */- $repository = app(LinkTypeRepositoryInterface::class);$nameRule = 'required|min:1|unique:link_types,name';$idRule = '';- if (null !== $repository->find($this->integer('id'))->id) {++ // get parameter link:+ $link = $this->route()->parameter('linkType');++ if (null !== $link) {$idRule = 'exists:link_types,id';$nameRule = 'required|min:1';}diff --git a/app/Http/Requests/ReportFormRequest.php b/app/Http/Requests/ReportFormRequest.phpindex 728071c7d7..9d57443286 100644--- a/app/Http/Requests/ReportFormRequest.php+++ b/app/Http/Requests/ReportFormRequest.php@@ -57,8 +57,8 @@ class ReportFormRequest extends Request$collection = new Collection;if (is_array($set)) {foreach ($set as $accountId) {- $account = $repository->find(intval($accountId));- if (null !== $account->id) {+ $account = $repository->findNull(intval($accountId));+ if (null !== $account) {$collection->push($account);}}@@ -78,8 +78,8 @@ class ReportFormRequest extends Request$collection = new Collection;if (is_array($set)) {foreach ($set as $budgetId) {- $budget = $repository->find(intval($budgetId));- if (null !== $budget->id) {+ $budget = $repository->findNull(intval($budgetId));+ if (null !== $budget) {$collection->push($budget);}}@@ -99,8 +99,8 @@ class ReportFormRequest extends Request$collection = new Collection;if (is_array($set)) {foreach ($set as $categoryId) {- $category = $repository->find(intval($categoryId));- if (null !== $category->id) {+ $category = $repository->findNull(intval($categoryId));+ if (null !== $category) {$collection->push($category);}}@@ -142,8 +142,8 @@ class ReportFormRequest extends Request$collection = new Collection;if (is_array($set)) {foreach ($set as $accountId) {- $account = $repository->find(intval($accountId));- if (null !== $account->id) {+ $account = $repository->findNull(intval($accountId));+ if (null !== $account) {$collection->push($account);}}