Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several templates, for example for invoices #104

Closed
MeisterAdebar opened this issue Feb 3, 2025 · 8 comments
Closed

Several templates, for example for invoices #104

MeisterAdebar opened this issue Feb 3, 2025 · 8 comments

Comments

@MeisterAdebar
Copy link

Hello,

Great project, I should have found it sooner. Hope the integration of the electronic invoice function will happen soon.

I'm working on the templates, installed is the current 1.3.7. I imagine being able to use one template for cash payments, one for transfers and one for payments via Booking.
No matter which template I select in the combo box on the "Invoice overview" page, the template that I chose in my first test is always applied. Selecting another template has no function.

Is it really only possible to create one template type per category or am I doing something wrong when using it?

And another question, why is the following code often, not always, added to the top of the source code after saving?

<p><audio class="audio-for-speech"></audio></p>
<div class="translate-tooltip-mtz translator-hidden">
<div class="header">
<div class="header-controls">Translator</div>
<div class="header-controls"> </div>
<div class="header-controls"> </div>
</div>
<div class="translated-text">
<div class="words"> </div>
<div class="sentences"> </div>
</div>
</div>
<p> </p>
<p><audio class="audio-for-speech"></audio></p>
<div class="translate-tooltip-mtz translator-hidden">
<div class="header">
<div class="header-controls">Translator</div>
<div class="header-controls"> </div>
<div class="header-controls"> </div>
</div>
<div class="translated-text">
<div class="words"> </div>
<div class="sentences"> </div>
</div>
</div>
<style>

Is it somehow possible to add, for example, 10 days to the placeholder invoice date?

Gruß

Thomas

@developeregrem
Copy link
Owner

Hi Thomas,
I was just testing your template issue on different environments and can not reproduce it unfortunately :(
You wrote version 1.3.7. Is that correct? Latest version is 3.7.0.
In my test I've created 2 templates with type PDF Invoice:
Image

And the correct invoice template is chosen when I click on download as PDF for an invoice.

And your second issue with the added code seem to be a mystery :D At least the code is not coming from FewohBee. Maybe some browser extension on your site is adding this automatically?

Can you explain the stuff with the invoice date in more detail, please? Do you mean that the invoice date should be "now + 10 days"?

Alex

@MeisterAdebar
Copy link
Author

MeisterAdebar commented Feb 3, 2025

You wrote version 1.3.7. Is that correct? Latest version is 3.7.0.

Yes, sry, I meant 3.7.0. On Raspberry 4, but under Bullseye (yet), not Bookworm.
No matter which browser. I tried Firefox, Chrome, Edge and Brave. Under Ubuntu, Windows and Android-Tablet.
Something is going wrong for me after there is a second template with type PDF Invoice
Now I'm coming back and want to continue testing and when I click on Export as PDF I get this back, no matter which device/browser I use to access fewohbee:

Oops! An Error Occurred
The server returned a "500 Internal Server Error".
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

I can already see that using the program will fail because of this :'(

And your second issue with the added code seem to be a mystery :D At least the code is not coming from FewohBee. Maybe some browser extension on your site is adding this automatically?

I haven't bothered with it that much yet (but it's been a few hours just for the templates), but I'm not looking for the reason why the code is added above my source code after saving. You can remove the added code and at some point when saving, no more code will be added. I suspect that it's due to Firefox (under Ubuntu), so I'll have to look into it further.

Can you explain the stuff with the invoice date in more detail, please? Do you mean that the invoice date should be "now + 10 days"?

Yes, I always specify the payment deadline like this, where February 12, 2025 should be something like [[invoice.date|date('d.m.Y')]+10]:

Wir erwarten Ihren Zahlungseingang bis zum 12.02.2025.

@developeregrem
Copy link
Owner

Hi Thomas,
weird -.-
Maybe you have something in your template that breaks syntax. Are you using the dockerized version? Then have a look into the log after the error occurs. You can see the output with this command:
docker compose logs php

In order to achieve your +x days requirement you can write the following (Twig-Syntax):
[[invoice.date|date_modify('+10 days')|date('d.m.Y')]]

@MeisterAdebar
Copy link
Author

Hi,

Are you using the dockerized version?
Yes

Look.
I deleted all the templates.
Then restarted the container:

