Update various pages, clean up some code.

This commit is contained in:
James Cole
2024-12-26 09:16:17 +01:00
parent d313f5fdf5
commit 06049a9a28
8 changed files with 58 additions and 56 deletions

View File

@@ -76,7 +76,6 @@ class IndexController extends Controller
$collection = $this->repository->getBills(); $collection = $this->repository->getBills();
$total = $collection->count(); $total = $collection->count();
$defaultCurrency = app('amount')->getDefaultCurrency();
$parameters = new ParameterBag(); $parameters = new ParameterBag();
// sub one day from temp start so the last paid date is one day before it should be. // sub one day from temp start so the last paid date is one day before it should be.
$tempStart = clone $start; $tempStart = clone $start;
@@ -84,7 +83,8 @@ class IndexController extends Controller
// $tempStart->subDay(); // $tempStart->subDay();
$parameters->set('start', $tempStart); $parameters->set('start', $tempStart);
$parameters->set('end', $end); $parameters->set('end', $end);
$parameters->set('convertToNative', $this->convertToNative);
$parameters->set('defaultCurrency', $this->defaultCurrency);
/** @var BillTransformer $transformer */ /** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class); $transformer = app(BillTransformer::class);
$transformer->setParameters($parameters); $transformer->setParameters($parameters);
@@ -112,7 +112,7 @@ class IndexController extends Controller
'bills' => [], 'bills' => [],
]; ];
$currency = $bill->transactionCurrency ?? $defaultCurrency; $currency = $bill->transactionCurrency ?? $this->defaultCurrency;
$array['currency_id'] = $currency->id; $array['currency_id'] = $currency->id;
$array['currency_name'] = $currency->name; $array['currency_name'] = $currency->name;
$array['currency_symbol'] = $currency->symbol; $array['currency_symbol'] = $currency->symbol;
@@ -122,7 +122,6 @@ class IndexController extends Controller
$array['rules'] = $rules[$bill['id']] ?? []; $array['rules'] = $rules[$bill['id']] ?? [];
$bills[$groupOrder]['bills'][] = $array; $bills[$groupOrder]['bills'][] = $array;
} }
// order by key // order by key
ksort($bills); ksort($bills);

View File

@@ -123,10 +123,10 @@ class ReconcileController extends Controller
Log::debug(sprintf('End balance: "%s"', $endBalance)); Log::debug(sprintf('End balance: "%s"', $endBalance));
Log::debug(sprintf('Cleared amount: "%s"', $clearedAmount)); Log::debug(sprintf('Cleared amount: "%s"', $clearedAmount));
Log::debug(sprintf('Amount: "%s"', $amount)); Log::debug(sprintf('Amount: "%s"', $amount));
$difference = bcadd(bcadd(bcsub($startBalance, $endBalance), $clearedAmount), $amount); $difference = bcadd(bcadd(bcsub($startBalance ?? '0', $endBalance ?? '0'), $clearedAmount?? '0'), $amount);
$diffCompare = bccomp($difference, '0'); $diffCompare = bccomp($difference, '0');
$countCleared = count($clearedJournals); $countCleared = count($clearedJournals);
$reconSum = bcadd(bcadd($startBalance, $amount), $clearedAmount); $reconSum = bcadd(bcadd($startBalance ?? '0', $amount ?? '0'), $clearedAmount ?? '0');
try { try {
$view = view('accounts.reconcile.overview', compact('account', 'start', 'diffCompare', 'difference', 'end', 'clearedAmount', 'startBalance', 'endBalance', 'amount', 'route', 'countCleared', 'reconSum', 'selectedIds'))->render(); $view = view('accounts.reconcile.overview', compact('account', 'start', 'diffCompare', 'difference', 'end', 'clearedAmount', 'startBalance', 'endBalance', 'amount', 'route', 'countCleared', 'reconSum', 'selectedIds'))->render();

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Middleware; namespace FireflyIII\Http\Middleware;
use DB;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Support\System\OAuthKeys; use FireflyIII\Support\System\OAuthKeys;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;

View File

@@ -60,6 +60,8 @@ class Bill extends Model
'match_encrypted' => 'boolean', 'match_encrypted' => 'boolean',
'amount_min' => 'string', 'amount_min' => 'string',
'amount_max' => 'string', 'amount_max' => 'string',
'native_amount_min' => 'string',
'native_amount_max' => 'string',
]; ];
protected $fillable protected $fillable
@@ -81,6 +83,8 @@ class Bill extends Model
'extension_date', 'extension_date',
'end_date_tz', 'end_date_tz',
'extension_date_tz', 'extension_date_tz',
'native_amount_min',
'native_amount_max',
]; ];
protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted']; protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted'];

View File

@@ -29,6 +29,7 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
/** /**
@@ -123,10 +124,10 @@ class Steam
[ // @phpstan-ignore-line [ // @phpstan-ignore-line
'transaction_journals.date', 'transaction_journals.date',
'transactions.transaction_currency_id', 'transactions.transaction_currency_id',
\DB::raw('SUM(transactions.amount) AS modified'), DB::raw('SUM(transactions.amount) AS modified'),
'transactions.foreign_currency_id', 'transactions.foreign_currency_id',
\DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'), DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'),
\DB::raw('SUM(transactions.native_amount) AS modified_native'), DB::raw('SUM(transactions.native_amount) AS modified_native'),
] ]
); );
@@ -178,24 +179,6 @@ class Steam
// add to GBP, as expected. // add to GBP, as expected.
$currentBalance[$entryCurrency->code] = bcadd($currentBalance[$entryCurrency->code] ?? '0', $modified); $currentBalance[$entryCurrency->code] = bcadd($currentBalance[$entryCurrency->code] ?? '0', $modified);
} }
// // add "modified" to amount if the currency id matches the account currency id.
// if ($entry->transaction_currency_id === $currency->id) {
// $currentBalance['balance'] = bcadd($currentBalance['balance'], $modified);
// $currentBalance[$currency->code] = bcadd($currentBalance[$currency->code], $modified);
// }
//
// // always add the native balance, even if it ends up at zero.
// $currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $nativeModified);
// DO NOT add modified foreign to the array
// if (null !== $entry->foreign_currency_id) {
// $foreignId = $entry->foreign_currency_id;
// $currencies[$foreignId] ??= TransactionCurrency::find($foreignId);
// $foreignCurrency = $currencies[$foreignId];
// $currentBalance[$foreignCurrency->code] ??= '0';
// $currentBalance[$foreignCurrency->code] = bcadd($currentBalance[$foreignCurrency->code], $foreignModified);
// }
$balances[$carbon->format('Y-m-d')] = $currentBalance; $balances[$carbon->format('Y-m-d')] = $currentBalance;
Log::debug('Updated entry',$currentBalance); Log::debug('Updated entry',$currentBalance);
} }

View File

@@ -30,6 +30,7 @@ use FireflyIII\Models\Bill;
use FireflyIII\Models\ObjectGroup; use FireflyIII\Models\ObjectGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Models\BillDateCalculator; use FireflyIII\Support\Models\BillDateCalculator;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@@ -58,6 +59,8 @@ class BillTransformer extends AbstractTransformer
*/ */
public function transform(Bill $bill): array public function transform(Bill $bill): array
{ {
$defaultCurrency = $this->parameters->get('defaultCurrency') ?? Amount::getDefaultCurrency();
$paidData = $this->paidData($bill); $paidData = $this->paidData($bill);
$lastPaidDate = $this->getLastPaidDate($paidData); $lastPaidDate = $this->getLastPaidDate($paidData);
$start = $this->parameters->get('start') ?? today()->subYears(10); $start = $this->parameters->get('start') ?? today()->subYears(10);
@@ -149,6 +152,8 @@ class BillTransformer extends AbstractTransformer
'name' => $bill->name, 'name' => $bill->name,
'amount_min' => app('steam')->bcround($bill->amount_min, $currency->decimal_places), 'amount_min' => app('steam')->bcround($bill->amount_min, $currency->decimal_places),
'amount_max' => app('steam')->bcround($bill->amount_max, $currency->decimal_places), 'amount_max' => app('steam')->bcround($bill->amount_max, $currency->decimal_places),
'native_amount_min' => app('steam')->bcround($bill->native_amount_min, $defaultCurrency->decimal_places),
'native_amount_max' => app('steam')->bcround($bill->native_amount_max, $defaultCurrency->decimal_places),
'date' => $bill->date->toAtomString(), 'date' => $bill->date->toAtomString(),
'end_date' => $bill->end_date?->toAtomString(), 'end_date' => $bill->end_date?->toAtomString(),
'extension_date' => $bill->extension_date?->toAtomString(), 'extension_date' => $bill->extension_date?->toAtomString(),
@@ -169,7 +174,7 @@ class BillTransformer extends AbstractTransformer
'links' => [ 'links' => [
[ [
'rel' => 'self', 'rel' => 'self',
'uri' => '/bills/'.$bill->id, 'uri' => '/bills/' . $bill->id,
], ],
], ],
]; ];

