mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 01:42:19 +00:00
Update various pages, clean up some code.
This commit is contained in:
@@ -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);
|
||||||
|
|
||||||
|
@@ -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();
|
||||||
|
@@ -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;
|
||||||
|
@@ -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'];
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
|
@@ -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,21 +59,23 @@ class BillTransformer extends AbstractTransformer
|
|||||||
*/
|
*/
|
||||||
public function transform(Bill $bill): array
|
public function transform(Bill $bill): array
|
||||||
{
|
{
|
||||||
$paidData = $this->paidData($bill);
|
$defaultCurrency = $this->parameters->get('defaultCurrency') ?? Amount::getDefaultCurrency();
|
||||||
$lastPaidDate = $this->getLastPaidDate($paidData);
|
|
||||||
$start = $this->parameters->get('start') ?? today()->subYears(10);
|
$paidData = $this->paidData($bill);
|
||||||
$end = $this->parameters->get('end') ?? today()->addYears(10);
|
$lastPaidDate = $this->getLastPaidDate($paidData);
|
||||||
$payDates = $this->calculator->getPayDates($start, $end, $bill->date, $bill->repeat_freq, $bill->skip, $lastPaidDate);
|
$start = $this->parameters->get('start') ?? today()->subYears(10);
|
||||||
$currency = $bill->transactionCurrency;
|
$end = $this->parameters->get('end') ?? today()->addYears(10);
|
||||||
$notes = $this->repository->getNoteText($bill);
|
$payDates = $this->calculator->getPayDates($start, $end, $bill->date, $bill->repeat_freq, $bill->skip, $lastPaidDate);
|
||||||
$notes = '' === $notes ? null : $notes;
|
$currency = $bill->transactionCurrency;
|
||||||
$objectGroupId = null;
|
$notes = $this->repository->getNoteText($bill);
|
||||||
$objectGroupOrder = null;
|
$notes = '' === $notes ? null : $notes;
|
||||||
$objectGroupTitle = null;
|
$objectGroupId = null;
|
||||||
|
$objectGroupOrder = null;
|
||||||
|
$objectGroupTitle = null;
|
||||||
$this->repository->setUser($bill->user);
|
$this->repository->setUser($bill->user);
|
||||||
|
|
||||||
/** @var null|ObjectGroup $objectGroup */
|
/** @var null|ObjectGroup $objectGroup */
|
||||||
$objectGroup = $bill->objectGroups->first();
|
$objectGroup = $bill->objectGroups->first();
|
||||||
if (null !== $objectGroup) {
|
if (null !== $objectGroup) {
|
||||||
$objectGroupId = $objectGroup->id;
|
$objectGroupId = $objectGroup->id;
|
||||||
$objectGroupOrder = $objectGroup->order;
|
$objectGroupOrder = $objectGroup->order;
|
||||||
@@ -82,7 +85,7 @@ class BillTransformer extends AbstractTransformer
|
|||||||
$paidDataFormatted = [];
|
$paidDataFormatted = [];
|
||||||
$payDatesFormatted = [];
|
$payDatesFormatted = [];
|
||||||
foreach ($paidData as $object) {
|
foreach ($paidData as $object) {
|
||||||
$date = Carbon::createFromFormat('!Y-m-d', $object['date'], config('app.timezone'));
|
$date = Carbon::createFromFormat('!Y-m-d', $object['date'], config('app.timezone'));
|
||||||
if (null === $date) {
|
if (null === $date) {
|
||||||
$date = today(config('app.timezone'));
|
$date = today(config('app.timezone'));
|
||||||
}
|
}
|
||||||
@@ -91,24 +94,24 @@ class BillTransformer extends AbstractTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($payDates as $string) {
|
foreach ($payDates as $string) {
|
||||||
$date = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone'));
|
$date = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone'));
|
||||||
if (null === $date) {
|
if (null === $date) {
|
||||||
$date = today(config('app.timezone'));
|
$date = today(config('app.timezone'));
|
||||||
}
|
}
|
||||||
$payDatesFormatted[] = $date->toAtomString();
|
$payDatesFormatted[] = $date->toAtomString();
|
||||||
}
|
}
|
||||||
// next expected match
|
// next expected match
|
||||||
$nem = null;
|
$nem = null;
|
||||||
$nemDate = null;
|
$nemDate = null;
|
||||||
$nemDiff = trans('firefly.not_expected_period');
|
$nemDiff = trans('firefly.not_expected_period');
|
||||||
$firstPayDate = $payDates[0] ?? null;
|
$firstPayDate = $payDates[0] ?? null;
|
||||||
|
|
||||||
if (null !== $firstPayDate) {
|
if (null !== $firstPayDate) {
|
||||||
$nemDate = Carbon::createFromFormat('!Y-m-d', $firstPayDate, config('app.timezone'));
|
$nemDate = Carbon::createFromFormat('!Y-m-d', $firstPayDate, config('app.timezone'));
|
||||||
if (null === $nemDate) {
|
if (null === $nemDate) {
|
||||||
$nemDate = today(config('app.timezone'));
|
$nemDate = today(config('app.timezone'));
|
||||||
}
|
}
|
||||||
$nem = $nemDate->toAtomString();
|
$nem = $nemDate->toAtomString();
|
||||||
|
|
||||||
// nullify again when it's outside the current view range.
|
// nullify again when it's outside the current view range.
|
||||||
if (
|
if (
|
||||||
@@ -129,7 +132,7 @@ class BillTransformer extends AbstractTransformer
|
|||||||
|
|
||||||
$current = $payDatesFormatted[0] ?? null;
|
$current = $payDatesFormatted[0] ?? null;
|
||||||
if (null !== $current && !$nemDate->isToday()) {
|
if (null !== $current && !$nemDate->isToday()) {
|
||||||
$temp2 = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
|
$temp2 = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
|
||||||
if (null === $temp2) {
|
if (null === $temp2) {
|
||||||
$temp2 = today(config('app.timezone'));
|
$temp2 = today(config('app.timezone'));
|
||||||
}
|
}
|
||||||
@@ -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,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@@ -191,13 +196,13 @@ class BillTransformer extends AbstractTransformer
|
|||||||
// 2023-07-18 this particular date is used to search for the last paid date.
|
// 2023-07-18 this particular date is used to search for the last paid date.
|
||||||
// 2023-07-18 the cloned $searchDate is used to grab the correct transactions.
|
// 2023-07-18 the cloned $searchDate is used to grab the correct transactions.
|
||||||
/** @var Carbon $start */
|
/** @var Carbon $start */
|
||||||
$start = clone $this->parameters->get('start');
|
$start = clone $this->parameters->get('start');
|
||||||
$searchStart = clone $start;
|
$searchStart = clone $start;
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = clone $this->parameters->get('end');
|
$end = clone $this->parameters->get('end');
|
||||||
$searchEnd = clone $end;
|
$searchEnd = clone $end;
|
||||||
|
|
||||||
// move the search dates to the start of the day.
|
// move the search dates to the start of the day.
|
||||||
$searchStart->startOfDay();
|
$searchStart->startOfDay();
|
||||||
@@ -207,7 +212,7 @@ class BillTransformer extends AbstractTransformer
|
|||||||
app('log')->debug(sprintf('Search parameters are: start: %s', $searchStart->format('Y-m-d')));
|
app('log')->debug(sprintf('Search parameters are: start: %s', $searchStart->format('Y-m-d')));
|
||||||
|
|
||||||
// Get from database when bill was paid.
|
// Get from database when bill was paid.
|
||||||
$set = $this->repository->getPaidDatesInRange($bill, $searchStart, $searchEnd);
|
$set = $this->repository->getPaidDatesInRange($bill, $searchStart, $searchEnd);
|
||||||
app('log')->debug(sprintf('Count %d entries in getPaidDatesInRange()', $set->count()));
|
app('log')->debug(sprintf('Count %d entries in getPaidDatesInRange()', $set->count()));
|
||||||
|
|
||||||
// Grab from array the most recent payment. If none exist, fall back to the start date and pretend *that* was the last paid date.
|
// Grab from array the most recent payment. If none exist, fall back to the start date and pretend *that* was the last paid date.
|
||||||
@@ -216,7 +221,7 @@ class BillTransformer extends AbstractTransformer
|
|||||||
app('log')->debug(sprintf('Result of lastPaidDate is %s', $lastPaidDate->format('Y-m-d')));
|
app('log')->debug(sprintf('Result of lastPaidDate is %s', $lastPaidDate->format('Y-m-d')));
|
||||||
|
|
||||||
// At this point the "next match" is exactly after the last time the bill was paid.
|
// At this point the "next match" is exactly after the last time the bill was paid.
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
$result[] = [
|
$result[] = [
|
||||||
'transaction_group_id' => (string) $entry->transaction_group_id,
|
'transaction_group_id' => (string) $entry->transaction_group_id,
|
||||||
|
@@ -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>
|
||||||
|
@@ -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>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user