Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portugal #6

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/bill/invoice/invoice.templ
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/invopop/gobl.html/components/regimes/mx"
"github.com/invopop/gobl.html/internal"
"github.com/invopop/gobl.html/components/regimes/pl"
"github.com/invopop/gobl.html/components/regimes/pt"
)

// Invoice renders a complete GOBL bill.Invoice object.
Expand Down Expand Up @@ -44,6 +45,7 @@ templ Invoice(env *gobl.Envelope, inv *bill.Invoice) {
@co.DIANQR(env, inv)
@mx.CFDI(env, inv)
@pl.KSeFQR(env)
@pt.ATQR(env)
</div>
</article>
}
Expand Down
9 changes: 7 additions & 2 deletions components/bill/invoice/invoice_templ.go

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

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.

Loading
Loading