pi@fhempi:/opt/fewohbee-dockerized $ sudo docker compose stop
[+] Stopping 5/5
✔ Container fewohbee-dockerized-php-1 Stopped 2.0s
✔ Container fewohbee-dockerized-redis-1 Stopped 2.1s
✔ Container fewohbee-dockerized-acme-1 Stopped 10.7s
✔ Container fewohbee-dockerized-web-1 Stopped 2.1s
✔ Container fewohbee-dockerized-db-1 Stopped 2.2s
pi@fhempi:/opt/fewohbee-dockerized $ sudo docker compose up -d
[+] Running 5/5
✔ Container fewohbee-dockerized-web-1 Started 1.5s
✔ Container fewohbee-dockerized-php-1 Started 1.2s
✔ Container fewohbee-dockerized-db-1 Started 1.3s
✔ Container fewohbee-dockerized-redis-1 Started 1.3s
✔ Container fewohbee-dockerized-acme-1 Started 1.3s
pi@fhempi:/opt/fewohbee-dockerized $

Only the invoice example https://raw.githubusercontent.com/developeregrem/fewohbee-examples/refs/heads/master/templates/rechnung-default.txt copied into the source code editor.

The first three lines are always removed, no matter which template I want to create:

<!DOCTYPE html>
<html>
<head>

Sometimes, but not always, the code mentioned in the first post is added for each save (I still believe it is due to Firefox):

<p><audio class="audio-for-speech"></audio></p>
<div class="translate-tooltip-mtz translator-hidden">
<div class="header">
<div class="header-controls">Translator</div>
<div class="header-controls"> </div>
<div class="header-controls"> </div>
</div>
<div class="translated-text">
<div class="words"> </div>
<div class="sentences"> </div>
</div>
</div>
<p> </p>

Then it looks like this:

