This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new calculation mode and system configuration (#4)
- Loading branch information
1 parent
b37c0db
commit 098ed2a
Showing
14 changed files
with
316 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.gitignore | ||
.idea | ||
.php_cs.cache | ||
.disabled | ||
/vendor/ | ||
.php-cs-fixer.cache | ||
composer.lock | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the RecalculateRatesBundle 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\RecalculateRatesBundle\EventSubscriber; | ||
|
||
use App\Event\SystemConfigurationEvent; | ||
use App\Form\Model\Configuration; | ||
use App\Form\Model\SystemConfiguration; | ||
use KimaiPlugin\RecalculateRatesBundle\Form\RecalculateModeType; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
final class SystemConfigurationSubscriber implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @return array<string, array<int, string|int>> | ||
*/ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
SystemConfigurationEvent::class => ['onSystemConfiguration', 100], | ||
]; | ||
} | ||
|
||
public function onSystemConfiguration(SystemConfigurationEvent $event): void | ||
{ | ||
$newConfiguration = (new Configuration()) | ||
->setName('timesheet.recalculate.mode') | ||
->setLabel('recalculate.mode') | ||
->setRequired(true) | ||
->setTranslationDomain('system-configuration') | ||
->setType(RecalculateModeType::class); | ||
|
||
foreach ($event->getConfigurations() as $configuration) { | ||
if ($configuration->getSection() === 'timesheet') { | ||
$configuration->addConfiguration($newConfiguration); | ||
|
||
return; | ||
} | ||
} | ||
|
||
$event->addConfiguration( | ||
(new SystemConfiguration('recalculate'))->setConfiguration([$newConfiguration]) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the RecalculateRatesBundle 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\RecalculateRatesBundle\Form; | ||
|
||
use App\Constants; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class RecalculateModeType extends AbstractType | ||
{ | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$modes = ['recalculate.mode.off' => null]; | ||
|
||
/* @phpstan-ignore-next-line */ | ||
if (\defined('App\Constants::VERSION_ID') && Constants::VERSION_ID > 12000) { | ||
$modes['recalculate.mode.default'] = 'default'; | ||
} | ||
|
||
$modes['recalculate.mode.always'] = 'always'; | ||
|
||
$resolver->setDefaults([ | ||
'required' => true, | ||
'multiple' => false, | ||
'label' => 'kiosk.login_type', | ||
'choices' => $modes, | ||
]); | ||
} | ||
|
||
public function getParent(): string | ||
{ | ||
return ChoiceType::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,54 @@ | ||
# RecalculateRatesBundle | ||
# Recalculate-Rates plugin for Kimai | ||
|
||
A Kimai 2 plugin, which forces a recalculation of the hourly and fixed rates for timesheet records on every update. | ||
A Kimai plugin, which forces a recalculation of the hourly and fixed rates for timesheet records on certain updates. | ||
|
||
By default, Kimai will use the hourly/fixed rate which was initially found. | ||
There are two possible modes in which this plugin can work: | ||
|
||
## Warning | ||
1. Recalculate prices if certain fields were changed | ||
2. Recalculate prices on every update | ||
|
||
The good part is: you can change customer/project and activity and be sure, that the correct rate is used. | ||
The first mode is the better one, but only available from Kimai 1.20.1 on. | ||
|
||
The bad part: a manually entered hourly/fixed rate will be overwritten. You HAVE to work with the pre-configured rates on your activities/projects/customers. | ||
You can configure the mode, by default mode 1 is used, unless your Kimai version is too old, then 2 is used. | ||
|
||
## Recalculate prices if certain fields were changed | ||
|
||
This mode should be preferred. | ||
|
||
A timesheet record rate will be recalculated if it was changed in one of these fields: Customer, Project, Activity, User, Price | ||
|
||
This still might overwrite custom rates, which were applied to single timesheets. | ||
But this case is very rare and using custom rates for single entries should be avoided anyway. | ||
If you find yourself using this workflow often, consider using the [Expense plugin](https://www.kimai.org/store/expenses-bundle.html). | ||
|
||
## Recalculate prices on every update | ||
|
||
The good part is: | ||
- you can change customer/project and activity and be sure, that the correct rate is used. | ||
|
||
The bad part: | ||
- even setting the export field might change the hourly rate and render your history invalid | ||
- a manually entered hourly/fixed rate will be overwritten | ||
- you HAVE to work with the pre-configured rates on your activities/projects/customers. | ||
|
||
## Installation | ||
|
||
First clone it to your Kimai installation `plugins` directory: | ||
``` | ||
cd /kimai/var/plugins/ | ||
```bash | ||
cd var/plugins/ | ||
git clone https://github.com/Keleo/RecalculateRatesBundle.git | ||
``` | ||
|
||
And then rebuild the cache: | ||
``` | ||
cd /kimai/ | ||
bin/console cache:clear | ||
bin/console cache:warmup | ||
``` | ||
|
||
You could also [download it as zip](https://github.com/keleo/RecalculateRatesBundle/archive/master.zip) and upload the directory via FTP: | ||
The file structure needs to look like this afterwards: | ||
|
||
``` | ||
/kimai/var/plugins/ | ||
```bash | ||
var/plugins/ | ||
├── RecalculateRatesBundle | ||
│ ├── RecalculateRatesBundle.php | ||
│ ├── RecalculateRatesBundle.php | ||
| └ ... more files and directories follow here ... | ||
``` | ||
|
||
And then rebuild the cache: | ||
```bash | ||
bin/console kimai:reload --env=prod | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
<file source-language="en" target-language="de" datatype="plaintext" original="system-configuration.en.xlf"> | ||
<body> | ||
<trans-unit id="rH7H.bA" resname="label.recalculate"> | ||
<source>label.recalculate</source> | ||
<target>Preisneuberechnung</target> | ||
</trans-unit> | ||
<trans-unit id="GLQB2Tb" resname="label.recalculate.mode"> | ||
<source>label.recalculate.mode</source> | ||
<target>Modus für Preisneuberechnung</target> | ||
</trans-unit> | ||
<trans-unit id="nQcA1bA" resname="recalculate.mode.off"> | ||
<source>recalculate.mode.off</source> | ||
<target>Aus</target> | ||
</trans-unit> | ||
<trans-unit id="hjnOnzm" resname="recalculate.mode.always"> | ||
<source>recalculate.mode.always</source> | ||
<target>Bei jeder Änderung</target> | ||
</trans-unit> | ||
<trans-unit id="J1cndMp" resname="recalculate.mode.default"> | ||
<source>recalculate.mode.default</source> | ||
<target>Bei Änderung von Kunde, Projekt, Tätigkeit, Benutzer oder Preis</target> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
<file source-language="en" target-language="en" datatype="plaintext" original="system-configuration.en.xlf"> | ||
<body> | ||
<trans-unit id="rH7H.bA" resname="label.recalculate"> | ||
<source>label.recalculate</source> | ||
<target>Price recalculation</target> | ||
</trans-unit> | ||
<trans-unit id="GLQB2Tb" resname="label.recalculate.mode"> | ||
<source>label.recalculate.mode</source> | ||
<target>Mode for price recalculation</target> | ||
</trans-unit> | ||
<trans-unit id="nQcA1bA" resname="recalculate.mode.off"> | ||
<source>recalculate.mode.off</source> | ||
<target>Off</target> | ||
</trans-unit> | ||
<trans-unit id="hjnOnzm" resname="recalculate.mode.always"> | ||
<source>recalculate.mode.always</source> | ||
<target>With every update</target> | ||
</trans-unit> | ||
<trans-unit id="J1cndMp" resname="recalculate.mode.default"> | ||
<source>recalculate.mode.default</source> | ||
<target>With update of customer, project, activity, user or price</target> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
Oops, something went wrong.