-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert to EstadoDeCuentaCombustible complement
- Loading branch information
Showing
9 changed files
with
411 additions
and
2,389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package cfdi | ||
|
||
import ( | ||
"encoding/xml" | ||
|
||
"github.com/invopop/gobl/regimes/mx" | ||
) | ||
|
||
// ECC Schema constants | ||
const ( | ||
ECCVersion = "1.2" | ||
ECCTipoOperacion = "Tarjeta" | ||
ECCNamespace = "http://www.sat.gob.mx/EstadoDeCuentaCombustible12" | ||
ECCSchemaLocation = "http://www.sat.gob.mx/sitio_internet/cfd/EstadoDeCuentaCombustible/ecc12.xsd" | ||
) | ||
|
||
// EstadoDeCuentaCombustible stores the fuel account balance data | ||
type EstadoDeCuentaCombustible struct { | ||
XMLName xml.Name `xml:"ecc12:EstadoDeCuentaCombustible"` | ||
Version string `xml:",attr"` | ||
TipoOperacion string `xml:",attr"` | ||
|
||
NumeroDeCuenta string `xml:",attr"` | ||
SubTotal string `xml:",attr"` | ||
Total string `xml:",attr"` | ||
|
||
Conceptos []*ECCConcepto `xml:"ecc12:Conceptos>ecc12:ConceptoEstadoDeCuentaCombustible"` // nolint:misspell | ||
} | ||
|
||
// ECCConcepto stores the data of a fuel purchase | ||
type ECCConcepto struct { | ||
Identificador string `xml:",attr"` | ||
Fecha string `xml:",attr"` | ||
Rfc string `xml:",attr"` | ||
ClaveEstacion string `xml:",attr"` | ||
Cantidad string `xml:",attr"` | ||
TipoCombustible string `xml:",attr"` | ||
Unidad string `xml:",attr,omitempty"` | ||
NombreCombustible string `xml:",attr"` | ||
FolioOperacion string `xml:",attr"` | ||
ValorUnitario string `xml:",attr"` | ||
Importe string `xml:",attr"` | ||
|
||
Traslados []*ECCTraslado `xml:"ecc12:Traslados>ecc12:Traslado"` | ||
} | ||
|
||
// ECCTraslado stores the tax data of a fuel purchase | ||
type ECCTraslado struct { | ||
Impuesto string `xml:",attr"` | ||
TasaOCuota string `xml:",attr"` | ||
Importe string `xml:",attr"` | ||
} | ||
|
||
func addEstadoCuentaCombustible(doc *Document, fc *mx.FuelAccountBalance) { | ||
ecc := &EstadoDeCuentaCombustible{ | ||
Version: ECCVersion, | ||
TipoOperacion: ECCTipoOperacion, | ||
|
||
NumeroDeCuenta: fc.AccountNumber, | ||
SubTotal: fc.Subtotal.String(), | ||
Total: fc.Total.String(), | ||
|
||
Conceptos: newECCConceptos(fc.Lines), // nolint:misspell | ||
} | ||
|
||
doc.ECCNamespace = ECCNamespace | ||
doc.SchemaLocation = doc.SchemaLocation + " " + formatSchemaLocation(ECCNamespace, ECCSchemaLocation) | ||
doc.Complementos = append(doc.Complementos, ecc) | ||
} | ||
|
||
// nolint:misspell | ||
func newECCConceptos(lines []*mx.FuelAccountLine) []*ECCConcepto { | ||
cs := make([]*ECCConcepto, len(lines)) | ||
|
||
for i, l := range lines { | ||
cs[i] = &ECCConcepto{ | ||
Identificador: l.EWalletID.String(), | ||
Fecha: l.PurchaseDateTime.String(), | ||
Rfc: l.VendorTaxCode.String(), | ||
ClaveEstacion: l.ServiceStationCode.String(), | ||
Cantidad: l.Quantity.String(), | ||
TipoCombustible: l.Item.Type.String(), | ||
Unidad: l.Item.Unit.UNECE().String(), | ||
NombreCombustible: l.Item.Name, | ||
FolioOperacion: l.PurchaseCode.String(), | ||
ValorUnitario: l.Item.Price.String(), | ||
Importe: l.Total.String(), | ||
Traslados: newECCTraslados(l.Taxes), | ||
} | ||
} | ||
|
||
return cs | ||
} | ||
|
||
func newECCTraslados(taxes []*mx.FuelAccountTax) []*ECCTraslado { | ||
ts := make([]*ECCTraslado, len(taxes)) | ||
|
||
for i, t := range taxes { | ||
ts[i] = &ECCTraslado{ | ||
Impuesto: t.Code.String(), | ||
TasaOCuota: t.Rate.String(), | ||
Importe: t.Amount.String(), | ||
} | ||
} | ||
|
||
return ts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cfdi_test | ||
|
||
import ( | ||
"testing" | ||
|
||
cfdi "github.com/invopop/gobl.cfdi" | ||
"github.com/invopop/gobl.cfdi/test" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEstadoDeCuentaCombustible(t *testing.T) { | ||
t.Run("should return a Document with the EstadoDeCuentaCombustible data", func(t *testing.T) { | ||
doc, err := test.NewDocumentFrom("fuel-account-balance.json") | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, 1, len(doc.Complementos)) | ||
|
||
ecc := doc.Complementos[0].(*cfdi.EstadoDeCuentaCombustible) | ||
|
||
assert.Equal(t, "0123456789", ecc.NumeroDeCuenta) | ||
assert.Equal(t, "246.13", ecc.SubTotal) | ||
assert.Equal(t, "400.00", ecc.Total) | ||
|
||
require.Equal(t, 2, len(ecc.Conceptos)) | ||
|
||
c := ecc.Conceptos[0] | ||
|
||
assert.Equal(t, "1234", c.Identificador) | ||
assert.Equal(t, "2022-07-19T10:20:30", c.Fecha) | ||
assert.Equal(t, "RWT860605OF5", c.Rfc) | ||
assert.Equal(t, "8171650", c.ClaveEstacion) | ||
assert.Equal(t, "9.661", c.Cantidad) | ||
assert.Equal(t, "3", c.TipoCombustible) | ||
assert.Equal(t, "Diesel", c.NombreCombustible) | ||
assert.Equal(t, "2794668", c.FolioOperacion) | ||
assert.Equal(t, "12.743", c.ValorUnitario) | ||
assert.Equal(t, "123.11", c.Importe) | ||
assert.Equal(t, "LTR", c.Unidad) | ||
|
||
require.Equal(t, 2, len(c.Traslados)) | ||
|
||
ct := c.Traslados[0] | ||
|
||
assert.Equal(t, "IVA", ct.Impuesto) | ||
assert.Equal(t, "0.160000", ct.TasaOCuota) | ||
assert.Equal(t, "19.70", ct.Importe) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.