1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Update a WIP period |
7 | * Updates an existing WIP period by setting the field values. Any fields not provided remain unchanged. |
8 |
|
9 |
|
10 | Permissions and other requirements |
11 |
|
12 | SubscriptionConstruction |
13 | User typeBusiness, Project Manager |
14 | PermissionsEdit WIP Periods |
15 |
|
16 |
|
17 |
|
18 |
|
19 | */ |
20 | export async function main( |
21 | auth: SageIntacct, |
22 | key: string, |
23 | body: { |
24 | key?: string |
25 | id?: string |
26 | periodName?: string |
27 | periodStartDate?: string |
28 | periodEndDate?: string |
29 | fiscalYear?: string |
30 | state?: 'unposted' | 'posted' |
31 | notes?: string |
32 | isHistoricalImport?: false | true |
33 | lastRefreshDateTime?: string |
34 | createdFromEntity?: { |
35 | key?: string |
36 | id?: string |
37 | name?: string |
38 | href?: string |
39 | } |
40 | assignedEntity?: { |
41 | key?: string |
42 | id?: string |
43 | name?: string |
44 | href?: string |
45 | } |
46 | endOfPriorYearPeriod?: { |
47 | key?: string |
48 | id?: string |
49 | periodName?: string |
50 | href?: string |
51 | } |
52 | audit?: { |
53 | createdDateTime?: string |
54 | modifiedDateTime?: string |
55 | createdBy?: string |
56 | modifiedBy?: string |
57 | } |
58 | wipProjects?: { |
59 | key?: string |
60 | id?: string |
61 | isFinalized?: false | true |
62 | glPostedDate?: string |
63 | estimatedCostToDateAmount?: string |
64 | jobToDateCosts?: string |
65 | estimatedCostToComplete?: string |
66 | estimatedCostAtCompletion?: string |
67 | pendingEstimatesAmount?: string |
68 | estimatedPercentComplete?: string |
69 | projectManagerForecast?: { |
70 | costToComplete?: string |
71 | costAtCompletion?: string |
72 | percentComplete?: string |
73 | contractValue?: string |
74 | lastUpdatedDate?: string |
75 | } |
76 | cfoForecast?: { |
77 | costToComplete?: string |
78 | costAtCompletion?: string |
79 | percentComplete?: string |
80 | contractValue?: string |
81 | lastUpdatedDate?: string |
82 | } |
83 | costAtCompletionVariance?: string |
84 | totalContractValue?: string |
85 | contractVarianceAmount?: string |
86 | jobToDateBillings?: string |
87 | earnedToDateAmount?: string |
88 | remainingBacklogAmount?: string |
89 | overUnderBillingAmount?: string |
90 | earnedProfitToDateAmount?: string |
91 | grossProfitPercentOfContract?: string |
92 | grossProfitPercentOfCost?: string |
93 | totalGrossProfitEstimatedAtCompletion?: string |
94 | cfoForecastGrossProfitAtCompletion?: string |
95 | grossProfitVarianceAmount?: string |
96 | cfoForecastGrossProfitMarginPercent?: string |
97 | priorYearsProfit?: string |
98 | endOfPriorYearEarnedToDateAmount?: string |
99 | endOfPriorYearEarnedProfit?: string |
100 | remainingProfit?: string |
101 | yearToDateCostAmount?: string |
102 | yearToDateBillingAmount?: string |
103 | yearToDateEarnedRevenueAmount?: string |
104 | jobToDateOverBillingAmount?: string |
105 | jobToDateUnderBillingAmount?: string |
106 | yearToDateEarnedProfitAmount?: string |
107 | currentPeriodBillingAmount?: string |
108 | currentPeriodCostAmount?: string |
109 | currentPeriodEarnedProfitAmount?: string |
110 | currentPeriodEarnedRevenueAmount?: string |
111 | notes?: string |
112 | forecastDetails?: { |
113 | key?: string |
114 | id?: string |
115 | wipPeriod?: { |
116 | key?: string |
117 | id?: string |
118 | periodName?: string |
119 | href?: string |
120 | } |
121 | assignedEntity?: { |
122 | key?: string |
123 | id?: string |
124 | name?: string |
125 | href?: string |
126 | } |
127 | wipProject?: { key?: string; id?: string; href?: string } |
128 | project?: { key?: string; id?: string; name?: string; href?: string } |
129 | costType?: { id?: string; key?: string; name?: string; href?: string } |
130 | task?: { id?: string; key?: string; name?: string; href?: string } |
131 | groupTask?: { id?: string; key?: string; name?: string; href?: string } |
132 | costAndEstimateDetail?: { |
133 | key?: string |
134 | jobToDateCosts?: string |
135 | estimatedCostToDateAmount?: string |
136 | estimatedCostAtCompletion?: string |
137 | pendingEstimatesAmount?: string |
138 | estimatedCostToComplete?: string |
139 | estimatedPercentComplete?: string |
140 | estimateVsForecastVariance?: string |
141 | href?: string |
142 | } |
143 | projectManagerForecast?: { |
144 | key?: string |
145 | costToComplete?: string |
146 | costAtCompletion?: string |
147 | percentComplete?: string |
148 | notes?: string |
149 | pmUserUpdatedDate?: string |
150 | costToCompleteVariance?: string |
151 | costAtCompletionVariance?: string |
152 | href?: string |
153 | } |
154 | priorPeriodProjectManagerForecast?: { |
155 | costToComplete?: string |
156 | costAtCompletion?: string |
157 | percentComplete?: string |
158 | } |
159 | href?: string |
160 | }[] |
161 | href?: string |
162 | audit?: { |
163 | createdDateTime?: string |
164 | modifiedDateTime?: string |
165 | createdBy?: string |
166 | modifiedBy?: string |
167 | } |
168 | project?: { |
169 | key?: string |
170 | id?: string |
171 | name?: string |
172 | description?: string |
173 | status?: 'active' | 'inactive' |
174 | startDate?: string |
175 | endDate?: string |
176 | href?: string |
177 | } |
178 | customer?: { key?: string; id?: string; name?: string; href?: string } |
179 | projectType?: { key?: string; id?: string; href?: string } |
180 | projectStatus?: { key?: string; id?: string; href?: string } |
181 | location?: { key?: string; id?: string; name?: string; href?: string } |
182 | class?: { key?: string; id?: string; name?: string; href?: string } |
183 | department?: { key?: string; id?: string; name?: string; href?: string } |
184 | manager?: { key?: string; id?: string; name?: string; href?: string } |
185 | wipPeriod?: { |
186 | key?: string |
187 | id?: string |
188 | periodName?: string |
189 | href?: string |
190 | } |
191 | }[] |
192 | href?: string |
193 | } & { id?: {} } |
194 | ) { |
195 | const url = new URL( |
196 | `https://api.intacct.com/ia/api/v1/objects/construction-forecasting/wip-period/${key}` |
197 | ) |
198 |
|
199 | const response = await fetch(url, { |
200 | method: 'PATCH', |
201 | headers: { |
202 | 'Content-Type': 'application/json', |
203 | Authorization: 'Bearer ' + auth.token |
204 | }, |
205 | body: JSON.stringify(body) |
206 | }) |
207 | if (!response.ok) { |
208 | const text = await response.text() |
209 | throw new Error(`${response.status} ${text}`) |
210 | } |
211 | return await response.json() |
212 | } |
213 |
|