forked from jinmatt/go-quickbooks.v2
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathitem.go
66 lines (58 loc) · 2.07 KB
/
item.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
package quickbooks
import (
"encoding/json"
"fmt"
)
// ItemObject the complete quickbooks item object type
type ItemObject struct {
Item Item `json:"Item"`
Time string `json:"time"`
}
// Item quickbooks item type
type Item struct {
ID string `json:"Id,omitempty"`
Name string `json:"Name"`
Description string `json:"Description,omitempty"`
Type string `json:"Type"`
Active bool `json:"Active,omitempty"`
FullyQualifiedName string `json:"FullyQualifiedName,omitempty"`
Taxable bool `json:"Taxable,omitempty"`
UnitPrice float64 `json:"UnitPrice,omitempty"`
IncomeAccountRef *AccountRef `json:"IncomeAccountRef"`
PurchaseDesc string `json:"PurchaseDesc,omitempty"`
PurchaseCost float64 `json:"PurchaseCost,omitempty"`
ExpenseAccountRef *AccountRef `json:"ExpenseAccountRef,omitempty"`
AssetAccountRef *AccountRef `json:"AssetAccountRef,omitempty"`
TrackQtyOnHand bool `json:"TrackQtyOnHand,omitempty"`
QtyOnHand float64 `json:"QtyOnHand,omitempty"`
InvStartDate string `json:"InvStartDate,omitempty"`
Domain string `json:"domain,omitempty"`
Sparse bool `json:"sparse,omitempty"`
SyncToken string `json:"SyncToken,omitempty"`
MetaData *struct {
CreateTime string `json:"CreateTime"`
LastUpdatedTime string `json:"LastUpdatedTime"`
} `json:"MetaData,omitempty"`
}
// ItemRef quickbooks item reference object
type ItemRef struct {
Value string `json:"value"`
Name string `json:"name,omitempty"`
}
// CreateItem creates an item on quickbooks
func (q *Quickbooks) CreateItem(item Item) (*ItemObject, error) {
endpoint := fmt.Sprintf("/company/%s/item", q.RealmID)
res, err := q.makePostRequest(endpoint, item)
if err != nil {
return nil, err
}
if res.Body != nil {
defer res.Body.Close()
}
newItem := ItemObject{}
err = json.NewDecoder(res.Body).Decode(&newItem)
if err != nil {
return nil, err
}
return &newItem, nil
}