Various code cleanup and sorting.

This commit is contained in:
James Cole
2025-03-08 19:55:21 +01:00
parent 2d3d3bc0a4
commit 30b7e17b6f
60 changed files with 1402 additions and 1475 deletions

View File

@@ -97,7 +97,6 @@ class ShowController extends Controller
$admin = auth()->user(); $admin = auth()->user();
$enrichment = new AccountEnrichment(); $enrichment = new AccountEnrichment();
$enrichment->setUser($admin); $enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency); $enrichment->setNative($this->nativeCurrency);
$accounts = $enrichment->enrich($accounts); $accounts = $enrichment->enrich($accounts);
@@ -133,7 +132,6 @@ class ShowController extends Controller
$admin = auth()->user(); $admin = auth()->user();
$enrichment = new AccountEnrichment(); $enrichment = new AccountEnrichment();
$enrichment->setUser($admin); $enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency); $enrichment->setNative($this->nativeCurrency);
$account = $enrichment->enrichSingle($account); $account = $enrichment->enrichSingle($account);

View File

@@ -76,7 +76,6 @@ class StoreController extends Controller
$admin = auth()->user(); $admin = auth()->user();
$enrichment = new AccountEnrichment(); $enrichment = new AccountEnrichment();
$enrichment->setUser($admin); $enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency); $enrichment->setNative($this->nativeCurrency);
$account = $enrichment->enrichSingle($account); $account = $enrichment->enrichSingle($account);

View File

@@ -80,7 +80,6 @@ class UpdateController extends Controller
$admin = auth()->user(); $admin = auth()->user();
$enrichment = new AccountEnrichment(); $enrichment = new AccountEnrichment();
$enrichment->setUser($admin); $enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency); $enrichment->setNative($this->nativeCurrency);
$account = $enrichment->enrichSingle($account); $account = $enrichment->enrichSingle($account);

View File

@@ -84,7 +84,6 @@ class ListController extends Controller
$admin = auth()->user(); $admin = auth()->user();
$enrichment = new AccountEnrichment(); $enrichment = new AccountEnrichment();
$enrichment->setUser($admin); $enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency); $enrichment->setNative($this->nativeCurrency);
$accounts = $enrichment->enrich($accounts); $accounts = $enrichment->enrich($accounts);

View File

@@ -107,7 +107,6 @@ class ListController extends Controller
$admin = auth()->user(); $admin = auth()->user();
$enrichment = new AccountEnrichment(); $enrichment = new AccountEnrichment();
$enrichment->setUser($admin); $enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency); $enrichment->setNative($this->nativeCurrency);
$accounts = $enrichment->enrich($accounts); $accounts = $enrichment->enrich($accounts);

View File

@@ -88,7 +88,6 @@ class AccountController extends Controller
$admin = auth()->user(); $admin = auth()->user();
$enrichment = new AccountEnrichment(); $enrichment = new AccountEnrichment();
$enrichment->setUser($admin); $enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->nativeCurrency); $enrichment->setNative($this->nativeCurrency);
$accounts = $enrichment->enrich($accounts); $accounts = $enrichment->enrich($accounts);

View File

