🤖 Auto commit for release 'develop' on 2025-09-07

This commit is contained in:
JC5
2025-09-07 07:56:10 +02:00
parent 602df95f3c
commit 262f1bae34
93 changed files with 804 additions and 767 deletions

View File

@@ -50,6 +50,7 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use function Safe\json_decode;
/**
@@ -143,21 +144,22 @@ 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;
@@ -173,8 +175,9 @@ 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;
}
@@ -195,13 +198,14 @@ 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.
@@ -247,6 +251,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
return Amount::formatAnything($currency, app('steam')->negative($amount));
}
return Amount::formatAnything($currency, $amount);
}
@@ -262,13 +267,14 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
return '';
}
$currency = $transaction->foreignCurrency;
$type = $journal->transactionType->type;
$amount = app('steam')->positive($transaction->foreign_amount);
$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);
return Amount::formatAnything($currency, $amount);
}
public function getLocation(int $journalId): ?Location
@@ -288,10 +294,11 @@ 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) {
@@ -307,10 +314,11 @@ 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) {
@@ -331,8 +339,9 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
$journals = $group->transactionJournals->pluck('id')->toArray();
$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) {
@@ -340,13 +349,14 @@ 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][] = [
@@ -373,10 +383,11 @@ 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();
}