1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Update an employee expense |
7 | * Updates an existing employee expense by setting field values. Any fields not provided remain unchanged. |
8 |
|
9 |
|
10 | Permissions and other requirements |
11 |
|
12 | SubscriptionTime & Expenses |
13 | User typeBusiness, Employee |
14 | PermissionsEdit Expenses |
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 | createdDate?: string |
27 | employee?: { key?: string; id?: string; href?: string } |
28 | employeeContact?: { |
29 | key?: string |
30 | id?: string |
31 | firstName?: string |
32 | lastName?: string |
33 | href?: string |
34 | } |
35 | state?: |
36 | | 'draft' |
37 | | 'submitted' |
38 | | 'partiallyApproved' |
39 | | 'partiallyDeclined' |
40 | | 'approved' |
41 | | 'posted' |
42 | | 'declined' |
43 | | 'reversalPending' |
44 | | 'reversed' |
45 | | 'reversal' |
46 | | 'paid' |
47 | | 'confirmed' |
48 | | 'voided' |
49 | | 'partiallyPaid' |
50 | | 'selected' |
51 | basePayment?: { |
52 | baseCurrency?: string |
53 | paidDate?: string |
54 | totalEntered?: string |
55 | totalPaid?: string |
56 | totalDue?: string |
57 | totalSelected?: string |
58 | } |
59 | reimbursement?: { |
60 | reimbursementCurrency?: string |
61 | totalEntered?: string |
62 | totalPaid?: string |
63 | totalDue?: string |
64 | totalSelected?: string |
65 | } |
66 | expenseReportNumber?: string |
67 | expenseSummary?: { |
68 | key?: string |
69 | id?: string |
70 | title?: string |
71 | postingDate?: string |
72 | state?: 'open' | 'closed' |
73 | preventGLPosting?: false | true |
74 | href?: string |
75 | } |
76 | nonReimbursable?: { |
77 | baseTotalEntered?: string |
78 | reimbursementTotalEntered?: string |
79 | } |
80 | memo?: string |
81 | description?: string |
82 | reclassificationNotes?: string |
83 | attachment?: { key?: string; id?: string; href?: string } |
84 | audit?: { |
85 | createdDateTime?: string |
86 | modifiedDateTime?: string |
87 | createdBy?: string |
88 | modifiedBy?: string |
89 | } & { createdDateTime?: string } |
90 | lines?: { |
91 | key?: string |
92 | id?: string |
93 | href?: string |
94 | entryDate?: string |
95 | baseCurrency?: string |
96 | baseAmount?: string |
97 | reimbursementCurrency?: string |
98 | reimbursementAmount?: string |
99 | txnCurrency?: string |
100 | txnAmount?: string |
101 | totalSelected?: string |
102 | totalPaid?: string |
103 | quantity?: string |
104 | unitRate?: string |
105 | paidTo?: string |
106 | paidFor?: string |
107 | glAccount?: { key?: string; id?: string; name?: string; href?: string } |
108 | expenseType?: { key?: string; id?: string; href?: string } |
109 | lineNumber?: number |
110 | reimburseToBaseConversion?: { |
111 | exchangeRateDate?: string |
112 | exchangeRateTypeId?: string |
113 | exchangeRate?: string |
114 | } |
115 | transactionToReimburseConversion?: { |
116 | exchangeRate?: string |
117 | exchangeRateDate?: string |
118 | exchangeRateTypeId?: string |
119 | } |
120 | state?: |
121 | | 'draft' |
122 | | 'submitted' |
123 | | 'partiallyApproved' |
124 | | 'partiallyDeclined' |
125 | | 'approved' |
126 | | 'posted' |
127 | | 'declined' |
128 | | 'reversalPending' |
129 | | 'reversed' |
130 | | 'reversal' |
131 | | 'paid' |
132 | | 'confirmed' |
133 | | 'voided' |
134 | | 'partiallyPaid' |
135 | | 'saved' |
136 | isBillable?: false | true |
137 | isBilled?: false | true |
138 | form1099?: { isForm1099?: string; type?: string; box?: string } |
139 | paymentType?: { |
140 | key?: string |
141 | id?: string |
142 | isNonReimbursable?: false | true |
143 | href?: string |
144 | } |
145 | electronicReceipt?: { id?: string; key?: string; href?: string } |
146 | electronicReceiptLine?: { id?: string; key?: string; href?: string } |
147 | audit?: { |
148 | createdDateTime?: string |
149 | modifiedDateTime?: string |
150 | createdBy?: string |
151 | modifiedBy?: 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 | employeeExpense?: { id?: string; key?: string; href?: string } |
188 | }[] |
189 | entity?: { key?: string; id?: string; name?: string; href?: string } |
190 | } & { reimbursement?: { reimbursementCurrency?: {} } } |
191 | ) { |
192 | const url = new URL(`https://api.intacct.com/ia/api/v1/objects/expenses/employee-expense/${key}`) |
193 |
|
194 | const response = await fetch(url, { |
195 | method: 'PATCH', |
196 | headers: { |
197 | 'Content-Type': 'application/json', |
198 | Authorization: 'Bearer ' + auth.token |
199 | }, |
200 | body: JSON.stringify(body) |
201 | }) |
202 | if (!response.ok) { |
203 | const text = await response.text() |
204 | throw new Error(`${response.status} ${text}`) |
205 | } |
206 | return await response.json() |
207 | } |
208 |
|