Skip to content

Commit

Permalink
Merge pull request #3 from invopop/ksef-qr
Browse files Browse the repository at this point in the history
Adding PL and KSeF with QR. Also party labels.
  • Loading branch information
samlown authored May 16, 2024
2 parents 60d917b + 0860a08 commit fc41a07
Show file tree
Hide file tree
Showing 20 changed files with 723 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ time = false
clean_on_exit = false

[proxy]
enabled = true
enabled = false
app_port = 3001
proxy_port = 3000

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The `.toml` is already configured and ready in this repository, so simply run:
air
```

Air is a bit more reliable at detecting file changes, especially for stylesheets. It's configured to offer a proxy with auto-reload, but of course that will only work at the moment when viewing HTML documents, not PDFs. You'll always need to wait a few seconds before page reloads to give the system chance to recompile.
Air is a bit more reliable at detecting file changes, especially for stylesheets. You'll always need to wait a few seconds before page reloads to give the system chance to recompile. A proxy is available with Air, but we didn't find it to be very reliable and was breaking with query parameters, it obvously also wouldn't work for PDF reloads.

#### Templ Watcher

Expand Down
6 changes: 5 additions & 1 deletion components/bill/invoice/customer.templ
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import (
templ customer(inv *bill.Invoice) {
<section class="customer">
<h2>
@t.T("billing.invoice.customer.title")
if inv.Customer != nil && inv.Customer.Label != "" {
{ inv.Customer.Label }
} else {
@t.T("billing.invoice.customer.title")
}
</h2>
@org.Party(inv.Customer)
</section>
Expand Down
18 changes: 15 additions & 3 deletions components/bill/invoice/customer_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions components/bill/invoice/invoice.templ
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/invopop/gobl.html/components/regimes/co"
"github.com/invopop/gobl.html/components/regimes/mx"
"github.com/invopop/gobl.html/internal"
"github.com/invopop/gobl.html/components/regimes/pl"
)

// Invoice renders a complete GOBL bill.Invoice object.
Expand Down Expand Up @@ -42,6 +43,7 @@ templ Invoice(env *gobl.Envelope, inv *bill.Invoice) {
@es.TicketBAIQR(env)
@co.DIANQR(env, inv)
@mx.CFDI(env, inv)
@pl.KSeFQR(env)
</div>
</article>
}
Expand Down
9 changes: 7 additions & 2 deletions components/bill/invoice/invoice_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion components/bill/invoice/supplier.templ
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import (
templ supplier(inv *bill.Invoice) {
<section class="supplier">
<h2>
@t.T("billing.invoice.supplier.title")
if inv.Supplier != nil && inv.Supplier.Label != "" {
{ inv.Supplier.Label }
} else {
@t.T("billing.invoice.supplier.title")
}
</h2>
@org.Party(inv.Supplier)
</section>
Expand Down
18 changes: 15 additions & 3 deletions components/bill/invoice/supplier_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions components/regimes/pl/ksef.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package pl

import (
"regexp"

"github.com/invopop/gobl"
"github.com/invopop/gobl/regimes/pl"
"github.com/invopop/gobl.html/components/t"
"github.com/invopop/ctxi18n/i18n"
"github.com/invopop/gobl.html/components/images"
)

var dianQRHTTPRegexp = regexp.MustCompile(`https.+`)

templ KSeFQR(env *gobl.Envelope) {
if id := ksefID(env); id != "" {
if qr := ksefQR(env); qr != "" {
@generateQR(id, qr)
}
}
}

templ generateQR(id, qr string) {
<style type="text/css">
.ksef-qr {
display: flex;
font-family: monospace;
font-size: 7pt;
}
.ksef-qr .image {
margin-right: 6mm;
}
.ksef-qr .text {
margin-top: auto;
word-break: break-all;
}
.ksef-qr img {
width: 24mm;
height: 24mm;
}
</style>
<section class="ksef-qr">
<div class="image">
<a href={ templ.URL(qr) }>
@images.QR(qr)
</a>
</div>
<div class="text">
<div class="ksef-id">
@t.T("billing.invoice.regimes.pl.ksef-id", i18n.M{"id": id})
</div>
</div>
</section>
}

func ksefQR(env *gobl.Envelope) string {
for _, stamp := range env.Head.Stamps {
switch stamp.Provider {
case pl.StampProviderKSeFQR:
return stamp.Value
}
}
return ""
}

func ksefID(env *gobl.Envelope) string {
for _, stamp := range env.Head.Stamps {
switch stamp.Provider {
case pl.StampProviderKSeFID:
return stamp.Value
}
}
return ""
}
120 changes: 120 additions & 0 deletions components/regimes/pl/ksef_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions components/regimes/pl/pl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package pl defines extra output for Polish invoices.
package pl
2 changes: 2 additions & 0 deletions examples/invoice-es-usd.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
],
"supplier": {
"name": "Provide One S.L.",
"label": "Host",
"tax_id": {
"country": "ES",
"code": "B98602642"
Expand All @@ -52,6 +53,7 @@
},
"customer": {
"name": "Sample Consumer Inc.",
"label": "Client",
"tax_id": {
"country": "US"
}
Expand Down
Loading

0 comments on commit fc41a07

Please sign in to comment.