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