rounding rules via admin screen, round begin when starting record (#1229)

This commit is contained in:
Kevin Papst
2019-11-10 13:57:05 +01:00
committed by GitHub
parent fa1c79e15c
commit c6c4098759
47 changed files with 1100 additions and 185 deletions

View File

@@ -9,8 +9,25 @@
namespace App\Timesheet\TrackingMode;
class DefaultMode extends AbstractTrackingMode
use App\Configuration\TimesheetConfiguration;
use App\Entity\Timesheet;
use App\Timesheet\RoundingService;
use App\Timesheet\UserDateTimeFactory;
use Symfony\Component\HttpFoundation\Request;
final class DefaultMode extends AbstractTrackingMode
{
/**
* @var RoundingService
*/
private $rounding;
public function __construct(UserDateTimeFactory $dateTime, TimesheetConfiguration $configuration, RoundingService $rounding)
{
parent::__construct($dateTime, $configuration);
$this->rounding = $rounding;
}
public function canEditBegin(): bool
{
return true;
@@ -40,4 +57,23 @@ class DefaultMode extends AbstractTrackingMode
{
return true;
}
public function create(Timesheet $timesheet, Request $request): void
{
parent::create($timesheet, $request);
if (null === $timesheet->getBegin()) {
$timesheet->setBegin($this->dateTime->createDateTime());
}
$this->rounding->roundBegin($timesheet);
if (null !== $timesheet->getEnd()) {
$this->rounding->roundEnd($timesheet);
if (null !== $timesheet->getDuration()) {
$this->rounding->roundDuration($timesheet);
}
}
}
}