Skip to content

Commit 17ac7d2

Browse files
committed
Refactor and reorganization
1 parent 42d0fdd commit 17ac7d2

10 files changed

+697
-564
lines changed

README-HR.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,6 @@ func main() {
126126
"G", // payment method G - cash, K - credit card, T -
127127
// transfer, O - other, C - check (deprecated)
128128
"12345678901", // operator OIB
129-
false, // late delivery, if previous attempt failed but the
130-
// invoice was issued with just ZKI
131-
"", // receipt book number, if the invoicing system was
132-
// unusable and the invoice was issued manually, the
133-
// number of the receipt book
134-
"", // unused, reserved field for future or temporary
135-
// unexpected use by the CIS, should be empty
136129
)
137130

138131
if err != nil {
@@ -151,14 +144,14 @@ func main() {
151144
// serial of the certificate used to generate it for future reference. You
152145
// can get the cert serial with fiskalEntity.GetCertSERIAL().
153146

154-
// Display the invoice
147+
// Display the invoice for test
155148
fmt.Println(invoice)
156149

157150
// NOW we should have a saved invoice with a valid ZKI and we are ready to
158151
// send the invoice to the CIS
159152

160153
// Send test invoice to CIS with InvoiceRequest
161-
jir, zkiR, err := fiskalEntity.InvoiceRequest(invoice)
154+
jir, zkiR, err := invoice.InvoiceRequest()
162155

163156
if err != nil {
164157
log.Fatalf("Failed to send invoice: %v", err)

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ func main() {
125125
"G", // payment method G - cash, K - credit card, T -
126126
// transfer, O - other, C - check (deprecated)
127127
"12345678901", // operator OIB
128-
false, // late delivery, if previous attempt failed but the
129-
// invoice was issued with just ZKI
130-
"", // receipt book number, if the invoicing system was
131-
// unusable and the invoice was issued manually, the
132-
// number of the receipt book
133-
"", // unused, reserved field for future or temporary
134-
// unexpected use by the CIS, should be empty
135128
)
136129

137130
if err != nil {
@@ -150,14 +143,14 @@ func main() {
150143
// serial of the certificate used to generate it for future reference. You
151144
// can get the cert serial with fiskalEntity.GetCertSERIAL().
152145

153-
// Display the invoice
146+
// Display the invoice for test
154147
fmt.Println(invoice)
155148

156149
// NOW we should have a saved invoice with a valid ZKI and we are ready to
157150
// send the invoice to the CIS
158151

159152
// Send test invoice to CIS with InvoiceRequest
160-
jir, zkiR, err := fiskalEntity.InvoiceRequest(invoice)
153+
jir, zkiR, err := invoice.InvoiceRequest()
161154

162155
if err != nil {
163156
log.Fatalf("Failed to send invoice: %v", err)

basicvalidators.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ func IsValidCurrencyFormat(amount string) bool {
1717
return validCurrency.MatchString(amount)
1818
}
1919

20+
// IsValidTaxRate checks if the given string is a valid non-negative tax rate with exactly two decimal places.
21+
// Allows positive values and 0.00, but not negative values.
22+
func IsValidTaxRate(rate string) bool {
23+
// Regex pattern to match a positive or zero decimal number with exactly two decimal places
24+
// Matches values like "0.00", "25.00", "5.00", etc.
25+
validTaxRate := regexp.MustCompile(`^([0-9]+)(\.[0-9]{2})$`)
26+
return validTaxRate.MatchString(rate)
27+
}
28+
2029
// ValidateOIB checks if an OIB is valid using the Mod 11, 10 algorithm
2130
func ValidateOIB(oib string) bool {
2231
if len(oib) != 11 {
@@ -86,3 +95,19 @@ func IsFileReadable(filePath string) bool {
8695

8796
return true
8897
}
98+
99+
// ValidateJIR checks if the given JIR is a valid UUID format (e.g., "9d6f5bb6-da48-4fcd-a803-4586a025e0e4").
100+
// Returns true if valid, otherwise false.
101+
func ValidateJIR(jir string) bool {
102+
// Regular expression to match UUID format (e.g., "9d6f5bb6-da48-4fcd-a803-4586a025e0e4")
103+
var jirRegex = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
104+
return jirRegex.MatchString(jir)
105+
}
106+
107+
// ValidateZKI checks if the given ZKI is a valid MD5 hash in hexadecimal format (32 characters).
108+
// Returns true if valid, otherwise false.
109+
func ValidateZKI(zki string) bool {
110+
// Regular expression to match a 32-character hexadecimal MD5 hash
111+
var zkiRegex = regexp.MustCompile(`^[0-9a-f]{32}$`)
112+
return zkiRegex.MatchString(zki)
113+
}

dsignandverify.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,10 @@ import (
1111
"crypto/x509"
1212
"encoding/base64"
1313
"fmt"
14-
"time"
1514

1615
"github.com/beevik/etree"
1716
)
1817

19-
// generateUniqueID generates a unique ID
20-
func generateUniqueID() string {
21-
return fmt.Sprintf("%x", time.Now().UnixNano())
22-
}
23-
2418
// doc14n applies Exclusive Canonical XML (http://www.w3.org/2001/10/xml-exc-c14n#) to the input XML data
2519
func doc14n(xmlData []byte) ([]byte, error) {
2620
// Parse the input XML string into an etree.Document

0 commit comments

Comments
 (0)