Keleo / kimai2-grandtotal

A plugin to import timesheet data from Kimai in GrandTotal
Other
1 stars 4 forks source link

Export "hourly_rate" instead "rate" #6

Open gises opened 3 years ago

gises commented 3 years ago

Currently, a calculated hourly rate is transferred to GrandTotal. This leads to different hourly rates being shown in the invoice. According to the database, the field "hourly_rate" should be used instead of "rate" for the entry "Cost".

Many thanks

for (var aEntry of aItems) { var aItemResult = { 'startDate': aEntry['begin'], 'client': '', 'project': '', 'minutes': Math.round(aEntry['duration'] / 60), 'notes': aEntry['description'] !== null ? aEntry['description'] : '', 'label': aEntry['tags'].join(", "), 'user': aEntry['user'], 'cost': aEntry['rate'], 'uid': 'com.kimai2.' + aEntry['id'],

kevinpapst commented 3 years ago

I don't think so. Grandtotal calculates the unit cost from cost and minutes. The Kimai import view in Grandtotal shows the correct values for "Quantity, Unit, Unitprice, Cost". Are you sure your invoice template is correct?

Bildschirmfoto 2021-02-06 um 16 36 51
gises commented 3 years ago

Hi Kevin, I quickly made two test entries for better understanding. An hourly rate of 75.25 is stored in Kimai with time entries of 15 and 30 minutes. When importing into GrandTotal, i.e. before the invoice is created, it looks like this.

image

Screenshot aus der Kimai DB image

kevinpapst commented 3 years ago

Yes, and what is the problem now? Einzelpreis = 72,25 for one complete item. Grandtotal sees that it is just half of an item (30 minutes) so it Kosten is 37,63. Looks correct to me.

gises commented 3 years ago

The hourly rate is fixed but is now displayed differently. Even if the differences are only minor, they are not accepted. If the expenses are then summed up in GrandTotal, it looks like this. This is wrong and leads to questions from the client. That is why I asked why the hourly rate stored cannot be transmitted. In addition, the rounding in Switzerland is to 5 centimes and this works in GrandTotal.

image

kevinpapst commented 3 years ago

Aha, I was concentrating on the logic, not the cents. Kimai rounds to 2 decimals, that can't be changed. I would transfer the hourly rate, but Grandtotal cannot use it AFAIK.

Talk to the Grandtotal developer please and explain the problem, maybe he allows to set the Einzelpreis instead of the costs in plugins.

gises commented 3 years ago

Hi Kevin, i talked to Stefan from GrandTotal. His answer Das müsste es fixen: 'cost': aEntry['hourly_rate'] * (aItemResult["minutes"] / 60);

Could you check this

kevinpapst commented 3 years ago

You can try it yourself. Clone the repository, change the line and then double click the directory Kimai2.grandtotalplugin. This will import the plugin into Grandtotal.

gises commented 3 years ago

Hi Kevin

Following results: If i use the fix as proposed from Stefan i got an error message.

image

Then i tried this, and i can import in GrandTotal, but still with the false Rate since i use "rate" instead" of "hourly_rate"

image

When i switch from "rate" to "hourly_rate" there is no log or import in GrandTotal. Seems that "hourly_rate" is not transferd or maybe the wrong format. Do you have any further idea? Thanks in advance!

kevinpapst commented 3 years ago

Hm, true. The hourly_rate is missing in these objects. That needs to be fixed in Kimai first. You could try to calculate the hourly_rate first (var hourlyRate = aEntry['rate'] / aEntry['duration'] * 3600) and then apply the next steps.

gises commented 3 years ago

Hi Kevin

I think this is a dead end. Even if I calculate it this way, the rounding problem remains. The only solution in my eyes would be if the "hourly_rate" can be transferred to GrandTotal as stored in Kimai. I write this again to Stefan from GrandTotal

kevinpapst commented 3 years ago

Maybe I am wrong, but I don't think that it matter if you calculate the hourly rate or if it comes from Kimai. There should be no difference for the algorithm.

       var hourlyRate = aEntry['rate'] / aEntry['duration'] * 3600
       var minutes = Math.round(aEntry['duration'] / 60);
        var aItemResult = {
            'startDate': aEntry['begin'],
            'client': '',
            'project': '',
            'minutes': minutes,
            'notes': aEntry['description'] !== null ? aEntry['description'] : '',
            'label': aEntry['tags'].join(", "),
            'user': aEntry['user'],
            'cost': hourlyRate * minutes / 60,
            'uid': 'com.kimai2.' + aEntry['id'],
        };