commit 9f731d053f36ffcacf6eb93216607f5f41505040 Author: Eduardo Silva Date: Wed Sep 3 23:53:39 2025 +0100 Started developing this, hopefully it will be quick diff --git a/Especificações_Técnicas_-_Especificacoes_Tecnicas_Codigo_QR.pdf b/Especificações_Técnicas_-_Especificacoes_Tecnicas_Codigo_QR.pdf new file mode 100644 index 0000000..f4aeb38 Binary files /dev/null and b/Especificações_Técnicas_-_Especificacoes_Tecnicas_Codigo_QR.pdf differ diff --git a/fatQR.go b/fatQR.go new file mode 100644 index 0000000..9677901 --- /dev/null +++ b/fatQR.go @@ -0,0 +1,75 @@ +package gofatqr + +// TODO +// Check what we can take form SAF-T to put here, maybe work on a SAF-T +// implementation too, who knows amirite + +import ( + "fmt" + "math/big" + "strings" + "time" +) + +type FiscalSpace struct { + TaxCountryRegion string // 1 - fiscal space + TaxableBase *big.Rat // 2 + TaxabledReduced *big.Rat // 3 + VatTotalReducedTax *big.Rat // 4 + TaxableIntermediateBase *big.Rat // 5 + VatTotalIntermediateTax *big.Rat // 6 + TaxableNormalBase *big.Rat // 7 + VatTotalNormalBase *big.Rat // 8 +} + +type FatQR struct { + TaxRegistrationNumber string // A + CustomerTaxID string // B + Country string // C - customer country + InvoiceType string // D + InvoiceStatus bool // E + InvoiceDate time.Time // F + InvoiceNo string // G + ATCUD string // H + IFiscalSpace FiscalSpace // I1 - I8 + JFiscalSpace FiscalSpace // I1 - I8 + KFiscalSpace FiscalSpace // I1 - I8 + NotTaxable *big.Rat // L + StampDuty *big.Rat // M - "Imposto de Selo" + TaxPayable *big.Rat // N + GrossTotal *big.Rat // O + WithholdingTaxAmount *big.Rat // P + HashQuartet string // Q + SoftwareCertificateNumber int // R + OtherInfo string // S +} + +type part struct { + key string + value string +} + +func (fq *FatQR) scanParts(parts []string) error { + fmt.Println(parts) + + for k := range parts { + keyValuePair := strings.Split(parts[k], ":") + if len(keyValuePair) != 2 { + return fmt.Errorf("failed to parse key value pair: %s", parts[k]) + } + } + + return nil +} + +func (fq *FatQR) Scan(s string) error { + parts := strings.Split(s, "*") + + fq.scanParts(parts) + + return nil +} + +func (fq *FatQR) String() string { + return "" +} diff --git a/fatQR_test.go b/fatQR_test.go new file mode 100644 index 0000000..5df416f --- /dev/null +++ b/fatQR_test.go @@ -0,0 +1,15 @@ +package gofatqr + +import ( + "testing" +) + +func TestScan(t *testing.T) { + testStr := "A:513847588*B:239752988*C:PT*D:FS*E:N*F:20250828*G:FS 437251001/115666*H:0*I1:PT*I7:37.94*I8:8.73*N:8.73*O:46.67*Q:mWUp*R:0177" + + var qr FatQR + err := qr.Scan(testStr) + if err != nil { + t.Errorf("Should not have occurred an error for: %s, %+v", testStr, err) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9a58200 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module gofatqr + +go 1.24.6 diff --git a/main.go b/main.go new file mode 100644 index 0000000..606219e --- /dev/null +++ b/main.go @@ -0,0 +1,4 @@ +package gofatqr + +func Parse(data string) { +}