1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Create a project estimate |
7 | * Creates a new project estimate. You must specify a unique ID when creating a project estimate unless document sequencing is configured, in which case the ID is auto-generated. |
8 | */ |
9 | export async function main( |
10 | auth: SageIntacct, |
11 | body: { |
12 | key?: string |
13 | id?: string |
14 | href?: string |
15 | description?: string |
16 | postTo?: 'firstPeriod' | 'estimateDate' | 'effectiveDate' | 'allPeriods' |
17 | totalEstimateAmount?: string |
18 | status?: 'active' | 'inactive' | 'finalized' |
19 | isPrimary?: false | true |
20 | isPosted?: false | true |
21 | estimateDate?: string |
22 | currency?: string |
23 | budget?: { key?: string; id?: string; href?: string } |
24 | project?: { |
25 | key?: string |
26 | id?: string |
27 | name?: string |
28 | startDate?: string |
29 | endDate?: string |
30 | href?: string |
31 | } |
32 | projectEstimateType?: { |
33 | key?: string |
34 | id?: string |
35 | workflowTypes?: |
36 | | 'original' |
37 | | 'revision' |
38 | | 'forecast' |
39 | | 'approvedChange' |
40 | | 'pendingChange' |
41 | | 'other'[] |
42 | href?: string |
43 | } |
44 | location?: { key?: string; id?: string; name?: string; href?: string } |
45 | parentProject?: { key?: string; id?: string; name?: string; href?: string } |
46 | customer?: { key?: string; id?: string; name?: string; href?: string } |
47 | projectEstimateLines?: { |
48 | key?: string |
49 | id?: string |
50 | href?: string |
51 | amount?: string |
52 | quantity?: string |
53 | unitCost?: string |
54 | currency?: string |
55 | memo?: string |
56 | lineNumber?: number |
57 | externalUOM?: string |
58 | workflowType?: |
59 | | 'original' |
60 | | 'revision' |
61 | | 'forecast' |
62 | | 'approvedChange' |
63 | | 'pendingChange' |
64 | | 'other' |
65 | isPosted?: false | true |
66 | effectiveDate?: string |
67 | numberOfProductionUnits?: number |
68 | productionUnitDescription?: string |
69 | projectEstimate?: { key?: string; id?: string; href?: string } |
70 | glAccount?: { key?: string; id?: string; name?: string; href?: string } |
71 | changeRequest?: { key?: string; id?: string; href?: string } |
72 | changeRequestLine?: { key?: string; id?: string; href?: string } |
73 | dimensions?: { |
74 | location?: { key?: string; id?: string; name?: string; href?: string } |
75 | department?: { |
76 | key?: string |
77 | id?: string |
78 | name?: string |
79 | href?: string |
80 | } |
81 | employee?: { key?: string; id?: string; name?: string; href?: string } |
82 | project?: { key?: string; id?: string; name?: string; href?: string } |
83 | customer?: { key?: string; id?: string; name?: string; href?: string } |
84 | vendor?: { key?: string; id?: string; name?: string; href?: string } |
85 | item?: { key?: string; id?: string; name?: string; href?: string } |
86 | warehouse?: { key?: string; id?: string; name?: string; href?: string } |
87 | class?: { key?: string; id?: string; name?: string; href?: string } |
88 | task?: { id?: string; key?: string; name?: string; href?: string } |
89 | costType?: { id?: string; key?: string; name?: string; href?: string } |
90 | asset?: { id?: string; key?: string; name?: string; href?: string } |
91 | contract?: { id?: string; key?: string; name?: string; href?: string } |
92 | affiliateEntity?: { |
93 | key?: string |
94 | id?: string |
95 | href?: string |
96 | name?: string |
97 | } |
98 | } & { |
99 | department?: { key?: string; id?: string; name?: string } |
100 | location?: { |
101 | key?: string |
102 | id?: string |
103 | name?: string |
104 | href?: string |
105 | } & { id?: string } |
106 | } |
107 | audit?: { |
108 | createdDateTime?: string |
109 | modifiedDateTime?: string |
110 | createdBy?: string |
111 | modifiedBy?: string |
112 | } |
113 | }[] |
114 | attachment?: { key?: string; id?: string; href?: string } |
115 | audit?: { |
116 | createdDateTime?: string |
117 | modifiedDateTime?: string |
118 | createdBy?: string |
119 | modifiedBy?: string |
120 | } |
121 | entity?: { key?: string; id?: string; name?: string; href?: string } |
122 | } & {} |
123 | ) { |
124 | const url = new URL(`https://api.intacct.com/ia/api/v1/objects/construction/project-estimate`) |
125 |
|
126 | const response = await fetch(url, { |
127 | method: 'POST', |
128 | headers: { |
129 | 'Content-Type': 'application/json', |
130 | Authorization: 'Bearer ' + auth.token |
131 | }, |
132 | body: JSON.stringify(body) |
133 | }) |
134 | if (!response.ok) { |
135 | const text = await response.text() |
136 | throw new Error(`${response.status} ${text}`) |
137 | } |
138 | return await response.json() |
139 | } |
140 |
|