Various code cleanup.

This commit is contained in:
James Cole 2018-03-25 09:01:43 +02:00
parent dd9694890a
commit 6660306ac4
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
46 changed files with 327 additions and 121 deletions

View File

@ -224,7 +224,7 @@ class TransactionRequest extends Request
return $first; return $first;
} }
$account = $repository->findByName($accountName, [AccountType::ASSET]); $account = $repository->findByNameNull($accountName, [AccountType::ASSET]);
if (is_null($account)) { if (is_null($account)) {
$validator->errors()->add($nameField, trans('validation.belongs_user')); $validator->errors()->add($nameField, trans('validation.belongs_user'));

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Export\Collector; namespace FireflyIII\Export\Collector;
use Crypt; use Crypt;
use Exception;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Log; use Log;
use Storage; use Storage;
@ -99,7 +99,7 @@ class UploadCollector extends BasicCollector implements CollectorInterface
$content = ''; $content = '';
try { try {
$content = Crypt::decrypt($this->uploadDisk->get(sprintf('%s.upload', $key))); $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())); Log::error(sprintf('Could not decrypt old import file "%s". Skipped because: %s', $key, $e->getMessage()));
} }

View File

@ -43,6 +43,7 @@ class AccountFactory
* @param array $data * @param array $data
* *
* @return Account * @return Account
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function create(array $data): Account public function create(array $data): Account
{ {

View File

@ -30,6 +30,26 @@ use FireflyIII\Models\TransactionCurrency;
*/ */
class TransactionCurrencyFactory 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 int|null $currencyId
* @param null|string $currencyCode * @param null|string $currencyCode

View File

@ -45,6 +45,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
/** /**
* @return string * @return string
* @throws \Throwable
*/ */
public function generate(): string public function generate(): string
{ {

View File

@ -63,6 +63,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
/** /**
* @return string * @return string
* @throws \Throwable
*/ */
public function generate(): string public function generate(): string
{ {

View File

@ -64,6 +64,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
/** /**
* @return string * @return string
* @throws \Throwable
*/ */
public function generate(): string public function generate(): string
{ {

View File

@ -66,6 +66,7 @@ class StoredJournalEventHandler
* @param StoredTransactionJournal $storedJournalEvent * @param StoredTransactionJournal $storedJournalEvent
* *
* @return bool * @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function processRules(StoredTransactionJournal $storedJournalEvent): bool public function processRules(StoredTransactionJournal $storedJournalEvent): bool
{ {

View File

@ -51,11 +51,11 @@ class UpdatedJournalEventHandler
/** /**
* This method will check all the rules when a journal is updated. * This method will check all the rules when a journal is updated.
* TODO move to factory.
* *
* @param UpdatedTransactionJournal $updatedJournalEvent * @param UpdatedTransactionJournal $updatedJournalEvent
* *
* @return bool * @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function processRules(UpdatedTransactionJournal $updatedJournalEvent): bool 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. * 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 * @param UpdatedTransactionJournal $updatedJournalEvent
* *

View File

@ -36,6 +36,7 @@ use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Services\Internal\Update\CurrencyUpdateService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
@ -49,6 +50,10 @@ use Session;
*/ */
class ReconcileController extends Controller class ReconcileController extends Controller
{ {
/** @var CurrencyUpdateService */
private $accountRepos;
/** @var AccountRepositoryInterface */
private $currencyRepos;
/** @var JournalRepositoryInterface */ /** @var JournalRepositoryInterface */
private $repository; private $repository;
@ -64,7 +69,9 @@ class ReconcileController extends Controller
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', trans('firefly.accounts')); 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); return $next($request);
} }
@ -182,10 +189,8 @@ class ReconcileController extends Controller
return redirect(route('accounts.index', [config('firefly.shortNamesByFullName.' . $account->accountType->type)])); return redirect(route('accounts.index', [config('firefly.shortNamesByFullName.' . $account->accountType->type)]));
} }
/** @var CurrencyRepositoryInterface $currencyRepos */ $currencyId = intval($this->accountRepos->getMetaValue($account, 'currency_id'));
$currencyRepos = app(CurrencyRepositoryInterface::class); $currency = $this->currencyRepos->findNull($currencyId);
$currencyId = intval($account->getMeta('currency_id'));
$currency = $currencyRepos->findNull($currencyId);
if (0 === $currencyId) { if (0 === $currencyId) {
$currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore $currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore
} }
@ -265,9 +270,7 @@ class ReconcileController extends Controller
// create reconciliation transaction (if necessary): // create reconciliation transaction (if necessary):
if ('create' === $data['reconcile']) { if ('create' === $data['reconcile']) {
// get "opposing" account. // get "opposing" account.
/** @var AccountRepositoryInterface $accountRepos */ $reconciliation = $this->accountRepos->getReconciliation($account);
$accountRepos = app(AccountRepositoryInterface::class);
$reconciliation = $accountRepos->getReconciliation($account);
$difference = $data['difference']; $difference = $data['difference'];
@ -297,7 +300,7 @@ class ReconcileController extends Controller
'tags' => null, 'tags' => null,
'interest_date' => null, 'interest_date' => null,
'transactions' => [[ 'transactions' => [[
'currency_id' => intval($account->getMeta('currency_id')), 'currency_id' => intval($this->accountRepos->getMetaValue($account, 'currency_id')),
'currency_code' => null, 'currency_code' => null,
'description' => null, 'description' => null,
'amount' => app('steam')->positive($difference), 'amount' => app('steam')->positive($difference),
@ -347,10 +350,8 @@ class ReconcileController extends Controller
$startDate = clone $start; $startDate = clone $start;
$startDate->subDays(1); $startDate->subDays(1);
/** @var CurrencyRepositoryInterface $currencyRepos */ $currencyId = intval($this->accountRepos->getMetaValue($account, 'currency_id'));
$currencyRepos = app(CurrencyRepositoryInterface::class); $currency = $this->currencyRepos->findNull($currencyId);
$currencyId = intval($account->getMeta('currency_id'));
$currency = $currencyRepos->findNull($currencyId);
if (0 === $currencyId) { if (0 === $currencyId) {
$currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore $currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore
} }

View File

@ -186,17 +186,17 @@ class AccountController extends Controller
$openingBalanceAmount = strval($repository->getOpeningBalanceAmount($account)); $openingBalanceAmount = strval($repository->getOpeningBalanceAmount($account));
$openingBalanceDate = $repository->getOpeningBalanceDate($account); $openingBalanceDate = $repository->getOpeningBalanceDate($account);
$default = app('amount')->getDefaultCurrency(); $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)) { if (is_null($currency)) {
$currency = $default; $currency = $default;
} }
$preFilled = [ $preFilled = [
'accountNumber' => $account->getMeta('accountNumber'), 'accountNumber' => $repository->getMetaValue($account, 'accountNumber'),
'accountRole' => $account->getMeta('accountRole'), 'accountRole' => $repository->getMetaValue($account, 'accountRole'),
'ccType' => $account->getMeta('ccType'), 'ccType' => $repository->getMetaValue($account, 'ccType'),
'ccMonthlyPaymentDate' => $account->getMeta('ccMonthlyPaymentDate'), 'ccMonthlyPaymentDate' => $repository->getMetaValue($account, 'ccMonthlyPaymentDate'),
'BIC' => $account->getMeta('BIC'), 'BIC' => $repository->getMetaValue($account, 'BIC'),
'openingBalanceDate' => $openingBalanceDate, 'openingBalanceDate' => $openingBalanceDate,
'openingBalance' => $openingBalanceAmount, 'openingBalance' => $openingBalanceAmount,
'virtualBalance' => $account->virtual_balance, 'virtualBalance' => $account->virtual_balance,

View File

@ -139,7 +139,7 @@ class Controller extends BaseController
*/ */
protected function isOpeningBalance(TransactionJournal $journal): bool protected function isOpeningBalance(TransactionJournal $journal): bool
{ {
return TransactionType::OPENING_BALANCE === $journal->transactionTypeStr(); return TransactionType::OPENING_BALANCE === $journal->transactionType->type;
} }
/** /**

View File

@ -121,7 +121,6 @@ class ExportController extends Controller
// does the user have shared accounts? // does the user have shared accounts?
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
// todo could be removed?
$accountList = ExpandedForm::makeSelectList($accounts); $accountList = ExpandedForm::makeSelectList($accounts);
$checked = array_keys($accountList); $checked = array_keys($accountList);
$formats = array_keys(config('firefly.export_formats')); $formats = array_keys(config('firefly.export_formats'));

View File

@ -54,7 +54,7 @@ class JavascriptController extends Controller
/** @var Account $account */ /** @var Account $account */
foreach ($accounts as $account) { foreach ($accounts as $account) {
$accountId = $account->id; $accountId = $account->id;
$currency = intval($account->getMeta('currency_id')); $currency = intval($repository->getMetaValue($account, 'currency_id'));
$currency = 0 === $currency ? $default->id : $currency; $currency = 0 === $currency ? $default->id : $currency;
$entry = ['preferredCurrency' => $currency, 'name' => $account->name]; $entry = ['preferredCurrency' => $currency, 'name' => $account->name];
$data['accounts'][$accountId] = $entry; $data['accounts'][$accountId] = $entry;
@ -98,7 +98,7 @@ class JavascriptController extends Controller
$account = $repository->findNull(intval($request->get('account'))); $account = $repository->findNull(intval($request->get('account')));
$currencyId = 0; $currencyId = 0;
if (null !== $account) { if (null !== $account) {
$currencyId = intval($account->getMeta('currency_id')); $currencyId = intval($repository->getMetaValue($account, 'currency_id'));
} }
/** @var TransactionCurrency $currency */ /** @var TransactionCurrency $currency */
$currency = $currencyRepository->findNull($currencyId); $currency = $currencyRepository->findNull($currencyId);

View File

@ -236,7 +236,7 @@ class BoxController extends Controller
foreach ($accounts as $account) { foreach ($accounts as $account) {
$accountCurrency = $currency; $accountCurrency = $currency;
$balance = $balances[$account->id] ?? '0'; $balance = $balances[$account->id] ?? '0';
$currencyId = intval($account->getMeta('currency_id')); $currencyId = intval($repository->getMetaValue($account, 'currency_id'));
if ($currencyId !== 0) { if ($currencyId !== 0) {
$accountCurrency = $currencyRepos->findNull($currencyId); $accountCurrency = $currencyRepos->findNull($currencyId);
} }

View File

@ -129,8 +129,8 @@ class ReportController extends Controller
private function balanceAmount(array $attributes): string private function balanceAmount(array $attributes): string
{ {
$role = intval($attributes['role']); $role = intval($attributes['role']);
$budget = $this->budgetRepository->find(intval($attributes['budgetId'])); $budget = $this->budgetRepository->findNull(intval($attributes['budgetId']));
$account = $this->accountRepository->find(intval($attributes['accountId'])); $account = $this->accountRepository->findNull(intval($attributes['accountId']));
switch (true) { switch (true) {
case BalanceLine::ROLE_DEFAULTROLE === $role && null !== $budget->id: case BalanceLine::ROLE_DEFAULTROLE === $role && null !== $budget->id:
@ -166,7 +166,7 @@ class ReportController extends Controller
*/ */
private function budgetSpentAmount(array $attributes): string 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); $journals = $this->popupHelper->byBudget($budget, $attributes);
$view = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render(); $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 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); $journals = $this->popupHelper->byCategory($category, $attributes);
$view = view('popup.report.category-entry', compact('journals', 'category'))->render(); $view = view('popup.report.category-entry', compact('journals', 'category'))->render();
@ -202,7 +202,7 @@ class ReportController extends Controller
*/ */
private function expenseEntry(array $attributes): string 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); $journals = $this->popupHelper->byExpenses($account, $attributes);
$view = view('popup.report.expense-entry', compact('journals', 'account'))->render(); $view = view('popup.report.expense-entry', compact('journals', 'account'))->render();
@ -220,7 +220,7 @@ class ReportController extends Controller
*/ */
private function incomeEntry(array $attributes): string 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); $journals = $this->popupHelper->byIncome($account, $attributes);
$view = view('popup.report.income-entry', compact('journals', 'account'))->render(); $view = view('popup.report.income-entry', compact('journals', 'account'))->render();

View File

@ -189,7 +189,6 @@ class RuleGroupController extends Controller
{ {
// does the user have shared accounts? // does the user have shared accounts?
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
// todo could be removed?
$accountList = ExpandedForm::makeSelectList($accounts); $accountList = ExpandedForm::makeSelectList($accounts);
$checkedAccounts = array_keys($accountList); $checkedAccounts = array_keys($accountList);
$first = session('first')->format('Y-m-d'); $first = session('first')->format('Y-m-d');

View File

@ -115,8 +115,6 @@ class MassController extends Controller
} }
/** /**
* TODO this code is a mess.
*
* @param Collection $journals * @param Collection $journals
* *
* @return View * @return View
@ -207,8 +205,6 @@ class MassController extends Controller
} }
/** /**
* TODO this cannot work with new update service.
*
* @param MassEditJournalRequest $request * @param MassEditJournalRequest $request
* @param JournalRepositoryInterface $repository * @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; $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]) ? $foreignCurrencyId = isset($request->get('foreign_currency_id')[$journal->id]) ?
intval($request->get('foreign_currency_id')[$journal->id]) : null; intval($request->get('foreign_currency_id')[$journal->id]) : null;
$notes = $repository->getNoteText($journal);
// build data array // build data array
$data = [ $data = [
'id' => $journal->id, 'id' => $journal->id,
@ -245,7 +240,7 @@ class MassController extends Controller
'date' => new Carbon($request->get('date')[$journal->id]), 'date' => new Carbon($request->get('date')[$journal->id]),
'bill_id' => null, 'bill_id' => null,
'bill_name' => null, 'bill_name' => null,
'notes' => $notes, 'notes' => $repository->getNoteText($journal),
'transactions' => [[ 'transactions' => [[
'category_id' => null, 'category_id' => null,
@ -262,7 +257,7 @@ class MassController extends Controller
'currency_id' => intval($currencyId), 'currency_id' => intval($currencyId),
'currency_code' => null, 'currency_code' => null,
'description' => null, 'description' => null,
'foreign_amount' => null, 'foreign_amount' => $foreignAmount,
'foreign_currency_id' => $foreignCurrencyId, 'foreign_currency_id' => $foreignCurrencyId,
'foreign_currency_code' => null, 'foreign_currency_code' => null,
//'native_amount' => $amount, //'native_amount' => $amount,

View File

@ -103,7 +103,6 @@ class SingleController extends Controller
$categoryName = $this->repository->getJournalCategoryName($journal); $categoryName = $this->repository->getJournalCategoryName($journal);
$tags = join(',', $this->repository->getTags($journal)); $tags = join(',', $this->repository->getTags($journal));
// todo less direct database access. Use collector?
/** @var Transaction $transaction */ /** @var Transaction $transaction */
$transaction = $journal->transactions()->first(); $transaction = $journal->transactions()->first();
$amount = app('steam')->positive($transaction->amount); $amount = app('steam')->positive($transaction->amount);

View File

@ -58,7 +58,7 @@ class BudgetFormRequest extends Request
/** @var BudgetRepositoryInterface $repository */ /** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class); $repository = app(BudgetRepositoryInterface::class);
$nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name'; $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')); $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,' . intval($this->get('id'));
} }

View File

@ -56,7 +56,7 @@ class CategoryFormRequest extends Request
/** @var CategoryRepositoryInterface $repository */ /** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class); $repository = app(CategoryRepositoryInterface::class);
$nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name'; $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'); $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,' . $this->integer('id');
} }

View File

@ -135,6 +135,8 @@ class ExecuteRuleOnExistingTransactions extends Job implements ShouldQueue
/** /**
* Execute the job. * Execute the job.
*
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function handle() public function handle()
{ {

View File

@ -22,14 +22,13 @@ declare(strict_types=1);
namespace FireflyIII\Jobs; namespace FireflyIII\Jobs;
use ErrorException; use Exception;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Message; use Illuminate\Mail\Message;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Log; use Log;
use Mail; use Mail;
use Swift_TransportException;
/** /**
* Class MailError. * Class MailError.
@ -89,11 +88,8 @@ class MailError extends Job implements ShouldQueue
} }
} }
); );
} catch (Swift_TransportException $e) { } catch (Exception $e) {
// could also not mail! :o Log::error('Exception when mailing: ' . $e->getMessage());
Log::error('Swift Transport Exception' . $e->getMessage());
} catch (ErrorException $e) {
Log::error('ErrorException ' . $e->getMessage());
} }
} }
} }

View File

@ -92,7 +92,6 @@ interface AccountRepositoryInterface
* @param string $name * @param string $name
* @param array $types * @param array $types
* *
* @deprecated
* @return Account|null * @return Account|null
*/ */
public function findByName(string $name, array $types): ?Account; public function findByName(string $name, array $types): ?Account;

View File

@ -141,7 +141,6 @@ trait FindAccountsTrait
* @param string $name * @param string $name
* @param array $types * @param array $types
* *
* @deprecated
* @return Account|null * @return Account|null
*/ */
public function findByName(string $name, array $types): ?Account public function findByName(string $name, array $types): ?Account

View File

@ -161,14 +161,14 @@ class AttachmentRepository implements AttachmentRepositoryInterface
* *
* @return string * @return string
*/ */
public function getNoteText(Attachment $attachment): string public function getNoteText(Attachment $attachment): ?string
{ {
$note = $attachment->notes()->first(); $note = $attachment->notes()->first();
if (!is_null($note)) { if (!is_null($note)) {
return strval($note->text); return strval($note->text);
} }
return ''; return null;
} }
/** /**

View File

@ -88,7 +88,7 @@ interface AttachmentRepositoryInterface
* *
* @return string * @return string
*/ */
public function getNoteText(Attachment $attachment): string; public function getNoteText(Attachment $attachment): ?string;
/** /**
* @param User $user * @param User $user

View File

@ -486,8 +486,6 @@ class BillRepository implements BillRepositoryInterface
} }
/** /**
* TODO move to a service.
*
* @param Bill $bill * @param Bill $bill
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
@ -572,8 +570,6 @@ class BillRepository implements BillRepositoryInterface
} }
/** /**
* TODO refactor
*
* @param float $amount * @param float $amount
* @param float $min * @param float $min
* @param float $max * @param float $max
@ -590,8 +586,6 @@ class BillRepository implements BillRepositoryInterface
} }
/** /**
* TODO refactor
*
* @param array $matches * @param array $matches
* @param $description * @param $description
* *

View File

@ -28,6 +28,8 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Category; use FireflyIII\Models\Category;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Services\Internal\Destroy\CategoryDestroyService;
use FireflyIII\Services\Internal\Update\CategoryUpdateService;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
@ -42,8 +44,6 @@ class CategoryRepository implements CategoryRepositoryInterface
private $user; private $user;
/** /**
* TODO move to delete service
*
* @param Category $category * @param Category $category
* *
* @return bool * @return bool
@ -52,7 +52,9 @@ class CategoryRepository implements CategoryRepositoryInterface
*/ */
public function destroy(Category $category): bool public function destroy(Category $category): bool
{ {
$category->delete(); /** @var CategoryDestroyService $service */
$service = app(CategoryDestroyService::class);
$service->destroy($category);
return true; return true;
} }
@ -456,8 +458,6 @@ class CategoryRepository implements CategoryRepositoryInterface
} }
/** /**
* TODO move to update service
*
* @param Category $category * @param Category $category
* @param array $data * @param array $data
* *
@ -465,11 +465,10 @@ class CategoryRepository implements CategoryRepositoryInterface
*/ */
public function update(Category $category, array $data): Category public function update(Category $category, array $data): Category
{ {
// update the account: /** @var CategoryUpdateService $service */
$category->name = $data['name']; $service = app(CategoryUpdateService::class);
$category->save();
return $category; return $service->update($category, $data);
} }
/** /**

View File

@ -23,9 +23,12 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Currency; namespace FireflyIII\Repositories\Currency;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Models\CurrencyExchangeRate; use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\Preference; use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Services\Internal\Destroy\CurrencyDestroyService;
use FireflyIII\Services\Internal\Update\CurrencyUpdateService;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
@ -89,8 +92,6 @@ class CurrencyRepository implements CurrencyRepositoryInterface
} }
/** /**
* TODO use service
*
* @param TransactionCurrency $currency * @param TransactionCurrency $currency
* *
* @return bool * @return bool
@ -98,7 +99,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface
public function destroy(TransactionCurrency $currency): bool public function destroy(TransactionCurrency $currency): bool
{ {
if ($this->user->hasRole('owner')) { if ($this->user->hasRole('owner')) {
$currency->forceDelete(); /** @var CurrencyDestroyService $service */
$service = app(CurrencyDestroyService::class);
$service->destroy($currency);
} }
return true; return true;
@ -307,30 +310,19 @@ class CurrencyRepository implements CurrencyRepositoryInterface
} }
/** /**
* TODO use factory
*
* @param array $data * @param array $data
* *
* @return TransactionCurrency * @return TransactionCurrency
*/ */
public function store(array $data): TransactionCurrency public function store(array $data): TransactionCurrency
{ {
/** @var TransactionCurrency $currency */ /** @var TransactionCurrencyFactory $factory */
$currency = TransactionCurrency::create( $factory = app(TransactionCurrencyFactory::class);
[
'name' => $data['name'],
'code' => $data['code'],
'symbol' => $data['symbol'],
'decimal_places' => $data['decimal_places'],
]
);
return $currency; return $factory->create($data);
} }
/** /**
* TODO use factory
*
* @param TransactionCurrency $currency * @param TransactionCurrency $currency
* @param array $data * @param array $data
* *
@ -338,12 +330,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface
*/ */
public function update(TransactionCurrency $currency, array $data): TransactionCurrency public function update(TransactionCurrency $currency, array $data): TransactionCurrency
{ {
$currency->code = $data['code']; /** @var CurrencyUpdateService $service */
$currency->symbol = $data['symbol']; $service = app(CurrencyUpdateService::class);
$currency->name = $data['name'];
$currency->decimal_places = $data['decimal_places'];
$currency->save();
return $currency; return $service->update($currency, $data);
} }
} }

View File

@ -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 * @param TransactionJournal $journal
* *
* @return string * @return string|null
*/ */
public function getNoteText(TransactionJournal $journal): string public function getNoteText(TransactionJournal $journal): ?string
{ {
$note = $this->getNote($journal); $note = $this->getNote($journal);
if (is_null($note)) { if (is_null($note)) {
return ''; return null;
} }
return $note->text; return $note->text;

View File

@ -194,13 +194,13 @@ interface JournalRepositoryInterface
public function getNote(TransactionJournal $journal): ?Note; public 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 * @param TransactionJournal $journal
* *
* @return string * @return string|null
*/ */
public function getNoteText(TransactionJournal $journal): string; public function getNoteText(TransactionJournal $journal): ?string;
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal

View File

@ -59,7 +59,6 @@ class BelongsUser implements Rule
/** /**
* Determine if the validation rule passes. * Determine if the validation rule passes.
* TODO use repositories?
* *
* @param string $attribute * @param string $attribute
* @param mixed $value * @param mixed $value

View File

@ -92,6 +92,9 @@ class MonetaryAccountBank extends BunqObject
$this->monetaryAccountProfile = new MonetaryAccountProfile($data['monetary_account_profile']); $this->monetaryAccountProfile = new MonetaryAccountProfile($data['monetary_account_profile']);
$this->setting = new MonetaryAccountSetting($data['setting']); $this->setting = new MonetaryAccountSetting($data['setting']);
$this->overdraftLimit = new Amount($data['overdraft_limit']); $this->overdraftLimit = new Amount($data['overdraft_limit']);
$this->avatar = new Avatar($data['avatar']);
$this->reason = $data['reason'];
$this->reasonDescription = $data['reason_description'];
// create aliases: // create aliases:
foreach ($data['alias'] as $alias) { foreach ($data['alias'] as $alias) {
@ -102,10 +105,6 @@ class MonetaryAccountBank extends BunqObject
$this->notificationFilters[] = new NotificationFilter($filter); $this->notificationFilters[] = new NotificationFilter($filter);
} }
// TODO avatar
// TODO reason
// TODO reason description
return; return;
} }
@ -178,6 +177,9 @@ class MonetaryAccountBank extends BunqObject
'monetary_account_profile' => $this->monetaryAccountProfile->toArray(), 'monetary_account_profile' => $this->monetaryAccountProfile->toArray(),
'setting' => $this->setting->toArray(), 'setting' => $this->setting->toArray(),
'overdraft_limit' => $this->overdraftLimit->toArray(), 'overdraft_limit' => $this->overdraftLimit->toArray(),
'avatar' => $this->avatar->toArray(),
'reason' => $this->reason,
'reason_description' => $this->reasonDescription,
'alias' => [], 'alias' => [],
'notification_filters' => [], 'notification_filters' => [],
]; ];
@ -192,10 +194,6 @@ class MonetaryAccountBank extends BunqObject
$data['notification_filters'][] = $filter->toArray(); $data['notification_filters'][] = $filter->toArray();
} }
// TODO avatar
// TODO reason
// TODO reason description
return $data; return $data;
} }
} }

View File

@ -162,6 +162,19 @@ class UserCompany extends BunqObject
'name' => $this->name, '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; return $data;
} }
} }

View File

@ -46,6 +46,7 @@ class ListPaymentRequest extends BunqRequest
/** /**
* TODO support pagination. * TODO support pagination.
* TODO impose limits on import.
* *
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
*/ */

View File

@ -39,9 +39,9 @@ class AccountDestroyService
* @param Account $account * @param Account $account
* @param Account|null $moveTo * @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) { if (null !== $moveTo) {
DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]); DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
@ -66,7 +66,7 @@ class AccountDestroyService
Log::error(sprintf('Could not delete account: %s', $e->getMessage())); // @codeCoverageIgnore Log::error(sprintf('Could not delete account: %s', $e->getMessage())); // @codeCoverageIgnore
} }
return true; return;
} }
} }

View File

@ -0,0 +1,46 @@
<?php
/**
* CategoryDestroyService.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* 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
}
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* CurrencyDestroyService.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* 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
}
}
}

View File

@ -211,8 +211,6 @@ trait AccountServiceTrait
} }
/** /**
* TODO make sure this works (user ID, etc.)
*
* @param User $user * @param User $user
* @param string $name * @param string $name
* *
@ -234,6 +232,7 @@ trait AccountServiceTrait
* @param array $data * @param array $data
* *
* @return bool * @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function updateIB(Account $account, array $data): bool public function updateIB(Account $account, array $data): bool
{ {

View File

@ -41,6 +41,7 @@ class AccountUpdateService
* @param array $data * @param array $data
* *
* @return Account * @return Account
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function update(Account $account, array $data): Account public function update(Account $account, array $data): Account
{ {

View File

@ -0,0 +1,48 @@
<?php
/**
* CategoryUpdateService.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* 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;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* CurrencyUpdateService.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* 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;
}
}

View File

@ -174,6 +174,7 @@ final class Processor
* @param Transaction $transaction * @param Transaction $transaction
* *
* @return bool * @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function handleTransaction(Transaction $transaction): bool public function handleTransaction(Transaction $transaction): bool
{ {
@ -208,6 +209,7 @@ final class Processor
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return bool * @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
public function handleTransactionJournal(TransactionJournal $journal): bool public function handleTransactionJournal(TransactionJournal $journal): bool
{ {

View File

@ -149,7 +149,11 @@ function updateNativeAmount(data) {
countConversions++; countConversions++;
return; 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 * @param data
*/ */
function updateDestinationAmount(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);
}
} }

View File

@ -40,8 +40,6 @@ use Symfony\Component\HttpFoundation\ParameterBag;
use Tests\TestCase; use Tests\TestCase;
/** /**
* TODO test split transaction.
*
* Class TransactionTransformerTest * Class TransactionTransformerTest
*/ */
class TransactionTransformerTest extends TestCase class TransactionTransformerTest extends TestCase