forked from edmt/xml2sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.go
More file actions
128 lines (109 loc) · 3.84 KB
/
schema.go
File metadata and controls
128 lines (109 loc) · 3.84 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"encoding/xml"
"fmt"
"time"
)
type Doc struct {
XMLName xml.Name `xml:"Comprobante"`
Tipo string `xml:"tipoDeComprobante,attr"`
Version string `xml:"version,attr"`
Serie string `xml:"serie,attr"`
Folio string `xml:"folio,attr"`
Fecha string `xml:"fecha,attr"`
Moneda string `xml:"Moneda,attr"`
TipoCambio string `xml:"TipoCambio,attr"`
Total string `xml:"total,attr"`
SubTotal string `xml:"subTotal,attr"`
MetodoDePago string `xml:"metodoDePago,attr"`
LugarExpedicion string `xml:"LugarExpedicion,attr"`
NoCertificado string `xml:"noCertificado,attr"`
Emisor CFDIEmisor `xml:"Emisor"`
Receptor CFDIReceptor `xml:"Receptor"`
Conceptos []CFDIConcepto `xml:"Conceptos>Concepto"`
Impuestos CFDIImpuestos `xml:"Impuestos"`
Complemento CFDIComplemento `xml:"Complemento"`
Addenda CFDIAddenda `xml:"Addenda"`
}
type CFDIImpuestos struct {
XMLName xml.Name `xml:"Impuestos"`
Total string `xml:"totalImpuestosTrasladados,attr"`
Traslados CFDITraslados `xml:"Traslados"`
}
type CFDITraslados struct {
XMLName xml.Name `xml:"Traslados"`
Traslado CFDITraslado `xml:"Traslado"`
}
type CFDITraslado struct {
XMLName xml.Name `xml:"Traslado"`
Importe string `xml:"importe,attr"`
}
type CFDIAddenda struct {
XMLName xml.Name `xml:"Addenda"`
AddendaBuzonFiscal AddendaBuzonFiscalNode `xml:"AddendaBuzonFiscal"`
}
type AddendaBuzonFiscalNode struct {
XMLName xml.Name `xml:"AddendaBuzonFiscal"`
CFD CFDNode `xml:"CFD"`
}
type CFDNode struct {
XMLName xml.Name `xml:"CFD"`
RefID string `xml:"refID,attr"`
}
type CFDIEmisor struct {
XMLName xml.Name `xml:"Emisor"`
RFC string `xml:"rfc,attr"`
Nombre string `xml:"nombre,attr"`
DomicilioFiscal EmisorDomicilioFiscalNode `xml:"DomicilioFiscal"`
}
type EmisorDomicilioFiscalNode struct {
XMLName xml.Name `xml:"DomicilioFiscal"`
Municipio string `xml:"municipio,attr"`
Estado string `xml:"estado,attr"`
}
type CFDIReceptor struct {
XMLName xml.Name `xml:"Receptor"`
RFC string `xml:"rfc,attr"`
Nombre string `xml:"nombre,attr"`
}
type CFDIConcepto struct {
XMLName xml.Name `xml:"Concepto"`
Descripcion string `xml:"descripcion,attr"`
NoIdentificacion string `xml:"noIdentificacion,attr"`
Cantidad string `xml:"cantidad,attr"`
Unidad string `xml:"unidad,attr"`
ValorUnitario string `xml:"valorUnitario,attr"`
Importe string `xml:"importe,attr"`
}
type CFDIComplemento struct {
XMLName xml.Name `xml:"Complemento"`
TimbreFiscalDigital TFDTimbreFiscalDigital `xml:"TimbreFiscalDigital"`
Nomina NominaNomina `xml:"Nomina"`
}
type TFDTimbreFiscalDigital struct {
XMLName xml.Name `xml:"TimbreFiscalDigital"`
NumeroCertificado string `xml:"noCertificadoSAT,attr"`
FechaTimbrado string `xml:"FechaTimbrado,attr"`
UUID string `xml:"UUID,attr"`
}
type NominaNomina struct {
XMLName xml.Name `xml:"Nomina"`
FechaInicialPago string `xml:"FechaInicialPago,attr"`
FechaFinalPago string `xml:"FechaFinalPago,attr"`
}
func (d Doc) NumeroDeFactura() string {
return fmt.Sprintf("%s-%s", d.Serie, d.Folio)
}
func (tfd TFDTimbreFiscalDigital) FechaTimbre() string {
layout := "2006-01-02T15:04:05"
t, err := time.Parse(layout, tfd.FechaTimbrado)
if err != nil {
return ""
}
return fmt.Sprintf("%d-%02d-%02d", t.Year(), t.Month(), t.Day())
}
func parseXml(doc []byte) Doc {
var query Doc
xml.Unmarshal(doc, &query)
return query
}