mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Use different method for finding objects.
This commit is contained in:
parent
fdd2dedfc6
commit
54ba18975a
@ -254,16 +254,14 @@ class ReconcileController extends Controller
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function submit(ReconciliationStoreRequest $request, Account $account, Carbon $start, Carbon $end)
|
||||
public function submit(ReconciliationStoreRequest $request, JournalRepositoryInterface $repository, Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
Log::debug('In ReconcileController::submit()');
|
||||
$data = $request->getAll();
|
||||
/** @var TransactionUpdateService $service */
|
||||
$service = app(TransactionUpdateService::class); // todo move to repos
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($data['transactions'] as $transactionId) {
|
||||
$service->reconcile(intval($transactionId));
|
||||
$repository->reconcileById(intval($transactionId));
|
||||
}
|
||||
Log::debug('Reconciled all transactions.');
|
||||
|
||||
@ -324,10 +322,7 @@ class ReconcileController extends Controller
|
||||
'notes' => join(', ', $data['transactions']),
|
||||
];
|
||||
|
||||
/** @var TransactionJournalFactory $factory */
|
||||
$factory = app(TransactionJournalFactory::class); // todo move to repos
|
||||
$factory->setUser(auth()->user());
|
||||
$journal = $factory->create($journalData);
|
||||
$journal = $repository->store($journalData);
|
||||
}
|
||||
Log::debug('End of routine.');
|
||||
|
||||
@ -358,7 +353,7 @@ class ReconcileController extends Controller
|
||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
$currencyId = intval($account->getMeta('currency_id'));
|
||||
$currency = $currencyRepos->find($currencyId);
|
||||
$currency = $currencyRepos->findNull($currencyId);
|
||||
if (0 === $currencyId) {
|
||||
$currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore
|
||||
}
|
||||
@ -403,8 +398,8 @@ class ReconcileController extends Controller
|
||||
$submitted = $request->getJournalData();
|
||||
|
||||
// amount pos neg influences the accounts:
|
||||
$source = $this->repository->getSourceAccount($journal);
|
||||
$destination = $this->repository->getDestinationAccount($journal);
|
||||
$source = $this->repository->getJournalSourceAccounts($journal)->first();
|
||||
$destination = $this->repository->getJournalDestinationAccounts($journal)->first();
|
||||
if (bccomp($submitted['amount'], '0') === 1) {
|
||||
// amount is positive, switch accounts:
|
||||
list($source, $destination) = [$destination, $source];
|
||||
|
@ -185,7 +185,7 @@ class AccountController extends Controller
|
||||
// the opening balance is tricky:
|
||||
$openingBalanceAmount = strval($repository->getOpeningBalanceAmount($account));
|
||||
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
|
||||
$currency = $this->currencyRepos->find(intval($account->getMeta('currency_id')));
|
||||
$currency = $this->currencyRepos->findNull(intval($account->getMeta('currency_id')));
|
||||
|
||||
$preFilled = [
|
||||
'accountNumber' => $account->getMeta('accountNumber'),
|
||||
@ -304,7 +304,7 @@ class AccountController extends Controller
|
||||
$page = intval($request->get('page'));
|
||||
$pageSize = intval(Preferences::get('listPageSize', 50)->data);
|
||||
$currencyId = intval($account->getMeta('currency_id'));
|
||||
$currency = $this->currencyRepos->find($currencyId);
|
||||
$currency = $this->currencyRepos->findNull($currencyId);
|
||||
if (0 === $currencyId) {
|
||||
$currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class JavascriptController extends Controller
|
||||
{
|
||||
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
$preference = Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR'));
|
||||
$default = $currencyRepository->findByCode($preference->data);
|
||||
$default = $currencyRepository->findByCodeNull($preference->data);
|
||||
|
||||
$data = ['accounts' => []];
|
||||
|
||||
@ -95,13 +95,13 @@ class JavascriptController extends Controller
|
||||
*/
|
||||
public function variables(Request $request, AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository)
|
||||
{
|
||||
$account = $repository->find(intval($request->get('account')));
|
||||
$account = $repository->findNull(intval($request->get('account')));
|
||||
$currencyId = 0;
|
||||
if (null !== $account) {
|
||||
$currencyId = intval($account->getMeta('currency_id'));
|
||||
}
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = $currencyRepository->find($currencyId);
|
||||
$currency = $currencyRepository->findNull($currencyId);
|
||||
if (0 === $currencyId) {
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ class BoxController extends Controller
|
||||
$balance = $balances[$account->id] ?? '0';
|
||||
$currencyId = intval($account->getMeta('currency_id'));
|
||||
if ($currencyId !== 0) {
|
||||
$accountCurrency = $currencyRepos->find($currencyId);
|
||||
$accountCurrency = $currencyRepos->findNull($currencyId);
|
||||
}
|
||||
if (!isset($netWorth[$accountCurrency->id])) {
|
||||
$netWorth[$accountCurrency->id]['currency'] = $accountCurrency;
|
||||
|
@ -85,9 +85,9 @@ class NewUserController extends Controller
|
||||
$this->createSavingsAccount($request, $repository);
|
||||
|
||||
// also store currency preference from input:
|
||||
$currency = $currencyRepository->find(intval($request->input('amount_currency_id_bank_balance')));
|
||||
$currency = $currencyRepository->findNull(intval($request->input('amount_currency_id_bank_balance')));
|
||||
|
||||
if (null !== $currency->id) {
|
||||
if (null !== $currency) {
|
||||
// store currency preference:
|
||||
Preferences::set('currencyPreference', $currency->code);
|
||||
Preferences::mark();
|
||||
|
@ -199,7 +199,7 @@ class ConvertController extends Controller
|
||||
break;
|
||||
case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER:
|
||||
// two
|
||||
$destination = $accountRepository->find(intval($data['destination_account_asset']));
|
||||
$destination = $accountRepository->findNull(intval($data['destination_account_asset']));
|
||||
break;
|
||||
case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL:
|
||||
case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL:
|
||||
@ -276,7 +276,7 @@ class ConvertController extends Controller
|
||||
$source = $destinationAccount;
|
||||
break;
|
||||
case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER:
|
||||
$source = $accountRepository->find(intval($data['source_account_asset']));
|
||||
$source = $accountRepository->findNull(intval($data['source_account_asset']));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -148,13 +148,13 @@ class MassController extends Controller
|
||||
$messages[] = trans('firefly.cannot_edit_multiple_dest', ['description' => $journal->description, 'id' => $journal->id]);
|
||||
continue;
|
||||
}
|
||||
if (TransactionType::OPENING_BALANCE === $journal->transactionType->type) {
|
||||
if (TransactionType::OPENING_BALANCE === $this->repository->getTransactionType($journal)) {
|
||||
$messages[] = trans('firefly.cannot_edit_opening_balance');
|
||||
continue;
|
||||
}
|
||||
|
||||
// cannot edit reconciled transactions / journals:
|
||||
if ($journal->transactions->first()->reconciled) {
|
||||
if ($this->repository->isJournalReconciled($journal)) {
|
||||
$messages[] = trans('firefly.cannot_edit_reconciled', ['description' => $journal->description, 'id' => $journal->id]);
|
||||
continue;
|
||||
}
|
||||
@ -172,7 +172,7 @@ class MassController extends Controller
|
||||
// collect some useful meta data for the mass edit:
|
||||
$filtered->each(
|
||||
function (TransactionJournal $journal) {
|
||||
$transaction = $journal->positiveTransaction();
|
||||
$transaction = $this->repository->getFirstPosTransaction($journal);
|
||||
$currency = $transaction->transactionCurrency;
|
||||
$journal->amount = floatval($transaction->amount);
|
||||
$sources = $this->repository->getJournalSourceAccounts($journal);
|
||||
@ -205,6 +205,8 @@ class MassController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO this cannot work with new update service.
|
||||
*
|
||||
* @param MassEditJournalRequest $request
|
||||
* @param JournalRepositoryInterface $repository
|
||||
*
|
||||
@ -219,7 +221,7 @@ class MassController extends Controller
|
||||
$journal = $repository->find(intval($journalId));
|
||||
if (!is_null($journal)) {
|
||||
// get optional fields:
|
||||
$what = strtolower($journal->transactionTypeStr());
|
||||
$what = strtolower($this->repository->getTransactionType($journal));
|
||||
$sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0;
|
||||
$sourceAccountName = $request->get('source_account_name')[$journal->id] ?? '';
|
||||
$destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0;
|
||||
|
@ -424,7 +424,7 @@ class SingleController extends Controller
|
||||
event(new UpdatedTransactionJournal($journal));
|
||||
// update, get events by date and sort DESC
|
||||
|
||||
$type = strtolower($journal->transactionTypeStr());
|
||||
$type = strtolower($this->repository->getTransactionType($journal));
|
||||
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => $data['description']])));
|
||||
Preferences::mark();
|
||||
|
||||
|
@ -44,12 +44,13 @@ class LinkTypeFormRequest extends Request
|
||||
public function rules()
|
||||
{
|
||||
// fixed
|
||||
|
||||
/** @var LinkTypeRepositoryInterface $repository */
|
||||
$repository = app(LinkTypeRepositoryInterface::class);
|
||||
$nameRule = 'required|min:1|unique:link_types,name';
|
||||
$idRule = '';
|
||||
if (null !== $repository->find($this->integer('id'))->id) {
|
||||
|
||||
// get parameter link:
|
||||
$link = $this->route()->parameter('linkType');
|
||||
|
||||
if (null !== $link) {
|
||||
$idRule = 'exists:link_types,id';
|
||||
$nameRule = 'required|min:1';
|
||||
}
|
||||
|
@ -57,8 +57,8 @@ class ReportFormRequest extends Request
|
||||
$collection = new Collection;
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $accountId) {
|
||||
$account = $repository->find(intval($accountId));
|
||||
if (null !== $account->id) {
|
||||
$account = $repository->findNull(intval($accountId));
|
||||
if (null !== $account) {
|
||||
$collection->push($account);
|
||||
}
|
||||
}
|
||||
@ -78,8 +78,8 @@ class ReportFormRequest extends Request
|
||||
$collection = new Collection;
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $budgetId) {
|
||||
$budget = $repository->find(intval($budgetId));
|
||||
if (null !== $budget->id) {
|
||||
$budget = $repository->findNull(intval($budgetId));
|
||||
if (null !== $budget) {
|
||||
$collection->push($budget);
|
||||
}
|
||||
}
|
||||
@ -99,8 +99,8 @@ class ReportFormRequest extends Request
|
||||
$collection = new Collection;
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $categoryId) {
|
||||
$category = $repository->find(intval($categoryId));
|
||||
if (null !== $category->id) {
|
||||
$category = $repository->findNull(intval($categoryId));
|
||||
if (null !== $category) {
|
||||
$collection->push($category);
|
||||
}
|
||||
}
|
||||
@ -142,8 +142,8 @@ class ReportFormRequest extends Request
|
||||
$collection = new Collection;
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $accountId) {
|
||||
$account = $repository->find(intval($accountId));
|
||||
if (null !== $account->id) {
|
||||
$account = $repository->findNull(intval($accountId));
|
||||
if (null !== $account) {
|
||||
$collection->push($account);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user