-
Notifications
You must be signed in to change notification settings - Fork 6
/
account.go
65 lines (56 loc) · 2.18 KB
/
account.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
package quickbooks
import (
"encoding/json"
"fmt"
)
// AccountObject the complete quickbooks account object type
type AccountObject struct {
Account Account `json:"Account"`
Time string `json:"time"`
}
// Account quickbooks account type
type Account struct {
Name string `json:"Name"`
SubAccount bool `json:"SubAccount,omitempty"`
FullyQualifiedName string `json:"FullyQualifiedName,omitempty"`
Active bool `json:"Active,omitempty"`
Classification string `json:"Classification,omitempty"`
AccountType string `json:"AccountType"`
AccountSubType string `json:"AccountSubType,omitempty"`
CurrentBalance int `json:"CurrentBalance,omitempty"`
CurrentBalanceWithSubAccounts int `json:"CurrentBalanceWithSubAccounts,omitempty"`
CurrencyRef *CurrencyRef `json:"CurrencyRef,omitempty"`
Domain string `json:"domain,omitempty"`
Sparse bool `json:"sparse,omitempty"`
ID string `json:"Id,omitempty"`
SyncToken string `json:"SyncToken,omitempty"`
MetaData *struct {
CreateTime string `json:"CreateTime,omitempty"`
LastUpdatedTime string `json:"LastUpdatedTime,omitempty"`
} `json:"MetaData,omitempty"`
}
// AccountRef chart of account reference
type AccountRef struct {
Value string `json:"value"`
Name string `json:"name,omitempty"`
}
// CurrencyRef chart of account currency reference
type CurrencyRef struct {
Value string `json:"value"`
Name string `json:"name,omitempty"`
}
// CreateAccount creates a chart of account on quickbooks
func (q *Quickbooks) CreateAccount(account Account) (*AccountObject, error) {
endpoint := fmt.Sprintf("/company/%s/account", q.RealmID)
res, err := q.makePostRequest(endpoint, account)
if err != nil {
return nil, err
}
defer res.Body.Close()
newAccount := AccountObject{}
err = json.NewDecoder(res.Body).Decode(&newAccount)
if err != nil {
return nil, err
}
return &newAccount, nil
}