Feature request: custom template engine

Discussions about iCompta on macOS
Post Reply
iaanus
Posts: 3
Joined: 05 October 2014, 12:14

Feature request: custom template engine

Post by iaanus »

Hello,

first of all thanks a lot for the very good app! I used earlier versions of iCompta for my personal accounts and recently I decided to use it also for my business. I was very happy to hear about the possibility to print invoices. Unfortunately, the Italian legislation is quite complex and just writing the amount (with and without taxes) is not enough. I understand that I can't expect iCompta to support all the Italian subtleties, but I believe it actually doesn't need to, because the necessary computations could easily be computed externally by the template engine. The point is that the MGTemplateEngine is not powerful enough for that, being simply a framework for string substitutions and little more. I initially thought the problem could be approached by extending MGTemplateEngine with just a couple custom "filters" (implementing addition and multiplication), but the fact that you can't neither concatenate filters nor assign the result of an expression to a variable is very limiting.

What I would like to request, is to allow the user to provide its own custom template engine. In practice, when asked to print an invoice, iCompta could invoke a user-provided command line, passing it the invoice data (for example passing the data in json or some other notation on stdin) and then interpret the script output as the html to be printed. With such a feature, anyone could write a script (for example in python) to accommodate for any complex computation or layout, with no additional effort on iCompta. What do you think? Would that be possible? I understand that this feature would be used only by script-savvy pro users, but it seems very easy to implement, so it might still be worth the effort.
User avatar
Angeman
Administrateur
Posts: 2366
Joined: 28 December 2008, 21:28
Location: Toulouse, France
Contact:

Re: Feature request: custom template engine

Post by Angeman »

Thanks for your idea, I'll think about it. Can you tell me which variables (and how to calculate them) you are missing ? Because I'd like to know how it works in Italy.
iaanus
Posts: 3
Joined: 05 October 2014, 12:14

Re: Feature request: custom template engine

Post by iaanus »

Thanks for considering this. Since you can very easily write a MGTemplateEngine template to produce a text file in json or csv format, another possible approach could be to allow the external tool to post-process the MGTemplateEngine output. Or you could even invoke the custom tool instead of printing, as the custom tool could directly print the invoice as well as perform some other automatable tasks like producing a pdf for archival purposes and/or sending it by email.

As for your question about Italian invoices, please bear in mind that the actual computations may differ according to the kind of business. For example, I believe that what iCompta provides is ok for a company that sells goods. For freelance individuals that "sell" work (as I am) things are a bit more complex. This is a typical invoice of mine:

Wage: € 100,00
Rivalsa INPS (for social security): € 4,00 (4% of € 100,00)
Total ET: € 104,00

VAT 22%: € 22,88 (22% of € 104,00)
Total incl. VAT: € 126,88

Withholding tax: € 20,80 (20% of € 104,00)
Invoice total: € 106,08

I will be paid € 106,08 from my client and I will have to pay taxes of € 22,88 for VAT on the next month. The client will also have to pay the withholding tax of € 20,80, eventually. The percentages of 4% and 20% are fixed (as long as the legislation doesn't change...).

Hope it helps.
iaanus
Posts: 3
Joined: 05 October 2014, 12:14

Re: Feature request: custom template engine

Post by iaanus »

If invoking a custom engine proves too problematic, I have an even easier approach: just add an option to allow saving to a file the output of the MGTemplateEngine as-is.

Currently you can either print (which also allows to save a PDF version) or send by email a PDF version. However, the conversion between HTML and PDF loses information. If I had access to the unconverted HTML file, it could be easy for me to apply further processing. Think about it, I could even embed the additional processing as javascript right in the HTML file, so I could just open the HTML file in a Safari and print it from there!

By the way, when converting HTML to PDF, iCompta doesn't respect a lot of CSS formatting, in particular with absolute positioning and page layout, making it quite hard to make nice-looking invoices. Printing via Safari could easily address the problem.
User avatar
Angeman
Administrateur
Posts: 2366
Joined: 28 December 2008, 21:28
Location: Toulouse, France
Contact:

Re: Feature request: custom template engine

Post by Angeman »

Great idea, I will include this in version 5.1.5.
Post Reply