<style>
table {
  border-spacing: 0;
  border-collapse: collapse; 
}
table th,td {
  padding-right: 5px;
  padding-left: 5px;
}
</style>
<p style="text-align: center;"><span style="font-size: 18pt; font-family: arial, helvetica, sans-serif;"><strong>Unterkunft zum sonnigen Gemüt</strong></span></p>
<p style="text-align: right;"><span style="font-family: arial, helvetica, sans-serif;"><span style="font-size: 10pt;">Inhaber: Max Mustermann<br></span><span style="font-size: 10pt;">Musterstraße 12, </span><span style="font-size: 10pt;">12345 Musterhause</span></span><br><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;">Telefon: 123456 789, Mobil: 987654321</span></p>
<p><span style="font-size: 16pt; font-family: arial, helvetica, sans-serif;"><strong>Rechnung</strong></span></p>
<p><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><span class="mceNonEditable">[[invoice.firstname]]</span> <span class="mceNonEditable">[[invoice.lastname]]</span><br><span class="mceNonEditable">[[invoice.company]]</span><br><span class="mceNonEditable">[[invoice.address]]</span><br><span class="mceNonEditable">[[invoice.zip]]</span> <span class="mceNonEditable">[[invoice.city]]</span><br></span></p>
<p style="text-align: right;"><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><strong>Rechnungsnr.</strong><br><span class="mceNonEditable">[[invoice.number]]</span><br><strong>Rechnungsdatum</strong><br><span class="mceNonEditable">[[invoice.date|date('d.m.Y')]]</span><br></span></p>
<p style="text-align: left;"> </p>
<table style="width: 100%;">
<thead>
<tr style="background-color: #ced4d9;">
<th style="border-bottom: 1px solid #333333; text-align: left;" scope="col"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Zimmer</span></th>
<th style="border-bottom: 1px solid #333333; text-align: center;" scope="col"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Anzahl</span></th>
<th style="text-align: right; border-bottom: 1px solid #333333;" scope="col"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Einzelpreis</span></th>
<th style="text-align: right; border-bottom: 1px solid #333333;" scope="col"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">MwSt.</span></th>
<th style="text-align: right; border-bottom: 1px solid #333333;" scope="col"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Gesamt</span></th>
</tr>
</thead>
<tbody><!-- [% for appartment in invoice.appartments %] -->
<tr>
<td style="border-bottom: 1px solid #DDDDDD;"><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><span class="mceNonEditable">[[appartment.description]]</span> (Personen: <span class="mceNonEditable">[[appartment.persons]]</span>)</span><br><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><span class="mceNonEditable">[[appartment.startDate|date('d.m.Y')]]</span> - <span class="mceNonEditable">[[appartment.endDate|date('d.m.Y')]]</span></span></td>
<td style="text-align: center; border-bottom: 1px solid #DDDDDD;"><span class="mceNonEditable" style="font-size: 10pt; font-family: arial, helvetica, sans-serif;">[[appartment.amount]]</span></td>
<td style="text-align: right; border-bottom: 1px solid #DDDDDD;"><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><span class="mceNonEditable">[[appartment.priceFormated]]</span> €</span></td>
<td style="text-align: right; border-bottom: 1px solid #DDDDDD;"><span class="mceNonEditable" style="font-size: 10pt; font-family: arial, helvetica, sans-serif;">[[appartment.vat]]</span></td>
<td style="text-align: right; border-bottom: 1px solid #DDDDDD;"><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><span class="mceNonEditable">[[appartment.totalPrice]]</span> €</span></td>
</tr>
<!-- [% endfor %] -->
<tr>
<td style="text-align: right;" colspan="5"><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><span class="mceNonEditable"><strong>[[appartmentTotal]]</strong></span><strong> €</strong></span></td>
</tr>
</tbody>
</table>
<p style="text-align: left;"> </p>
<table style="width: 100%;">
<thead>
<tr style="background-color: #ced4d9;">
<th style="border-bottom: 1px solid #333333; text-align: left;" scope="col"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">weitere Leistungen</span></th>
<th style="border-bottom: 1px solid #333333; text-align: center;" scope="col"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Anzahl</span></th>
<th style="text-align: right; border-bottom: 1px solid #333333;" scope="col"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Einzelpreis</span></th>
<th style="text-align: right; #dddddd; border-bottom: 1px solid #333333;" scope="col"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">MwSt.</span></th>
<th style="text-align: right; border-bottom: 1px solid #333333;" scope="col"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Gesamt</span></th>
</tr>
</thead>
<tbody><!-- [% for position in invoice.positions %] -->
<tr style="border-bottom: 1px solid #DDDDDD;">
<td style="border-bottom: 1px solid #DDDDDD;"><span class="mceNonEditable" style="font-size: 10pt; font-family: arial, helvetica, sans-serif;">[[position.description]]</span></td>
<td style="border-bottom: 1px solid #dddddd; text-align: center;"><span class="mceNonEditable" style="font-size: 10pt; font-family: arial, helvetica, sans-serif;">[[position.amount]]</span></td>
<td style="text-align: right; border-bottom: 1px solid #DDDDDD;"><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><span class="mceNonEditable">[[position.priceFormated]]</span> €</span></td>
<td style="text-align: right; border-bottom: 1px solid #DDDDDD;"><span class="mceNonEditable" style="font-size: 10pt; font-family: arial, helvetica, sans-serif;">[[position.vat]]</span></td>
<td style="text-align: right; border-bottom: 1px solid #DDDDDD;"><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><span class="mceNonEditable">[[position.totalPrice]]</span> €</span></td>
</tr>
<!-- [% endfor %] -->
<tr>
<td style="text-align: right;" colspan="5"><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><span class="mceNonEditable"><strong>[[miscTotal]]</strong></span><strong> €</strong></span></td>
</tr>
</tbody>
</table>
<p> </p>
<table style="width: 100%;" border="0">
<tbody>
<tr>
<td style="width: 33.3333%;"><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;">enthaltene Mehrwertsteuer</span><br>
<table border="0"><!-- [% for key, value in vats %] -->
<tbody>
<tr>
<td style="text-align: right;"><span class="mceNonEditable" style="font-size: 10pt; font-family: arial, helvetica, sans-serif;">[[key]] %:</span></td>
<td style="text-align: right;"><span class="mceNonEditable" style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"> [[value.nettoFormated]] €</span></td>
</tr>
<!-- [% endfor %] --></tbody>
</table>
<span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><br></span></td>
<td style="width: 47.7411%; text-align: right; vertical-align: top;"><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;">Netto</span><br><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><strong>Brutto</strong></span></td>
<td style="width: 18.9255%; text-align: right; vertical-align: top;"><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><span class="mceNonEditable">[[nettoFormated]] </span>€</span><br><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><strong><span class="mceNonEditable">[[bruttoFormated]] </span>€</strong></span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Das Datum der Rechnung entspricht dem Leistungsdatum.</span></p>
<p><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;">Zahlbar nach Erhalt der Rechnung.</span></p>
<p> </p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong>Bemerkungen</strong></span></p>
<p><span style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><span class="mceNonEditable">[[invoice.remark]]</span></span></p>
<div class="footer">
<p style="text-align: center;"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Wie hoffen, Sie hatten einen angenehmen Aufenthalt. Bitte denken Sie gerne an die Tage in unserem Haus zurück. Auf Wiedersehen!<br><br></span></p>
<table style="border-collapse: collapse; width: 100%;" border="0">
<tbody>
<tr>
<td style="width: 49.6849%; vertical-align: top;"><span style="font-size: 8pt; font-family: arial, helvetica, sans-serif; color: #7e8c8d;">Bankverbindung:</span><br><span style="font-size: 8pt; font-family: arial, helvetica, sans-serif; color: #7e8c8d;">Bank AG</span><br><span style="font-size: 8pt; font-family: arial, helvetica, sans-serif; color: #7e8c8d;">IBAN: DE12 3456 7890 1234 5678 90</span><br><span style="font-size: 8pt; font-family: arial, helvetica, sans-serif; color: #7e8c8d;">BIC: XXXXXXXXX </span></td>
<td style="width: 49.6849%; text-align: right; vertical-align: top;"><span style="font-family: arial, helvetica, sans-serif; font-size: 8pt; color: #7e8c8d;">Steuernummer: 123/456/78901</span><br><br><span style="font-family: arial, helvetica, sans-serif; font-size: 8pt; color: #7e8c8d;">eMail: [email protected]</span><br><span style="font-family: arial, helvetica, sans-serif; font-size: 8pt; color: #7e8c8d;">www.meinhotel.tld</span></td>
</tr>
</tbody>
</table>
</div>

