1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Update an invoice |
7 | * Updates an existing invoice by setting field values. Any fields not provided remain unchanged. Allowed edits depend on the state an invoice is in. For more information, see [About editing invoices](https://www.intacct.com/ia/docs/en_US/help_action/Accounts_Receivable/Invoices/Tasks/edit-an-invoice-overview.htm). |
8 |
|
9 |
|
10 | Permissions and other requirements |
11 |
|
12 | SubscriptionAccounts Receivable |
13 | User typeBusiness, Employee, Approver |
14 | PermissionsEdit Invoices |
15 |
|
16 |
|
17 |
|
18 |
|
19 | */ |
20 | export async function main( |
21 | auth: SageIntacct, |
22 | key: string, |
23 | body: { |
24 | key?: string |
25 | id?: string |
26 | action?: 'submit' | 'draft' |
27 | recordType?: string |
28 | moduleKey?: 'accountsReceivable' | 'orderEntry' |
29 | invoiceNumber?: string |
30 | state?: |
31 | | 'draft' |
32 | | 'reversed' |
33 | | 'reversal' |
34 | | 'noValue' |
35 | | 'posted' |
36 | | 'paid' |
37 | | 'partiallyPaid' |
38 | | 'selected' |
39 | dueInDays?: number |
40 | referenceNumber?: string |
41 | description?: string |
42 | documentId?: string |
43 | discountCutOffDate?: string |
44 | invoiceDate?: string |
45 | dueDate?: string |
46 | currency?: { |
47 | baseCurrency?: string |
48 | txnCurrency?: string |
49 | exchangeRate?: { date?: string; rate?: number; typeId?: string } |
50 | } |
51 | totalBaseAmount?: string |
52 | totalBaseAmountDue?: string |
53 | totalTxnAmount?: string |
54 | totalTxnAmountDue?: string |
55 | dunningCount?: number |
56 | customerMessage?: { |
57 | key?: string |
58 | id?: string |
59 | message?: string |
60 | href?: string |
61 | } |
62 | recurringSchedule?: { key?: string } |
63 | paymentInformation?: { |
64 | fullyPaidDate?: string |
65 | totalBaseAmountPaid?: string |
66 | totalBaseAmountSelectedForPayment?: string |
67 | totalTxnAmountSelectedForPayment?: string |
68 | totalTxnAmountPaid?: string |
69 | } |
70 | contacts?: { |
71 | payTo?: { key?: string; id?: string } |
72 | returnTo?: { |
73 | key?: string |
74 | id?: string |
75 | tax?: { |
76 | taxId?: string |
77 | group?: { key?: string; id?: string; href?: string } |
78 | } |
79 | } |
80 | } |
81 | isSystemGeneratedDocument?: false | true |
82 | billbackTemplate?: { key?: string; id?: string; href?: string } |
83 | attachment?: { key?: string; id?: string; href?: string } |
84 | customer?: { |
85 | key?: string |
86 | id?: string |
87 | name?: string |
88 | emailOption?: false | true |
89 | customerDue?: string |
90 | deliveryOptions?: 'print' | 'email' | 'both' |
91 | href?: string |
92 | } |
93 | term?: { key?: string; id?: string; href?: string } |
94 | taxSolution?: { key?: string; id?: string; href?: string } |
95 | invoiceSummary?: { |
96 | key?: string |
97 | id?: string |
98 | glPostingDate?: string |
99 | isSummaryOpen?: 'open' | 'closed' |
100 | isSummaryPosted?: string |
101 | href?: string |
102 | } |
103 | lines?: { |
104 | key?: string |
105 | id?: string |
106 | glAccount?: { key?: string; id?: string; name?: string; href?: string } |
107 | overrideOffsetGLAccount?: { |
108 | key?: string |
109 | id?: string |
110 | name?: string |
111 | href?: string |
112 | } |
113 | baseAmount?: string |
114 | txnAmount?: string |
115 | memo?: string |
116 | currency?: { |
117 | baseCurrency?: string |
118 | txnCurrency?: string |
119 | exchangeRate?: { date?: string; rate?: number; typeId?: string } |
120 | } |
121 | paymentInformation?: { |
122 | totalBaseAmountPaid?: string |
123 | totalTxnAmountPaid?: string |
124 | totalBaseAmountSelectedForPayment?: string |
125 | totalTxnAmountSelectedForPayment?: string |
126 | } |
127 | allocation?: { key?: string; id?: string; href?: string } |
128 | lineNumber?: number |
129 | isSubtotal?: 'subtotal' | 'tax' |
130 | baseLocation?: { |
131 | key?: string |
132 | id?: string |
133 | name?: string |
134 | href?: string |
135 | } & { key?: string } |
136 | createdDate?: string |
137 | accountLabel?: { |
138 | key?: string |
139 | id?: string |
140 | name?: string |
141 | href?: string |
142 | } |
143 | taxEntries?: { |
144 | key?: string |
145 | id?: string |
146 | baseTaxAmount?: string |
147 | txnTaxAmount?: string |
148 | taxRate?: number |
149 | } & { |
150 | orderEntryTaxDetail?: { key?: string; id?: string; href?: string } |
151 | invoiceLine?: { id?: string; key?: string; href?: string } |
152 | }[] |
153 | dimensions?: { |
154 | location?: { key?: string; id?: string; name?: string; href?: string } |
155 | department?: { |
156 | key?: string |
157 | id?: string |
158 | name?: string |
159 | href?: string |
160 | } |
161 | employee?: { key?: string; id?: string; name?: string; href?: string } |
162 | project?: { key?: string; id?: string; name?: string; href?: string } |
163 | customer?: { key?: string; id?: string; name?: string; href?: string } |
164 | vendor?: { key?: string; id?: string; name?: string; href?: string } |
165 | item?: { key?: string; id?: string; name?: string; href?: string } |
166 | warehouse?: { key?: string; id?: string; name?: string; href?: string } |
167 | class?: { key?: string; id?: string; name?: string; href?: string } |
168 | task?: { id?: string; key?: string; name?: string; href?: string } |
169 | costType?: { id?: string; key?: string; name?: string; href?: string } |
170 | asset?: { id?: string; key?: string; name?: string; href?: string } |
171 | contract?: { id?: string; key?: string; name?: string; href?: string } |
172 | affiliateEntity?: { |
173 | key?: string |
174 | id?: string |
175 | href?: string |
176 | name?: string |
177 | } |
178 | } & { |
179 | location?: { key?: string; id?: string; name?: string; href?: string } |
180 | department?: { |
181 | key?: string |
182 | id?: string |
183 | name?: string |
184 | href?: string |
185 | } |
186 | } |
187 | invoice?: { id?: string; key?: string; href?: string } |
188 | audit?: { |
189 | createdDateTime?: string |
190 | modifiedDateTime?: string |
191 | createdBy?: string |
192 | modifiedBy?: string |
193 | } |
194 | }[] |
195 | entity?: { key?: string; id?: string; name?: string; href?: string } |
196 | audit?: { |
197 | createdDateTime?: string |
198 | modifiedDateTime?: string |
199 | createdBy?: string |
200 | modifiedBy?: string |
201 | } & { createdDateTime?: string } |
202 | } & { id?: {} } |
203 | ) { |
204 | const url = new URL( |
205 | `https://api.intacct.com/ia/api/v1/objects/accounts-receivable/invoice/${key}` |
206 | ) |
207 |
|
208 | const response = await fetch(url, { |
209 | method: 'PATCH', |
210 | headers: { |
211 | 'Content-Type': 'application/json', |
212 | Authorization: 'Bearer ' + auth.token |
213 | }, |
214 | body: JSON.stringify(body) |
215 | }) |
216 | if (!response.ok) { |
217 | const text = await response.text() |
218 | throw new Error(`${response.status} ${text}`) |
219 | } |
220 | return await response.json() |
221 | } |
222 |
|