Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Various code cleanup.
James Cole6660306ac4b2
diff --git a/app/Api/V1/Requests/TransactionRequest.php b/app/Api/V1/Requests/TransactionRequest.phpindex dcc4b8e322..efef5a3658 100644--- a/app/Api/V1/Requests/TransactionRequest.php+++ b/app/Api/V1/Requests/TransactionRequest.php@@ -224,7 +224,7 @@ class TransactionRequest extends Requestreturn $first;}- $account = $repository->findByName($accountName, [AccountType::ASSET]);+ $account = $repository->findByNameNull($accountName, [AccountType::ASSET]);if (is_null($account)) {$validator->errors()->add($nameField, trans('validation.belongs_user'));diff --git a/app/Export/Collector/UploadCollector.php b/app/Export/Collector/UploadCollector.phpindex 7100c35287..9f4a932fec 100644--- a/app/Export/Collector/UploadCollector.php+++ b/app/Export/Collector/UploadCollector.php@@ -23,8 +23,8 @@ declare(strict_types=1);namespace FireflyIII\Export\Collector;use Crypt;+use Exception;use Illuminate\Contracts\Encryption\DecryptException;-use Illuminate\Contracts\Filesystem\FileNotFoundException;use Log;use Storage;@@ -99,7 +99,7 @@ class UploadCollector extends BasicCollector implements CollectorInterface$content = '';try {$content = Crypt::decrypt($this->uploadDisk->get(sprintf('%s.upload', $key)));- } catch (FileNotFoundException | DecryptException $e) {+ } catch (Exception | DecryptException $e) {Log::error(sprintf('Could not decrypt old import file "%s". Skipped because: %s', $key, $e->getMessage()));}diff --git a/app/Factory/AccountFactory.php b/app/Factory/AccountFactory.phpindex dd9cf10589..13ddf7a626 100644--- a/app/Factory/AccountFactory.php+++ b/app/Factory/AccountFactory.php@@ -43,6 +43,7 @@ class AccountFactory* @param array $data** @return Account+ * @throws \FireflyIII\Exceptions\FireflyException*/public function create(array $data): Account{diff --git a/app/Factory/TransactionCurrencyFactory.php b/app/Factory/TransactionCurrencyFactory.phpindex c73fe74f93..db6972f2e4 100644--- a/app/Factory/TransactionCurrencyFactory.php+++ b/app/Factory/TransactionCurrencyFactory.php@@ -30,6 +30,26 @@ use FireflyIII\Models\TransactionCurrency;*/class TransactionCurrencyFactory{+ /**+ * @param array $data+ *+ * @return TransactionCurrency+ */+ public function create(array $data): TransactionCurrency+ {+ /** @var TransactionCurrency $currency */+ $currency = TransactionCurrency::create(+ [+ 'name' => $data['name'],+ 'code' => $data['code'],+ 'symbol' => $data['symbol'],+ 'decimal_places' => $data['decimal_places'],+ ]+ );++ return $currency;+ }+/*** @param int|null $currencyId* @param null|string $currencyCodediff --git a/app/Generator/Report/Audit/MonthReportGenerator.php b/app/Generator/Report/Audit/MonthReportGenerator.phpindex 9bdf1b28be..e8d9205417 100644--- a/app/Generator/Report/Audit/MonthReportGenerator.php+++ b/app/Generator/Report/Audit/MonthReportGenerator.php@@ -45,6 +45,7 @@ class MonthReportGenerator implements ReportGeneratorInterface/*** @return string+ * @throws \Throwable*/public function generate(): string{diff --git a/app/Generator/Report/Budget/MonthReportGenerator.php b/app/Generator/Report/Budget/MonthReportGenerator.phpindex adf6639de0..ad26a9d435 100644--- a/app/Generator/Report/Budget/MonthReportGenerator.php+++ b/app/Generator/Report/Budget/MonthReportGenerator.php@@ -63,6 +63,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface/*** @return string+ * @throws \Throwable*/public function generate(): string{diff --git a/app/Generator/Report/Category/MonthReportGenerator.php b/app/Generator/Report/Category/MonthReportGenerator.phpindex 7977f83d0a..0b32b11007 100644--- a/app/Generator/Report/Category/MonthReportGenerator.php+++ b/app/Generator/Report/Category/MonthReportGenerator.php@@ -64,6 +64,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface/*** @return string+ * @throws \Throwable*/public function generate(): string{diff --git a/app/Handlers/Events/StoredJournalEventHandler.php b/app/Handlers/Events/StoredJournalEventHandler.phpindex 65f73c5573..6cfb5ad600 100644--- a/app/Handlers/Events/StoredJournalEventHandler.php+++ b/app/Handlers/Events/StoredJournalEventHandler.php@@ -66,6 +66,7 @@ class StoredJournalEventHandler* @param StoredTransactionJournal $storedJournalEvent** @return bool+ * @throws \FireflyIII\Exceptions\FireflyException*/public function processRules(StoredTransactionJournal $storedJournalEvent): bool{diff --git a/app/Handlers/Events/UpdatedJournalEventHandler.php b/app/Handlers/Events/UpdatedJournalEventHandler.phpindex a99a078374..4b1ee5b3ff 100644--- a/app/Handlers/Events/UpdatedJournalEventHandler.php+++ b/app/Handlers/Events/UpdatedJournalEventHandler.php@@ -51,11 +51,11 @@ class UpdatedJournalEventHandler/*** This method will check all the rules when a journal is updated.- * TODO move to factory.** @param UpdatedTransactionJournal $updatedJournalEvent** @return bool+ * @throws \FireflyIII\Exceptions\FireflyException*/public function processRules(UpdatedTransactionJournal $updatedJournalEvent): bool{@@ -82,7 +82,6 @@ class UpdatedJournalEventHandler/*** This method calls a special bill scanner that will check if the updated journal is part of a bill.- * TODO move to factory.** @param UpdatedTransactionJournal $updatedJournalEvent*diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.phpindex c31e55a948..46aa0460a0 100644--- a/app/Http/Controllers/Account/ReconcileController.php+++ b/app/Http/Controllers/Account/ReconcileController.php@@ -36,6 +36,7 @@ use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;use FireflyIII\Repositories\Journal\JournalRepositoryInterface;+use FireflyIII\Services\Internal\Update\CurrencyUpdateService;use Illuminate\Http\Request;use Illuminate\Support\Collection;use Log;@@ -49,6 +50,10 @@ use Session;*/class ReconcileController extends Controller{+ /** @var CurrencyUpdateService */+ private $accountRepos;+ /** @var AccountRepositoryInterface */+ private $currencyRepos;/** @var JournalRepositoryInterface */private $repository;@@ -64,7 +69,9 @@ class ReconcileController extends Controllerfunction ($request, $next) {app('view')->share('mainTitleIcon', 'fa-credit-card');app('view')->share('title', trans('firefly.accounts'));- $this->repository = app(JournalRepositoryInterface::class);+ $this->repository = app(JournalRepositoryInterface::class);+ $this->accountRepos = app(AccountRepositoryInterface::class);+ $this->currencyRepos = app(CurrencyRepositoryInterface::class);return $next($request);}@@ -182,10 +189,8 @@ class ReconcileController extends Controllerreturn redirect(route('accounts.index', [config('firefly.shortNamesByFullName.' . $account->accountType->type)]));}- /** @var CurrencyRepositoryInterface $currencyRepos */- $currencyRepos = app(CurrencyRepositoryInterface::class);- $currencyId = intval($account->getMeta('currency_id'));- $currency = $currencyRepos->findNull($currencyId);+ $currencyId = intval($this->accountRepos->getMetaValue($account, 'currency_id'));+ $currency = $this->currencyRepos->findNull($currencyId);if (0 === $currencyId) {$currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore}@@ -265,9 +270,7 @@ class ReconcileController extends Controller// create reconciliation transaction (if necessary):if ('create' === $data['reconcile']) {// get "opposing" account.- /** @var AccountRepositoryInterface $accountRepos */- $accountRepos = app(AccountRepositoryInterface::class);- $reconciliation = $accountRepos->getReconciliation($account);+ $reconciliation = $this->accountRepos->getReconciliation($account);$difference = $data['difference'];@@ -297,7 +300,7 @@ class ReconcileController extends Controller'tags' => null,'interest_date' => null,'transactions' => [[- 'currency_id' => intval($account->getMeta('currency_id')),+ 'currency_id' => intval($this->accountRepos->getMetaValue($account, 'currency_id')),'currency_code' => null,'description' => null,'amount' => app('steam')->positive($difference),@@ -347,10 +350,8 @@ class ReconcileController extends Controller$startDate = clone $start;$startDate->subDays(1);- /** @var CurrencyRepositoryInterface $currencyRepos */- $currencyRepos = app(CurrencyRepositoryInterface::class);- $currencyId = intval($account->getMeta('currency_id'));- $currency = $currencyRepos->findNull($currencyId);+ $currencyId = intval($this->accountRepos->getMetaValue($account, 'currency_id'));+ $currency = $this->currencyRepos->findNull($currencyId);if (0 === $currencyId) {$currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore}diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.phpindex b9ff714633..113062dc37 100644--- a/app/Http/Controllers/AccountController.php+++ b/app/Http/Controllers/AccountController.php@@ -186,17 +186,17 @@ class AccountController extends Controller$openingBalanceAmount = strval($repository->getOpeningBalanceAmount($account));$openingBalanceDate = $repository->getOpeningBalanceDate($account);$default = app('amount')->getDefaultCurrency();- $currency = $this->currencyRepos->findNull(intval($account->getMeta('currency_id')));+ $currency = $this->currencyRepos->findNull(intval($repository->getMetaValue($account, 'currency_id')));if (is_null($currency)) {$currency = $default;}$preFilled = [- 'accountNumber' => $account->getMeta('accountNumber'),- 'accountRole' => $account->getMeta('accountRole'),- 'ccType' => $account->getMeta('ccType'),- 'ccMonthlyPaymentDate' => $account->getMeta('ccMonthlyPaymentDate'),- 'BIC' => $account->getMeta('BIC'),+ 'accountNumber' => $repository->getMetaValue($account, 'accountNumber'),+ 'accountRole' => $repository->getMetaValue($account, 'accountRole'),+ 'ccType' => $repository->getMetaValue($account, 'ccType'),+ 'ccMonthlyPaymentDate' => $repository->getMetaValue($account, 'ccMonthlyPaymentDate'),+ 'BIC' => $repository->getMetaValue($account, 'BIC'),'openingBalanceDate' => $openingBalanceDate,'openingBalance' => $openingBalanceAmount,'virtualBalance' => $account->virtual_balance,diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.phpindex 8f1f4ecd39..02e8aa7793 100644--- a/app/Http/Controllers/Controller.php+++ b/app/Http/Controllers/Controller.php@@ -139,7 +139,7 @@ class Controller extends BaseController*/protected function isOpeningBalance(TransactionJournal $journal): bool{- return TransactionType::OPENING_BALANCE === $journal->transactionTypeStr();+ return TransactionType::OPENING_BALANCE === $journal->transactionType->type;}/**diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.phpindex 5d216fee28..c4d21f257d 100644--- a/app/Http/Controllers/ExportController.php+++ b/app/Http/Controllers/ExportController.php@@ -121,7 +121,6 @@ class ExportController extends Controller// does the user have shared accounts?$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);- // todo could be removed?$accountList = ExpandedForm::makeSelectList($accounts);$checked = array_keys($accountList);$formats = array_keys(config('firefly.export_formats'));diff --git a/app/Http/Controllers/JavascriptController.php b/app/Http/Controllers/JavascriptController.phpindex bb991eb100..74516ae6a6 100644--- a/app/Http/Controllers/JavascriptController.php+++ b/app/Http/Controllers/JavascriptController.php@@ -54,7 +54,7 @@ class JavascriptController extends Controller/** @var Account $account */foreach ($accounts as $account) {$accountId = $account->id;- $currency = intval($account->getMeta('currency_id'));+ $currency = intval($repository->getMetaValue($account, 'currency_id'));$currency = 0 === $currency ? $default->id : $currency;$entry = ['preferredCurrency' => $currency, 'name' => $account->name];$data['accounts'][$accountId] = $entry;@@ -98,7 +98,7 @@ class JavascriptController extends Controller$account = $repository->findNull(intval($request->get('account')));$currencyId = 0;if (null !== $account) {- $currencyId = intval($account->getMeta('currency_id'));+ $currencyId = intval($repository->getMetaValue($account, 'currency_id'));}/** @var TransactionCurrency $currency */$currency = $currencyRepository->findNull($currencyId);diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.phpindex 8d0eebcd32..7646e1ba70 100644--- a/app/Http/Controllers/Json/BoxController.php+++ b/app/Http/Controllers/Json/BoxController.php@@ -236,7 +236,7 @@ class BoxController extends Controllerforeach ($accounts as $account) {$accountCurrency = $currency;$balance = $balances[$account->id] ?? '0';- $currencyId = intval($account->getMeta('currency_id'));+ $currencyId = intval($repository->getMetaValue($account, 'currency_id'));if ($currencyId !== 0) {$accountCurrency = $currencyRepos->findNull($currencyId);}diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.phpindex 0cb703e5ba..456be43bec 100644--- a/app/Http/Controllers/Popup/ReportController.php+++ b/app/Http/Controllers/Popup/ReportController.php@@ -129,8 +129,8 @@ class ReportController extends Controllerprivate function balanceAmount(array $attributes): string{$role = intval($attributes['role']);- $budget = $this->budgetRepository->find(intval($attributes['budgetId']));- $account = $this->accountRepository->find(intval($attributes['accountId']));+ $budget = $this->budgetRepository->findNull(intval($attributes['budgetId']));+ $account = $this->accountRepository->findNull(intval($attributes['accountId']));switch (true) {case BalanceLine::ROLE_DEFAULTROLE === $role && null !== $budget->id:@@ -166,7 +166,7 @@ class ReportController extends Controller*/private function budgetSpentAmount(array $attributes): string{- $budget = $this->budgetRepository->find(intval($attributes['budgetId']));+ $budget = $this->budgetRepository->findNull(intval($attributes['budgetId']));$journals = $this->popupHelper->byBudget($budget, $attributes);$view = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render();@@ -184,7 +184,7 @@ class ReportController extends Controller*/private function categoryEntry(array $attributes): string{- $category = $this->categoryRepository->find(intval($attributes['categoryId']));+ $category = $this->categoryRepository->findNull(intval($attributes['categoryId']));$journals = $this->popupHelper->byCategory($category, $attributes);$view = view('popup.report.category-entry', compact('journals', 'category'))->render();@@ -202,7 +202,7 @@ class ReportController extends Controller*/private function expenseEntry(array $attributes): string{- $account = $this->accountRepository->find(intval($attributes['accountId']));+ $account = $this->accountRepository->findNull(intval($attributes['accountId']));$journals = $this->popupHelper->byExpenses($account, $attributes);$view = view('popup.report.expense-entry', compact('journals', 'account'))->render();@@ -220,7 +220,7 @@ class ReportController extends Controller*/private function incomeEntry(array $attributes): string{- $account = $this->accountRepository->find(intval($attributes['accountId']));+ $account = $this->accountRepository->findNull(intval($attributes['accountId']));$journals = $this->popupHelper->byIncome($account, $attributes);$view = view('popup.report.income-entry', compact('journals', 'account'))->render();diff --git a/app/Http/Controllers/RuleGroupController.php b/app/Http/Controllers/RuleGroupController.phpindex 630c8378b5..d31b7d17a1 100644--- a/app/Http/Controllers/RuleGroupController.php+++ b/app/Http/Controllers/RuleGroupController.php@@ -189,7 +189,6 @@ class RuleGroupController extends Controller{// does the user have shared accounts?$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);- // todo could be removed?$accountList = ExpandedForm::makeSelectList($accounts);$checkedAccounts = array_keys($accountList);$first = session('first')->format('Y-m-d');diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.phpindex ad9844fb08..e21f296f4c 100644--- a/app/Http/Controllers/Transaction/MassController.php+++ b/app/Http/Controllers/Transaction/MassController.php@@ -115,8 +115,6 @@ class MassController extends Controller}/**- * TODO this code is a mess.- ** @param Collection $journals** @return View@@ -207,8 +205,6 @@ class MassController extends Controller}/**- * TODO this cannot work with new update service.- ** @param MassEditJournalRequest $request* @param JournalRepositoryInterface $repository*@@ -236,7 +232,6 @@ class MassController extends Controller$foreignAmount = isset($request->get('foreign_amount')[$journal->id]) ? round($request->get('foreign_amount')[$journal->id], 12) : null;$foreignCurrencyId = isset($request->get('foreign_currency_id')[$journal->id]) ?intval($request->get('foreign_currency_id')[$journal->id]) : null;- $notes = $repository->getNoteText($journal);// build data array$data = ['id' => $journal->id,@@ -245,7 +240,7 @@ class MassController extends Controller'date' => new Carbon($request->get('date')[$journal->id]),'bill_id' => null,'bill_name' => null,- 'notes' => $notes,+ 'notes' => $repository->getNoteText($journal),'transactions' => [['category_id' => null,@@ -262,7 +257,7 @@ class MassController extends Controller'currency_id' => intval($currencyId),'currency_code' => null,'description' => null,- 'foreign_amount' => null,+ 'foreign_amount' => $foreignAmount,'foreign_currency_id' => $foreignCurrencyId,'foreign_currency_code' => null,//'native_amount' => $amount,diff --git a/app/Http/Controllers/Transaction/SingleController.php b/app/Http/Controllers/Transaction/SingleController.phpindex 68288fa699..287da2d212 100644--- a/app/Http/Controllers/Transaction/SingleController.php+++ b/app/Http/Controllers/Transaction/SingleController.php@@ -103,7 +103,6 @@ class SingleController extends Controller$categoryName = $this->repository->getJournalCategoryName($journal);$tags = join(',', $this->repository->getTags($journal));- // todo less direct database access. Use collector?/** @var Transaction $transaction */$transaction = $journal->transactions()->first();$amount = app('steam')->positive($transaction->amount);diff --git a/app/Http/Requests/BudgetFormRequest.php b/app/Http/Requests/BudgetFormRequest.phpindex 2042a32660..9bce8af565 100644--- a/app/Http/Requests/BudgetFormRequest.php+++ b/app/Http/Requests/BudgetFormRequest.php@@ -58,7 +58,7 @@ class BudgetFormRequest extends Request/** @var BudgetRepositoryInterface $repository */$repository = app(BudgetRepositoryInterface::class);$nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name';- if (null !== $repository->find(intval($this->get('id')))->id) {+ if (null !== $repository->findNull(intval($this->get('id')))) {$nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,' . intval($this->get('id'));}diff --git a/app/Http/Requests/CategoryFormRequest.php b/app/Http/Requests/CategoryFormRequest.phpindex f48a2d7c21..38b2b872e6 100644--- a/app/Http/Requests/CategoryFormRequest.php+++ b/app/Http/Requests/CategoryFormRequest.php@@ -56,7 +56,7 @@ class CategoryFormRequest extends Request/** @var CategoryRepositoryInterface $repository */$repository = app(CategoryRepositoryInterface::class);$nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name';- if (null !== $repository->find($this->integer('id'))->id) {+ if (null !== $repository->findNull($this->integer('id'))) {$nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,' . $this->integer('id');}diff --git a/app/Jobs/ExecuteRuleOnExistingTransactions.php b/app/Jobs/ExecuteRuleOnExistingTransactions.phpindex fafa74a5b9..be5778934b 100644--- a/app/Jobs/ExecuteRuleOnExistingTransactions.php+++ b/app/Jobs/ExecuteRuleOnExistingTransactions.php@@ -135,6 +135,8 @@ class ExecuteRuleOnExistingTransactions extends Job implements ShouldQueue/*** Execute the job.+ *+ * @throws \FireflyIII\Exceptions\FireflyException*/public function handle(){diff --git a/app/Jobs/MailError.php b/app/Jobs/MailError.phpindex 8c61797fa2..7afc2840b3 100644--- a/app/Jobs/MailError.php+++ b/app/Jobs/MailError.php@@ -22,14 +22,13 @@ declare(strict_types=1);namespace FireflyIII\Jobs;-use ErrorException;+use Exception;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Mail\Message;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;use Log;use Mail;-use Swift_TransportException;/*** Class MailError.@@ -89,11 +88,8 @@ class MailError extends Job implements ShouldQueue}});- } catch (Swift_TransportException $e) {- // could also not mail! :o- Log::error('Swift Transport Exception' . $e->getMessage());- } catch (ErrorException $e) {- Log::error('ErrorException ' . $e->getMessage());+ } catch (Exception $e) {+ Log::error('Exception when mailing: ' . $e->getMessage());}}}diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.phpindex 6066ae969d..8c8bdaf7ea 100644--- a/app/Repositories/Account/AccountRepositoryInterface.php+++ b/app/Repositories/Account/AccountRepositoryInterface.php@@ -92,7 +92,6 @@ interface AccountRepositoryInterface* @param string $name* @param array $types*- * @deprecated* @return Account|null*/public function findByName(string $name, array $types): ?Account;diff --git a/app/Repositories/Account/FindAccountsTrait.php b/app/Repositories/Account/FindAccountsTrait.phpindex 2aba29be10..a8e393631a 100644--- a/app/Repositories/Account/FindAccountsTrait.php+++ b/app/Repositories/Account/FindAccountsTrait.php@@ -141,7 +141,6 @@ trait FindAccountsTrait* @param string $name* @param array $types*- * @deprecated* @return Account|null*/public function findByName(string $name, array $types): ?Accountdiff --git a/app/Repositories/Attachment/AttachmentRepository.php b/app/Repositories/Attachment/AttachmentRepository.phpindex dc8f1bbbbc..1726188161 100644--- a/app/Repositories/Attachment/AttachmentRepository.php+++ b/app/Repositories/Attachment/AttachmentRepository.php@@ -161,14 +161,14 @@ class AttachmentRepository implements AttachmentRepositoryInterface** @return string*/- public function getNoteText(Attachment $attachment): string+ public function getNoteText(Attachment $attachment): ?string{$note = $attachment->notes()->first();if (!is_null($note)) {return strval($note->text);}- return '';+ return null;}/**diff --git a/app/Repositories/Attachment/AttachmentRepositoryInterface.php b/app/Repositories/Attachment/AttachmentRepositoryInterface.phpindex 43ae9100db..0a2b63b537 100644--- a/app/Repositories/Attachment/AttachmentRepositoryInterface.php+++ b/app/Repositories/Attachment/AttachmentRepositoryInterface.php@@ -88,7 +88,7 @@ interface AttachmentRepositoryInterface** @return string*/- public function getNoteText(Attachment $attachment): string;+ public function getNoteText(Attachment $attachment): ?string;/*** @param User $userdiff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.phpindex 704f668df3..9df1cae343 100644--- a/app/Repositories/Bill/BillRepository.php+++ b/app/Repositories/Bill/BillRepository.php@@ -486,8 +486,6 @@ class BillRepository implements BillRepositoryInterface}/**- * TODO move to a service.- ** @param Bill $bill* @param TransactionJournal $journal*@@ -572,8 +570,6 @@ class BillRepository implements BillRepositoryInterface}/**- * TODO refactor- ** @param float $amount* @param float $min* @param float $max@@ -590,8 +586,6 @@ class BillRepository implements BillRepositoryInterface}/**- * TODO refactor- ** @param array $matches* @param $description*diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.phpindex 53328074fd..72f8f5c33a 100644--- a/app/Repositories/Category/CategoryRepository.php+++ b/app/Repositories/Category/CategoryRepository.php@@ -28,6 +28,8 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;use FireflyIII\Models\Category;use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionType;+use FireflyIII\Services\Internal\Destroy\CategoryDestroyService;+use FireflyIII\Services\Internal\Update\CategoryUpdateService;use FireflyIII\User;use Illuminate\Support\Collection;use Log;@@ -42,8 +44,6 @@ class CategoryRepository implements CategoryRepositoryInterfaceprivate $user;/**- * TODO move to delete service- ** @param Category $category** @return bool@@ -52,7 +52,9 @@ class CategoryRepository implements CategoryRepositoryInterface*/public function destroy(Category $category): bool{- $category->delete();+ /** @var CategoryDestroyService $service */+ $service = app(CategoryDestroyService::class);+ $service->destroy($category);return true;}@@ -456,8 +458,6 @@ class CategoryRepository implements CategoryRepositoryInterface}/**- * TODO move to update service- ** @param Category $category* @param array $data*@@ -465,11 +465,10 @@ class CategoryRepository implements CategoryRepositoryInterface*/public function update(Category $category, array $data): Category{- // update the account:- $category->name = $data['name'];- $category->save();+ /** @var CategoryUpdateService $service */+ $service = app(CategoryUpdateService::class);- return $category;+ return $service->update($category, $data);}/**diff --git a/app/Repositories/Currency/CurrencyRepository.php b/app/Repositories/Currency/CurrencyRepository.phpindex adb2a6caf5..f0da06ba51 100644--- a/app/Repositories/Currency/CurrencyRepository.php+++ b/app/Repositories/Currency/CurrencyRepository.php@@ -23,9 +23,12 @@ declare(strict_types=1);namespace FireflyIII\Repositories\Currency;use Carbon\Carbon;+use FireflyIII\Factory\TransactionCurrencyFactory;use FireflyIII\Models\CurrencyExchangeRate;use FireflyIII\Models\Preference;use FireflyIII\Models\TransactionCurrency;+use FireflyIII\Services\Internal\Destroy\CurrencyDestroyService;+use FireflyIII\Services\Internal\Update\CurrencyUpdateService;use FireflyIII\User;use Illuminate\Support\Collection;use Log;@@ -89,8 +92,6 @@ class CurrencyRepository implements CurrencyRepositoryInterface}/**- * TODO use service- ** @param TransactionCurrency $currency** @return bool@@ -98,7 +99,9 @@ class CurrencyRepository implements CurrencyRepositoryInterfacepublic function destroy(TransactionCurrency $currency): bool{if ($this->user->hasRole('owner')) {- $currency->forceDelete();+ /** @var CurrencyDestroyService $service */+ $service = app(CurrencyDestroyService::class);+ $service->destroy($currency);}return true;@@ -307,30 +310,19 @@ class CurrencyRepository implements CurrencyRepositoryInterface}/**- * TODO use factory- ** @param array $data** @return TransactionCurrency*/public function store(array $data): TransactionCurrency{- /** @var TransactionCurrency $currency */- $currency = TransactionCurrency::create(- [- 'name' => $data['name'],- 'code' => $data['code'],- 'symbol' => $data['symbol'],- 'decimal_places' => $data['decimal_places'],- ]- );+ /** @var TransactionCurrencyFactory $factory */+ $factory = app(TransactionCurrencyFactory::class);- return $currency;+ return $factory->create($data);}/**- * TODO use factory- ** @param TransactionCurrency $currency* @param array $data*@@ -338,12 +330,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface*/public function update(TransactionCurrency $currency, array $data): TransactionCurrency{- $currency->code = $data['code'];- $currency->symbol = $data['symbol'];- $currency->name = $data['name'];- $currency->decimal_places = $data['decimal_places'];- $currency->save();+ /** @var CurrencyUpdateService $service */+ $service = app(CurrencyUpdateService::class);- return $currency;+ return $service->update($currency, $data);}}diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.phpindex e5041c0390..ed47af2193 100644--- a/app/Repositories/Journal/JournalRepository.php+++ b/app/Repositories/Journal/JournalRepository.php@@ -456,17 +456,17 @@ class JournalRepository implements JournalRepositoryInterface}/**- * Return text of a note attached to journal, or ''.+ * Return text of a note attached to journal, or NULL** @param TransactionJournal $journal*- * @return string+ * @return string|null*/- public function getNoteText(TransactionJournal $journal): string+ public function getNoteText(TransactionJournal $journal): ?string{$note = $this->getNote($journal);if (is_null($note)) {- return '';+ return null;}return $note->text;diff --git a/app/Repositories/Journal/JournalRepositoryInterface.php b/app/Repositories/Journal/JournalRepositoryInterface.phpindex cefcc53a31..b0ddcfd54f 100644--- a/app/Repositories/Journal/JournalRepositoryInterface.php+++ b/app/Repositories/Journal/JournalRepositoryInterface.php@@ -194,13 +194,13 @@ interface JournalRepositoryInterfacepublic function getNote(TransactionJournal $journal): ?Note;/**- * Return text of a note attached to journal, or ''.+ * Return text of a note attached to journal, or NULL** @param TransactionJournal $journal*- * @return string+ * @return string|null*/- public function getNoteText(TransactionJournal $journal): string;+ public function getNoteText(TransactionJournal $journal): ?string;/*** @param TransactionJournal $journaldiff --git a/app/Rules/BelongsUser.php b/app/Rules/BelongsUser.phpindex 6e695dcd02..1607a29bf0 100644--- a/app/Rules/BelongsUser.php+++ b/app/Rules/BelongsUser.php@@ -59,7 +59,6 @@ class BelongsUser implements Rule/*** Determine if the validation rule passes.- * TODO use repositories?** @param string $attribute* @param mixed $valuediff --git a/app/Services/Bunq/Object/MonetaryAccountBank.php b/app/Services/Bunq/Object/MonetaryAccountBank.phpindex 619a8827d9..cdca32f84e 100644--- a/app/Services/Bunq/Object/MonetaryAccountBank.php+++ b/app/Services/Bunq/Object/MonetaryAccountBank.php@@ -92,6 +92,9 @@ class MonetaryAccountBank extends BunqObject$this->monetaryAccountProfile = new MonetaryAccountProfile($data['monetary_account_profile']);$this->setting = new MonetaryAccountSetting($data['setting']);$this->overdraftLimit = new Amount($data['overdraft_limit']);+ $this->avatar = new Avatar($data['avatar']);+ $this->reason = $data['reason'];+ $this->reasonDescription = $data['reason_description'];// create aliases:foreach ($data['alias'] as $alias) {@@ -102,10 +105,6 @@ class MonetaryAccountBank extends BunqObject$this->notificationFilters[] = new NotificationFilter($filter);}- // TODO avatar- // TODO reason- // TODO reason description-return;}@@ -178,6 +177,9 @@ class MonetaryAccountBank extends BunqObject'monetary_account_profile' => $this->monetaryAccountProfile->toArray(),'setting' => $this->setting->toArray(),'overdraft_limit' => $this->overdraftLimit->toArray(),+ 'avatar' => $this->avatar->toArray(),+ 'reason' => $this->reason,+ 'reason_description' => $this->reasonDescription,'alias' => [],'notification_filters' => [],];@@ -192,10 +194,6 @@ class MonetaryAccountBank extends BunqObject$data['notification_filters'][] = $filter->toArray();}- // TODO avatar- // TODO reason- // TODO reason description-return $data;}}diff --git a/app/Services/Bunq/Object/UserCompany.php b/app/Services/Bunq/Object/UserCompany.phpindex 85ee718dae..196445743d 100644--- a/app/Services/Bunq/Object/UserCompany.php+++ b/app/Services/Bunq/Object/UserCompany.php@@ -162,6 +162,19 @@ class UserCompany extends BunqObject'name' => $this->name,];+ // TODO alias+ // TODO avatar+ // TODO daily_limit_without_confirmation_login+ // TODO notification_filters+ // TODO address_main+ // TODO address_postal+ // TODO director_alias+ // TODO ubo+ // TODO customer+ // TODO customer_limit+ // TODO billing_contract+ // TODO pack_membership+return $data;}}diff --git a/app/Services/Bunq/Request/ListPaymentRequest.php b/app/Services/Bunq/Request/ListPaymentRequest.phpindex 04565a292f..5394ff928c 100644--- a/app/Services/Bunq/Request/ListPaymentRequest.php+++ b/app/Services/Bunq/Request/ListPaymentRequest.php@@ -46,6 +46,7 @@ class ListPaymentRequest extends BunqRequest/*** TODO support pagination.+ * TODO impose limits on import.** @throws \FireflyIII\Exceptions\FireflyException*/diff --git a/app/Services/Internal/Destroy/AccountDestroyService.php b/app/Services/Internal/Destroy/AccountDestroyService.phpindex 222363b4aa..8006315735 100644--- a/app/Services/Internal/Destroy/AccountDestroyService.php+++ b/app/Services/Internal/Destroy/AccountDestroyService.php@@ -39,9 +39,9 @@ class AccountDestroyService* @param Account $account* @param Account|null $moveTo*- * @return bool+ * @return void*/- public function destroy(Account $account, ?Account $moveTo): bool+ public function destroy(Account $account, ?Account $moveTo): void{if (null !== $moveTo) {DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);@@ -66,7 +66,7 @@ class AccountDestroyServiceLog::error(sprintf('Could not delete account: %s', $e->getMessage())); // @codeCoverageIgnore}- return true;+ return;}}diff --git a/app/Services/Internal/Destroy/CategoryDestroyService.php b/app/Services/Internal/Destroy/CategoryDestroyService.phpnew file mode 100644index 0000000000..08e163313c--- /dev/null+++ b/app/Services/Internal/Destroy/CategoryDestroyService.php@@ -0,0 +1,46 @@+<?php+/**+ * CategoryDestroyService.php+ * Copyright (c) 2018 [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\Services\Internal\Destroy;++use Exception;+use FireflyIII\Models\Category;+use Log;++/**+ * Class CategoryDestroyService+ */+class CategoryDestroyService+{+ /**+ * @param Category $category+ */+ public function destroy(Category $category): void+ {+ try {+ $category->delete();+ } catch (Exception $e) { // @codeCoverageIgnore+ Log::error(sprintf('Could not delete category: %s', $e->getMessage())); // @codeCoverageIgnore+ }+ }+}\ No newline at end of filediff --git a/app/Services/Internal/Destroy/CurrencyDestroyService.php b/app/Services/Internal/Destroy/CurrencyDestroyService.phpnew file mode 100644index 0000000000..58689f349e--- /dev/null+++ b/app/Services/Internal/Destroy/CurrencyDestroyService.php@@ -0,0 +1,48 @@+<?php+/**+ * CurrencyDestroyService.php+ * Copyright (c) 2018 [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\Services\Internal\Destroy;++use Exception;+use FireflyIII\Models\TransactionCurrency;+use Log;++/**+ * Class CurrencyDestroyService+ */+class CurrencyDestroyService+{+ /**+ * @param TransactionCurrency $currency+ */+ public function destroy(TransactionCurrency $currency): void+ {++ try {+ $currency->forceDelete();+ } catch (Exception $e) { // @codeCoverageIgnore+ Log::error(sprintf('Could not delete transaction currency: %s', $e->getMessage())); // @codeCoverageIgnore+ }+ }++}\ No newline at end of filediff --git a/app/Services/Internal/Support/AccountServiceTrait.php b/app/Services/Internal/Support/AccountServiceTrait.phpindex 045453a486..9e92951945 100644--- a/app/Services/Internal/Support/AccountServiceTrait.php+++ b/app/Services/Internal/Support/AccountServiceTrait.php@@ -211,8 +211,6 @@ trait AccountServiceTrait}/**- * TODO make sure this works (user ID, etc.)- ** @param User $user* @param string $name*@@ -234,6 +232,7 @@ trait AccountServiceTrait* @param array $data** @return bool+ * @throws \FireflyIII\Exceptions\FireflyException*/public function updateIB(Account $account, array $data): bool{diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.phpindex 48e46dd7ba..1c57223155 100644--- a/app/Services/Internal/Update/AccountUpdateService.php+++ b/app/Services/Internal/Update/AccountUpdateService.php@@ -41,6 +41,7 @@ class AccountUpdateService* @param array $data** @return Account+ * @throws \FireflyIII\Exceptions\FireflyException*/public function update(Account $account, array $data): Account{diff --git a/app/Services/Internal/Update/CategoryUpdateService.php b/app/Services/Internal/Update/CategoryUpdateService.phpnew file mode 100644index 0000000000..9aaa335afc--- /dev/null+++ b/app/Services/Internal/Update/CategoryUpdateService.php@@ -0,0 +1,48 @@+<?php+/**+ * CategoryUpdateService.php+ * Copyright (c) 2018 [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\Services\Internal\Update;++use FireflyIII\Models\Category;+++/**+ * Class CategoryUpdateService+ */+class CategoryUpdateService+{+ /**+ * @param Category $category+ * @param array $data+ *+ * @return Category+ */+ public function update(Category $category, array $data): Category+ {+ $category->name = $data['name'];+ $category->save();++ return $category;+ }++}\ No newline at end of filediff --git a/app/Services/Internal/Update/CurrencyUpdateService.php b/app/Services/Internal/Update/CurrencyUpdateService.phpnew file mode 100644index 0000000000..416282f67e--- /dev/null+++ b/app/Services/Internal/Update/CurrencyUpdateService.php@@ -0,0 +1,50 @@+<?php+/**+ * CurrencyUpdateService.php+ * Copyright (c) 2018 [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\Services\Internal\Update;++use FireflyIII\Models\TransactionCurrency;++/**+ * Class CurrencyUpdateService+ */+class CurrencyUpdateService+{+ /**+ * @param TransactionCurrency $currency+ * @param array $data+ *+ * @return TransactionCurrency+ */+ public function update(TransactionCurrency $currency, array $data): TransactionCurrency+ {+ $currency->code = $data['code'];+ $currency->symbol = $data['symbol'];+ $currency->name = $data['name'];+ $currency->decimal_places = $data['decimal_places'];+ $currency->save();++ return $currency;+ }++}\ No newline at end of filediff --git a/app/TransactionRules/Processor.php b/app/TransactionRules/Processor.phpindex 2c97e755a0..2c4d343765 100644--- a/app/TransactionRules/Processor.php+++ b/app/TransactionRules/Processor.php@@ -174,6 +174,7 @@ final class Processor* @param Transaction $transaction** @return bool+ * @throws \FireflyIII\Exceptions\FireflyException*/public function handleTransaction(Transaction $transaction): bool{@@ -208,6 +209,7 @@ final class Processor* @param TransactionJournal $journal** @return bool+ * @throws \FireflyIII\Exceptions\FireflyException*/public function handleTransactionJournal(TransactionJournal $journal): bool{diff --git a/public/js/ff/transactions/single/common.js b/public/js/ff/transactions/single/common.jsindex e68f4a5492..47962ab6a8 100644--- a/public/js/ff/transactions/single/common.js+++ b/public/js/ff/transactions/single/common.js@@ -149,7 +149,11 @@ function updateNativeAmount(data) {countConversions++;return;}- $('#ffInput_native_amount').val(data.amount);+ console.log('Returned amount is: ' + data.amount);++ if (data.amount !== 0) {+ $('#ffInput_native_amount').val(data.amount);+ }}/**@@ -225,5 +229,9 @@ function convertSourceToDestination() {* @param data*/function updateDestinationAmount(data) {- $('#ffInput_destination_amount').val(data.amount);+ console.log('Returned amount is: ' + data.amount);++ if (data.amount !== 0) {+ $('#ffInput_destination_amount').val(data.amount);+ }}\ No newline at end of filediff --git a/tests/Unit/Transformers/TransactionTransformerTest.php b/tests/Unit/Transformers/TransactionTransformerTest.phpindex 44688369c3..2db67d4b79 100644--- a/tests/Unit/Transformers/TransactionTransformerTest.php+++ b/tests/Unit/Transformers/TransactionTransformerTest.php@@ -40,8 +40,6 @@ use Symfony\Component\HttpFoundation\ParameterBag;use Tests\TestCase;/**- * TODO test split transaction.- ** Class TransactionTransformerTest*/class TransactionTransformerTest extends TestCase