From 8317a687185f0e9750cddbfff1025bef9e1060df Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Tue, 23 Jul 2024 15:43:59 +0000 Subject: [PATCH] List people in contact --- components/org/party.templ | 33 ++++++++++ components/org/party_templ.go | 103 ++++++++++++++++++++++++++----- examples/gr-invoice.json | 4 +- examples/invoice-es-usd.json | 9 +++ examples/out/gr-invoice.html | 4 +- examples/out/invoice-es-usd.html | 3 + go.mod | 6 +- go.sum | 14 ++--- locales/en/app.yml | 2 + 9 files changed, 147 insertions(+), 31 deletions(-) diff --git a/components/org/party.templ b/components/org/party.templ index f11c6c0..9cc7112 100644 --- a/components/org/party.templ +++ b/components/org/party.templ @@ -22,6 +22,9 @@ templ Party(party *org.Party) { if party.Alias != "" {
{ party.Alias }
} + if len(party.People) > 0 { + @people(party.People) + } for _, a := range party.Addresses { @AddressWithLabel(a) } @@ -51,6 +54,20 @@ templ taxID(party *org.Party) { } +templ people(people []*org.Person) { + for _, p := range people { + if n := personName(p); n != "" { +
+ if p.Label != "" { + @t.T(".person_label", i18n.M{"label": p.Label, "name": n}) + } else { + @t.T(".person", i18n.M{"name": n}) + } +
+ } + } +} + templ telephones(tels []*org.Telephone) { for _, tel := range tels {
@@ -99,6 +116,22 @@ templ partyExtensions(party *org.Party) { } } +func personName(p *org.Person) string { + n := p.Name + nom := []string{ + n.Prefix, + n.Given, + n.Middle, + n.Surname, + n.Surname2, + n.Suffix, + } + nom = slices.DeleteFunc(nom, func(s string) bool { + return s == "" + }) + return strings.Join(nom, " ") +} + func emailAddresses(ctx context.Context, emails []*org.Email) string { str := make([]string, len(emails)) for i, e := range emails { diff --git a/components/org/party_templ.go b/components/org/party_templ.go index e838b60..00bbf9e 100644 --- a/components/org/party_templ.go +++ b/components/org/party_templ.go @@ -84,6 +84,16 @@ func Party(party *org.Party) templ.Component { return templ_7745c5c3_Err } } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(party.People) > 0 { + templ_7745c5c3_Err = people(party.People).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } for _, a := range party.Addresses { templ_7745c5c3_Err = AddressWithLabel(a).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { @@ -200,7 +210,7 @@ func taxID(party *org.Party) templ.Component { }) } -func telephones(tels []*org.Telephone) templ.Component { +func people(people []*org.Person) templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -213,6 +223,49 @@ func telephones(tels []*org.Telephone) templ.Component { templ_7745c5c3_Var6 = templ.NopComponent } ctx = templ.ClearChildren(ctx) + for _, p := range people { + if n := personName(p); n != "" { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if p.Label != "" { + templ_7745c5c3_Err = t.T(".person_label", i18n.M{"label": p.Label, "name": n}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = t.T(".person", i18n.M{"name": n}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func telephones(tels []*org.Telephone) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var7 := templ.GetChildren(ctx) + if templ_7745c5c3_Var7 == nil { + templ_7745c5c3_Var7 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) for _, tel := range tels { _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { @@ -249,9 +302,9 @@ func emails(emails []*org.Email) templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var7 := templ.GetChildren(ctx) - if templ_7745c5c3_Var7 == nil { - templ_7745c5c3_Var7 = templ.NopComponent + templ_7745c5c3_Var8 := templ.GetChildren(ctx) + if templ_7745c5c3_Var8 == nil { + templ_7745c5c3_Var8 = templ.NopComponent } ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") @@ -281,9 +334,9 @@ func websites(websites []*org.Website) templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var8 := templ.GetChildren(ctx) - if templ_7745c5c3_Var8 == nil { - templ_7745c5c3_Var8 = templ.NopComponent + templ_7745c5c3_Var9 := templ.GetChildren(ctx) + if templ_7745c5c3_Var9 == nil { + templ_7745c5c3_Var9 = templ.NopComponent } ctx = templ.ClearChildren(ctx) for _, web := range websites { @@ -322,9 +375,9 @@ func identities(idents []*org.Identity) templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var9 := templ.GetChildren(ctx) - if templ_7745c5c3_Var9 == nil { - templ_7745c5c3_Var9 = templ.NopComponent + templ_7745c5c3_Var10 := templ.GetChildren(ctx) + if templ_7745c5c3_Var10 == nil { + templ_7745c5c3_Var10 = templ.NopComponent } ctx = templ.ClearChildren(ctx) for _, ident := range idents { @@ -356,9 +409,9 @@ func partyExtensions(party *org.Party) templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var10 := templ.GetChildren(ctx) - if templ_7745c5c3_Var10 == nil { - templ_7745c5c3_Var10 = templ.NopComponent + templ_7745c5c3_Var11 := templ.GetChildren(ctx) + if templ_7745c5c3_Var11 == nil { + templ_7745c5c3_Var11 = templ.NopComponent } ctx = templ.ClearChildren(ctx) for _, k := range extensionKeys(party.Ext) { @@ -367,12 +420,12 @@ func partyExtensions(party *org.Party) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var11 string - templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(txt) + var templ_7745c5c3_Var12 string + templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(txt) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/org/party.templ`, Line: 96, Col: 9} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/org/party.templ`, Line: 113, Col: 9} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -389,6 +442,22 @@ func partyExtensions(party *org.Party) templ.Component { }) } +func personName(p *org.Person) string { + n := p.Name + nom := []string{ + n.Prefix, + n.Given, + n.Middle, + n.Surname, + n.Surname2, + n.Suffix, + } + nom = slices.DeleteFunc(nom, func(s string) bool { + return s == "" + }) + return strings.Join(nom, " ") +} + func emailAddresses(ctx context.Context, emails []*org.Email) string { str := make([]string, len(emails)) for i, e := range emails { diff --git a/examples/gr-invoice.json b/examples/gr-invoice.json index 3e2cf72..2081084 100644 --- a/examples/gr-invoice.json +++ b/examples/gr-invoice.json @@ -40,7 +40,7 @@ "supplier": { "name": "Ελληνικά Τρόφιμα Α.Ε.", "tax_id": { - "country": "GR", + "country": "EL", "code": "177472438" }, "addresses": [ @@ -53,7 +53,7 @@ "customer": { "name": "Αιγαίο Λιανική Α.Ε.", "tax_id": { - "country": "GR", + "country": "EL", "code": "841442160" }, "addresses": [ diff --git a/examples/invoice-es-usd.json b/examples/invoice-es-usd.json index 014f4b0..b33d089 100644 --- a/examples/invoice-es-usd.json +++ b/examples/invoice-es-usd.json @@ -54,6 +54,15 @@ "customer": { "name": "Sample Consumer Inc.", "label": "Client", + "people": [ + { + "label": "Contact", + "name": { + "given": "John", + "surname": "Doe" + } + } + ], "tax_id": { "country": "US" } diff --git a/examples/out/gr-invoice.html b/examples/out/gr-invoice.html index 79737f4..7460a6b 100644 --- a/examples/out/gr-invoice.html +++ b/examples/out/gr-invoice.html @@ -85,7 +85,7 @@

- Tax Code: (GR) 177472438 + Tax Code: (EL) 177472438
@@ -103,7 +103,7 @@

- Tax Code: (GR) 841442160 + Tax Code: (EL) 841442160
diff --git a/examples/out/invoice-es-usd.html b/examples/out/invoice-es-usd.html index 1c122f0..6a58920 100644 --- a/examples/out/invoice-es-usd.html +++ b/examples/out/invoice-es-usd.html @@ -100,6 +100,9 @@

Sample Consumer Inc.
+
+ Contact: John Doe +
diff --git a/go.mod b/go.mod index 2ef83ec..cd1d245 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,12 @@ require ( github.com/a-h/templ v0.2.731 github.com/go-resty/resty/v2 v2.12.0 github.com/invopop/ctxi18n v0.6.0 - github.com/invopop/gobl v0.81.0 + github.com/invopop/gobl v0.110.2 github.com/invopop/princepdf v0.0.0-20240408123340-585be3cab91a - github.com/labstack/echo/v4 v4.11.4 + github.com/labstack/echo/v4 v4.12.0 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/spf13/cobra v1.8.1 github.com/stretchr/testify v1.9.0 github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 github.com/yuin/goldmark v1.4.13 diff --git a/go.sum b/go.sum index 6deda4f..785ac10 100644 --- a/go.sum +++ b/go.sum @@ -11,7 +11,7 @@ github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPn github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -26,8 +26,8 @@ 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.81.0 h1:bFzXkiNCdjXZcTrggsM8bzeddPDwAk/sUxinK7jaSlQ= -github.com/invopop/gobl v0.81.0/go.mod h1:3ixShxX1jlOKo5Rw22HVQh3jXnK9AZa7Twcw7L92qn0= +github.com/invopop/gobl v0.110.2 h1:6Jh6PoFIojxyTMGuOBhMnuw6O9qy7Bu0oYochEEWogc= +github.com/invopop/gobl v0.110.2/go.mod h1:SNuHEQJ0UEYVW9jd27MzlUiOWPviJnBygZ9/q5G5B5c= github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI= github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0= github.com/invopop/princepdf v0.0.0-20240408123340-585be3cab91a h1:xt18LlIfizLkFgLi+vK/m2SWOsAbQwVwQgbkzxKY0eU= @@ -39,8 +39,8 @@ github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81 github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/labstack/echo/v4 v4.11.4 h1:vDZmA+qNeh1pd/cCkEicDMrjtrnMGQ1QFI9gWN1zGq8= -github.com/labstack/echo/v4 v4.11.4/go.mod h1:noh7EvLwqDsmh/X/HWKPUl1AjzJrhyptRyEbQJfxen8= +github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0= +github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= @@ -59,8 +59,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= -github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 h1:wD1IWQwAhdWclCwaf6DdzgCAe9Bfz1M+4AHRd7N786Y= diff --git a/locales/en/app.yml b/locales/en/app.yml index df0b79a..7005ee4 100644 --- a/locales/en/app.yml +++ b/locales/en/app.yml @@ -126,6 +126,8 @@ en: org: party: tax_id: "%{label}: (%{country}) %{code}" + person: "%{name}" + person_label: "%{label}: %{name}" tel: "Tel: %{num}" tel_label: "Tel: %{num} (%{label})" email: