1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Create an advance |
7 | * Creates a new advance. |
8 | */ |
9 | export async function main( |
10 | auth: SageIntacct, |
11 | body: { |
12 | key?: string |
13 | id?: string |
14 | recordType?: string |
15 | href?: string |
16 | referenceNumber?: string |
17 | description?: string |
18 | state?: |
19 | | 'reversed' |
20 | | 'reversal' |
21 | | 'draft' |
22 | | 'reconciled' |
23 | | 'fullyApplied' |
24 | | 'partiallyApplied' |
25 | | 'posted' |
26 | | 'selected' |
27 | totalEntered?: string |
28 | txnTotalEntered?: string |
29 | paymentInformation?: { |
30 | paymentDate?: string |
31 | totalPaid?: string |
32 | totalSelected?: string |
33 | txnTotalSelected?: string |
34 | txnTotalPaid?: string |
35 | totalDue?: string |
36 | totalTxnAmountDue?: string |
37 | paymentMethod?: 'printedCheck' | 'creditCard' | 'eft' | 'cash' | 'ach' |
38 | receiptDate?: string |
39 | financialEntity?: { key?: string; id?: string; href?: string } |
40 | currency?: { |
41 | exchangeRateDate?: string |
42 | exchangeRateTypeId?: string |
43 | exchangeRate?: number |
44 | baseCurrency?: string |
45 | txnCurrency?: string |
46 | } |
47 | } |
48 | reconciliationGroup?: { |
49 | clearingDate?: string |
50 | cleared?: 'true' | 'false' | 'matched' |
51 | } |
52 | isSystemGenerated?: false | true |
53 | createdDate?: string |
54 | deposit?: { key?: string; id?: string; href?: string } |
55 | advanceSummary?: { href?: string; key?: string; id?: string } |
56 | customer?: { href?: string; id?: string; key?: string; name?: string } |
57 | glAccount?: { |
58 | href?: string |
59 | id?: string |
60 | key?: string |
61 | undepositedGLAccountNumber?: string |
62 | } |
63 | attachment?: { key?: string; id?: string; href?: string } |
64 | items?: { |
65 | key?: string |
66 | id?: string |
67 | href?: string |
68 | baseAmount?: string |
69 | txnAmount?: string |
70 | memo?: string |
71 | currency?: { |
72 | baseCurrency?: string |
73 | txnCurrency?: string |
74 | exchangeRate?: { date?: string; rate?: number; typeId?: string } |
75 | } |
76 | lineNumber?: number |
77 | paymentInformation?: { |
78 | totalPaid?: string |
79 | txnTotalPaid?: string |
80 | totalSelected?: string |
81 | txnTotalSelected?: string |
82 | } |
83 | baseLocation?: { |
84 | key?: string |
85 | id?: string |
86 | name?: string |
87 | href?: string |
88 | } & { key?: string } |
89 | accountLabel?: { |
90 | key?: string |
91 | id?: string |
92 | name?: string |
93 | href?: string |
94 | } |
95 | glAccount?: { key?: string; id?: string; name?: string; href?: string } |
96 | dimensions?: { |
97 | location?: { key?: string; id?: string; name?: string; href?: string } |
98 | department?: { |
99 | key?: string |
100 | id?: string |
101 | name?: string |
102 | href?: string |
103 | } |
104 | employee?: { key?: string; id?: string; name?: string; href?: string } |
105 | project?: { key?: string; id?: string; name?: string; href?: string } |
106 | customer?: { key?: string; id?: string; name?: string; href?: string } |
107 | vendor?: { key?: string; id?: string; name?: string; href?: string } |
108 | item?: { key?: string; id?: string; name?: string; href?: string } |
109 | warehouse?: { key?: string; id?: string; name?: string; href?: string } |
110 | class?: { key?: string; id?: string; name?: string; href?: string } |
111 | task?: { id?: string; key?: string; name?: string; href?: string } |
112 | costType?: { id?: string; key?: string; name?: string; href?: string } |
113 | asset?: { id?: string; key?: string; name?: string; href?: string } |
114 | contract?: { id?: string; key?: string; name?: string; href?: string } |
115 | affiliateEntity?: { |
116 | key?: string |
117 | id?: string |
118 | href?: string |
119 | name?: string |
120 | } |
121 | } & { |
122 | location?: { key?: string; id?: string; name?: string; href?: string } |
123 | department?: { |
124 | key?: string |
125 | id?: string |
126 | name?: string |
127 | href?: string |
128 | } |
129 | } |
130 | arAdvance?: { |
131 | id?: string |
132 | key?: string |
133 | href?: string |
134 | recordType?: string |
135 | } |
136 | audit?: { |
137 | createdDateTime?: string |
138 | modifiedDateTime?: string |
139 | createdBy?: string |
140 | modifiedBy?: string |
141 | } |
142 | }[] |
143 | entity?: { key?: string; id?: string; name?: string; href?: string } |
144 | audit?: { |
145 | createdDateTime?: string |
146 | modifiedDateTime?: string |
147 | createdBy?: string |
148 | modifiedBy?: string |
149 | } |
150 | } & { |
151 | customer?: {} |
152 | paymentInformation?: {} |
153 | items?: { glAccount?: {}; dimensions?: { location?: {} } }[] |
154 | } |
155 | ) { |
156 | const url = new URL(`https://api.intacct.com/ia/api/v1/objects/accounts-receivable/advance`) |
157 |
|
158 | const response = await fetch(url, { |
159 | method: 'POST', |
160 | headers: { |
161 | 'Content-Type': 'application/json', |
162 | Authorization: 'Bearer ' + auth.token |
163 | }, |
164 | body: JSON.stringify(body) |
165 | }) |
166 | if (!response.ok) { |
167 | const text = await response.text() |
168 | throw new Error(`${response.status} ${text}`) |
169 | } |
170 | return await response.json() |
171 | } |
172 |
|