1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Create a contract line |
7 | * Creates a new contract line. |
8 | */ |
9 | export async function main( |
10 | auth: SageIntacct, |
11 | body: { |
12 | key?: string |
13 | id?: string |
14 | href?: string |
15 | state?: |
16 | | 'draft' |
17 | | 'inProgress' |
18 | | 'renewalOnly' |
19 | | 'canceled' |
20 | | 'notRenewed' |
21 | | 'completed' |
22 | | 'revalued' |
23 | | 'closed' |
24 | | 'renewalForecast' |
25 | lineNumber?: number |
26 | recurringBillingPeriod?: number |
27 | startDate?: string |
28 | endDate?: string |
29 | cancelationDate?: string |
30 | changeType?: |
31 | | 'newMRR' |
32 | | 'addOnMRR' |
33 | | 'renewalUpgrade' |
34 | | 'renewalDowngrade' |
35 | | 'churnMRR' |
36 | | 'downgrade' |
37 | itemDescription?: string |
38 | priceCalculationMemo?: string |
39 | deliveryStatus?: 'delivered' | 'undelivered' |
40 | deliveryDate?: string |
41 | postingDate?: string |
42 | lineType?: 'sale' | 'discount' | 'debook' |
43 | memo?: string |
44 | shipToSource?: 'contractValue' | 'userSpecifiedValue' |
45 | billToSource?: 'contractValue' | 'userSpecifiedValue' |
46 | revenueDeferralStatus?: |
47 | | 'deferRevenueUntilItemIsDelivered' |
48 | | 'deferRevenueUntilAllItemsAreDelivered' |
49 | isRecurring?: false | true |
50 | currency?: { |
51 | exchangeRateDate?: string |
52 | exchangeRate?: string |
53 | baseCurrency?: string |
54 | txnCurrency?: string |
55 | } |
56 | billing?: { |
57 | amountFrequency?: 'oneTime' | 'useBillingTemplate' | 'includeWithEveryInvoice' |
58 | template?: { key?: string; id?: string; method?: string; href?: string } |
59 | schedule?: { |
60 | key?: string |
61 | id?: string |
62 | status?: |
63 | | 'draft' |
64 | | 'inProgress' |
65 | | 'completed' |
66 | | 'renewalForecast' |
67 | | 'onHold' |
68 | | 'terminated' |
69 | | 'estimateRevalued' |
70 | href?: string |
71 | } |
72 | method?: 'fixedPrice' | 'quantityBased' | 'projectT&M' | 'projectTime' | 'projectMaterials' |
73 | usageQuantityReset?: 'afterEachRenewal' | 'afterEachInvoice' |
74 | isUsageQuantityRecurring?: false | true |
75 | committedQuantityEndAction?: 'billUnusedQuantity' | 'cancelUnusedQuantity' | 'doNothing' |
76 | committedQuantityExcess?: 'doNothing' | 'billOverage' | 'doNotAllowOverage' |
77 | quantityType?: 'variable' | 'committed' |
78 | durationInPeriods?: string |
79 | proratePartialPeriods?: false | true |
80 | frequency?: 'monthly' | 'quarterly' | 'annually' |
81 | startDate?: string |
82 | endDate?: string |
83 | holdDate?: string |
84 | resumeDate?: string |
85 | memo?: string |
86 | quantity?: string |
87 | rate?: string |
88 | multiplier?: string |
89 | discount?: string |
90 | flatFixedAmount?: string |
91 | baseFlatFixedAmount?: string |
92 | totalFlatFixedAmount?: string |
93 | totalBaseFlatFixedAmount?: string |
94 | } |
95 | expense?: { holdDate?: string; resumeDate?: string; memo?: string } |
96 | revenue?: { |
97 | journal1?: { |
98 | glJournal?: { key?: string; id?: string; name?: string; href?: string } |
99 | revenueTemplate?: { |
100 | key?: string |
101 | id?: string |
102 | recognitionMethod?: string |
103 | href?: string |
104 | } |
105 | revenueSchedule?: { |
106 | key?: string |
107 | id?: string |
108 | status?: |
109 | | 'draft' |
110 | | 'inProgress' |
111 | | 'completed' |
112 | | 'renewalForecast' |
113 | | 'onHold' |
114 | | 'terminated' |
115 | | 'estimateRevalued' |
116 | | 'pendingDelivery' |
117 | | 'pendingDeliveryAll' |
118 | href?: string |
119 | } |
120 | startDate?: string |
121 | endDate?: string |
122 | } |
123 | journal2?: { |
124 | glJournal?: { key?: string; id?: string; name?: string; href?: string } |
125 | revenueTemplate?: { |
126 | key?: string |
127 | id?: string |
128 | recognitionMethod?: string |
129 | href?: string |
130 | } |
131 | revenueSchedule?: { |
132 | key?: string |
133 | id?: string |
134 | status?: |
135 | | 'draft' |
136 | | 'inProgress' |
137 | | 'completed' |
138 | | 'renewalForecast' |
139 | | 'onHold' |
140 | | 'terminated' |
141 | | 'estimateRevalued' |
142 | | 'pendingDelivery' |
143 | | 'pendingDeliveryAll' |
144 | href?: string |
145 | } |
146 | startDate?: string |
147 | endDate?: string |
148 | } |
149 | totalQuantity?: string |
150 | resumeDate?: string |
151 | holdDate?: string |
152 | memo?: string |
153 | } |
154 | renewal?: { |
155 | renew?: false | true |
156 | billingTemplate?: { key?: string; id?: string; href?: string } |
157 | } |
158 | contacts?: { |
159 | shipTo?: { key?: string; id?: string; href?: string } |
160 | billTo?: { key?: string; id?: string; href?: string } |
161 | } |
162 | contract?: { |
163 | key?: string |
164 | id?: string |
165 | endDate?: string |
166 | termType?: string |
167 | state?: 'draft' | 'inProgress' | 'canceled' | 'notRenewed' | 'renewed' |
168 | name?: string |
169 | href?: string |
170 | } |
171 | item?: { key?: string; id?: string; name?: string; href?: string } |
172 | renewalTriggerDate?: string |
173 | lineRenewalDate?: string |
174 | parent?: { key?: string; id?: string; lineNumber?: string; href?: string } |
175 | dimensions?: { |
176 | location?: { key?: string; id?: string; name?: string; href?: string } |
177 | department?: { key?: string; id?: string; name?: string; href?: string } |
178 | class?: { key?: string; id?: string; name?: string; href?: string } |
179 | task?: { id?: string; key?: string; name?: string; href?: string } |
180 | vendor?: { key?: string; id?: string; name?: string; href?: string } |
181 | customer?: { key?: string; id?: string; name?: string; href?: string } |
182 | project?: { key?: string; id?: string; name?: string; href?: string } |
183 | employee?: { key?: string; id?: string; name?: string; href?: string } |
184 | } |
185 | audit?: { |
186 | createdDateTime?: string |
187 | modifiedDateTime?: string |
188 | createdBy?: string |
189 | modifiedBy?: string |
190 | createdByUser?: { key?: string; id?: string; href?: string } |
191 | modifiedByUser?: { key?: string; id?: string; href?: string } |
192 | } |
193 | } & {} |
194 | ) { |
195 | const url = new URL(`https://api.intacct.com/ia/api/v1/objects/contracts/contract-line`) |
196 |
|
197 | const response = await fetch(url, { |
198 | method: 'POST', |
199 | headers: { |
200 | 'Content-Type': 'application/json', |
201 | Authorization: 'Bearer ' + auth.token |
202 | }, |
203 | body: JSON.stringify(body) |
204 | }) |
205 | if (!response.ok) { |
206 | const text = await response.text() |
207 | throw new Error(`${response.status} ${text}`) |
208 | } |
209 | return await response.json() |
210 | } |
211 |
|