View File

@@ -27,7 +27,15 @@
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<td colspan="2"> <td colspan="2">
{{ trans('firefly.match_between_amounts', {low: formatAmountByCurrency(object.data.currency,object.data.amount_min), high: formatAmountByCurrency(object.data.currency,object.data.amount_max) })|raw }} {% set lowAmount = formatAmountByCurrency(object.data.currency,object.data.amount_min) %}
{% set highAmount = formatAmountByCurrency(object.data.currency,object.data.amount_max) %}
{% if(0 != object.data.native_amount_min) %}
{% set lowAmount = lowAmount ~ ' (' ~ formatAmountByCode(object.data.native_amount_min, defaultCurrency.code) ~ ')' %}
{% endif %}
{% if(0 != object.data.native_amount_max) %}
{% set highAmount = highAmount ~ ' (' ~ formatAmountByCode(object.data.native_amount_max, defaultCurrency.code) ~ ')' %}
{% endif %}
{{ trans('firefly.match_between_amounts', {low: lowAmount, high: highAmount })|raw }}
{{ 'repeats'|_ }} {{ 'repeats'|_ }}
{{ trans('firefly.repeat_freq_' ~object.data.repeat_freq) }}. {{ trans('firefly.repeat_freq_' ~object.data.repeat_freq) }}.
</td> </td>

View File

@@ -67,6 +67,10 @@
title="{{ formatAmountBySymbol(entry.amount_min, entry.currency_symbol, entry.currency_decimal_places, false)|escape }} -- {{ formatAmountBySymbol(entry.amount_max, entry.currency_symbol, entry.currency_decimal_places, false)|escape }}" title="{{ formatAmountBySymbol(entry.amount_min, entry.currency_symbol, entry.currency_decimal_places, false)|escape }} -- {{ formatAmountBySymbol(entry.amount_max, entry.currency_symbol, entry.currency_decimal_places, false)|escape }}"
> >
~ {{ formatAmountBySymbol((entry.amount_max + entry.amount_min)/2, entry.currency_symbol, entry.currency_decimal_places) }} ~ {{ formatAmountBySymbol((entry.amount_max + entry.amount_min)/2, entry.currency_symbol, entry.currency_decimal_places) }}
{% if '0' != entry.native_amount_max %}
({{ formatAmountBySymbol((entry.native_amount_max + entry.native_amount_min)/2, defaultCurrency.symbol, defaultCurrency.decimal_places) }})
{% endif %}
</span> </span>
</td> </td>