From ffdfc17da9789c2ec4c3743407b21bf091bd9970 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 10 Jan 2024 17:37:16 +0100 Subject: [PATCH 1/2] configure if a deduction time should use normal or negative rates --- CHANGELOG.md | 6 +++ .../ActivityMetaDefinitionSubscriber.php | 2 +- .../SystemConfigurationSubscriber.php | 44 +++++++++++++++++++ Form/DeductionRateChoiceType.php | 35 +++++++++++++++ README.md | 15 ++++++- Resources/translations/messages.de.xlf | 16 ++++++- Resources/translations/messages.en.xlf | 16 ++++++- .../Calculator/DeductionTimeCalculator.php | 21 +++++++++ composer.json | 2 +- 9 files changed, 150 insertions(+), 7 deletions(-) create mode 100644 EventSubscriber/SystemConfigurationSubscriber.php create mode 100644 Form/DeductionRateChoiceType.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 6470e9a..36fb849 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Version 2.1.0 + +Compatibility: requires minimum Kimai 2.0 + +- New: configure if a deduction time should use normal or negative rates + ## Version 2.0.1 Compatibility: requires minimum Kimai 2.0 diff --git a/EventSubscriber/ActivityMetaDefinitionSubscriber.php b/EventSubscriber/ActivityMetaDefinitionSubscriber.php index c51ef43..925351a 100644 --- a/EventSubscriber/ActivityMetaDefinitionSubscriber.php +++ b/EventSubscriber/ActivityMetaDefinitionSubscriber.php @@ -31,7 +31,7 @@ public static function getSubscribedEvents(): array public function onEvent(ActivityMetaDefinitionEvent $event): void { $definition = new ActivityMeta(); - $definition->setLabel('deduction.label'); + $definition->setLabel('deduction_time'); $definition->setOptions(['help' => 'deduction.help']); $definition->setName(DeductionTimeBundle::META_FIELD_DEDUCTION); $definition->setType(CheckboxType::class); diff --git a/EventSubscriber/SystemConfigurationSubscriber.php b/EventSubscriber/SystemConfigurationSubscriber.php new file mode 100644 index 0000000..b6d7eac --- /dev/null +++ b/EventSubscriber/SystemConfigurationSubscriber.php @@ -0,0 +1,44 @@ + ['onSystemConfiguration', 100], + ]; + } + + public function onSystemConfiguration(SystemConfigurationEvent $event): void + { + $event->addConfiguration( + (new SystemConfiguration('deduction_time')) + //->setTranslationDomain('messages') + ->setConfiguration([ + (new Configuration('deduction.rate_config')) + //->setTranslationDomain('messages') + ->setType(DeductionRateChoiceType::class), + ]) + ); + } +} diff --git a/Form/DeductionRateChoiceType.php b/Form/DeductionRateChoiceType.php new file mode 100644 index 0000000..7ff62ad --- /dev/null +++ b/Form/DeductionRateChoiceType.php @@ -0,0 +1,35 @@ +setDefaults([ + 'choices' => [ + 'deduction.rate_default' => 'default', + 'deduction.rate_negative' => 'negative', + ], + ]); + } + + public function getParent(): string + { + return ChoiceType::class; + } +} diff --git a/README.md b/README.md index c1416ea..7f304b2 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Deduction times can be edited, but the negative duration is not used in the UI a It is always the calculated duration of `end - start`, which is then converted to its negative value. +There is a new system configuration, which defines how a rates are used for deduction times (see below). + ### Configure an activity When editing any activity, you will see a new checkbox `Deduction time`. @@ -24,13 +26,24 @@ You could manually subtract breaks from every day OR you use this plugin. 3. Use that new activity to record your employees break times, e.g. via calendar 4. Safely export or invoice your times: due to the negative duration the break times will be subtracted from the attendance time +### Handling rates + +Usually it is advised to configure a price of zero for everyone for deduction times. +But if you apply a regular hourly rates, the plugin will by default use this result as rate. + +You can switch this behavior and let the plugin switch the calculated rate into its negative value, to match the negative duration. +This behavior can be configured at System > Configuration > Deduction time: + +- Leave the price of each timesheet unchanged +- The price of each timesheet becomes negative + ## Installation This plugin is compatible with the following Kimai releases: | Bundle version | Minimum Kimai version | |----------------|-----------------------| -| 2.0 - 2.0.1 | 2.0.0 | +| 2.0 - 2.1.0 | 2.0.0 | | 1.0 | 1.27.0 | You find the most notable changes between the versions in the file [CHANGELOG.md](CHANGELOG.md). diff --git a/Resources/translations/messages.de.xlf b/Resources/translations/messages.de.xlf index cf9aaea..250b79c 100644 --- a/Resources/translations/messages.de.xlf +++ b/Resources/translations/messages.de.xlf @@ -2,14 +2,26 @@ - - deduction.label + + deduction_time Abzugszeit deduction.help Jeder Zeiteintrag wird als Abzugszeit angesehen und die errechnete Dauer wird ins negative umgekehrt + + deduction.rate_config + Preise für Abzugszeiten + + + deduction.rate_default + Den Preis jedes Zeiteintrags unverändert lassen + + + deduction.rate_negative + Der Satz jeden Eintrags wird negativ + diff --git a/Resources/translations/messages.en.xlf b/Resources/translations/messages.en.xlf index 7a76216..17ca63c 100644 --- a/Resources/translations/messages.en.xlf +++ b/Resources/translations/messages.en.xlf @@ -2,14 +2,26 @@ - - deduction.label + + deduction_time Deduction time deduction.help Each time entry is considered as a deduction time and the calculated duration is inverted to negative + + deduction.rate_config + Prices for deduction times + + + deduction.rate_default + Leave the price of each timesheet unchanged + + + deduction.rate_negative + The price of each timesheet becomes negative + diff --git a/Timesheet/Calculator/DeductionTimeCalculator.php b/Timesheet/Calculator/DeductionTimeCalculator.php index 191dbdb..acec754 100644 --- a/Timesheet/Calculator/DeductionTimeCalculator.php +++ b/Timesheet/Calculator/DeductionTimeCalculator.php @@ -10,12 +10,17 @@ namespace KimaiPlugin\DeductionTimeBundle\Timesheet\Calculator; +use App\Configuration\SystemConfiguration; use App\Entity\Timesheet; use App\Timesheet\CalculatorInterface; use KimaiPlugin\DeductionTimeBundle\DeductionTimeBundle; final class DeductionTimeCalculator implements CalculatorInterface { + public function __construct(private readonly SystemConfiguration $systemConfiguration) + { + } + public function calculate(Timesheet $record, array $changeset): void { if ($record->getActivity() === null) { @@ -28,6 +33,22 @@ public function calculate(Timesheet $record, array $changeset): void $duration = $record->getDuration(false); if ($duration > 0) { $record->setDuration($duration * -1); + + $config = $this->systemConfiguration->find('deduction.rate_config'); + if ($config === 'negative') { + $rate = $record->getRate(); + if ($rate > 0.00) { + $record->setRate($rate * -1); + } + } + + // hourly rate: cannot be smaller than 0 + // $hourly = $record->getHourlyRate(); + // if ($hourly !== null && $hourly > 0.00) { + // $record->setHourlyRate($hourly * -1); + // } + + // internal rate: leave it positive, someone could use it to cover lunch expenses } } } diff --git a/composer.json b/composer.json index 3569411..d31bd0f 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Configure certain activities as deduction time, resulting in negative durations for timesheets.", "homepage": "https://www.kimai.org/store/keleo-deduction-time-bundle.html", "type": "kimai-plugin", - "version": "2.0.1", + "version": "2.1.0", "keywords": [ "kimai", "kimai-plugin" From c8a91a2abe1c25fae46cd028ba0393db0b2fb451 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 10 Jan 2024 17:38:55 +0100 Subject: [PATCH 2/2] code styles --- EventSubscriber/SystemConfigurationSubscriber.php | 8 ++------ Form/DeductionRateChoiceType.php | 6 ++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/EventSubscriber/SystemConfigurationSubscriber.php b/EventSubscriber/SystemConfigurationSubscriber.php index b6d7eac..af8efc5 100644 --- a/EventSubscriber/SystemConfigurationSubscriber.php +++ b/EventSubscriber/SystemConfigurationSubscriber.php @@ -1,8 +1,8 @@