mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Optimise transformer.
This commit is contained in:
@@ -231,7 +231,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getAccountCurrency(Account $account): ?TransactionCurrency
|
||||
{
|
||||
$currencyId = (int)$this->getMetaValue($account, 'currency_id');
|
||||
$currencyId = (int) $this->getMetaValue($account, 'currency_id');
|
||||
if ($currencyId > 0) {
|
||||
return TransactionCurrency::find($currencyId);
|
||||
}
|
||||
@@ -351,13 +351,16 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getMetaValue(Account $account, string $field): ?string
|
||||
{
|
||||
/** @var AccountMeta $meta */
|
||||
$meta = $account->accountMeta()->where('name', $field)->first();
|
||||
if (null === $meta) {
|
||||
$result = $account->accountMeta->filter(function (AccountMeta $meta) use ($field) {
|
||||
return strtolower($meta->name) === strtolower($field);
|
||||
});
|
||||
if (0 === $result->count()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string)$meta->data;
|
||||
if (1 === $result->count()) {
|
||||
return (string)$result->first()->data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -414,7 +417,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string)$transaction->amount;
|
||||
return (string) $transaction->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -476,13 +479,13 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
throw new FireflyException(sprintf('%s is not an asset account.', $account->name));
|
||||
}
|
||||
$currency = $this->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
||||
$name = trans('firefly.reconciliation_account_name', ['name' => $account->name, 'currency' => $currency->code]);
|
||||
$name = trans('firefly.reconciliation_account_name', ['name' => $account->name, 'currency' => $currency->code]);
|
||||
|
||||
/** @var AccountType $type */
|
||||
$type = AccountType::where('type', AccountType::RECONCILIATION)->first();
|
||||
$current = $this->user->accounts()->where('account_type_id', $type->id)
|
||||
->where('name', $name)
|
||||
->first();
|
||||
->where('name', $name)
|
||||
->first();
|
||||
|
||||
/** @var Account $current */
|
||||
if (null !== $current) {
|
||||
@@ -532,7 +535,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
->orderBy('transaction_journals.id', 'ASC')
|
||||
->first(['transaction_journals.id']);
|
||||
if (null !== $first) {
|
||||
return TransactionJournal::find((int)$first->id);
|
||||
return TransactionJournal::find((int) $first->id);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -559,7 +562,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array $types
|
||||
* @param int $limit
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -574,7 +577,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
if ('' !== $query) {
|
||||
// split query on spaces just in case:
|
||||
$parts = explode(' ', $query);
|
||||
foreach($parts as $part) {
|
||||
foreach ($parts as $part) {
|
||||
$search = sprintf('%%%s%%', $part);
|
||||
$dbQuery->where('name', 'LIKE', $search);
|
||||
}
|
||||
@@ -664,7 +667,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getAttachments(Account $account): Collection
|
||||
{
|
||||
$set = $account->attachments()->get();
|
||||
$set = $account->attachments()->get();
|
||||
|
||||
/** @var Storage $disk */
|
||||
$disk = Storage::disk('upload');
|
||||
|
Reference in New Issue
Block a user