kimai / DemoBundle

Kimai Demo bundle for developers, who want to create a plugin and extend the time-tracking experience
MIT License
16 stars 11 forks source link

Question on Invoice without Templates #1

Open labor4 opened 4 years ago

labor4 commented 4 years ago

Hi Kevin Thanks for this extensive hero demo of a plugin. I was able to achieve some things with it, and learn how to survive better, in general... Still, Symfony is a long way to go.

I'm now trying to re-implement my old Indesign XML Exporter from V1.

But at this stage I think I need to ask directly, since I seem to hit a solid wall, and from the past hours of trial'n'error it seems wise:

I extended the plugin with an exporter, that I think will serve as a minimum to get Indesign XML out in the end. However I also tried the "Invoice" route, since it allows userland'ish restrictions.

I'm not sure if there is a benefit in a template for this kind of playout, but maybe I'm wrong.

Best wishes Manu

kevinpapst commented 4 years ago

Yes, all public invoice renderer are template based, but you don't have to use a template when creating the actual invoice. You can do whatever you want in your invoice renderer.

The template is just the way to tell Kimai that it should use your renderer. Create an empty file indesign.xml and then implement a renderer:

public function supports(InvoiceDocument $document): bool
{
     return $document->getFilename() === 'indesign.xml';
}
public function render(InvoiceDocument $document, InvoiceModel $model): Response
{
    // do whatever you want, simply ignore the $document... you could even
    // send the invoice data to a web service and let them create the invoice
    // the only "limitation" is: you have to return some kind of response
    $response =  new Response();
     // ....
    return $response;
}

Is final class ServiceInvoice the place where templates-are-mandatory is hardcoded? Or where would be the place to build a hook on?

I don't think that I understand this question.

labor4 commented 4 years ago

I see thanks. So Kimai seeing the possibility of using a template makes Kimai include it in the choice list, even though that template is empty. There's the hook!

Is final class ServiceInvoice the place where templates-are-mandatory is hardcoded? Or where would be the place to build a hook on?

I don't think that I understand this question.

I saw that I cannot change the template behaviour without going into Kimai code (and didn't know I can trick it like you say), so I thought there is no way to build on the existing methods.

I'll go on. Thanks

labor4 commented 4 years ago

Thanks for the note on the webhook. Extremely powerful indeed.