diff --git a/bill/invoice.go b/bill/invoice.go index d85b3562..9f2595f8 100644 --- a/bill/invoice.go +++ b/bill/invoice.go @@ -469,14 +469,14 @@ func (inv *Invoice) calculate(r *tax.Regime, tID *tax.Identity) error { t.round(zero) // Complements - if err := calculateComplements(r, inv.Complements); err != nil { + if err := calculateComplements(inv.Complements); err != nil { return validation.Errors{"complements": err} } return nil } -func calculateComplements(r *tax.Regime, comps []*schema.Object) error { +func calculateComplements(comps []*schema.Object) error { for _, c := range comps { if err := c.Calculate(); err != nil { return err diff --git a/regimes/mx/fuel_account_balance.go b/regimes/mx/fuel_account_balance.go index 62fd9b84..cf9d0623 100644 --- a/regimes/mx/fuel_account_balance.go +++ b/regimes/mx/fuel_account_balance.go @@ -8,15 +8,24 @@ import ( "github.com/invopop/validation" ) +// Constants for the precision of complement's amounts const ( FuelAccountInterimPrecision = 3 FuelAccountFinalPrecision = 2 FuelAccountRatePrecision = 6 +) +// Constants for the complement's allowed tax codes +const ( FuelAccountTaxCodeVAT = cbc.Code("IVA") FuelAccountTaxCodeIEPS = cbc.Code("IEPS") ) +var validTaxCodes = []interface{}{ + FuelAccountTaxCodeVAT, + FuelAccountTaxCodeIEPS, +} + // FuelAccountBalance carries the data to produce a CFDI's "Complemento de // Estado de Cuenta de Combustibles para Monederos Electrónicos" (version 1.2 // revision B) providing detailed information about fuel purchases made with @@ -77,6 +86,7 @@ type FuelAccountTax struct { Amount num.Amount `json:"amount" jsonschema:"title=Amount"` } +// Validate ensures that the complement's data is valid. func (comp *FuelAccountBalance) Validate() error { return validation.ValidateStruct(comp, validation.Field(&comp.AccountNumber, @@ -128,11 +138,6 @@ func validateFuelAccountLine(value interface{}) error { ) } -var validTaxCodes = []interface{}{ - FuelAccountTaxCodeVAT, - FuelAccountTaxCodeIEPS, -} - func validateFuelAccountTax(value interface{}) error { tax, _ := value.(*FuelAccountTax) if tax == nil { @@ -155,6 +160,7 @@ func isValidLineTotal(line *FuelAccountLine) validation.Rule { return validation.In(expected).Error("must be quantity x unit_price") } +// Calculate performs the complement's calculations and normalisations. func (comp *FuelAccountBalance) Calculate() error { var subtotal, taxtotal num.Amount