Started developing this, hopefully it will be quick
This commit is contained in:
Binary file not shown.
@@ -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 ""
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user