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