1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Create a budget |
7 | * Creates a new budget. The API does not compute amounts for calculated budgets, so an `amount` must be provided when creating a budget-detail. |
8 |
|
9 |
|
10 | Permissions and other requirements |
11 |
|
12 | SubscriptionGeneral Ledger |
13 | User typeBusiness User |
14 | PermissionsAdd Budgets |
15 |
|
16 |
|
17 |
|
18 |
|
19 | */ |
20 | export async function main( |
21 | auth: SageIntacct, |
22 | body: { |
23 | key?: string |
24 | id?: string |
25 | description?: string |
26 | isDefault?: false | true |
27 | submitterName?: string |
28 | status?: 'active' | 'inactive' |
29 | consolidateAmounts?: false | true |
30 | currency?: string |
31 | postProjectEstimate?: false | true |
32 | postProjectContract?: false | true |
33 | audit?: { |
34 | createdDateTime?: string |
35 | modifiedDateTime?: string |
36 | createdBy?: string |
37 | modifiedBy?: string |
38 | } & { createdBy?: string; modifiedBy?: string } |
39 | entity?: { key?: string; id?: string; name?: string; href?: string } |
40 | href?: string |
41 | lines?: { |
42 | key?: string |
43 | id?: string |
44 | budget?: { key?: string; id?: string; href?: string } |
45 | glAccount?: { |
46 | key?: string |
47 | id?: string |
48 | name?: string |
49 | href?: string |
50 | } & { key?: string; id?: string; name?: string; href?: string } |
51 | dimensions?: { |
52 | location?: { key?: string; id?: string; name?: string; href?: string } |
53 | department?: { |
54 | key?: string |
55 | id?: string |
56 | name?: string |
57 | href?: string |
58 | } |
59 | employee?: { key?: string; id?: string; name?: string; href?: string } |
60 | project?: { key?: string; id?: string; name?: string; href?: string } |
61 | customer?: { key?: string; id?: string; name?: string; href?: string } |
62 | vendor?: { key?: string; id?: string; name?: string; href?: string } |
63 | item?: { key?: string; id?: string; name?: string; href?: string } |
64 | warehouse?: { key?: string; id?: string; name?: string; href?: string } |
65 | class?: { key?: string; id?: string; name?: string; href?: string } |
66 | task?: { id?: string; key?: string; name?: string; href?: string } |
67 | costType?: { id?: string; key?: string; name?: string; href?: string } |
68 | asset?: { id?: string; key?: string; name?: string; href?: string } |
69 | contract?: { id?: string; key?: string; name?: string; href?: string } |
70 | affiliateEntity?: { |
71 | key?: string |
72 | id?: string |
73 | href?: string |
74 | name?: string |
75 | } |
76 | } & { |
77 | location?: { key?: string; id?: string; name?: string; href?: string } |
78 | department?: { |
79 | key?: string |
80 | id?: string |
81 | name?: string |
82 | href?: string |
83 | } |
84 | } |
85 | reportingPeriod?: { key?: string; id?: string; href?: string } |
86 | notes?: string |
87 | budgetGrowth?: { |
88 | basedOn?: 'budget' | 'actual' | 'employeeCount' |
89 | growBy?: string |
90 | perPeriod?: 'actual' | 'percentage' |
91 | } |
92 | amount?: string |
93 | currency?: { |
94 | exchangeRateDate?: string |
95 | exchangeRateTypeId?: string |
96 | exchangeRate?: number |
97 | baseCurrency?: string |
98 | txnCurrency?: string |
99 | } |
100 | audit?: { |
101 | createdDateTime?: string |
102 | modifiedDateTime?: string |
103 | createdBy?: string |
104 | modifiedBy?: string |
105 | } |
106 | }[] |
107 | } & { lines?: {}[] } |
108 | ) { |
109 | const url = new URL(`https://api.intacct.com/ia/api/v1/objects/general-ledger/budget`) |
110 |
|
111 | const response = await fetch(url, { |
112 | method: 'POST', |
113 | headers: { |
114 | 'Content-Type': 'application/json', |
115 | Authorization: 'Bearer ' + auth.token |
116 | }, |
117 | body: JSON.stringify(body) |
118 | }) |
119 | if (!response.ok) { |
120 | const text = await response.text() |
121 | throw new Error(`${response.status} ${text}`) |
122 | } |
123 | return await response.json() |
124 | } |
125 |
|