The message also comes:
Oops! An Error Occurred...

The log then says when you "Als PDF exportieren":

php-1  | 172.18.0.2 -  04/Feb/2025:12:25:49 +0100 "GET /index.php" 500
php-1  | 172.18.0.2 -  04/Feb/2025:12:26:15 +0100 "GET /index.php" 200
php-1  | 172.18.0.2 -  04/Feb/2025:12:26:17 +0100 "GET /index.php" 200
php-1  | 172.18.0.2 -  04/Feb/2025:12:28:28 +0100 "POST /index.php" 200
php-1  | 172.18.0.2 -  04/Feb/2025:12:28:28 +0100 "GET /index.php" 200
php-1  | 172.18.0.2 -  04/Feb/2025:12:28:31 +0100 "GET /index.php" 200
php-1  | 172.18.0.2 -  04/Feb/2025:12:28:34 +0100 "GET /index.php" 200
php-1  | {"message":"Matched route \"invoices.export.pdf\".","context":{"route":"invoices.export.pdf","route_parameters":{"_route":"invoices.export.pdf","_controller":"App\\Controller\\InvoiceServiceController::exportToPdfAction","id":"10","templateId":"1"},"request_uri":"https://fhempi/invoices/export/pdf/10/1","method":"GET"},"level":200,"level_name":"INFO","channel":"request","datetime":"2025-02-04T12:28:39.841333+01:00","extra":{}}
php-1  | {"message":"Checking for authenticator support.","context":{"firewall_name":"main","authenticators":2},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2025-02-04T12:28:39.845630+01:00","extra":{}}
php-1  | {"message":"Checking support on authenticator.","context":{"firewall_name":"main","authenticator":"Symfony\\Component\\Security\\Http\\Authenticator\\FormLoginAuthenticator"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2025-02-04T12:28:39.845682+01:00","extra":{}}
php-1  | {"message":"Authenticator does not support the request.","context":{"firewall_name":"main","authenticator":"Symfony\\Component\\Security\\Http\\Authenticator\\FormLoginAuthenticator"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2025-02-04T12:28:39.845717+01:00","extra":{}}
php-1  | {"message":"Checking support on authenticator.","context":{"firewall_name":"main","authenticator":"Symfony\\Component\\Security\\Http\\Authenticator\\RememberMeAuthenticator"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2025-02-04T12:28:39.845739+01:00","extra":{}}
php-1  | {"message":"Authenticator does not support the request.","context":{"firewall_name":"main","authenticator":"Symfony\\Component\\Security\\Http\\Authenticator\\RememberMeAuthenticator"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2025-02-04T12:28:39.845819+01:00","extra":{}}
php-1  | {"message":"Read existing security token from the session.","context":{"key":"_security_main","token_class":"Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2025-02-04T12:28:39.851223+01:00","extra":{}}
php-1  | {"message":"User was reloaded from a user provider.","context":{"provider":"Symfony\\Bridge\\Doctrine\\Security\\User\\EntityUserProvider","username":"TomLee"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2025-02-04T12:28:39.871015+01:00","extra":{}}
php-1  | {"message":"Uncaught PHP Exception Error: \"Call to a member function getTemplateType() on null\" at TemplatesService.php line 116","context":{"exception":{"class":"Error","message":"Call to a member function getTemplateType() on null","code":0,"file":"/var/www/html/fewohbee/src/Service/TemplatesService.php:116"}},"level":500,"level_name":"CRITICAL","channel":"request","datetime":"2025-02-04T12:28:39.883867+01:00","extra":{}}
php-1  | {"message":"Stored the security token in the session.","context":{"key":"_security_main"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2025-02-04T12:28:39.908401+01:00","extra":{}}
php-1  | 172.18.0.2 -  04/Feb/2025:12:28:39 +0100 "GET /index.php" 500

In order to achieve your +x days requirement you can write the following (Twig-Syntax):
[[invoice.date|date_modify('+10 days')|date('d.m.Y')]]

Thanks, I just can't test it anymore because it's just Oops! An Error Occurred... occurs when exporting.

@developeregrem
Copy link
Owner

Ok, very strange. It seems that the template-ID you choose is not set correctly when clicking on download.
Please go the the Invoice page. Open the developer console of your browser, reload the page, select a template from the dropdown and look whether there are any JavaScript errors in the "console". It seems that the JS function that applies the new template to the download buttons is not working properly in your browser.

Furthermore, you can check whether it is possible to download an invoice manually.
For this you need to get the template-ID of the template you want to use. For this, look into the pages source code like this and remember the ID:

Image

Next, right click on any download icon of an invoice and select "copy link address"

Use this link and open it in a new tab and change the last number in the link, which represent the template-ID. E.g.:
https://fewohbee/invoices/export/pdf/10/7

If this is still not working, I recommend cleaning everything and perform a fresh installation. You can clean it with the script
cleanup.sh
rm .env
install.sh

@MeisterAdebar
Copy link
Author

Nix passiert in der Konsole, wenn ich auf der Rechnungsübersicht-Seite ein Template wähle.
Die ganze Zeit rufe ich Als PDF exportieren über die Seite auf, zu der man über den Infobutton Details Anzeigen kommt, jetzt klick ich mal den Button zum Download direkt in der Übersichts-Seite und das klappt plötzlich. Auch auf der Detailseite klappt der Download plötzlich wieder, kein OOPS... mehr. Ich kann es mir nicht erklären.

Aber, was ich jetzt feststelle: Die Template-ID des Link zum direkten Download auf der Rechnungsübersicht-Seite ändert sich mit Auswahl eines Templates, je nach Auswahl wird das richtige Template angewendet, das ist schonmal ein Erfolg.
Die Template-ID des Download-Link auf der Detail-Seite oder der Bearbeiten-Seite (so wie ich es die ganze Zeit versuche) ist statisch, die ändert sich nicht mit Auswahl eines anderen Templates. Ist das denn bei Dir nicht so?

In order to achieve your +x days requirement you can write the following (Twig-Syntax):
[[invoice.date|date_modify('+10 days')|date('d.m.Y')]]

Cool, vielen dank.

@MeisterAdebar
Copy link
Author

Moin,

Weitere Feststellung. Hat man keine Standard-Vorlage gewählt, ist die Template-ID default 1. Gibt es kein Template mit der 1, kommt die OOPS-Meldung.
Wählt man auf der Rechnungsübersicht-Seite ein Template, wird die ID nur für den Download-Button auf der Seite übernommen, nicht aber auf der Detail.-und Bearbeiten-Seite.

Gruß

Thomas

@developeregrem
Copy link
Owner

Hi Thomas,

you are right, I forgot that there is another place to download an invoice :D I always use the icon in the overview page.
On the page you describe the behaviour works as designed. Here the template is used which you mark as default template. Maybe not the best solution. I will add this to the backlog and will change the behaviour in the future.
Sorry for the confusion -.-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants