-
Notifications
You must be signed in to change notification settings - Fork 0
/
food_vouchers.go
75 lines (61 loc) · 2.3 KB
/
food_vouchers.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package cfdi
import (
"encoding/xml"
"github.com/invopop/gobl.cfdi/internal/format"
"github.com/invopop/gobl/regimes/mx"
)
// VD Schema constants
const (
VDVersion = "1.0"
VDTipoOperacion = "monedero electrónico"
VDNamespace = "http://www.sat.gob.mx/valesdedespensa"
VDSchemaLocation = "http://www.sat.gob.mx/sitio_internet/cfd/valesdedespensa/valesdedespensa.xsd"
)
// ValesDeDespensa stores the food vouchers data
type ValesDeDespensa struct {
XMLName xml.Name `xml:"valesdedespensa:ValesDeDespensa"`
Version string `xml:"version,attr"`
TipoOperacion string `xml:"tipoOperacion,attr"`
RegistroPatronal string `xml:"registroPatronal,attr,omitempty"`
NumeroDeCuenta string `xml:"numeroDeCuenta,attr"`
Total string `xml:"total,attr"`
Conceptos []*VDConcepto `xml:"valesdedespensa:Conceptos>valesdedespensa:Concepto"` // nolint:misspell
}
// VDConcepto stores the data of a single food voucher
type VDConcepto struct {
Identificador string `xml:"identificador,attr"`
Fecha string `xml:"fecha,attr"`
Rfc string `xml:"rfc,attr"`
Curp string `xml:"curp,attr"`
Nombre string `xml:"nombre,attr"`
NumSeguridadSocial string `xml:"numSeguridadSocial,attr,omitempty"`
Importe string `xml:"importe,attr"`
}
func addValesDeDespensa(doc *Document, fvc *mx.FoodVouchers) {
vd := &ValesDeDespensa{
Version: VDVersion,
TipoOperacion: VDTipoOperacion,
RegistroPatronal: fvc.EmployerRegistration,
NumeroDeCuenta: fvc.AccountNumber,
Total: fvc.Total.String(),
Conceptos: newVDConceptos(fvc.Lines), // nolint:misspell
}
doc.VDNamespace = VDNamespace
doc.SchemaLocation = doc.SchemaLocation + " " + format.SchemaLocation(VDNamespace, VDSchemaLocation)
doc.AppendComplemento(vd)
}
func newVDConceptos(lines []*mx.FoodVouchersLine) []*VDConcepto {
cs := make([]*VDConcepto, len(lines))
for i, l := range lines {
cs[i] = &VDConcepto{
Identificador: l.EWalletID.String(),
Fecha: l.IssueDateTime.String(),
Rfc: l.Employee.TaxCode.String(),
Curp: l.Employee.CURP.String(),
Nombre: l.Employee.Name,
NumSeguridadSocial: l.Employee.SocialSecurity.String(),
Importe: l.Amount.String(),
}
}
return cs
}