-
Notifications
You must be signed in to change notification settings - Fork 1
/
corrected.go
44 lines (37 loc) · 1.06 KB
/
corrected.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
package ksef
import (
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/head"
)
// CorrectedInv defines the XML structure for KSeF correction invoice
type CorrectedInv struct {
IssueDate string `xml:"DataWystFaKorygowanej,omitempty"`
SequentialNumber string `xml:"NrFaKorygowanej,omitempty"`
KsefNumberPresent int `xml:"NrKSeF,omitempty"`
NoKsefNumberPresent int `xml:"NrKSeFN,omitempty"`
KsefNumber string `xml:"NrKSeFFaKorygowanej,omitempty"`
}
// NewCorrectedInv gets credit note data from GOBL invoice
func NewCorrectedInv(prc *bill.Preceding) *CorrectedInv {
inv := &CorrectedInv{
SequentialNumber: invoiceNumber(prc.Series, prc.Code),
}
if prc.IssueDate != nil {
inv.IssueDate = prc.IssueDate.String()
}
if id := findStamp(prc.Stamps, "ksef-id"); id != -1 {
inv.KsefNumberPresent = 1
inv.KsefNumber = prc.Stamps[id].Value
} else {
inv.NoKsefNumberPresent = 1
}
return inv
}
func findStamp(a []*head.Stamp, x string) int {
for i, n := range a {
if x == string(n.Provider) {
return i
}
}
return -1
}