Configurable rate rounding (#5734)

* added invoice hydration of the issuer object
* added "rate calculator" mode
* new config to select rounding mode
* replace static calls with dependency injection
This commit is contained in:
Kevin Papst
2025-12-16 16:47:46 +01:00
committed by GitHub
parent 07ac6c308f
commit 595b5f4b25
43 changed files with 876 additions and 411 deletions

View File

@@ -15,7 +15,8 @@ use App\Entity\Tag;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Entity\UserPreference;
use App\Timesheet\Util;
use App\Timesheet\RateCalculator\ClassicRateCalculator;
use App\Timesheet\RateCalculator\RateCalculatorMode;
use Doctrine\Persistence\ObjectManager;
use Faker\Factory;
@@ -205,6 +206,7 @@ final class TimesheetFixtures implements TestFixture
}
}
$manager->flush();
$calculator = new ClassicRateCalculator();
for ($i = 0; $i < $this->amount; $i++) {
$description = $faker->text();
@@ -217,6 +219,9 @@ final class TimesheetFixtures implements TestFixture
}
$user = $users[array_rand($users)];
if ($user === null) {
continue;
}
$activity = $activities[array_rand($activities)];
$project = $activity->getProject();
@@ -225,6 +230,7 @@ final class TimesheetFixtures implements TestFixture
}
$timesheet = $this->createTimesheetEntry(
$calculator,
$user,
$activity,
$project,
@@ -244,12 +250,16 @@ final class TimesheetFixtures implements TestFixture
$activity = $activities[array_rand($activities)];
$project = $activity->getProject();
$user = $users[array_rand($users)];
if ($user === null) {
continue;
}
if (null === $project) {
if ($project === null) {
$project = $projects[array_rand($projects)];
}
$timesheet = $this->createTimesheetEntry(
$calculator,
$user,
$activity,
$project,
@@ -310,17 +320,25 @@ final class TimesheetFixtures implements TestFixture
}
/**
* @param \DateTime $start
* @param array<Tag> $tagArray
*/
private function createTimesheetEntry(User $user, Activity $activity, Project $project, ?string $description, \DateTime $start, array $tagArray = [], bool $setEndDate = true): Timesheet
private function createTimesheetEntry(
RateCalculatorMode $calculatorMode,
User $user,
Activity $activity,
Project $project,
?string $description,
\DateTime $start,
array $tagArray = [],
bool $setEndDate = true
): Timesheet
{
$end = clone $start;
$end = $end->modify('+ ' . (rand(1, 86400)) . ' seconds');
$duration = $end->getTimestamp() - $start->getTimestamp();
$hourlyRate = (float) $user->getPreferenceValue(UserPreference::HOURLY_RATE);
$rate = Util::calculateRate($hourlyRate, $duration);
$rate = $calculatorMode->calculateRate($hourlyRate, $duration);
$entry = new Timesheet();
$entry->setActivity($activity);