mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Merge branch 'feature/credit_calc' into develop
This commit is contained in:
@@ -123,14 +123,24 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function findByIbanNull(string $iban, array $types): ?Account
|
||||
{
|
||||
$query = $this->user->accounts()->where('accounts.iban', $iban);
|
||||
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
|
||||
|
||||
if (0 !== count($types)) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$query->whereIn('account_types.type', $types);
|
||||
}
|
||||
|
||||
return $query->first(['accounts.*']);
|
||||
// TODO a loop like this is no longer necessary
|
||||
|
||||
$accounts = $query->get(['accounts.*']);
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
if ($account->iban === $iban) {
|
||||
return $account;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -738,6 +748,23 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $service->update($account, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCreditTransactionGroup(Account $account): ?TransactionGroup
|
||||
{
|
||||
$journal = TransactionJournal
|
||||
::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->transactionTypes([TransactionType::LIABILITY_CREDIT])
|
||||
->first(['transaction_journals.*']);
|
||||
if (null === $journal) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $journal->transactionGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -762,4 +789,5 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
return $dbQuery->first(['accounts.*']);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -207,6 +207,13 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function getOpeningBalanceDate(Account $account): ?string;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionGroup|null
|
||||
*/
|
||||
public function getCreditTransactionGroup(Account $account): ?TransactionGroup;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
|
Reference in New Issue
Block a user