1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Update a bill |
7 | * Updates an existing bill by setting field values. |
8 | */ |
9 | export async function main( |
10 | auth: SageIntacct, |
11 | key: string, |
12 | body: { |
13 | key?: string |
14 | id?: string |
15 | href?: string |
16 | billNumber?: string |
17 | state?: |
18 | | 'reversed' |
19 | | 'reversal' |
20 | | 'analyzing' |
21 | | 'partiallyApproved' |
22 | | 'submitted' |
23 | | 'declined' |
24 | | 'noValue' |
25 | | 'posted' |
26 | | 'paid' |
27 | | 'partiallyPaid' |
28 | | 'selected' |
29 | | 'draft' |
30 | recordType?: string |
31 | vendor?: { |
32 | key?: string |
33 | id?: string |
34 | name?: string |
35 | href?: string |
36 | vendorDue?: string |
37 | form1099?: { |
38 | type?: string |
39 | box?: string |
40 | vendorTypeForm1099Type?: string |
41 | } |
42 | } |
43 | term?: { key?: string; id?: string; href?: string } |
44 | referenceNumber?: string |
45 | description?: string |
46 | dueInDays?: string |
47 | postingDate?: string |
48 | discountCutOffDate?: string |
49 | dueDate?: string |
50 | recommendedPaymentDate?: string |
51 | createdDate?: string |
52 | isOnHold?: false | true |
53 | isTaxInclusive?: false | true |
54 | paymentPriority?: 'urgent' | 'high' | 'normal' | 'low' |
55 | totalBaseAmount?: string |
56 | totalBaseAmountDue?: string |
57 | totalTxnAmount?: string |
58 | totalTxnAmountDue?: string |
59 | isSystemGenerated?: false | true |
60 | purchasing?: { id?: string; key?: string; href?: string } |
61 | recurringSchedule?: { key?: string; id?: string; href?: string } |
62 | contacts?: { |
63 | payTo?: { |
64 | key?: string |
65 | id?: string |
66 | tax?: { |
67 | taxId?: string |
68 | group?: { key?: string; id?: string; href?: string } |
69 | } |
70 | href?: string |
71 | } |
72 | returnTo?: { key?: string; id?: string; href?: string } |
73 | } |
74 | currency?: { |
75 | baseCurrency?: string |
76 | txnCurrency?: string |
77 | exchangeRate?: { date?: string; rate?: number; typeId?: string } |
78 | } |
79 | taxSolution?: { |
80 | key?: string |
81 | id?: string |
82 | showMultiLineTax?: string |
83 | taxCalculationMethod?: string |
84 | method?: string |
85 | href?: string |
86 | } |
87 | billSummary?: { |
88 | key?: string |
89 | id?: string |
90 | name?: string |
91 | isSummaryOpen?: 'open' | 'closed' |
92 | isSummaryPosted?: string |
93 | href?: string |
94 | } |
95 | sourceModule?: 'accountsPayable' | 'purchasing' |
96 | paymentInformation?: { |
97 | fullyPaidDate?: string |
98 | totalBaseAmountPaid?: string |
99 | totalBaseAmountSelectedForPayment?: string |
100 | totalTxnAmountSelectedForPayment?: string |
101 | totalTxnAmountPaid?: string |
102 | } |
103 | retainage?: { |
104 | defaultPercentage?: string |
105 | totalTxnAmountRetained?: string |
106 | totalTxnAmountReleased?: string |
107 | totalBaseAmountRetained?: string |
108 | } |
109 | billBackTemplate?: { |
110 | key?: string |
111 | id?: string |
112 | enableInterEntityPostings?: false | true |
113 | href?: string |
114 | } |
115 | attachment?: { key?: string; id?: string; href?: string } |
116 | location?: { key?: string; id?: string; name?: string; href?: string } |
117 | lines?: { |
118 | id?: string |
119 | key?: string |
120 | href?: string |
121 | lineNumber?: string |
122 | hasForm1099?: string |
123 | form1099?: { type?: string; box?: string } |
124 | createdDate?: string |
125 | glAccount?: { key?: string; id?: string; name?: string; href?: string } |
126 | overrideOffsetGLAccount?: { |
127 | key?: string |
128 | id?: string |
129 | name?: string |
130 | href?: string |
131 | } |
132 | accountLabel?: { key?: string; id?: string; href?: string } |
133 | baseAmount?: string |
134 | txnAmount?: string |
135 | totalTxnAmount?: string |
136 | memo?: string |
137 | allocation?: { key?: string; id?: string; href?: string } |
138 | currency?: { |
139 | baseCurrency?: string |
140 | txnCurrency?: string |
141 | exchangeRate?: { date?: string; rate?: number; typeId?: string } |
142 | } |
143 | paymentInformation?: { |
144 | totalBaseAmountPaid?: string |
145 | totalTxnAmountPaid?: string |
146 | totalBaseAmountSelectedForPayment?: string |
147 | totalTxnAmountSelectedForPayment?: string |
148 | } |
149 | releaseToPay?: false | true |
150 | isSubTotal?: 'subtotal' | 'tax' |
151 | baseLocation?: { |
152 | key?: string |
153 | id?: string |
154 | name?: string |
155 | href?: string |
156 | } & { key?: string } |
157 | retainage?: { |
158 | hasRetainage?: false | true |
159 | percentage?: string |
160 | baseAmountRetained?: string |
161 | txnAmountRetained?: string |
162 | txnAmountReleased?: string |
163 | release?: false | true |
164 | } |
165 | project?: { isBillable?: false | true; isBilled?: false | true } |
166 | fixedAsset?: { |
167 | nameOfAcquiredAsset?: string |
168 | includeTaxInAssetCost?: false | true |
169 | } |
170 | purchasing?: { |
171 | document?: { key?: string; id?: string; href?: string } |
172 | documentLine?: { key?: string; id?: string; href?: string } |
173 | } |
174 | taxEntries?: { |
175 | key?: string |
176 | id?: string |
177 | baseTaxAmount?: string |
178 | txnTaxAmount?: string |
179 | taxRate?: number |
180 | } & { |
181 | purchasingTaxDetail?: { key?: string; id?: string; href?: string } |
182 | billLine?: { id?: string; key?: string; href?: string } |
183 | isPartialExemption?: false | true |
184 | }[] |
185 | dimensions?: { |
186 | location?: { key?: string; id?: string; name?: string; href?: string } |
187 | department?: { |
188 | key?: string |
189 | id?: string |
190 | name?: string |
191 | href?: string |
192 | } |
193 | employee?: { key?: string; id?: string; name?: string; href?: string } |
194 | project?: { key?: string; id?: string; name?: string; href?: string } |
195 | customer?: { key?: string; id?: string; name?: string; href?: string } |
196 | vendor?: { key?: string; id?: string; name?: string; href?: string } |
197 | item?: { key?: string; id?: string; name?: string; href?: string } |
198 | warehouse?: { key?: string; id?: string; name?: string; href?: string } |
199 | class?: { key?: string; id?: string; name?: string; href?: string } |
200 | task?: { id?: string; key?: string; name?: string; href?: string } |
201 | costType?: { id?: string; key?: string; name?: string; href?: string } |
202 | asset?: { id?: string; key?: string; name?: string; href?: string } |
203 | contract?: { id?: string; key?: string; name?: string; href?: string } |
204 | affiliateEntity?: { |
205 | key?: string |
206 | id?: string |
207 | href?: string |
208 | name?: string |
209 | } |
210 | } & { |
211 | location?: { key?: string; id?: string; name?: string; href?: string } |
212 | department?: { |
213 | key?: string |
214 | id?: string |
215 | name?: string |
216 | href?: string |
217 | } |
218 | } |
219 | bill?: { id?: string; key?: string; href?: string } |
220 | }[] |
221 | entity?: { key?: string; id?: string; name?: string; href?: string } |
222 | audit?: { |
223 | createdDateTime?: string |
224 | modifiedDateTime?: string |
225 | createdBy?: string |
226 | modifiedBy?: string |
227 | } |
228 | } & { id?: {} } |
229 | ) { |
230 | const url = new URL(`https://api.intacct.com/ia/api/v1/objects/accounts-payable/bill/${key}`) |
231 |
|
232 | const response = await fetch(url, { |
233 | method: 'PATCH', |
234 | headers: { |
235 | 'Content-Type': 'application/json', |
236 | Authorization: 'Bearer ' + auth.token |
237 | }, |
238 | body: JSON.stringify(body) |
239 | }) |
240 | if (!response.ok) { |
241 | const text = await response.text() |
242 | throw new Error(`${response.status} ${text}`) |
243 | } |
244 | return await response.json() |
245 | } |
246 |
|