Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure if a deduction time should use normal or negative rates #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion EventSubscriber/ActivityMetaDefinitionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions EventSubscriber/SystemConfigurationSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the "DeductionTimeBundle" for Kimai.
* All rights reserved by Kevin Papst (www.keleo.de).
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace KimaiPlugin\DeductionTimeBundle\EventSubscriber;

use App\Event\SystemConfigurationEvent;
use App\Form\Model\Configuration;
use App\Form\Model\SystemConfiguration;
use KimaiPlugin\DeductionTimeBundle\Form\DeductionRateChoiceType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

final class SystemConfigurationSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
SystemConfigurationEvent::class => ['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),
])
);
}
}
33 changes: 33 additions & 0 deletions Form/DeductionRateChoiceType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the "DeductionTimeBundle" for Kimai.
* All rights reserved by Kevin Papst (www.keleo.de).
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace KimaiPlugin\DeductionTimeBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;

class DeductionRateChoiceType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'choices' => [
'deduction.rate_default' => 'default',
'deduction.rate_negative' => 'negative',
],
]);
}

public function getParent(): string
{
return ChoiceType::class;
}
}
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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).
Expand Down
16 changes: 14 additions & 2 deletions Resources/translations/messages.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" target-language="de" datatype="plaintext" original="messages.en.xlf">
<body>
<trans-unit id="zc6XdUj" resname="deduction.label">
<source>deduction.label</source>
<trans-unit id="6cyD5gx" resname="deduction_time">
<source>deduction_time</source>
<target>Abzugszeit</target>
</trans-unit>
<trans-unit id="8uh0_wt" resname="deduction.help">
<source>deduction.help</source>
<target>Jeder Zeiteintrag wird als Abzugszeit angesehen und die errechnete Dauer wird ins negative umgekehrt</target>
</trans-unit>
<trans-unit id="PC5Edo5" resname="deduction.rate_config">
<source>deduction.rate_config</source>
<target>Preise für Abzugszeiten</target>
</trans-unit>
<trans-unit id="y8Hhcfp" resname="deduction.rate_default">
<source>deduction.rate_default</source>
<target>Den Preis jedes Zeiteintrags unverändert lassen</target>
</trans-unit>
<trans-unit id="vOTCO93" resname="deduction.rate_negative">
<source>deduction.rate_negative</source>
<target>Der Satz jeden Eintrags wird negativ</target>
</trans-unit>
</body>
</file>
</xliff>
16 changes: 14 additions & 2 deletions Resources/translations/messages.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" target-language="en" datatype="plaintext" original="none">
<body>
<trans-unit id="zc6XdUj" resname="deduction.label">
<source>deduction.label</source>
<trans-unit id="6cyD5gx" resname="deduction_time">
<source>deduction_time</source>
<target>Deduction time</target>
</trans-unit>
<trans-unit id="8uh0_wt" resname="deduction.help">
<source>deduction.help</source>
<target>Each time entry is considered as a deduction time and the calculated duration is inverted to negative</target>
</trans-unit>
<trans-unit id="PC5Edo5" resname="deduction.rate_config">
<source>deduction.rate_config</source>
<target>Prices for deduction times</target>
</trans-unit>
<trans-unit id="y8Hhcfp" resname="deduction.rate_default">
<source>deduction.rate_default</source>
<target>Leave the price of each timesheet unchanged</target>
</trans-unit>
<trans-unit id="vOTCO93" resname="deduction.rate_negative">
<source>deduction.rate_negative</source>
<target>The price of each timesheet becomes negative</target>
</trans-unit>
</body>
</file>
</xliff>
21 changes: 21 additions & 0 deletions Timesheet/Calculator/DeductionTimeCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down