Attempt to fix https://github.com/firefly-iii/firefly-iii/issues/8195 (this really needs refactor, separate tests.

This commit is contained in:
James Cole
2023-11-25 19:29:10 +01:00
parent 3355645cb4
commit 43c79af293
2 changed files with 39 additions and 18 deletions

View File

@@ -86,24 +86,37 @@ class BillTransformer extends AbstractTransformer
foreach ($payDates as $string) { foreach ($payDates as $string) {
$payDatesFormatted[] = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone'))->toAtomString(); $payDatesFormatted[] = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone'))->toAtomString();
} }
$nextExpectedMatch = null; // next expected match
if (null !== ($payDates[0] ?? null)) { $nem = null;
$nextExpectedMatch = Carbon::createFromFormat('!Y-m-d', $payDates[0], config('app.timezone'))->toAtomString(); $nemDate = null;
$nemDiff = trans('firefly.not_expected_period');
$firstPayDate = $payDates[0] ?? null;
if (null !== $firstPayDate) {
$nemDate = Carbon::createFromFormat('!Y-m-d', $firstPayDate, config('app.timezone'));
$nem = $nemDate->toAtomString();
// nullify again when it's outside the current view range.
if ($nemDate->lt($this->parameters->get('start')) || $nemDate->gt($this->parameters->get('end'))) {
$nem = null;
$nemDate = null;
$firstPayDate = null;
} }
$nextExpectedMatchDiff = trans('firefly.not_expected_period'); }
// converting back and forth is bad code but OK. // converting back and forth is bad code but OK.
$temp = new Carbon($nextExpectedMatch); if (null !== $nemDate) {
if ($temp->isToday()) { if ($nemDate->isToday()) {
$nextExpectedMatchDiff = trans('firefly.today'); $nemDiff = trans('firefly.today');
} }
$current = $payDatesFormatted[0] ?? null; $current = $payDatesFormatted[0] ?? null;
if (null !== $current && !$temp->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);
$nextExpectedMatchDiff = $temp2->diffForHumans(today(config('app.timezone')), CarbonInterface::DIFF_RELATIVE_TO_NOW); $nemDiff = trans('firefly.bill_expected_date', ['date' => $temp2->diffForHumans(today(config('app.timezone')), CarbonInterface::DIFF_RELATIVE_TO_NOW)]);
}
unset($temp2);
} }
unset($temp, $temp2);
return [ return [
'id' => $bill->id, 'id' => $bill->id,
'created_at' => $bill->created_at->toAtomString(), 'created_at' => $bill->created_at->toAtomString(),
@@ -128,8 +141,8 @@ class BillTransformer extends AbstractTransformer
'object_group_title' => $objectGroupTitle, 'object_group_title' => $objectGroupTitle,
// these fields need work: // these fields need work:
'next_expected_match' => $nextExpectedMatch, 'next_expected_match' => $nem,
'next_expected_match_diff' => $nextExpectedMatchDiff, 'next_expected_match_diff' => $nemDiff,
'pay_dates' => $payDatesFormatted, 'pay_dates' => $payDatesFormatted,
'paid_dates' => $paidDataFormatted, 'paid_dates' => $paidDataFormatted,
'links' => [ 'links' => [
@@ -299,8 +312,15 @@ class BillTransformer extends AbstractTransformer
// If nextExpectedMatch is after end, we continue: // If nextExpectedMatch is after end, we continue:
if ($nextExpectedMatch > $this->parameters->get('end')) { if ($nextExpectedMatch > $this->parameters->get('end')) {
app('log')->debug('Next expected match is after END, so stop looking'); app('log')->debug('Next expected match is after END, so stop looking');
//break;
if ($set->count() > 0) {
app('log')->debug(sprintf('Already have %d date(s), so break.', $set->count()));
break; break;
} }
app('log')->debug('Add date to set anyway.');
$set->push(clone $nextExpectedMatch);
continue;
}
app('log')->debug(sprintf('Next expected match is %s', $nextExpectedMatch->format('Y-m-d'))); app('log')->debug(sprintf('Next expected match is %s', $nextExpectedMatch->format('Y-m-d')));
// add to set, if the date is ON or after the start parameter // add to set, if the date is ON or after the start parameter
// AND date is after last paid date // AND date is after last paid date

View File

@@ -94,7 +94,8 @@
#} #}
{% if entry.paid_dates|length == 0 and entry.pay_dates|length > 0 and entry.active %} {% if entry.paid_dates|length == 0 and entry.pay_dates|length > 0 and entry.active %}
<td class="paid_in_period text-warning"> <td class="paid_in_period text-warning">
{{ trans('firefly.bill_expected_date', {date: entry.next_expected_match_diff }) }} {{ entry.next_expected_match_diff }}
<!-- {{ trans('firefly.bill_expected_date', {date: entry.next_expected_match_diff }) }} -->
</td> </td>
<td class="expected_in_period hidden-sm hidden-xs"> <td class="expected_in_period hidden-sm hidden-xs">
{% for date in entry.pay_dates %} {% for date in entry.pay_dates %}