/
lines.go
54 lines (45 loc) · 1.46 KB
/
lines.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package cfdi
import (
"github.com/invopop/gobl.cfdi/internal"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/tax"
)
// Conceptos list invoice lines
// nolint:misspell
type Conceptos struct {
Concepto []*Concepto `xml:"cfdi:Concepto"`
}
// Concepto stores an invoice line data
type Concepto struct {
ClaveProdServ string `xml:",attr"`
Cantidad string `xml:",attr"`
ClaveUnidad string `xml:",attr"`
Descripcion string `xml:",attr"` // nolint:misspell
ValorUnitario string `xml:",attr"`
Importe string `xml:",attr"`
Descuento string `xml:",attr,omitempty"`
ObjetoImp string `xml:",attr"`
Impuestos *ConceptoImpuestos `xml:"cfdi:Impuestos,omitempty"`
}
// nolint:misspell
func newConceptos(lines []*bill.Line, regime *tax.Regime) *Conceptos {
var conceptos []*Concepto
for _, line := range lines {
conceptos = append(conceptos, newConcepto(line, regime))
}
return &Conceptos{conceptos}
}
func newConcepto(line *bill.Line, regime *tax.Regime) *Concepto {
concepto := &Concepto{
ClaveProdServ: internal.ClaveProdServ(line).String(),
Cantidad: line.Quantity.String(),
ClaveUnidad: internal.ClaveUnidad(line).String(),
Descripcion: line.Item.Name, // nolint:misspell
ValorUnitario: line.Item.Price.String(),
Importe: line.Sum.String(),
Descuento: formatOptionalAmount(internal.TotalLineDiscount(line)),
ObjetoImp: ObjetoImpSi,
Impuestos: newConceptoImpuestos(line, regime),
}
return concepto
}