Skip to content

Commit

Permalink
Additional footer and registration details for PT
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Jun 18, 2024
1 parent c21947b commit c73146c
Show file tree
Hide file tree
Showing 27 changed files with 774 additions and 98 deletions.
36 changes: 34 additions & 2 deletions components/bill/invoice/notes.templ
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/invopop/gobl.html/components/t"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/renderer/html"
)

var markdown goldmark.Markdown
Expand All @@ -20,11 +21,15 @@ func init() {
goldmark.WithExtensions(
extension.NewLinkify(),
),
goldmark.WithRendererOptions(
// NOTE: Please remove this!
html.WithUnsafe(),
),
)
}

templ notes(inv *bill.Invoice) {
if len(inv.Notes) > 0 {
if len(inv.Notes) > 0 || inv.Supplier.Registration != nil {
<section class="notes">
@t.Scope("billing.invoice.notes") {
<h2>
Expand All @@ -47,8 +52,20 @@ templ noteRegSummary(reg *org.Registration) {
<div class="note registration">
@t.Scope(".reg") {
<span class="title">
@t.T(".inscription")
@t.T(".registration")
</span>
if reg.Capital != nil {
if a := registrationCapital(ctx, reg); a != "" {
<span class="capital">
@t.T(".capital", i18n.M{"amount": a})
</span>
}
}
if reg.Office != "" {
<span class="office">
{ reg.Office }
</span>
}
if reg.Book != "" {
<span class="book">
@t.T(".book", i18n.M{"id": reg.Book})
Expand Down Expand Up @@ -79,6 +96,11 @@ templ noteRegSummary(reg *org.Registration) {
@t.T(".entry", i18n.M{"id": reg.Entry})
</span>
}
if reg.Other != "" {
<span class="other">
{ reg.Other }
</span>
}
}
</div>
}
Expand All @@ -90,3 +112,13 @@ func renderNote(note *cbc.Note) string {
}
return buf.String()
}

func registrationCapital(ctx context.Context, reg *org.Registration) string {
if reg.Capital != nil {
if reg.Currency != "" {
return t.LocalizeCurrency(ctx, *reg.Capital, reg.Currency)
}
return t.LocalizeMoney(ctx, *reg.Capital)
}
return ""
}
85 changes: 83 additions & 2 deletions components/bill/invoice/notes_templ.go

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

13 changes: 13 additions & 0 deletions components/bill/invoice/taxes.templ
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ templ taxRateRow(inv *bill.Invoice, cat *tax.CategoryTotal, rate *tax.RateTotal,
} else {
@t.L(*rate.Percent)
}
} else if txt := taxExemptionCode(rate.Ext); txt != "" {
{ txt }
} else {
&mdash;
}
Expand Down Expand Up @@ -96,3 +98,14 @@ func taxCategoryTotalName(ctx context.Context, inv *bill.Invoice, cat *tax.Categ
category := r.Category(cat.Code)
return category.Name.In(t.Lang(ctx))
}

// taxExemptionCode looks at the exemption reasons and tries to extract the
// first code. We'll see if this is a good idea or not.
func taxExemptionCode(ext tax.Extensions) string {
if len(ext) > 0 {
for _, v := range ext {
return fmt.Sprintf("(%s)", v.String())
}
}
return ""
}
25 changes: 25 additions & 0 deletions components/bill/invoice/taxes_templ.go

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

17 changes: 12 additions & 5 deletions components/footer.templ
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package components

import (
"strings"

"github.com/invopop/gobl"
"github.com/invopop/gobl.html/components/images"
"github.com/invopop/ctxi18n/i18n"
"github.com/invopop/gobl.html/internal"
"github.com/invopop/gobl.html/components/regimes/pt"
)

templ footerPrint(env *gobl.Envelope) {
Expand Down Expand Up @@ -53,11 +56,15 @@ func pageNumber(ctx context.Context) string {
}

func footerNotesText(ctx context.Context, env *gobl.Envelope) string {
if opts := internal.Options(ctx); opts.Notes != "" {
return opts.Notes
out := make([]string, 0)
// special case for PT
if txt := pt.FooterNotes(env); txt != "" {
out = append(out, txt)
}
if env.Head.Notes != "" {
return env.Head.Notes
if opts := internal.Options(ctx); opts.Notes != "" {
out = append(out, opts.Notes)
} else if env.Head.Notes != "" {
out = append(out, env.Head.Notes)
}
return ""
return strings.Join(out, " &middot; ")
}
17 changes: 12 additions & 5 deletions components/footer_templ.go

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

15 changes: 15 additions & 0 deletions components/org/party.templ
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ templ Party(party *org.Party) {
if len(party.Emails) > 0 {
@emails(party.Emails)
}
if len(party.Websites) > 0 {
@websites(party.Websites)
}
if showTaxID(party) {
@taxID(party)
}
Expand Down Expand Up @@ -65,6 +68,18 @@ templ emails(emails []*org.Email) {
</div>
}

templ websites(websites []*org.Website) {
for _, web := range websites {
<div class="website">
if web.Label != "" {
@t.T(".website_label", i18n.M{"label": web.Label, "url": web.URL})
} else {
@t.T(".website", i18n.M{"url": web.URL})
}
</div>
}
}

templ identities(idents []*org.Identity) {
for _, ident := range idents {
<div class="identitiy">
Expand Down
Loading

0 comments on commit c73146c

Please sign in to comment.