mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Simplify code.
This commit is contained in:
parent
3979e12043
commit
9d826519e3
@ -54,17 +54,32 @@ class JournalUpdateService
|
||||
{
|
||||
use JournalServiceTrait;
|
||||
|
||||
private BillRepositoryInterface $billRepository;
|
||||
private CurrencyRepositoryInterface $currencyRepository;
|
||||
private array $data;
|
||||
private Account $destinationAccount;
|
||||
private Transaction $destinationTransaction;
|
||||
private array $metaDate;
|
||||
private array $metaString;
|
||||
private Account $sourceAccount;
|
||||
private Transaction $sourceTransaction;
|
||||
private TransactionGroup $transactionGroup;
|
||||
private TransactionJournal $transactionJournal;
|
||||
/** @var BillRepositoryInterface */
|
||||
private $billRepository;
|
||||
/** @var CurrencyRepositoryInterface */
|
||||
private $currencyRepository;
|
||||
/** @var array The data to update the journal with. */
|
||||
private $data;
|
||||
/** @var Account The destination account. */
|
||||
private $destinationAccount;
|
||||
/** @var Transaction */
|
||||
private $destinationTransaction;
|
||||
/** @var array All meta values that are dates. */
|
||||
private $metaDate;
|
||||
/** @var array All meta values that are strings. */
|
||||
private $metaString;
|
||||
/** @var Account Source account of the journal */
|
||||
private $sourceAccount;
|
||||
/** @var Transaction Source transaction of the journal. */
|
||||
private $sourceTransaction;
|
||||
/** @var TransactionGroup The parent group. */
|
||||
private $transactionGroup;
|
||||
/** @var TransactionJournal The journal to update. */
|
||||
private $transactionJournal;
|
||||
/** @var Account If new account info is submitted, this array will hold the valid destination. */
|
||||
private $validDestination;
|
||||
/** @var Account If new account info is submitted, this array will hold the valid source. */
|
||||
private $validSource;
|
||||
|
||||
/**
|
||||
* JournalUpdateService constructor.
|
||||
@ -363,9 +378,9 @@ class JournalUpdateService
|
||||
$sourceName = $this->data['source_name'] ?? null;
|
||||
|
||||
if (!$this->hasFields(['source_id', 'source_name'])) {
|
||||
$sourceAccount = $this->getOriginalSourceAccount();
|
||||
$sourceId = $sourceAccount->id;
|
||||
$sourceName = $sourceAccount->name;
|
||||
$origSourceAccount = $this->getOriginalSourceAccount();
|
||||
$sourceId = $origSourceAccount->id;
|
||||
$sourceName = $origSourceAccount->name;
|
||||
}
|
||||
|
||||
// make new account validator.
|
||||
@ -402,9 +417,9 @@ class JournalUpdateService
|
||||
return;
|
||||
}
|
||||
|
||||
$sourceTransaction = $this->getSourceTransaction();
|
||||
$sourceTransaction->account()->associate($source);
|
||||
$sourceTransaction->save();
|
||||
$origSourceTransaction = $this->getSourceTransaction();
|
||||
$origSourceTransaction->account()->associate($source);
|
||||
$origSourceTransaction->save();
|
||||
|
||||
$destTransaction = $this->getDestinationTransaction();
|
||||
$destTransaction->account()->associate($destination);
|
||||
@ -436,9 +451,9 @@ class JournalUpdateService
|
||||
|
||||
return;
|
||||
}
|
||||
$sourceTransaction = $this->getSourceTransaction();
|
||||
$sourceTransaction->amount = app('steam')->negative($amount);
|
||||
$sourceTransaction->save();
|
||||
$origSourceTransaction = $this->getSourceTransaction();
|
||||
$origSourceTransaction->amount = app('steam')->negative($amount);
|
||||
$origSourceTransaction->save();
|
||||
|
||||
|
||||
$destTransaction = $this->getDestinationTransaction();
|
||||
|
@ -75,20 +75,20 @@ class RemoteUserGuard implements Guard
|
||||
throw new FireflyException('The guard header was unexpectedly empty. See the logs.');
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->provider->retrieveById($userID);
|
||||
/** @var User $retrievedUser */
|
||||
$retrievedUser = $this->provider->retrieveById($userID);
|
||||
|
||||
// store email address if present in header and not already set.
|
||||
$header = config('auth.guard_email');
|
||||
$emailAddress = request()->server($header) ?? null;
|
||||
$preference = app('preferences')->getForUser($user, 'remote_guard_alt_email', null);
|
||||
$preference = app('preferences')->getForUser($retrievedUser, 'remote_guard_alt_email', null);
|
||||
|
||||
if (null !== $emailAddress && null === $preference && $emailAddress !== $userID) {
|
||||
app('preferences')->setForUser($user, 'remote_guard_alt_email', $emailAddress);
|
||||
app('preferences')->setForUser($retrievedUser, 'remote_guard_alt_email', $emailAddress);
|
||||
}
|
||||
|
||||
Log::debug(sprintf('Result of getting user from provider: %s', $user->email));
|
||||
$this->user = $user;
|
||||
Log::debug(sprintf('Result of getting user from provider: %s', $retrievedUser->email));
|
||||
$this->user = $retrievedUser;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,15 +45,10 @@ class AccountSearch implements GenericSearchInterface
|
||||
/** @var string */
|
||||
public const SEARCH_ID = 'id';
|
||||
|
||||
/** @var string */
|
||||
private $field;
|
||||
/** @var string */
|
||||
private $query;
|
||||
/** @var array */
|
||||
private $types;
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
private string $field;
|
||||
private string $query;
|
||||
private array $types;
|
||||
private User $user;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@ -66,7 +61,7 @@ class AccountSearch implements GenericSearchInterface
|
||||
public function search(): Collection
|
||||
{
|
||||
|
||||
$query = $this->user->accounts()
|
||||
$searchQuery = $this->user->accounts()
|
||||
->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')
|
||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->whereIn('account_types.type', $this->types);
|
||||
@ -75,7 +70,7 @@ class AccountSearch implements GenericSearchInterface
|
||||
switch ($this->field) {
|
||||
default:
|
||||
case self::SEARCH_ALL:
|
||||
$query->where(
|
||||
$searchQuery->where(
|
||||
static function (Builder $q) use ($like) {
|
||||
$q->where('accounts.id', 'LIKE', $like);
|
||||
$q->orWhere('accounts.name', 'LIKE', $like);
|
||||
@ -83,7 +78,7 @@ class AccountSearch implements GenericSearchInterface
|
||||
}
|
||||
);
|
||||
// meta data:
|
||||
$query->orWhere(
|
||||
$searchQuery->orWhere(
|
||||
static function (Builder $q) use ($originalQuery) {
|
||||
$json = json_encode($originalQuery, JSON_THROW_ON_ERROR);
|
||||
$q->where('account_meta.name', '=', 'account_number');
|
||||
@ -92,17 +87,17 @@ class AccountSearch implements GenericSearchInterface
|
||||
);
|
||||
break;
|
||||
case self::SEARCH_ID:
|
||||
$query->where('accounts.id', '=', (int)$originalQuery);
|
||||
$searchQuery->where('accounts.id', '=', (int)$originalQuery);
|
||||
break;
|
||||
case self::SEARCH_NAME:
|
||||
$query->where('accounts.name', 'LIKE', $like);
|
||||
$searchQuery->where('accounts.name', 'LIKE', $like);
|
||||
break;
|
||||
case self::SEARCH_IBAN:
|
||||
$query->where('accounts.iban', 'LIKE', $like);
|
||||
$searchQuery->where('accounts.iban', 'LIKE', $like);
|
||||
break;
|
||||
case self::SEARCH_NUMBER:
|
||||
// meta data:
|
||||
$query->Where(
|
||||
$searchQuery->Where(
|
||||
static function (Builder $q) use ($originalQuery) {
|
||||
$json = json_encode($originalQuery, JSON_THROW_ON_ERROR);
|
||||
$q->where('account_meta.name', 'account_number');
|
||||
@ -111,7 +106,8 @@ class AccountSearch implements GenericSearchInterface
|
||||
);
|
||||
break;
|
||||
}
|
||||
return $query->distinct()->get(['accounts.*']);
|
||||
|
||||
return $searchQuery->distinct()->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user