Debug bill transformer

This commit is contained in:
James Cole
2023-10-27 17:47:12 +02:00
parent 106471877f
commit 902cc21ff0
2 changed files with 107 additions and 57 deletions

View File

@@ -58,6 +58,7 @@ class Navigation
*/
public function addPeriod(Carbon $theDate, string $repeatFreq, int $skip = 0): Carbon
{
$date = clone $theDate;
$functionMap = [
'1D' => Periodicity::Daily,
'daily' => Periodicity::Daily,
@@ -95,7 +96,7 @@ class Navigation
return $theDate;
}
return $this->nextDateByInterval($theDate, $functionMap[$repeatFreq], $skip);
return $this->nextDateByInterval($date, $functionMap[$repeatFreq], $skip);
}
/**
@@ -348,25 +349,36 @@ class Navigation
*
* @return int
*/
public function diffInPeriods(string $period, Carbon $beginning, Carbon $end): int
public function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int
{
app('log')->debug(sprintf('diffInPeriods: %s (skip: %d), between %s and %s.',
$period, $skip, $beginning->format('Y-m-d'), $end->format('Y-m-d')));
$map = [
'daily' => 'diffInDays',
'weekly' => 'diffInWeeks',
'monthly' => 'diffInMonths',
'quarterly' => 'diffInQuarters',
'half-year' => 'diffInQuarters',
'yearly' => 'diffInYears',
'daily' => 'floatDiffInDays',
'weekly' => 'floatDiffInWeeks',
'monthly' => 'floatDiffInMonths',
//'quarterly' => 'floatDiffInMonths',
//'half-year' => 'floatDiffInQuarters',
'yearly' => 'floatDiffInYears',
];
if (!array_key_exists($period, $map)) {
app('log')->warning(sprintf('No diffInPeriods for period "%s"', $period));
return 1;
}
$func = $map[$period];
$diff = $beginning->$func($end);
$diff = ceil($beginning->$func($end));
app('log')->debug(sprintf('Diff is %f (%d)', $beginning->$func($end), $diff));
if ('half-year' === $period) {
$diff = ceil($diff / 2);
}
if($skip > 0) {
$parameter = $skip + 1;
$diff = ceil($diff / $parameter) * $parameter;
app('log')->debug(sprintf('diffInPeriods: skip is %d, so param is %d, and diff becomes %d',
$skip, $parameter, $diff));
}
return (int)$diff;
}