From 905792a51ba7888df36ff674454b729757edb94b Mon Sep 17 00:00:00 2001 From: apardods Date: Fri, 20 Dec 2024 12:45:53 +0000 Subject: [PATCH] Normalize opt name,add example --- cmd/gobl.html/convert.go | 2 + examples/invoice-de-zugferd.json | 179 +++++++++++++++++++++++++++ examples/out/invoice-de-zugferd.html | 152 +++++++++++++++++++++++ pkg/pdf/pdf.go | 4 +- pkg/pdf/prince.go | 1 + 5 files changed, 336 insertions(+), 2 deletions(-) create mode 100644 examples/invoice-de-zugferd.json create mode 100755 examples/out/invoice-de-zugferd.html diff --git a/cmd/gobl.html/convert.go b/cmd/gobl.html/convert.go index 07672c0..375face 100644 --- a/cmd/gobl.html/convert.go +++ b/cmd/gobl.html/convert.go @@ -12,6 +12,7 @@ import ( type convertOpts struct { *rootOpts + Zugferd bool } func convert(o *rootOpts) *convertOpts { @@ -24,6 +25,7 @@ func (c *convertOpts) cmd() *cobra.Command { Short: "Convert a GOBL JSON into an HTML file", RunE: c.runE, } + cmd.Flags().BoolVar(&c.Zugferd, "zugferd", false, "Add Zugferd XMP metadata to the PDF") return cmd } diff --git a/examples/invoice-de-zugferd.json b/examples/invoice-de-zugferd.json new file mode 100644 index 0000000..7381cbc --- /dev/null +++ b/examples/invoice-de-zugferd.json @@ -0,0 +1,179 @@ +{ + "$schema": "https://gobl.org/draft-0/envelope", + "head": { + "uuid": "8a51fd30-2a27-11ee-be56-0242ac120002", + "dig": { + "alg": "sha256", + "val": "583130bdfd84c31d23f7bcdf778363ffdbc7eb132faf1180efb1be1fc438e069" + } + }, + "doc": { + "$schema": "https://gobl.org/draft-0/bill/invoice", + "$regime": "DE", + "$addons": [ + "eu-en16931-v2017" + ], + "uuid": "019231f1-9128-71fc-b0e2-820af3036d1b", + "type": "standard", + "series": "SAMPLE", + "code": "001", + "issue_date": "2024-02-13", + "currency": "EUR", + "supplier": { + "name": "Provide One GmbH", + "tax_id": { + "country": "DE", + "code": "111111125" + }, + "people": [ + { + "name": { + "given": "John", + "surname": "Doe" + } + } + ], + "addresses": [ + { + "num": "16", + "street": "Dietmar-Hopp-Allee", + "locality": "Walldorf", + "code": "69190", + "country": "DE" + } + ], + "emails": [ + { + "addr": "billing@example.com" + } + ], + "telephones": [ + { + "num": "+49100200300" + } + ] + }, + "customer": { + "name": "Sample Consumer", + "tax_id": { + "country": "DE", + "code": "282741168" + }, + "addresses": [ + { + "num": "25", + "street": "Werner-Heisenberg-Allee", + "locality": "München", + "code": "80939", + "country": "DE" + } + ], + "emails": [ + { + "addr": "email@sample.com" + } + ] + }, + "lines": [ + { + "i": 1, + "quantity": "20", + "item": { + "name": "Development services", + "price": "90.00", + "unit": "h" + }, + "sum": "1800.00", + "taxes": [ + { + "cat": "VAT", + "rate": "standard", + "percent": "19%" + } + ], + "total": "1800.00" + } + ], + "ordering": { + "code": "XR-2024-2", + "seller": { + "name": "Salescompany ltd.", + "tax_id": { + "country": "NO", + "code": "123456789MVA" + }, + "identities": [ + { + "label": "CompanyID", + "code": "123456789" + }, + { + "label": "0088", + "code": "1238764941386" + } + ], + "people": [ + { + "name": { + "given": "Antonio Salesmacher" + } + } + ], + "addresses": [ + { + "street": "Main street 34", + "street_extra": "Suite 123", + "locality": "Big city", + "region": "RegionA", + "code": "303", + "country": "NO" + } + ], + "emails": [ + { + "addr": "antonio@salescompany.no" + } + ], + "telephones": [ + { + "num": "46211230" + } + ] + } + }, + "payment": { + "terms": { + "detail": "lorem ipsum" + } + }, + "tax": { + "ext": { + "untdid-document-type": "380" + } + }, + "totals": { + "sum": "1800.00", + "total": "1800.00", + "taxes": { + "categories": [ + { + "code": "VAT", + "rates": [ + { + "key": "standard", + "base": "1800.00", + "percent": "19%", + "amount": "342.00" + } + ], + "amount": "342.00" + } + ], + "sum": "342.00" + }, + "tax": "342.00", + "total_with_tax": "2142.00", + "payable": "2142.00" + } + } +} diff --git a/examples/out/invoice-de-zugferd.html b/examples/out/invoice-de-zugferd.html new file mode 100755 index 0000000..04230b0 --- /dev/null +++ b/examples/out/invoice-de-zugferd.html @@ -0,0 +1,152 @@ + + + GOBL HTML Generator + + + + + + + + + +
+
+ Page 1 of 1 + +
+
+
+
+
+
Provide One GmbH
+

Invoice

+

SAMPLE-001

+
+
+

Summary

+
    +
  • Issue Date 2024-02-13
  • +
  • Currency Euro (EUR)
  • +
  • Order XR-2024-2
  • +
+
+
+
+
+

Supplier

+
+
Provide One GmbH
+
John Doe
+
Dietmar-Hopp-Allee 16, Walldorf, 69190 (Germany)
+
Tel: +49100200300
+
Email: billing@example.com
+
TIN: (DE) 111111125
+
+
+
+

Customer

+
+
Sample Consumer
+
Werner-Heisenberg-Allee 25, München, 80939 (Germany)
+
Email: email@sample.com
+
TIN: (DE) 282741168
+
+
+
+
+
+

Lines

+ + + + + + + + + + + + + + + + + + + + + + + +
#DescriptionQty.UnitPriceVATTotal
1Development services20h€90,0019%€1.800,00
+
+
+
+

Totals

+ + + + + + + + + + + + + + + +
Sum€1.800,00
Tax€342,00
Total to pay€2.142,00
+
+
+

Taxes

+ + + + + + + + + + + + + + + + + +
TaxBaseRateAmount
VAT€1.800,0019%€342,00
+
+
+
+

Payment

+
    +
    +
    +
    + +
    + + diff --git a/pkg/pdf/pdf.go b/pkg/pdf/pdf.go index 482acc6..13f80d2 100644 --- a/pkg/pdf/pdf.go +++ b/pkg/pdf/pdf.go @@ -112,8 +112,8 @@ func WithAttachment(a *Attachment) Option { } } -// WithXMPMetadata adds the XMP metadata to the conversion request. -func WithXMPMetadata() Option { +// WithZugferd adds the Zugferd XMP metadata to the conversion request. +func WithZugferd() Option { return func(o *options) { o.xmpMetadata = &XMPMetadata{ Data: loadXMP(), diff --git a/pkg/pdf/prince.go b/pkg/pdf/prince.go index 062e5be..5786433 100644 --- a/pkg/pdf/prince.go +++ b/pkg/pdf/prince.go @@ -68,6 +68,7 @@ func (pc *princeConvertor) HTML(_ context.Context, data []byte, opts ...Option) if j.PDF == nil { j.PDF = new(princepdf.PDF) } + j.PDF.PDFXMP = xmpFilename j.PDF.Attach = append(j.PDF.Attach, &princepdf.Attachment{ URL: xmpFilename, Filename: xmpFilename,