mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 09:52:20 +00:00
Fix currency collection.
This commit is contained in:
@@ -29,6 +29,8 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
|||||||
private Collection $budgets;
|
private Collection $budgets;
|
||||||
private array $expenses = [];
|
private array $expenses = [];
|
||||||
private array $pcExpenses = [];
|
private array $pcExpenses = [];
|
||||||
|
private array $currencyIds = [];
|
||||||
|
private array $currencies = [];
|
||||||
private bool $convertToPrimary = true;
|
private bool $convertToPrimary = true;
|
||||||
private TransactionCurrency $primaryCurrency;
|
private TransactionCurrency $primaryCurrency;
|
||||||
|
|
||||||
@@ -42,6 +44,7 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
|||||||
{
|
{
|
||||||
$this->collection = $collection;
|
$this->collection = $collection;
|
||||||
$this->collectIds();
|
$this->collectIds();
|
||||||
|
$this->collectCurrencies();
|
||||||
$this->collectNotes();
|
$this->collectNotes();
|
||||||
$this->collectBudgets();
|
$this->collectBudgets();
|
||||||
$this->appendCollectedData();
|
$this->appendCollectedData();
|
||||||
@@ -76,9 +79,14 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
|||||||
|
|
||||||
/** @var BudgetLimit $limit */
|
/** @var BudgetLimit $limit */
|
||||||
foreach ($this->collection as $limit) {
|
foreach ($this->collection as $limit) {
|
||||||
$this->ids[] = (int)$limit->id;
|
$id = (int)$limit->id;
|
||||||
|
$this->ids[] = $id;
|
||||||
|
if (0 !== (int)$limit->transaction_currency_id) {
|
||||||
|
$this->currencyIds[$id] = (int)$limit->transaction_currency_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->ids = array_unique($this->ids);
|
$this->ids = array_unique($this->ids);
|
||||||
|
$this->currencyIds = array_unique($this->currencyIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function collectNotes(): void
|
private function collectNotes(): void
|
||||||
@@ -86,8 +94,7 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
|||||||
$notes = Note::query()->whereIn('noteable_id', $this->ids)
|
$notes = Note::query()->whereIn('noteable_id', $this->ids)
|
||||||
->whereNotNull('notes.text')
|
->whereNotNull('notes.text')
|
||||||
->where('notes.text', '!=', '')
|
->where('notes.text', '!=', '')
|
||||||
->where('noteable_type', BudgetLimit::class)->get(['notes.noteable_id', 'notes.text'])->toArray()
|
->where('noteable_type', BudgetLimit::class)->get(['notes.noteable_id', 'notes.text'])->toArray();
|
||||||
;
|
|
||||||
foreach ($notes as $note) {
|
foreach ($notes as $note) {
|
||||||
$this->notes[(int)$note['noteable_id']] = (string)$note['text'];
|
$this->notes[(int)$note['noteable_id']] = (string)$note['text'];
|
||||||
}
|
}
|
||||||
@@ -98,10 +105,15 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
|||||||
{
|
{
|
||||||
$this->collection = $this->collection->map(function (BudgetLimit $item) {
|
$this->collection = $this->collection->map(function (BudgetLimit $item) {
|
||||||
$id = (int)$item->id;
|
$id = (int)$item->id;
|
||||||
|
$currencyId = (int)$item->transaction_currency_id;
|
||||||
|
if (0 === $currencyId) {
|
||||||
|
$currencyId = $this->primaryCurrency->id;
|
||||||
|
}
|
||||||
$meta = [
|
$meta = [
|
||||||
'notes' => $this->notes[$id] ?? null,
|
'notes' => $this->notes[$id] ?? null,
|
||||||
'spent' => $this->expenses[$id] ?? [],
|
'spent' => $this->expenses[$id] ?? [],
|
||||||
'pc_spent' => $this->pcExpenses[$id] ?? [],
|
'pc_spent' => $this->pcExpenses[$id] ?? [],
|
||||||
|
'currency' => $this->currencies[$currencyId],
|
||||||
];
|
];
|
||||||
$item->meta = $meta;
|
$item->meta = $meta;
|
||||||
|
|
||||||
@@ -133,4 +145,13 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function collectCurrencies(): void
|
||||||
|
{
|
||||||
|
$this->currencies[$this->primaryCurrency->id] = $this->primaryCurrency;
|
||||||
|
$currencies = TransactionCurrency::whereIn('id', $this->currencyIds)->whereNot('id', $this->primaryCurrency->id)->get();
|
||||||
|
foreach ($currencies as $currency) {
|
||||||
|
$this->currencies[(int)$currency->id] = $currency;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
|
|
||||||
$this->transactions[$id][$transactionId] = [
|
$this->transactions[$id][$transactionId] = [
|
||||||
'id' => (string)$transactionId,
|
'id' => (string)$transactionId,
|
||||||
'recurrence_id' => $id,
|
//'recurrence_id' => $id,
|
||||||
'transaction_currency_id' => (int)$transaction->transaction_currency_id,
|
'transaction_currency_id' => (int)$transaction->transaction_currency_id,
|
||||||
'foreign_currency_id' => null === $transaction->foreign_currency_id ? null : (int)$transaction->foreign_currency_id,
|
'foreign_currency_id' => null === $transaction->foreign_currency_id ? null : (int)$transaction->foreign_currency_id,
|
||||||
'source_id' => (int)$transaction->source_id,
|
'source_id' => (int)$transaction->source_id,
|
||||||
|
|||||||
@@ -64,10 +64,7 @@ class BudgetLimitTransformer extends AbstractTransformer
|
|||||||
public function transform(BudgetLimit $budgetLimit): array
|
public function transform(BudgetLimit $budgetLimit): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$currency = $budgetLimit->transactionCurrency;
|
$currency = $budgetLimit->meta['currency'];
|
||||||
if (null === $currency) {
|
|
||||||
$currency = $this->primaryCurrency;
|
|
||||||
}
|
|
||||||
$amount = Steam::bcround($budgetLimit->amount, $currency->decimal_places);
|
$amount = Steam::bcround($budgetLimit->amount, $currency->decimal_places);
|
||||||
$pcAmount = null;
|
$pcAmount = null;
|
||||||
if ($this->convertToPrimary && $currency->id === $this->primaryCurrency->id) {
|
if ($this->convertToPrimary && $currency->id === $this->primaryCurrency->id) {
|
||||||
@@ -76,9 +73,6 @@ class BudgetLimitTransformer extends AbstractTransformer
|
|||||||
if ($this->convertToPrimary && $currency->id !== $this->primaryCurrency->id) {
|
if ($this->convertToPrimary && $currency->id !== $this->primaryCurrency->id) {
|
||||||
$pcAmount = Steam::bcround($budgetLimit->native_amount, $this->primaryCurrency->decimal_places);
|
$pcAmount = Steam::bcround($budgetLimit->native_amount, $this->primaryCurrency->decimal_places);
|
||||||
}
|
}
|
||||||
// TODO fix currency collection.
|
|
||||||
// TODO fix documentation.a
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => (string)$budgetLimit->id,
|
'id' => (string)$budgetLimit->id,
|
||||||
'created_at' => $budgetLimit->created_at->toAtomString(),
|
'created_at' => $budgetLimit->created_at->toAtomString(),
|
||||||
|
|||||||
Reference in New Issue
Block a user