@@ -76,7 +76,7 @@ class ValidatesEnvironmentVariables extends Command
private function validateGuard(): void private function validateGuard(): void
{ {
$guard = env('AUTHENTICATION_GUARD', 'web'); $guard = config('auth.defaults.guard');
if ('web' !== $guard && 'remote_user_guard' !== $guard) { if ('web' !== $guard && 'remote_user_guard' !== $guard) {
$this->friendlyError(sprintf('AUTHENTICATION_GUARD "%s" is not a valid guard for Firefly III.', $guard)); $this->friendlyError(sprintf('AUTHENTICATION_GUARD "%s" is not a valid guard for Firefly III.', $guard));
$this->friendlyError('Please check your .env file and make sure you use a valid setting.'); $this->friendlyError('Please check your .env file and make sure you use a valid setting.');
@@ -87,7 +87,7 @@ class ValidatesEnvironmentVariables extends Command
private function validateStaticToken(): void private function validateStaticToken(): void
{ {
$token = (string) env('STATIC_CRON_TOKEN', ''); $token = (string) config('firefly.static_cron_token');
if (0 !== strlen($token) && 32 !== strlen($token)) { if (0 !== strlen($token) && 32 !== strlen($token)) {
$this->friendlyError('STATIC_CRON_TOKEN must be empty or a 32-character string.'); $this->friendlyError('STATIC_CRON_TOKEN must be empty or a 32-character string.');
$this->friendlyError('Please check your .env file and make sure you use a valid setting.'); $this->friendlyError('Please check your .env file and make sure you use a valid setting.');

View File

@@ -88,7 +88,8 @@ class AccountObserver
} }
$journalIds = Transaction::where('account_id', $account->id)->get(['transactions.transaction_journal_id'])->pluck('transaction_journal_id')->toArray(); $journalIds = Transaction::where('account_id', $account->id)->get(['transactions.transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
$groupIds = TransactionJournal::whereIn('id', $journalIds)->get(['transaction_journals.transaction_group_id'])->pluck('transaction_group_id')->toArray(); $groupIds = TransactionJournal::whereIn('id', $journalIds)->get(['transaction_journals.transaction_group_id'])->pluck('transaction_group_id')->toArray(); // @phpstan-ignore-line
if (count($journalIds) > 0) { if (count($journalIds) > 0) {
Transaction::whereIn('transaction_journal_id', $journalIds)->delete(); Transaction::whereIn('transaction_journal_id', $journalIds)->delete();
TransactionJournal::whereIn('id', $journalIds)->delete(); TransactionJournal::whereIn('id', $journalIds)->delete();

View File

@@ -49,8 +49,8 @@ class NetWorth implements NetWorthInterface
{ {
private AccountRepositoryInterface $accountRepository; private AccountRepositoryInterface $accountRepository;
private CurrencyRepositoryInterface $currencyRepos; private CurrencyRepositoryInterface $currencyRepos;
private User $user; private User $user; // @phpstan-ignore-line
private ?UserGroup $userGroup; private ?UserGroup $userGroup; // @phpstan-ignore-line
/** /**
* This method collects the user's net worth in ALL the user's currencies * This method collects the user's net worth in ALL the user's currencies
@@ -121,14 +121,7 @@ class NetWorth implements NetWorthInterface
return; return;
} }
$this->user = $user; $this->user = $user;
$this->userGroup = null; $this->setUserGroup($user->userGroup);
// make repository:
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->accountRepository->setUser($this->user);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
$this->currencyRepos->setUser($this->user);
} }
public function setUserGroup(UserGroup $userGroup): void public function setUserGroup(UserGroup $userGroup): void
@@ -136,6 +129,9 @@ class NetWorth implements NetWorthInterface
$this->userGroup = $userGroup; $this->userGroup = $userGroup;
$this->accountRepository = app(AccountRepositoryInterface::class); $this->accountRepository = app(AccountRepositoryInterface::class);
$this->accountRepository->setUserGroup($userGroup); $this->accountRepository->setUserGroup($userGroup);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
$this->currencyRepos->setUserGroup($this->userGroup);
} }
/** /**

View File

@@ -148,7 +148,6 @@ class IndexController extends Controller
// enrich each account. // enrich each account.
$enrichment = new AccountEnrichment(); $enrichment = new AccountEnrichment();
$enrichment->setUser(auth()->user()); $enrichment->setUser(auth()->user());
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->defaultCurrency); $enrichment->setNative($this->defaultCurrency);
$return = []; $return = [];
@@ -158,6 +157,7 @@ class IndexController extends Controller
/** @var Account $account */ /** @var Account $account */
foreach ($accounts as $account) { foreach ($accounts as $account) {
/** @var Account $account */
$account = $enrichment->enrichSingle($account); $account = $enrichment->enrichSingle($account);
$array = $accountTransformer->transform($account); $array = $accountTransformer->transform($account);
$accountId = (int) $array['id']; $accountId = (int) $array['id'];

View File

@@ -45,6 +45,7 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Override;
/** /**
* Class AccountRepository. * Class AccountRepository.
@@ -65,12 +66,6 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
return true; return true;
} }
#[\Override]
public function getAccountBalances(Account $account): Collection
{
return $account->accountBalances;
}
/** /**
* Find account with same name OR same IBAN or both, but not the same type or ID. * Find account with same name OR same IBAN or both, but not the same type or ID.
*/ */
@@ -81,8 +76,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
/** @var Account $account */ /** @var Account $account */
foreach ($accounts as $account) { foreach ($accounts as $account) {
$byName = $this->user->accounts()->where('name', $account->name) $byName = $this->user->accounts()->where('name', $account->name)
->where('id', '!=', $account->id)->first() ->where('id', '!=', $account->id)->first();
;
if (null !== $byName) { if (null !== $byName) {
$result->push($account); $result->push($account);
$result->push($byName); $result->push($byName);
@@ -91,8 +85,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
} }
if (null !== $account->iban) { if (null !== $account->iban) {
$byIban = $this->user->accounts()->where('iban', $account->iban) $byIban = $this->user->accounts()->where('iban', $account->iban)
->where('id', '!=', $account->id)->first() ->where('id', '!=', $account->id)->first();
;
if (null !== $byIban) { if (null !== $byIban) {
$result->push($account); $result->push($account);
$result->push($byIban); $result->push($byIban);
@@ -118,8 +111,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
$q1->where('account_meta.name', '=', 'account_number'); $q1->where('account_meta.name', '=', 'account_number');
$q1->where('account_meta.data', '=', $json); $q1->where('account_meta.data', '=', $json);
} }
) );
;
if (0 !== count($types)) { if (0 !== count($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); $dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
@@ -168,6 +160,12 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
return $account; return $account;
} }
#[Override]
public function getAccountBalances(Account $account): Collection
{
return $account->accountBalances;
}
/** /**
* Return account type or null if not found. * Return account type or null if not found.
*/ */
@@ -249,8 +247,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
$journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') $journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id) ->where('transactions.account_id', $account->id)
->transactionTypes([TransactionTypeEnum::LIABILITY_CREDIT->value]) ->transactionTypes([TransactionTypeEnum::LIABILITY_CREDIT->value])
->first(['transaction_journals.*']) ->first(['transaction_journals.*']);
;
return $journal?->transactionGroup; return $journal?->transactionGroup;
} }
@@ -297,8 +294,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
$journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') $journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id) ->where('transactions.account_id', $account->id)
->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value, TransactionTypeEnum::LIABILITY_CREDIT->value]) ->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value, TransactionTypeEnum::LIABILITY_CREDIT->value])
->first(['transaction_journals.*']) ->first(['transaction_journals.*']);
;
if (null === $journal) { if (null === $journal) {
return null; return null;
} }
@@ -321,8 +317,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id) ->where('transactions.account_id', $account->id)
->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value, TransactionTypeEnum::LIABILITY_CREDIT->value]) ->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value, TransactionTypeEnum::LIABILITY_CREDIT->value])
->first(['transaction_journals.*'])?->date->format('Y-m-d H:i:s') ->first(['transaction_journals.*'])?->date->format('Y-m-d H:i:s');
;
} }
public function getOpeningBalanceGroup(Account $account): ?TransactionGroup public function getOpeningBalanceGroup(Account $account): ?TransactionGroup
@@ -337,8 +332,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id) ->where('transactions.account_id', $account->id)
->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value]) ->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value])
->first(['transaction_journals.*']) ->first(['transaction_journals.*']);
;
} }
public function getPiggyBanks(Account $account): Collection public function getPiggyBanks(Account $account): Collection
@@ -363,8 +357,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
/** @var null|Account $current */ /** @var null|Account $current */
$current = $this->user->accounts()->where('account_type_id', $type->id) $current = $this->user->accounts()->where('account_type_id', $type->id)
->where('name', $name) ->where('name', $name)
->first() ->first();
;
if (null !== $current) { if (null !== $current) {
return $current; return $current;
@@ -525,8 +518,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
->orderBy('transaction_journals.order', 'DESC') ->orderBy('transaction_journals.order', 'DESC')
->where('transaction_journals.user_id', $this->user->id) ->where('transaction_journals.user_id', $this->user->id)
->orderBy('transaction_journals.id', 'ASC') ->orderBy('transaction_journals.id', 'ASC')
->first(['transaction_journals.id']) ->first(['transaction_journals.id']);
;
if (null !== $first) { if (null !== $first) {
/** @var null|TransactionJournal */ /** @var null|TransactionJournal */
return TransactionJournal::find($first->id); return TransactionJournal::find($first->id);
@@ -565,8 +557,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
$all = [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value]; $all = [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value];
$this->user->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') $this->user->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->whereNotIn('account_types.type', $all) ->whereNotIn('account_types.type', $all)
->update(['order' => 0]) ->update(['order' => 0]);
;
} }
/** /**
@@ -587,8 +578,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
->orderBy('accounts.order', 'ASC') ->orderBy('accounts.order', 'ASC')
->orderBy('accounts.account_type_id', 'ASC') ->orderBy('accounts.account_type_id', 'ASC')
->orderBy('accounts.name', 'ASC') ->orderBy('accounts.name', 'ASC')
->with(['accountType']) ->with(['accountType']);
;
if ('' !== $query) { if ('' !== $query) {
// split query on spaces just in case: // split query on spaces just in case:
$parts = explode(' ', $query); $parts = explode(' ', $query);
@@ -613,8 +603,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
->orderBy('accounts.order', 'ASC') ->orderBy('accounts.order', 'ASC')
->orderBy('accounts.account_type_id', 'ASC') ->orderBy('accounts.account_type_id', 'ASC')
->orderBy('accounts.name', 'ASC') ->orderBy('accounts.name', 'ASC')
->with(['accountType', 'accountMeta']) ->with(['accountType', 'accountMeta']);
;
if ('' !== $query) { if ('' !== $query) {
// split query on spaces just in case: // split query on spaces just in case:
$parts = explode(' ', $query); $parts = explode(' ', $query);

View File

@@ -52,7 +52,6 @@ interface AccountRepositoryInterface
* Moved here from account CRUD. * Moved here from account CRUD.
*/ */
public function count(array $types): int; public function count(array $types): int;
public function getAccountBalances(Account $account): Collection;
/** /**
* Moved here from account CRUD. * Moved here from account CRUD.
@@ -72,6 +71,8 @@ interface AccountRepositoryInterface
public function findByName(string $name, array $types): ?Account; public function findByName(string $name, array $types): ?Account;
public function getAccountBalances(Account $account): Collection;
public function getAccountCurrency(Account $account): ?TransactionCurrency; public function getAccountCurrency(Account $account): ?TransactionCurrency;
/** /**

View File

@@ -123,7 +123,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
?Collection $accounts = null, ?Collection $accounts = null,
?Collection $expense = null, ?Collection $expense = null,
?TransactionCurrency $currency = null ?TransactionCurrency $currency = null
): array { ): array
{
$journals = $this->getTransactionsForSum(TransactionTypeEnum::WITHDRAWAL->value, $start, $end, $accounts, $expense, $currency); $journals = $this->getTransactionsForSum(TransactionTypeEnum::WITHDRAWAL->value, $start, $end, $accounts, $expense, $currency);
return $this->groupByCurrency($journals, 'negative'); return $this->groupByCurrency($journals, 'negative');
@@ -140,7 +141,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
?Collection $accounts = null, ?Collection $accounts = null,
?Collection $opposing = null, ?Collection $opposing = null,
?TransactionCurrency $currency = null ?TransactionCurrency $currency = null
): array { ): array
{
$start->startOfDay(); $start->startOfDay();
$end->endOfDay(); $end->endOfDay();
@@ -180,8 +182,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([$type])->withAccountInformation() $collector->setUser($this->user)->setRange($start, $end)->setTypes([$type])->withAccountInformation()
->setForeignCurrency($currency) ->setForeignCurrency($currency);
;
if (TransactionTypeEnum::WITHDRAWAL->value === $type) { if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
if (null !== $accounts) { if (null !== $accounts) {
$collector->setSourceAccounts($accounts); $collector->setSourceAccounts($accounts);
@@ -224,7 +225,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
?Collection $accounts = null, ?Collection $accounts = null,
?Collection $expense = null, ?Collection $expense = null,
?TransactionCurrency $currency = null ?TransactionCurrency $currency = null
): array { ): array
{
$journals = $this->getTransactionsForSum(TransactionTypeEnum::WITHDRAWAL->value, $start, $end, $accounts, $expense, $currency); $journals = $this->getTransactionsForSum(TransactionTypeEnum::WITHDRAWAL->value, $start, $end, $accounts, $expense, $currency);
return $this->groupByDirection($journals, 'destination', 'negative'); return $this->groupByDirection($journals, 'destination', 'negative');
@@ -246,7 +248,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
?Collection $accounts = null, ?Collection $accounts = null,
?Collection $expense = null, ?Collection $expense = null,
?TransactionCurrency $currency = null ?TransactionCurrency $currency = null
): array { ): array
{
$journals = $this->getTransactionsForSum(TransactionTypeEnum::WITHDRAWAL->value, $start, $end, $accounts, $expense, $currency); $journals = $this->getTransactionsForSum(TransactionTypeEnum::WITHDRAWAL->value, $start, $end, $accounts, $expense, $currency);
return $this->groupByDirection($journals, 'source', 'negative'); return $this->groupByDirection($journals, 'source', 'negative');
@@ -261,7 +264,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
?Collection $accounts = null, ?Collection $accounts = null,
?Collection $revenue = null, ?Collection $revenue = null,
?TransactionCurrency $currency = null ?TransactionCurrency $currency = null
): array { ): array
{
$journals = $this->getTransactionsForSum(TransactionTypeEnum::DEPOSIT->value, $start, $end, $accounts, $revenue, $currency); $journals = $this->getTransactionsForSum(TransactionTypeEnum::DEPOSIT->value, $start, $end, $accounts, $revenue, $currency);
return $this->groupByCurrency($journals, 'positive'); return $this->groupByCurrency($journals, 'positive');
@@ -276,7 +280,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
?Collection $accounts = null, ?Collection $accounts = null,
?Collection $revenue = null, ?Collection $revenue = null,
?TransactionCurrency $currency = null ?TransactionCurrency $currency = null
): array { ): array
{
$journals = $this->getTransactionsForSum(TransactionTypeEnum::DEPOSIT->value, $start, $end, $accounts, $revenue, $currency); $journals = $this->getTransactionsForSum(TransactionTypeEnum::DEPOSIT->value, $start, $end, $accounts, $revenue, $currency);
return $this->groupByDirection($journals, 'destination', 'positive'); return $this->groupByDirection($journals, 'destination', 'positive');
@@ -291,7 +296,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
?Collection $accounts = null, ?Collection $accounts = null,
?Collection $revenue = null, ?Collection $revenue = null,
?TransactionCurrency $currency = null ?TransactionCurrency $currency = null
): array { ): array
{
$journals = $this->getTransactionsForSum(TransactionTypeEnum::DEPOSIT->value, $start, $end, $accounts, $revenue, $currency); $journals = $this->getTransactionsForSum(TransactionTypeEnum::DEPOSIT->value, $start, $end, $accounts, $revenue, $currency);
return $this->groupByDirection($journals, 'source', 'positive'); return $this->groupByDirection($journals, 'source', 'positive');

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Attachment; namespace FireflyIII\Repositories\Attachment;
use Exception;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AttachmentFactory; use FireflyIII\Factory\AttachmentFactory;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
@@ -35,6 +36,7 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use League\Flysystem\UnableToDeleteFile; use League\Flysystem\UnableToDeleteFile;
use LogicException;
/** /**
* Class AttachmentRepository. * Class AttachmentRepository.
@@ -44,7 +46,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface, UserGroupIn
use UserGroupTrait; use UserGroupTrait;
/** /**
* @throws \Exception * @throws Exception
*/ */
public function destroy(Attachment $attachment): bool public function destroy(Attachment $attachment): bool
{ {
@@ -158,7 +160,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface, UserGroupIn
if (null !== $dbNote) { if (null !== $dbNote) {
try { try {
$dbNote->delete(); $dbNote->delete();
} catch (\LogicException $e) { } catch (LogicException $e) {
app('log')->error($e->getMessage()); app('log')->error($e->getMessage());
} }
} }

View File

@@ -62,8 +62,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
$search->whereLike('name', sprintf('%%%s', $query)); $search->whereLike('name', sprintf('%%%s', $query));
} }
$search->orderBy('name', 'ASC') $search->orderBy('name', 'ASC')
->where('active', true) ->where('active', true);
;
return $search->take($limit)->get(); return $search->take($limit)->get();
} }
@@ -75,8 +74,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
$search->whereLike('name', sprintf('%s%%', $query)); $search->whereLike('name', sprintf('%s%%', $query));
} }
$search->orderBy('name', 'ASC') $search->orderBy('name', 'ASC')
->where('active', true) ->where('active', true);
;
return $search->take($limit)->get(); return $search->take($limit)->get();
} }
@@ -180,8 +178,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
return $this->user->bills() return $this->user->bills()
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('active', 'DESC') ->orderBy('active', 'DESC')
->orderBy('name', 'ASC')->get() ->orderBy('name', 'ASC')->get();
;
} }
public function getBillsForAccounts(Collection $accounts): Collection public function getBillsForAccounts(Collection $accounts): Collection
@@ -222,8 +219,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
->orderBy('bills.active', 'DESC') ->orderBy('bills.active', 'DESC')
->orderBy('bills.name', 'ASC') ->orderBy('bills.name', 'ASC')
->groupBy($fields) ->groupBy($fields)
->get($fields) ->get($fields);
;
} }
/** /**
@@ -297,8 +293,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
{ {
return $this->user->bills() return $this->user->bills()
->orderBy('active', 'DESC') ->orderBy('active', 'DESC')
->orderBy('name', 'ASC')->paginate($size) ->orderBy('name', 'ASC')->paginate($size);
;
} }
/** /**
@@ -317,8 +312,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
'transaction_journals.date', 'transaction_journals.date',
'transaction_journals.transaction_group_id', 'transaction_journals.transaction_group_id',
] ]
) );
;
} }
/** /**
@@ -330,8 +324,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
->leftJoin('rule_actions', 'rule_actions.rule_id', '=', 'rules.id') ->leftJoin('rule_actions', 'rule_actions.rule_id', '=', 'rules.id')
->where('rule_actions.action_type', 'link_to_bill') ->where('rule_actions.action_type', 'link_to_bill')
->where('rule_actions.action_value', $bill->name) ->where('rule_actions.action_value', $bill->name)
->get(['rules.*']) ->get(['rules.*']);
;
} }
/** /**
@@ -345,8 +338,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
$rules = $this->user->rules() $rules = $this->user->rules()
->leftJoin('rule_actions', 'rule_actions.rule_id', '=', 'rules.id') ->leftJoin('rule_actions', 'rule_actions.rule_id', '=', 'rules.id')
->where('rule_actions.action_type', 'link_to_bill') ->where('rule_actions.action_type', 'link_to_bill')
->get(['rules.id', 'rules.title', 'rule_actions.action_value', 'rules.active']) ->get(['rules.id', 'rules.title', 'rule_actions.action_value', 'rules.active']);
;
$array = []; $array = [];
/** @var Rule $rule */ /** @var Rule $rule */
@@ -374,8 +366,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
$journals = $bill->transactionJournals() $journals = $bill->transactionJournals()
->where('date', '>=', $date->year . '-01-01 00:00:00') ->where('date', '>=', $date->year . '-01-01 00:00:00')
->where('date', '<=', $date->year . '-12-31 23:59:59') ->where('date', '<=', $date->year . '-12-31 23:59:59')
->get() ->get();
;
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach ($journals as $journal) { foreach ($journals as $journal) {

View File

@@ -108,8 +108,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
->where('transaction_currency_id', $currency->id) ->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d')) ->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d')) ->where('end_date', $end->format('Y-m-d'))
->first() ->first();
;
} }
public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string
@@ -120,8 +119,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
$availableBudget = $this->user->availableBudgets() $availableBudget = $this->user->availableBudgets()
->where('transaction_currency_id', $currency->id) ->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d')) ->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))->first() ->where('end_date', $end->format('Y-m-d'))->first();
;
if (null !== $availableBudget) { if (null !== $availableBudget) {
$amount = $availableBudget->amount; $amount = $availableBudget->amount;
} }
@@ -135,8 +133,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
$return = []; $return = [];
$availableBudgets = $this->user->availableBudgets() $availableBudgets = $this->user->availableBudgets()
->where('start_date', $start->format('Y-m-d')) ->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))->get() ->where('end_date', $end->format('Y-m-d'))->get();
;
Log::debug(sprintf('Found %d available budgets', $availableBudgets->count())); Log::debug(sprintf('Found %d available budgets', $availableBudgets->count()));
@@ -189,8 +186,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
return $this->user->availableBudgets() return $this->user->availableBudgets()
->where('start_date', '=', $start->format('Y-m-d')) ->where('start_date', '=', $start->format('Y-m-d'))
->where('end_date', '=', $end->format('Y-m-d')) ->where('end_date', '=', $end->format('Y-m-d'))
->get() ->get();
;
} }
public function getByCurrencyDate(Carbon $start, Carbon $end, TransactionCurrency $currency): ?AvailableBudget public function getByCurrencyDate(Carbon $start, Carbon $end, TransactionCurrency $currency): ?AvailableBudget
@@ -200,8 +196,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
->availableBudgets() ->availableBudgets()
->where('transaction_currency_id', $currency->id) ->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d')) ->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))->first() ->where('end_date', $end->format('Y-m-d'))->first();
;
} }
/** /**
@@ -213,8 +208,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
$availableBudget = $this->user->availableBudgets() $availableBudget = $this->user->availableBudgets()
->where('transaction_currency_id', $currency->id) ->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d')) ->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))->first() ->where('end_date', $end->format('Y-m-d'))->first();
;
if (null === $availableBudget) { if (null === $availableBudget) {
$availableBudget = new AvailableBudget(); $availableBudget = new AvailableBudget();
$availableBudget->user()->associate($this->user); $availableBudget->user()->associate($this->user);

View File

@@ -33,10 +33,10 @@ use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface; use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Override;
/** /**
* Class BudgetLimitRepository * Class BudgetLimitRepository
@@ -69,8 +69,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d')); $q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d'));
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d')); $q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d'));
} }
) );
;
} }
) )
->orWhere( ->orWhere(
@@ -79,15 +78,13 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
$q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d')); $q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d'));
$q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d')); $q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d'));
} }
) );
;
} }
) )
->where('budget_limits.transaction_currency_id', $currency->id) ->where('budget_limits.transaction_currency_id', $currency->id)
->whereNull('budgets.deleted_at') ->whereNull('budgets.deleted_at')
->where('budgets.active', true) ->where('budgets.active', true)
->where('budgets.user_id', $this->user->id) ->where('budgets.user_id', $this->user->id);
;
if (null !== $budgets && $budgets->count() > 0) { if (null !== $budgets && $budgets->count() > 0) {
$query->whereIn('budget_limits.budget_id', $budgets->pluck('id')->toArray()); $query->whereIn('budget_limits.budget_id', $budgets->pluck('id')->toArray());
} }
@@ -142,16 +139,14 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
->with(['budget']) ->with(['budget'])
->where('budgets.user_id', $this->user->id) ->where('budgets.user_id', $this->user->id)
->whereNull('budgets.deleted_at') ->whereNull('budgets.deleted_at')
->get(['budget_limits.*']) ->get(['budget_limits.*']);
;
} }
// one of the two is NULL. // one of the two is NULL.
if (null === $start xor null === $end) { if (null === $start xor null === $end) {
$query = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') $query = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
->with(['budget']) ->with(['budget'])
->whereNull('budgets.deleted_at') ->whereNull('budgets.deleted_at')
->where('budgets.user_id', $this->user->id) ->where('budgets.user_id', $this->user->id);
;
if (null !== $end) { if (null !== $end) {
// end date must be before $end. // end date must be before $end.
$query->where('end_date', '<=', $end->format('Y-m-d 00:00:00')); $query->where('end_date', '<=', $end->format('Y-m-d 00:00:00'));
@@ -184,8 +179,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d')); $q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d'));
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d')); $q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d'));
} }
) );
;
} }
) )
->orWhere( ->orWhere(
@@ -194,11 +188,9 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
$q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d')); $q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d'));
$q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d')); $q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d'));
} }
) );
;
} }
)->get(['budget_limits.*']) )->get(['budget_limits.*']);
;
} }
public function getBudgetLimits(Budget $budget, ?Carbon $start = null, ?Carbon $end = null): Collection public function getBudgetLimits(Budget $budget, ?Carbon $start = null, ?Carbon $end = null): Collection
@@ -240,8 +232,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d 00:00:00')); $q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d 00:00:00'));
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d 23:59:59')); $q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d 23:59:59'));
} }
) );
;
} }
) )
->orWhere( ->orWhere(
@@ -250,14 +241,12 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
$q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d 23:59:59')); $q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d 23:59:59'));
$q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d 00:00:00')); $q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d 00:00:00'));
} }
) );
;
} }
)->orderBy('budget_limits.start_date', 'DESC')->get(['budget_limits.*']) )->orderBy('budget_limits.start_date', 'DESC')->get(['budget_limits.*']);
;
} }
#[\Override] #[Override]
public function getNoteText(BudgetLimit $budgetLimit): string public function getNoteText(BudgetLimit $budgetLimit): string
{ {
return (string) $budgetLimit->notes()->first()?->text; return (string) $budgetLimit->notes()->first()?->text;
@@ -290,8 +279,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
->where('budget_limits.start_date', $data['start_date']->format('Y-m-d')) ->where('budget_limits.start_date', $data['start_date']->format('Y-m-d'))
->where('budget_limits.end_date', $data['end_date']->format('Y-m-d')) ->where('budget_limits.end_date', $data['end_date']->format('Y-m-d'))
->where('budget_limits.transaction_currency_id', $currency->id) ->where('budget_limits.transaction_currency_id', $currency->id)
->first(['budget_limits.*']) ->first(['budget_limits.*']);
;
if (null !== $limit) { if (null !== $limit) {
throw new FireflyException('200027: Budget limit already exists.'); throw new FireflyException('200027: Budget limit already exists.');
} }
@@ -322,11 +310,10 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
return $budget->budgetlimits() return $budget->budgetlimits()
->where('transaction_currency_id', $currency->id) ->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d')) ->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))->first() ->where('end_date', $end->format('Y-m-d'))->first();
;
} }
#[\Override] #[Override]
public function setNoteText(BudgetLimit $budgetLimit, string $text): void public function setNoteText(BudgetLimit $budgetLimit, string $text): void
{ {
$dbNote = $budgetLimit->notes()->first(); $dbNote = $budgetLimit->notes()->first();
@@ -393,8 +380,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
$limits = $budget->budgetlimits() $limits = $budget->budgetlimits()
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00')) ->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00')) ->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
->count('budget_limits.*') ->count('budget_limits.*');
;
app('log')->debug(sprintf('Found %d budget limits.', $limits)); app('log')->debug(sprintf('Found %d budget limits.', $limits));
// there might be a budget limit for these dates: // there might be a budget limit for these dates:
@@ -402,8 +388,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
$limit = $budget->budgetlimits() $limit = $budget->budgetlimits()
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00')) ->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00')) ->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
->first(['budget_limits.*']) ->first(['budget_limits.*']);
;
// if more than 1 limit found, delete the others: // if more than 1 limit found, delete the others:
if ($limits > 1 && null !== $limit) { if ($limits > 1 && null !== $limit) {
@@ -411,8 +396,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
$budget->budgetlimits() $budget->budgetlimits()
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00')) ->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00')) ->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
->where('budget_limits.id', '!=', $limit->id)->delete() ->where('budget_limits.id', '!=', $limit->id)->delete();
;
} }
// delete if amount is zero. // delete if amount is zero.

View File

@@ -63,8 +63,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
$search->whereLike('name', sprintf('%%%s', $query)); $search->whereLike('name', sprintf('%%%s', $query));
} }
$search->orderBy('order', 'ASC') $search->orderBy('order', 'ASC')
->orderBy('name', 'ASC')->where('active', true) ->orderBy('name', 'ASC')->where('active', true);
;
return $search->take($limit)->get(); return $search->take($limit)->get();
} }
@@ -76,8 +75,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
$search->whereLike('name', sprintf('%s%%', $query)); $search->whereLike('name', sprintf('%s%%', $query));
} }
$search->orderBy('order', 'ASC') $search->orderBy('order', 'ASC')
->orderBy('name', 'ASC')->where('active', true) ->orderBy('name', 'ASC')->where('active', true);
;
return $search->take($limit)->get(); return $search->take($limit)->get();
} }
@@ -161,8 +159,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
return $this->user->budgets()->where('active', true) return $this->user->budgets()->where('active', true)
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('name', 'ASC') ->orderBy('name', 'ASC')
->get() ->get();
;
} }
/** /**
@@ -327,8 +324,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
->where('rules.user_id', $this->user->id) ->where('rules.user_id', $this->user->id)
->whereIn('rule_actions.action_type', $types) ->whereIn('rule_actions.action_type', $types)
->where('rule_actions.action_value', $oldName) ->where('rule_actions.action_value', $oldName)
->get(['rule_actions.*']) ->get(['rule_actions.*']);
;
app('log')->debug(sprintf('Found %d actions to update.', $actions->count())); app('log')->debug(sprintf('Found %d actions to update.', $actions->count()));
/** @var RuleAction $action */ /** @var RuleAction $action */
@@ -346,8 +342,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
->where('rules.user_id', $this->user->id) ->where('rules.user_id', $this->user->id)
->whereIn('rule_triggers.trigger_type', $types) ->whereIn('rule_triggers.trigger_type', $types)
->where('rule_triggers.trigger_value', $oldName) ->where('rule_triggers.trigger_value', $oldName)
->get(['rule_triggers.*']) ->get(['rule_triggers.*']);
;
app('log')->debug(sprintf('Found %d triggers to update.', $triggers->count())); app('log')->debug(sprintf('Found %d triggers to update.', $triggers->count()));
/** @var RuleTrigger $trigger */ /** @var RuleTrigger $trigger */
@@ -471,8 +466,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
public function getBudgets(): Collection public function getBudgets(): Collection
{ {
return $this->user->budgets()->orderBy('order', 'ASC') return $this->user->budgets()->orderBy('order', 'ASC')
->orderBy('name', 'ASC')->get() ->orderBy('name', 'ASC')->get();
;
} }
public function destroyAutoBudget(Budget $budget): void public function destroyAutoBudget(Budget $budget): void
@@ -557,8 +551,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
{ {
return $this->user->budgets() return $this->user->budgets()
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('name', 'ASC')->where('active', 0)->get() ->orderBy('name', 'ASC')->where('active', 0)->get();
;
} }
public function getNoteText(Budget $budget): ?string public function getNoteText(Budget $budget): ?string
@@ -578,8 +571,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
$search->whereLike('name', sprintf('%%%s%%', $query)); $search->whereLike('name', sprintf('%%%s%%', $query));
} }
$search->orderBy('order', 'ASC') $search->orderBy('order', 'ASC')
->orderBy('name', 'ASC')->where('active', true) ->orderBy('name', 'ASC')->where('active', true);
;
return $search->take($limit)->get(); return $search->take($limit)->get();
} }
@@ -616,8 +608,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
->setRange($start, $end) ->setRange($start, $end)
->excludeDestinationAccounts($selection) ->excludeDestinationAccounts($selection)
->setTypes([TransactionTypeEnum::WITHDRAWAL->value]) ->setTypes([TransactionTypeEnum::WITHDRAWAL->value])
->setBudgets($this->getActiveBudgets()) ->setBudgets($this->getActiveBudgets());
;
$journals = $collector->getExtractedJournals(); $journals = $collector->getExtractedJournals();
$array = []; $array = [];
@@ -678,8 +669,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
->setRange($start, $end) ->setRange($start, $end)
->excludeDestinationAccounts($selection) ->excludeDestinationAccounts($selection)
->setTypes([TransactionTypeEnum::WITHDRAWAL->value]) ->setTypes([TransactionTypeEnum::WITHDRAWAL->value])
->setBudget($budget) ->setBudget($budget);
;
$journals = $collector->getExtractedJournals(); $journals = $collector->getExtractedJournals();
$array = []; $array = [];

