-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoice_types.go
599 lines (470 loc) · 21.2 KB
/
invoice_types.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
package basware
// Accounting related content.
type Accounting struct {
// Virtual bar code can be added to the business document that should be
// printed.
VirtualBankBarcode VirtualBankBarcode `json:"virtualBankBarcode,omitempty"`
}
// Party that is the accountable buyer of the goods/services in the referred
// business document.
type AccountingCustomerParty struct {
// An array holding the external system identifiers of the party. Used for
// defining customer, supplier and delivery party data.
Endpoint Endpoint `json:"endpoint,omitempty"`
// An array holding the external system identifiers of the party. Used for
// defining customer, supplier and delivery party data.
PartyIdentification []PartyIdentificationItem `json:"partyIdentification,omitempty"`
// A name of the party. Used for defining supplier, customer and delivery
// party names.
PartyName string `json:"partyName"`
// An object containing address information. Used for defining supplier
// party, customer party and delivery party address data.
PostalAddress PostalAddress `json:"postalAddress,omitempty"`
// An object containing information about contacts. Used for defining the
// company contact data
Contact Contact `json:"contact,omitempty"`
// Information about taxes. Notice that only one tax scheme is used,
// although there could be multiple.
PartyTaxScheme PartyTaxScheme `json:"partyTaxScheme,omitempty"`
}
// Information about taxes. Notice that only one tax scheme is used, although
// there could be multiple.
type PartyTaxScheme struct {
// Information about the company taxes.
Company PartyTaxSchemeCompany `json:"company,omitempty"`
}
// Information about the company taxes.
type PartyTaxSchemeCompany struct {
// A tax identifier for a company. The identifier assigned for tax purposes
// to a party by the taxation authority.
ID string `json:"id,omitempty"`
// External global identifier of the endpoint identifier element. Valid
// values: Country specific agency schema, example DK:CVR for Denmark.
SchemeID string `json:"schemeId,omitempty"`
}
// Party that is the accountable supplier of the goods/services in the referred
// business document.
type AccountingSupplierParty struct {
// An array holding the external system identifiers of the party. Used for
// defining customer, supplier and delivery party data.
Endpoint Endpoint `json:"endpoint,omitempty"`
// An array holding the external system identifiers of the party. Used for
// defining customer, supplier and delivery party data.
PartyIdentification []PartyIdentificationItem `json:"partyIdentification,omitempty"`
// A name of the party. Used for defining supplier, customer and delivery
// party names.
PartyName string `json:"partyName"`
// An object containing address information. Used for defining supplier
// party, customer party and delivery party address data.
PostalAddress PostalAddress `json:"postalAddress,omitempty"`
// Information about taxes. Notice that only one tax scheme is used,
// although there could be multiple.
PartyTaxScheme PartyTaxScheme `json:"partyTaxScheme,omitempty"`
// An object containing information about contacts. Used for defining the
// company contact data
Contact Contact `json:"contact,omitempty"`
}
// An object containing information about contacts. Used for defining the
// company contact data
type Contact struct {
// A contact name of the party.
Name string `json:"name,omitempty"`
// A telephone number of the contact of the party.
Telephone string `json:"telephone,omitempty"`
// A fax number of the contact of the party.
Telefax string `json:"telefax,omitempty"`
// An email of the contact of the party.
ElectronicMail string `json:"electronicMail,omitempty"`
}
// An array holding the external system identifiers of the party. Used for
// defining customer, supplier and delivery party data.
type Endpoint struct {
// An object holding the external system identifier of the party.
ID string `json:"id"`
// External global identifier of the id identifier element.
SchemeID string `json:"schemeId,omitempty"`
}
// An object holding a party identification.
type PartyIdentificationItem struct {
// An object holding the external system identifier of the party.
ID string `json:"id"`
// External global identifier of the id identifier element.
SchemeID string `json:"schemeId,omitempty"`
}
type AdditionalDocumentReference struct {
// An identifier for the referenced document (i.e. bumid).
ID string `json:"id"`
// External system specific identifier of the invoicing system identifier
// element. If the source business document has any matching element, it
// should be used.
SchemeID string `json:"schemeId,omitempty"`
// Date when the referenced document was issued. Valid values must be in
// format: CCYY-MM-DD. If the time zone is known, it must be represented
// with +hh:mm or -hh:mm or Z (which means UTC). If time zone is not known,
// it must be left empty.
IssueDate string `json:"issueDate,omitempty"`
// The type of document being referenced, expressed as a code, for example
// to reference to an Invoice document, code is 380.
TypeCode string `json:"typeCode,omitempty"`
}
type BillingReference struct {
// External system identifier of the billing entity referenced by the
// Business Document.
ID string `json:"id"`
// External system specific identifier of the billing reference system
// identifier element. If the source business document has any matching
// element, it should be used.
SchemeID string `json:"schemeId,omitempty"`
}
type BuyerReference struct {
// The id value of the buyer reference
ID string `json:"id"`
}
type ContractDocumentReference struct {
// External system identifier of the contract referenced by the Business
// Document (i.e. buyers contract number). Mandatory field if the customer
// demands that the goods or services invoiced refer to a contract number
// defined by the customer to which he wants to assign the Business
// Document. Is demanded for example in service and maintenance agreements
// for which there is generally no explicit order.
ID string `json:"id"`
// External system specific identifier of the contract system identifier
// element. If the source business document has any matching element, it should
// be used.
SchemeID string `json:"schemeId,omitempty"`
}
// Object holding the business content of the Invoice. Content is at some level
// based on Universal Business Language (UBL) standard version 2.1. It has also
// been extended by Basware so it is not strictly UBL.
type Invoice struct {
// External system identifier of the business document.
ID string `json:"id"`
// External system specific identifier of the system identifier element. If
// the source business document has any matching element, it should be used.
IDSchemeID string `json:"idSchemeId,omitempty"`
// The date when the Invoice was issued. Valid values must be in format:
// CCYY-MM-DD. If the time zone is known, it must be represented with +hh:mm
// or -hh:mm or Z (which means UTC). If time zone is not known, it must be
// left empty.
IssueDate string `json:"issueDate"`
// Currency presentation of the Invoice document. Valid values must be ISO
// 4217 Alpha format.
DocumentCurrencyCode string `json:"documentCurrencyCode,omitempty"`
// Free-form text pertinent to this document, conveying information that is
// not contained explicitly in other structures.
Note string `json:"note,omitempty"`
AllowanceCharge AllowanceCharge `json:"allowanceCharge,omitempty"`
OrderReference OrderReference `json:"orderReference,omitempty"`
BillingReference BillingReference `json:"billingReference,omitempty"`
ContractDocumentReference ContractDocumentReference `json:"contractDocumentReference,omitempty"`
AdditionalDocumentReference AdditionalDocumentReference `json:"additionalDocumentReference,omitempty"`
// Party that is the accountable supplier of the goods/services in the
// referred business document.
AccountingSupplierParty AccountingSupplierParty `json:"accountingSupplierParty"`
// Party that is the accountable buyer of the goods/services in the referred
// business document.
AccountingCustomerParty AccountingCustomerParty `json:"accountingCustomerParty"`
BuyerReference BuyerReference `json:"buyerReference,omitempty"`
Delivery Delivery `json:"delivery,omitempty"`
DeliveryParty DeliveryParty `json:"deliveryParty,omitempty"`
// An array holding the Invoice lines.
InvoiceLine []InvoiceLine `json:"invoiceLine"`
LegalMonetaryTotal LegalMonetaryTotal `json:"legalMonetaryTotal"`
// An object holding the available payment means.
PaymentMeans PaymentMeans `json:"paymentMeans,omitempty"`
PaymentTerms PaymentTerms `json:"paymentTerms,omitempty"`
TaxTotal TaxTotal `json:"taxTotal,omitempty"`
}
type AllowanceCharge struct {
// Freight charge.
Freight float64 `json:"freight,omitempty"`
// Handling charge.
Handling float64 `json:"handling,omitempty"`
}
// func (a *AllowanceCharge) MarshalJSON() ([]byte, error) {
// if zero.IsZero(a) {
// return json.Marshal(nil)
// }
// type Alias AllowanceCharge
// alias := Alias(*a)
// return json.Marshal(alias)
// }
type Delivery struct {
// Date when the goods/services are delivered. Valid values must be in
// format: CCYY-MM-DD. If the time zone is known, it must be represented
// with +hh:mm or -hh:mm or Z (which means UTC). If time zone is not known,
// it must be left empty.
ActualDeliveryDate string `json:"actualDeliveryDate,omitempty"`
}
// Party that is responsible for the delivery of the goods/services in the
// referred business document.
type DeliveryParty struct {
Contact Contact `json:"contact,omitempty"`
Endpoint Endpoint `json:"endpoint,omitempty"`
PartyIdentification []PartyIdentificationItem `json:"partyIdentification,omitempty"`
PartyName string `json:"partyName"`
PartyTaxScheme PartyTaxScheme `json:"partyTaxScheme,omitempty"`
PostalAddress PostalAddress `json:"postalAddress,omitempty"`
}
// Description of the Business Document line item.
type DescriptionItem string
type FileRef struct {
FileType string `json:"fileType"`
RefID string `json:"refId"`
}
// Object holding the financial account data
type FinancialAccountItem struct {
// The name of financial institution.
FinancialInstitutionName string `json:"financialInstitutionName,omitempty"`
// Identifier of financial institution.
FinancialInstitutionID string `json:"financialInstitutionId,omitempty"`
// The external identifier of the financial institution id identifier
// element.
FinancialInstitutionIDSchemeID string `json:"financialInstitutionIdSchemeId,omitempty"`
// The identifier of financial institution branch, for example 342-085. This
// field is typically used by institutions in Australia and New Zealand.
FinancialInstitutionBranchID string `json:"financialInstitutionBranchId,omitempty"`
// The scheme identifier of financial institution branch. For example for an
// Australian institutions, possible scheme is BSB.
FinancialInstitutionBranchSchemeID string `json:"financialInstitutionBranchSchemeId,omitempty"`
// Array holding ids
Ids []ID `json:"ids,omitempty"`
// Accounting related content.
Accounting Accounting `json:"accounting,omitempty"`
}
// Object holding identifier data
type ID struct {
// Identifier.
ID string `json:"id"`
// External identifier.
SchemeID string `json:"schemeId,omitempty"`
}
// An object holding a Invoice line.
type InvoiceLine struct {
// External system identifier for the Invoice line.
ID string `json:"id"`
// Internal identifier for the Invoice line.
InternalID string `json:"internalId,omitempty"`
Quantity Quantity `json:"quantity,omitempty"`
// Flag indicating whether the line represents goods or services (true if
// services, false if goods).
ServiceIndicator bool `json:"serviceIndicator,omitempty"`
LineExtension LineExtension `json:"lineExtension"`
Item Item `json:"item"`
TaxTotal []TaxTotalItem `json:"taxTotal,omitempty"`
AllowanceCharge *AllowanceCharge `json:"allowanceCharge,omitempty"`
Delivery Delivery `json:"delivery,omitempty"`
OrderLineReference OrderLineReference `json:"orderLineReference,omitempty"`
Price Price `json:"price,omitempty"`
}
// func (i InvoiceLine) MarshalJSON() ([]byte, error) {
// type Alias InvoiceLine
// alias := Alias(i)
// b, err := json.Marshal(alias)
// if err != nil {
// return b, err
// }
// // Options:
// // * to map[string]interface{}
// // fast json parser with query language
// // to map[string]*json.RawMessage
// v := make(map[string]json.RawMessage)
// err = json.Unmarshal(b, &v)
// // * loop omitempty's
// // * unmarshal back to type
// // * check for zero
// // * remove entry from map
// // * marshal map again
// log.Fatal(v)
// return json.Marshal(alias)
// }
type Item struct {
// An array holding the descriptions of the Business Document line items.
Description []DescriptionItem `json:"description,omitempty"`
// Name of the Business Document line item. A short name optionally given
// to an item, such as a name from a catalogue, as distinct from a
// description.
Name string `json:"name,omitempty"`
// An object holding a identification of the Business Documents line item as
// it is in sellers system.
SellersItem SellersItem `json:"sellersItem,omitempty"`
// Tax amount for the item
TaxPercent float64 `json:"taxPercent,omitempty"`
}
type LegalMonetaryTotal struct {
// An object holding total amount of line extensions.
LineExtensionAmount Amount `json:"lineExtensionAmount,omitempty"`
// An object holding total payable amount of line extensions.
PayableAmount Amount `json:"payableAmount"`
}
type LineExtension struct {
// The currency of the amount.
CurrencyID string `json:"currencyId"`
// The total amount for the line item, including allowance charges but net
// of taxes.
Amount float64 `json:"amount"`
}
// An object holding total amount of line extensions.
type LineExtensionAmount struct {
Amount float64 `json:"amount"`
CurrencyID string `json:"currencyId"`
}
// Links related to the business document
type Link struct {
Href string `json:"href,omitempty"`
Method string `json:"method,omitempty"`
Rel string `json:"rel,omitempty"`
}
type OrderLineReference struct {
LineID string `json:"lineId"`
OrderReference string `json:"orderReference,omitempty"`
}
type OrderReference struct {
// Order number reference on the business document. Identifies the referenced
// order assigned by the buyer.
ID string `json:"id"`
// External system specific identifier of the order system identifier element. If
// the source business document has any matching element, it should be used.
SchemeID string `json:"schemeId,omitempty"`
// Customer Reference Identifier (CRI) when using a purchasing card.
CustomerReference string `json:"customerReference,omitempty"`
// Sales order identifier.
SalesOrderID string `json:"salesOrderId,omitempty"`
}
// An object holding total payable amount of line extensions.
type Amount struct {
// Total amount of line extensions.
Amount float64 `json:"amount"`
// A code that identifies the currency of the total line extension amount.
// Valid values: ISO 4217 code represented as string.
CurrencyID string `json:"currencyId"`
}
// An identifier for a payment made using this means of payment.
type PaymentIdentifier struct {
ID string `json:"id"`
SchemeID string `json:"schemeId,omitempty"`
}
// An object holding the available payment means.
type PaymentMeans struct {
// A code that identifies how the payment can be done. Valid values: UN/ECE
// 4461 code represented as string.
PaymentMeansCode string `json:"paymentMeansCode"`
// Date when the business document is due for the payment means. Valid
// values must be in format: CCYY-MM-DD. If the time zone is known, it must
// be represented with +hh:mm or -hh:mm or Z (which means UTC). If time zone
// is not known, it must be left empty.
PaymentDueDate string `json:"paymentDueDate,omitempty"`
// An identifier for a payment made using this means of payment.
PaymentIdentifier PaymentIdentifier `json:"paymentIdentifier,omitempty"`
// Array holding the financial account data
FinancialAccount []FinancialAccountItem `json:"financialAccount,omitempty"`
}
type PaymentTerms struct {
Note string `json:"note,omitempty"`
PenaltySurchargePercent float64 `json:"penaltySurchargePercent,omitempty"`
SettlementPeriod SettlementPeriod `json:"settlementPeriod,omitempty"`
}
type Price struct {
Amount float64 `json:"amount"`
CurrencyID string `json:"currencyId"`
}
type Quantity struct {
// The quantity of the target Business Document line items.
Amount float64 `json:"amount,omitempty"`
// The available quantity of the target Business Document line item which
// has not been invoiced.
AmountUninvoiced float64 `json:"amountUninvoiced,omitempty"`
// The unit code of the quantity of the target Business Document line item.
// Valid values: UN/ECE CEFACT Trade Facilitation Recommendation No.20
// common code value represented as string.
UnitCode string `json:"unitCode,omitempty"`
}
// An object holding a identification of the Business Documents line item as it
// is in sellers system.
type SellersItem struct {
ID string `json:"id"`
SchemeID string `json:"schemeId,omitempty"`
}
// An object holding the settlement period dates.
type SettlementPeriod struct {
// Date when the payment terms starts. Valid values must be in format:
// CCYY-MM-DD. If the time zone is known, it must be represented with +hh:mm
// or -hh:mm or Z (which means UTC). If time zone is not known, it must be
// left empty.
StartDate string `json:"startDate,omitempty"`
// Date when the payment terms ends. Valid values must be in format:
// CCYY-MM-DD. If the time zone is known, it must be represented with +hh:mm
// or -hh:mm or Z (which means UTC). If time zone is not known, it must be
// left empty.
EndDate string `json:"endDate,omitempty"`
}
type TaxTotal struct {
// A code that identifies the currency of the total payable amount. Valid
// values: ISO 4217 code represented as string.
CurrencyID string `json:"currencyId"`
// Total amount of the taxes. The total tax amount for particular tax scheme
// e.g. VAT; the sum of each of the tax subtotals for each tax category
// within the tax scheme.
Amount float64 `json:"amount"`
TaxSubTotal []TaxSubTotalItem `json:"taxSubTotal,omitempty"`
}
// An object holding the information about tax.
type TaxTotalItem struct {
// Total amount of the taxes. The total tax amount for particular tax scheme
// e.g. VAT; the sum of each of the tax subtotals for each tax category
// within the tax scheme.
Amount float64 `json:"amount"`
// A code that identifies the currency of the total payable amount. Valid
// values: ISO 4217 code represented as string.
CurrencyID string `json:"currencyId"`
// An object holding transaction tax.
TransactionCurrencyTax TransactionCurrencyTax `json:"transactionCurrencyTax,omitempty"`
TaxSubTotal []TaxSubTotalItem `json:"taxSubTotal,omitempty"`
}
// An object holding the information about tax.
type TaxSubTotalItem struct {
// A code that identifies the currency of the tax subtotal. Valid values:
// ISO 4217 code represented as string.
CurrencyID string `json:"currencyId"`
// Total amount of the taxes.
Amount float64 `json:"amount"`
// The tax rate for the category, expressed as a percentage.
Percent float64 `json:"percent,omitempty"`
// Basis of the taxes. The net amount to which the tax percent (rate) is
// applied to calculate the tax amount.
TaxableAmount float64 `json:"taxableAmount,omitempty"`
}
// An object holding transaction tax.
type TransactionCurrencyTax struct {
Amount float64 `json:"amount"`
}
// Virtual bar code can be added to the business document that should be printed.
type VirtualBankBarcode struct {
// Identifier of the virtual bar code.
VirtualBankBarCode string `json:"id,omitempty"`
// Scheme identifier of the virtual bank bar code, typically country code
// according to ISO3166-1 alpha-2. Possible values: FI
SchemeIDForVirtualBankBarCode string `json:"schemeId,omitempty"`
}
// An object containing address information. Used for defining supplier party,
// customer party and delivery party address data.
type PostalAddress struct {
// The name of the city, town or village in the postal address of the party.
CityName string `json:"cityName"`
// The postal code of the area in the postal address of the party. The
// identifier for an addressable group of properties according to the
// relevant national postal service, such as a ZIP code or Post Code.
PostalZone string `json:"postalZone"`
// The address line of the postal address of the party.
AddressLine string `json:"addressLine"`
// The second address line of the postal address of the party.
AddressLine2 string `json:"addressLine2"`
// Neighbourhood or district within town or city. Required in UK if a
// similar road name exists within a post town area.
Locality string `json:"locality"`
// The sub-entity of the area in the postal address.
CountrySubentity string `json:"countrySubentity"`
// The country of the postal address of party. Valid values: ISO3166-1
// alpha-2 values can be used.
CountryID string `json:"countryId"`
}