Skip to content

Commit

Permalink
List people in contact
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Jul 23, 2024
1 parent fed959b commit 8317a68
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 31 deletions.
33 changes: 33 additions & 0 deletions components/org/party.templ
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ templ Party(party *org.Party) {
if party.Alias != "" {
<div class="alias">{ party.Alias }</div>
}
if len(party.People) > 0 {
@people(party.People)
}
for _, a := range party.Addresses {
@AddressWithLabel(a)
}
Expand Down Expand Up @@ -51,6 +54,20 @@ templ taxID(party *org.Party) {
</div>
}

templ people(people []*org.Person) {
for _, p := range people {
if n := personName(p); n != "" {
<div class="person">
if p.Label != "" {
@t.T(".person_label", i18n.M{"label": p.Label, "name": n})
} else {
@t.T(".person", i18n.M{"name": n})
}
</div>
}
}
}

templ telephones(tels []*org.Telephone) {
for _, tel := range tels {
<div class="telephone">
Expand Down Expand Up @@ -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 {
Expand Down
103 changes: 86 additions & 17 deletions components/org/party_templ.go

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

4 changes: 2 additions & 2 deletions examples/gr-invoice.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"supplier": {
"name": "Ελληνικά Τρόφιμα Α.Ε.",
"tax_id": {
"country": "GR",
"country": "EL",
"code": "177472438"
},
"addresses": [
Expand All @@ -53,7 +53,7 @@
"customer": {
"name": "Αιγαίο Λιανική Α.Ε.",
"tax_id": {
"country": "GR",
"country": "EL",
"code": "841442160"
},
"addresses": [
Expand Down
9 changes: 9 additions & 0 deletions examples/invoice-es-usd.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
"customer": {
"name": "Sample Consumer Inc.",
"label": "Client",
"people": [
{
"label": "Contact",
"name": {
"given": "John",
"surname": "Doe"
}
}
],
"tax_id": {
"country": "US"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/out/gr-invoice.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h2>
</span>
</div>
<div class="tax-id">
Tax Code: (GR) 177472438
Tax Code: (EL) 177472438
</div>
</div>
</section>
Expand All @@ -103,7 +103,7 @@ <h2>
</span>
</div>
<div class="tax-id">
Tax Code: (GR) 841442160
Tax Code: (EL) 841442160
</div>
</div>
</section>
Expand Down
3 changes: 3 additions & 0 deletions examples/out/invoice-es-usd.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ <h2>
<div class="name">
Sample Consumer Inc.
</div>
<div class="person">
Contact: John Doe
</div>
</div>
</section>
</div>
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down
2 changes: 2 additions & 0 deletions locales/en/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8317a68

Please sign in to comment.