1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Create an inventory transaction definition |
7 | * Creates a new inventory transaction definition. |
8 | */ |
9 | export async function main( |
10 | auth: SageIntacct, |
11 | body: { |
12 | key?: string |
13 | id?: string |
14 | href?: string |
15 | templateType?: 'quote' | 'order' | 'list' | 'invoice' | 'adjustment' | 'other' |
16 | description?: string |
17 | workflowCategory?: 'adjustment' | 'receipt' | 'transfer' | 'shipping' |
18 | reportingCategory?: |
19 | | 'inventoryAdjustment' |
20 | | 'buildKits' |
21 | | 'disassembleKits' |
22 | | 'inventoryDamagedGoods' |
23 | | 'inventoryReceipt' |
24 | | 'inventoryScrapOrSpoilage' |
25 | | 'inventoryShipper' |
26 | | 'warehouseTransfer' |
27 | status?: 'active' | 'inactive' |
28 | txnNumbering?: { |
29 | enableSequenceNumbering?: false | true |
30 | numberingSequence?: { key?: string; id?: string; href?: string } |
31 | preserveSequenceNumbers?: false | true |
32 | inheritSourceDocumentNumber?: false | true |
33 | } |
34 | inventoryControl?: { |
35 | enableWarnOnLowQty?: false | true |
36 | updatesInventory?: 'no' | 'quantity' | 'value' | 'quantityAndValue' |
37 | updatesCost?: false | true |
38 | increaseOrDecreaseInventory?: 'increase' | 'decrease' |
39 | warehouseSelectionMethod?: |
40 | | 'sortByID' |
41 | | 'sortByName' |
42 | | 'warehouseWithAvailableInventory' |
43 | | 'useTheDefaultWarehouse' |
44 | defaultWarehouse?: { key?: string; id?: string; href?: string } |
45 | } |
46 | accounting?: { |
47 | txnPosting?: 'postToGeneralLedger' | 'doNotPost' |
48 | isSubTotalsEnabled?: false | true |
49 | } |
50 | conversionType?: 'leaveTxnOpen' | 'closeTxn' |
51 | pricingAndTerms?: { |
52 | initialPriceList?: { key?: string; id?: string; href?: string } |
53 | specialPriceList?: { key?: string; id?: string; href?: string } |
54 | } |
55 | print?: { documentTemplate?: string; defaultText?: string } |
56 | enableUserOrGroupPermmission?: false | true |
57 | userOverrides?: { |
58 | allowDepartmentOverride?: false | true |
59 | allowLocationOverride?: false | true |
60 | } |
61 | documentPermissions?: { |
62 | editPolicy?: 'noEdit' | 'beforePrinting' | 'editInDraftOnly' | 'all' |
63 | deletePolicy?: 'beforePrinting' | 'all' | 'noDelete' | 'deleteInDraftOnly' |
64 | createPolicy?: 'newDocumentOrConvert' | 'convertOnly' |
65 | multiEntityRuleForTxn?: 'topLevelOrEntity' | 'topLevelOnly' | 'entityOnly' |
66 | } |
67 | inventoryTotalDetail?: { |
68 | key?: string |
69 | id?: string |
70 | href?: string |
71 | maintainType?: 'quantity' | 'value' | 'quantityAndValue' |
72 | operation?: 'add' | 'subtract' |
73 | inventoryTotal?: { key?: string; id?: string; href?: string } |
74 | inventoryTxnDefinition?: { key?: string; id?: string; href?: string } |
75 | }[] |
76 | subtotalDetail?: { |
77 | key?: string |
78 | id?: string |
79 | href?: string |
80 | inventoryTxnDefinition?: { key?: string; id?: string; href?: string } |
81 | lineNumber?: number |
82 | description?: string |
83 | subtotalType?: 'discount' | 'charge' |
84 | appliedToLineNumber?: number |
85 | valueType?: 'amount' | 'percent' |
86 | subtotalValue?: string |
87 | txnType?: '' | 'debit' | 'credit' |
88 | glAccount?: { href?: string; id?: string; key?: string } |
89 | offsetGlAccount?: { href?: string; id?: string; key?: string } |
90 | isTax?: false | true |
91 | enableAvaTax?: false | true |
92 | dimensions?: { |
93 | location?: { key?: string; id?: string; name?: string; href?: string } |
94 | department?: { |
95 | key?: string |
96 | id?: string |
97 | name?: string |
98 | href?: string |
99 | } |
100 | employee?: { key?: string; id?: string; name?: string; href?: string } |
101 | project?: { key?: string; id?: string; name?: string; href?: string } |
102 | customer?: { key?: string; id?: string; name?: string; href?: string } |
103 | vendor?: { key?: string; id?: string; name?: string; href?: string } |
104 | item?: { key?: string; id?: string; name?: string; href?: string } |
105 | warehouse?: { key?: string; id?: string; name?: string; href?: string } |
106 | class?: { key?: string; id?: string; name?: string; href?: string } |
107 | task?: { id?: string; key?: string; name?: string; href?: string } |
108 | costType?: { id?: string; key?: string; name?: string; href?: string } |
109 | asset?: { id?: string; key?: string; name?: string; href?: string } |
110 | contract?: { id?: string; key?: string; name?: string; href?: string } |
111 | affiliateEntity?: { |
112 | key?: string |
113 | id?: string |
114 | href?: string |
115 | name?: string |
116 | } |
117 | } & { |
118 | department?: { |
119 | href?: string |
120 | id?: string |
121 | key?: string |
122 | name?: string |
123 | } |
124 | location?: { href?: string; id?: string; key?: string; name?: string } |
125 | } |
126 | }[] |
127 | sourceDocumentDetail?: { |
128 | key?: string |
129 | id?: string |
130 | href?: string |
131 | inventoryTxnDefinition?: { key?: string; id?: string; href?: string } |
132 | convertedFrom?: { key?: string; id?: string; href?: string } |
133 | }[] |
134 | inventoryAccountMapping?: { |
135 | key?: string |
136 | id?: string |
137 | href?: string |
138 | txnType?: 'debit' | 'credit' |
139 | moduleType?: 'subledger' | 'inventory' |
140 | lineNumber?: number |
141 | glAccount?: { key?: string; id?: string; href?: string } |
142 | dimensions?: { |
143 | location?: { key?: string; id?: string; name?: string; href?: string } |
144 | department?: { |
145 | key?: string |
146 | id?: string |
147 | name?: string |
148 | href?: string |
149 | } |
150 | employee?: { key?: string; id?: string; name?: string; href?: string } |
151 | project?: { key?: string; id?: string; name?: string; href?: string } |
152 | customer?: { key?: string; id?: string; name?: string; href?: string } |
153 | vendor?: { key?: string; id?: string; name?: string; href?: string } |
154 | item?: { key?: string; id?: string; name?: string; href?: string } |
155 | warehouse?: { key?: string; id?: string; name?: string; href?: string } |
156 | class?: { key?: string; id?: string; name?: string; href?: string } |
157 | task?: { id?: string; key?: string; name?: string; href?: string } |
158 | costType?: { id?: string; key?: string; name?: string; href?: string } |
159 | asset?: { id?: string; key?: string; name?: string; href?: string } |
160 | contract?: { id?: string; key?: string; name?: string; href?: string } |
161 | affiliateEntity?: { |
162 | key?: string |
163 | id?: string |
164 | href?: string |
165 | name?: string |
166 | } |
167 | } & { |
168 | location?: { key?: string; id?: string; name?: string; href?: string } |
169 | department?: { |
170 | key?: string |
171 | id?: string |
172 | name?: string |
173 | href?: string |
174 | } |
175 | warehouse?: { key?: string; id?: string; href?: string } |
176 | } |
177 | itemGLGroup?: { key?: string; id?: string; href?: string } |
178 | inventoryTxnDefinition?: { key?: string; id?: string; href?: string } |
179 | }[] |
180 | entitySettingDetail?: { |
181 | key?: string |
182 | id?: string |
183 | href?: string |
184 | txnNumbering?: { |
185 | preserveSequenceNumbering?: false | true |
186 | inheritSourceDocumentNumber?: false | true |
187 | sequenceNumber?: { key?: string; href?: string; id?: string } |
188 | } |
189 | documentTemplate?: { key?: string; id?: string } |
190 | entity?: { href?: string; key?: string; id?: string } |
191 | inventoryTxnDefinition?: { key?: string; id?: string; href?: string } |
192 | }[] |
193 | audit?: { |
194 | createdDateTime?: string |
195 | modifiedDateTime?: string |
196 | createdBy?: string |
197 | modifiedBy?: string |
198 | } |
199 | entity?: { key?: string; id?: string; name?: string; href?: string } |
200 | } & {} |
201 | ) { |
202 | const url = new URL(`https://api.intacct.com/ia/api/v1/objects/inventory-control/txn-definition`) |
203 |
|
204 | const response = await fetch(url, { |
205 | method: 'POST', |
206 | headers: { |
207 | 'Content-Type': 'application/json', |
208 | Authorization: 'Bearer ' + auth.token |
209 | }, |
210 | body: JSON.stringify(body) |
211 | }) |
212 | if (!response.ok) { |
213 | const text = await response.text() |
214 | throw new Error(`${response.status} ${text}`) |
215 | } |
216 | return await response.json() |
217 | } |
218 |
|