fix one-minute rounding bug in quick-entries (#3580)
* fix one-minute rounding bug for quick entries form * allow to delete and create/update timesheets in one go * prevent issues with negative durations
This commit is contained in:
@@ -118,7 +118,10 @@ class QuickEntryController extends AbstractController
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$beginTime = $factory->createDateTime($this->configuration->getTimesheetDefaultBeginTime())->format('H:i:s');
|
$defaultBegin = $factory->createDateTime($this->configuration->getTimesheetDefaultBeginTime());
|
||||||
|
$defaultHour = (int) $defaultBegin->format('H');
|
||||||
|
$defaultMinute = (int) $defaultBegin->format('i');
|
||||||
|
$defaultBegin->setTime($defaultHour, $defaultMinute, 0, 0);
|
||||||
|
|
||||||
// fill all rows and columns to make sure we do not have missing records
|
// fill all rows and columns to make sure we do not have missing records
|
||||||
/** @var QuickEntryModel[] $models */
|
/** @var QuickEntryModel[] $models */
|
||||||
@@ -132,7 +135,7 @@ class QuickEntryController extends AbstractController
|
|||||||
$tmp->setProject($row['project']);
|
$tmp->setProject($row['project']);
|
||||||
$tmp->setActivity($row['activity']);
|
$tmp->setActivity($row['activity']);
|
||||||
$tmp->setBegin(clone $day['day']);
|
$tmp->setBegin(clone $day['day']);
|
||||||
$tmp->getBegin()->modify($beginTime);
|
$tmp->getBegin()->setTime($defaultHour, $defaultMinute, 0, 0);
|
||||||
$model->addTimesheet($tmp);
|
$model->addTimesheet($tmp);
|
||||||
} else {
|
} else {
|
||||||
$model->addTimesheet($day['entry']);
|
$model->addTimesheet($day['entry']);
|
||||||
@@ -147,7 +150,7 @@ class QuickEntryController extends AbstractController
|
|||||||
$tmp = new Timesheet();
|
$tmp = new Timesheet();
|
||||||
$tmp->setUser($user);
|
$tmp->setUser($user);
|
||||||
$tmp->setBegin(clone $day['day']);
|
$tmp->setBegin(clone $day['day']);
|
||||||
$tmp->getBegin()->modify($beginTime);
|
$tmp->getBegin()->setTime($defaultHour, $defaultMinute, 0, 0);
|
||||||
$empty->addTimesheet($tmp);
|
$empty->addTimesheet($tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +164,7 @@ class QuickEntryController extends AbstractController
|
|||||||
$tmp = new Timesheet();
|
$tmp = new Timesheet();
|
||||||
$tmp->setUser($user);
|
$tmp->setUser($user);
|
||||||
$tmp->setBegin(clone $day['day']);
|
$tmp->setBegin(clone $day['day']);
|
||||||
$tmp->getBegin()->modify($beginTime);
|
$tmp->getBegin()->setTime($defaultHour, $defaultMinute, 0, 0);
|
||||||
$model->addTimesheet($tmp);
|
$model->addTimesheet($tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,28 +207,28 @@ class QuickEntryController extends AbstractController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isGranted('delete_own_timesheet') && \count($deleteTimesheets) > 0) {
|
|
||||||
try {
|
try {
|
||||||
|
$saved = false;
|
||||||
|
if (\count($deleteTimesheets) > 0 && $this->isGranted('delete_own_timesheet')) {
|
||||||
$this->timesheetService->deleteMultipleTimesheets($deleteTimesheets);
|
$this->timesheetService->deleteMultipleTimesheets($deleteTimesheets);
|
||||||
|
$saved = true;
|
||||||
return $this->redirectToRoute('quick_entry', ['begin' => $begin->format('Y-m-d')]);
|
|
||||||
} catch (\Exception $ex) {
|
|
||||||
$this->flashError('action.delete.error');
|
|
||||||
$this->logException($ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\count($saveTimesheets) > 0) {
|
if (\count($saveTimesheets) > 0) {
|
||||||
try {
|
|
||||||
$this->timesheetService->updateMultipleTimesheets($saveTimesheets);
|
$this->timesheetService->updateMultipleTimesheets($saveTimesheets);
|
||||||
|
$saved = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($saved) {
|
||||||
|
$this->flashSuccess('action.update.success');
|
||||||
|
|
||||||
return $this->redirectToRoute('quick_entry', ['begin' => $begin->format('Y-m-d')]);
|
return $this->redirectToRoute('quick_entry', ['begin' => $begin->format('Y-m-d')]);
|
||||||
|
}
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
$this->flashError('action.update.error');
|
$this->flashError('action.update.error');
|
||||||
$this->logException($ex);
|
$this->logException($ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $this->render('quick-entry/index.html.twig', [
|
return $this->render('quick-entry/index.html.twig', [
|
||||||
'days' => $week,
|
'days' => $week,
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class QuickEntryTimesheetType extends AbstractType
|
|||||||
try {
|
try {
|
||||||
if (null !== $duration) {
|
if (null !== $duration) {
|
||||||
$end = clone $data->getBegin();
|
$end = clone $data->getBegin();
|
||||||
$end->modify('+ ' . $duration . ' seconds');
|
$end->modify('+ ' . abs($duration) . ' seconds');
|
||||||
$data->setEnd($end);
|
$data->setEnd($end);
|
||||||
} else {
|
} else {
|
||||||
$data->setDuration(null);
|
$data->setDuration(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user