Documentation
¶
Overview ¶
Package finvoice converts GOBL invoices and credit notes to Finvoice 3.0 and back. The fi-finvoice-v3 addon in the addon subpackage holds the validation rules and the e-invoice operator extension the converter reads.
Index ¶
- Constants
- Variables
- func Bytes(doc any) ([]byte, error)
- func Convert(env *gobl.Envelope, opts ...Option) (any, error)
- func Parse(data []byte) (*gobl.Envelope, error)
- type Account
- type Amount
- type BuyerCommunicationDetails
- type BuyerPartyDetails
- type BuyerPostalAddressDetails
- type ChargeDetails
- type Date
- type DeliveryDetails
- type DeliveryPartyDetails
- type DeliveryPeriodDetails
- type DeliveryPostalAddressDetails
- type DiscountDetails
- type EpiBeneficiaryPartyDetails
- type EpiBfiPartyDetails
- type EpiCharge
- type EpiDetails
- type EpiIdentificationDetails
- type EpiPartyDetails
- type EpiPaymentInstructionDetails
- type Identifier
- type Invoice
- type InvoiceDetails
- type InvoiceRow
- type InvoiceTypeCode
- type MessageDetails
- type MessageReceiverDetails
- type MessageSenderDetails
- type MessageTransmissionDetails
- type Option
- type OriginalInvoiceReference
- type PaymentTermsDetails
- type Quantity
- type RemittanceReference
- type RowChargeDetails
- type RowProgressiveDiscountDetails
- type SellerAccountDetails
- type SellerCommunicationDetails
- type SellerInformationDetails
- type SellerPartyDetails
- type SellerPostalAddressDetails
- type UnitAmount
- type VatSpecificationDetails
Constants ¶
const Version = "3.0"
Version is the Finvoice version written.
Variables ¶
var ( // ErrUnsupportedDocumentType is returned when the envelope holds anything // other than an invoice, or a Finvoice message that is not one. ErrUnsupportedDocumentType = errors.New("unsupported document type") // ErrSenderOperatorRequired is returned when the receiving party names // its operator but the conversion was given no sender operator to route // from. ErrSenderOperatorRequired = errors.New("sender operator is required to route to the receiver's operator") )
Functions ¶
Types ¶
type Account ¶
type Account struct {
Value string `xml:",chardata"`
Scheme string `xml:"IdentificationSchemeName,attr,omitempty"`
}
Account is a bank account or bank identifier with its scheme (IBAN, BBAN, BIC, SPY, ISO).
type Amount ¶
type Amount struct {
Value string `xml:",chardata"`
Currency string `xml:"AmountCurrencyIdentifier,attr"`
}
Amount is a monetary value with its currency.
type BuyerCommunicationDetails ¶
type BuyerCommunicationDetails struct {
Phone string `xml:"BuyerPhoneNumberIdentifier,omitempty"`
Email string `xml:"BuyerEmailaddressIdentifier,omitempty"`
}
BuyerCommunicationDetails holds the buyer contact's phone and email.
type BuyerPartyDetails ¶
type BuyerPartyDetails struct {
Identifier *Identifier `xml:"BuyerPartyIdentifier,omitempty"`
Name []string `xml:"BuyerOrganisationName"`
TradingName string `xml:"BuyerOrganisationTradingName,omitempty"`
TaxCode string `xml:"BuyerOrganisationTaxCode,omitempty"`
Address *BuyerPostalAddressDetails `xml:"BuyerPostalAddressDetails,omitempty"`
}
BuyerPartyDetails identifies the buyer.
type BuyerPostalAddressDetails ¶
type BuyerPostalAddressDetails struct {
StreetName []string `xml:"BuyerStreetName"`
TownName string `xml:"BuyerTownName"`
PostCode string `xml:"BuyerPostCodeIdentifier"`
Subdivision string `xml:"BuyerCountrySubdivision,omitempty"`
CountryCode string `xml:"CountryCode,omitempty"`
PostOfficeBox string `xml:"BuyerPostOfficeBoxIdentifier,omitempty"`
}
BuyerPostalAddressDetails is the buyer's postal address.
type ChargeDetails ¶
type ChargeDetails struct {
ReasonText string `xml:"ReasonText,omitempty"`
ReasonCode string `xml:"ReasonCode,omitempty"`
Percent string `xml:"Percent,omitempty"`
Amount *Amount `xml:"Amount,omitempty"`
BaseAmount *Amount `xml:"BaseAmount,omitempty"`
VatCategoryCode string `xml:"VatCategoryCode,omitempty"`
VatRatePercent string `xml:"VatRatePercent,omitempty"`
}
ChargeDetails is a document-level charge.
type DeliveryDetails ¶
type DeliveryDetails struct {
Date *Date `xml:"DeliveryDate,omitempty"`
Period *DeliveryPeriodDetails `xml:"DeliveryPeriodDetails,omitempty"`
}
DeliveryDetails holds when the goods were delivered.
type DeliveryPartyDetails ¶
type DeliveryPartyDetails struct {
Identifier *Identifier `xml:"DeliveryPartyIdentifier,omitempty"`
Name []string `xml:"DeliveryOrganisationName"`
TaxCode string `xml:"DeliveryOrganisationTaxCode,omitempty"`
Address *DeliveryPostalAddressDetails `xml:"DeliveryPostalAddressDetails"`
}
DeliveryPartyDetails identifies who receives the goods.
type DeliveryPeriodDetails ¶
type DeliveryPeriodDetails struct {
StartDate *Date `xml:"StartDate"`
EndDate *Date `xml:"EndDate"`
}
DeliveryPeriodDetails is the delivery period.
type DeliveryPostalAddressDetails ¶
type DeliveryPostalAddressDetails struct {
StreetName []string `xml:"DeliveryStreetName"`
TownName string `xml:"DeliveryTownName"`
PostCode string `xml:"DeliveryPostCodeIdentifier"`
Subdivision string `xml:"DeliveryCountrySubdivision,omitempty"`
CountryCode string `xml:"CountryCode,omitempty"`
PostOfficeBox string `xml:"DeliveryPostofficeBoxIdentifier,omitempty"`
}
DeliveryPostalAddressDetails is the delivery address.
type DiscountDetails ¶
type DiscountDetails struct {
FreeText string `xml:"FreeText,omitempty"`
ReasonCode string `xml:"ReasonCode,omitempty"`
Percent string `xml:"Percent,omitempty"`
Amount *Amount `xml:"Amount,omitempty"`
BaseAmount *Amount `xml:"BaseAmount,omitempty"`
VatCategoryCode string `xml:"VatCategoryCode,omitempty"`
VatRatePercent string `xml:"VatRatePercent,omitempty"`
}
DiscountDetails is a document-level allowance.
type EpiBeneficiaryPartyDetails ¶
type EpiBeneficiaryPartyDetails struct {
NameAddress string `xml:"EpiNameAddressDetails,omitempty"`
AccountID Account `xml:"EpiAccountID"`
}
EpiBeneficiaryPartyDetails identifies the payee and its account.
type EpiBfiPartyDetails ¶
type EpiBfiPartyDetails struct {
Identifier *Account `xml:"EpiBfiIdentifier,omitempty"`
Name string `xml:"EpiBfiName,omitempty"`
}
EpiBfiPartyDetails identifies the beneficiary's bank.
type EpiDetails ¶
type EpiDetails struct {
Identification EpiIdentificationDetails `xml:"EpiIdentificationDetails"`
Party EpiPartyDetails `xml:"EpiPartyDetails"`
PaymentInstruction EpiPaymentInstructionDetails `xml:"EpiPaymentInstructionDetails"`
}
EpiDetails is the payment order: reference, beneficiary account and the amount and date to pay.
type EpiIdentificationDetails ¶
type EpiIdentificationDetails struct {
Date *Date `xml:"EpiDate"`
Reference string `xml:"EpiReference"`
}
EpiIdentificationDetails dates and references the payment order.
type EpiPartyDetails ¶
type EpiPartyDetails struct {
BFI EpiBfiPartyDetails `xml:"EpiBfiPartyDetails"`
Beneficiary EpiBeneficiaryPartyDetails `xml:"EpiBeneficiaryPartyDetails"`
}
EpiPartyDetails names the beneficiary's bank and account.
type EpiPaymentInstructionDetails ¶
type EpiPaymentInstructionDetails struct {
InstructionCode string `xml:"EpiInstructionCode,omitempty"`
RemittanceInfoIdentifier *RemittanceReference `xml:"EpiRemittanceInfoIdentifier,omitempty"`
InstructedAmount Amount `xml:"EpiInstructedAmount"`
Charge EpiCharge `xml:"EpiCharge"`
DateOptionDate *Date `xml:"EpiDateOptionDate"`
PaymentMeansCode string `xml:"EpiPaymentMeansCode,omitempty"`
PaymentMeansText string `xml:"EpiPaymentMeansText,omitempty"`
}
EpiPaymentInstructionDetails says what to pay, by when, and under which reference.
type Identifier ¶
type Identifier struct {
Value string `xml:",chardata"`
SchemeID string `xml:"SchemeID,attr,omitempty"`
}
Identifier is a party, address or item identifier with an optional ISO 6523 scheme.
type Invoice ¶
type Invoice struct {
XMLName xml.Name `xml:"Finvoice"`
Version string `xml:"Version,attr"`
Transmission *MessageTransmissionDetails `xml:"MessageTransmissionDetails,omitempty"`
Seller *SellerPartyDetails `xml:"SellerPartyDetails"`
SellerOrganisationUnitNumber string `xml:"SellerOrganisationUnitNumber,omitempty"`
SellerContactPersonName string `xml:"SellerContactPersonName,omitempty"`
SellerCommunication *SellerCommunicationDetails `xml:"SellerCommunicationDetails,omitempty"`
SellerInformation *SellerInformationDetails `xml:"SellerInformationDetails,omitempty"`
Buyer *BuyerPartyDetails `xml:"BuyerPartyDetails"`
BuyerOrganisationUnitNumber string `xml:"BuyerOrganisationUnitNumber,omitempty"`
BuyerContactPersonName string `xml:"BuyerContactPersonName,omitempty"`
BuyerCommunication *BuyerCommunicationDetails `xml:"BuyerCommunicationDetails,omitempty"`
DeliveryParty *DeliveryPartyDetails `xml:"DeliveryPartyDetails,omitempty"`
DeliveryDetails *DeliveryDetails `xml:"DeliveryDetails,omitempty"`
InvoiceDetails *InvoiceDetails `xml:"InvoiceDetails"`
Rows []*InvoiceRow `xml:"InvoiceRow"`
Epi *EpiDetails `xml:"EpiDetails"`
InvoiceURLNames []string `xml:"InvoiceUrlNameText,omitempty"`
InvoiceURLs []string `xml:"InvoiceUrlText,omitempty"`
}
Invoice is the Finvoice message of an invoice or credit note.
func ConvertInvoice ¶
ConvertInvoice is Convert for callers that already know the envelope holds an invoice.
type InvoiceDetails ¶
type InvoiceDetails struct {
TypeCode InvoiceTypeCode `xml:"InvoiceTypeCode"`
TypeCodeUN string `xml:"InvoiceTypeCodeUN,omitempty"`
TypeText string `xml:"InvoiceTypeText"`
OriginCode string `xml:"OriginCode"`
InvoiceNumber string `xml:"InvoiceNumber"`
InvoiceDate *Date `xml:"InvoiceDate"`
OriginalInvoiceNumber string `xml:"OriginalInvoiceNumber,omitempty"`
OriginalInvoiceDate *Date `xml:"OriginalInvoiceDate,omitempty"`
OriginalInvoiceReference []*OriginalInvoiceReference `xml:"OriginalInvoiceReference,omitempty"`
PeriodStartDate *Date `xml:"InvoicingPeriodStartDate,omitempty"`
PeriodEndDate *Date `xml:"InvoicingPeriodEndDate,omitempty"`
SellerReference string `xml:"SellerReferenceIdentifier,omitempty"`
OrderIdentifier string `xml:"OrderIdentifier,omitempty"`
OrderDate *Date `xml:"OrderDate,omitempty"`
AgreementIdentifier string `xml:"AgreementIdentifier,omitempty"`
AgreementDate *Date `xml:"AgreementDate,omitempty"`
BuyerReference string `xml:"BuyerReferenceIdentifier,omitempty"`
ProjectReference string `xml:"ProjectReferenceIdentifier,omitempty"`
RowsTotalVatExcludedAmount *Amount `xml:"RowsTotalVatExcludedAmount,omitempty"`
DiscountsTotalVatExcludedAmount *Amount `xml:"DiscountsTotalVatExcludedAmount,omitempty"`
ChargesTotalVatExcludedAmount *Amount `xml:"ChargesTotalVatExcludedAmount,omitempty"`
TotalVatExcludedAmount *Amount `xml:"InvoiceTotalVatExcludedAmount,omitempty"`
TotalVatAmount *Amount `xml:"InvoiceTotalVatAmount,omitempty"`
TotalVatIncludedAmount *Amount `xml:"InvoiceTotalVatIncludedAmount"`
TotalRoundoffAmount *Amount `xml:"InvoiceTotalRoundoffAmount,omitempty"`
PaidAmount *Amount `xml:"InvoicePaidAmount,omitempty"`
VatSpecifications []*VatSpecificationDetails `xml:"VatSpecificationDetails,omitempty"`
FreeText []string `xml:"InvoiceFreeText,omitempty"`
PaymentTerms []*PaymentTermsDetails `xml:"PaymentTermsDetails,omitempty"`
Discounts []*DiscountDetails `xml:"DiscountDetails,omitempty"`
Charges []*ChargeDetails `xml:"ChargeDetails,omitempty"`
TenderReference string `xml:"TenderReference,omitempty"`
}
InvoiceDetails holds the document header: type, numbers, dates, references, totals, VAT breakdown, terms, and document-level discounts and charges.
type InvoiceRow ¶
type InvoiceRow struct {
ArticleIdentifier string `xml:"ArticleIdentifier,omitempty"`
ArticleName string `xml:"ArticleName,omitempty"`
ArticleDescription string `xml:"ArticleDescription,omitempty"`
EANCode *Identifier `xml:"EanCode,omitempty"`
DeliveredQuantity []*Quantity `xml:"DeliveredQuantity,omitempty"`
OrderedQuantity *Quantity `xml:"OrderedQuantity,omitempty"`
InvoicedQuantity []*Quantity `xml:"InvoicedQuantity,omitempty"`
StartDate *Date `xml:"StartDate,omitempty"`
EndDate *Date `xml:"EndDate,omitempty"`
UnitPriceAmount *UnitAmount `xml:"UnitPriceAmount,omitempty"`
UnitPriceNetAmount *UnitAmount `xml:"UnitPriceNetAmount,omitempty"`
UnitPriceBaseQuantity *Quantity `xml:"UnitPriceBaseQuantity,omitempty"`
RowPositionIdentifier string `xml:"RowPositionIdentifier,omitempty"`
OriginalInvoiceNumber string `xml:"OriginalInvoiceNumber,omitempty"`
FreeText []string `xml:"RowFreeText,omitempty"`
DiscountPercent string `xml:"RowDiscountPercent,omitempty"`
DiscountAmount *Amount `xml:"RowDiscountAmount,omitempty"`
DiscountBaseAmount *Amount `xml:"RowDiscountBaseAmount,omitempty"`
DiscountTypeCode string `xml:"RowDiscountTypeCode,omitempty"`
DiscountTypeText string `xml:"RowDiscountTypeText,omitempty"`
ProgressiveDiscount []*RowProgressiveDiscountDetails `xml:"RowProgressiveDiscountDetails,omitempty"`
Charges []*RowChargeDetails `xml:"RowChargeDetails,omitempty"`
VatRatePercent string `xml:"RowVatRatePercent,omitempty"`
VatCode string `xml:"RowVatCode,omitempty"`
VatAmount *Amount `xml:"RowVatAmount,omitempty"`
VatExcludedAmount *Amount `xml:"RowVatExcludedAmount,omitempty"`
Amount *Amount `xml:"RowAmount,omitempty"`
// SubRows marks a subtotal row, which is read only to be left out.
SubRows []struct{} `xml:"SubInvoiceRow,omitempty"`
}
InvoiceRow is one invoice line.
type InvoiceTypeCode ¶
type InvoiceTypeCode struct {
Value string `xml:",chardata"`
CodeList string `xml:"CodeListAgencyIdentifier,attr,omitempty"`
}
InvoiceTypeCode is the Finvoice invoice type code with its code list.
type MessageDetails ¶
type MessageDetails struct {
Identifier string `xml:"MessageIdentifier"`
Timestamp string `xml:"MessageTimeStamp"`
RefToMessageIdentifier string `xml:"RefToMessageIdentifier,omitempty"`
SpecificationIdentifier string `xml:"SpecificationIdentifier,omitempty"`
}
MessageDetails identifies the message itself.
type MessageReceiverDetails ¶
type MessageReceiverDetails struct {
Identifier Identifier `xml:"ToIdentifier"`
Intermediator string `xml:"ToIntermediator"`
}
MessageReceiverDetails holds the receiver's e-invoice address and operator.
type MessageSenderDetails ¶
type MessageSenderDetails struct {
Identifier Identifier `xml:"FromIdentifier"`
Intermediator string `xml:"FromIntermediator"`
}
MessageSenderDetails holds the sender's e-invoice address and operator.
type MessageTransmissionDetails ¶
type MessageTransmissionDetails struct {
Sender MessageSenderDetails `xml:"MessageSenderDetails"`
Receiver MessageReceiverDetails `xml:"MessageReceiverDetails"`
Message MessageDetails `xml:"MessageDetails"`
}
MessageTransmissionDetails routes the message: who sends it, who receives it, and through which operators.
type Option ¶
type Option func(*options)
Option configures a conversion.
func WithInvoiceURL ¶
WithInvoiceURL adds a named link to the document, such as the reference to the invoice's PDF image that an operator's intake expects.
func WithMessageID ¶
WithMessageID sets the message identifier in the transmission details, which the invoice's UUID otherwise provides; the schema takes 2 to 48 characters.
func WithMessageTime ¶
WithMessageTime sets the timestamp in the transmission details, which is otherwise the time of conversion.
func WithSenderOperator ¶
WithSenderOperator names the e-invoice operator the message is sent through, written as the sender's intermediator in the transmission details; the schema takes 2 to 35 characters.
type OriginalInvoiceReference ¶
type OriginalInvoiceReference struct {
InvoiceNumber string `xml:"InvoiceNumber,omitempty"`
InvoiceDate *Date `xml:"InvoiceDate,omitempty"`
}
OriginalInvoiceReference points at a further preceding document.
type PaymentTermsDetails ¶
type PaymentTermsDetails struct {
FreeText []string `xml:"PaymentTermsFreeText,omitempty"`
DueDate *Date `xml:"InvoiceDueDate,omitempty"`
}
PaymentTermsDetails describes when the invoice is due.
type Quantity ¶
type Quantity struct {
Value string `xml:",chardata"`
UnitCode string `xml:"QuantityUnitCode,attr,omitempty"`
UnitCodeUN string `xml:"QuantityUnitCodeUN,attr,omitempty"`
}
Quantity is a number of units, with the unit as free text and, when known, as its UN/ECE code.
type RemittanceReference ¶
type RemittanceReference struct {
Value string `xml:",chardata"`
Scheme string `xml:"IdentificationSchemeName,attr"`
}
RemittanceReference is the payment reference with its scheme, SPY or ISO.
type RowChargeDetails ¶
type RowChargeDetails struct {
ReasonText string `xml:"ReasonText,omitempty"`
ReasonCode string `xml:"ReasonCode,omitempty"`
Percent string `xml:"Percent,omitempty"`
Amount *Amount `xml:"Amount,omitempty"`
BaseAmount *Amount `xml:"BaseAmount,omitempty"`
}
RowChargeDetails is a charge on a line.
type RowProgressiveDiscountDetails ¶
type RowProgressiveDiscountDetails struct {
Percent string `xml:"RowDiscountPercent,omitempty"`
Amount *Amount `xml:"RowDiscountAmount,omitempty"`
BaseAmount *Amount `xml:"RowDiscountBaseAmount,omitempty"`
TypeCode string `xml:"RowDiscountTypeCode,omitempty"`
TypeText string `xml:"RowDiscountTypeText,omitempty"`
}
RowProgressiveDiscountDetails is one of several discounts on a line.
type SellerAccountDetails ¶
type SellerAccountDetails struct {
AccountID Account `xml:"SellerAccountID"`
BIC Account `xml:"SellerBic"`
Name string `xml:"SellerAccountName,omitempty"`
}
SellerAccountDetails is one of the seller's bank accounts.
type SellerCommunicationDetails ¶
type SellerCommunicationDetails struct {
Phone string `xml:"SellerPhoneNumberIdentifier,omitempty"`
Email string `xml:"SellerEmailaddressIdentifier,omitempty"`
}
SellerCommunicationDetails holds the seller contact's phone and email.
type SellerInformationDetails ¶
type SellerInformationDetails struct {
Email string `xml:"SellerCommonEmailaddressIdentifier,omitempty"`
Website string `xml:"SellerWebaddressIdentifier,omitempty"`
Accounts []*SellerAccountDetails `xml:"SellerAccountDetails,omitempty"`
}
SellerInformationDetails holds the seller's general details and bank accounts.
type SellerPartyDetails ¶
type SellerPartyDetails struct {
Identifier *Identifier `xml:"SellerPartyIdentifier,omitempty"`
Name []string `xml:"SellerOrganisationName"`
TradingName string `xml:"SellerOrganisationTradingName,omitempty"`
TaxCode string `xml:"SellerOrganisationTaxCode,omitempty"`
Address *SellerPostalAddressDetails `xml:"SellerPostalAddressDetails,omitempty"`
}
SellerPartyDetails identifies the seller.
type SellerPostalAddressDetails ¶
type SellerPostalAddressDetails struct {
StreetName []string `xml:"SellerStreetName"`
TownName string `xml:"SellerTownName"`
PostCode string `xml:"SellerPostCodeIdentifier"`
Subdivision string `xml:"SellerCountrySubdivision,omitempty"`
CountryCode string `xml:"CountryCode,omitempty"`
PostOfficeBox string `xml:"SellerPostOfficeBoxIdentifier,omitempty"`
}
SellerPostalAddressDetails is the seller's postal address.
type UnitAmount ¶
type UnitAmount struct {
Value string `xml:",chardata"`
Currency string `xml:"AmountCurrencyIdentifier,attr"`
UnitCode string `xml:"UnitPriceUnitCode,attr,omitempty"`
UnitCodeUN string `xml:"QuantityUnitCodeUN,attr,omitempty"`
}
UnitAmount is a unit price with its currency and optional unit.
type VatSpecificationDetails ¶
type VatSpecificationDetails struct {
BaseAmount *Amount `xml:"VatBaseAmount,omitempty"`
RatePercent string `xml:"VatRatePercent,omitempty"`
Code string `xml:"VatCode,omitempty"`
RateAmount *Amount `xml:"VatRateAmount,omitempty"`
FreeText []string `xml:"VatFreeText,omitempty"`
ExemptionReasonCode string `xml:"VatExemptionReasonCode,omitempty"`
}
VatSpecificationDetails is one line of the VAT breakdown.