Skip to content

Commit

Permalink
update header class names and QR methods
Browse files Browse the repository at this point in the history
  • Loading branch information
beliolfa committed Dec 13, 2024
1 parent fe53dd5 commit 3bcbad7
Show file tree
Hide file tree
Showing 26 changed files with 86 additions and 75 deletions.
18 changes: 9 additions & 9 deletions assets/styles/invoice.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@ header {
flex-flow: row wrap;
border-bottom: 0.5px solid #e5e7eb;
}
header.not-qr div.details {
header.regular div.details {
flex: 1;
border-right: 0.5px solid #e5e7eb;
}
header.not-qr > div.contacts {
header.regular > div.contacts {
flex: 1;
}
header.not-qr section.supplier {
header.regular section.supplier {
padding: 6mm;
padding-top: 0mm;
}
header.not-qr section.customer {
header.regular section.customer {
padding: 6mm;
border-top: 0.5px solid #e5e7eb;
}
header.qr > section.qr {
header.with-qr > section.qr {
display: flex;
justify-content: center;
align-items: center;
flex-basis: 50%;
padding-bottom: 24px;
}
header.qr > div.details {
header.with-qr > div.details {
flex-basis: 50%;
box-sizing: border-box;
border-right: 0.5px solid #e5e7eb;
}
header.qr div.contacts {
header.with-qr div.contacts {
flex-basis: 100%;
display: flex;
border-top: 0.5px solid #e5e7eb;
}
header.qr section.supplier {
header.with-qr section.supplier {
padding-top: 6mm;
padding-bottom: 6mm;
}
header.qr section.customer {
header.with-qr section.customer {
padding-left: 6mm;
padding-top: 6mm;
padding-bottom: 6mm;
Expand Down
13 changes: 0 additions & 13 deletions components/bill/invoice/helpers.go

This file was deleted.

14 changes: 13 additions & 1 deletion components/bill/invoice/invoice.templ
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
templ Invoice(env *gobl.Envelope, inv *bill.Invoice) {
// Footer needs to be at the top to show on all pages
<article class="invoice">
<header class={ templ.KV("qr", HasHeaderQR(env)), templ.KV("not-qr", !HasHeaderQR(env)) }>
<header class={ headerClass(env) }>
<div class="details">
@title(inv)
@summary(inv)
Expand Down Expand Up @@ -122,3 +122,15 @@ func code(series, code cbc.Code) string {
}
return fmt.Sprintf("%s-%s", series, code)
}

func hasHeaderQR(env *gobl.Envelope) bool {
return es.HasVerifactuQR(env) || es.HasTicketBAIQR(env)
}

func headerClass(env *gobl.Envelope) string {
if hasHeaderQR(env) {
return "with-qr"
}

return "regular"
}
14 changes: 13 additions & 1 deletion components/bill/invoice/invoice_templ.go

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

12 changes: 7 additions & 5 deletions components/regimes/es/ticketbai.templ
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ import (

// TicketBAIQR generates a QR code area for the TicketBAI code in the given envelope.
templ TicketBAIQR(env *gobl.Envelope) {
if result, code, qr := HasTicketBAIQR(env); result {
@generateTicketBAIQR(code, qr)
if code := ticketbaiCode(env); code != "" {
if qr := ticketbaiQR(env); qr != "" {
@generateTicketBAIQR(code, qr)
}
}
}

// HasTicketBAIQR returns a boolean indicating whether the envelope has a TicketBAI QR or not.
func HasTicketBAIQR(env *gobl.Envelope) (bool, string, string) {
func HasTicketBAIQR(env *gobl.Envelope) bool {
if code := ticketbaiCode(env); code != "" {
if qr := ticketbaiQR(env); qr != "" {
return true, code, qr
return true
}
}

return false, "", ""
return false
}

templ generateTicketBAIQR(code, qr string) {
Expand Down
18 changes: 10 additions & 8 deletions components/regimes/es/ticketbai_templ.go

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

18 changes: 8 additions & 10 deletions components/regimes/es/verifactu.templ
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import (
"github.com/invopop/gobl"
"github.com/invopop/gobl.html/components/images"
"github.com/invopop/gobl/addons/es/verifactu"
"github.com/invopop/gobl/head"
)

// VerifactuQR generates a QR code area for the Verifactu code in the given envelope.
templ VerifactuQR(env *gobl.Envelope) {
if result, qr := HasVerifactuQR(env); result {
if qr := verifactuQR(env); qr != "" {
@generateVerifactuQR(qr)
}
}

// HasVerifactuQR returns a boolean indicating whether the envelope has a Verifactu QR or not.
func HasVerifactuQR(env *gobl.Envelope) (bool, string) {
func HasVerifactuQR(env *gobl.Envelope) bool {
if qr := verifactuQR(env); qr != "" {
return true, qr
return true
}

return false, ""
return false
}

templ generateVerifactuQR(qr string) {
Expand Down Expand Up @@ -67,11 +67,9 @@ templ generateVerifactuQR(qr string) {
}

func verifactuQR(env *gobl.Envelope) string {
for _, stamp := range env.Head.Stamps {
switch stamp.Provider {
case verifactu.StampQR:
return stamp.Value
}
stamp := head.GetStamp(env.Head.Stamps, verifactu.StampQR)
if stamp != nil {
return stamp.Value
}
return ""
}
18 changes: 8 additions & 10 deletions components/regimes/es/verifactu_templ.go

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

2 changes: 1 addition & 1 deletion examples/out/credit-note-es-es-tbai.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="not-qr">
<header class="regular">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/full-invoice.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="not-qr">
<header class="regular">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/gr-invoice.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="not-qr">
<header class="regular">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/invoice-es-simplified.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="not-qr">
<header class="regular">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/invoice-es-ticketbai.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="qr">
<header class="with-qr">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/invoice-es-usd.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="not-qr">
<header class="regular">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/invoice-es-verifactu.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="qr">
<header class="with-qr">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/invoice-limited-company.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="not-qr">
<header class="regular">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/invoice-mx.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="not-qr">
<header class="regular">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/invoice-pl.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="not-qr">
<header class="regular">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/invoice-tax-included.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="not-qr">
<header class="regular">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/invoice-zw-usd.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="not-qr">
<header class="regular">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
2 changes: 1 addition & 1 deletion examples/out/invoice.env.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</footer>
<article class="invoice">
<header class="not-qr">
<header class="regular">
<div class="details">
<section class="title">
<div class="hero">
Expand Down
Loading

0 comments on commit 3bcbad7

Please sign in to comment.