Documentation
¶
Index ¶
- Constants
- Variables
- func Encode(doc *Document) ([]byte, error)
- func Import(doc *Document) (*gobl.Envelope, error)
- type AdditionalData
- type Address
- type AdministrativeCentre
- type AdministrativeCentres
- type Amount
- type BankAccount
- type Batch
- type CertificateRepo
- type Charge
- type Charges
- type ContactDetails
- type Corrective
- type Discount
- type Discounts
- type Document
- type ExchangeRateDetails
- type FileHeader
- type Individual
- type Installment
- type Invoice
- type InvoiceHeader
- type InvoiceIssueData
- type InvoiceLine
- type InvoiceTotals
- type Invoices
- type Items
- type LegalEntity
- type LegalLiterals
- type Option
- type OverseasAddress
- type Parties
- type Party
- type PaymentDetails
- type PaymentOnAccount
- type PaymentsOnAccount
- type PeriodDates
- type ReimbursableExpense
- type ReimbursableExpenses
- type SpecialTaxableEvent
- type SpecialTaxableEventCode
- type Subsidies
- type Subsidy
- type Tax
- type TaxID
- type TaxSummary
- type ThirdParty
Constants ¶
const ( NamespaceFacturaE = "http://www.facturae.gob.es/formato/Versiones/Facturaev3_2_2.xml" NamespaceDSig = "http://www.w3.org/2000/09/xmldsig#" )
Namespaces used for FacturaE. DSig stuff is handled in the signatures.
const ( XAdESSupplier xmldsig.XAdESSignerRole = "supplier" XAdESCustomer xmldsig.XAdESSignerRole = "customer" XAdESThirdParty xmldsig.XAdESSignerRole = "third party" )
XAdES Signer Roles used for FacturaE
const ( ModalityIndividual = "I" // Individual ModalityBatch = "L" // Batch or multiple invoices in on document )
List of accepted Mobility Types
const ( InvoiceIssuerSeller = "EM" // Seller InvoiceIssuerBuyer = " RE" // Buyer InvoiceIssuerThirdParty = "TE" // Third party )
List of accepted Issuer Types
const ( RoleTypeFiscal = "01" // Oficina Contable RoleTypeReceiver = "02" // Órgano Gestor RoleTypePayer = "03" // Unidad Tramitadora )
Administrative centre role type codes for FACe
const ES string = "ESP"
ES is the ISO Alpha-3 code used for Spain
const KeyFacturaE cbc.Key = "es-facturae-v3"
KeyFacturaE identifies the FacturaE 3.2.2 format in the GOBL convert register.
Variables ¶
var (
ErrCertificateNotFound = errors.New("certificate-not-found")
)
Standard error messages for the repo
var ErrUnsupportedBatch = errors.New("facturae documents must contain a single invoice")
ErrUnsupportedBatch is returned when importing a document that does not contain exactly one invoice.
var ErrUnsupportedDocument = errors.New("unsupported document: expected FacturaE 3.2.2")
ErrUnsupportedDocument is returned when decoding data that is not a FacturaE 3.2.2 document.
Functions ¶
Types ¶
type AdditionalData ¶
type AdditionalData struct {
InvoiceAdditionalInformation string `xml:"InvoiceAdditionalInformation,omitempty"`
}
AdditionalData stores notes that the provider of the invoice estimates are needed
type Address ¶
type Address struct {
Address string `xml:"Address,omitempty"`
PostCode string `xml:"PostCode,omitempty"`
Town string `xml:"Town,omitempty"`
Province string `xml:"Province,omitempty"`
CountryCode string `xml:"CountryCode,omitempty"`
}
Address stores location information for addresses in Spain
type AdministrativeCentre ¶
type AdministrativeCentre struct {
CentreCode string `xml:"CentreCode,omitempty"`
RoleTypeCode string `xml:"RoleTypeCode,omitempty"`
AddressInSpain *Address `xml:"AddressInSpain,omitempty"`
OverseasAddress *OverseasAddress `xml:"OverseasAddress,omitempty"`
}
AdministrativeCentre represents an administrative unit within a public administration
type AdministrativeCentres ¶
type AdministrativeCentres struct {
Centres []*AdministrativeCentre `xml:"AdministrativeCentre"`
}
AdministrativeCentres contains a list of administrative centres required for invoicing Spanish public administrations (FACe)
type Amount ¶
type Amount struct {
TotalAmount string `xml:"TotalAmount"`
EquivalentInEuros string `xml:"EquivalentInEuros,omitempty"`
}
Amount wraps the Facturae AmountType. Monetary values rendered through amount are rounded to two decimals per Orden HAP/1650/2015 Annex II rule 6; unit prices and tax rates are the regulation's explicit exceptions and do not flow through this type.
type BankAccount ¶
type BankAccount struct {
IBAN string `xml:"IBAN,omitempty"`
AccountNumber string `xml:"AccountNumber,omitempty"`
BranchInSpainAddress *Address `xml:"BranchInSpainAddress,omitempty"`
OverseasBranchAddress *Address `xml:"OverseasBranchAddress,omitempty"`
BIC string `xml:"BIC,omitempty"`
}
BankAccount contains info needed to pay by transfer or direct debit
type Batch ¶
type Batch struct {
BatchIdentifier string `xml:"BatchIdentifier"`
InvoicesCount int `xml:"InvoicesCount"`
TotalInvoicesAmount Amount `xml:"TotalInvoicesAmount"`
TotalOutstandingAmount Amount `xml:"TotalOutstandingAmount"`
TotalExecutableAmount Amount `xml:"TotalExecutableAmount"`
InvoiceCurrencyCode string `xml:"InvoiceCurrencyCode"`
}
Batch would contain info about a group of invoices that are submitted at the same time, but we only allow one invoice at a time
type CertificateRepo ¶
type CertificateRepo struct {
// contains filtered or unexported fields
}
CertificateRepo is an implementation of the CertificateRepo that loads the certificate from a local file
func NewCertificateRepo ¶
func NewCertificateRepo(path string) (*CertificateRepo, error)
NewCertificateRepo instantiates a new repository of certificates stored in a local directory. Each certificate found will be parsed and stored in a map of file names without extension to certificate instances.
func (*CertificateRepo) Get ¶
func (repo *CertificateRepo) Get(id string) (*xmldsig.Certificate, error)
Get returns the local pre-loaded certificate
type Charge ¶
type Charge struct {
Reason string `xml:"ChargeReason"`
Rate string `xml:"ChargeRate,omitempty"`
Amount string `xml:"ChargeAmount"`
}
Charge defines the basic data for a single surcharge.
type Charges ¶
type Charges struct {
Items []*Charge `xml:"Charge"`
}
Charges contains a list of charge instances. This is used both at a line and document level as per the FacturaE specification. Unfortunately, this implies that taxes will not be applied in the context of a global charge. We recommend avoiding using this in Spanish invoices.
type ContactDetails ¶
type ContactDetails struct {
Telephone string `xml:"Telephone,omitempty"`
TeleFax string `xml:"TeleFax,omitempty"`
WebAddress string `xml:"WebAddress,omitempty"`
ElectronicMail string `xml:"ElectronicMail,omitempty"`
ContactPersons string `xml:"ContactPersons,omitempty"`
CnoCnae string `xml:"CnoCnae,omitempty"` // Code of economic activity from INE
INETownCode string `xml:"INETownCode,omitempty"` // Code of town allocated by INE
AdditionalContactDetails string `xml:"AdditionalContactDetails,omitempty"`
}
ContactDetails store info about how to contact the party
type Corrective ¶
type Corrective struct {
InvoiceNumber string `xml:"InvoiceNumber,omitempty"`
InvoiceSeriesCode string `xml:"InvoiceSeriesCode,omitempty"`
ReasonCode string `xml:"ReasonCode"`
ReasonDescription string `xml:"ReasonDescription"`
TaxPeriod *PeriodDates `xml:"TaxPeriod"`
CorrectionMethod string `xml:"CorrectionMethod"`
CorrectionMethodDescription string `xml:"CorrectionMethodDescription"`
AdditionalReasonDescription string `xml:"AdditionalReasonDescription,omitempty"`
InvoiceIssueDate string `xml:"InvoiceIssueDate,omitempty"`
}
Corrective is used to represent the details of a previous invoice that this one serves to modify or replace. Details here are a bit sketchy as in practical usage, most companies don't demand this level of detail.
type Discount ¶
type Discount struct {
Reason string `xml:"DiscountReason"`
Rate string `xml:"DiscountRate,omitempty"`
Amount string `xml:"DiscountAmount"`
}
Discount is used in general and line discounts. Unlike in GOBL, FacturaE does not differentiate between the two, which could potentially lead to confusion for handling taxes.
type Discounts ¶
type Discounts struct {
Items []*Discount `xml:"Discount"`
}
Discounts list discounts applied on a line or document level.
type Document ¶
type Document struct {
XMLName xml.Name `xml:"fe:Facturae"`
FeNamespace string `xml:"xmlns:fe,attr"`
FileHeader *FileHeader `xml:"FileHeader"`
Parties *Parties `xml:"Parties"`
Invoices *Invoices `xml:"Invoices"`
Signature *xmldsig.Signature `xml:"ds:Signature,omitempty"`
// contains filtered or unexported fields
}
Document is a pseudo-model for containing the XML document being created.
func Decode ¶ added in v0.24.0
Decode parses FacturaE 3.2.2 XML data into a document. Signatures are read but not verified.
func Export ¶ added in v0.24.0
Export converts the invoice in the GOBL envelope into a FacturaE document, signed when a certificate is provided.
func (*Document) BytesIndent ¶
BytesIndent returns the XML document bytes with indentation for readability. This is useful for debugging and testing purposes, but should not be used in production as it will not work correctly with digital signatures.
func (*Document) Canonical ¶
Canonical converts a struct representation of facturae to its canonical representation as defined in https://www.w3.org/TR/2001/REC-xml-c14n-20010315 (for a simpler explanation look at https://www.di-mgt.com.au/xmldsig-c14n.html) This is used when we need to create a hash for signing, timestamping, ...
type ExchangeRateDetails ¶
type ExchangeRateDetails struct {
ExchangeRate string `xml:"ExchangeRate"`
ExchangeRateDate string `xml:"ExchangeRateDate"`
}
ExchangeRateDetails describes how to exchange from the invoices currency to euros.
type FileHeader ¶
type FileHeader struct {
SchemaVersion string `xml:"SchemaVersion"`
Modality string `xml:"Modality"`
InvoiceIssuerType string `xml:"InvoiceIssuerType"` // Who is signing the invoice?
ThirdParty *ThirdParty `xml:"ThirdParty,omitempty"`
Batch *Batch `xml:"Batch"`
}
FileHeader contains the FileHeader element of a facturae invoice
type Individual ¶
type Individual struct {
Name string `xml:"Name"`
FirstSurname string `xml:"FirstSurname,omitempty"`
SecondSurname string `xml:"SecondSurname,omitempty"`
AddressInSpain *Address `xml:"AddressInSpain,omitempty"`
OverseasAddress *OverseasAddress `xml:"OverseasAddress,omitempty"`
ContactDetails *ContactDetails `xml:"ContactDetails,omitempty"`
}
Individual stores party info for people
type Installment ¶
type Installment struct {
InstallmentDueDate string `xml:"InstallmentDueDate"`
InstallmentAmount string `xml:"InstallmentAmount"`
PaymentMeans string `xml:"PaymentMeans,omitempty"`
AccountToBeCredited *BankAccount `xml:"AccountToBeCredited,omitempty"`
AccountToBeDebited *BankAccount `xml:"AccountToBeDebited,omitempty"`
CollectionAdditionalInformation string `xml:"CollectionAdditionalInformation,omitempty"`
DebitReconciliationReference string `xml:"DebitReconciliationReference,omitempty"`
}
Installment contains info about each of the payment terms
type Invoice ¶
type Invoice struct {
InvoiceHeader *InvoiceHeader `xml:"InvoiceHeader"`
InvoiceIssueData *InvoiceIssueData `xml:"InvoiceIssueData"`
TaxesOutputs *TaxSummary `xml:"TaxesOutputs,omitempty"`
TaxesWithheld *TaxSummary `xml:"TaxesWithheld,omitempty"`
InvoiceTotals *InvoiceTotals `xml:"InvoiceTotals"`
Items *Items `xml:"Items"`
PaymentDetails *PaymentDetails `xml:"PaymentDetails,omitempty"`
LegalLiterals *LegalLiterals `xml:"LegalLiterals,omitempty"`
AdditionalData *AdditionalData `xml:"AdditionalData,omitempty"`
}
Invoice contains info about a single invoice
type InvoiceHeader ¶
type InvoiceHeader struct {
InvoiceNumber string `xml:"InvoiceNumber"`
InvoiceSeriesCode string `xml:"InvoiceSeriesCode,omitempty"`
InvoiceDocumentType string `xml:"InvoiceDocumentType"`
InvoiceClass string `xml:"InvoiceClass"`
Corrective *Corrective `xml:"Corrective,omitempty"`
}
InvoiceHeader contains general information of a single invoice
type InvoiceIssueData ¶
type InvoiceIssueData struct {
IssueDate string `xml:"IssueDate"`
OperationDate string `xml:"OperationDate,omitempty"`
PlaceOfIssue string `xml:"PlaceOfIssue,omitempty"`
InvoiceingPeriod *PeriodDates `xml:"InvoiceingPeriod,omitempty"`
InvoiceCurrencyCode string `xml:"InvoiceCurrencyCode"`
ExchangeRateDetails *ExchangeRateDetails `xml:"ExchangeRateDetails,omitempty"`
TaxCurrencyCode string `xml:"TaxCurrencyCode"`
LanguageName string `xml:"LanguageName"` // FIXME: [JUANJO] are we going to support multiple languages?
InvoiceDescription string `xml:"InvoiceDescription,omitempty"` // TODO
ReceiverTransactionReference string `xml:"ReceiverTransactionReference,omitempty"` // TODO
FileReference string `xml:"FileReference,omitempty"` // TODO
ReceiverContractReference string `xml:"ReceiverContractReference,omitempty"` // TODO
}
InvoiceIssueData contains information about dates, lang and currencies
type InvoiceLine ¶
type InvoiceLine struct {
ItemDescription string `xml:"ItemDescription"`
Quantity string `xml:"Quantity"`
UnitOfMeasure string `xml:"UnitOfMeasure,omitempty"`
UnitPriceWithoutTax string `xml:"UnitPriceWithoutTax"`
TotalCost string `xml:"TotalCost"` // Unit Price * quantity
DiscountsAndRebates *Discounts `xml:"DiscountsAndRebates,omitempty"`
Charges *Charges `xml:"Charges,omitempty"`
GrossAmount string `xml:"GrossAmount"` // total cost - discount + charges
TaxesWithheld *TaxSummary `xml:"TaxesWithheld,omitempty"`
TaxesOutputs *TaxSummary `xml:"TaxesOutputs,omitempty"`
AdditionalLineItemInformation string `xml:"AdditionalLineItemInformation,omitempty"`
SpecialTaxableEvent *SpecialTaxableEvent `xml:"SpecialTaxableEvent,omitempty"`
}
InvoiceLine contains info about a specific line
type InvoiceTotals ¶
type InvoiceTotals struct {
TotalGrossAmount string `xml:"TotalGrossAmount"` // Without included taxes
GeneralDiscounts *Discounts `xml:"GeneralDiscounts,omitempty"`
GeneralSurcharges *Charges `xml:"GeneralSurcharges,omitempty"`
TotalGeneralDiscounts string `xml:"TotalGeneralDiscounts,omitempty"`
TotalGeneralSurcharges string `xml:"TotalGeneralSurcharges,omitempty"`
TotalGrossAmountBeforeTaxes string `xml:"TotalGrossAmountBeforeTaxes"`
TotalTaxOutputs string `xml:"TotalTaxOutputs"`
TotalTaxesWithheld string `xml:"TotalTaxesWithheld"`
InvoiceTotal string `xml:"InvoiceTotal"`
Subsidies *Subsidies `xml:"Subsidies,omitempty"`
PaymentsOnAccount *PaymentsOnAccount `xml:"PaymentsOnAccount,omitempty"`
ReimbursableExpenses *ReimbursableExpenses `xml:"ReimbursableExpenses,omitempty"`
TotalOutstandingAmount string `xml:"TotalOutstandingAmount"` // InvoiceTotal - (Total subvenciones + TotalPaymentsOnAccount)
TotalPaymentsOnAccount string `xml:"TotalPaymentsOnAccount,omitempty"`
TotalExecutableAmount string `xml:"TotalExecutableAmount"`
TotalReimbursableExpenses string `xml:"TotalReimbursableExpenses,omitempty"`
}
InvoiceTotals contains the summary of the amounts in an invoice
type Invoices ¶
type Invoices struct {
List []*Invoice `xml:"Invoice"`
}
Invoices contains info about a batch of invoices. In our case there will only be one invoice per batch
type Items ¶
type Items struct {
InvoiceLine []*InvoiceLine `xml:"InvoiceLine"`
}
Items contains info about all the lines in an invoice
type LegalEntity ¶
type LegalEntity struct {
CorporateName string `xml:"CorporateName"`
AddressInSpain *Address `xml:"AddressInSpain,omitempty"`
OverseasAddress *OverseasAddress `xml:"OverseasAddress,omitempty"`
ContactDetails *ContactDetails `xml:"ContactDetails,omitempty"`
}
LegalEntity stores party info for companies, associations, ...
type LegalLiterals ¶
type LegalLiterals struct {
LegalReference []string `xml:"LegalReference"`
}
LegalLiterals contains an array of legal texts to add to the Invoice in certain situations.
type Option ¶
type Option func(*options)
Option defines a callback configuration option used to customize the conversion to XML process
func WithCertificate ¶
func WithCertificate(cert *xmldsig.Certificate) Option
WithCertificate will use the provided certificate to sign the XML document.
func WithSigning ¶
WithSigning allows passing additional xmldsig options that will be appended to the signing call. Useful to inject a deterministic signing time or other parameters in tests.
func WithThirdParty ¶
func WithThirdParty(tp *ThirdParty) Option
WithThirdParty adds optional information about who is manipulating and signing the document.
func WithTimestamp ¶
WithTimestamp will ensure the XML document is timestamped
type OverseasAddress ¶
type OverseasAddress struct {
Address string `xml:"Address,omitempty"`
PostCodeAndTown string `xml:"PostCodeAndTown,omitempty"`
Province string `xml:"Province,omitempty"`
CountryCode string `xml:"CountryCode,omitempty"`
}
OverseasAddress stores location information for addresses outside Spain
type Party ¶
type Party struct {
TaxID *TaxID `xml:"TaxIdentification,omitempty"`
AdministrativeCentres *AdministrativeCentres `xml:"AdministrativeCentres,omitempty"`
LegalEntity *LegalEntity `xml:"LegalEntity,omitempty"`
Individual *Individual `xml:"Individual,omitempty"`
}
Party stores the info for one of the participants of the invoice
type PaymentDetails ¶
type PaymentDetails struct {
Installments []*Installment `xml:"Installment"`
}
PaymentDetails contains info about how the invoice should be paid
type PaymentOnAccount ¶
type PaymentOnAccount struct {
PaymentOnAccountDate cal.Date `xml:"PaymentOnAccountDate"`
PaymentOnAccountAmount string `xml:"PaymentOnAccountAmount"`
}
PaymentOnAccount is a single advance payment.
type PaymentsOnAccount ¶
type PaymentsOnAccount struct {
PaymentOnAccount []*PaymentOnAccount `xml:"PaymentOnAccount"`
}
PaymentsOnAccount stores payments made in advance.
type PeriodDates ¶
PeriodDates is used in corrective tax periods to define a date range.
type ReimbursableExpense ¶
type ReimbursableExpense struct {
ReimbursableExpensesSellerParty *TaxID `xml:"ReimbursableExpensesSellerParty,omitempty"`
ReimbursableExpensesBuyerParty *TaxID `xml:"ReimbursableExpensesBuyerParty,omitempty"` // never used!
IssueDate *cal.Date `xml:"IssueDate,omitempty"`
InvoiceNumber string `xml:"InvoiceNumber,omitempty"`
InvoiceSeriesCode string `xml:"InvoiceSeriesCode,omitempty"`
ReimbursableExpensesAmount string `xml:"ReimbursableExpensesAmount"`
}
ReimbursableExpense stores info about a single reimbursable expense.
type ReimbursableExpenses ¶
type ReimbursableExpenses struct {
ReimbursableExpenses []*ReimbursableExpense `xml:"ReimbursableExpenses"`
}
ReimbursableExpenses is a group of reimbursable expenses.
type SpecialTaxableEvent ¶
type SpecialTaxableEvent struct {
SpecialTaxableEventCode SpecialTaxableEventCode `xml:"SpecialTaxableEventCode"`
SpecialTaxableEventReason string `xml:"SpecialTaxableEventReason"`
}
SpecialTaxableEvent stores details as to way the invoice line does not need taxes to be applied.
type SpecialTaxableEventCode ¶
type SpecialTaxableEventCode string
SpecialTaxableEventCode used for special invoice lines that do not need taxes to be applied.
const ( TaxableAndExemptCode SpecialTaxableEventCode = "01" NonTaxableCode SpecialTaxableEventCode = "02" )
Special taxable event codes
type Subsidies ¶
type Subsidies struct {
Subsidy []*Subsidy `xml:"Subsidy"`
}
Subsidies is currently a placeholder, as we don't use it yet.
type Subsidy ¶
type Subsidy struct {
SubsidyDescription string `xml:"SubsidyDescription"`
SubsidyRate string `xml:"SubsidyRate,omitempty"`
SubsidyAmount string `xml:"SubsidyAmount"`
}
Subsidy is a single subsidy entry
type Tax ¶
type Tax struct {
Code string `xml:"TaxTypeCode"`
Rate string `xml:"TaxRate"`
Base Amount `xml:"TaxableBase"`
Amount Amount `xml:"TaxAmount"`
Surcharge string `xml:"EquivalenceSurcharge,omitempty"` // must be with two decimal places
SurchargeAmount *Amount `xml:"EquivalenceSurchargeAmount,omitempty"`
}
Tax contains the info of a particular tax type
type TaxID ¶
type TaxID struct {
PersonTypeCode string `xml:"PersonTypeCode"`
ResidenceTypeCode string `xml:"ResidenceTypeCode"`
TaxIdentificationNumber string `xml:"TaxIdentificationNumber"`
}
TaxID stores fiscal id
type TaxSummary ¶
type TaxSummary struct {
List []*Tax `xml:"Tax"`
}
TaxSummary contains a list with the info of each tax type
type ThirdParty ¶
type ThirdParty struct {
TaxIdentification *TaxID `xml:"TaxIdentification"`
LegalEntity *LegalEntity `xml:"LegalEntity"`
}
ThirdParty is used to identify an intermediary building and issuing the invoice.
Source Files
¶
- additional_data.go
- address.go
- amount.go
- charges.go
- contact_details.go
- converter.go
- corrective.go
- corrective_parse.go
- discounts.go
- facturae.go
- file_header.go
- invoice_parse.go
- invoice_totals.go
- invoices.go
- items.go
- items_parse.go
- local_repo.go
- parties.go
- parties_parse.go
- payments.go
- payments_parse.go
- reimbursable_expenses.go
- tax_id.go
- taxes.go
- utils_parse.go