-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparties.go
73 lines (65 loc) · 2.22 KB
/
parties.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
package cfdi
import (
"github.com/invopop/gobl/addons/mx/cfdi"
"github.com/invopop/gobl/l10n"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/mx"
)
// Emisor stores the invoice supplier data
type Emisor struct {
Rfc string `xml:",attr"`
Nombre string `xml:",attr"`
RegimenFiscal string `xml:",attr"`
}
// Receptor stores the invoice customer data
type Receptor struct {
Rfc string `xml:",attr"`
Nombre string `xml:",attr"`
DomicilioFiscalReceptor string `xml:",attr"`
RegimenFiscalReceptor string `xml:",attr"`
UsoCFDI string `xml:",attr"`
NumRegIdTrib string `xml:",attr,omitempty"` //nolint:revive
ResidenciaFiscal string `xml:",attr,omitempty"`
}
func newEmisor(supplier *org.Party) *Emisor {
emisor := &Emisor{
Rfc: supplier.TaxID.Code.String(),
Nombre: supplier.Name,
RegimenFiscal: supplier.Ext[cfdi.ExtKeyFiscalRegime].String(),
}
return emisor
}
func newReceptor(customer *org.Party, issuePlace string) *Receptor {
if customer == nil {
return &Receptor{
Nombre: NombreReceptorGenerico,
Rfc: mx.TaxIdentityCodeGeneric.String(),
RegimenFiscalReceptor: RegimenFiscalSinObligaciones,
UsoCFDI: UsoCFDISinEfectos,
DomicilioFiscalReceptor: issuePlace,
}
}
if customer.TaxID.Country.Code() != l10n.MX {
cd := l10n.Countries().Code(customer.TaxID.Country.Code())
return &Receptor{
Nombre: customer.Name,
Rfc: mx.TaxIdentityCodeForeign.String(),
RegimenFiscalReceptor: RegimenFiscalSinObligaciones,
UsoCFDI: UsoCFDISinEfectos,
DomicilioFiscalReceptor: issuePlace,
NumRegIdTrib: customer.TaxID.Code.String(),
ResidenciaFiscal: cd.Alpha3,
}
}
var postcode string
if len(customer.Addresses) > 0 {
postcode = customer.Addresses[0].Code.String()
}
return &Receptor{
Nombre: customer.Name,
Rfc: customer.TaxID.Code.String(),
RegimenFiscalReceptor: customer.Ext[cfdi.ExtKeyFiscalRegime].String(),
UsoCFDI: customer.Ext[cfdi.ExtKeyUse].String(),
DomicilioFiscalReceptor: postcode,
}
}