cfdi

package
v0.216.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package cfdi implements the CFDI (Comprobante Fiscal Digital por Internet) extensions and validation rules that need to be applied to GOBL documents in order to comply with the Mexican tax authority (SAT).

Index

Constants

View Source
const (
	StampSignature cbc.Key = "cfdi-sig"    // Signature - Sello Digital del CFDI
	StampSerial    cbc.Key = "cfdi-serial" // Cert Serial - Número de Certificado del CFDI
)

Official CFDI codes to include in stamps.

View Source
const (
	ExtKeyIssuePlace   cbc.Key = "mx-cfdi-issue-place"
	ExtKeyFiscalRegime cbc.Key = "mx-cfdi-fiscal-regime"
	ExtKeyUse          cbc.Key = "mx-cfdi-use"
	ExtKeyProdServ     cbc.Key = "mx-cfdi-prod-serv"     // name from XML field: ClaveProdServ
	ExtKeyRelType      cbc.Key = "mx-cfdi-rel-type"      // name from XML field: TipoRelacion
	ExtKeyDocType      cbc.Key = "mx-cfdi-doc-type"      // name from XML field: TipoDeComprobante
	ExtKeyTaxType      cbc.Key = "mx-cfdi-tax-type"      // name from XML field: TipoImpuesto
	ExtKeyPaymentMeans cbc.Key = "mx-cfdi-payment-means" // name from XML field: FormaPago
	ExtKeyGlobalPeriod cbc.Key = "mx-cfdi-global-period"
	ExtKeyGlobalMonth  cbc.Key = "mx-cfdi-global-month"
	ExtKeyGlobalYear   cbc.Key = "mx-cfdi-global-year"
)

Mexican CFDI extension keys required by the SAT (tax authority in Mexico) in all invoices and cannot be determined automatically.

View Source
const (
	CURPPattern           = "" /* 132-byte string literal not displayed */
	SocialSecurityPattern = "^[0-9]{11}$"
	PostCodePattern       = "^[0-9]{5}$"
)

Complement's Codes Patterns

View Source
const (
	FuelAccountPriceMinimumPrecision = 3
	FuelAccountTotalsPrecision       = 2
)

Constants for the precision of complement's amounts

View Source
const (
	MeansKeyWallet          cbc.Key = "wallet"
	MeansKeyGroceryVouchers cbc.Key = "grocery-vouchers"
	MeansKeyInKind          cbc.Key = "in-kind"
	MeansKeySubrogation     cbc.Key = "subrogation"
	MeansKeyConsignment     cbc.Key = "consignment"
	MeansKeyDebtRelief      cbc.Key = "debt-relief"
	MeansKeyNovation        cbc.Key = "novation"
	MeansKeyMerger          cbc.Key = "merger"
	MeansKeyRemission       cbc.Key = "remission"
	MeansKeyExpiration      cbc.Key = "expiration"
	MeansKeySatisfyCreditor cbc.Key = "satisfy-creditor"
	MeansKeyDebit           cbc.Key = "debit"
	MeansKeyServices        cbc.Key = "services"
	MeansKeyAdvance         cbc.Key = "advance"
	MeansKeyIntermediary    cbc.Key = "intermediary"
)

Regime Specific Payment Means Extension Keys

View Source
const (
	FoodVouchersFinalPrecision = 2
)

Constants for the precision of the complement's amounts

View Source
const (
	TagGlobal cbc.Key = "global"
)

Tags used to add validation or normalization rules.

View Source
const (
	V4 cbc.Key = "mx-cfdi-v4"
)

Key to identify the CFDI addon.

Variables

View Source
var (
	CURPRegexp           = regexp.MustCompile(CURPPattern)
	SocialSecurityRegexp = regexp.MustCompile(SocialSecurityPattern)
	PostCodeRegexp       = regexp.MustCompile(PostCodePattern)
)

Complement's Codes Regexps

View Source
var FuelAccountValidTaxCodes = []any{
	tax.CategoryVAT,
	mx.TaxCategoryIEPS,
}

FuelAccountValidTaxCodes lists of the complement's allowed tax codes

Functions

func PaymentMeansExtensions

func PaymentMeansExtensions() tax.Extensions

PaymentMeansExtensions returns the mapping of payment means to their extension values used by CFDI.

Types

type FoodVouchers

