. */ declare(strict_types=1); namespace FireflyIII\Support\Http\Controllers; use FireflyIII\Support\Facades\Steam; trait ResolvesJournalAmountAndCurrency { /** * Normalize journal currency metadata and positive amount, honoring primary currency conversion. */ protected function resolveJournalAmountAndCurrency(array $journal, ?array $currency = null): array { $currency ??= $journal; $currencyId = (int) ($journal['currency_id'] ?? $currency['currency_id']); $currencyName = (string) ($journal['currency_name'] ?? $currency['currency_name']); $currencySymbol = (string) ($journal['currency_symbol'] ?? $currency['currency_symbol']); $currencyCode = (string) ($journal['currency_code'] ?? $currency['currency_code']); $currencyDecimalPlaces = (int) ($journal['currency_decimal_places'] ?? $currency['currency_decimal_places'] ?? 2); $amount = (string) $journal['amount']; if ($this->convertToPrimary && null !== $this->primaryCurrency && $currencyId !== $this->primaryCurrency->id) { $currencyId = $this->primaryCurrency->id; $currencyName = $this->primaryCurrency->name; $currencySymbol = $this->primaryCurrency->symbol; $currencyCode = $this->primaryCurrency->code; $currencyDecimalPlaces = $this->primaryCurrency->decimal_places; $amount = (int) ($journal['foreign_currency_id'] ?? 0) === $this->primaryCurrency->id ? (string) ($journal['foreign_amount'] ?? '0') : (string) ($journal['pc_amount'] ?? '0'); } return [ 'currency_id' => $currencyId, 'currency_name' => $currencyName, 'currency_symbol' => $currencySymbol, 'currency_code' => $currencyCode, 'currency_decimal_places' => $currencyDecimalPlaces, 'amount' => Steam::positive($amount), ]; } }