Attempt to fix bill view

This commit is contained in:
James Cole
2023-10-06 18:21:49 +02:00
parent 8c1cbd77dd
commit d46041f22e
3 changed files with 64 additions and 34 deletions

View File

@@ -55,7 +55,6 @@ class Navigation
* @param int $skip
*
* @return Carbon
* @deprecated This method will be substituted by nextDateByInterval()
*/
public function addPeriod(Carbon $theDate, string $repeatFreq, int $skip = 0): Carbon
{
@@ -89,10 +88,10 @@ class Navigation
if (!array_key_exists($repeatFreq, $functionMap)) {
Log::error(sprintf(
'The periodicity %s is unknown. Choose one of available periodicity: %s',
$repeatFreq,
join(', ', array_keys($functionMap))
));
'The periodicity %s is unknown. Choose one of available periodicity: %s',
$repeatFreq,
join(', ', array_keys($functionMap))
));
return $theDate;
}
@@ -342,6 +341,35 @@ class Navigation
return $currentEnd;
}
/**
* @param string $period
* @param Carbon $beginning
* @param Carbon $end
*
* @return int
*/
public function diffInPeriods(string $period, Carbon $beginning, Carbon $end): int
{
$map = [
'daily' => 'diffInDays',
'weekly' => 'diffInWeeks',
'monthly' => 'diffInMonths',
'quarterly' => 'diffInQuarters',
'half-year' => 'diffInQuarters',
'yearly' => 'diffInYears',
];
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);
if ('half-year' === $period) {
$diff = ceil($diff / 2);
}
return (int)$diff;
}
/**
* @param Carbon $theCurrentEnd
* @param string $repeatFreq