-
Notifications
You must be signed in to change notification settings - Fork 3
/
workorder_costs.ts
275 lines (260 loc) · 9.29 KB
/
workorder_costs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import { CWError } from './error'
import ReversibleMap from 'reversible-map'
const _ = require('lodash')
export class WorkOrderCosts {
/**
* @hidden
*/
cw: any
/**
* Storage of object's active activityType
*/
currentActivityType: string
/**
* @hidden
*/
constructor(cw:any) {
this.cw = cw
this.currentActivityType = "WorkOrder"
}
/**
* Get Cost Codes
*
* @category Labor Costs
* @param {Array<number>} employeeSids - A list of Employee IDs for which to get the job codes.
* @param {boolean} commonOnly - Set to true to get the Cost Codes that are common to ALL employees in the list, otherwise get all job codes that apply to at least one employee in the list.
* @return {Object} Returns Promise that represents an object describing
*/
getCodes(employeeSids: Object, commonOnly: boolean = false) {
return new Promise((resolve, reject) => {
var data = {
EmployeeSids: employeeSids,
CommonCodesOnly: commonOnly
}
this.cw.runRequest('Ams/LaborCost/CostCodes', data).then(r => {
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Get Job Codes
*
* @category Labor Costs
* @return {Object} Returns Promise that represents an object describing
*/
getJobCodes() {
return new Promise((resolve, reject) => {
this.cw.runRequest('Ams/LaborCost/JobCodes').then(r => {
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Add WorkOrder Labor Costs
*
* @category WorkOrder Costs
* @param {number} workOrderSid - Array of inspection labor costings
* @param {number} hours - Number of hours to add
* @param {Object} options - options for the work order
* @return {Object} Returns Promise that represents an object describing
*/
addLabor(workOrderSid: number, hours: number, options: Object) {
return new Promise((resolve, reject) => {
var data = {
WorkOrderSid: workOrderSid,
Hours: hours
}
if(typeof(options)!='undefined') {
data = _.merge(data, options)
}
// TODO: ensure each object has Hours & InspectionId
this.cw.runRequest('Ams/LaborCost/AddWorkOrderCosts', data).then((response: any) => {
resolve(response.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Get Labor Costs for WorkOrder(s)
*
* @category WorkOrder Costs
* @param {Array<number>} workOrderSids - Array of request Ids to get costs for
* @param {boolean} estimated - Whether to get estimates or actuals (defaults to false -- get actuals)
* @return {Object} Returns Promise that represents an object describing
*/
getLabor(workOrderSids: Array<number>, estimated: boolean = false) {
return new Promise((resolve, reject) => {
var data = {
Estimated: estimated,
WorkOrderSids: workOrderSids
}
this.cw.runRequest('Ams/LaborCost/WorkOrderCostsByWorkOrder', data).then((response: any) => {
resolve(response.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Delete WorkOrder Labor Costs
*
* @category WorkOrder Costs
* @param {Array<number>} laborCostIds - List of labor cost IDs to delete
* @param {boolean} estimated - Whether to delete estimates or actuals (defaults to false -- delete actuals)
* @return {Object} Returns Promise that represents an object describing
*/
deleteLabor(laborCostIds: Array<number>, estimated: boolean = false) {
return new Promise((resolve, reject) => {
var data = {
LaborCostIds: laborCostIds,
Estimated: estimated
}
this.cw.runRequest('Ams/LaborCost/DeleteWorkOrderCosts', data).then((response: any) => {
resolve(response.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Add WorkOrder Equipment Costs
*
* @category WorkOrder Costs
* @param {Object} workOrderSid - the work order to add the equipment costs to
* @param {Object} options - additional options
* @return {Object} Returns Promise that represents an object describing
*/
addEquipment(workOrderSid: number, options: Object) {
return new Promise((resolve, reject) => {
var data = {
WorkOrderSid: workOrderSid
}
if(typeof(options)!='undefined') {
data = _.merge(data, options)
}
// TODO: ensure each object has Hours & InspectionId
this.cw.runRequest('Ams/EquipmentCost/AddWorkOrderCosts', data).then((response: any) => {
resolve(response.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Get Equipment Costs for WorkOrder(s)
*
* @category WorkOrder Costs
* @param {number} workOrderSid - the work order to add the equipment costs to
* @param {boolean} estimated - true to get estimated costs. defaults to false
* @return {Object} Returns Promise that represents an object describing
*/
// WorkOrderCostsByWorkOrderList<EquipmentCost>
getEquipment(workOrderSid: number, estimated: boolean = false) {
return new Promise((resolve, reject) => {
var data = {
WorkOrderSid: workOrderSid,
Estimated: estimated
}
// TODO: ensure each object has Hours & InspectionId
this.cw.runRequest('Ams/EquipmentCost/WorkOrderCostsByWorkOrder', data).then((response: any) => {
resolve(response.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Delete WorkOrder Equipment Costs
*
* @category WorkOrder Costs
* @param {Object}
* @return {Object} Returns Promise that represents an object describing
*/
deleteEquipment(equipmentCostIds: Array<number>, estimated: boolean = false) { // "WorkOrderId", "WorkOrderSid", "Estimated", "MaterialSids", "Units", "AcctNum", "Source", "TransDate", "ContractorSids", "ContractorMaterialId", "ContractorMaterialDescription", "ContractorMaterialCost", "TaskIds", "Entities", "CombineIssuesByMaterialSid"
return new Promise((resolve, reject) => {
var data = {
EquipmentCostIds: equipmentCostIds,
Estimated: estimated
}
this.cw.runRequest('Ams/EquipmentCost/DeleteWorkOrderCosts', data).then((response: any) => {
resolve(response.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Add WorkOrder Material Costs
*
* @category WorkOrder Costs
* @param {number} workOrderSid - Work Order SID number to add the material to
* @param {number} units - Decimal units for material
* @param {Object} options - Additional work order options
* @param {boolean} combineIssuesByMaterialSid - Combine issues with the same MaterialSid into a single commit, default is true
* @return {Object} Returns Promise that represents a collection describing the work order material costs
*/
addMaterial(workOrderSid: number, units: number, options: Object, combineIssuesByMaterialSid: boolean = true) { // "WorkOrderId", "WorkOrderSid", "Estimated", "MaterialSids", "Units", "AcctNum", "Source", "TransDate", "ContractorSids", "ContractorMaterialId", "ContractorMaterialDescription", "ContractorMaterialCost", "TaskIds", "Entities", "CombineIssuesByMaterialSid"
return new Promise((resolve, reject) => {
var data = {
Units: units,
WorkOrderSid: workOrderSid,
CombineIssuesByMaterialSid: combineIssuesByMaterialSid
}
if(typeof(options)!='undefined') {
data = _.merge(data, options)
}
this.cw.runRequest('Ams/MaterialCost/AddWorkOrderCosts', data).then((response: any) => {
resolve(response.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Get Material Costs for WorkOrder(s)
*
* @category WorkOrder Costs
* @param {number} workOrderSid - the work order to add the equipment costs to
* @param {boolean} estimated - true to get estimated costs. defaults to false and gets actuals.
* @return {Object} Returns Promise that represents an object describing
*/
getMaterial(workOrderSid: number, estimated: boolean = false) { // "WorkOrderId", "WorkOrderSid", "Estimated", "MaterialSids", "Units", "AcctNum", "Source", "TransDate", "ContractorSids", "ContractorMaterialId", "ContractorMaterialDescription", "ContractorMaterialCost", "TaskIds", "Entities", "CombineIssuesByMaterialSid"
return new Promise((resolve, reject) => {
var data = {
WorkOrderSid: workOrderSid,
Estimated: estimated
}
this.cw.runRequest('Ams/MaterialCost/AddWorkOrderCosts', data).then((response: any) => {
resolve(response.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Delete WorkOrder Material Costs
*
* @category WorkOrder Costs
* @param {Array<number>} materialCostIds - list of material cost IDs to delete
* @param {boolean} estimated - true to delete the estimated costs. defaults to false and deletes actuals.
* @return {Object} Returns Promise that represents an object describing
*/
deleteMaterial(materialCostIds: number, estimated: boolean = false) {
return new Promise((resolve, reject) => {
var data = {
MaterialCostIds: materialCostIds,
Estimated: estimated
}
this.cw.runRequest('Ams/MaterialCost/DeleteWorkOrderCosts', data).then((response: any) => {
resolve(response.Value)
}).catch(e => {
reject(e)
})
})
}
}