diff --git a/components/bill/invoice.templ b/components/bill/invoice.templ index 408c2c0..c130114 100644 --- a/components/bill/invoice.templ +++ b/components/bill/invoice.templ @@ -14,6 +14,7 @@ import ( "github.com/invopop/gobl.html/components/regimes/mx" "github.com/invopop/gobl.html/components/regimes/pl" "github.com/invopop/gobl.html/components/regimes/pt" + "github.com/invopop/gobl.html/components/regimes/sa" "github.com/invopop/gobl.html/components/t" "github.com/invopop/gobl.html/components/utils" "github.com/invopop/gobl.html/internal" @@ -50,6 +51,7 @@ templ Invoice(env *gobl.Envelope, inv *bill.Invoice) { @mx.CFDI(env, inv) @pl.KSeFQR(env) @pt.ATQR(env) + @sa.ZATCAQR(env) @gr.IAPR(env) diff --git a/components/bill/invoice_templ.go b/components/bill/invoice_templ.go index 69f2548..493bf82 100644 --- a/components/bill/invoice_templ.go +++ b/components/bill/invoice_templ.go @@ -22,6 +22,7 @@ import ( "github.com/invopop/gobl.html/components/regimes/mx" "github.com/invopop/gobl.html/components/regimes/pl" "github.com/invopop/gobl.html/components/regimes/pt" + "github.com/invopop/gobl.html/components/regimes/sa" "github.com/invopop/gobl.html/components/t" "github.com/invopop/gobl.html/components/utils" "github.com/invopop/gobl.html/internal" @@ -174,6 +175,10 @@ func Invoice(env *gobl.Envelope, inv *bill.Invoice) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = sa.ZATCAQR(env).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } templ_7745c5c3_Err = gr.IAPR(env).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -266,7 +271,7 @@ func title(env *gobl.Envelope, doc internal.Document) templ.Component { var templ_7745c5c3_Var11 string templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(" ") if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 67, Col: 9} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 69, Col: 9} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) if templ_7745c5c3_Err != nil { @@ -331,7 +336,7 @@ func titleHero(doc internal.Document) templ.Component { var templ_7745c5c3_Var13 string templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(img.URL) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 81, Col: 22} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 83, Col: 22} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) if templ_7745c5c3_Err != nil { @@ -344,7 +349,7 @@ func titleHero(doc internal.Document) templ.Component { var templ_7745c5c3_Var14 string templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(img.Label) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 81, Col: 40} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 83, Col: 40} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) if templ_7745c5c3_Err != nil { @@ -357,7 +362,7 @@ func titleHero(doc internal.Document) templ.Component { var templ_7745c5c3_Var15 string templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(logoHeight(img)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 81, Col: 67} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 83, Col: 67} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) if templ_7745c5c3_Err != nil { @@ -371,7 +376,7 @@ func titleHero(doc internal.Document) templ.Component { var templ_7745c5c3_Var16 string templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(supplierAlias(doc.GetSupplier())) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 83, Col: 38} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 85, Col: 38} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) if templ_7745c5c3_Err != nil { @@ -479,7 +484,7 @@ func defaultJoinCode(_ internal.Document, series, code cbc.Code) templ.Component var templ_7745c5c3_Var20 string templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(series.Join(code).String()) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 102, Col: 29} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 104, Col: 29} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20)) if templ_7745c5c3_Err != nil { @@ -560,7 +565,7 @@ func untdidTitleType(doc internal.Document) templ.Component { var templ_7745c5c3_Var23 string templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(lbl) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 122, Col: 7} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 124, Col: 7} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) if templ_7745c5c3_Err != nil { @@ -678,7 +683,7 @@ func titleBadges(env *gobl.Envelope, doc internal.Document) templ.Component { var templ_7745c5c3_Var26 string templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(lbl) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 158, Col: 8} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/bill/invoice.templ`, Line: 160, Col: 8} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) if templ_7745c5c3_Err != nil { diff --git a/components/regimes/sa/sa.go b/components/regimes/sa/sa.go new file mode 100644 index 0000000..383cbd8 --- /dev/null +++ b/components/regimes/sa/sa.go @@ -0,0 +1,2 @@ +// Package sa defines extra output for Saudi Arabian invoices. +package sa diff --git a/components/regimes/sa/zatca.templ b/components/regimes/sa/zatca.templ new file mode 100644 index 0000000..e46328f --- /dev/null +++ b/components/regimes/sa/zatca.templ @@ -0,0 +1,42 @@ +package sa + +import ( + "github.com/invopop/gobl" + "github.com/invopop/gobl.html/components/images" + "github.com/invopop/gobl/addons/sa/zatca" +) + +// ZATCAQR renders the ZATCA QR code carried as a stamp on the envelope +// header. The stamp value is the base64-encoded TLV payload defined by +// the ZATCA e-invoicing specification. +templ ZATCAQR(env *gobl.Envelope) { + if qr := zatcaQR(env); qr != "" { + @generateQR(qr) + } +} + +templ generateQR(qr string) { + +
+
+ @images.QR(qr) +
+
+} + +func zatcaQR(env *gobl.Envelope) string { + for _, stamp := range env.Head.Stamps { + if stamp.Provider == zatca.StampQR { + return stamp.Value + } + } + return "" +} diff --git a/components/regimes/sa/zatca_templ.go b/components/regimes/sa/zatca_templ.go new file mode 100644 index 0000000..583f545 --- /dev/null +++ b/components/regimes/sa/zatca_templ.go @@ -0,0 +1,97 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.3.977 +package sa + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import ( + "github.com/invopop/gobl" + "github.com/invopop/gobl.html/components/images" + "github.com/invopop/gobl/addons/sa/zatca" +) + +// ZATCAQR renders the ZATCA QR code carried as a stamp on the envelope +// header. The stamp value is the base64-encoded TLV payload defined by +// the ZATCA e-invoicing specification. +func ZATCAQR(env *gobl.Envelope) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + if qr := zatcaQR(env); qr != "" { + templ_7745c5c3_Err = generateQR(qr).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) +} + +func generateQR(qr string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var2 := templ.GetChildren(ctx) + if templ_7745c5c3_Var2 == nil { + templ_7745c5c3_Var2 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = images.QR(qr).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func zatcaQR(env *gobl.Envelope) string { + for _, stamp := range env.Head.Stamps { + if stamp.Provider == zatca.StampQR { + return stamp.Value + } + } + return "" +} + +var _ = templruntime.GeneratedTemplate diff --git a/examples/out/sa-invoice-simplified.html b/examples/out/sa-invoice-simplified.html index 206ad45..3b119c6 100644 --- a/examples/out/sa-invoice-simplified.html +++ b/examples/out/sa-invoice-simplified.html @@ -229,16 +229,28 @@

Notes

-
- -

Simplified Tax Invoice

-
+
+ +
+
+ +
+
+
diff --git a/examples/sa-invoice-simplified.json b/examples/sa-invoice-simplified.json index b4620da..e732fe1 100644 --- a/examples/sa-invoice-simplified.json +++ b/examples/sa-invoice-simplified.json @@ -4,11 +4,18 @@ "uuid": "3a8e2ae1-eab8-11ed-b735-3e7e00ce5635", "dig": { "alg": "sha256", - "val": "06f08895b0f7cf34392a0a17f67fb2f7efe162d0d283137b275c5b8e27228fe8" - } + "val": "31b900c32da25c7c5bd0363e8dbede8880d5f3a0b11e75d37f160b2acb2261be" + }, + "stamps": [ + { + "prv": "zatca-qr", + "val": "AS3Yp9mF2YrZitmF2YjYsyDYp9mE2LnYsdio2YrYqSDZhNmE2YHYudin2YTZitin2Kog2KfZhNiq2LHZgdmK2YfZitipAg8zMTE1ODgxMDcyMDAwMDMDEzIwMjUtMDktMjVUMDA6MDA6MDBaBAY5NDguNzUFBjEyMy43NQ==" + } + ] }, "doc": { "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "SA", "$tags": [ "simplified" ], @@ -85,14 +92,14 @@ "payable": "948.75" }, "notes": [ - { - "text": "\u003cimg src='https://assets.invopop.com/misc/qr.png' width='100'\u003e" - }, { "key": "legal", "src": "simplified", "text": "Simplified Tax Invoice" } ] - } + }, + "sigs": [ + "eyJhbGciOiJFUzI1NiIsImtpZCI6ImUzNzFjMzBiLTNiMzMtNGNiMC04NzM5LThiOTUzMWM1NWM2NiJ9.eyJ1dWlkIjoiM2E4ZTJhZTEtZWFiOC0xMWVkLWI3MzUtM2U3ZTAwY2U1NjM1IiwiZGlnIjp7ImFsZyI6InNoYTI1NiIsInZhbCI6IjA2ZjA4ODk1YjBmN2NmMzQzOTJhMGExN2Y2N2ZiMmY3ZWZlMTYyZDBkMjgzMTM3YjI3NWM1YjhlMjcyMjhmZTgifSwic3RhbXBzIjpbeyJwcnYiOiJ6YXRjYS1xciIsInZhbCI6IkFTM1lwOW1GMllyWml0bUYyWWpZc3lEWXA5bUUyTGppU2RpbzJZclpxU0RaaE5tRTJZUFl1ZGluMllUWml0aW4yS29nMktmWmhOaXEyTGZaZ2RtSzJZZlppdGlwQWc4ek1URTFPRGd4TURjeU1EQXdNRE1ERXpJd01qVXRNRGt0TWpWVU1EQTZNREE2TURCYUJBWTVORGd1TnpVRkJqRXlNeTQzTlE9PSJ9XX0.PLACEHOLDER_SIGNATURE_FOR_EXAMPLE_RENDERING_NOT_CRYPTOGRAPHICALLY_VALIA" + ] } \ No newline at end of file diff --git a/go.mod b/go.mod index 9c1256d..db0cf32 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/a-h/templ v0.3.977 github.com/go-resty/resty/v2 v2.12.0 github.com/invopop/ctxi18n v0.9.0 - github.com/invopop/gobl v0.403.0 + github.com/invopop/gobl v0.403.1-0.20260514080559-652a479eb819 github.com/invopop/princepdf v0.0.0-20240408123340-585be3cab91a github.com/labstack/echo/v4 v4.15.0 github.com/piglig/go-qr v0.2.4 diff --git a/go.sum b/go.sum index 82da321..d1eeae3 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,8 @@ github.com/invopop/ctxi18n v0.9.0 h1:BIia4u4OngaHVn/7gvK0w6lccOXVtad8xU0KgJ+mnVA github.com/invopop/ctxi18n v0.9.0/go.mod h1:1Osw+JGYA+anHt0Z4reF36r5FtGHYjGQ+m1X7keIhPc= github.com/invopop/gobl v0.403.0 h1:jLkqmPbeTxu4gXntjsCtczq3rGg6JnXBwyMF/TkvOhU= github.com/invopop/gobl v0.403.0/go.mod h1:6jYbcNFgUcBXIsS3PIeZc99rrMLBaGzPsFEg7y2DyrQ= +github.com/invopop/gobl v0.403.1-0.20260514080559-652a479eb819 h1:Oae58LfslZNIWwphN+Z1QHoY5PuO1A5cUpFknbj8XNg= +github.com/invopop/gobl v0.403.1-0.20260514080559-652a479eb819/go.mod h1:6jYbcNFgUcBXIsS3PIeZc99rrMLBaGzPsFEg7y2DyrQ= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I= github.com/invopop/princepdf v0.0.0-20240408123340-585be3cab91a h1:xt18LlIfizLkFgLi+vK/m2SWOsAbQwVwQgbkzxKY0eU=