1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Create a journal entry |
7 | * Creates a new journal entry (transaction). |
8 | */ |
9 | export async function main( |
10 | auth: SageIntacct, |
11 | body: { |
12 | key?: string |
13 | id?: string |
14 | txnNumber?: number |
15 | glJournal?: { |
16 | key?: string |
17 | id?: string |
18 | isAdjustment?: false | true |
19 | href?: string |
20 | } |
21 | description?: string |
22 | postingDate?: string |
23 | automaticReversalDate?: string |
24 | reversedFromDate?: string |
25 | reversedBy?: { key?: string; id?: string; href?: string } |
26 | moduleName?: string |
27 | referenceNumber?: string |
28 | attachment?: { key?: string; id?: string; href?: string } |
29 | entity?: { key?: string; id?: string; name?: string; href?: string } |
30 | baseLocation?: { key?: string; id?: string; href?: string } |
31 | state?: |
32 | | 'draft' |
33 | | 'submitted' |
34 | | 'partiallyApproved' |
35 | | 'approved' |
36 | | 'posted' |
37 | | 'declined' |
38 | | 'reversalPending' |
39 | | 'reversed' |
40 | sequenceNumber?: string |
41 | tax?: { |
42 | taxImplication?: 'none' | 'inbound' | 'outbound' |
43 | taxSolution?: { key?: string; id?: string; href?: string } |
44 | vendor?: { key?: string; id?: string; href?: string } |
45 | customer?: { key?: string; id?: string; href?: string } |
46 | contact?: { key?: string; id?: string; href?: string } |
47 | } |
48 | audit?: { |
49 | createdDateTime?: string |
50 | modifiedDateTime?: string |
51 | createdBy?: string |
52 | modifiedBy?: string |
53 | } |
54 | href?: string |
55 | accountAllocationRun?: { key?: string; id?: string; href?: string } |
56 | lines?: { |
57 | key?: string |
58 | id?: string |
59 | lineNumber?: number |
60 | txnType?: 'debit' | 'credit' |
61 | txnAmount?: string |
62 | entryDate?: string |
63 | documentId?: string |
64 | description?: string |
65 | numberOfUnits?: number |
66 | reconciliationGroup?: { |
67 | clearingDate?: string |
68 | cleared?: 'true' | 'false' | 'matched' |
69 | reconciliationDate?: string |
70 | } |
71 | accountingPeriod?: number |
72 | isBillable?: false | true |
73 | isBilled?: false | true |
74 | baseAmount?: string |
75 | interEntityTxnType?: string |
76 | parent?: { key?: string; id?: string; href?: string } |
77 | state?: |
78 | | 'draft' |
79 | | 'submitted' |
80 | | 'partiallyApproved' |
81 | | 'approved' |
82 | | 'posted' |
83 | | 'declined' |
84 | | 'reversalPending' |
85 | | 'reversed' |
86 | | 'partiallyPaid' |
87 | | 'paid' |
88 | | 'reversal' |
89 | audit?: { |
90 | createdDateTime?: string |
91 | modifiedDateTime?: string |
92 | createdBy?: string |
93 | modifiedBy?: string |
94 | } |
95 | currency?: { |
96 | exchangeRateDate?: string |
97 | exchangeRateTypeId?: string |
98 | exchangeRate?: number |
99 | baseCurrency?: string |
100 | txnCurrency?: string |
101 | } |
102 | glAccount?: { key?: string; id?: string; name?: string; href?: string } |
103 | allocation?: { key?: string; id?: string; href?: string } |
104 | dimensions?: { |
105 | location?: { key?: string; id?: string; name?: string; href?: string } |
106 | department?: { |
107 | key?: string |
108 | id?: string |
109 | name?: string |
110 | href?: string |
111 | } |
112 | employee?: { key?: string; id?: string; name?: string; href?: string } |
113 | project?: { key?: string; id?: string; name?: string; href?: string } |
114 | customer?: { key?: string; id?: string; name?: string; href?: string } |
115 | vendor?: { key?: string; id?: string; name?: string; href?: string } |
116 | item?: { key?: string; id?: string; name?: string; href?: string } |
117 | warehouse?: { key?: string; id?: string; name?: string; href?: string } |
118 | class?: { key?: string; id?: string; name?: string; href?: string } |
119 | task?: { id?: string; key?: string; name?: string; href?: string } |
120 | costType?: { id?: string; key?: string; name?: string; href?: string } |
121 | asset?: { id?: string; key?: string; name?: string; href?: string } |
122 | contract?: { id?: string; key?: string; name?: string; href?: string } |
123 | affiliateEntity?: { |
124 | key?: string |
125 | id?: string |
126 | href?: string |
127 | name?: string |
128 | } |
129 | } |
130 | href?: string |
131 | journalEntry?: { id?: string; key?: string; href?: string } |
132 | taxEntries?: { |
133 | key?: string |
134 | id?: string |
135 | baseTaxAmount?: string |
136 | txnTaxAmount?: string |
137 | taxRate?: number |
138 | } & { |
139 | taxDetail?: { key?: string; id?: string; href?: string } |
140 | journalEntryLine?: { id?: string; key?: string; href?: string } |
141 | }[] |
142 | }[] |
143 | } & { lines: {}[] } |
144 | ) { |
145 | const url = new URL(`https://api.intacct.com/ia/api/v1/objects/general-ledger/journal-entry`) |
146 |
|
147 | const response = await fetch(url, { |
148 | method: 'POST', |
149 | headers: { |
150 | 'Content-Type': 'application/json', |
151 | Authorization: 'Bearer ' + auth.token |
152 | }, |
153 | body: JSON.stringify(body) |
154 | }) |
155 | if (!response.ok) { |
156 | const text = await response.text() |
157 | throw new Error(`${response.status} ${text}`) |
158 | } |
159 | return await response.json() |
160 | } |
161 |
|