View File

@@ -202,7 +202,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
?Collection $accounts = null, ?Collection $accounts = null,
?Collection $budgets = null, ?Collection $budgets = null,
?TransactionCurrency $currency = null ?TransactionCurrency $currency = null
): array { ): array
{
Log::debug(sprintf('Start of %s.', __METHOD__)); Log::debug(sprintf('Start of %s.', __METHOD__));
// this collector excludes all transfers TO liabilities (which are also withdrawals) // this collector excludes all transfers TO liabilities (which are also withdrawals)
// because those expenses only become expenses once they move from the liability to the friend. // because those expenses only become expenses once they move from the liability to the friend.
@@ -225,8 +226,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$collector->setUser($this->user) $collector->setUser($this->user)
->setRange($start, $end) ->setRange($start, $end)
// ->excludeDestinationAccounts($selection) // ->excludeDestinationAccounts($selection)
->setTypes([TransactionTypeEnum::WITHDRAWAL->value]) ->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
;
if (null !== $accounts) { if (null !== $accounts) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Category; namespace FireflyIII\Repositories\Category;
use Carbon\Carbon; use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\CategoryFactory; use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Models\Attachment; use FireflyIII\Models\Attachment;
@@ -224,8 +225,7 @@ class CategoryRepository implements CategoryRepositoryInterface, UserGroupInterf
// check transactions: // check transactions:
$query = $category->transactions() $query = $category->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->orderBy('transaction_journals.date', 'ASC') ->orderBy('transaction_journals.date', 'ASC');
;
$lastTransaction = $query->first(['transaction_journals.*']); $lastTransaction = $query->first(['transaction_journals.*']);
if (null !== $lastTransaction) { if (null !== $lastTransaction) {
@@ -271,7 +271,7 @@ class CategoryRepository implements CategoryRepositoryInterface, UserGroupInterf
} }
/** /**
* @throws \Exception * @throws Exception
*/ */
public function lastUseDate(Category $category, Collection $accounts): ?Carbon public function lastUseDate(Category $category, Collection $accounts): ?Carbon
{ {
@@ -314,15 +314,14 @@ class CategoryRepository implements CategoryRepositoryInterface, UserGroupInterf
} }
/** /**
* @throws \Exception * @throws Exception
*/ */
private function getLastTransactionDate(Category $category, Collection $accounts): ?Carbon private function getLastTransactionDate(Category $category, Collection $accounts): ?Carbon
{ {
// check transactions: // check transactions:
$query = $category->transactions() $query = $category->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.date', 'DESC');
;
if ($accounts->count() > 0) { if ($accounts->count() > 0) {
// filter journals: // filter journals:
$query->whereIn('transactions.account_id', $accounts->pluck('id')->toArray()); $query->whereIn('transactions.account_id', $accounts->pluck('id')->toArray());
@@ -347,7 +346,7 @@ class CategoryRepository implements CategoryRepositoryInterface, UserGroupInterf
} }
/** /**
* @throws \Exception * @throws Exception
*/ */
public function update(Category $category, array $data): Category public function update(Category $category, array $data): Category
{ {

View File

@@ -31,7 +31,6 @@ use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Report\Summarizer\TransactionSummarizer; use FireflyIII\Support\Report\Summarizer\TransactionSummarizer;
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface; use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@@ -194,8 +193,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::TRANSFER->value]) $collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::TRANSFER->value])
->setDestinationAccounts($accounts)->excludeSourceAccounts($accounts) ->setDestinationAccounts($accounts)->excludeSourceAccounts($accounts);
;
if (null !== $categories && $categories->count() > 0) { if (null !== $categories && $categories->count() > 0) {
$collector->setCategories($categories); $collector->setCategories($categories);
} }
@@ -257,8 +255,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::TRANSFER->value]) $collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::TRANSFER->value])
->setSourceAccounts($accounts)->excludeDestinationAccounts($accounts) ->setSourceAccounts($accounts)->excludeDestinationAccounts($accounts);
;
if (null !== $categories && $categories->count() > 0) { if (null !== $categories && $categories->count() > 0) {
$collector->setCategories($categories); $collector->setCategories($categories);
} }
@@ -346,8 +343,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end) $collector->setUser($this->user)->setRange($start, $end)
->setTypes([TransactionTypeEnum::DEPOSIT->value]) ->setTypes([TransactionTypeEnum::DEPOSIT->value]);
;
if (null !== $accounts && $accounts->count() > 0) { if (null !== $accounts && $accounts->count() > 0) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);
@@ -415,8 +411,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end) $collector->setUser($this->user)->setRange($start, $end)
->setTypes([TransactionTypeEnum::TRANSFER->value]) ->setTypes([TransactionTypeEnum::TRANSFER->value]);
;
if (null !== $accounts && $accounts->count() > 0) { if (null !== $accounts && $accounts->count() > 0) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);

View File

