Update meta files for new release.

This commit is contained in:
James Cole
2023-10-28 17:17:09 +02:00
parent 62458885ce
commit 78153c2aa4
39 changed files with 433 additions and 162 deletions

View File

@@ -57,11 +57,12 @@ class BillTransformer extends AbstractTransformer
*/
public function transform(Bill $bill): array
{
$paidData = $this->paidData($bill);
$payDates = $this->payDates($bill);
$currency = $bill->transactionCurrency;
$notes = $this->repository->getNoteText($bill);
$notes = '' === $notes ? null : $notes;
$paidData = $this->paidData($bill);
$lastPaidDate = $this->getLastPaidDate($paidData);
$payDates = $this->payDates($bill, $lastPaidDate);
$currency = $bill->transactionCurrency;
$notes = $this->repository->getNoteText($bill);
$notes = '' === $notes ? null : $notes;
$this->repository->setUser($bill->user);
$objectGroupId = null;
@@ -86,8 +87,8 @@ class BillTransformer extends AbstractTransformer
$payDatesFormatted[] = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone'))->toAtomString();
}
$nextExpectedMatch = null;
if (null !== $paidData['next_expected_match']) {
$nextExpectedMatch = Carbon::createFromFormat('!Y-m-d', $paidData['next_expected_match'], config('app.timezone'))->toAtomString();
if (null !== ($payDates[0] ?? null)) {
$nextExpectedMatch = Carbon::createFromFormat('!Y-m-d', $payDates[0], config('app.timezone'))->toAtomString();
}
$nextExpectedMatchDiff = trans('firefly.not_expected_period');
// converting back and forth is bad code but OK.
@@ -182,31 +183,6 @@ class BillTransformer extends AbstractTransformer
$lastPaidDate = $this->lastPaidDate($set, $start);
app('log')->debug(sprintf('Result of lastPaidDate is %s', $lastPaidDate->format('Y-m-d')));
/*
* The next expected match (nextMatch) is, initially, the bill's date.
*/
$nextMatch = clone $bill->date;
/*
* Diff in months (or other period) between bill start and last paid date or $start.
*/
$steps = app('navigation')->diffInPeriods($bill->repeat_freq, $bill->skip, $start, $nextMatch);
$nextMatch = app('navigation')->addPeriod($nextMatch, $bill->repeat_freq, $steps);
if ($nextMatch->lt($lastPaidDate)) {
/*
* Add another period because it's before the last paid date
*/
app('log')->debug('Because the last paid date was before our next expected match, add another period.');
$nextMatch = app('navigation')->addPeriod($nextMatch, $bill->repeat_freq, $bill->skip);
}
if ($nextMatch->isSameDay($lastPaidDate)) {
/*
* Add another period because it's the same day as the last paid date.
*/
app('log')->debug('Because the last paid date was on the same day as our next expected match, add another day.');
$nextMatch = app('navigation')->addPeriod($nextMatch, $bill->repeat_freq, $bill->skip);
}
/*
* At this point the "next match" is exactly after the last time the bill was paid.
*/
@@ -219,11 +195,8 @@ class BillTransformer extends AbstractTransformer
];
}
app('log')->debug(sprintf('Next match: %s', $nextMatch->toIso8601String()));
return [
'paid_dates' => $result,
'next_expected_match' => $nextMatch->format('Y-m-d'),
'paid_dates' => $result
];
}
@@ -253,12 +226,13 @@ class BillTransformer extends AbstractTransformer
/**
* @param Bill $bill
* @param Carbon $lastPaidDate
*
* @return array
*/
protected function payDates(Bill $bill): array
protected function payDates(Bill $bill, ?Carbon $lastPaidDate): array
{
app('log')->debug(sprintf('Now in payDates() for bill #%d', $bill->id));
app('log')->debug(sprintf('Now in payDates(#%d, "%s")', $bill->id, $lastPaidDate?->format('Y-m-d')));
if (null === $this->parameters->get('start') || null === $this->parameters->get('end')) {
app('log')->debug('No start or end date, give empty array.');
@@ -303,7 +277,11 @@ class BillTransformer extends AbstractTransformer
}
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
if ($nextExpectedMatch->gte($this->parameters->get('start'))) {
// AND date is after last paid date
if ($nextExpectedMatch->gte($this->parameters->get('start'))
&& (null === $lastPaidDate || $nextExpectedMatch->gt($lastPaidDate))
) {
app('log')->debug('Add date to set.');
$set->push(clone $nextExpectedMatch);
}
@@ -315,7 +293,7 @@ class BillTransformer extends AbstractTransformer
$loop++;
if ($loop > 4) {
if ($loop > 12) {
break;
}
}
@@ -359,4 +337,30 @@ class BillTransformer extends AbstractTransformer
app('log')->debug(sprintf('Number of steps is %d, result is %s', $steps, $result->format('Y-m-d')));
return $result;
}
/**
* @param array $paidData
*
* @return Carbon|null
*/
private function getLastPaidDate(array $paidData): ?Carbon
{
app('log')->debug('getLastPaidDate()');
$return = null;
foreach ($paidData['paid_dates'] as $entry) {
if (null !== $return) {
$current = Carbon::createFromFormat('!Y-m-d', $entry['date'], config('app.timezone'));
if ($current->gt($return)) {
$return = clone $current;
}
app('log')->debug(sprintf('Last paid date is: %s', $return->format('Y-m-d')));
}
if (null === $return) {
$return = Carbon::createFromFormat('!Y-m-d', $entry['date'], config('app.timezone'));
app('log')->debug(sprintf('Last paid date is: %s', $return->format('Y-m-d')));
}
}
app('log')->debug(sprintf('Last paid date is: "%s"', $return?->format('Y-m-d')));
return $return;
}
}

View File

@@ -358,6 +358,8 @@ class BillTransformer extends AbstractTransformer
* Given a bill and a date, this method will tell you at which moment this bill expects its next
* transaction. Whether or not it is there already, is not relevant.
*
* TODO this method is bad compared to the v1 one.
*
* @param Bill $bill
* @param Carbon $date
*