kimai / Paid-plugins

Support for paid Kimai plugins: Discussions and feature requests
https://www.kimai.org/store/
11 stars 1 forks source link

Allow duration to be modified based on content of meta field #35

Open robotictacos opened 3 years ago

robotictacos commented 3 years ago

My use case is that I have defined a "lunch break" meta field. The break duration should be deducted from the overall duration.

HeinzWuert commented 3 years ago

see kevinpapst/MetaFieldsBundle#72 not for a special use like yours but is going in the same direction

Recoil1980 commented 3 years ago

I like this option. When I first started using Kimai, if we were on a job the whole day, I would have 2 entries for each day - before and after lunch. Now I use the meta field for a lunch break section and just manually subtract the hours at the end of the week.

robotictacos commented 3 years ago

I made a code change that does this, but I don't know how to make a plugin out of it , soooo?

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Nicholas Franks @.> Sent: Monday, May 17, 2021 6:48:07 PM To: kevinpapst/MetaFieldsBundle @.> Cc: Dave Campbell @.>; Author @.> Subject: Re: [kevinpapst/MetaFieldsBundle] Allow duration to be modified based on content of meta field (#82)

I like this option. When I first started using Kimai, if we were on a job the whole day, I would have 2 entries for each day - before and after lunch. Now I use the meta field for a lunch break section and just manually subtract the hours at the end of the week.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/kevinpapst/kimai-plugins/issues/35, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALKJUXZSAKZEIBCTOSAEOOTTOGMKPANCNFSM432TJK5Q.

Recoil1980 commented 3 years ago

I made a code change that does this, but I don't know how to make a plugin out of it , soooo?

I don't even know where to start on making a plugin, but is there any way you can post what changes you made and where? I will take some time and see if I can assist you with a plugin because I know that more than just us will get some use out of this feature.

robotictacos commented 3 years ago

Happy to, and also happy if my code is re-used, I saw at least one other open issue asking for lunch break functionality (https://github.com/kevinpapst/kimai2/issues/2523), so it would seem this is widely desired, if I can figure out how to make a plugin, then I'll post it in the plugin store.

  1. If you are using docker, then understand that because this isn't a plugin, when the app gets updated it will of course blow this change away. I currently am not updating until I can figure out how to create the plugin.
  2. I have purchased and installed the custom fields plugin. If you don't have that there may be a way to do the same thing still but this method wouldn't work.
  3. Create a custom timesheet field called break, using datatype duration. I set mine to a default of 01:00, which users can change if they took a longer or shorter break.
  4. In the app folder (/opt/kimai inside the container) navigate to /opt/kimai/src/Timesheet, you will be making the same change to two sources:

In RoundingService.php, line 121, the existing code is: $duration = $record->getEnd()->getTimestamp() - $record->getBegin()->getTimestamp();

I have changed that to read: //$duration = $record->getEnd()->getTimestamp() - $record->getBegin()->getTimestamp(); $duration = $record->getEnd()->getTimestamp() - $record->getBegin()->getTimestamp() - $record->getMetaField('break')->getValue();

You will make that same change in the source /opt/kimai/src/Timesheet/Calculator/DurationCalculator.php, at line 40.

  1. After, refresh the cache by doing
    • bin/console cache:clear --env=prod
    • bin/console cache:warmup --env=prod
robotictacos commented 3 years ago

see kevinpapst/MetaFieldsBundle#72 not for a special use like yours but is going in the same direction

I agree it's similar in the sense that as currently implemented the custom fields are not terribly useful, mainly because it only allows you to store additional pieces of data alongside the current records, but it doesn't allow for actually using the data for anything, such as in your use case or mine. However, I think implementing that would be pretty tough, because I'm sure there are a crazy number of use cases. I suspect its much easier to simply have more fields built-in which can modify things such as rates, durations, costs, etc. One example that exists currently is the order number field, which I currently use as a project number, a PO number, order number or any other financial reference I might need.

Recoil1980 commented 3 years ago

Happy to, and also happy if my code is re-used, I saw at least one other open issue asking for lunch break functionality (kevinpapst/kimai2#2523), so it would seem this is widely desired, if I can figure out how to make a plugin, then I'll post it in the plugin store.

1. If you are using docker, then understand that because this isn't a plugin, when the app gets updated it will of course blow this change away.  I currently am not updating until I can figure out how to create the plugin.

2. I have purchased and installed the custom fields plugin.  If you don't have that there may be a way to do the same thing still but this method wouldn't work.

3. Create a custom timesheet field called break, using datatype duration.  I set mine to a default of 01:00, which users can change if they took a longer or shorter break.

4. In the app folder (/opt/kimai inside the container) navigate to /opt/kimai/src/Timesheet, you will be making the same change to two sources:

In RoundingService.php, line 121, the existing code is: $duration = $record->getEnd()->getTimestamp() - $record->getBegin()->getTimestamp();

I have changed that to read: //$duration = $record->getEnd()->getTimestamp() - $record->getBegin()->getTimestamp(); $duration = $record->getEnd()->getTimestamp() - $record->getBegin()->getTimestamp() - $record->getMetaField('break')->getValue();

You will make that same change in the source /opt/kimai/src/Timesheet/Calculator/DurationCalculator.php, at line 40.

1. After, refresh the cache by doing

* bin/console cache:clear --env=prod

* bin/console cache:warmup --env=prod

Let me take a look about helping to make this into a plugin for the Custom Fields plugin. I'll post an update in a bit.

Recoil1980 commented 3 years ago

Happy to, and also happy if my code is re-used, I saw at least one other open issue asking for lunch break functionality (kevinpapst/kimai2#2523), so it would seem this is widely desired, if I can figure out how to make a plugin, then I'll post it in the plugin store.

1. If you are using docker, then understand that because this isn't a plugin, when the app gets updated it will of course blow this change away.  I currently am not updating until I can figure out how to create the plugin.

2. I have purchased and installed the custom fields plugin.  If you don't have that there may be a way to do the same thing still but this method wouldn't work.

3. Create a custom timesheet field called break, using datatype duration.  I set mine to a default of 01:00, which users can change if they took a longer or shorter break.

4. In the app folder (/opt/kimai inside the container) navigate to /opt/kimai/src/Timesheet, you will be making the same change to two sources:

In RoundingService.php, line 121, the existing code is: $duration = $record->getEnd()->getTimestamp() - $record->getBegin()->getTimestamp();

I have changed that to read: //$duration = $record->getEnd()->getTimestamp() - $record->getBegin()->getTimestamp(); $duration = $record->getEnd()->getTimestamp() - $record->getBegin()->getTimestamp() - $record->getMetaField('break')->getValue();

You will make that same change in the source /opt/kimai/src/Timesheet/Calculator/DurationCalculator.php, at line 40.

1. After, refresh the cache by doing

* bin/console cache:clear --env=prod

* bin/console cache:warmup --env=prod

MetaFieldsBreak.zip

Okay, so that does not work. I skimmed over the plugin development docs, but since I mainly write desktop apps, decided to try and copy/modify from an existing plugin. It does not show up in the plugin list, and using the following:

bin/console kimai:bundle:metafieldsbreak:install bin/console cache:clear --env=prod bin/console cache:warmup --env=prod

Results in this error on the terminal: There are no commands defined in the "kimai:bundle:metafieldsbreak" namespace.

I will try to come back to this when I have more time to sit and work on it, but maybe someone with more dev experience with Kimai can make something out of that...I tried...