Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -15,9 +15,9 @@ use App\Timesheet\CalculatorInterface;
|
||||
/**
|
||||
* Implementation to calculate the billable field for a timesheet record.
|
||||
*/
|
||||
class BillableCalculator implements CalculatorInterface
|
||||
final class BillableCalculator implements CalculatorInterface
|
||||
{
|
||||
public function calculate(Timesheet $record)
|
||||
public function calculate(Timesheet $record, array $changeset): void
|
||||
{
|
||||
switch ($record->getBillableMode()) {
|
||||
case Timesheet::BILLABLE_NO:
|
||||
|
||||
@@ -18,20 +18,11 @@ use App\Timesheet\RoundingService;
|
||||
*/
|
||||
final class DurationCalculator implements CalculatorInterface
|
||||
{
|
||||
/**
|
||||
* @var RoundingService
|
||||
*/
|
||||
private $roundings;
|
||||
|
||||
public function __construct(RoundingService $roundings)
|
||||
public function __construct(private RoundingService $roundings)
|
||||
{
|
||||
$this->roundings = $roundings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Timesheet $record
|
||||
*/
|
||||
public function calculate(Timesheet $record)
|
||||
public function calculate(Timesheet $record, array $changeset): void
|
||||
{
|
||||
if (null === $record->getEnd()) {
|
||||
return;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace App\Timesheet\Calculator;
|
||||
|
||||
use App\Entity\Rate;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Timesheet\CalculatorInterface;
|
||||
use App\Timesheet\RateService;
|
||||
@@ -17,19 +16,13 @@ use App\Timesheet\RateService;
|
||||
/**
|
||||
* Implementation to calculate the rate for a timesheet record.
|
||||
*/
|
||||
class RateCalculator implements CalculatorInterface
|
||||
final class RateCalculator implements CalculatorInterface
|
||||
{
|
||||
/**
|
||||
* @var RateService
|
||||
*/
|
||||
private $service;
|
||||
|
||||
public function __construct(RateService $service)
|
||||
public function __construct(private RateService $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
public function calculate(Timesheet $record)
|
||||
public function calculate(Timesheet $record, array $changeset): void
|
||||
{
|
||||
$rate = $this->service->calculate($record);
|
||||
|
||||
|
||||
52
src/Timesheet/Calculator/RateResetCalculator.php
Normal file
52
src/Timesheet/Calculator/RateResetCalculator.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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;
|
||||
|
||||
final class RateResetCalculator implements CalculatorInterface
|
||||
{
|
||||
public function calculate(Timesheet $record, array $changeset): void
|
||||
{
|
||||
// check if the rate was changed manually
|
||||
$changedRate = false;
|
||||
foreach (['hourlyRate', 'fixedRate', 'internalRate', 'rate'] as $field) {
|
||||
if (\array_key_exists($field, $changeset)) {
|
||||
$changedRate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if no manual rate changed was applied:
|
||||
// check if a field changed, that is relevant for the rate calculation: if one was changed =>
|
||||
// reset all rates, because most users do not even see their rates and would not be able
|
||||
// to fix or empty the rate, even if they knew that the changed project has another base rate
|
||||
if (!$changedRate) {
|
||||
foreach (['project', 'activity', 'user'] as $field) {
|
||||
if (\array_key_exists($field, $changeset)) {
|
||||
// this has room for minor improvements: entries with a manual rate might be changed
|
||||
$record->setRate(0.00);
|
||||
$record->setInternalRate(null);
|
||||
$record->setHourlyRate(null);
|
||||
$record->setFixedRate(null);
|
||||
$record->setBillableMode(Timesheet::BILLABLE_AUTOMATIC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getPriority(): int
|
||||
{
|
||||
// needs to run before all other
|
||||
return 50;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user