mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-26 16:26:35 -06:00
Various code cleanup.
This commit is contained in:
parent
dd9694890a
commit
6660306ac4
@ -224,7 +224,7 @@ class TransactionRequest extends Request
|
||||
return $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'));
|
||||
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ class AccountFactory
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function create(array $data): Account
|
||||
{
|
||||
|
@ -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 $currencyCode
|
||||
|
@ -45,6 +45,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function generate(): string
|
||||
{
|
||||
|
@ -63,6 +63,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function generate(): string
|
||||
{
|
||||
|
@ -64,6 +64,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function generate(): string
|
||||
{
|
||||
|
@ -66,6 +66,7 @@ class StoredJournalEventHandler
|
||||
* @param StoredTransactionJournal $storedJournalEvent
|
||||
*
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function processRules(StoredTransactionJournal $storedJournalEvent): bool
|
||||
{
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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 Controller
|
||||
function ($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 Controller
|
||||
|
||||
return 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
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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'));
|
||||
|
@ -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);
|
||||
|
@ -236,7 +236,7 @@ class BoxController extends Controller
|
||||
foreach ($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);
|
||||
}
|
||||
|
@ -129,8 +129,8 @@ class ReportController extends Controller
|
||||
private 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();
|
||||
|
||||
|
@ -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');
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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'));
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
@ -135,6 +135,8 @@ class ExecuteRuleOnExistingTransactions extends Job implements ShouldQueue
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,6 @@ interface AccountRepositoryInterface
|
||||
* @param string $name
|
||||
* @param array $types
|
||||
*
|
||||
* @deprecated
|
||||
* @return Account|null
|
||||
*/
|
||||
public function findByName(string $name, array $types): ?Account;
|
||||
|
@ -141,7 +141,6 @@ trait FindAccountsTrait
|
||||
* @param string $name
|
||||
* @param array $types
|
||||
*
|
||||
* @deprecated
|
||||
* @return Account|null
|
||||
*/
|
||||
public function findByName(string $name, array $types): ?Account
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,7 +88,7 @@ interface AttachmentRepositoryInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNoteText(Attachment $attachment): string;
|
||||
public function getNoteText(Attachment $attachment): ?string;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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 CategoryRepositoryInterface
|
||||
private $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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 CurrencyRepositoryInterface
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -194,13 +194,13 @@ interface JournalRepositoryInterface
|
||||
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
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNoteText(TransactionJournal $journal): string;
|
||||
public function getNoteText(TransactionJournal $journal): ?string;
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
|
@ -59,7 +59,6 @@ class BelongsUser implements Rule
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
* TODO use repositories?
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ class ListPaymentRequest extends BunqRequest
|
||||
|
||||
/**
|
||||
* TODO support pagination.
|
||||
* TODO impose limits on import.
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
|
@ -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 AccountDestroyService
|
||||
Log::error(sprintf('Could not delete account: %s', $e->getMessage())); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
46
app/Services/Internal/Destroy/CategoryDestroyService.php
Normal file
46
app/Services/Internal/Destroy/CategoryDestroyService.php
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
48
app/Services/Internal/Destroy/CurrencyDestroyService.php
Normal file
48
app/Services/Internal/Destroy/CurrencyDestroyService.php
Normal 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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
{
|
||||
|
@ -41,6 +41,7 @@ class AccountUpdateService
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function update(Account $account, array $data): Account
|
||||
{
|
||||
|
48
app/Services/Internal/Update/CategoryUpdateService.php
Normal file
48
app/Services/Internal/Update/CategoryUpdateService.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
50
app/Services/Internal/Update/CurrencyUpdateService.php
Normal file
50
app/Services/Internal/Update/CurrencyUpdateService.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -40,8 +40,6 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* TODO test split transaction.
|
||||
*
|
||||
* Class TransactionTransformerTest
|
||||
*/
|
||||
class TransactionTransformerTest extends TestCase
|
||||
|
Loading…
Reference in New Issue
Block a user