From 399ebcf7e635e404de7e100137ca6596b206cefd Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Wed, 8 May 2024 10:53:08 +0000 Subject: [PATCH] Hide empty taxes table --- .gitignore | 3 + components/bill/invoice/taxes.templ | 2 +- components/bill/invoice/taxes_templ.go | 2 +- examples/out/us-invoice.html | 623 +++++++++++++++++++++++++ examples/us-invoice.json | 127 +++++ go.mod | 2 +- go.sum | 2 - 7 files changed, 756 insertions(+), 5 deletions(-) create mode 100644 examples/out/us-invoice.html create mode 100644 examples/us-invoice.json diff --git a/.gitignore b/.gitignore index f6abc6e..97b6b9b 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,9 @@ *.hide.json *.hide.html +# Ingore all templ txt files +*_templ.txt + # Go workspace file go.work diff --git a/components/bill/invoice/taxes.templ b/components/bill/invoice/taxes.templ index c9de366..b32974d 100644 --- a/components/bill/invoice/taxes.templ +++ b/components/bill/invoice/taxes.templ @@ -9,7 +9,7 @@ import ( ) templ taxes(inv *bill.Invoice, taxes *tax.Total) { - if taxes != nil { + if taxes != nil && len(taxes.Categories) > 0 {
@t.Scope("billing.invoice.taxes") {

diff --git a/components/bill/invoice/taxes_templ.go b/components/bill/invoice/taxes_templ.go index e1b67b4..c43bf11 100644 --- a/components/bill/invoice/taxes_templ.go +++ b/components/bill/invoice/taxes_templ.go @@ -31,7 +31,7 @@ func taxes(inv *bill.Invoice, taxes *tax.Total) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - if taxes != nil { + if taxes != nil && len(taxes.Categories) > 0 { _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err diff --git a/examples/out/us-invoice.html b/examples/out/us-invoice.html new file mode 100644 index 0000000..35b6f9e --- /dev/null +++ b/examples/out/us-invoice.html @@ -0,0 +1,623 @@ + + + + GOBL HTML Generator + + + + + + + + + +
+ +
+ + Page + + 1 + + of + + 1 + + + +
+ +
+
+
+
+
+ Invopop +
+

+ Invoice +

+

+ FAKE-0001 +

+
+
+

+ Summary +

+
    +
  • + + Issue Date + + + 2024-05-08 + +
  • +
  • + + Currency + + + United States Dollar (USD) + +
  • +
+
+
+
+
+

+ Supplier +

+
+
+ Invopop Inc. +
+
+ + 1111B S Governors Ave #6229, Dover, DE, 19904 (United States of America) + +
+
+ Email: billing@invopop.com +
+
+
+
+

+ Customer +

+
+
+ Customer Random Inc. +
+
+ + Office:  + + + 10 Calle Mayor, Madrid, CA, 28003 (United States of America) + +
+
+ Email: sam@example.com +
+
+ Código de Cliente: 123456789ABC +
+
+
+
+
+
+

+ Lines +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ # + + Description + + Qty. + + Price + + Disc. + + Total +
+ 1 + + + Development Day Rate + +
+ + Development services for the month of February 2022 + +
+ 20 + + $200.00 + + 5% + + $3,800.00 +
+ 2 + + + Something random + + + 10 + + $100.00 + + $1,000.00 +
+
+
+
+

+ Totals +

+ + + + + + + + + + + + + + + +
+ Sum + + $4,800.00 +
+ Tax + + $0.00 +
+ Total to pay + + $4,800.00 +
+
+
+
+

+ Notes +

+
+

+ Thank you for you business! +

+
+
+

+ Please pay within 30 days according to some random law in the country we sell from that you should comply with because we want to be paid sooner. +

+
+
+
+
+ +
+ + \ No newline at end of file diff --git a/examples/us-invoice.json b/examples/us-invoice.json new file mode 100644 index 0000000..d322676 --- /dev/null +++ b/examples/us-invoice.json @@ -0,0 +1,127 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "3a8e2ae1-eab8-11ed-b735-3e7e00ce5635", + "dig": { + "alg": "sha256", + "val": "ac1ea2ef0d248f7f7a9bfdcb608f864571bdb746d55ce6ebbf6e803c07ca787f" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "uuid": "018f57cc-cc50-7289-a654-a2507af6c889", + "type": "standard", + "series": "FAKE", + "code": "0001", + "issue_date": "2024-05-08", + "currency": "USD", + "supplier": { + "name": "Invopop Inc.", + "tax_id": { + "country": "US" + }, + "addresses": [ + { + "num": "1111B", + "street": "S Governors Ave #6229", + "locality": "Dover", + "region": "DE", + "code": "19904", + "country": "US" + } + ], + "emails": [ + { + "addr": "billing@invopop.com" + } + ], + "logos": [ + { + "label": "Invopop", + "url": "https://ams3.digitaloceanspaces.com/invopop-console-files-dev/3c5f601121ad9726776ce51b00a585e4e09387a7375fe352536bacd1793affd0" + } + ] + }, + "customer": { + "name": "Customer Random Inc.", + "tax_id": { + "country": "US" + }, + "identities": [ + { + "label": "Código de Cliente", + "code": "123456789ABC" + } + ], + "addresses": [ + { + "label": "Office", + "po_box": "20", + "num": "10", + "street": "Calle Mayor", + "locality": "Madrid", + "region": "CA", + "code": "28003", + "country": "US" + } + ], + "emails": [ + { + "addr": "sam@example.com" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "20", + "item": { + "name": "Development Day Rate", + "description": "Development services for the month of February 2022", + "price": "200.00" + }, + "sum": "4000.00", + "discounts": [ + { + "percent": "5%", + "amount": "200.00", + "reason": "Just because" + } + ], + "total": "3800.00" + }, + { + "i": 2, + "quantity": "10", + "item": { + "name": "Something random", + "price": "100.00" + }, + "sum": "1000.00", + "total": "1000.00" + } + ], + "totals": { + "sum": "4800.00", + "total": "4800.00", + "taxes": { + "sum": "0.00" + }, + "tax": "0.00", + "total_with_tax": "4800.00", + "payable": "4800.00" + }, + "notes": [ + { + "text": "Thank you for you business!" + }, + { + "key": "legal", + "text": "Please pay within 30 days according to some random law in the country we sell from that you should comply with because we want to be paid sooner.", + "meta": { + "position": "footer" + } + } + ] + } +} diff --git a/go.mod b/go.mod index d411523..4619102 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/invopop/princepdf v0.0.0-20240408123340-585be3cab91a github.com/labstack/echo/v4 v4.11.4 github.com/piglig/go-qr v0.2.4 + github.com/pmezard/go-difflib v1.0.0 github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.9.0 github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 @@ -36,7 +37,6 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect diff --git a/go.sum b/go.sum index 684e64d..8279c45 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,6 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/invopop/ctxi18n v0.6.0 h1:Qm3ZL/kK4EKvmLI3U2ETN2rWrtSTaxXrcA6ZUY9aVGE= github.com/invopop/ctxi18n v0.6.0/go.mod h1:1Osw+JGYA+anHt0Z4reF36r5FtGHYjGQ+m1X7keIhPc= -github.com/invopop/gobl v0.74.2-0.20240429205753-51d26c7ca2f8 h1:1EPYjNWXRiW7n80XmBSLcO9MfOlilVxLUj3l+Iy/6Ng= -github.com/invopop/gobl v0.74.2-0.20240429205753-51d26c7ca2f8/go.mod h1:3ixShxX1jlOKo5Rw22HVQh3jXnK9AZa7Twcw7L92qn0= github.com/invopop/gobl v0.75.0 h1:QQpFTkraauZoGEGQlYqfHpJmBNayamtjT1+Onw8zVEA= github.com/invopop/gobl v0.75.0/go.mod h1:3ixShxX1jlOKo5Rw22HVQh3jXnK9AZa7Twcw7L92qn0= github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=