-
Notifications
You must be signed in to change notification settings - Fork 0
/
cancel.go
37 lines (31 loc) · 1.02 KB
/
cancel.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
package verifactu
import (
"errors"
"github.com/invopop/gobl"
"github.com/invopop/gobl.verifactu/doc"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/l10n"
)
// GenerateCancel creates a new cancellation document from the provided
// GOBL Envelope.
func (c *Client) GenerateCancel(env *gobl.Envelope) (*doc.Envelope, error) {
// Extract the Invoice
inv, ok := env.Extract().(*bill.Invoice)
if !ok {
return nil, errors.New("only invoices are supported")
}
if inv.Supplier.TaxID.Country != l10n.ES.Tax() {
return nil, errors.New("only spanish invoices are supported")
}
// Create the document
cd, err := doc.NewVerifactu(inv, c.CurrentTime(), c.issuerRole, c.software, true)
if err != nil {
return nil, err
}
return cd, nil
}
// FingerprintCancel generates a fingerprint for the cancellation document using the
// data provided from the previous chain data. The document is updated in place.
func (c *Client) FingerprintCancel(d *doc.Envelope, prev *doc.ChainData) error {
return d.FingerprintCancel(prev)
}