|
6 | 6 | "fmt" |
7 | 7 |
|
8 | 8 | "github.com/invopop/gobl.html/components/t" |
| 9 | + "github.com/invopop/gobl/bill" |
9 | 10 | "github.com/invopop/gobl/org" |
| 11 | + "github.com/invopop/gobl/tax" |
10 | 12 | "github.com/yuin/goldmark" |
11 | 13 | "github.com/yuin/goldmark/extension" |
12 | 14 | "github.com/yuin/goldmark/renderer/html" |
@@ -58,6 +60,40 @@ templ note(note *org.Note) { |
58 | 60 | </div> |
59 | 61 | } |
60 | 62 |
|
| 63 | +// invoiceNotes converts tax notes to org notes (with bold category prefix) |
| 64 | +// and prepends them to the invoice's regular notes. |
| 65 | +func invoiceNotes(ctx context.Context, inv *bill.Invoice) []*org.Note { |
| 66 | + var result []*org.Note |
| 67 | + if inv.Tax != nil { |
| 68 | + r := inv.RegimeDef() |
| 69 | + for _, tn := range inv.Tax.Notes { |
| 70 | + result = append(result, &org.Note{ |
| 71 | + Text: renderTaxNoteText(ctx, r, tn), |
| 72 | + }) |
| 73 | + } |
| 74 | + } |
| 75 | + result = append(result, inv.Notes...) |
| 76 | + return result |
| 77 | +} |
| 78 | + |
| 79 | +// renderTaxNoteText returns formatted markdown text for a tax note, |
| 80 | +// with a bold category prefix when available. |
| 81 | +func renderTaxNoteText(ctx context.Context, r *tax.RegimeDef, n *tax.Note) string { |
| 82 | + txt := n.Text |
| 83 | + prefix := "" |
| 84 | + if n.Category != "" { |
| 85 | + if cd := r.CategoryDef(n.Category); cd != nil { |
| 86 | + prefix = cd.Name.In(t.Lang(ctx)) |
| 87 | + } else { |
| 88 | + prefix = n.Category.String() |
| 89 | + } |
| 90 | + } |
| 91 | + if prefix != "" { |
| 92 | + txt = fmt.Sprintf("%s · %s", prefix, txt) |
| 93 | + } |
| 94 | + return txt |
| 95 | +} |
| 96 | + |
61 | 97 | func renderNote(note *org.Note) string { |
62 | 98 | txt := note.Text |
63 | 99 | if note.Code != "" { |
|
0 commit comments