type FoodVouchers struct {
	// Customer's employer registration number (maps to `registroPatronal`).
	EmployerRegistration string `json:"employer_registration,omitempty" jsonschema:"title=Employer Registration"`
	// Customer's account number (maps to `numeroDeCuenta`).
	AccountNumber string `json:"account_number" jsonschema:"title=Account Number"`
	// Sum of all line amounts (calculated, maps to `total`).
	Total num.Amount `json:"total" jsonschema:"title=Total" jsonschema_extras:"calculated=true"`
	// List of food vouchers issued to the customer's employees (maps to `Conceptos`).
	Lines []*FoodVouchersLine `json:"lines" jsonschema:"title=Lines"`
}

FoodVouchers carries the data to produce a CFDI's "Complemento de Vales de Despensa" (version 1.0) providing detailed information about food vouchers issued by an e-wallet supplier to its customer's employees.

This struct maps to the `ValesDeDespensa` root node in the CFDI's complement.

func (*FoodVouchers) Calculate

func (fvc *FoodVouchers) Calculate() error

Calculate performs the complement's calculations and normalisations.

func (*FoodVouchers) Validate

func (fvc *FoodVouchers) Validate() error

Validate checks the FoodVouchers data according to the SAT's rules for the "Complemento de Vales de Despensa".

type FoodVouchersEmployee

type FoodVouchersEmployee struct {
	// Employee's tax identity code (maps to `rfc`).
	TaxCode cbc.Code `json:"tax_code" jsonschema:"title=Employee's Tax Identity Code"`
	// Employee's CURP ("Clave Única de Registro de Población", maps to `curp`).
	CURP cbc.Code `json:"curp" jsonschema:"title=Employee's CURP"`
	// Employee's name (maps to `nombre`).
	Name string `json:"name" jsonschema:"title=Employee's Name"`
	// Employee's Social Security Number (maps to `numSeguridadSocial`).
	SocialSecurity cbc.Code `json:"social_security,omitempty" jsonschema:"title=Employee's Social Security Number"`
}

FoodVouchersEmployee represents an employee that received a food voucher. It groups employee related field that appears under the `Concepto` node in the CFDI's complement.

func (*FoodVouchersEmployee) Validate

func (fve *FoodVouchersEmployee) Validate() error

Validate checks the FoodVouchersEmployee data is valid.

type FoodVouchersLine

type FoodVouchersLine struct {
	// Line number starting from 1 (calculated).
	Index int `json:"i" jsonschema:"title=Index" jsonschema_extras:"calculated=true"`
	// Identifier of the e-wallet that received the food voucher (maps to `Identificador`).
	EWalletID cbc.Code `json:"e_wallet_id" jsonschema:"title=E-wallet Identifier"`
	// Date and time of the food voucher's issue (maps to `Fecha`).
	IssueDateTime cal.DateTime `json:"issue_date_time" jsonschema:"title=Issue Date and Time"`
	// Employee that received the food voucher.
	Employee *FoodVouchersEmployee `json:"employee,omitempty" jsonschema:"title=Employee"`
	// Amount of the food voucher (maps to `importe`).
	Amount num.Amount `json:"amount" jsonschema:"title=Amount"`
}

FoodVouchersLine represents a single food voucher issued to the e-wallet of one of the customer's employees. It maps to one `Concepto` node in the CFDI's complement.

func (*FoodVouchersLine) Validate

func (fvl *FoodVouchersLine) Validate() error

Validate checks the FoodVouchersLine data is valid.

type FuelAccountBalance

type FuelAccountBalance struct {
	// Customer's account number (maps to `NumeroDeCuenta`).
	AccountNumber string `json:"account_number" jsonschema:"title=Account Number"`
	// Sum of all line totals (i.e. taxes not included) (calculated, maps to `SubTotal`).
	Subtotal num.Amount `json:"subtotal" jsonschema:"title=Subtotal" jsonschema_extras:"calculated=true"`
	// Grand total after taxes have been applied (calculated, maps to `Total`).
	Total num.Amount `json:"total" jsonschema:"title=Total" jsonschema_extras:"calculated=true"`
	// List of fuel purchases made with the customer's e-wallets (maps to `Conceptos`).
	Lines []*FuelAccountLine `json:"lines" jsonschema:"title=Lines"`
}

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 electronic wallets. In Mexico, e-wallet suppliers are required to report this complementary information in the invoices they issue to their customers.

This struct maps to the `EstadoDeCuentaCombustible` root node in the CFDI's complement.

func (*FuelAccountBalance) Calculate

