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