mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
Fix reference to old method.
This commit is contained in:
@@ -82,8 +82,10 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
|
|
||||||
public function find(int $piggyBankId): ?PiggyBank
|
public function find(int $piggyBankId): ?PiggyBank
|
||||||
{
|
{
|
||||||
// phpstan doesn't get the Model.
|
return PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
|
||||||
return $this->user->piggyBanks()->find($piggyBankId); // @phpstan-ignore-line
|
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
||||||
|
->where('accounts.user_id', $this->user->id)
|
||||||
|
->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,12 +93,15 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function findByName(string $name): ?PiggyBank
|
public function findByName(string $name): ?PiggyBank
|
||||||
{
|
{
|
||||||
return $this->user->piggyBanks()->where('piggy_banks.name', $name)->first(['piggy_banks.*']);
|
return PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
|
||||||
|
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
||||||
|
->where('accounts.user_id', $this->user->id)
|
||||||
|
->where('piggy_banks.name', $name)->first(['piggy_banks.*']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAttachments(PiggyBank $piggyBank): Collection
|
public function getAttachments(PiggyBank $piggyBank): Collection
|
||||||
{
|
{
|
||||||
$set = $piggyBank->attachments()->get();
|
$set = $piggyBank->attachments()->get();
|
||||||
|
|
||||||
/** @var \Storage $disk */
|
/** @var \Storage $disk */
|
||||||
$disk = \Storage::disk('upload');
|
$disk = \Storage::disk('upload');
|
||||||
@@ -156,15 +161,15 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
throw new FireflyException('[c] Piggy bank repetitions are EOL.');
|
throw new FireflyException('[c] Piggy bank repetitions are EOL.');
|
||||||
app('log')->debug(sprintf('Now in getExactAmount(%d, %d, %d)', $piggyBank->id, $repetition->id, $journal->id));
|
app('log')->debug(sprintf('Now in getExactAmount(%d, %d, %d)', $piggyBank->id, $repetition->id, $journal->id));
|
||||||
|
|
||||||
$operator = null;
|
$operator = null;
|
||||||
$currency = null;
|
$currency = null;
|
||||||
|
|
||||||
/** @var JournalRepositoryInterface $journalRepost */
|
/** @var JournalRepositoryInterface $journalRepost */
|
||||||
$journalRepost = app(JournalRepositoryInterface::class);
|
$journalRepost = app(JournalRepositoryInterface::class);
|
||||||
$journalRepost->setUser($this->user);
|
$journalRepost->setUser($this->user);
|
||||||
|
|
||||||
/** @var AccountRepositoryInterface $accountRepos */
|
/** @var AccountRepositoryInterface $accountRepos */
|
||||||
$accountRepos = app(AccountRepositoryInterface::class);
|
$accountRepos = app(AccountRepositoryInterface::class);
|
||||||
$accountRepos->setUser($this->user);
|
$accountRepos->setUser($this->user);
|
||||||
|
|
||||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||||
@@ -173,10 +178,10 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
app('log')->debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBankCurrency->code));
|
app('log')->debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBankCurrency->code));
|
||||||
|
|
||||||
/** @var Transaction $source */
|
/** @var Transaction $source */
|
||||||
$source = $journal->transactions()->with(['account'])->where('amount', '<', 0)->first();
|
$source = $journal->transactions()->with(['account'])->where('amount', '<', 0)->first();
|
||||||
|
|
||||||
/** @var Transaction $destination */
|
/** @var Transaction $destination */
|
||||||
$destination = $journal->transactions()->with(['account'])->where('amount', '>', 0)->first();
|
$destination = $journal->transactions()->with(['account'])->where('amount', '>', 0)->first();
|
||||||
|
|
||||||
// matches source, which means amount will be removed from piggy:
|
// matches source, which means amount will be removed from piggy:
|
||||||
if ($source->account_id === $piggyBank->account_id) {
|
if ($source->account_id === $piggyBank->account_id) {
|
||||||
@@ -198,7 +203,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
}
|
}
|
||||||
// currency of the account + the piggy bank currency are almost the same.
|
// currency of the account + the piggy bank currency are almost the same.
|
||||||
// which amount from the transaction matches?
|
// which amount from the transaction matches?
|
||||||
$amount = null;
|
$amount = null;
|
||||||
if ((int) $source->transaction_currency_id === $currency->id) {
|
if ((int) $source->transaction_currency_id === $currency->id) {
|
||||||
app('log')->debug('Use normal amount');
|
app('log')->debug('Use normal amount');
|
||||||
$amount = app('steam')->{$operator}($source->amount); // @phpstan-ignore-line
|
$amount = app('steam')->{$operator}($source->amount); // @phpstan-ignore-line
|
||||||
@@ -214,8 +219,8 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
app('log')->debug(sprintf('The currency is %s and the amount is %s', $currency->code, $amount));
|
app('log')->debug(sprintf('The currency is %s and the amount is %s', $currency->code, $amount));
|
||||||
$room = bcsub($piggyBank->target_amount, $repetition->current_amount);
|
$room = bcsub($piggyBank->target_amount, $repetition->current_amount);
|
||||||
$compare = bcmul($repetition->current_amount, '-1');
|
$compare = bcmul($repetition->current_amount, '-1');
|
||||||
|
|
||||||
if (0 === bccomp($piggyBank->target_amount, '0')) {
|
if (0 === bccomp($piggyBank->target_amount, '0')) {
|
||||||
// amount is zero? then the "room" is positive amount of we wish to add or remove.
|
// amount is zero? then the "room" is positive amount of we wish to add or remove.
|
||||||
@@ -247,7 +252,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
return (string) $amount;
|
return (string) $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUser(null|Authenticatable|User $user): void
|
public function setUser(null | Authenticatable | User $user): void
|
||||||
{
|
{
|
||||||
if ($user instanceof User) {
|
if ($user instanceof User) {
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
@@ -275,7 +280,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
/** @var PiggyBank $piggy */
|
/** @var PiggyBank $piggy */
|
||||||
foreach ($set as $piggy) {
|
foreach ($set as $piggy) {
|
||||||
$currentAmount = $this->getCurrentAmount($piggy);
|
$currentAmount = $this->getCurrentAmount($piggy);
|
||||||
$piggy->name = sprintf('%s (%s)',$piggy->name,app('amount')->formatAnything($piggy->transactionCurrency, $currentAmount, false));
|
$piggy->name = sprintf('%s (%s)', $piggy->name, app('amount')->formatAnything($piggy->transactionCurrency, $currentAmount, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $set;
|
return $set;
|
||||||
@@ -284,15 +289,14 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
public function getPiggyBanks(): Collection
|
public function getPiggyBanks(): Collection
|
||||||
{
|
{
|
||||||
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', auth()->user()->id)
|
->where('accounts.user_id', $this->user->id)
|
||||||
->with(
|
->with(
|
||||||
[
|
[
|
||||||
'objectGroups',
|
'objectGroups',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
->orderBy('piggy_banks.order', 'ASC')->distinct()->get(['piggy_banks.*'])
|
->orderBy('piggy_banks.order', 'ASC')->distinct()->get(['piggy_banks.*']);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -348,21 +352,19 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
public function searchPiggyBank(string $query, int $limit): Collection
|
public function searchPiggyBank(string $query, int $limit): Collection
|
||||||
{
|
{
|
||||||
$search = PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
|
$search = 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', auth()->user()->id)
|
->where('accounts.user_id', $this->user->id)
|
||||||
->with(
|
->with(
|
||||||
[
|
[
|
||||||
'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.*']);
|
||||||
}
|
}
|
||||||
@@ -371,16 +373,16 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
public function purgeAll(): void
|
public function purgeAll(): void
|
||||||
{
|
{
|
||||||
PiggyBank::withTrashed()
|
PiggyBank::withTrashed()
|
||||||
->whereNotNull('piggy_banks.deleted_at')
|
->whereNotNull('piggy_banks.deleted_at')
|
||||||
->leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
|
->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', auth()->user()->id)
|
->where('accounts.user_id', $this->user->id)
|
||||||
->with(
|
->with(
|
||||||
[
|
[
|
||||||
'objectGroups',
|
'objectGroups',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\Override]
|
#[\Override]
|
||||||
|
Reference in New Issue
Block a user