Documentation
¶
Overview ¶
Package saft implements the conversion of GOBL invoices, payments, orders and delivery documents into Portuguese SAF-T (PT) structures, as well as the sealing of those documents: the AT signature (hash), ATCUD and QR code.
The GOBL addon itself lives in the addon subpackage; the client for the AT web services in atws, and the builders of its real-time reporting requests in realtime.
Index ¶
- Constants
- func BuildATCUD(doc SourceDocument, valCode string) string
- func BuildQRCode(qr *BuildQRCodeParams) string
- func DecodeXML(r io.Reader, v any) error
- func DocNumber(series, code cbc.Code) string
- func DocNumberParts(c string) (cbc.Code, cbc.Code, int)
- func EncodeXML(v any, w io.Writer, root bool) error
- func HashCharacters(hash string) string
- func IsWorkDocument(ginv *bill.Invoice) bool
- func MarshalXML(v any, root bool) ([]byte, error)
- func Timestamp() string
- func UnmarshalXML(data []byte, v any) error
- func ValidateIssuer(val any) error
- func ValidatePeriod(per cal.Period) error
- type Address
- type AuditFile
- type AuditFileParams
- type BuildParams
- type BuildQRCodeParams
- type ClassTotals
- type ConvertResult
- type Currency
- type Customer
- type CustomsDetails
- type CustomsInformation
- type DocTotals
- type DocumentClass
- type DocumentTotals
- type Header
- type Invoice
- func (i *Invoice) GetCustomerID() string
- func (i *Invoice) GetDocumentClass() DocumentClass
- func (i *Invoice) GetDocumentNo() string
- func (i *Invoice) GetDocumentTotals() *DocumentTotals
- func (i *Invoice) GetDocumentType() string
- func (i *Invoice) GetGrossTotal() string
- func (i *Invoice) GetIssueDate() string
- func (i *Invoice) GetStatus() string
- func (i *Invoice) GetStatusDate() string
- func (i *Invoice) GetStatusReason() string
- func (i *Invoice) GetTaxPayable() string
- func (i *Invoice) GetTaxTotal() *tax.Total
- func (i *Invoice) SetStatus(status, reason, sourceID string)
- type InvoiceStatus
- type Line
- type MasterFiles
- type MovementOfGoods
- type MovementStatus
- type OrderReference
- type Payment
- func (p *Payment) GetCustomerID() string
- func (p *Payment) GetDocumentClass() DocumentClass
- func (p *Payment) GetDocumentNo() string
- func (p *Payment) GetDocumentTotals() *DocumentTotals
- func (p *Payment) GetDocumentType() string
- func (p *Payment) GetGrossTotal() string
- func (p *Payment) GetIssueDate() string
- func (p *Payment) GetStatus() string
- func (p *Payment) GetStatusDate() string
- func (p *Payment) GetStatusReason() string
- func (p *Payment) GetTaxPayable() string
- func (p *Payment) GetTaxTotal() *tax.Total
- func (p *Payment) SetStatus(status string, reason string, sourceID string)
- type PaymentLine
- type PaymentMethod
- type PaymentStatus
- type PaymentTax
- type Payments
- type Product
- type References
- type SalesInvoices
- type Settlement
- type ShippingPoint
- type Signature
- type SourceDocument
- type SourceDocumentID
- type SourceDocuments
- type SpecialRegimes
- type StockMovement
- func (sm *StockMovement) GetCustomerID() string
- func (sm *StockMovement) GetDocumentClass() DocumentClass
- func (sm *StockMovement) GetDocumentNo() string
- func (sm *StockMovement) GetDocumentTotals() *DocumentTotals
- func (sm *StockMovement) GetDocumentType() string
- func (sm *StockMovement) GetGrossTotal() string
- func (sm *StockMovement) GetIssueDate() string
- func (sm *StockMovement) GetStatus() string
- func (sm *StockMovement) GetStatusDate() string
- func (sm *StockMovement) GetStatusReason() string
- func (sm *StockMovement) GetTaxPayable() string
- func (sm *StockMovement) GetTaxTotal() *tax.Total
- func (sm *StockMovement) SetStatus(status, reason, sourceID string)
- type StreamEncoder
- func (e *StreamEncoder) Begin() error
- func (e *StreamEncoder) BeginClass(dc DocumentClass, t ClassTotals) error
- func (e *StreamEncoder) End() error
- func (e *StreamEncoder) WriteDocument(frag []byte) error
- func (e *StreamEncoder) WriteMasterFile(frag []byte) error
- func (e *StreamEncoder) WriteTaxTableEntry(frag []byte) error
- type Supplier
- type Tax
- type TaxTable
- type TaxTableEntry
- type WithholdingTax
- type WorkDocument
- func (w *WorkDocument) GetCustomerID() string
- func (w *WorkDocument) GetDocumentClass() DocumentClass
- func (w *WorkDocument) GetDocumentNo() string
- func (w *WorkDocument) GetDocumentTotals() *DocumentTotals
- func (w *WorkDocument) GetDocumentType() string
- func (w *WorkDocument) GetGrossTotal() string
- func (w *WorkDocument) GetIssueDate() string
- func (w *WorkDocument) GetStatus() string
- func (w *WorkDocument) GetStatusDate() string
- func (w *WorkDocument) GetStatusReason() string
- func (w *WorkDocument) GetTaxPayable() string
- func (w *WorkDocument) GetTaxTotal() *tax.Total
- func (w *WorkDocument) SetStatus(status, reason, sourceID string)
- type WorkDocumentTotals
- type WorkStatus
- type WorkingDocuments
Constants ¶
const ( AuditFileVersion = "1.04_01" CurrencyCode = "EUR" TaxAccountingBasis = "F" // F - Faturação (Invoicing) TaxEntity = "Global" )
Header constants
const ( GenericCustomerTaxID = "999999990" GenericCustomerID = "Consumidor final" GenericCustomerHash = "931747646aa67138f346d6ed06fc03" ValueUnknown = "Desconhecido" )
Final consumer constants
const ( StatusNormal = "N" // Normal StatusSelfInvoice = "S" // Autofaturação StatusCanceled = "A" // Anulado StatusSummary = "R" // Resumo StatusBilled = "F" // Faturado )
Status codes
const ( // TimeLocation used as reference for SAF-T documents TimeLocation = "Europe/Lisbon" // TaxTypeVAT is the TaxType value for VAT TaxTypeVAT = "IVA" )
const (
LabelFax = "fax"
)
Other constants
const XMLNamespace = "urn:OECD:StandardAuditFile-Tax:PT_1.04_01"
XMLNamespace is the target namespace of the SAF-T PT XSD schema.
Variables ¶
This section is empty.
Functions ¶
func BuildATCUD ¶
func BuildATCUD(doc SourceDocument, valCode string) string
BuildATCUD builds the ATCUD code for a given document and validation code.
func BuildQRCode ¶
func BuildQRCode(qr *BuildQRCodeParams) string
BuildQRCode builds a QR code for a given document
func DecodeXML ¶
DecodeXML decodes the given XML data into the given value according to the SAF-T specification. The input reader is assumed to be encoded in Windows-1252.
func DocNumberParts ¶
DocNumberParts splits a SAF-T document number into its components: document type, series code and sequence number
func EncodeXML ¶
EncodeXML encodes the given value to XML in Windows-1252 as required by SAF-T. If root is true, the XML header is prepended. Characters unsupported by Windows-1252 are normalized or escaped as HTML entities.
func HashCharacters ¶
HashCharacters extracts a 4-char snippet from a full hash string
func IsWorkDocument ¶
IsWorkDocument returns whether a GOBL invoice represents a SAF-T work document
func MarshalXML ¶
MarshalXML encodes the given value to XML according to the SAF-T specification and returns the resulting byte slice. If the root parameter is true, the value is considered a root document and the XML header is prepended to the output.
func Timestamp ¶
func Timestamp() string
Timestamp returns the current timestamp in the SAF-T format
func UnmarshalXML ¶
UnmarshalXML decodes the given XML data into the given value according to the SAF-T specification. The input byte slice is assumed to be encoded in Windows-1252.
func ValidateIssuer ¶
ValidateIssuer validates a GOBL party as a SAF-T issuer
func ValidatePeriod ¶
ValidatePeriod checks that a reporting period is complete and already elapsed.
Types ¶
type Address ¶
type Address struct {
BuildingNumber string `xml:"BuildingNumber,omitempty"`
StreetName string `xml:"StreetName,omitempty"`
AddressDetail string `xml:"AddressDetail"`
City string `xml:"City"`
PostalCode string `xml:"PostalCode"`
Region string `xml:"Region,omitempty"`
Country string `xml:"Country"`
}
Address represents an address in the SAF-T file
func BuildAddress ¶
BuildAddress builds a SAF-T address from a GOBL address
type AuditFile ¶
type AuditFile struct {
XMLName struct{} `xml:"urn:OECD:StandardAuditFile-Tax:PT_1.04_01 AuditFile"`
Header *Header `xml:"Header"`
MasterFiles *MasterFiles `xml:"MasterFiles"`
SourceDocuments *SourceDocuments `xml:"SourceDocuments,omitempty"`
}
AuditFile represents the root element of a SAF-T file
func BuildAuditFile ¶
func BuildAuditFile(p *AuditFileParams) (*AuditFile, error)
BuildAuditFile builds a SAF-T audit file from the given input parameters
type AuditFileParams ¶
type AuditFileParams struct {
config.Config
Issuer *org.Party
Period cal.Period
Products []*Product
Customers []*Customer
TaxTableEntries []*TaxTableEntry
SourceDocuments []SourceDocument
}
AuditFileParams provides the parameters to build a SAF-T audit file
type BuildParams ¶
type BuildParams struct {
ATCUD string
Customer *Customer
Products []*Product
SourceID string
Hash string
SigningKeyVersion string
SystemEntryDate string
}
BuildParams are the parameters for building a source document
type BuildQRCodeParams ¶
type BuildQRCodeParams struct {
Supplier *Supplier
Customer *Customer
Document SourceDocument
ATCUD string
Signature *Signature
SWCertNum int
}
BuildQRCodeParams is the parameters for building a QR code
type ClassTotals ¶
ClassTotals holds the values of a document class wrapper element that must be known before the documents of that class are streamed.
type ConvertResult ¶
type ConvertResult struct {
Document SourceDocument
Supplier *Supplier
Customer *Customer
Products []*Product
TaxTableEntries []*TaxTableEntry
}
ConvertResult provides the SAF-T structures resulting from a conversion
func (*ConvertResult) ValidateXSD ¶
func (r *ConvertResult) ValidateXSD(ctx context.Context) []error
ValidateXSD validates the XML against the official SAF-T PT XSD schema. Returns the full list of validations error or nil if none.
type Currency ¶
type Currency struct {
CurrencyCode string `xml:"CurrencyCode"`
CurrencyAmount string `xml:"CurrencyAmount"`
ExchangeRate string `xml:"ExchangeRate"`
}
Currency represents the currency information of an invoice
type Customer ¶
type Customer struct {
CustomerID string `xml:"CustomerID"`
AccountID string `xml:"AccountID"`
CustomerTaxID string `xml:"CustomerTaxID"`
CompanyName string `xml:"CompanyName"`
Contact string `xml:"Contact,omitempty"`
BillingAddress *Address `xml:"BillingAddress"`
ShipToAddresses []*Address `xml:"ShipToAddress,omitempty"`
Telephone string `xml:"Telephone,omitempty"`
Fax string `xml:"Fax,omitempty"`
Email string `xml:"Email,omitempty"`
Website string `xml:"Website,omitempty"`
SelfBillingIndicator int `xml:"SelfBillingIndicator"`
}
Customer represents a customer in a SAF-T report
func BuildCustomer ¶
BuildCustomer converts a GOBL party to a SAF-T customer
type CustomsDetails ¶
type CustomsDetails struct {
CNCode string `xml:"CNCode,omitempty"`
UNNumber string `xml:"UNNumber,omitempty"`
}
CustomsDetails represents the customs details of a product
type CustomsInformation ¶
type CustomsInformation struct {
ARCNo []string `xml:"ARCNo,omitempty"`
IECAmount string `xml:"IECAmount,omitempty"`
}
CustomsInformation represents customs information for a line
type DocTotals ¶
DocTotals holds the line count and line-amount sums of a single source document, computed with the same precision rules as the SAF-T report totals. Lines is counted for every class even though only MovementOfGoods reports it, as NumberOfMovementLines; the other three wrappers count documents, with NumberOfEntries.
func ComputeDocTotals ¶
func ComputeDocTotals(doc SourceDocument) DocTotals
ComputeDocTotals sums the line amounts of a document.
type DocumentClass ¶
type DocumentClass string
DocumentClass represents the class of source document
const ( DocumentClassInvoice DocumentClass = "SI" // Faturas e documentos retificativos DocumentClassTransport DocumentClass = "MG" // Documentos de Transporte DocumentClassWork DocumentClass = "WD" // Documentos de Conferência DocumentClassPayment DocumentClass = "PY" // Recibos )
Document class constants
type DocumentTotals ¶
type DocumentTotals struct {
TaxPayable string `xml:"TaxPayable"`
NetTotal string `xml:"NetTotal"`
GrossTotal string `xml:"GrossTotal"`
Currency *Currency `xml:"Currency,omitempty"`
Settlements []*Settlement `xml:"Settlement,omitempty"`
Payments []*PaymentMethod `xml:"Payment,omitempty"`
}
DocumentTotals represents the totals of an invoice
type Header ¶
type Header struct {
AuditFileVersion string `xml:"AuditFileVersion"`
CompanyID string `xml:"CompanyID"`
TaxRegistrationNumber string `xml:"TaxRegistrationNumber"`
TaxAccountingBasis string `xml:"TaxAccountingBasis"`
CompanyName string `xml:"CompanyName"`
BusinessName string `xml:"BusinessName,omitempty"`
CompanyAddress *Address `xml:"CompanyAddress"`
FiscalYear string `xml:"FiscalYear"`
StartDate string `xml:"StartDate"`
EndDate string `xml:"EndDate"`
CurrencyCode string `xml:"CurrencyCode"`
DateCreated string `xml:"DateCreated"`
TaxEntity string `xml:"TaxEntity"`
ProductCompanyTaxID string `xml:"ProductCompanyTaxID"`
SoftwareCertificateNumber int `xml:"SoftwareCertificateNumber"`
ProductID string `xml:"ProductID"`
ProductVersion string `xml:"ProductVersion"`
HeaderComment string `xml:"HeaderComment,omitempty"`
Telephone string `xml:"Telephone,omitempty"`
Fax string `xml:"Fax,omitempty"`
Email string `xml:"Email,omitempty"`
Website string `xml:"Website,omitempty"`
}
Header represents the header of a SAF-T file
type Invoice ¶
type Invoice struct {
InvoiceNo string `xml:"InvoiceNo"`
ATCUD string `xml:"ATCUD"`
DocumentStatus *InvoiceStatus `xml:"DocumentStatus"`
Hash string `xml:"Hash"`
HashControl string `xml:"HashControl"`
Period int `xml:"Period"`
InvoiceDate string `xml:"InvoiceDate"`
InvoiceType string `xml:"InvoiceType"`
SpecialRegimes *SpecialRegimes `xml:"SpecialRegimes"`
SourceID string `xml:"SourceID"`
EACCode string `xml:"EACCode,omitempty"`
SystemEntryDate string `xml:"SystemEntryDate"`
CustomerID string `xml:"CustomerID"`
Lines []*Line `xml:"Line"`
DocumentTotals *DocumentTotals `xml:"DocumentTotals"`
WithholdingTaxes []*WithholdingTax `xml:"WithholdingTax,omitempty"`
// store the original tax total for QR code generation
GOBLTaxTotal *tax.Total `xml:"-"`
}
Invoice represents an invoice in a SAF-T report
func BuildInvoice ¶
func BuildInvoice(ginv *bill.Invoice, p *BuildParams) (*Invoice, error)
BuildInvoice converts a GOBL invoice to a SAF-T invoice
func (*Invoice) GetCustomerID ¶
GetCustomerID returns the customer ID of the invoice
func (*Invoice) GetDocumentClass ¶
func (i *Invoice) GetDocumentClass() DocumentClass
GetDocumentClass returns the document class of the invoice
func (*Invoice) GetDocumentNo ¶
GetDocumentNo returns the document number of the invoice
func (*Invoice) GetDocumentTotals ¶
func (i *Invoice) GetDocumentTotals() *DocumentTotals
GetDocumentTotals returns the document totals of the invoice
func (*Invoice) GetDocumentType ¶
GetDocumentType returns the document type of the invoice
func (*Invoice) GetGrossTotal ¶
GetGrossTotal returns the gross total of the invoice
func (*Invoice) GetIssueDate ¶
GetIssueDate returns the issue date of the invoice
func (*Invoice) GetStatusDate ¶
GetStatusDate returns the status date of the invoice
func (*Invoice) GetStatusReason ¶
GetStatusReason returns the status reason of the invoice
func (*Invoice) GetTaxPayable ¶
GetTaxPayable returns the tax payable of the invoice
func (*Invoice) GetTaxTotal ¶
GetTaxTotal returns the tax total of the invoice
type InvoiceStatus ¶
type InvoiceStatus struct {
InvoiceStatus string `xml:"InvoiceStatus"`
InvoiceStatusDate string `xml:"InvoiceStatusDate"`
Reason string `xml:"Reason,omitempty"`
SourceID string `xml:"SourceID"`
SourceBilling string `xml:"SourceBilling"`
}
InvoiceStatus represents the status of an invoice
type Line ¶
type Line struct {
LineNumber int `xml:"LineNumber"`
OrderReferences []*OrderReference `xml:"OrderReferences,omitempty"`
ProductCode string `xml:"ProductCode"`
ProductDesc string `xml:"ProductDescription"`
Quantity string `xml:"Quantity"`
UnitOfMeasure string `xml:"UnitOfMeasure"`
UnitPrice string `xml:"UnitPrice"`
TaxBase string `xml:"TaxBase,omitempty"`
TaxPointDate string `xml:"TaxPointDate,omitempty"`
References []*References `xml:"References,omitempty"`
Description string `xml:"Description"`
DebitAmount string `xml:"DebitAmount,omitempty"`
CreditAmount string `xml:"CreditAmount,omitempty"`
Tax *Tax `xml:"Tax"`
TaxExemptionReason string `xml:"TaxExemptionReason,omitempty"`
TaxExemptionCode string `xml:"TaxExemptionCode,omitempty"`
SettlementAmount string `xml:"SettlementAmount,omitempty"`
ProductSerialNumber string `xml:"ProductSerialNumber,omitempty"`
CustomsInformation *CustomsInformation `xml:"CustomsInformation,omitempty"`
}
Line represents a line in an invoice
type MasterFiles ¶
type MasterFiles struct {
Customers []*Customer `xml:"Customer,omitempty"`
Products []*Product `xml:"Product,omitempty"`
TaxTable *TaxTable `xml:"TaxTable,omitempty"`
}
MasterFiles represents the master files of a SAF-T file
type MovementOfGoods ¶
type MovementOfGoods struct {
NumberOfMovementLines int `xml:"NumberOfMovementLines"`
TotalQuantityIssued string `xml:"TotalQuantityIssued"`
StockMovements []*StockMovement `xml:"StockMovement,omitempty"`
}
MovementOfGoods represents the movement of goods in a SAF-T file
type MovementStatus ¶
type MovementStatus struct {
MovementStatus string `xml:"MovementStatus"`
MovementStatusDate string `xml:"MovementStatusDate"`
Reason string `xml:"Reason,omitempty"`
SourceID string `xml:"SourceID"`
SourceBilling string `xml:"SourceBilling"`
}
MovementStatus represents the status of a stock movement
type OrderReference ¶
type OrderReference struct {
OriginatingON string `xml:"OriginatingON,omitempty"`
OrderDate string `xml:"OrderDate,omitempty"`
}
OrderReference represents an order reference in a line
type Payment ¶
type Payment struct {
PaymentRefNo string `xml:"PaymentRefNo"`
ATCUD string `xml:"ATCUD"`
Period int `xml:"Period,omitempty"`
TransactionID string `xml:"TransactionID,omitempty"`
TransactionDate string `xml:"TransactionDate"`
PaymentType string `xml:"PaymentType"`
Description string `xml:"Description,omitempty"`
SystemID string `xml:"SystemID,omitempty"`
DocumentStatus *PaymentStatus `xml:"DocumentStatus"`
PaymentMethods []*PaymentMethod `xml:"PaymentMethod,omitempty"`
SourceID string `xml:"SourceID"`
SystemEntryDate string `xml:"SystemEntryDate"`
CustomerID string `xml:"CustomerID"`
Lines []*PaymentLine `xml:"Line"`
DocumentTotals *DocumentTotals `xml:"DocumentTotals"`
WithholdingTaxes []*WithholdingTax `xml:"WithholdingTax,omitempty"`
// store the original tax total for QR code generation
GOBLTaxTotal *tax.Total `xml:"-"`
}
Payment represents a payment in a SAF-T file
func BuildPayment ¶
func BuildPayment(gpmt *bill.Payment, p *BuildParams) (*Payment, error)
BuildPayment builds a payment from a GOBL payment
func (*Payment) GetCustomerID ¶
GetCustomerID returns the customer ID of the payment
func (*Payment) GetDocumentClass ¶
func (p *Payment) GetDocumentClass() DocumentClass
GetDocumentClass returns the document class of the payment
func (*Payment) GetDocumentNo ¶
GetDocumentNo returns the document number of the payment
func (*Payment) GetDocumentTotals ¶
func (p *Payment) GetDocumentTotals() *DocumentTotals
GetDocumentTotals returns the document totals of the payment
func (*Payment) GetDocumentType ¶
GetDocumentType returns the document type of the payment
func (*Payment) GetGrossTotal ¶
GetGrossTotal returns the gross total of the payment
func (*Payment) GetIssueDate ¶
GetIssueDate returns the issue date of the payment
func (*Payment) GetStatusDate ¶
GetStatusDate returns the status date of the payment
func (*Payment) GetStatusReason ¶
GetStatusReason returns the status reason of the payment
func (*Payment) GetTaxPayable ¶
GetTaxPayable returns the tax payable of the payment
func (*Payment) GetTaxTotal ¶
GetTaxTotal returns the tax total of the payment
type PaymentLine ¶
type PaymentLine struct {
LineNumber int `xml:"LineNumber"`
SourceDocumentIDs []*SourceDocumentID `xml:"SourceDocumentID"`
SettlementAmount string `xml:"SettlementAmount,omitempty"`
DebitAmount string `xml:"DebitAmount,omitempty"`
CreditAmount string `xml:"CreditAmount,omitempty"`
Tax *PaymentTax `xml:"Tax,omitempty"`
TaxExemptionReason string `xml:"TaxExemptionReason,omitempty"`
TaxExemptionCode string `xml:"TaxExemptionCode,omitempty"`
}
PaymentLine represents a payment line
type PaymentMethod ¶
type PaymentMethod struct {
PaymentMechanism string `xml:"PaymentMechanism,omitempty"`
PaymentAmount string `xml:"PaymentAmount"`
PaymentDate string `xml:"PaymentDate"`
}
PaymentMethod represents a payment method
type PaymentStatus ¶
type PaymentStatus struct {
PaymentStatus string `xml:"PaymentStatus"`
PaymentStatusDate string `xml:"PaymentStatusDate"`
Reason string `xml:"Reason,omitempty"`
SourceID string `xml:"SourceID"`
SourcePayment string `xml:"SourcePayment"`
}
PaymentStatus represents the status of a payment
type PaymentTax ¶
type PaymentTax struct {
TaxType string `xml:"TaxType"`
TaxCountryRegion string `xml:"TaxCountryRegion"`
TaxCode string `xml:"TaxCode"`
TaxPercentage string `xml:"TaxPercentage,omitempty"`
TaxAmount string `xml:"TaxAmount,omitempty"`
}
PaymentTax represents the tax info of a payment line
type Payments ¶
type Payments struct {
NumberOfEntries int `xml:"NumberOfEntries"`
TotalDebit string `xml:"TotalDebit"`
TotalCredit string `xml:"TotalCredit"`
Payments []*Payment `xml:"Payment,omitempty"`
}
Payments represents the payments of a SAF-T file
type Product ¶
type Product struct {
ProductType string `xml:"ProductType"`
ProductCode string `xml:"ProductCode"`
ProductGroup string `xml:"ProductGroup,omitempty"`
ProductDesc string `xml:"ProductDescription"`
ProductNumberCode string `xml:"ProductNumberCode"`
CustomsDetails *CustomsDetails `xml:"CustomsDetails,omitempty"`
}
Product represents a product or service in the SAF-T file
func BuildDeductionProduct ¶ added in v0.0.12
BuildDeductionProduct builds a product from an advance payment deduction, using the "other" product type that SAF-T reserves for received advances.
func BuildProduct ¶
BuildProduct builds a product from a GOBL invoice line
type References ¶
type References struct {
Reference string `xml:"Reference,omitempty"`
Reason string `xml:"Reason,omitempty"`
}
References represents a reference of a line
type SalesInvoices ¶
type SalesInvoices struct {
NumberOfEntries int `xml:"NumberOfEntries"`
TotalDebit string `xml:"TotalDebit"`
TotalCredit string `xml:"TotalCredit"`
Invoices []*Invoice `xml:"Invoice,omitempty"`
}
SalesInvoices represents the sales invoices of a SAF-T file
type Settlement ¶
type Settlement struct {
SettlementDiscount string `xml:"SettlementDiscount,omitempty"`
SettlementAmount string `xml:"SettlementAmount,omitempty"`
SettlementDate string `xml:"SettlementDate,omitempty"`
PaymentTerms string `xml:"PaymentTerms,omitempty"`
}
Settlement represents a settlement of an invoice
type ShippingPoint ¶
type ShippingPoint struct {
DeliveryID []string `xml:"DeliveryID,omitempty"`
DeliveryDate string `xml:"DeliveryDate,omitempty"`
WarehouseID string `xml:"WarehouseID,omitempty"`
LocationID string `xml:"LocationID,omitempty"`
Address *Address `xml:"Address,omitempty"`
}
ShippingPoint represents a shipping point in a SAF-T file
type Signature ¶
type Signature struct {
IssueDate string
SystemEntryDate string
DocumentNo string
GrossTotal string
PreviousHash string
Hash string
}
Signature represents an invoice signature
func BuildSignature ¶
func BuildSignature(doc SourceDocument, prevSig *Signature, pkey []byte) (*Signature, error)
BuildSignature builds a signature for a given document.
func Seal ¶
func Seal(env *gobl.Envelope, prevSig *Signature, startDate cal.Date, valCode string, cfg *config.Config) (*Signature, error)
Seal generates the signature, ATCUD, and QR code for a GOBL invoice envelope and appends them as stamps to the envelope.
func (*Signature) HashCharacters ¶
HashCharacters extracts a 4-char snippet of the signature hash
type SourceDocument ¶
type SourceDocument interface {
GetDocumentClass() DocumentClass
GetDocumentType() string
GetDocumentNo() string
GetIssueDate() string
GetCustomerID() string
GetGrossTotal() string
GetStatus() string
GetStatusDate() string
GetStatusReason() string
SetStatus(status, reason, sourceID string)
GetTaxTotal() *tax.Total
GetTaxPayable() string
GetDocumentTotals() *DocumentTotals
}
SourceDocument is the interface providing common accessors for SAFT source documents
func BuildSourceDocument ¶
func BuildSourceDocument(doc any, params *BuildParams) (SourceDocument, error)
BuildSourceDocument builds a document from a given document and parameters.
func NewSourceDocument ¶
func NewSourceDocument(docClass DocumentClass) SourceDocument
NewSourceDocument builds a new source document for a given document class.
type SourceDocumentID ¶
type SourceDocumentID struct {
OriginatingON string `xml:"OriginatingON"`
InvoiceDate string `xml:"InvoiceDate"`
Description string `xml:"Description,omitempty"`
}
SourceDocumentID represents a source document ID of a payment line
type SourceDocuments ¶
type SourceDocuments struct {
SalesInvoices *SalesInvoices `xml:"SalesInvoices,omitempty"`
MovementOfGoods *MovementOfGoods `xml:"MovementOfGoods,omitempty"`
WorkingDocuments *WorkingDocuments `xml:"WorkingDocuments,omitempty"`
Payments *Payments `xml:"Payments,omitempty"`
}
SourceDocuments represents the source documents of a SAF-T file
type SpecialRegimes ¶
type SpecialRegimes struct {
SelfBillingIndicator int `xml:"SelfBillingIndicator"`
CashVATSchemeIndicator int `xml:"CashVATSchemeIndicator"`
ThirdPartiesBillingIndicator int `xml:"ThirdPartiesBillingIndicator"`
}
SpecialRegimes represents the special regimes of an invoice
type StockMovement ¶
type StockMovement struct {
DocumentNumber string `xml:"DocumentNumber"`
ATCUD string `xml:"ATCUD"`
DocumentStatus *MovementStatus `xml:"DocumentStatus"`
Hash string `xml:"Hash"`
HashControl string `xml:"HashControl"`
Period int `xml:"Period,omitempty"`
MovementDate string `xml:"MovementDate"`
MovementType string `xml:"MovementType"`
SystemEntryDate string `xml:"SystemEntryDate"`
TransactionID string `xml:"TransactionID,omitempty"`
CustomerID string `xml:"CustomerID,omitempty"`
SupplierID string `xml:"SupplierID,omitempty"`
SourceID string `xml:"SourceID"`
EACCode string `xml:"EACCode,omitempty"`
MovementComments string `xml:"MovementComments,omitempty"`
ShipTo *ShippingPoint `xml:"ShipTo,omitempty"`
ShipFrom *ShippingPoint `xml:"ShipFrom,omitempty"`
MovementEndTime string `xml:"MovementEndTime,omitempty"`
MovementStartTime string `xml:"MovementStartTime"`
ATDocCodeID string `xml:"ATDocCodeID,omitempty"`
Lines []*Line `xml:"Line"`
DocumentTotals *DocumentTotals `xml:"DocumentTotals"`
// store the original tax total for QR code generation
GOBLTaxTotal *tax.Total `xml:"-"`
}
StockMovement represents a stock movement in a SAF-T file
func BuildStockMovement ¶
func BuildStockMovement(gdlv *bill.Delivery, p *BuildParams) (*StockMovement, error)
BuildStockMovement converts a GOBL delivery to a SAF-T stock movement
func (*StockMovement) GetCustomerID ¶
func (sm *StockMovement) GetCustomerID() string
GetCustomerID returns the customer ID of the stock movement
func (*StockMovement) GetDocumentClass ¶
func (sm *StockMovement) GetDocumentClass() DocumentClass
GetDocumentClass returns the document class of the stock movement
func (*StockMovement) GetDocumentNo ¶
func (sm *StockMovement) GetDocumentNo() string
GetDocumentNo returns the document number of the stock movement
func (*StockMovement) GetDocumentTotals ¶
func (sm *StockMovement) GetDocumentTotals() *DocumentTotals
GetDocumentTotals returns the document totals of the stock movement
func (*StockMovement) GetDocumentType ¶
func (sm *StockMovement) GetDocumentType() string
GetDocumentType returns the document type of the stock movement
func (*StockMovement) GetGrossTotal ¶
func (sm *StockMovement) GetGrossTotal() string
GetGrossTotal returns the gross total of the stock movement
func (*StockMovement) GetIssueDate ¶
func (sm *StockMovement) GetIssueDate() string
GetIssueDate returns the issue date of the stock movement
func (*StockMovement) GetStatus ¶
func (sm *StockMovement) GetStatus() string
GetStatus returns the status of the stock movement
func (*StockMovement) GetStatusDate ¶
func (sm *StockMovement) GetStatusDate() string
GetStatusDate returns the status date of the stock movement
func (*StockMovement) GetStatusReason ¶
func (sm *StockMovement) GetStatusReason() string
GetStatusReason returns the status reason of the stock movement
func (*StockMovement) GetTaxPayable ¶
func (sm *StockMovement) GetTaxPayable() string
GetTaxPayable returns the tax payable of the stock movement
func (*StockMovement) GetTaxTotal ¶
func (sm *StockMovement) GetTaxTotal() *tax.Total
GetTaxTotal returns the tax total of the stock movement
func (*StockMovement) SetStatus ¶
func (sm *StockMovement) SetStatus(status, reason, sourceID string)
SetStatus sets the status of the stock movement
type StreamEncoder ¶
type StreamEncoder struct {
// contains filtered or unexported fields
}
StreamEncoder writes a SAF-T audit file incrementally to an output writer.
func NewStreamEncoder ¶
func NewStreamEncoder(w io.Writer, cfg config.Config, issuer *org.Party, per cal.Period) *StreamEncoder
NewStreamEncoder prepares a stream encoder. The issuer and period are expected to have been validated by the caller with ValidateIssuer and ValidatePeriod.
func (*StreamEncoder) Begin ¶
func (e *StreamEncoder) Begin() error
Begin writes the XML declaration, the audit file root element and its header.
func (*StreamEncoder) BeginClass ¶
func (e *StreamEncoder) BeginClass(dc DocumentClass, t ClassTotals) error
BeginClass opens the wrapper element of a document class, writing its entry count and total amounts. Classes must be written in the SAF-T schema order: SI, MG, WD, PY.
func (*StreamEncoder) End ¶
func (e *StreamEncoder) End() error
End closes all open sections and the audit file root element.
func (*StreamEncoder) WriteDocument ¶
func (e *StreamEncoder) WriteDocument(frag []byte) error
WriteDocument writes a stored source document XML fragment into the currently open document class.
func (*StreamEncoder) WriteMasterFile ¶
func (e *StreamEncoder) WriteMasterFile(frag []byte) error
WriteMasterFile writes a stored customer or product XML fragment, which both sit directly inside the master files. The caller is responsible for the order the SAF-T schema fixes: customers, then products, then tax table entries.
func (*StreamEncoder) WriteTaxTableEntry ¶
func (e *StreamEncoder) WriteTaxTableEntry(frag []byte) error
WriteTaxTableEntry writes a stored tax table entry XML fragment, one level deeper than the other master files as it is wrapped in a tax table of its own.
type Supplier ¶
type Supplier struct {
SupplierTaxID string `xml:"SupplierTaxID"`
}
Supplier represents a supplier in a SAF-T document
func BuildSupplier ¶
BuildSupplier converts a GOBL party to a SAF-T supplier
type Tax ¶
type Tax struct {
TaxType string `xml:"TaxType"`
TaxCountryRegion string `xml:"TaxCountryRegion,omitempty"`
TaxCode string `xml:"TaxCode,omitempty"`
TaxPercentage string `xml:"TaxPercentage"`
}
Tax represents the tax information of a line
type TaxTable ¶
type TaxTable struct {
TaxTableEntries []*TaxTableEntry `xml:"TaxTableEntry"`
}
TaxTable represents the tax table in the SAF-T file
type TaxTableEntry ¶
type TaxTableEntry struct {
TaxType string `xml:"TaxType"`
TaxCountryRegion string `xml:"TaxCountryRegion"`
TaxCode string `xml:"TaxCode"`
Description string `xml:"Description"`
TaxPercentage string `xml:"TaxPercentage,omitempty"`
TaxAmount string `xml:"TaxAmount,omitempty"`
TaxTableEntryID string `xml:"-"` // Auxiliary field for unique identification
}
TaxTableEntry represents an entry of that SAF-T tax table
func BuildTaxTableEntries ¶
func BuildTaxTableEntries(gts *bill.Totals) []*TaxTableEntry
BuildTaxTableEntries builds the tax table entries from GOBL tax totals
func BuildTaxTableEntry ¶
func BuildTaxTableEntry(rt *tax.RateTotal) *TaxTableEntry
BuildTaxTableEntry builds a tax table entry from a GOBL tax rate
type WithholdingTax ¶
type WithholdingTax struct {
WithholdingTaxType string `xml:"WithholdingTaxType,omitempty"`
WithholdingTaxDescription string `xml:"WithholdingTaxDescription,omitempty"`
WithholdingTaxAmount string `xml:"WithholdingTaxAmount"`
}
WithholdingTax represents a withholding tax of a payment
type WorkDocument ¶
type WorkDocument struct {
DocumentNumber string `xml:"DocumentNumber"`
ATCUD string `xml:"ATCUD"`
DocumentStatus *WorkStatus `xml:"DocumentStatus"`
Hash string `xml:"Hash,omitempty"`
HashControl string `xml:"HashControl,omitempty"`
Period int `xml:"Period"`
WorkDate string `xml:"WorkDate"`
WorkType string `xml:"WorkType"`
SourceID string `xml:"SourceID"`
EACCode string `xml:"EACCode,omitempty"`
SystemEntryDate string `xml:"SystemEntryDate"`
TransactionID string `xml:"TransactionID,omitempty"`
CustomerID string `xml:"CustomerID"`
Lines []*Line `xml:"Line"`
DocumentTotals *WorkDocumentTotals `xml:"DocumentTotals"`
// store the original tax total for QR code generation
GOBLTaxTotal *tax.Total `xml:"-"`
}
WorkDocument represents a working document in a SAF-T report
func BuildWorkDocumentFromInvoice ¶
func BuildWorkDocumentFromInvoice(ginv *bill.Invoice, p *BuildParams) (*WorkDocument, error)
BuildWorkDocumentFromInvoice converts a GOBL invoice to a SAF-T work document
func BuildWorkDocumentFromOrder ¶
func BuildWorkDocumentFromOrder(gord *bill.Order, p *BuildParams) (*WorkDocument, error)
BuildWorkDocumentFromOrder converts a GOBL order to a SAF-T work document
func (*WorkDocument) GetCustomerID ¶
func (w *WorkDocument) GetCustomerID() string
GetCustomerID returns the customer ID of the work document
func (*WorkDocument) GetDocumentClass ¶
func (w *WorkDocument) GetDocumentClass() DocumentClass
GetDocumentClass returns the document class of the work document
func (*WorkDocument) GetDocumentNo ¶
func (w *WorkDocument) GetDocumentNo() string
GetDocumentNo returns the document number of the work document
func (*WorkDocument) GetDocumentTotals ¶
func (w *WorkDocument) GetDocumentTotals() *DocumentTotals
GetDocumentTotals returns the document totals of the work document
func (*WorkDocument) GetDocumentType ¶
func (w *WorkDocument) GetDocumentType() string
GetDocumentType returns the document type of the work document
func (*WorkDocument) GetGrossTotal ¶
func (w *WorkDocument) GetGrossTotal() string
GetGrossTotal returns the gross total of the work document
func (*WorkDocument) GetIssueDate ¶
func (w *WorkDocument) GetIssueDate() string
GetIssueDate returns the issue date of the work document
func (*WorkDocument) GetStatus ¶
func (w *WorkDocument) GetStatus() string
GetStatus returns the status of the work document
func (*WorkDocument) GetStatusDate ¶
func (w *WorkDocument) GetStatusDate() string
GetStatusDate returns the status date of the work document
func (*WorkDocument) GetStatusReason ¶
func (w *WorkDocument) GetStatusReason() string
GetStatusReason returns the status reason of the work document
func (*WorkDocument) GetTaxPayable ¶
func (w *WorkDocument) GetTaxPayable() string
GetTaxPayable returns the tax payable of the work document
func (*WorkDocument) GetTaxTotal ¶
func (w *WorkDocument) GetTaxTotal() *tax.Total
GetTaxTotal returns the tax total of the work document
func (*WorkDocument) SetStatus ¶
func (w *WorkDocument) SetStatus(status, reason, sourceID string)
SetStatus sets the status of the work document
type WorkDocumentTotals ¶
type WorkDocumentTotals struct {
TaxPayable string `xml:"TaxPayable"`
NetTotal string `xml:"NetTotal"`
GrossTotal string `xml:"GrossTotal"`
Currency *Currency `xml:"Currency,omitempty"`
}
WorkDocumentTotals represents the totals of a working document
type WorkStatus ¶
type WorkStatus struct {
WorkStatus string `xml:"WorkStatus"`
WorkStatusDate string `xml:"WorkStatusDate"`
Reason string `xml:"Reason,omitempty"`
SourceID string `xml:"SourceID"`
SourceBilling string `xml:"SourceBilling"`
}
WorkStatus represents the status of a working document
type WorkingDocuments ¶
type WorkingDocuments struct {
NumberOfEntries int `xml:"NumberOfEntries"`
TotalDebit string `xml:"TotalDebit"`
TotalCredit string `xml:"TotalCredit"`
WorkDocuments []*WorkDocument `xml:"WorkDocument,omitempty"`
}
WorkingDocuments represents the working documents of a SAF-T file
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package addon provides the SAF-T addon for Portuguese invoices.
|
Package addon provides the SAF-T addon for Portuguese invoices. |
|
Package atws provides a client for the AT Web Services.
|
Package atws provides a client for the AT Web Services. |
|
soap
Package soap provides types and functions to work with SOAP messages.
|
Package soap provides types and functions to work with SOAP messages. |
|
Package config provides the configuration for the other gobl.pt.saft packages
|
Package config provides the configuration for the other gobl.pt.saft packages |
|
Package goblwrap provides wrappers to handle GOBL types generically.
|
Package goblwrap provides wrappers to handle GOBL types generically. |
|
Package realtime implements conversion from GOBL documents to the AT web service requests for realtime reporting.
|
Package realtime implements conversion from GOBL documents to the AT web service requests for realtime reporting. |
|
Package test provides common functions for testing.
|
Package test provides common functions for testing. |