-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdelivery.go
More file actions
65 lines (55 loc) · 1.6 KB
/
Copy pathdelivery.go
File metadata and controls
65 lines (55 loc) · 1.6 KB
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
package ubl
import (
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/catalogues/iso"
)
// Delivery represents delivery information
type Delivery struct {
ActualDeliveryDate *string `xml:"cbc:ActualDeliveryDate"`
LatestDeliveryDate *string `xml:"cbc:LatestDeliveryDate"`
DeliveryLocation *Location `xml:"cac:DeliveryLocation"`
RequestedDeliveryPeriod *Period `xml:"cac:RequestedDeliveryPeriod"`
EstimatedDeliveryPeriod *Period `xml:"cac:EstimatedDeliveryPeriod"`
DeliveryParty *Party `xml:"cac:DeliveryParty"`
}
// Location represents a location
type Location struct {
ID *IDType `xml:"cbc:ID"`
Address *PostalAddress `xml:"cac:Address"`
}
// DeliveryTerms represents the terms of delivery
type DeliveryTerms struct {
ID string `xml:"cbc:ID"`
}
func newDelivery(del *bill.DeliveryDetails, ctx Context) *Delivery {
if del == nil {
return nil
}
out := new(Delivery)
if del.Date != nil {
date := formatDate(*del.Date)
out.ActualDeliveryDate = &date
}
if del.Period != nil {
end := formatDate(del.Period.End)
start := formatDate(del.Period.Start)
out.LatestDeliveryDate = &end
out.ActualDeliveryDate = &start
}
if del.Receiver != nil {
out.DeliveryParty = newDeliveryParty(del.Receiver)
out.DeliveryLocation =
&Location{
Address: newAddress(del.Receiver.Addresses, ctx),
}
if len(del.Identities) > 0 {
id := del.Identities[0]
idType := &IDType{Value: id.Code.String()}
if s := id.Ext.Get(iso.ExtKeySchemeID).String(); s != "" {
idType.SchemeID = &s
}
out.DeliveryLocation.ID = idType
}
}
return out
}