Add new fields to API.

This commit is contained in:
James Cole
2025-05-30 08:10:51 +02:00
parent 7e9c5a668f
commit 0521da124e
3 changed files with 44 additions and 3 deletions

View File

@@ -30,10 +30,12 @@ use FireflyIII\Models\Attachment;
use FireflyIII\Models\Location;
use FireflyIII\Models\Note;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Models\UserGroup;
use FireflyIII\Support\Facades\Amount;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
@@ -52,6 +54,7 @@ class TransactionGroupEnrichment implements EnrichmentInterface
private array $notes; // @phpstan-ignore-line
private array $tags;
private User $user;
private TransactionCurrency $nativeCurrency;
private UserGroup $userGroup;
public function __construct()
@@ -63,6 +66,7 @@ class TransactionGroupEnrichment implements EnrichmentInterface
$this->locations = [];
$this->attachmentCount = [];
$this->dateFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date'];
$this->nativeCurrency = Amount::getNativeCurrency();
}
#[Override]
@@ -192,8 +196,9 @@ class TransactionGroupEnrichment implements EnrichmentInterface
$metaData = $this->metaData;
$locations = $this->locations;
$attachmentCount = $this->attachmentCount;
$nativeCurrency = $this->nativeCurrency;
$this->collection = $this->collection->map(function (array $item) use ($notes, $tags, $metaData, $locations, $attachmentCount) {
$this->collection = $this->collection->map(function (array $item) use ($nativeCurrency, $notes, $tags, $metaData, $locations, $attachmentCount) {
foreach ($item['transactions'] as $index => $transaction) {
$journalId = (int) $transaction['transaction_journal_id'];
@@ -213,6 +218,15 @@ class TransactionGroupEnrichment implements EnrichmentInterface
'zoom_level' => null,
];
// native currency
$item['transactions'][$index]['native_currency'] = [
'id' => (string) $nativeCurrency->id,
'code' => $nativeCurrency->code,
'name' => $nativeCurrency->name,
'symbol' => $nativeCurrency->symbol,
'decimal_places' => $nativeCurrency->decimal_places,
];
// append meta data
$item['transactions'][$index]['meta'] = [];
$item['transactions'][$index]['meta_date'] = [];