forked from jinmatt/go-quickbooks.v2
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjournal_entry.go
103 lines (87 loc) · 3.24 KB
/
journal_entry.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package quickbooks
import (
"encoding/json"
"fmt"
)
// JournalEntryObject the complete quickbooks journal entry object type
type JournalEntryObject struct {
JournalEntry JournalEntry `json:"JournalEntry"`
Time string `json:"time"`
}
// Journal Entry quickbooks Journal Entry type
type JournalEntry struct {
ID string `json:"Id,omitempty"`
Adjustment bool `json:"Adjustment,omitempty"`
Domain string `json:"domain,omitempty"`
Sparse bool `json:"sparse,omitempty"`
SyncToken string `json:"SyncToken,omitempty"`
DocNumber string `json:"DocNumber,omitempty"`
TxnDate string `json:"TxnDate,omitempty"`
Line []Line `json:"Line"`
TxnTaxDetail *TxnTaxDetail `json:"TxnTaxDetail,omitempty"`
MetaData *MetaData `json:"MetaData,omitempty"`
}
// Line type - part of Journal Entry
type Line struct {
LineID string `json:"Id,omitempty"`
Description string `json:"Description,omitempty"`
Amount float64 `json:"Amount,omitempty"`
DetailType string `json:"DetailType,omitempty"`
JournalEntryLineDetail *JournalEntryLineDetail `json:"JournalEntryLineDetail,omitempty"`
LineNum *int `json:"LineNum,omitempty"`
}
// JournalEntryLineDetail - part of Journal Entry
type JournalEntryLineDetail struct {
AccountRef JournalEntryRef `json:"AccountRef,omitempty"`
PostingType string `json:"PostingType,omitempty"`
TaxCodeRef *TaxCodeRef `json:"TaxCodeRef,omitempty"`
TaxApplicableOn *string `json:"TaxApplicableOn,omitempty"`
TaxAmount *float64 `json:"TaxAmount,omitempty"`
ClassRef *ClassRef `json:"ClassRef,omitempty"`
Entity *Entity `json:"Entity,omitempty"`
JournalCodeRef JournalCodeRef `json:"JournalCodeRef,omitempty"`
}
// Metadata - info about when the journal entry was created/updated.
type MetaData struct {
CreateTime string `json:"CreateTime,omitempty"`
LastUpdatedTime string `json:"LastUpdatedTime,omitempty"`
}
type JournalCodeRef struct {
Value string `json:"value,omitempty"`
Name string `json:"name,omitempty"`
}
type JournalEntryRef struct {
Value string `json:"value,omitempty"`
Name string `json:"name,omitempty"`
}
type ClassRef struct {
Value string `json:"value,omitempty"`
Name string `json:"name,omitempty"`
}
type Entity struct {
Type string `json:"Type"`
EntityRef EntityRef `json:"EntityRef"`
}
type EntityRef struct {
Name string `json:"name"`
Value string `json:"value"`
}
type TxnTaxDetail struct {
TotalTax *float64 `json:"TotalTax,omitempty"`
TaxLine []TaxLine `json:"TaxLine,omitempty"`
}
// CreateJE creates a journal entry on quickbooks
func (q *Quickbooks) CreateJournalEntry(journalentry JournalEntry) (*JournalEntryObject, error) {
endpoint := fmt.Sprintf("/company/%s/journalentry", q.RealmID)
response, err := q.makePostRequest(endpoint, journalentry)
if err != nil {
return nil, err
}
defer response.Body.Close()
newJE := JournalEntryObject{}
err = json.NewDecoder(response.Body).Decode(&newJE)
if err != nil {
return nil, err
}
return &newJE, nil
}