Code reordering and reformatting. I should really start employing style CI.

This commit is contained in:
James Cole
2021-09-18 10:26:12 +02:00
parent 9b9d52e99f
commit 4003cea759
344 changed files with 2776 additions and 2605 deletions

View File

@@ -40,6 +40,7 @@ use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;
use JsonException;
use Log;
use Storage;
@@ -115,6 +116,41 @@ class AccountRepository implements AccountRepositoryInterface
}
/**
* @param int $accountId
*
* @return Account|null
*/
public function find(int $accountId): ?Account
{
return $this->user->accounts()->find($accountId);
}
/**
* @inheritDoc
*/
public function findByAccountNumber(string $number, array $types): ?Account
{
$dbQuery = $this->user
->accounts()
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('accounts.active', true)
->where(
function (EloquentBuilder $q1) use ($number) {
$json = json_encode($number);
$q1->where('account_meta.name', '=', 'account_number');
$q1->where('account_meta.data', '=', $json);
}
);
if (!empty($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$dbQuery->whereIn('account_types.type', $types);
}
return $dbQuery->first(['accounts.*']);
}
/**
* @param string $iban
* @param array $types
@@ -162,16 +198,6 @@ class AccountRepository implements AccountRepositoryInterface
return $account;
}
/**
* @param int $accountId
*
* @return Account|null
*/
public function find(int $accountId): ?Account
{
return $this->user->accounts()->find($accountId);
}
/**
* @param Account $account
*
@@ -310,6 +336,23 @@ class AccountRepository implements AccountRepositoryInterface
return $factory->findOrCreate('Cash account', $type->type);
}
/**
* @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;
}
/**
* @param array $types
*
@@ -731,7 +774,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Account
* @throws FireflyException
* @throws \JsonException
* @throws JsonException
*/
public function update(Account $account, array $data): Account
{
@@ -741,46 +784,4 @@ 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
*/
public function findByAccountNumber(string $number, array $types): ?Account
{
$dbQuery = $this->user
->accounts()
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('accounts.active', true)
->where(
function (EloquentBuilder $q1) use ($number) {
$json = json_encode($number);
$q1->where('account_meta.name', '=', 'account_number');
$q1->where('account_meta.data', '=', $json);
}
);
if (!empty($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$dbQuery->whereIn('account_types.type', $types);
}
return $dbQuery->first(['accounts.*']);
}
}

View File

@@ -66,6 +66,13 @@ interface AccountRepositoryInterface
*/
public function expandWithDoubles(Collection $accounts): Collection;
/**
* @param int $accountId
*
* @return Account|null
*/
public function find(int $accountId): ?Account;
/**
* @param string $number
* @param array $types
@@ -90,13 +97,6 @@ interface AccountRepositoryInterface
*/
public function findByName(string $name, array $types): ?Account;
/**
* @param int $accountId
*
* @return Account|null
*/
public function find(int $accountId): ?Account;
/**
* @param Account $account
*
@@ -147,6 +147,13 @@ interface AccountRepositoryInterface
*/
public function getCashAccount(): Account;
/**
* @param Account $account
*
* @return TransactionGroup|null
*/
public function getCreditTransactionGroup(Account $account): ?TransactionGroup;
/**
* @param array $types
*
@@ -208,13 +215,6 @@ interface AccountRepositoryInterface
*/
public function getOpeningBalanceDate(Account $account): ?string;
/**
* @param Account $account
*
* @return TransactionGroup|null
*/
public function getCreditTransactionGroup(Account $account): ?TransactionGroup;
/**
* @param Account $account
*

View File

@@ -78,21 +78,6 @@ interface OperationsRepositoryInterface
public function sumExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null
): array;
/**
* Sum of withdrawal journals in period for a set of accounts, grouped per source / currency. Amounts are always negative.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $expense
* @param TransactionCurrency|null $currency
*
* @return array
*/
public function sumExpensesBySource(
Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null
): array;
/**
* Sum of withdrawal journals in period for a set of accounts, grouped per destination / currency. Amounts are always negative.
*
@@ -108,6 +93,21 @@ interface OperationsRepositoryInterface
Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null
): array;
/**
* Sum of withdrawal journals in period for a set of accounts, grouped per source / currency. Amounts are always negative.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $expense
* @param TransactionCurrency|null $currency
*
* @return array
*/
public function sumExpensesBySource(
Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null
): array;
/**
* Sum of income journals in period for a set of accounts, grouped per currency. Amounts are always positive.
*
@@ -133,7 +133,8 @@ interface OperationsRepositoryInterface
*
* @return array
*/
public function sumIncomeByDestination(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, ?TransactionCurrency $currency = null
public function sumIncomeByDestination(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null,
?TransactionCurrency $currency = null
): array;
/**
@@ -147,7 +148,8 @@ interface OperationsRepositoryInterface
*
* @return array
*/
public function sumIncomeBySource(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, ?TransactionCurrency $currency = null
public function sumIncomeBySource(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null,
?TransactionCurrency $currency = null
): array;
/**