@@ -40,9 +40,9 @@ use FireflyIII\Services\Internal\Destroy\CurrencyDestroyService;
use FireflyIII\Services\Internal\Update\CurrencyUpdateService; use FireflyIII\Services\Internal\Update\CurrencyUpdateService;
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface; use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Override;
/** /**
* Class CurrencyRepository. * Class CurrencyRepository.
@@ -60,132 +60,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
return null !== $result; return null !== $result;
} }
public function disable(TransactionCurrency $currency): void
{
$this->userGroup->currencies()->detach($currency->id);
$currency->enabled = false;
$currency->save();
}
public function enable(TransactionCurrency $currency): void
{
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id]);
$currency->enabled = false;
$currency->save();
}
public function update(TransactionCurrency $currency, array $data): TransactionCurrency
{
app('log')->debug('Now in update()');
// can be true, false, null
$enabled = array_key_exists('enabled', $data) ? $data['enabled'] : null;
// can be true, false, but method only responds to "true".
$default = array_key_exists('default', $data) ? $data['default'] : false;
// remove illegal combo's:
if (false === $enabled && true === $default) {
$enabled = true;
}
// update currency with current user specific settings
$currency->refreshForUser($this->user);
// currency is enabled, must be disabled.
if (false === $enabled) {
app('log')->debug(sprintf('Disabled currency %s for user #%d', $currency->code, $this->userGroup->id));
$this->userGroup->currencies()->detach($currency->id);
}
// currency must be enabled
if (true === $enabled) {
app('log')->debug(sprintf('Enabled currency %s for user #%d', $currency->code, $this->userGroup->id));
$this->userGroup->currencies()->detach($currency->id);
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => false]]);
}
// currency must be made default.
if (true === $default) {
$this->makeDefault($currency);
}
/** @var CurrencyUpdateService $service */
$service = app(CurrencyUpdateService::class);
return $service->update($currency, $data);
}
public function destroy(TransactionCurrency $currency): bool
{
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
if ($repository->hasRole($this->user, 'owner')) {
/** @var CurrencyDestroyService $service */
$service = app(CurrencyDestroyService::class);
$service->destroy($currency);
}
return true;
}
/**
* @throws FireflyException
*/
public function store(array $data): TransactionCurrency
{
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
$result = $factory->create($data);
if (true === $data['enabled']) {
$this->userGroup->currencies()->attach($result->id);
}
return $result;
}
public function makeDefault(TransactionCurrency $currency): void
{
$current = app('amount')->getNativeCurrencyByUserGroup($this->userGroup);
app('log')->debug(sprintf('Enabled + made default currency %s for user #%d', $currency->code, $this->userGroup->id));
$this->userGroup->currencies()->detach($currency->id);
foreach ($this->userGroup->currencies()->get() as $item) {
$this->userGroup->currencies()->updateExistingPivot($item->id, ['group_default' => false]);
}
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => true]]);
if ($current->id !== $currency->id) {
Log::debug('Trigger on a different default currency.');
// clear all native amounts through an event.
event(new UserGroupChangedDefaultCurrency($this->userGroup));
}
}
public function isFallbackCurrency(TransactionCurrency $currency): bool
{
return $currency->code === config('firefly.default_currency', 'EUR');
}
/**
* Returns ALL currencies, regardless of whether they are enabled or not.
*/
public function getAll(): Collection
{
$all = TransactionCurrency::orderBy('code', 'ASC')->get();
$local = $this->get();
return $all->map(static function (TransactionCurrency $current) use ($local) {
$hasId = $local->contains(static function (TransactionCurrency $entry) use ($current) {
return $entry->id === $current->id;
});
$isNative = $local->contains(static function (TransactionCurrency $entry) use ($current) {
return 1 === (int) $entry->pivot->group_default && $entry->id === $current->id;
});
$current->userGroupEnabled = $hasId;
$current->userGroupNative = $isNative;
return $current;
});
}
private function countJournals(TransactionCurrency $currency): int
{
$count = $currency->transactions()->whereNull('deleted_at')->count() + $currency->transactionJournals()->whereNull('deleted_at')->count();
// also count foreign:
return $count + Transaction::where('foreign_currency_id', $currency->id)->count();
}
/** /**
* @throws FireflyException * @throws FireflyException
*/ */
@@ -243,8 +118,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
// is being used in accounts (as integer) // is being used in accounts (as integer)
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id') $meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
->whereNull('accounts.deleted_at') ->whereNull('accounts.deleted_at')
->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count() ->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count();
;
if ($meta > 0) { if ($meta > 0) {
app('log')->info(sprintf('Used in %d accounts as currency_id, return true. ', $meta)); app('log')->info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
@@ -288,17 +162,120 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
return null; return null;
} }
public function searchCurrency(string $search, int $limit): Collection private function countJournals(TransactionCurrency $currency): int
{ {
$query = TransactionCurrency::where('enabled', true); $count = $currency->transactions()->whereNull('deleted_at')->count() + $currency->transactionJournals()->whereNull('deleted_at')->count();
if ('' !== $search) {
$query->whereLike('name', sprintf('%%%s%%', $search)); // also count foreign:
return $count + Transaction::where('foreign_currency_id', $currency->id)->count();
} }
return $query->take($limit)->get(); /**
* Returns ALL currencies, regardless of whether they are enabled or not.
*/
public function getAll(): Collection
{
$all = TransactionCurrency::orderBy('code', 'ASC')->get();
$local = $this->get();
return $all->map(static function (TransactionCurrency $current) use ($local) {
$hasId = $local->contains(static function (TransactionCurrency $entry) use ($current) {
return $entry->id === $current->id;
});
$isNative = $local->contains(static function (TransactionCurrency $entry) use ($current) {
return 1 === (int) $entry->pivot->group_default && $entry->id === $current->id;
});
$current->userGroupEnabled = $hasId;
$current->userGroupNative = $isNative;
return $current;
});
} }
#[\Override] public function get(): Collection
{
$all = $this->userGroup->currencies()->orderBy('code', 'ASC')->withPivot(['group_default'])->get();
$all->map(static function (TransactionCurrency $current) { // @phpstan-ignore-line
$current->userGroupEnabled = true;
$current->userGroupNative = 1 === (int) $current->pivot->group_default;
return $current;
});
/** @var Collection */
return $all;
}
public function destroy(TransactionCurrency $currency): bool
{
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
if ($repository->hasRole($this->user, 'owner')) {
/** @var CurrencyDestroyService $service */
$service = app(CurrencyDestroyService::class);
$service->destroy($currency);
}
return true;
}
public function disable(TransactionCurrency $currency): void
{
$this->userGroup->currencies()->detach($currency->id);
$currency->enabled = false;
$currency->save();
}
public function findByName(string $name): ?TransactionCurrency
{
return TransactionCurrency::where('name', $name)->first();
}
/**
* Find by object, ID or code. Returns user default or system default.
*
* @throws FireflyException
*/
public function findCurrency(?int $currencyId, ?string $currencyCode): TransactionCurrency
{
$result = $this->findCurrencyNull($currencyId, $currencyCode);
if (null === $result) {
app('log')->debug('Grabbing default currency for this user...');
/** @var null|TransactionCurrency $result */
$result = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
}
app('log')->debug(sprintf('Final result: %s', $result->code));
if (false === $result->enabled) {
app('log')->debug(sprintf('Also enabled currency %s', $result->code));
$this->enable($result);
}
return $result;
}
/**
* Find by object, ID or code. Returns NULL if nothing found.
*/
public function findCurrencyNull(?int $currencyId, ?string $currencyCode): ?TransactionCurrency
{
app('log')->debug('Now in findCurrencyNull()');
$result = $this->find((int) $currencyId);
if (null === $result) {
app('log')->debug(sprintf('Searching for currency with code %s...', $currencyCode));
$result = $this->findByCode((string) $currencyCode);
}
if (null !== $result && false === $result->enabled) {
app('log')->debug(sprintf('Also enabled currency %s', $result->code));
$this->enable($result);
}
return $result;
}
#[Override]
public function find(int $currencyId): ?TransactionCurrency public function find(int $currencyId): ?TransactionCurrency
{ {
return TransactionCurrency::find($currencyId); return TransactionCurrency::find($currencyId);
@@ -312,6 +289,13 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
return TransactionCurrency::where('code', $currencyCode)->first(); return TransactionCurrency::where('code', $currencyCode)->first();
} }
public function enable(TransactionCurrency $currency): void
{
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id]);
$currency->enabled = false;
$currency->save();
}
/** /**
* Returns the complete set of transactions but needs * Returns the complete set of transactions but needs
* no user object. * no user object.
@@ -320,19 +304,6 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
{ {
return TransactionCurrency::where('enabled', true)->orderBy('code', 'ASC')->get(); return TransactionCurrency::where('enabled', true)->orderBy('code', 'ASC')->get();
} }
public function get(): Collection
{
$all = $this->userGroup->currencies()->orderBy('code', 'ASC')->withPivot(['group_default'])->get();
$all->map(static function (TransactionCurrency $current) { // @phpstan-ignore-line
$current->userGroupEnabled = true;
$current->userGroupNative = 1 === (int) $current->pivot->group_default;
return $current;
});
/** @var Collection */
return $all;
}
/** /**
* Get currency exchange rate. * Get currency exchange rate.
@@ -351,8 +322,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
$rate = $this->user->currencyExchangeRates() $rate = $this->user->currencyExchangeRates()
->where('from_currency_id', $fromCurrency->id) ->where('from_currency_id', $fromCurrency->id)
->where('to_currency_id', $toCurrency->id) ->where('to_currency_id', $toCurrency->id)
->where('date', $date->format('Y-m-d'))->first() ->where('date', $date->format('Y-m-d'))->first();
;
if (null !== $rate) { if (null !== $rate) {
app('log')->debug(sprintf('Found cached exchange rate in database for %s to %s on %s', $fromCurrency->code, $toCurrency->code, $date->format('Y-m-d'))); app('log')->debug(sprintf('Found cached exchange rate in database for %s to %s on %s', $fromCurrency->code, $toCurrency->code, $date->format('Y-m-d')));
@@ -362,6 +332,21 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
return null; return null;
} }
public function isFallbackCurrency(TransactionCurrency $currency): bool
{
return $currency->code === config('firefly.default_currency', 'EUR');
}
public function searchCurrency(string $search, int $limit): Collection
{
$query = TransactionCurrency::where('enabled', true);
if ('' !== $search) {
$query->whereLike('name', sprintf('%%%s%%', $search));
}
return $query->take($limit)->get();
}
/** /**
* TODO must be a factory * TODO must be a factory
*/ */
@@ -379,4 +364,75 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
] ]
); );
} }
/**
* @throws FireflyException
*/
public function store(array $data): TransactionCurrency
{
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
$result = $factory->create($data);
if (true === $data['enabled']) {
$this->userGroup->currencies()->attach($result->id);
}
return $result;
}
public function update(TransactionCurrency $currency, array $data): TransactionCurrency
{
app('log')->debug('Now in update()');
// can be true, false, null
$enabled = array_key_exists('enabled', $data) ? $data['enabled'] : null;
// can be true, false, but method only responds to "true".
$default = array_key_exists('default', $data) ? $data['default'] : false;
// remove illegal combo's:
if (false === $enabled && true === $default) {
$enabled = true;
}
// update currency with current user specific settings
$currency->refreshForUser($this->user);
// currency is enabled, must be disabled.
if (false === $enabled) {
app('log')->debug(sprintf('Disabled currency %s for user #%d', $currency->code, $this->userGroup->id));
$this->userGroup->currencies()->detach($currency->id);
}
// currency must be enabled
if (true === $enabled) {
app('log')->debug(sprintf('Enabled currency %s for user #%d', $currency->code, $this->userGroup->id));
$this->userGroup->currencies()->detach($currency->id);
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => false]]);
}
// currency must be made default.
if (true === $default) {
$this->makeDefault($currency);
}
/** @var CurrencyUpdateService $service */
$service = app(CurrencyUpdateService::class);
return $service->update($currency, $data);
}
public function makeDefault(TransactionCurrency $currency): void
{
$current = app('amount')->getNativeCurrencyByUserGroup($this->userGroup);
app('log')->debug(sprintf('Enabled + made default currency %s for user #%d', $currency->code, $this->userGroup->id));
$this->userGroup->currencies()->detach($currency->id);
foreach ($this->userGroup->currencies()->get() as $item) {
$this->userGroup->currencies()->updateExistingPivot($item->id, ['group_default' => false]);
}
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => true]]);
if ($current->id !== $currency->id) {
Log::debug('Trigger on a different default currency.');
// clear all native amounts through an event.
event(new UserGroupChangedDefaultCurrency($this->userGroup));
}
}
} }

View File

@@ -46,26 +46,24 @@ use Illuminate\Support\Collection;
*/ */
interface CurrencyRepositoryInterface interface CurrencyRepositoryInterface
{ {
public function find(int $currencyId): ?TransactionCurrency; /**
public function searchCurrency(string $search, int $limit): Collection; * @throws FireflyException
public function isFallbackCurrency(TransactionCurrency $currency): bool; */
public function getAll(): Collection; public function currencyInUse(TransactionCurrency $currency): bool;
public function store(array $data): TransactionCurrency;
public function makeDefault(TransactionCurrency $currency): void;
public function destroy(TransactionCurrency $currency): bool;
public function enable(TransactionCurrency $currency): void;
public function disable(TransactionCurrency $currency): void;
public function update(TransactionCurrency $currency, array $data): TransactionCurrency;
/**
* @throws FireflyException
*/
public function currencyInUse(TransactionCurrency $currency);
/** /**
* @throws FireflyException * @throws FireflyException
*/ */
public function currencyInUseAt(TransactionCurrency $currency): ?string; public function currencyInUseAt(TransactionCurrency $currency): ?string;
public function destroy(TransactionCurrency $currency): bool;
public function disable(TransactionCurrency $currency): void;
public function enable(TransactionCurrency $currency): void;
public function find(int $currencyId): ?TransactionCurrency;
/** /**
* Find by currency code, return NULL if unfound. * Find by currency code, return NULL if unfound.
* *
@@ -73,6 +71,21 @@ interface CurrencyRepositoryInterface
*/ */
public function findByCode(string $currencyCode): ?TransactionCurrency; public function findByCode(string $currencyCode): ?TransactionCurrency;
public function findByName(string $name): ?TransactionCurrency;
public function findCurrency(?int $currencyId, ?string $currencyCode): TransactionCurrency;
public function findCurrencyNull(?int $currencyId, ?string $currencyCode): ?TransactionCurrency;
/**
* Get the user group's currencies.
*
* @return Collection<TransactionCurrency>
*/
public function get(): Collection;
public function getAll(): Collection;
/** /**
* Returns the complete set of transactions but needs * Returns the complete set of transactions but needs
* no user object. * no user object.
@@ -81,14 +94,6 @@ interface CurrencyRepositoryInterface
*/ */
public function getCompleteSet(): Collection; public function getCompleteSet(): Collection;
/**
* Get the user group's currencies.
*
* @return Collection<TransactionCurrency>
*/
public function get(): Collection;
/** /**
* Get currency exchange rate. * Get currency exchange rate.
* *
@@ -96,10 +101,20 @@ interface CurrencyRepositoryInterface
*/ */
public function getExchangeRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date): ?CurrencyExchangeRate; public function getExchangeRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date): ?CurrencyExchangeRate;
public function isFallbackCurrency(TransactionCurrency $currency): bool;
public function makeDefault(TransactionCurrency $currency): void;
public function searchCurrency(string $search, int $limit): Collection;
/** /**
* Set currency exchange rate. * Set currency exchange rate.
* *
* Used in download exchange rate cron job. Needs the user object! * Used in download exchange rate cron job. Needs the user object!
*/ */
public function setExchangeRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date, float $rate): CurrencyExchangeRate; public function setExchangeRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date, float $rate): CurrencyExchangeRate;
public function store(array $data): TransactionCurrency;
public function update(TransactionCurrency $currency, array $data): TransactionCurrency;
} }

