Files
kimai2/src/Timesheet/Calculator/RateCalculator.php
2024-05-17 22:55:08 +02:00

46 lines
1.1 KiB
PHP

<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Timesheet\Calculator;
use App\Entity\Timesheet;
use App\Timesheet\CalculatorInterface;
use App\Timesheet\RateServiceInterface;
/**
* Implementation to calculate the rate for a timesheet record.
*/
final class RateCalculator implements CalculatorInterface
{
public function __construct(private RateServiceInterface $service)
{
}
public function calculate(Timesheet $record, array $changeset): void
{
$rate = $this->service->calculate($record);
$record->setRate($rate->getRate());
$record->setInternalRate($rate->getInternalRate());
if ($rate->getHourlyRate() !== null) {
$record->setHourlyRate($rate->getHourlyRate());
}
if ($rate->getFixedRate() !== null) {
$record->setFixedRate($rate->getFixedRate());
}
}
public function getPriority(): int
{
return 300;
}
}