Rebuild frontpage with better bills overview.

This commit is contained in:
James Cole
2023-09-17 09:45:34 +02:00
parent 518712d9e8
commit 35b0c20f88
57 changed files with 875 additions and 378 deletions

View File

@@ -107,6 +107,7 @@ class BillTransformer extends AbstractTransformer
}
$this->default = app('amount')->getDefaultCurrency();
$this->converter = new ExchangeRateConverter();
// grab all paid dates:
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$journals = TransactionJournal::whereIn('bill_id', $bills)
@@ -128,6 +129,7 @@ class BillTransformer extends AbstractTransformer
}
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
app('log')->debug(sprintf('Processing journal #%d', $journal->id));
$transaction = $transactions[(int)$journal->id] ?? [];
$billId = (int)$journal->bill_id;
$currencyId = (int)$transaction['transaction_currency_id'] ?? 0;
@@ -139,7 +141,9 @@ class BillTransformer extends AbstractTransformer
$foreignCurrencyName = null;
$foreignCurrencySymbol = null;
$foreignCurrencyDp = null;
app('log')->debug('Foreign currency is NULL');
if (null !== $transaction['foreign_currency_id']) {
app('log')->debug(sprintf('Foreign currency is #%d', $transaction['foreign_currency_id']));
$foreignCurrencyId = (int)$transaction['foreign_currency_id'];
$currencies[$foreignCurrencyId] = $currencies[$foreignCurrencyId] ?? TransactionCurrency::find($foreignCurrencyId);
$foreignCurrencyCode = $currencies[$foreignCurrencyId]->code;
@@ -157,10 +161,10 @@ class BillTransformer extends AbstractTransformer
'currency_name' => $currencies[$currencyId]->name,
'currency_symbol' => $currencies[$currencyId]->symbol,
'currency_decimal_places' => (int)$currencies[$currencyId]->decimal_places,
'native_id' => (int)$currencies[$currencyId]->id,
'native_code' => $currencies[$currencyId]->code,
'native_symbol' => $currencies[$currencyId]->symbol,
'native_decimal_places' => (int)$currencies[$currencyId]->decimal_places,
'native_currency_id' => (int)$currencies[$currencyId]->id,
'native_currency_code' => $currencies[$currencyId]->code,
'native_currency_symbol' => $currencies[$currencyId]->symbol,
'native_currency_decimal_places' => (int)$currencies[$currencyId]->decimal_places,
'foreign_currency_id' => $foreignCurrencyId,
'foreign_currency_code' => $foreignCurrencyCode,
'foreign_currency_name' => $foreignCurrencyName,
@@ -169,7 +173,9 @@ class BillTransformer extends AbstractTransformer
'amount' => $transaction['amount'],
'foreign_amount' => $transaction['foreign_amount'],
'native_amount' => $this->converter->convert($currencies[$currencyId], $this->default, $journal->date, $transaction['amount']),
'foreign_native_amount' => null === $transaction['foreign_amount'] ? null : $this->converter->convert($currencies[$foreignCurrencyId], $this->default, $journal->date, $transaction['foreign_amount']),
'foreign_native_amount' => '' === (string)$transaction['foreign_amount'] ? null : $this->converter->convert(
$currencies[$foreignCurrencyId],
$this->default, $journal->date, $transaction['foreign_amount']),
];
}
}
@@ -199,40 +205,40 @@ class BillTransformer extends AbstractTransformer
$nextExpectedMatchDiff = $this->getNextExpectedMatchDiff($nextExpectedMatch, $payDates);
return [
'id' => (int)$bill->id,
'created_at' => $bill->created_at->toAtomString(),
'updated_at' => $bill->updated_at->toAtomString(),
'name' => $bill->name,
'amount_min' => app('steam')->bcround($bill->amount_min, $currency->decimal_places),
'amount_max' => app('steam')->bcround($bill->amount_max, $currency->decimal_places),
'native_amount_min' => $this->converter->convert($currency, $this->default, $date, $bill->amount_min),
'native_amount_max' => $this->converter->convert($currency, $this->default, $date, $bill->amount_max),
'currency_id' => (string)$bill->transaction_currency_id,
'currency_code' => $currency->code,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => (int)$currency->decimal_places,
'native_id' => $this->default->id,
'native_code' => $this->default->code,
'native_name' => $this->default->name,
'native_symbol' => $this->default->symbol,
'native_decimal_places' => (int)$this->default->decimal_places,
'date' => $bill->date->toAtomString(),
'end_date' => $bill->end_date?->toAtomString(),
'extension_date' => $bill->extension_date?->toAtomString(),
'repeat_freq' => $bill->repeat_freq,
'skip' => (int)$bill->skip,
'active' => $bill->active,
'order' => (int)$bill->order,
'notes' => $this->notes[(int)$bill->id] ?? null,
'object_group_id' => $group ? $group['object_group_id'] : null,
'object_group_order' => $group ? $group['object_group_order'] : null,
'object_group_title' => $group ? $group['object_group_title'] : null,
'next_expected_match' => $nextExpectedMatch->toAtomString(),
'next_expected_match_diff' => $nextExpectedMatchDiff,
'pay_dates' => $payDates,
'paid_dates' => $paidData,
'links' => [
'id' => (int)$bill->id,
'created_at' => $bill->created_at->toAtomString(),
'updated_at' => $bill->updated_at->toAtomString(),
'name' => $bill->name,
'amount_min' => app('steam')->bcround($bill->amount_min, $currency->decimal_places),
'amount_max' => app('steam')->bcround($bill->amount_max, $currency->decimal_places),
'native_amount_min' => $this->converter->convert($currency, $this->default, $date, $bill->amount_min),
'native_amount_max' => $this->converter->convert($currency, $this->default, $date, $bill->amount_max),
'currency_id' => (string)$bill->transaction_currency_id,
'currency_code' => $currency->code,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => (int)$currency->decimal_places,
'native_currency_id' => $this->default->id,
'native_currency_code' => $this->default->code,
'native_currency_name' => $this->default->name,
'native_currency_symbol' => $this->default->symbol,
'native_currency_decimal_places' => (int)$this->default->decimal_places,
'date' => $bill->date->toAtomString(),
'end_date' => $bill->end_date?->toAtomString(),
'extension_date' => $bill->extension_date?->toAtomString(),
'repeat_freq' => $bill->repeat_freq,
'skip' => (int)$bill->skip,
'active' => $bill->active,
'order' => (int)$bill->order,
'notes' => $this->notes[(int)$bill->id] ?? null,
'object_group_id' => $group ? $group['object_group_id'] : null,
'object_group_order' => $group ? $group['object_group_order'] : null,
'object_group_title' => $group ? $group['object_group_title'] : null,
'next_expected_match' => $nextExpectedMatch->toAtomString(),
'next_expected_match_diff' => $nextExpectedMatchDiff,
'pay_dates' => $payDates,
'paid_dates' => $paidData,
'links' => [
[
'rel' => 'self',
'uri' => sprintf('/bills/%d', $bill->id),