View File

@@ -30,24 +30,25 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Override;
class ExchangeRateRepository implements ExchangeRateRepositoryInterface, UserGroupInterface class ExchangeRateRepository implements ExchangeRateRepositoryInterface, UserGroupInterface
{ {
use UserGroupTrait; use UserGroupTrait;
#[\Override] #[Override]
public function deleteRate(CurrencyExchangeRate $rate): void public function deleteRate(CurrencyExchangeRate $rate): void
{ {
$this->userGroup->currencyExchangeRates()->where('id', $rate->id)->delete(); $this->userGroup->currencyExchangeRates()->where('id', $rate->id)->delete();
} }
#[\Override] #[Override]
public function getAll(): Collection public function getAll(): Collection
{ {
return $this->userGroup->currencyExchangeRates()->orderBy('date', 'ASC')->get(); return $this->userGroup->currencyExchangeRates()->orderBy('date', 'ASC')->get();
} }
#[\Override] #[Override]
public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection
{ {
// orderBy('date', 'DESC')->toRawSql(); // orderBy('date', 'DESC')->toRawSql();
@@ -56,21 +57,18 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface, UserGro
->where(function (Builder $q1) use ($from, $to): void { ->where(function (Builder $q1) use ($from, $to): void {
$q1->where(function (Builder $q) use ($from, $to): void { $q1->where(function (Builder $q) use ($from, $to): void {
$q->where('from_currency_id', $from->id) $q->where('from_currency_id', $from->id)
->where('to_currency_id', $to->id) ->where('to_currency_id', $to->id);
;
})->orWhere(function (Builder $q) use ($from, $to): void { })->orWhere(function (Builder $q) use ($from, $to): void {
$q->where('from_currency_id', $to->id) $q->where('from_currency_id', $to->id)
->where('to_currency_id', $from->id) ->where('to_currency_id', $from->id);
;
}); });
}) })
->orderBy('date', 'DESC') ->orderBy('date', 'DESC')
->get(['currency_exchange_rates.*']) ->get(['currency_exchange_rates.*']);
;
} }
#[\Override] #[Override]
public function getSpecificRateOnDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): ?CurrencyExchangeRate public function getSpecificRateOnDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): ?CurrencyExchangeRate
{ {
/** @var null|CurrencyExchangeRate */ /** @var null|CurrencyExchangeRate */
@@ -79,11 +77,10 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface, UserGro
->where('from_currency_id', $from->id) ->where('from_currency_id', $from->id)
->where('to_currency_id', $to->id) ->where('to_currency_id', $to->id)
->where('date', $date->format('Y-m-d')) ->where('date', $date->format('Y-m-d'))
->first() ->first();
;
} }
#[\Override] #[Override]
public function storeExchangeRate(TransactionCurrency $from, TransactionCurrency $to, string $rate, Carbon $date): CurrencyExchangeRate public function storeExchangeRate(TransactionCurrency $from, TransactionCurrency $to, string $rate, Carbon $date): CurrencyExchangeRate
{ {
$object = new CurrencyExchangeRate(); $object = new CurrencyExchangeRate();
@@ -99,7 +96,7 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface, UserGro
return $object; return $object;
} }
#[\Override] #[Override]
public function updateExchangeRate(CurrencyExchangeRate $object, string $rate, ?Carbon $date = null): CurrencyExchangeRate public function updateExchangeRate(CurrencyExchangeRate $object, string $rate, ?Carbon $date = null): CurrencyExchangeRate
{ {
$object->rate = $rate; $object->rate = $rate;

View File

@@ -49,8 +49,7 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface, UserGroupIn
return Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') return Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.user_id', $this->user->id) ->where('transaction_journals.user_id', $this->user->id)
->where('transactions.id', $transactionId) ->where('transactions.id', $transactionId)
->first(['transactions.*']) ->first(['transactions.*']);
;
} }
/** /**

View File

@@ -32,6 +32,7 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use stdClass;
/** /**
* Class JournalCLIRepository * Class JournalCLIRepository
@@ -48,8 +49,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface, UserGroupIn
return TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') return TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->whereIn('transaction_types.type', $types) ->whereIn('transaction_types.type', $types)
->with(['user', 'transactionType', 'transactionCurrency', 'transactions', 'transactions.account']) ->with(['user', 'transactionType', 'transactionCurrency', 'transactions', 'transactions.account'])
->get(['transaction_journals.*']) ->get(['transaction_journals.*']);
;
} }
/** /**
@@ -179,12 +179,11 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface, UserGroupIn
public function getSplitJournals(): Collection public function getSplitJournals(): Collection
{ {
$query = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') $query = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->groupBy('transaction_journals.id') ->groupBy('transaction_journals.id');
;
$result = $query->get(['transaction_journals.id as id', DB::raw('count(transactions.id) as transaction_count')]); // @phpstan-ignore-line $result = $query->get(['transaction_journals.id as id', DB::raw('count(transactions.id) as transaction_count')]); // @phpstan-ignore-line
$journalIds = []; $journalIds = [];
/** @var \stdClass $row */ /** @var stdClass $row */
foreach ($result as $row) { foreach ($result as $row) {
if ((int) $row->transaction_count > 2) { if ((int) $row->transaction_count > 2) {
$journalIds[] = (int) $row->id; $journalIds[] = (int) $row->id;
@@ -193,8 +192,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface, UserGroupIn
$journalIds = array_unique($journalIds); $journalIds = array_unique($journalIds);
return TransactionJournal::with(['transactions']) return TransactionJournal::with(['transactions'])
->whereIn('id', $journalIds)->get() ->whereIn('id', $journalIds)->get();
;
} }
/** /**

View File

@@ -67,8 +67,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
->transactionJournals() ->transactionJournals()
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->whereIn('transaction_types.type', $types) ->whereIn('transaction_types.type', $types)
->get(['transaction_journals.*']) ->get(['transaction_journals.*']);
;
} }
/** /**
@@ -151,8 +150,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
return new Carbon($cache->get()); return new Carbon($cache->get());
} }
$entry = TransactionJournalMeta::where('transaction_journal_id', $journalId) $entry = TransactionJournalMeta::where('transaction_journal_id', $journalId)
->where('name', $field)->first() ->where('name', $field)->first();
;
if (null === $entry) { if (null === $entry) {
return null; return null;
} }
@@ -195,8 +193,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
public function searchJournalDescriptions(string $search, int $limit): Collection public function searchJournalDescriptions(string $search, int $limit): Collection
{ {
$query = $this->user->transactionJournals() $query = $this->user->transactionJournals()
->orderBy('date', 'DESC') ->orderBy('date', 'DESC');
;
if ('' !== $search) { if ('' !== $search) {
$query->whereLike('description', sprintf('%%%s%%', $search)); $query->whereLike('description', sprintf('%%%s%%', $search));
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\LinkType; namespace FireflyIII\Repositories\LinkType;
use Exception;
use FireflyIII\Events\DestroyedTransactionLink; use FireflyIII\Events\DestroyedTransactionLink;
use FireflyIII\Models\LinkType; use FireflyIII\Models\LinkType;
use FireflyIII\Models\Note; use FireflyIII\Models\Note;
@@ -71,7 +72,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface, UserGroupInterf
} }
/** /**
* @throws \Exception * @throws Exception
*/ */
public function destroyLink(TransactionJournalLink $link): bool public function destroyLink(TransactionJournalLink $link): bool
{ {
@@ -121,8 +122,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface, UserGroupInterf
->where('source_journals.user_id', $this->user->id) ->where('source_journals.user_id', $this->user->id)
->where('dest_journals.user_id', $this->user->id) ->where('dest_journals.user_id', $this->user->id)
->whereNull('source_journals.deleted_at') ->whereNull('source_journals.deleted_at')
->whereNull('dest_journals.deleted_at') ->whereNull('dest_journals.deleted_at');
;
if (null !== $linkType) { if (null !== $linkType) {
$query->where('journal_links.link_type_id', $linkType->id); $query->where('journal_links.link_type_id', $linkType->id);
@@ -172,7 +172,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface, UserGroupInterf
/** /**
* Store link between two journals. * Store link between two journals.
* *
* @throws \Exception * @throws Exception
*/ */
public function storeLink(array $information, TransactionJournal $inward, TransactionJournal $outward): ?TransactionJournalLink public function storeLink(array $information, TransactionJournal $inward, TransactionJournal $outward): ?TransactionJournalLink
{ {
@@ -234,12 +234,11 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface, UserGroupInterf
{ {
return TransactionJournalLink::where('link_type_id', $linkType->id) return TransactionJournalLink::where('link_type_id', $linkType->id)
->where('source_id', $inward->id) ->where('source_id', $inward->id)
->where('destination_id', $outward->id)->first() ->where('destination_id', $outward->id)->first();
;
} }
/** /**
* @throws \Exception * @throws Exception
*/ */
private function setNoteText(TransactionJournalLink $link, string $text): void private function setNoteText(TransactionJournalLink $link, string $text): void
{ {
@@ -281,7 +280,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface, UserGroupInterf
/** /**
* Update an existing transaction journal link. * Update an existing transaction journal link.
* *
* @throws \Exception * @throws Exception
*/ */
public function updateLink(TransactionJournalLink $journalLink, array $data): TransactionJournalLink public function updateLink(TransactionJournalLink $journalLink, array $data): TransactionJournalLink
{ {

View File

@@ -55,8 +55,7 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface, UserGroup
return $this->user->objectGroups() return $this->user->objectGroups()
->with(['piggyBanks', 'bills']) ->with(['piggyBanks', 'bills'])
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('title', 'ASC')->get() ->orderBy('title', 'ASC')->get();
;
} }
public function deleteEmpty(): void public function deleteEmpty(): void
@@ -150,8 +149,7 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface, UserGroup
if ($newOrder > $oldOrder) { if ($newOrder > $oldOrder) {
$this->user->objectGroups()->where('object_groups.order', '<=', $newOrder)->where('object_groups.order', '>', $oldOrder) $this->user->objectGroups()->where('object_groups.order', '<=', $newOrder)->where('object_groups.order', '>', $oldOrder)
->where('object_groups.id', '!=', $objectGroup->id) ->where('object_groups.id', '!=', $objectGroup->id)
->decrement('object_groups.order') ->decrement('object_groups.order');
;
$objectGroup->order = $newOrder; $objectGroup->order = $newOrder;
$objectGroup->save(); $objectGroup->save();
@@ -159,8 +157,7 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface, UserGroup
if ($newOrder < $oldOrder) { if ($newOrder < $oldOrder) {
$this->user->objectGroups()->where('object_groups.order', '>=', $newOrder)->where('object_groups.order', '<', $oldOrder) $this->user->objectGroups()->where('object_groups.order', '>=', $newOrder)->where('object_groups.order', '<', $oldOrder)
->where('object_groups.id', '!=', $objectGroup->id) ->where('object_groups.id', '!=', $objectGroup->id)
->increment('object_groups.order') ->increment('object_groups.order');
;
$objectGroup->order = $newOrder; $objectGroup->order = $newOrder;
$objectGroup->save(); $objectGroup->save();

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\PiggyBank; namespace FireflyIII\Repositories\PiggyBank;
use Exception;
use FireflyIII\Events\Model\PiggyBank\ChangedAmount; use FireflyIII\Events\Model\PiggyBank\ChangedAmount;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\PiggyBankFactory; use FireflyIII\Factory\PiggyBankFactory;
@@ -141,7 +142,7 @@ trait ModifiesPiggyBanks
} }
/** /**
* @throws \Exception * @throws Exception
*/ */
public function destroy(PiggyBank $piggyBank): bool public function destroy(PiggyBank $piggyBank): bool
{ {
@@ -326,8 +327,7 @@ trait ModifiesPiggyBanks
->where('accounts.user_id', $this->user->id) ->where('accounts.user_id', $this->user->id)
->where('piggy_banks.order', '<=', $newOrder)->where('piggy_banks.order', '>', $oldOrder) ->where('piggy_banks.order', '<=', $newOrder)->where('piggy_banks.order', '>', $oldOrder)
->where('piggy_banks.id', '!=', $piggyBank->id) ->where('piggy_banks.id', '!=', $piggyBank->id)
->distinct()->decrement('piggy_banks.order') ->distinct()->decrement('piggy_banks.order');
;
$piggyBank->order = $newOrder; $piggyBank->order = $newOrder;
Log::debug(sprintf('[1] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder)); Log::debug(sprintf('[1] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
@@ -340,8 +340,7 @@ trait ModifiesPiggyBanks
->where('accounts.user_id', $this->user->id) ->where('accounts.user_id', $this->user->id)
->where('piggy_banks.order', '>=', $newOrder)->where('piggy_banks.order', '<', $oldOrder) ->where('piggy_banks.order', '>=', $newOrder)->where('piggy_banks.order', '<', $oldOrder)
->where('piggy_banks.id', '!=', $piggyBank->id) ->where('piggy_banks.id', '!=', $piggyBank->id)
->distinct()->increment('piggy_banks.order') ->distinct()->increment('piggy_banks.order');
;
$piggyBank->order = $newOrder; $piggyBank->order = $newOrder;
Log::debug(sprintf('[2] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder)); Log::debug(sprintf('[2] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));

View File

@@ -41,6 +41,7 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Override;
/** /**
* Class PiggyBankRepository. * Class PiggyBankRepository.
@@ -58,8 +59,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id') PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id') ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
->where('accounts.user_id', $this->user->id) ->where('accounts.user_id', $this->user->id)
->delete() ->delete();
;
} }
public function findPiggyBank(?int $piggyBankId, ?string $piggyBankName): ?PiggyBank public function findPiggyBank(?int $piggyBankId, ?string $piggyBankName): ?PiggyBank
@@ -92,8 +92,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
return PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id') return PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id') ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
->where('accounts.user_id', $this->user->id) ->where('accounts.user_id', $this->user->id)
->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']) ->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
;
} }
/** /**
@@ -104,8 +103,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
return PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id') return PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id') ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
->where('accounts.user_id', $this->user->id) ->where('accounts.user_id', $this->user->id)
->where('piggy_banks.name', $name)->first(['piggy_banks.*']) ->where('piggy_banks.name', $name)->first(['piggy_banks.*']);
;
} }
public function getAttachments(PiggyBank $piggyBank): Collection public function getAttachments(PiggyBank $piggyBank): Collection
@@ -315,8 +313,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
'objectGroups', 'objectGroups',
] ]
) )
->orderBy('piggy_banks.order', 'ASC')->distinct()->get(['piggy_banks.*']) ->orderBy('piggy_banks.order', 'ASC')->distinct()->get(['piggy_banks.*']);
;
} }
public function getRepetition(PiggyBank $piggyBank, bool $overrule = false): ?PiggyBankRepetition public function getRepetition(PiggyBank $piggyBank, bool $overrule = false): ?PiggyBankRepetition
@@ -382,7 +379,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
return $balance; return $balance;
} }
#[\Override] #[Override]
public function purgeAll(): void public function purgeAll(): void
{ {
PiggyBank::withTrashed() PiggyBank::withTrashed()
@@ -395,11 +392,10 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
'objectGroups', 'objectGroups',
] ]
) )
->delete() ->delete();
;
} }
#[\Override] #[Override]
public function resetOrder(): void public function resetOrder(): void
{ {
$factory = new PiggyBankFactory(); $factory = new PiggyBankFactory();
@@ -417,14 +413,12 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
'objectGroups', 'objectGroups',
] ]
) )
->orderBy('piggy_banks.order', 'ASC')->distinct() ->orderBy('piggy_banks.order', 'ASC')->distinct();
;
if ('' !== $query) { if ('' !== $query) {
$search->whereLike('piggy_banks.name', sprintf('%%%s%%', $query)); $search->whereLike('piggy_banks.name', sprintf('%%%s%%', $query));
} }
$search->orderBy('piggy_banks.order', 'ASC') $search->orderBy('piggy_banks.order', 'ASC')
->orderBy('piggy_banks.name', 'ASC') ->orderBy('piggy_banks.name', 'ASC');
;
return $search->take($limit)->get(['piggy_banks.*']); return $search->take($limit)->get(['piggy_banks.*']);
} }

View File

@@ -45,7 +45,6 @@ use FireflyIII\Support\Repositories\Recurring\CalculateXOccurrencesSince;
use FireflyIII\Support\Repositories\Recurring\FiltersWeekends; use FireflyIII\Support\Repositories\Recurring\FiltersWeekends;
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface; use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@@ -81,8 +80,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
$q2->where('data', json_encode($string)); $q2->where('data', json_encode($string));
}) })
->where('transaction_journal_id', $journalMeta->transaction_journal_id) ->where('transaction_journal_id', $journalMeta->transaction_journal_id)
->count() ->count();
;
if ($count > 0) { if ($count > 0) {
app('log')->debug(sprintf('Looks like journal #%d was already created', $journalMeta->transaction_journal_id)); app('log')->debug(sprintf('Looks like journal #%d was already created', $journalMeta->transaction_journal_id));
@@ -103,8 +101,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
->orderBy('active', 'DESC') ->orderBy('active', 'DESC')
->orderBy('transaction_type_id', 'ASC') ->orderBy('transaction_type_id', 'ASC')
->orderBy('title', 'ASC') ->orderBy('title', 'ASC')
->get() ->get();
;
} }
/** /**
@@ -132,8 +129,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
return Recurrence::with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions']) return Recurrence::with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions'])
->orderBy('active', 'DESC') ->orderBy('active', 'DESC')
->orderBy('title', 'ASC') ->orderBy('title', 'ASC')
->get() ->get();
;
} }
public function getBillId(RecurrenceTransaction $recTransaction): ?int public function getBillId(RecurrenceTransaction $recTransaction): ?int
@@ -211,8 +207,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
->where('transaction_journals.user_id', $recurrence->user_id) ->where('transaction_journals.user_id', $recurrence->user_id)
->whereNull('transaction_journals.deleted_at') ->whereNull('transaction_journals.deleted_at')
->where('journal_meta.name', 'recurrence_id') ->where('journal_meta.name', 'recurrence_id')
->where('journal_meta.data', '"'.$recurrence->id.'"') ->where('journal_meta.data', '"' . $recurrence->id . '"');
;
if (null !== $start) { if (null !== $start) {
$query->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')); $query->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'));
} }
@@ -234,8 +229,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
->where('transaction_journals.user_id', $this->user->id) ->where('transaction_journals.user_id', $this->user->id)
->where('journal_meta.name', '=', 'recurrence_id') ->where('journal_meta.name', '=', 'recurrence_id')
->where('journal_meta.data', '=', json_encode((string) $recurrence->id)) ->where('journal_meta.data', '=', json_encode((string) $recurrence->id))
->get(['journal_meta.transaction_journal_id'])->pluck('transaction_journal_id')->toArray() ->get(['journal_meta.transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
;
} }
/** /**
@@ -287,8 +281,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
->where('transaction_journals.user_id', $this->user->id) ->where('transaction_journals.user_id', $this->user->id)
->where('name', 'recurrence_id') ->where('name', 'recurrence_id')
->where('data', json_encode((string) $recurrence->id)) ->where('data', json_encode((string) $recurrence->id))
->get()->pluck('transaction_journal_id')->toArray() ->get()->pluck('transaction_journal_id')->toArray();
;
$search = []; $search = [];
foreach ($journalMeta as $journalId) { foreach ($journalMeta as $journalId) {
$search[] = (int) $journalId; $search[] = (int) $journalId;
@@ -299,8 +292,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
$collector->setUser($recurrence->user); $collector->setUser($recurrence->user);
$collector->withCategoryInformation()->withBudgetInformation()->setLimit($pageSize)->setPage($page) $collector->withCategoryInformation()->withBudgetInformation()->setLimit($pageSize)->setPage($page)
->withAccountInformation() ->withAccountInformation();
;
$collector->setJournalIds($search); $collector->setJournalIds($search);
return $collector->getPaginatedGroups(); return $collector->getPaginatedGroups();
@@ -313,8 +305,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
->where('transaction_journals.user_id', $this->user->id) ->where('transaction_journals.user_id', $this->user->id)
->where('name', 'recurrence_id') ->where('name', 'recurrence_id')
->where('data', json_encode((string) $recurrence->id)) ->where('data', json_encode((string) $recurrence->id))
->get()->pluck('transaction_journal_id')->toArray() ->get()->pluck('transaction_journal_id')->toArray();
;
$search = []; $search = [];
foreach ($journalMeta as $journalId) { foreach ($journalMeta as $journalId) {
@@ -497,8 +488,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
$search->whereLike('recurrences.title', sprintf('%%%s%%', $query)); $search->whereLike('recurrences.title', sprintf('%%%s%%', $query));
} }
$search $search
->orderBy('recurrences.title', 'ASC') ->orderBy('recurrences.title', 'ASC');
;
return $search->take($limit)->get(['id', 'title', 'description']); return $search->take($limit)->get(['id', 'title', 'description']);
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Rule; namespace FireflyIII\Repositories\Rule;
use Exception;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleAction;
@@ -42,7 +43,7 @@ class RuleRepository implements RuleRepositoryInterface, UserGroupInterface
use UserGroupTrait; use UserGroupTrait;
/** /**
* @throws \Exception * @throws Exception
*/ */
public function destroy(Rule $rule): bool public function destroy(Rule $rule): bool
{ {
@@ -166,8 +167,7 @@ class RuleRepository implements RuleRepositoryInterface, UserGroupInterface
->orderBy('rule_groups.order', 'ASC') ->orderBy('rule_groups.order', 'ASC')
->orderBy('rules.order', 'ASC') ->orderBy('rules.order', 'ASC')
->orderBy('rules.id', 'ASC') ->orderBy('rules.id', 'ASC')
->with(['ruleGroup', 'ruleTriggers'])->get(['rules.*']) ->with(['ruleGroup', 'ruleTriggers'])->get(['rules.*']);
;
$filtered = new Collection(); $filtered = new Collection();
/** @var Rule $rule */ /** @var Rule $rule */
@@ -192,8 +192,7 @@ class RuleRepository implements RuleRepositoryInterface, UserGroupInterface
->orderBy('rule_groups.order', 'ASC') ->orderBy('rule_groups.order', 'ASC')
->orderBy('rules.order', 'ASC') ->orderBy('rules.order', 'ASC')
->orderBy('rules.id', 'ASC') ->orderBy('rules.id', 'ASC')
->with(['ruleGroup', 'ruleTriggers'])->get() ->with(['ruleGroup', 'ruleTriggers'])->get();
;
$filtered = new Collection(); $filtered = new Collection();
/** @var Rule $rule */ /** @var Rule $rule */
@@ -216,8 +215,7 @@ class RuleRepository implements RuleRepositoryInterface, UserGroupInterface
$search->whereLike('rules.title', sprintf('%%%s%%', $query)); $search->whereLike('rules.title', sprintf('%%%s%%', $query));
} }
$search->orderBy('rules.order', 'ASC') $search->orderBy('rules.order', 'ASC')
->orderBy('rules.title', 'ASC') ->orderBy('rules.title', 'ASC');
;
return $search->take($limit)->get(['id', 'title', 'description']); return $search->take($limit)->get(['id', 'title', 'description']);
} }
@@ -325,8 +323,7 @@ class RuleRepository implements RuleRepositoryInterface, UserGroupInterface
->where('rules.order', '<=', $newOrder) ->where('rules.order', '<=', $newOrder)
->where('rules.order', '>', $oldOrder) ->where('rules.order', '>', $oldOrder)
->where('rules.id', '!=', $rule->id) ->where('rules.id', '!=', $rule->id)
->decrement('rules.order') ->decrement('rules.order');
;
$rule->order = $newOrder; $rule->order = $newOrder;
app('log')->debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder)); app('log')->debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder));
$rule->save(); $rule->save();
@@ -339,8 +336,7 @@ class RuleRepository implements RuleRepositoryInterface, UserGroupInterface
->where('rules.order', '>=', $newOrder) ->where('rules.order', '>=', $newOrder)
->where('rules.order', '<', $oldOrder) ->where('rules.order', '<', $oldOrder)
->where('rules.id', '!=', $rule->id) ->where('rules.id', '!=', $rule->id)
->increment('rules.order') ->increment('rules.order');
;
$rule->order = $newOrder; $rule->order = $newOrder;
app('log')->debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder)); app('log')->debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder));
$rule->save(); $rule->save();

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\RuleGroup; namespace FireflyIII\Repositories\RuleGroup;
use Exception;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleAction;
use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleGroup;
@@ -47,8 +48,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('active', 'DESC') ->orderBy('active', 'DESC')
->orderBy('title', 'ASC') ->orderBy('title', 'ASC')
->get(['rule_groups.id']) ->get(['rule_groups.id']);
;
$index = 1; $index = 1;
/** @var RuleGroup $ruleGroup */ /** @var RuleGroup $ruleGroup */
@@ -72,7 +72,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
} }
/** /**
* @throws \Exception * @throws Exception
*/ */
public function destroy(RuleGroup $ruleGroup, ?RuleGroup $moveTo): bool public function destroy(RuleGroup $ruleGroup, ?RuleGroup $moveTo): bool
{ {
@@ -105,8 +105,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
->whereNull('deleted_at') ->whereNull('deleted_at')
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('title', 'DESC') ->orderBy('title', 'DESC')
->get() ->get();
;
$count = 1; $count = 1;
/** @var RuleGroup $entry */ /** @var RuleGroup $entry */
@@ -131,8 +130,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('title', 'DESC') ->orderBy('title', 'DESC')
->orderBy('updated_at', 'DESC') ->orderBy('updated_at', 'DESC')
->get(['rules.*']) ->get(['rules.*']);
;
$count = 1; $count = 1;
/** @var Rule $entry */ /** @var Rule $entry */
@@ -157,8 +155,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('active', 'DESC') ->orderBy('active', 'DESC')
->orderBy('action_type', 'ASC') ->orderBy('action_type', 'ASC')
->get() ->get();
;
$index = 1; $index = 1;
/** @var RuleAction $action */ /** @var RuleAction $action */
@@ -178,8 +175,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('active', 'DESC') ->orderBy('active', 'DESC')
->orderBy('trigger_type', 'ASC') ->orderBy('trigger_type', 'ASC')
->get() ->get();
;
$index = 1; $index = 1;
/** @var RuleTrigger $trigger */ /** @var RuleTrigger $trigger */
@@ -227,8 +223,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
{ {
return $group->rules() return $group->rules()
->where('rules.active', true) ->where('rules.active', true)
->get(['rules.*']) ->get(['rules.*']);
;
} }
public function getActiveStoreRules(RuleGroup $group): Collection public function getActiveStoreRules(RuleGroup $group): Collection
@@ -238,8 +233,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
->where('rule_triggers.trigger_type', 'user_action') ->where('rule_triggers.trigger_type', 'user_action')
->where('rule_triggers.trigger_value', 'store-journal') ->where('rule_triggers.trigger_value', 'store-journal')
->where('rules.active', true) ->where('rules.active', true)
->get(['rules.*']) ->get(['rules.*']);
;
} }
public function getActiveUpdateRules(RuleGroup $group): Collection public function getActiveUpdateRules(RuleGroup $group): Collection
@@ -249,8 +243,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
->where('rule_triggers.trigger_type', 'user_action') ->where('rule_triggers.trigger_type', 'user_action')
->where('rule_triggers.trigger_value', 'update-journal') ->where('rule_triggers.trigger_value', 'update-journal')
->where('rules.active', true) ->where('rules.active', true)
->get(['rules.*']) ->get(['rules.*']);
;
} }
public function getAllRuleGroupsWithRules(?string $filter): Collection public function getAllRuleGroupsWithRules(?string $filter): Collection
@@ -269,8 +262,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
$query->orderBy('order', 'ASC'); $query->orderBy('order', 'ASC');
}, },
] ]
)->get() )->get();
;
if (null === $filter) { if (null === $filter) {
return $groups; return $groups;
} }
@@ -325,8 +317,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
$query->orderBy('order', 'ASC'); $query->orderBy('order', 'ASC');
}, },
] ]
)->get() )->get();
;
if (null === $filter) { if (null === $filter) {
return $groups; return $groups;
} }
@@ -360,8 +351,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
public function getRules(RuleGroup $group): Collection public function getRules(RuleGroup $group): Collection
{ {
return $group->rules() return $group->rules()
->get(['rules.*']) ->get(['rules.*']);
;
} }
public function maxOrder(): int public function maxOrder(): int
@@ -376,8 +366,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
$search->whereLike('rule_groups.title', sprintf('%%%s%%', $query)); $search->whereLike('rule_groups.title', sprintf('%%%s%%', $query));
} }
$search->orderBy('rule_groups.order', 'ASC') $search->orderBy('rule_groups.order', 'ASC')
->orderBy('rule_groups.title', 'ASC') ->orderBy('rule_groups.title', 'ASC');
;
return $search->take($limit)->get(['id', 'title', 'description']); return $search->take($limit)->get(['id', 'title', 'description']);
} }
@@ -410,8 +399,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
if ($newOrder > $oldOrder) { if ($newOrder > $oldOrder) {
$this->user->ruleGroups()->where('rule_groups.order', '<=', $newOrder)->where('rule_groups.order', '>', $oldOrder) $this->user->ruleGroups()->where('rule_groups.order', '<=', $newOrder)->where('rule_groups.order', '>', $oldOrder)
->where('rule_groups.id', '!=', $ruleGroup->id) ->where('rule_groups.id', '!=', $ruleGroup->id)
->decrement('order') ->decrement('order');
;
$ruleGroup->order = $newOrder; $ruleGroup->order = $newOrder;
app('log')->debug(sprintf('Order of group #%d ("%s") is now %d', $ruleGroup->id, $ruleGroup->title, $newOrder)); app('log')->debug(sprintf('Order of group #%d ("%s") is now %d', $ruleGroup->id, $ruleGroup->title, $newOrder));
$ruleGroup->save(); $ruleGroup->save();
@@ -421,8 +409,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
$this->user->ruleGroups()->where('rule_groups.order', '>=', $newOrder)->where('rule_groups.order', '<', $oldOrder) $this->user->ruleGroups()->where('rule_groups.order', '>=', $newOrder)->where('rule_groups.order', '<', $oldOrder)
->where('rule_groups.id', '!=', $ruleGroup->id) ->where('rule_groups.id', '!=', $ruleGroup->id)
->increment('order') ->increment('order');
;
$ruleGroup->order = $newOrder; $ruleGroup->order = $newOrder;
app('log')->debug(sprintf('Order of group #%d ("%s") is now %d', $ruleGroup->id, $ruleGroup->title, $newOrder)); app('log')->debug(sprintf('Order of group #%d ("%s") is now %d', $ruleGroup->id, $ruleGroup->title, $newOrder));
$ruleGroup->save(); $ruleGroup->save();

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Tag; namespace FireflyIII\Repositories\Tag;
use Carbon\Carbon; use Carbon\Carbon;
use Exception;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Factory\TagFactory; use FireflyIII\Factory\TagFactory;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@@ -51,7 +52,7 @@ class TagRepository implements TagRepositoryInterface, UserGroupInterface
} }
/** /**
* @throws \Exception * @throws Exception
*/ */
public function destroy(Tag $tag): bool public function destroy(Tag $tag): bool
{ {

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\TransactionGroup; namespace FireflyIII\Repositories\TransactionGroup;
use Carbon\Carbon; use Carbon\Carbon;
use Exception;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\DuplicateTransactionException; use FireflyIII\Exceptions\DuplicateTransactionException;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@@ -144,8 +145,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
$set = Attachment::whereIn('attachable_id', $journals) $set = Attachment::whereIn('attachable_id', $journals)
->where('attachable_type', TransactionJournal::class) ->where('attachable_type', TransactionJournal::class)
->where('uploaded', true) ->where('uploaded', true)
->whereNull('deleted_at')->get() ->whereNull('deleted_at')->get();
;
$result = []; $result = [];
@@ -172,8 +172,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
/** @var null|Note $note */ /** @var null|Note $note */
$note = Note::where('noteable_id', $journalId) $note = Note::where('noteable_id', $journalId)
->where('noteable_type', TransactionJournal::class) ->where('noteable_type', TransactionJournal::class)
->first() ->first();
;
if (null === $note) { if (null === $note) {
return null; return null;
} }
@@ -196,8 +195,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
) )
->with(['source', 'destination', 'source.transactions']) ->with(['source', 'destination', 'source.transactions'])
->leftJoin('link_types', 'link_types.id', '=', 'journal_links.link_type_id') ->leftJoin('link_types', 'link_types.id', '=', 'journal_links.link_type_id')
->get(['journal_links.*', 'link_types.inward', 'link_types.outward', 'link_types.editable']) ->get(['journal_links.*', 'link_types.inward', 'link_types.outward', 'link_types.editable']);
;
/** @var TransactionJournalLink $entry */ /** @var TransactionJournalLink $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
@@ -291,7 +289,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
/** /**
* Return object with all found meta field things as Carbon objects. * Return object with all found meta field things as Carbon objects.
* *
* @throws \Exception * @throws Exception
*/ */
public function getMetaDateFields(int $journalId, array $fields): NullArrayObject public function getMetaDateFields(int $journalId, array $fields): NullArrayObject
{ {
@@ -299,8 +297,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
->where('transaction_journal_id', $journalId) ->where('transaction_journal_id', $journalId)
->whereIn('name', $fields) ->whereIn('name', $fields)
->whereNull('deleted_at') ->whereNull('deleted_at')
->get(['name', 'data']) ->get(['name', 'data']);
;
$return = []; $return = [];
foreach ($query as $row) { foreach ($query as $row) {
@@ -319,8 +316,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
->where('transaction_journal_id', $journalId) ->where('transaction_journal_id', $journalId)
->whereIn('name', $fields) ->whereIn('name', $fields)
->whereNull('deleted_at') ->whereNull('deleted_at')
->get(['name', 'data']) ->get(['name', 'data']);
;
$return = []; $return = [];
foreach ($query as $row) { foreach ($query as $row) {
@@ -342,8 +338,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
$data = PiggyBankEvent::whereIn('transaction_journal_id', $journals) $data = PiggyBankEvent::whereIn('transaction_journal_id', $journals)
->with('piggyBank', 'piggyBank.account') ->with('piggyBank', 'piggyBank.account')
->get(['piggy_bank_events.*']) ->get(['piggy_bank_events.*']);
;
/** @var PiggyBankEvent $row */ /** @var PiggyBankEvent $row */
foreach ($data as $row) { foreach ($data as $row) {
@@ -353,8 +348,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
// get currency preference. // get currency preference.
$currencyPreference = AccountMeta::where('account_id', $row->piggyBank->account_id) $currencyPreference = AccountMeta::where('account_id', $row->piggyBank->account_id)
->where('name', 'currency_id') ->where('name', 'currency_id')
->first() ->first();
;
if (null !== $currencyPreference) { if (null !== $currencyPreference) {
$currency = TransactionCurrency::where('id', $currencyPreference->data)->first(); $currency = TransactionCurrency::where('id', $currencyPreference->data)->first();
} }
@@ -388,8 +382,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id') ->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id')
->where('tag_transaction_journal.transaction_journal_id', $journalId) ->where('tag_transaction_journal.transaction_journal_id', $journalId)
->orderBy('tags.tag', 'ASC') ->orderBy('tags.tag', 'ASC')
->get(['tags.tag']) ->get(['tags.tag']);
;
return $result->pluck('tag')->toArray(); return $result->pluck('tag')->toArray();
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\User; namespace FireflyIII\Repositories\User;
use Exception;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\GroupMembership; use FireflyIII\Models\GroupMembership;
@@ -34,6 +35,7 @@ use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Override;
/** /**
* Class UserRepository. * Class UserRepository.
@@ -44,7 +46,7 @@ class UserRepository implements UserRepositoryInterface
* This updates the users email address and records some things so it can be confirmed or undone later. * This updates the users email address and records some things so it can be confirmed or undone later.
* The user is blocked until the change is confirmed. * The user is blocked until the change is confirmed.
* *
* @throws \Exception * @throws Exception
* *
* @see updateEmail * @see updateEmail
*/ */
@@ -99,7 +101,7 @@ class UserRepository implements UserRepositoryInterface
} }
/** /**
* @throws \Exception * @throws Exception
*/ */
public function destroy(User $user): bool public function destroy(User $user): bool
{ {
@@ -217,8 +219,7 @@ class UserRepository implements UserRepositoryInterface
->where('amount', '>', 0) ->where('amount', '>', 0)
->whereNull('budgets.deleted_at') ->whereNull('budgets.deleted_at')
->where('budgets.user_id', $user->id) ->where('budgets.user_id', $user->id)
->count('budget_limits.budget_id') ->count('budget_limits.budget_id');
;
$return['rule_groups'] = $user->ruleGroups()->count(); $return['rule_groups'] = $user->ruleGroups()->count();
$return['rules'] = $user->rules()->count(); $return['rules'] = $user->rules()->count();
$return['tags'] = $user->tags()->count(); $return['tags'] = $user->tags()->count();
@@ -243,7 +244,7 @@ class UserRepository implements UserRepositoryInterface
return false; return false;
} }
#[\Override] #[Override]
public function getUserGroups(User $user): Collection public function getUserGroups(User $user): Collection
{ {
$memberships = $user->groupMemberships()->get(); $memberships = $user->groupMemberships()->get();

View File

@@ -35,6 +35,8 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Override;
use ValueError;
/** /**
* Class UserGroupRepository * Class UserGroupRepository
@@ -176,13 +178,13 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
return UserGroup::all(); return UserGroup::all();
} }
#[\Override] #[Override]
public function getById(int $id): ?UserGroup public function getById(int $id): ?UserGroup
{ {
return UserGroup::find($id); return UserGroup::find($id);
} }
#[\Override] #[Override]
public function getMembershipsFromGroupId(int $groupId): Collection public function getMembershipsFromGroupId(int $groupId): Collection
{ {
return $this->user->groupMemberships()->where('user_group_id', $groupId)->get(); return $this->user->groupMemberships()->where('user_group_id', $groupId)->get();
@@ -265,8 +267,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
// group has multiple members. How many are owner, except the user we're editing now? // group has multiple members. How many are owner, except the user we're editing now?
$ownerCount = $userGroup->groupMemberships() $ownerCount = $userGroup->groupMemberships()
->where('user_role_id', $owner->id) ->where('user_role_id', $owner->id)
->where('user_id', '!=', $user->id)->count() ->where('user_id', '!=', $user->id)->count();
;
// if there are no other owners and the current users does not get or keep the owner role, refuse. // if there are no other owners and the current users does not get or keep the owner role, refuse.
if ( if (
0 === $ownerCount 0 === $ownerCount
@@ -286,7 +287,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
foreach ($rolesSimplified as $role) { foreach ($rolesSimplified as $role) {
try { try {
$enum = UserRoleEnum::from($role); $enum = UserRoleEnum::from($role);
} catch (\ValueError $e) { } catch (ValueError $e) {
// TODO error message // TODO error message
continue; continue;
} }
@@ -313,7 +314,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
return $roles; return $roles;
} }
#[\Override] #[Override]
public function useUserGroup(UserGroup $userGroup): void public function useUserGroup(UserGroup $userGroup): void
{ {
$this->user->user_group_id = $userGroup->id; $this->user->user_group_id = $userGroup->id;

View File

@@ -37,6 +37,8 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Override;
use stdClass;
/** /**
* Class AccountRepository * Class AccountRepository
@@ -47,7 +49,7 @@ class AccountRepository implements AccountRepositoryInterface
{ {
use UserGroupTrait; use UserGroupTrait;
#[\Override] #[Override]
public function countAccounts(array $types): int public function countAccounts(array $types): int
{ {
$query = $this->userGroup->accounts(); $query = $this->userGroup->accounts();
@@ -70,8 +72,7 @@ class AccountRepository implements AccountRepositoryInterface
$q1->where('account_meta.name', '=', 'account_number'); $q1->where('account_meta.name', '=', 'account_number');
$q1->where('account_meta.data', '=', $json); $q1->where('account_meta.data', '=', $json);
} }
) );
;
if (0 !== count($types)) { if (0 !== count($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); $dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
@@ -120,7 +121,7 @@ class AccountRepository implements AccountRepositoryInterface
return $account; return $account;
} }
#[\Override] #[Override]
public function getAccountBalances(Account $account): Collection public function getAccountBalances(Account $account): Collection
{ {
return $account->accountBalances; return $account->accountBalances;
@@ -174,13 +175,12 @@ class AccountRepository implements AccountRepositoryInterface
return $account; return $account;
} }
#[\Override] #[Override]
public function getAccountTypes(Collection $accounts): Collection public function getAccountTypes(Collection $accounts): Collection
{ {
return AccountType::leftJoin('accounts', 'accounts.account_type_id', '=', 'account_types.id') return AccountType::leftJoin('accounts', 'accounts.account_type_id', '=', 'account_types.id')
->whereIn('accounts.id', $accounts->pluck('id')->toArray()) ->whereIn('accounts.id', $accounts->pluck('id')->toArray())
->get(['accounts.id', 'account_types.type']) ->get(['accounts.id', 'account_types.type']);
;
} }
public function getAccountsById(array $accountIds): Collection public function getAccountsById(array $accountIds): Collection
@@ -197,7 +197,7 @@ class AccountRepository implements AccountRepositoryInterface
return $query->get(['accounts.*']); return $query->get(['accounts.*']);
} }
#[\Override] #[Override]
public function getAccountsInOrder(array $types, array $sort, int $startRow, int $endRow): Collection public function getAccountsInOrder(array $types, array $sort, int $startRow, int $endRow): Collection
{ {
$query = $this->userGroup->accounts(); $query = $this->userGroup->accounts();
@@ -237,7 +237,7 @@ class AccountRepository implements AccountRepositoryInterface
return $query->get(['accounts.*']); return $query->get(['accounts.*']);
} }
#[\Override] #[Override]
public function getLastActivity(Collection $accounts): array public function getLastActivity(Collection $accounts): array
{ {
return Transaction::whereIn('account_id', $accounts->pluck('id')->toArray()) return Transaction::whereIn('account_id', $accounts->pluck('id')->toArray())
@@ -247,7 +247,7 @@ class AccountRepository implements AccountRepositoryInterface
; ;
} }
#[\Override] #[Override]
public function getMetaValues(Collection $accounts, array $fields): Collection public function getMetaValues(Collection $accounts, array $fields): Collection
{ {
$query = AccountMeta::whereIn('account_id', $accounts->pluck('id')->toArray()); $query = AccountMeta::whereIn('account_id', $accounts->pluck('id')->toArray());
@@ -258,23 +258,22 @@ class AccountRepository implements AccountRepositoryInterface
return $query->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data']); return $query->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data']);
} }
#[\Override] #[Override]
public function getObjectGroups(Collection $accounts): array public function getObjectGroups(Collection $accounts): array
{ {
$groupIds = []; $groupIds = [];
$return = []; $return = [];
$set = DB::table('object_groupables')->where('object_groupable_type', Account::class) $set = DB::table('object_groupables')->where('object_groupable_type', Account::class)
->whereIn('object_groupable_id', $accounts->pluck('id')->toArray())->get() ->whereIn('object_groupable_id', $accounts->pluck('id')->toArray())->get();
;
/** @var \stdClass $row */ /** @var stdClass $row */
foreach ($set as $row) { foreach ($set as $row) {
$groupIds[] = $row->object_group_id; $groupIds[] = $row->object_group_id;
} }
$groupIds = array_unique($groupIds); $groupIds = array_unique($groupIds);
$groups = ObjectGroup::whereIn('id', $groupIds)->get(); $groups = ObjectGroup::whereIn('id', $groupIds)->get();
/** @var \stdClass $row */ /** @var stdClass $row */
foreach ($set as $row) { foreach ($set as $row) {
if (!array_key_exists($row->object_groupable_id, $return)) { if (!array_key_exists($row->object_groupable_id, $return)) {
/** @var null|ObjectGroup $group */ /** @var null|ObjectGroup $group */
@@ -315,8 +314,7 @@ class AccountRepository implements AccountRepositoryInterface
$all = [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value]; $all = [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value];
$this->user->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') $this->user->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->whereNotIn('account_types.type', $all) ->whereNotIn('account_types.type', $all)
->update(['order' => 0]) ->update(['order' => 0]);
;
} }
public function getAccountsByType(array $types, ?array $sort = [], ?array $filters = []): Collection public function getAccountsByType(array $types, ?array $sort = [], ?array $filters = []): Collection
@@ -370,7 +368,7 @@ class AccountRepository implements AccountRepositoryInterface
return $query->get(['accounts.*']); return $query->get(['accounts.*']);
} }
#[\Override] #[Override]
public function update(Account $account, array $data): Account public function update(Account $account, array $data): Account
{ {
/** @var AccountUpdateService $service */ /** @var AccountUpdateService $service */
@@ -388,8 +386,7 @@ class AccountRepository implements AccountRepositoryInterface
->orderBy('accounts.order', 'ASC') ->orderBy('accounts.order', 'ASC')
->orderBy('accounts.account_type_id', 'ASC') ->orderBy('accounts.account_type_id', 'ASC')
->orderBy('accounts.name', 'ASC') ->orderBy('accounts.name', 'ASC')
->with(['accountType']) ->with(['accountType']);
;
// split query on spaces just in case: // split query on spaces just in case:
if ('' !== trim($query)) { if ('' !== trim($query)) {

View File

@@ -26,7 +26,6 @@ namespace FireflyIII\Repositories\UserGroups\Account;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**

View File

@@ -63,8 +63,7 @@ class BillRepository implements BillRepositoryInterface
{ {
return $this->userGroup->bills() return $this->userGroup->bills()
->orderBy('bills.name', 'ASC') ->orderBy('bills.name', 'ASC')
->get(['bills.*']) ->get(['bills.*']);
;
} }
public function sumPaidInRange(Carbon $start, Carbon $end): array public function sumPaidInRange(Carbon $start, Carbon $end): array
@@ -132,8 +131,7 @@ class BillRepository implements BillRepositoryInterface
return $this->userGroup->bills() return $this->userGroup->bills()
->where('active', true) ->where('active', true)
->orderBy('bills.name', 'ASC') ->orderBy('bills.name', 'ASC')
->get(['bills.*']) ->get(['bills.*']);
;
} }
public function sumUnpaidInRange(Carbon $start, Carbon $end): array public function sumUnpaidInRange(Carbon $start, Carbon $end): array

View File

@@ -47,8 +47,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
$default = app('amount')->getNativeCurrency(); $default = app('amount')->getNativeCurrency();
$availableBudgets = $this->userGroup->availableBudgets() $availableBudgets = $this->userGroup->availableBudgets()
->where('start_date', $start->format('Y-m-d')) ->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))->get() ->where('end_date', $end->format('Y-m-d'))->get();
;
/** @var AvailableBudget $availableBudget */ /** @var AvailableBudget $availableBudget */
foreach ($availableBudgets as $availableBudget) { foreach ($availableBudgets as $availableBudget) {

View File

@@ -41,8 +41,7 @@ class BudgetRepository implements BudgetRepositoryInterface
return $this->userGroup->budgets()->where('active', true) return $this->userGroup->budgets()->where('active', true)
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('name', 'ASC') ->orderBy('name', 'ASC')
->get() ->get();
;
} }
public function getBudgets(): Collection public function getBudgets(): Collection
@@ -50,7 +49,6 @@ class BudgetRepository implements BudgetRepositoryInterface
return $this->userGroup->budgets() return $this->userGroup->budgets()
->orderBy('order', 'ASC') ->orderBy('order', 'ASC')
->orderBy('name', 'ASC') ->orderBy('name', 'ASC')
->get() ->get();
;
} }
} }

View File

@@ -28,6 +28,7 @@ use Carbon\Carbon;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;

View File

@@ -117,8 +117,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
// is being used in accounts (as integer) // is being used in accounts (as integer)
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id') $meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
->whereNull('accounts.deleted_at') ->whereNull('accounts.deleted_at')
->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count() ->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count();
;
if ($meta > 0) { if ($meta > 0) {
app('log')->info(sprintf('Used in %d accounts as currency_id, return true. ', $meta)); app('log')->info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));

View File

@@ -26,7 +26,6 @@ namespace FireflyIII\Repositories\UserGroups\Currency;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**

View File

@@ -30,6 +30,7 @@ use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Override;
/** /**
* Class ExchangeRateRepository * Class ExchangeRateRepository
@@ -40,19 +41,19 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface
{ {
use UserGroupTrait; use UserGroupTrait;
#[\Override] #[Override]
public function deleteRate(CurrencyExchangeRate $rate): void public function deleteRate(CurrencyExchangeRate $rate): void
{ {
$this->userGroup->currencyExchangeRates()->where('id', $rate->id)->delete(); $this->userGroup->currencyExchangeRates()->where('id', $rate->id)->delete();
} }
#[\Override] #[Override]
public function getAll(): Collection public function getAll(): Collection
{ {
return $this->userGroup->currencyExchangeRates()->orderBy('date', 'ASC')->get(); return $this->userGroup->currencyExchangeRates()->orderBy('date', 'ASC')->get();
} }
#[\Override] #[Override]
public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection
{ {
// orderBy('date', 'DESC')->toRawSql(); // orderBy('date', 'DESC')->toRawSql();
@@ -61,21 +62,18 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface
->where(function (Builder $q1) use ($from, $to): void { ->where(function (Builder $q1) use ($from, $to): void {
$q1->where(function (Builder $q) use ($from, $to): void { $q1->where(function (Builder $q) use ($from, $to): void {
$q->where('from_currency_id', $from->id) $q->where('from_currency_id', $from->id)
->where('to_currency_id', $to->id) ->where('to_currency_id', $to->id);
;
})->orWhere(function (Builder $q) use ($from, $to): void { })->orWhere(function (Builder $q) use ($from, $to): void {
$q->where('from_currency_id', $to->id) $q->where('from_currency_id', $to->id)
->where('to_currency_id', $from->id) ->where('to_currency_id', $from->id);
;
}); });
}) })
->orderBy('date', 'DESC') ->orderBy('date', 'DESC')
->get(['currency_exchange_rates.*']) ->get(['currency_exchange_rates.*']);
;
} }
#[\Override] #[Override]
public function getSpecificRateOnDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): ?CurrencyExchangeRate public function getSpecificRateOnDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): ?CurrencyExchangeRate
{ {
/** @var null|CurrencyExchangeRate */ /** @var null|CurrencyExchangeRate */
@@ -84,11 +82,10 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface
->where('from_currency_id', $from->id) ->where('from_currency_id', $from->id)
->where('to_currency_id', $to->id) ->where('to_currency_id', $to->id)
->where('date', $date->format('Y-m-d')) ->where('date', $date->format('Y-m-d'))
->first() ->first();
;
} }
#[\Override] #[Override]
public function storeExchangeRate(TransactionCurrency $from, TransactionCurrency $to, string $rate, Carbon $date): CurrencyExchangeRate public function storeExchangeRate(TransactionCurrency $from, TransactionCurrency $to, string $rate, Carbon $date): CurrencyExchangeRate
{ {
$object = new CurrencyExchangeRate(); $object = new CurrencyExchangeRate();
@@ -104,7 +101,7 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface
return $object; return $object;
} }
#[\Override] #[Override]
public function updateExchangeRate(CurrencyExchangeRate $object, string $rate, ?Carbon $date = null): CurrencyExchangeRate public function updateExchangeRate(CurrencyExchangeRate $object, string $rate, ?Carbon $date = null): CurrencyExchangeRate
{ {
$object->rate = $rate; $object->rate = $rate;

View File

@@ -40,8 +40,7 @@ class JournalRepository implements JournalRepositoryInterface
public function searchJournalDescriptions(array $query, int $limit): Collection public function searchJournalDescriptions(array $query, int $limit): Collection
{ {
$search = $this->userGroup->transactionJournals() $search = $this->userGroup->transactionJournals()
->orderBy('date', 'DESC') ->orderBy('date', 'DESC');
;
if (count($query) > 0) { if (count($query) > 0) {
// split query on spaces just in case: // split query on spaces just in case:
$search->where(function (EloquentBuilder $q) use ($query): void { $search->where(function (EloquentBuilder $q) use ($query): void {

View File

@@ -47,7 +47,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
'objectGroups', 'objectGroups',
] ]
) )
->orderBy('piggy_banks.order', 'ASC')->distinct()->get(['piggy_banks.*']) ->orderBy('piggy_banks.order', 'ASC')->distinct()->get(['piggy_banks.*']);
;
} }
} }

View File

@@ -68,8 +68,7 @@ class WebhookRepository implements WebhookRepositoryInterface, UserGroupInterfac
{ {
return $webhook->webhookMessages() return $webhook->webhookMessages()
->orderBy('created_at', 'DESC') ->orderBy('created_at', 'DESC')
->get(['webhook_messages.*']) ->get(['webhook_messages.*']);
;
} }
public function getReadyMessages(Webhook $webhook): Collection public function getReadyMessages(Webhook $webhook): Collection
@@ -82,8 +81,7 @@ class WebhookRepository implements WebhookRepositoryInterface, UserGroupInterfac
static function (WebhookMessage $message) { // @phpstan-ignore-line static function (WebhookMessage $message) { // @phpstan-ignore-line
return $message->webhookAttempts()->count() <= 2; return $message->webhookAttempts()->count() <= 2;
} }
)->splice(0, 3) )->splice(0, 3);
;
} }
public function store(array $data): Webhook public function store(array $data): Webhook