func (fab *FuelAccountBalance) Calculate() error

Calculate performs the complement's calculations and normalisations.

func (*FuelAccountBalance) Validate

func (fab *FuelAccountBalance) Validate() error

Validate ensures that the complement's data is valid.

type FuelAccountItem

type FuelAccountItem struct {
	// Type of fuel (one of `c_ClaveTipoCombustible` codes, maps to `TipoCombustible`).
	Type cbc.Code `json:"type" jsonschema:"title=Type"`
	// Reference unit of measure used in the price and the quantity (maps to `Unidad`).
	Unit org.Unit `json:"unit,omitempty" jsonschema:"title=Unit"`
	// Name of the fuel (maps to `NombreCombustible`).
	Name string `json:"name" jsonschema:"title=Name"`
	// Base price of a single unit of the fuel without taxes (maps to `ValorUnitario`).
	Price num.Amount `json:"price" jsonschema:"title=Price"`
}

FuelAccountItem provides the details of a fuel purchase. Its fields map to attributes of the `ConceptoEstadoDeCuentaCombustible` node in the CFDI's complement.

func (*FuelAccountItem) Validate

func (fai *FuelAccountItem) Validate() error

Validate ensures that the item's data is valid.

type FuelAccountLine

type FuelAccountLine struct {
	// Index of the line starting from 1 (calculated)
	Index int `json:"i" jsonschema:"title=Index" jsonschema_extras:"calculated=true"`
	// Identifier of the e-wallet used to make the purchase (maps to `Identificador`).
	EWalletID cbc.Code `json:"e_wallet_id" jsonschema:"title=E-wallet Identifier"`
	// Date and time of the purchase (maps to `Fecha`).
	PurchaseDateTime cal.DateTime `json:"purchase_date_time" jsonschema:"title=Purchase Date and Time"`
	// Tax Identity Code of the fuel's vendor (maps to `Rfc`)
	VendorTaxCode cbc.Code `json:"vendor_tax_code" jsonschema:"title=Vendor's Tax Identity Code"`
	// Code of the service station where the purchase was made (maps to `ClaveEstacion`).
	ServiceStationCode cbc.Code `json:"service_station_code" jsonschema:"title=Service Station Code"`
	// Amount of fuel units purchased (maps to `Cantidad`)
	Quantity num.Amount `json:"quantity" jsonschema:"title=Quantity"`
	// Details of the fuel purchased.
	Item *FuelAccountItem `json:"item" jsonschema:"title=Item"`
	// Identifier of the purchase (maps to `FolioOperacion`).
	PurchaseCode cbc.Code `json:"purchase_code" jsonschema:"title=Purchase Code"`
	// Result of quantity multiplied by the unit price (maps to `Importe`).
	Total num.Amount `json:"total" jsonschema:"title=Total" jsonschema_extras:"calculated=true"`
	// Map of taxes applied to the purchase (maps to `Traslados`).
	Taxes []*FuelAccountTax `json:"taxes" jsonschema:"title=Taxes"`
}

FuelAccountLine represents a single fuel purchase made with an e-wallet issued by the invoice's supplier. It maps to one `ConceptoEstadoDeCuentaCombustible` node in the CFDI's complement.

func (*FuelAccountLine) Validate

func (fal *FuelAccountLine) Validate() error

Validate ensures that the line's data is valid.

type FuelAccountTax

type FuelAccountTax struct {
	// Category that identifies the tax ("VAT" or "IEPS", maps to `Impuesto`)
	Category cbc.Code `json:"cat" jsonschema:"title=Category"`
	// Percent applicable to the line total (tasa) to use instead of Rate (maps to `TasaoCuota`)
	Percent *num.Percentage `json:"percent,omitempty" jsonschema:"title=Percent"`
	// Rate is a fixed fee to apply to the line quantity (cuota) (maps to `TasaOCuota`)
	Rate *num.Amount `json:"rate,omitempty" jsonschema:"title=Rate"`
	// Total amount of the tax once the percent or rate has been applied (maps to `Importe`).
	Amount num.Amount `json:"amount" jsonschema:"title=Amount" jsonschema_extras:"calculated=true"`
}

FuelAccountTax represents a single tax applied to a fuel purchase. It maps to one `Traslado` node in the CFDI's complement.

func (*FuelAccountTax) Validate

func (fat *FuelAccountTax) Validate() error

Validate ensures that the tax's data is valid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL