-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfiskal-schema.go
280 lines (243 loc) · 9.84 KB
/
fiskal-schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package fiskalhrgo
// SPDX-License-Identifier: MIT
// Copyright (c) 2024 L. D. T. d.o.o.
// Copyright (c) contributors for their respective contributions. See https://github.com/l-d-t/fiskalhrgo/graphs/contributors
import (
"encoding/xml"
"fmt"
"time"
"github.com/google/uuid"
)
const DefaultNamespace = "http://www.apis-it.hr/fin/2012/types/f73"
// RacunZahtjev ...
type RacunZahtjev struct {
XMLName xml.Name `xml:"tns:RacunZahtjev"`
Xmlns string `xml:"xmlns:tns,attr"` // Declare the tns namespace
IdAttr string `xml:"Id,attr,omitempty"`
Zaglavlje *ZaglavljeType `xml:"tns:Zaglavlje"`
Racun *RacunType `xml:"tns:Racun"`
}
// RacunOdgovor ...
type RacunOdgovor struct {
XMLName xml.Name `xml:"RacunOdgovor"`
IdAttr string `xml:"Id,attr,omitempty"`
Zaglavlje *ZaglavljeOdgovorType `xml:"Zaglavlje"`
Jir string `xml:"Jir"`
Greske *GreskeType `xml:"Greske"`
}
// PrateciDokumentiZahtjev ...
type PrateciDokumentiZahtjev struct {
XMLName xml.Name `xml:"tns:PrateciDokumentiZahtjev"`
Xmlns string `xml:"xmlns:tns,attr"` // Declare the tns namespace
IdAttr string `xml:"Id,attr,omitempty"`
Zaglavlje *ZaglavljeType `xml:"tns:Zaglavlje"`
PrateciDokument *PrateciDokumentType `xml:"tns:PrateciDokument"`
}
// PrateciDokumentiOdgovor ...
type PrateciDokumentiOdgovor struct {
XMLName xml.Name `xml:"PrateciDokumentiOdgovor"`
IdAttr string `xml:"Id,attr,omitempty"`
Zaglavlje *ZaglavljeOdgovorType `xml:"Zaglavlje"`
Jir string `xml:"Jir"`
Greske *GreskeType `xml:"Greske"`
}
// RacunPDZahtjev ...
type RacunPDZahtjev struct {
XMLName xml.Name `xml:"tns:RacunPDZahtjev"`
Xmlns string `xml:"xmlns:tns,attr"` // Declare the tns namespace
IdAttr string `xml:"Id,attr,omitempty"`
Zaglavlje *ZaglavljeType `xml:"tns:Zaglavlje"`
Racun *RacunType `xml:"tns:Racun"`
}
// RacunPDOdgovor ...
type RacunPDOdgovor struct {
XMLName xml.Name `xml:"RacunPDOdgovor"`
IdAttr string `xml:"Id,attr,omitempty"`
Zaglavlje *ZaglavljeOdgovorType `xml:"Zaglavlje"`
Jir string `xml:"Jir"`
Greske *GreskeType `xml:"Greske"`
}
// PromijeniNacPlacZahtjev ...
type PromijeniNacPlacZahtjev struct {
XMLName xml.Name `xml:"tns:PromijeniNacPlacZahtjev"`
Xmlns string `xml:"xmlns:tns,attr"` // Declare the tns namespace
IdAttr string `xml:"Id,attr,omitempty"`
Zaglavlje *ZaglavljeType `xml:"tns:Zaglavlje"`
Racun *RacunType `xml:"tns:Racun"`
}
// PromijeniNacPlacOdgovor ...
type PromijeniNacPlacOdgovor struct {
XMLName xml.Name `xml:"PromijeniNacPlacOdgovor"`
IdAttr string `xml:"Id,attr,omitempty"`
Zaglavlje *ZaglavljeOdgovorType `xml:"Zaglavlje"`
PorukaOdgovora *PorukaOdgovoraType `xml:"PorukaOdgovora"`
Greske *GreskeType `xml:"Greske"`
}
// NapojnicaZahtjev ...
type NapojnicaZahtjev struct {
XMLName xml.Name `xml:"tns:NapojnicaZahtjev"`
Xmlns string `xml:"xmlns:tns,attr"` // Declare the tns namespace
IdAttr string `xml:"Id,attr,omitempty"`
Zaglavlje *ZaglavljeType `xml:"tns:Zaglavlje"`
Racun *RacunType `xml:"tns:Racun"`
}
// NapojnicaOdgovor ...
type NapojnicaOdgovor struct {
XMLName xml.Name `xml:"NapojnicaOdgovor"`
IdAttr string `xml:"Id,attr,omitempty"`
Zaglavlje *ZaglavljeOdgovorType `xml:"Zaglavlje"`
PorukaOdgovora *PorukaOdgovoraType `xml:"PorukaOdgovora"`
Greske *GreskeType `xml:"Greske"`
}
// EchoRequest represents a simple request with a text body
type EchoRequest struct {
XMLName xml.Name `xml:"tns:EchoRequest"`
Xmlns string `xml:"xmlns:tns,attr"` // Declare the tns namespace
Text string `xml:",chardata"`
}
// EchoResponse represents a simple response with a text body
type EchoResponse struct {
XMLName xml.Name `xml:"EchoResponse"`
Text string `xml:",chardata"`
}
// PorukaOdgovoraType ...
type PorukaOdgovoraType struct {
SifraPoruke string `xml:"SifraPoruke"`
Poruka string `xml:"Poruka"`
}
// ZaglavljeType is Datum i vrijeme slanja poruke.
type ZaglavljeType struct {
IdPoruke string `xml:"tns:IdPoruke"`
DatumVrijeme string `xml:"tns:DatumVrijeme"`
}
// ZaglavljeOdgovorType ...
type ZaglavljeOdgovorType struct {
IdPoruke string `xml:"IdPoruke"`
DatumVrijeme string `xml:"DatumVrijeme"`
}
// RacunType represents the invoice type with various details required for fiscalization.
type RacunType struct {
XMLName xml.Name `xml:"tns:Racun"`
Oib string `xml:"tns:Oib"`
USustPdv bool `xml:"tns:USustPdv"`
DatVrijeme string `xml:"tns:DatVrijeme"`
OznSlijed string `xml:"tns:OznSlijed"`
BrRac *BrojRacunaType `xml:"tns:BrRac"`
Pdv *PdvType `xml:"tns:Pdv,omitempty"`
Pnp *PorezNaPotrosnjuType `xml:"tns:Pnp,omitempty"`
OstaliPor *OstaliPoreziType `xml:"tns:OstaliPor,omitempty"`
IznosOslobPdv string `xml:"tns:IznosOslobPdv,omitempty"`
IznosMarza string `xml:"tns:IznosMarza,omitempty"`
IznosNePodlOpor string `xml:"tns:IznosNePodlOpor,omitempty"`
Naknade *NaknadeType `xml:"tns:Naknade,omitempty"`
IznosUkupno string `xml:"tns:IznosUkupno"`
NacinPlac string `xml:"tns:NacinPlac"`
OibOper string `xml:"tns:OibOper"`
ZastKod string `xml:"tns:ZastKod"`
NakDost bool `xml:"tns:NakDost"`
ParagonBrRac string `xml:"tns:ParagonBrRac,omitempty"`
SpecNamj string `xml:"tns:SpecNamj,omitempty"`
PrateciDokument *PrateciDokument `xml:"tns:PrateciDokument,omitempty"`
PromijenjeniNacinPlac string `xml:"tns:PromijenjeniNacinPlac,omitempty"`
Napojnica *NapojnicaType `xml:"tns:Napojnica,omitempty"`
// Additional functional non XML fields
pointerToEntity *FiskalEntity // Pointer to the FiskalEntity
oldEntityForOldZKI *FiskalEntity // Pointer to the old FiskalEntity for the old ZKI
// This is used in the edge case that the ZKI was generated with one certificate and the fiscalization failed
// But the certificate expired or had to be changed and now fiscalization have to be repeated with new certificate
// If we replace the original ZKI its a problem we already gave the invoice with old ZKI out
// So we have to keep the old ZKI and validate it with the old certificate before signing and sending with new one
// In any case this is set by IhaveZKIwithExpiredCertificateEdgeCase(EntityWithOldCertLoaded *FiskalEntity) method
}
// PrateciDokumentType ...
type PrateciDokumentType struct {
Oib string `xml:"tns:Oib"`
DatVrijeme string `xml:"tns:DatVrijeme"`
BrPratecegDokumenta *BrojPDType `xml:"tns:BrPratecegDokumenta"`
IznosUkupno string `xml:"tns:IznosUkupno"`
ZastKodPD string `xml:"tns:ZastKodPD"`
NakDost bool `xml:"tns:NakDost"`
}
// PrateciDokument ...
type PrateciDokument struct {
JirPD string `xml:"tns:JirPD"`
ZastKodPD string `xml:"tns:ZastKodPD"`
}
// NapojnicaType ...
type NapojnicaType struct {
IznosNapojnice string `xml:"tns:iznosNapojnice"`
NacinPlacanjaNapojnice string `xml:"tns:nacinPlacanjaNapojnice"`
}
// GreskeType ...
type GreskeType struct {
Greska []*GreskaType `xml:"Greska"`
}
// GreskaType ...
type GreskaType struct {
SifraGreske string `xml:"SifraGreske"`
PorukaGreske string `xml:"PorukaGreske"`
}
// NaknadeType ...
type NaknadeType struct {
Naknada []*NaknadaType `xml:"tns:Naknada"`
}
// NaknadaType ...
type NaknadaType struct {
NazivN string `xml:"tns:NazivN"`
IznosN string `xml:"tns:IznosN"`
}
// OstaliPoreziType ...
type OstaliPoreziType struct {
Porez []*PorezOstaloType `xml:"tns:Porez"`
}
// PorezNaPotrosnjuType ...
type PorezNaPotrosnjuType struct {
Porez []*PorezType `xml:"tns:Porez"`
}
// PdvType ...
type PdvType struct {
Porez []*PorezType `xml:"tns:Porez"`
}
// PorezOstaloType ...
type PorezOstaloType struct {
Naziv string `xml:"tns:Naziv"`
Stopa string `xml:"tns:Stopa"`
Osnovica string `xml:"tns:Osnovica"`
Iznos string `xml:"tns:Iznos"`
}
// PorezType ...
type PorezType struct {
Stopa string `xml:"tns:Stopa"`
Osnovica string `xml:"tns:Osnovica"`
Iznos string `xml:"tns:Iznos"`
}
// BrojRacunaType ...
type BrojRacunaType struct {
BrOznRac uint `xml:"tns:BrOznRac"`
OznPosPr string `xml:"tns:OznPosPr"`
OznNapUr uint `xml:"tns:OznNapUr"`
}
// BrojPDType ...
type BrojPDType struct {
BrOznPD int `xml:"tns:BrOznPD"`
OznPosPr string `xml:"tns:OznPosPr"`
OznNapUr int `xml:"tns:OznNapUr"`
}
// generateUniqueID generates a unique ID
func generateUniqueID() string {
return fmt.Sprintf("%x", time.Now().UnixNano())
}
// newFiskalHeader creates a new instance of ZaglavljeType with a unique message ID and the current timestamp
//
// This function generates a new UUIDv4 for the IdPoruke field to ensure that each message has a unique identifier.
// It also sets the DatumVrijeme field to the current time formatted as "2006-01-02T15:04:05" to indicate when the message was created.
//
// Returns:
//
// *ZaglavljeType: A pointer to a new ZaglavljeType instance with the IdPoruke and DatumVrijeme fields populated.
func newFiskalHeader() *ZaglavljeType {
return &ZaglavljeType{
IdPoruke: uuid.New().String(),
DatumVrijeme: time.Now().Format("02.01.2006T15:04:05"),
}
}