View File

@@ -49,19 +49,9 @@ use Illuminate\Support\Facades\Log;
*/ */
class AccountEnrichment implements EnrichmentInterface class AccountEnrichment implements EnrichmentInterface
{ {
// private array $balances;
// private array $currencies;
// private CurrencyRepositoryInterface $currencyRepository;
// private TransactionCurrency $default;
// private ?Carbon $end;
// private array $grouped;
// private array $objectGroups;
// private AccountRepositoryInterface $repository;
// private ?Carbon $start;
private Collection $collection; private Collection $collection;
private bool $convertToNative;
private User $user; private User $user;
private UserGroup $userGroup; private UserGroup $userGroup;
private TransactionCurrency $native; private TransactionCurrency $native;
@@ -76,7 +66,6 @@ class AccountEnrichment implements EnrichmentInterface
public function __construct() public function __construct()
{ {
$this->convertToNative = false;
$this->accountIds = []; $this->accountIds = [];
$this->openingBalances = []; $this->openingBalances = [];
$this->currencies = []; $this->currencies = [];
@@ -197,7 +186,10 @@ class AccountEnrichment implements EnrichmentInterface
// use new group collector: // use new group collector:
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setAccounts($this->collection) $collector
->setUser($this->user)
->setUserGroup($this->userGroup)
->setAccounts($this->collection)
->withAccountInformation() ->withAccountInformation()
->setTypes([TransactionTypeEnum::OPENING_BALANCE->value]) ->setTypes([TransactionTypeEnum::OPENING_BALANCE->value])
; ;
@@ -269,11 +261,6 @@ class AccountEnrichment implements EnrichmentInterface
$this->userGroup = $user->userGroup; $this->userGroup = $user->userGroup;
} }
public function setConvertToNative(bool $convertToNative): void
{
$this->convertToNative = $convertToNative;
}
public function setNative(TransactionCurrency $native): void public function setNative(TransactionCurrency $native): void
{ {
$this->native = $native; $this->native = $native;

View File

@@ -47,8 +47,8 @@ class TransactionGroupEnrichment implements EnrichmentInterface
private array $tags; private array $tags;
private array $locations; private array $locations;
private array $journalIds; private array $journalIds;
private User $user; private User $user; // @phpstan-ignore-line
private UserGroup $userGroup; private UserGroup $userGroup; // @phpstan-ignore-line
private array $metaData; private array $metaData;
private array $dateFields; private array $dateFields;
private array $attachmentCount; private array $attachmentCount;

View File

@@ -24,10 +24,6 @@ declare(strict_types=1);
use FireflyIII\User; use FireflyIII\User;
if ('ldap' === strtolower((string) env('AUTHENTICATION_GUARD'))) {
exit('LDAP is no longer supported by Firefly III v5.7+. Sorry about that. You will have to switch to "remote_user_guard", and use tools like Authelia or Keycloak to use LDAP together with Firefly III.');
}
return [ return [
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------