mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix phpstan issues
This commit is contained in:
@@ -83,7 +83,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
|
||||
];
|
||||
|
||||
$array[$currencyId]['transaction_journals'][$journalId] = [
|
||||
'amount' => app('steam')->{$direction}((string) $journal['amount']), // @phpstan-ignore-line
|
||||
'amount' => Steam::{$direction}((string) $journal['amount']), // @phpstan-ignore-line
|
||||
'date' => $journal['date'],
|
||||
'transaction_journal_id' => $journalId,
|
||||
'budget_name' => $journal['budget_name'],
|
||||
@@ -331,7 +331,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
|
||||
$currencyId = $journal['currency_id'];
|
||||
$sourceKey = sprintf('%d-%d', $currencyId, $sourceId);
|
||||
$destKey = sprintf('%d-%d', $currencyId, $destinationId);
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$amount = Steam::positive($journal['amount']);
|
||||
|
||||
// source first
|
||||
$return[$sourceKey] ??= [
|
||||
@@ -366,7 +366,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
|
||||
$return[$sourceKey]['difference'] = bcadd($return[$sourceKey]['out'], (string) $return[$sourceKey]['in']);
|
||||
|
||||
// destination account? money comes in:
|
||||
$return[$destKey]['in'] = bcadd((string) $return[$destKey]['in'], (string) $amount);
|
||||
$return[$destKey]['in'] = bcadd((string) $return[$destKey]['in'], $amount);
|
||||
$return[$destKey]['difference'] = bcadd((string) $return[$destKey]['out'], $return[$destKey]['in']);
|
||||
|
||||
// foreign currency
|
||||
@@ -374,7 +374,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
|
||||
$currencyId = $journal['foreign_currency_id'];
|
||||
$sourceKey = sprintf('%d-%d', $currencyId, $sourceId);
|
||||
$destKey = sprintf('%d-%d', $currencyId, $destinationId);
|
||||
$amount = app('steam')->positive($journal['foreign_amount']);
|
||||
$amount = Steam::positive($journal['foreign_amount']);
|
||||
|
||||
// same as above:
|
||||
// source first
|
||||
@@ -409,7 +409,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
|
||||
$return[$sourceKey]['difference'] = bcadd($return[$sourceKey]['out'], (string) $return[$sourceKey]['in']);
|
||||
|
||||
// destination account? money comes in:
|
||||
$return[$destKey]['in'] = bcadd((string) $return[$destKey]['in'], (string) $amount);
|
||||
$return[$destKey]['in'] = bcadd((string) $return[$destKey]['in'], $amount);
|
||||
$return[$destKey]['difference'] = bcadd((string) $return[$destKey]['out'], $return[$destKey]['in']);
|
||||
}
|
||||
|
||||
|
@@ -310,10 +310,10 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
|
||||
return $budget;
|
||||
}
|
||||
if (0 === $autoBudgetType && !$autoBudget instanceof AutoBudget) {
|
||||
if (0 === $autoBudgetType) {
|
||||
return $budget;
|
||||
}
|
||||
if (null === $autoBudgetType && !$autoBudget instanceof AutoBudget) {
|
||||
if (null === $autoBudgetType) {
|
||||
return $budget;
|
||||
}
|
||||
$this->updateAutoBudget($budget, $data);
|
||||
|
@@ -267,10 +267,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
|
||||
|
||||
return $result;
|
||||
}
|
||||
if (null === $result) {
|
||||
Log::debug(sprintf('Searching for currency with code "%s"...', $currencyCode));
|
||||
$result = $this->findByCode((string) $currencyCode);
|
||||
}
|
||||
Log::debug(sprintf('Searching for currency with code "%s"...', $currencyCode));
|
||||
$result = $this->findByCode((string) $currencyCode);
|
||||
|
||||
if ($result instanceof TransactionCurrency && false === $result->enabled) {
|
||||
Log::debug(sprintf('Also enabled currency %s', $result->code));
|
||||
$this->enable($result);
|
||||
|
@@ -182,7 +182,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface, UserGroupIn
|
||||
$query = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_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')]);
|
||||
$journalIds = [];
|
||||
|
||||
/** @var stdClass $row */
|
||||
|
@@ -67,7 +67,7 @@ trait ModifiesPiggyBanks
|
||||
{
|
||||
$currentAmount = $this->getCurrentAmount($piggyBank, $account);
|
||||
$pivot = $piggyBank->accounts()->where('accounts.id', $account->id)->first()->pivot;
|
||||
$pivot->current_amount = bcsub((string)$currentAmount, $amount);
|
||||
$pivot->current_amount = bcsub($currentAmount, $amount);
|
||||
$pivot->native_current_amount = null;
|
||||
|
||||
// also update native_current_amount.
|
||||
@@ -90,7 +90,7 @@ trait ModifiesPiggyBanks
|
||||
{
|
||||
$currentAmount = $this->getCurrentAmount($piggyBank, $account);
|
||||
$pivot = $piggyBank->accounts()->where('accounts.id', $account->id)->first()->pivot;
|
||||
$pivot->current_amount = bcadd((string)$currentAmount, $amount);
|
||||
$pivot->current_amount = bcadd($currentAmount, $amount);
|
||||
$pivot->native_current_amount = null;
|
||||
|
||||
// also update native_current_amount.
|
||||
@@ -122,13 +122,13 @@ trait ModifiesPiggyBanks
|
||||
|
||||
|
||||
if (0 !== bccomp($piggyBank->target_amount, '0')) {
|
||||
$leftToSave = bcsub($piggyBank->target_amount, (string)$savedSoFar);
|
||||
$maxAmount = 1 === bccomp((string)$leftOnAccount, $leftToSave) ? $leftToSave : $leftOnAccount;
|
||||
$leftToSave = bcsub($piggyBank->target_amount, $savedSoFar);
|
||||
$maxAmount = 1 === bccomp($leftOnAccount, $leftToSave) ? $leftToSave : $leftOnAccount;
|
||||
Log::debug(sprintf('Left to save: %s', $leftToSave));
|
||||
Log::debug(sprintf('Maximum amount: %s', $maxAmount));
|
||||
}
|
||||
|
||||
$compare = bccomp($amount, (string)$maxAmount);
|
||||
$compare = bccomp($amount, $maxAmount);
|
||||
$result = $compare <= 0;
|
||||
|
||||
Log::debug(sprintf('Compare <= 0? %d, so canAddAmount is %s', $compare, var_export($result, true)));
|
||||
@@ -140,7 +140,7 @@ trait ModifiesPiggyBanks
|
||||
{
|
||||
$savedSoFar = $this->getCurrentAmount($piggyBank, $account);
|
||||
|
||||
return bccomp($amount, (string)$savedSoFar) <= 0;
|
||||
return bccomp($amount, $savedSoFar) <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,9 +234,9 @@ trait ModifiesPiggyBanks
|
||||
// if the piggy bank is now smaller than the sum of the money saved,
|
||||
// remove money from all accounts until the piggy bank is the right amount.
|
||||
$currentAmount = $this->getCurrentAmount($piggyBank);
|
||||
if (1 === bccomp((string)$currentAmount, (string)$piggyBank->target_amount) && 0 !== bccomp((string)$piggyBank->target_amount, '0')) {
|
||||
if (1 === bccomp($currentAmount, (string)$piggyBank->target_amount) && 0 !== bccomp((string)$piggyBank->target_amount, '0')) {
|
||||
Log::debug(sprintf('Current amount is %s, target amount is %s', $currentAmount, $piggyBank->target_amount));
|
||||
$difference = bcsub((string)$piggyBank->target_amount, (string)$currentAmount);
|
||||
$difference = bcsub((string)$piggyBank->target_amount, $currentAmount);
|
||||
|
||||
// an amount will be removed, create "negative" event:
|
||||
// Log::debug(sprintf('ChangedAmount: is triggered with difference "%s"', $difference));
|
||||
|
@@ -67,12 +67,12 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
|
||||
|
||||
public function findPiggyBank(?int $piggyBankId, ?string $piggyBankName): ?PiggyBank
|
||||
{
|
||||
app('log')->debug('Searching for piggy information.');
|
||||
Log::debug('Searching for piggy information.');
|
||||
|
||||
if (null !== $piggyBankId) {
|
||||
$searchResult = $this->find($piggyBankId);
|
||||
if ($searchResult instanceof PiggyBank) {
|
||||
app('log')->debug(sprintf('Found piggy based on #%d, will return it.', $piggyBankId));
|
||||
Log::debug(sprintf('Found piggy based on #%d, will return it.', $piggyBankId));
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
@@ -80,12 +80,12 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
|
||||
if (null !== $piggyBankName) {
|
||||
$searchResult = $this->findByName($piggyBankName);
|
||||
if ($searchResult instanceof PiggyBank) {
|
||||
app('log')->debug(sprintf('Found piggy based on "%s", will return it.', $piggyBankName));
|
||||
Log::debug(sprintf('Found piggy based on "%s", will return it.', $piggyBankName));
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
}
|
||||
app('log')->debug('Found no piggy bank.');
|
||||
Log::debug('Found no piggy bank.');
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -158,7 +158,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
|
||||
*/
|
||||
public function getExactAmount(PiggyBank $piggyBank, TransactionJournal $journal): string
|
||||
{
|
||||
app('log')->debug(sprintf('Now in getExactAmount(%d, %d)', $piggyBank->id, $journal->id));
|
||||
Log::debug(sprintf('Now in getExactAmount(%d, %d)', $piggyBank->id, $journal->id));
|
||||
|
||||
$operator = null;
|
||||
$currency = null;
|
||||
@@ -173,7 +173,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
|
||||
|
||||
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
|
||||
app('log')->debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBank->transactionCurrency->code));
|
||||
Log::debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBank->transactionCurrency->code));
|
||||
|
||||
/** @var Transaction $source */
|
||||
$source = $journal->transactions()->with(['account'])->where('amount', '<', 0)->first();
|
||||
@@ -187,26 +187,26 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
|
||||
if ($account->id === $source->account_id) {
|
||||
$operator = 'negative';
|
||||
$currency = $accountRepos->getAccountCurrency($source->account) ?? $primaryCurrency;
|
||||
app('log')->debug(sprintf('Currency will draw money out of piggy bank. Source currency is %s', $currency->code));
|
||||
Log::debug(sprintf('Currency will draw money out of piggy bank. Source currency is %s', $currency->code));
|
||||
++$hits;
|
||||
}
|
||||
// matches destination, which means amount will be added to piggy.
|
||||
if ($account->id === $destination->account_id) {
|
||||
$operator = 'positive';
|
||||
$currency = $accountRepos->getAccountCurrency($destination->account) ?? $primaryCurrency;
|
||||
app('log')->debug(sprintf('Currency will add money to piggy bank. Destination currency is %s', $currency->code));
|
||||
Log::debug(sprintf('Currency will add money to piggy bank. Destination currency is %s', $currency->code));
|
||||
++$hits;
|
||||
}
|
||||
}
|
||||
if ($hits > 1) {
|
||||
app('log')->debug(sprintf('Transaction journal is related to %d of the accounts, cannot determine what to do. Return "0".', $hits));
|
||||
Log::debug(sprintf('Transaction journal is related to %d of the accounts, cannot determine what to do. Return "0".', $hits));
|
||||
|
||||
return '0';
|
||||
}
|
||||
|
||||
|
||||
if (null === $operator || null === $currency) {
|
||||
app('log')->debug('Currency is NULL and operator is NULL, return "0".');
|
||||
Log::debug('Currency is NULL and operator is NULL, return "0".');
|
||||
|
||||
return '0';
|
||||
}
|
||||
@@ -214,52 +214,52 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
|
||||
// which amount from the transaction matches?
|
||||
$amount = null;
|
||||
if ((int) $source->transaction_currency_id === $currency->id) {
|
||||
app('log')->debug('Use normal amount');
|
||||
$amount = app('steam')->{$operator}($source->amount); // @phpstan-ignore-line
|
||||
Log::debug('Use normal amount');
|
||||
$amount = Steam::{$operator}($source->amount); // @phpstan-ignore-line
|
||||
}
|
||||
if ((int) $source->foreign_currency_id === $currency->id) {
|
||||
app('log')->debug('Use foreign amount');
|
||||
$amount = app('steam')->{$operator}($source->foreign_amount); // @phpstan-ignore-line
|
||||
Log::debug('Use foreign amount');
|
||||
$amount = Steam::{$operator}($source->foreign_amount); // @phpstan-ignore-line
|
||||
}
|
||||
if (null === $amount) {
|
||||
app('log')->debug('No match on currency, so amount remains null, return "0".');
|
||||
Log::debug('No match on currency, so amount remains null, return "0".');
|
||||
|
||||
return '0';
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('The currency is %s and the amount is %s', $currency->code, $amount));
|
||||
Log::debug(sprintf('The currency is %s and the amount is %s', $currency->code, $amount));
|
||||
$currentAmount = $this->getCurrentAmount($piggyBank);
|
||||
$room = bcsub($piggyBank->target_amount, $currentAmount);
|
||||
$compare = bcmul($currentAmount, '-1');
|
||||
|
||||
if (0 === bccomp($piggyBank->target_amount, '0')) {
|
||||
// amount is zero? then the "room" is positive amount of we wish to add or remove.
|
||||
$room = app('steam')->positive($amount);
|
||||
app('log')->debug(sprintf('Room is now %s', $room));
|
||||
$room = Steam::positive($amount);
|
||||
Log::debug(sprintf('Room is now %s', $room));
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('Will add/remove %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
Log::debug(sprintf('Will add/remove %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
|
||||
// if the amount is positive, make sure it fits in piggy bank:
|
||||
if (1 === bccomp($amount, '0') && -1 === bccomp((string) $room, $amount)) {
|
||||
if (1 === bccomp($amount, '0') && -1 === bccomp( $room, $amount)) {
|
||||
// amount is positive and $room is smaller than $amount
|
||||
app('log')->debug(sprintf('Room in piggy bank for extra money is %f', $room));
|
||||
app('log')->debug(sprintf('There is NO room to add %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
app('log')->debug(sprintf('New amount is %f', $room));
|
||||
Log::debug(sprintf('Room in piggy bank for extra money is %f', $room));
|
||||
Log::debug(sprintf('There is NO room to add %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
Log::debug(sprintf('New amount is %f', $room));
|
||||
|
||||
return $room;
|
||||
}
|
||||
|
||||
// amount is negative and $currentAmount is smaller than $amount
|
||||
if (-1 === bccomp($amount, '0') && 1 === bccomp($compare, $amount)) {
|
||||
app('log')->debug(sprintf('Max amount to remove is %f', $currentAmount));
|
||||
app('log')->debug(sprintf('Cannot remove %f from piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
app('log')->debug(sprintf('New amount is %f', $compare));
|
||||
Log::debug(sprintf('Max amount to remove is %f', $currentAmount));
|
||||
Log::debug(sprintf('Cannot remove %f from piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
Log::debug(sprintf('New amount is %f', $compare));
|
||||
|
||||
return $compare;
|
||||
}
|
||||
|
||||
return (string) $amount;
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -31,6 +31,7 @@ use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\Location;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Support\Facades\Steam;
|
||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
|
||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -268,12 +269,12 @@ class TagRepository implements TagRepositoryInterface, UserGroupInterface
|
||||
];
|
||||
|
||||
// add amount to correct type:
|
||||
$amount = app('steam')->positive((string) $journal['amount']);
|
||||
$amount = Steam::positive((string) $journal['amount']);
|
||||
$type = $journal['transaction_type_type'];
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||
$amount = bcmul((string) $amount, '-1');
|
||||
$amount = bcmul( $amount, '-1');
|
||||
}
|
||||
$sums[$currencyId][$type] = bcadd((string) $sums[$currencyId][$type], (string) $amount);
|
||||
$sums[$currencyId][$type] = bcadd((string) $sums[$currencyId][$type], $amount);
|
||||
|
||||
$foreignCurrencyId = $journal['foreign_currency_id'];
|
||||
if (null !== $foreignCurrencyId && 0 !== $foreignCurrencyId) {
|
||||
@@ -289,11 +290,11 @@ class TagRepository implements TagRepositoryInterface, UserGroupInterface
|
||||
TransactionTypeEnum::OPENING_BALANCE->value => '0',
|
||||
];
|
||||
// add foreign amount to correct type:
|
||||
$amount = app('steam')->positive((string) $journal['foreign_amount']);
|
||||
$amount = Steam::positive((string) $journal['foreign_amount']);
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||
$amount = bcmul((string) $amount, '-1');
|
||||
$amount = bcmul( $amount, '-1');
|
||||
}
|
||||
$sums[$foreignCurrencyId][$type] = bcadd((string) $sums[$foreignCurrencyId][$type], (string) $amount);
|
||||
$sums[$foreignCurrencyId][$type] = bcadd((string) $sums[$foreignCurrencyId][$type], $amount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\TransactionGroup;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Exceptions\DuplicateTransactionException;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -42,14 +43,13 @@ use FireflyIII\Models\TransactionJournalLink;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
use FireflyIII\Services\Internal\Destroy\TransactionGroupDestroyService;
|
||||
use FireflyIII\Services\Internal\Update\GroupUpdateService;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use FireflyIII\Support\NullArrayObject;
|
||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
|
||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Exception;
|
||||
|
||||
use function Safe\json_decode;
|
||||
|
||||
/**
|
||||
@@ -143,22 +143,21 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
{
|
||||
$repository = app(AttachmentRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$journals = $group->transactionJournals->pluck('id')->toArray();
|
||||
$set = Attachment::whereIn('attachable_id', $journals)
|
||||
->where('attachable_type', TransactionJournal::class)
|
||||
->where('uploaded', true)
|
||||
->whereNull('deleted_at')->get()
|
||||
;
|
||||
$journals = $group->transactionJournals->pluck('id')->toArray();
|
||||
$set = Attachment::whereIn('attachable_id', $journals)
|
||||
->where('attachable_type', TransactionJournal::class)
|
||||
->where('uploaded', true)
|
||||
->whereNull('deleted_at')->get();
|
||||
|
||||
$result = [];
|
||||
$result = [];
|
||||
|
||||
/** @var Attachment $attachment */
|
||||
foreach ($set as $attachment) {
|
||||
$journalId = $attachment->attachable_id;
|
||||
$result[$journalId] ??= [];
|
||||
$current = $attachment->toArray();
|
||||
$current['file_exists'] = true;
|
||||
$current['notes'] = $repository->getNoteText($attachment);
|
||||
$journalId = $attachment->attachable_id;
|
||||
$result[$journalId] ??= [];
|
||||
$current = $attachment->toArray();
|
||||
$current['file_exists'] = true;
|
||||
$current['notes'] = $repository->getNoteText($attachment);
|
||||
// already determined that this attachable is a TransactionJournal.
|
||||
$current['journal_title'] = $attachment->attachable->description;
|
||||
$result[$journalId][] = $current;
|
||||
@@ -174,9 +173,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
{
|
||||
/** @var null|Note $note */
|
||||
$note = Note::where('noteable_id', $journalId)
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->first()
|
||||
;
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->first();
|
||||
if (null === $note) {
|
||||
return null;
|
||||
}
|
||||
@@ -197,14 +195,13 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
$q->orWhereIn('destination_id', $journals);
|
||||
}
|
||||
)
|
||||
->with(['source', 'destination', 'source.transactions'])
|
||||
->leftJoin('link_types', 'link_types.id', '=', 'journal_links.link_type_id')
|
||||
->get(['journal_links.*', 'link_types.inward', 'link_types.outward', 'link_types.editable'])
|
||||
;
|
||||
->with(['source', 'destination', 'source.transactions'])
|
||||
->leftJoin('link_types', 'link_types.id', '=', 'journal_links.link_type_id')
|
||||
->get(['journal_links.*', 'link_types.inward', 'link_types.outward', 'link_types.editable']);
|
||||
|
||||
/** @var TransactionJournalLink $entry */
|
||||
foreach ($set as $entry) {
|
||||
$journalId = in_array($entry->source_id, $journals, true) ? $entry->source_id : $entry->destination_id;
|
||||
$journalId = in_array($entry->source_id, $journals, true) ? $entry->source_id : $entry->destination_id;
|
||||
$return[$journalId] ??= [];
|
||||
|
||||
// phpstan: the editable field is provided by the query.
|
||||
@@ -248,13 +245,9 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->amount);
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||
return app('amount')->formatAnything($currency, app('steam')->negative($amount));
|
||||
return Amount::formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value !== $type) {
|
||||
return app('amount')->formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
return '';
|
||||
return Amount::formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
private function getFormattedForeignAmount(TransactionJournal $journal): string
|
||||
@@ -264,20 +257,18 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
if (null === $transaction->foreign_amount || '' === $transaction->foreign_amount) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (0 === bccomp('0', (string)$transaction->foreign_amount)) {
|
||||
return '';
|
||||
}
|
||||
$currency = $transaction->foreignCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->foreign_amount);
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||
return app('amount')->formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value !== $type) {
|
||||
return app('amount')->formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
return '';
|
||||
$currency = $transaction->foreignCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->foreign_amount);
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||
return Amount::formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
return Amount::formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
public function getLocation(int $journalId): ?Location
|
||||
@@ -297,11 +288,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
public function getMetaDateFields(int $journalId, array $fields): NullArrayObject
|
||||
{
|
||||
$query = DB::table('journal_meta')
|
||||
->where('transaction_journal_id', $journalId)
|
||||
->whereIn('name', $fields)
|
||||
->whereNull('deleted_at')
|
||||
->get(['name', 'data'])
|
||||
;
|
||||
->where('transaction_journal_id', $journalId)
|
||||
->whereIn('name', $fields)
|
||||
->whereNull('deleted_at')
|
||||
->get(['name', 'data']);
|
||||
$return = [];
|
||||
|
||||
foreach ($query as $row) {
|
||||
@@ -317,11 +307,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
public function getMetaFields(int $journalId, array $fields): NullArrayObject
|
||||
{
|
||||
$query = DB::table('journal_meta')
|
||||
->where('transaction_journal_id', $journalId)
|
||||
->whereIn('name', $fields)
|
||||
->whereNull('deleted_at')
|
||||
->get(['name', 'data'])
|
||||
;
|
||||
->where('transaction_journal_id', $journalId)
|
||||
->whereIn('name', $fields)
|
||||
->whereNull('deleted_at')
|
||||
->get(['name', 'data']);
|
||||
$return = [];
|
||||
|
||||
foreach ($query as $row) {
|
||||
@@ -340,11 +329,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
{
|
||||
$return = [];
|
||||
$journals = $group->transactionJournals->pluck('id')->toArray();
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
$currency = Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
$data = PiggyBankEvent::whereIn('transaction_journal_id', $journals)
|
||||
->with('piggyBank', 'piggyBank.account')
|
||||
->get(['piggy_bank_events.*'])
|
||||
;
|
||||
->with('piggyBank', 'piggyBank.account')
|
||||
->get(['piggy_bank_events.*']);
|
||||
|
||||
/** @var PiggyBankEvent $row */
|
||||
foreach ($data as $row) {
|
||||
@@ -352,20 +340,19 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
continue;
|
||||
}
|
||||
// get currency preference.
|
||||
$currencyPreference = AccountMeta::where('account_id', $row->piggyBank->account_id)
|
||||
->where('name', 'currency_id')
|
||||
->first()
|
||||
;
|
||||
$currencyPreference = AccountMeta::where('account_id', $row->piggyBank->account_id)
|
||||
->where('name', 'currency_id')
|
||||
->first();
|
||||
if (null !== $currencyPreference) {
|
||||
$currency = TransactionCurrency::where('id', $currencyPreference->data)->first();
|
||||
}
|
||||
$journalId = $row->transaction_journal_id;
|
||||
$journalId = $row->transaction_journal_id;
|
||||
$return[$journalId] ??= [];
|
||||
|
||||
$return[$journalId][] = [
|
||||
'piggy' => $row->piggyBank->name,
|
||||
'piggy_id' => $row->piggy_bank_id,
|
||||
'amount' => app('amount')->formatAnything($currency, $row->amount),
|
||||
'amount' => Amount::formatAnything($currency, $row->amount),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -386,11 +373,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
public function getTags(int $journalId): array
|
||||
{
|
||||
$result = DB::table('tag_transaction_journal')
|
||||
->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
||||
->where('tag_transaction_journal.transaction_journal_id', $journalId)
|
||||
->orderBy('tags.tag', 'ASC')
|
||||
->get(['tags.tag'])
|
||||
;
|
||||
->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
||||
->where('tag_transaction_journal.transaction_journal_id', $journalId)
|
||||
->orderBy('tags.tag', 'ASC')
|
||||
->get(['tags.tag']);
|
||||
|
||||
return $result->pluck('tag')->toArray();
|
||||
}
|
||||
@@ -445,7 +431,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
if (-1 === bccomp('0', (string)$transaction->amount)) {
|
||||
$sum = bcadd($sum, (string) $transaction->amount);
|
||||
$sum = bcadd($sum, (string)$transaction->amount);
|
||||
$names = sprintf('%s%s', $names, $transaction->account->name);
|
||||
}
|
||||
}
|
||||
|
@@ -169,6 +169,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
$account = $this->user->accounts()->find($accountId);
|
||||
if (null === $account) {
|
||||
/** @var null|Account */
|
||||
return $this->userGroup->accounts()->find($accountId);
|
||||
}
|
||||
|
||||
@@ -242,11 +243,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
#[Override]
|
||||
public function getLastActivity(Collection $accounts): array
|
||||
{
|
||||
return Transaction::whereIn('account_id', $accounts->pluck('id')->toArray())
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', 'transactions.transaction_journal_id')
|
||||
->groupBy('transactions.account_id')
|
||||
->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) as date_max')])->toArray() // @phpstan-ignore-line
|
||||
;
|
||||
return Transaction::whereIn('account_id', $accounts->pluck('id')->toArray())->leftJoin('transaction_journals', 'transaction_journals.id', 'transactions.transaction_journal_id')->groupBy('transactions.account_id')->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) as date_max')])->toArray();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
|
Reference in New Issue
Block a user