2023-02-24 11:22:15 +00:00
|
|
|
{{ define "title" -}}
|
|
|
|
{{ .Number | printf ( pgettext "Invoice %s" "title" )}}
|
|
|
|
{{- end }}
|
|
|
|
|
2023-03-20 12:09:52 +00:00
|
|
|
{{ define "breadcrumbs" -}}
|
2023-02-24 11:22:15 +00:00
|
|
|
{{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.invoice*/ -}}
|
|
|
|
<nav>
|
2023-04-02 14:10:13 +00:00
|
|
|
<p data-hx-target="main" data-hx-boost="true">
|
2023-02-24 11:22:15 +00:00
|
|
|
<a href="{{ companyURI "/" }}">{{( pgettext "Home" "title" )}}</a> /
|
|
|
|
<a href="{{ companyURI "/invoices"}}">{{( pgettext "Invoices" "title" )}}</a> /
|
|
|
|
<a>{{ .Number }}</a>
|
|
|
|
</p>
|
Convert invoices to PDF with WeasyPrint
Although it is possible to just print the invoice from the browser, many
people will not even try an assume that they can not create a PDF for
the invoice.
I thought of using Groff or TeX to create the PDF, but it would mean
maintaining two templates in two different systems (HTML and whatever i
would use), and would probably look very different, because i do not
know Groff or TeX that well.
I wish there was a way to tell the browser to print to PDF, and it can
be done, but only with the Chrome Protocol to a server-side running
Chrome instance. This works, but i would need a Chrome running as a
daemon.
I also wrote a Qt application that uses QWebEngine to print the PDF,
much like wkhtmltopdf, but with support for more recent HTML and CSS
standards. Unfortunately, Qt 6.4’s embedded Chromium does not follow
break-page-inside as well as WeasyPrint does.
To use WeasyPrint, at first i wanted to reach the same URL as the user,
passing the cookie to WeasyPrint so that i can access the same invoice
as the user, something that can be done with wkhtmltopdf, but WeasyPrint
does not have such option. I did it with a custom Python script, but
then i need to package and install that script, that is not that much
work, but using the Debian-provided script is even less work, and less
likely to drift when WeasyPrint changes API.
Also, it is unnecessary to do a network round-trip from Go to Python
back to Go, because i can already write the invoice HTML as is to
WeasyPrint’s stdin.
2023-02-26 16:26:09 +00:00
|
|
|
<p>
|
2023-03-13 14:00:35 +00:00
|
|
|
<a class="button primary"
|
2023-04-25 13:28:55 +00:00
|
|
|
data-hx-target="main" data-hx-boost="true"
|
|
|
|
href="{{ companyURI "/invoices/new"}}?duplicate={{ .Slug }}">{{( pgettext "Duplicate" "action" )}}</a>
|
2023-04-02 14:10:13 +00:00
|
|
|
<a class="button primary"
|
2023-04-25 13:28:55 +00:00
|
|
|
data-hx-target="main" data-hx-boost="true"
|
|
|
|
href="{{ companyURI "/invoices/"}}{{ .Slug }}/edit">{{( pgettext "Edit" "action" )}}</a>
|
Convert invoices to PDF with WeasyPrint
Although it is possible to just print the invoice from the browser, many
people will not even try an assume that they can not create a PDF for
the invoice.
I thought of using Groff or TeX to create the PDF, but it would mean
maintaining two templates in two different systems (HTML and whatever i
would use), and would probably look very different, because i do not
know Groff or TeX that well.
I wish there was a way to tell the browser to print to PDF, and it can
be done, but only with the Chrome Protocol to a server-side running
Chrome instance. This works, but i would need a Chrome running as a
daemon.
I also wrote a Qt application that uses QWebEngine to print the PDF,
much like wkhtmltopdf, but with support for more recent HTML and CSS
standards. Unfortunately, Qt 6.4’s embedded Chromium does not follow
break-page-inside as well as WeasyPrint does.
To use WeasyPrint, at first i wanted to reach the same URL as the user,
passing the cookie to WeasyPrint so that i can access the same invoice
as the user, something that can be done with wkhtmltopdf, but WeasyPrint
does not have such option. I did it with a custom Python script, but
then i need to package and install that script, that is not that much
work, but using the Debian-provided script is even less work, and less
likely to drift when WeasyPrint changes API.
Also, it is unnecessary to do a network round-trip from Go to Python
back to Go, because i can already write the invoice HTML as is to
WeasyPrint’s stdin.
2023-02-26 16:26:09 +00:00
|
|
|
<a class="primary button"
|
|
|
|
href="{{ companyURI "/invoices/" }}{{ .Slug }}.pdf"
|
2023-07-07 09:32:59 +00:00
|
|
|
download="{{ .Number}}-{{ .Invoicee.Name | slugify }}.pdf">{{( pgettext "Download invoice" "action" )}}</a>
|
Convert invoices to PDF with WeasyPrint
Although it is possible to just print the invoice from the browser, many
people will not even try an assume that they can not create a PDF for
the invoice.
I thought of using Groff or TeX to create the PDF, but it would mean
maintaining two templates in two different systems (HTML and whatever i
would use), and would probably look very different, because i do not
know Groff or TeX that well.
I wish there was a way to tell the browser to print to PDF, and it can
be done, but only with the Chrome Protocol to a server-side running
Chrome instance. This works, but i would need a Chrome running as a
daemon.
I also wrote a Qt application that uses QWebEngine to print the PDF,
much like wkhtmltopdf, but with support for more recent HTML and CSS
standards. Unfortunately, Qt 6.4’s embedded Chromium does not follow
break-page-inside as well as WeasyPrint does.
To use WeasyPrint, at first i wanted to reach the same URL as the user,
passing the cookie to WeasyPrint so that i can access the same invoice
as the user, something that can be done with wkhtmltopdf, but WeasyPrint
does not have such option. I did it with a custom Python script, but
then i need to package and install that script, that is not that much
work, but using the Debian-provided script is even less work, and less
likely to drift when WeasyPrint changes API.
Also, it is unnecessary to do a network round-trip from Go to Python
back to Go, because i can already write the invoice HTML as is to
WeasyPrint’s stdin.
2023-02-26 16:26:09 +00:00
|
|
|
</p>
|
2023-02-24 11:22:15 +00:00
|
|
|
</nav>
|
2023-03-20 12:09:52 +00:00
|
|
|
{{- end }}
|
Convert invoices to PDF with WeasyPrint
Although it is possible to just print the invoice from the browser, many
people will not even try an assume that they can not create a PDF for
the invoice.
I thought of using Groff or TeX to create the PDF, but it would mean
maintaining two templates in two different systems (HTML and whatever i
would use), and would probably look very different, because i do not
know Groff or TeX that well.
I wish there was a way to tell the browser to print to PDF, and it can
be done, but only with the Chrome Protocol to a server-side running
Chrome instance. This works, but i would need a Chrome running as a
daemon.
I also wrote a Qt application that uses QWebEngine to print the PDF,
much like wkhtmltopdf, but with support for more recent HTML and CSS
standards. Unfortunately, Qt 6.4’s embedded Chromium does not follow
break-page-inside as well as WeasyPrint does.
To use WeasyPrint, at first i wanted to reach the same URL as the user,
passing the cookie to WeasyPrint so that i can access the same invoice
as the user, something that can be done with wkhtmltopdf, but WeasyPrint
does not have such option. I did it with a custom Python script, but
then i need to package and install that script, that is not that much
work, but using the Debian-provided script is even less work, and less
likely to drift when WeasyPrint changes API.
Also, it is unnecessary to do a network round-trip from Go to Python
back to Go, because i can already write the invoice HTML as is to
WeasyPrint’s stdin.
2023-02-26 16:26:09 +00:00
|
|
|
|
2023-03-20 12:09:52 +00:00
|
|
|
{{ define "content" }}
|
|
|
|
{{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.invoice*/ -}}
|
2023-02-24 11:22:15 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="/static/invoice.css">
|
|
|
|
<article class="invoice">
|
|
|
|
<header>
|
2023-02-25 12:48:57 +00:00
|
|
|
<div>
|
|
|
|
<h1>{{ .Number | printf ( pgettext "Invoice %s" "title" )}}</h1>
|
|
|
|
<p class="date">{{( pgettext "Date" "title" )}} {{ .Date | formatDate }}</p>
|
|
|
|
</div>
|
2023-02-24 11:22:15 +00:00
|
|
|
|
|
|
|
<address class="invoicer">
|
|
|
|
{{ .Invoicer.Name }}<br>
|
|
|
|
{{ .Invoicer.VATIN }}<br>
|
|
|
|
{{ .Invoicer.Address }}<br>
|
|
|
|
{{ .Invoicer.City }} ({{ .Invoicer.PostalCode}}), {{ .Invoicer.Province }}<br>
|
|
|
|
{{ .Invoicer.Email }}<br>
|
|
|
|
{{ .Invoicer.Phone }}<br>
|
|
|
|
</address>
|
2023-02-25 02:16:20 +00:00
|
|
|
|
2023-03-02 09:24:44 +00:00
|
|
|
<p class="legal">{{ .LegalDisclaimer }}</p>
|
2023-02-24 11:22:15 +00:00
|
|
|
</header>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<address class="invoicee">
|
|
|
|
{{ .Invoicee.Name }}<br>
|
|
|
|
{{ .Invoicee.VATIN }}<br>
|
|
|
|
{{ .Invoicee.Address }}<br>
|
|
|
|
{{ .Invoicee.City }} ({{ .Invoicee.PostalCode}}), {{ .Invoicee.Province }}<br>
|
|
|
|
</address>
|
|
|
|
|
2023-03-01 13:08:12 +00:00
|
|
|
{{- $columns := 5 | add (len .TaxClasses) | add (boolToInt .HasDiscounts) -}}
|
2023-02-24 11:22:15 +00:00
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>{{( pgettext "Concept" "title" )}}</th>
|
|
|
|
<th class="numeric">{{( pgettext "Price" "title" )}}</th>
|
2023-03-01 13:08:12 +00:00
|
|
|
{{ if .HasDiscounts -}}
|
|
|
|
<th class="numeric">{{( pgettext "Discount" "title" )}}</th>
|
|
|
|
{{ end -}}
|
2023-02-24 11:22:15 +00:00
|
|
|
<th class="numeric">{{( pgettext "Units" "title" )}}</th>
|
|
|
|
<th class="numeric">{{( pgettext "Subtotal" "title" )}}</th>
|
2023-03-01 13:08:12 +00:00
|
|
|
{{ range $class := .TaxClasses -}}
|
|
|
|
<th class="numeric">{{ . }}</th>
|
|
|
|
{{ end -}}
|
|
|
|
<th class="numeric">{{( pgettext "Total" "title" )}}</th>
|
2023-02-24 11:22:15 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
2023-02-25 02:16:20 +00:00
|
|
|
{{ $lastIndex := len .Products | sub 1 }}
|
|
|
|
{{ range $index, $product := .Products -}}
|
|
|
|
<tbody>
|
2023-03-01 13:08:12 +00:00
|
|
|
{{- if .Description }}
|
2023-02-24 11:22:15 +00:00
|
|
|
<tr class="name">
|
2023-03-01 13:08:12 +00:00
|
|
|
<td colspan="{{ $columns }}">{{ .Name }}</td>
|
2023-02-24 11:22:15 +00:00
|
|
|
</tr>
|
2023-03-01 13:08:12 +00:00
|
|
|
{{ end -}}
|
|
|
|
<tr>
|
|
|
|
{{- if .Description }}
|
2023-02-24 11:22:15 +00:00
|
|
|
<td>{{ .Description }}</td>
|
2023-03-01 13:08:12 +00:00
|
|
|
{{- else }}
|
2023-02-24 11:22:15 +00:00
|
|
|
<td>{{ .Name }}</td>
|
2023-03-01 13:08:12 +00:00
|
|
|
{{- end -}}
|
|
|
|
<td class="numeric">{{ .Price | formatPrice }}</td>
|
|
|
|
{{ if $.HasDiscounts -}}
|
|
|
|
<td class="numeric">{{ $product.Discount | formatPercent }}</td>
|
|
|
|
{{ end -}}
|
|
|
|
<td class="numeric">{{ .Quantity }}</td>
|
|
|
|
<td class="numeric">{{ .Subtotal | formatPrice }}</td>
|
|
|
|
{{ range $class := $.TaxClasses -}}
|
|
|
|
<td class="numeric">{{ index $product.Taxes $class | formatPercent }}</td>
|
|
|
|
{{ end -}}
|
|
|
|
<td class="numeric">{{ .Total | formatPrice }}</td>
|
|
|
|
</tr>
|
2023-02-25 02:16:20 +00:00
|
|
|
{{ if (eq $index $lastIndex) }}
|
2023-03-01 13:08:12 +00:00
|
|
|
<tr class="tfoot separator">
|
|
|
|
<th scope="row" colspan="{{ $columns | sub 1 }}">{{( pgettext "Tax Base" "title" )}}</th>
|
2023-02-25 02:16:20 +00:00
|
|
|
<td class="numeric">{{ $.Subtotal | formatPrice }}</td>
|
|
|
|
</tr>
|
|
|
|
{{ range $tax := $.Taxes -}}
|
|
|
|
<tr class="tfoot">
|
2023-03-01 13:08:12 +00:00
|
|
|
<th scope="row" colspan="{{ $columns | sub 1 }}">{{ index . 0 }}</th>
|
2023-02-25 02:16:20 +00:00
|
|
|
<td class="numeric">{{ index . 1 | formatPrice }}</td>
|
|
|
|
</tr>
|
|
|
|
{{- end }}
|
|
|
|
<tr class="tfoot">
|
2023-03-01 13:08:12 +00:00
|
|
|
<th scope="row" colspan="{{ $columns | sub 1 }}">{{( pgettext "Total" "title" )}}</th>
|
2023-02-25 02:16:20 +00:00
|
|
|
<td class="numeric">{{ $.Total | formatPrice }}</td>
|
|
|
|
</tr>
|
|
|
|
{{ end }}
|
|
|
|
</tbody>
|
2023-02-24 11:22:15 +00:00
|
|
|
{{- end }}
|
|
|
|
</table>
|
|
|
|
|
2023-02-25 02:16:20 +00:00
|
|
|
{{ if .Notes -}}
|
|
|
|
<p class="notes">{{ .Notes }}</p>
|
|
|
|
{{- end }}
|
2023-03-05 17:50:57 +00:00
|
|
|
<p class="payment-instructions">{{ .PaymentInstructions }}</p>
|
2023-02-24 11:22:15 +00:00
|
|
|
|
|
|
|
</div>
|
|
|
|
</article>
|
|
|
|
{{- end}}
|