-
Notifications
You must be signed in to change notification settings - Fork 0
/
preceding.go
58 lines (47 loc) · 1.18 KB
/
preceding.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
55
56
57
58
package cfdi
import (
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/regimes/mx"
)
// CFDIRelacionados list the preceding CFDI documents (e.g., the preceding
// invoices of a credit note)
type CFDIRelacionados struct { // nolint:revive
TipoRelacion string `xml:",attr"`
CfdiRelacionado []CFDIRelacionado `xml:"cfdi:CfdiRelacionado"`
}
// CFDIRelacionado stores the data of a preceding CFDI document
type CFDIRelacionado struct { // nolint:revive
UUID string `xml:",attr"`
}
func newCfdiRelacionados(inv *bill.Invoice) *CFDIRelacionados {
if len(inv.Preceding) == 0 {
return nil
}
crs := &CFDIRelacionados{
TipoRelacion: lookupTipoRelacion(inv),
}
for _, p := range inv.Preceding {
uuid := lookupUUID(p)
if uuid != "" {
cr := CFDIRelacionado{uuid}
crs.CfdiRelacionado = append(crs.CfdiRelacionado, cr)
}
}
return crs
}
func lookupUUID(p *bill.Preceding) string {
for _, s := range p.Stamps {
if s.Provider == mx.StampSATUUID {
return s.Value
}
}
return ""
}
func lookupTipoRelacion(inv *bill.Invoice) string {
ss := inv.ScenarioSummary()
if ss == nil {
return ""
}
code := ss.Codes[mx.KeySATTipoRelacion]
return code.String()
}