1
|
Ext.define('MinovaES.controller.orm.ctrlCustom.training.costpattern', {
|
2
|
extend: 'Ext.app.ViewController',
|
3
|
alias: 'controller.costpattern',
|
4
|
ObjectID: undefined,
|
5
|
init: function () {
|
6
|
this.control({
|
7
|
'[name=mainCostpattern]': {
|
8
|
afterrender: this.afterrenderCostPattern
|
9
|
},
|
10
|
'[name=saveCP]': {
|
11
|
click: this.save
|
12
|
},
|
13
|
'[action=addEmp]': {
|
14
|
click: this.addGrid
|
15
|
},
|
16
|
'[action=deleteData]': {
|
17
|
click: this.deleteGrid
|
18
|
},
|
19
|
'[name=PHROM0033]': {
|
20
|
afterrender: this.afterrenderGrid
|
21
|
},
|
22
|
'[name=PDSTRCOSTITEMSUM]': {
|
23
|
afterrender: this.afterrenderGridSum
|
24
|
},
|
25
|
'[name=gridPHROM0033]': {
|
26
|
edit: this.editGridCostPattern
|
27
|
},
|
28
|
'[id=PHROM0033CalculateAttendance]': {
|
29
|
change: this.calAtt
|
30
|
},
|
31
|
'[id=PHROM0033CalculateDay]': {
|
32
|
change: this.calDay
|
33
|
}
|
34
|
});
|
35
|
},
|
36
|
afterrenderGrid: function(){
|
37
|
var me = this;
|
38
|
var overView = Ext.StoreMgr.lookup("storePHROM0033");
|
39
|
overView.proxy.url = '/UserControl/GetStore';
|
40
|
var pnlORM = Ext.ComponentQuery.query('[name=mainORM]')[0];
|
41
|
var obj = pnlORM.getRecordSelect();
|
42
|
var objid = obj.data.ObjectId;
|
43
|
overView.proxy.extraParams = {
|
44
|
tableName: 'PHROM0033',
|
45
|
param: 'ObjectID[=]' + objid
|
46
|
};
|
47
|
overView.removeAll();
|
48
|
overView.reload();
|
49
|
overView.loadPage(1);
|
50
|
},
|
51
|
afterrenderGridSum: function(){
|
52
|
var me = this;
|
53
|
var pnlORM = Ext.ComponentQuery.query('[name=mainORM]')[0];
|
54
|
var gridSum = Ext.ComponentQuery.query('[name=PDSTRCOSTITEMSUM]')[0];
|
55
|
var strSum = Ext.StoreMgr.lookup("PDSTRCOSTITEMSUM");
|
56
|
var obj = pnlORM.getRecordSelect();
|
57
|
var objid = obj.data.ObjectId;
|
58
|
var total = 0;
|
59
|
var totalCost = 0;
|
60
|
Ext.Ajax.request({
|
61
|
async: false,
|
62
|
method: 'POST',
|
63
|
url: '/UserControl/GetStore',
|
64
|
params: {
|
65
|
tableName: 'PHROM0033',
|
66
|
param: 'ObjectID[equal]' + objid
|
67
|
},
|
68
|
success: function (response) {
|
69
|
var results = Ext.decode(response.responseText);
|
70
|
var dt = results.data;
|
71
|
for(var i = 0; i<dt.length; i++)
|
72
|
{
|
73
|
total = parseFloat(dt[i].Total);
|
74
|
var cur = dt[i].Currency;
|
75
|
var strSum = gridSum.store;
|
76
|
var idx = strSum.findExact('Currency', cur); console.log(idx);
|
77
|
if(idx >= 0)
|
78
|
{
|
79
|
var recsum = strSum.findRecord('Currency', cur)
|
80
|
totalCost = total + parseFloat(recsum.data.Amount);
|
81
|
recsum.data.Amount = totalCost;
|
82
|
//gridSum.view.refresh(); // comment by Tri nwh 20230307
|
83
|
}
|
84
|
else
|
85
|
{
|
86
|
strSum.add({
|
87
|
Currency: cur,
|
88
|
Amount: total
|
89
|
});
|
90
|
//gridSum.view.refresh(); // comment by Tri nwh 20230307
|
91
|
}
|
92
|
}
|
93
|
}
|
94
|
});
|
95
|
var overView = Ext.StoreMgr.lookup("storePHROM0033");
|
96
|
overView.reload();
|
97
|
},
|
98
|
afterrenderCostPattern: function(){
|
99
|
var me = this;
|
100
|
var pnl = Ext.ComponentQuery.query('[name=PanelOrmMdDetail]')[0];
|
101
|
pnl.setHeight(600);
|
102
|
},
|
103
|
addGrid: function(){
|
104
|
var store = Ext.StoreMgr.lookup('storePHROM0033');
|
105
|
var pnlORM = Ext.ComponentQuery.query('[name=mainORM]')[0];
|
106
|
var obj = pnlORM.getRecordSelect();
|
107
|
var objid = obj.data.ObjectId;
|
108
|
var objClass = obj.data.ObjectType;
|
109
|
idx = store.getCount();
|
110
|
var Sequence = 0;
|
111
|
if (idx == 0) {
|
112
|
Sequence = 1;
|
113
|
} else {
|
114
|
Sequence = 1 + idx;
|
115
|
}
|
116
|
var seq = 'Sequence';
|
117
|
var SequenceValue = Sequence;
|
118
|
data = {
|
119
|
Currency: '',
|
120
|
ObjectClass: objClass,
|
121
|
CostType: '',
|
122
|
DayNumber: '',
|
123
|
CalculateEvent: '',
|
124
|
CalculateDay: '',
|
125
|
CalculateAttendance: '',
|
126
|
AttendanceNumber: '',
|
127
|
Notes: '',
|
128
|
Total: '0',
|
129
|
UnitPrice: '0',
|
130
|
ObjectID: objid,
|
131
|
StartDate: obj.data.StartDate,
|
132
|
EndDate: obj.data.EndDate,
|
133
|
CreateDate: '',
|
134
|
CreateBy: '',
|
135
|
ChangeDate: '',
|
136
|
ChangeBy: '',
|
137
|
Action: 0
|
138
|
};
|
139
|
data[seq] = SequenceValue;
|
140
|
store.insert(idx, data);
|
141
|
},
|
142
|
calAtt: function(){
|
143
|
var attVal = Ext.ComponentQuery.query('[id=PHROM0033CalculateAttendance]')[0];
|
144
|
var obj = Ext.ComponentQuery.query('[id=PHROM0033ObjectID]')[0];
|
145
|
var objClass = Ext.ComponentQuery.query('[id=PHROM0033ObjectClass]')[0];
|
146
|
var q = Ext.ComponentQuery.query('[id=PHROM0033AttendanceNumber]')[0];
|
147
|
if(attVal.getValue() == "1")
|
148
|
{
|
149
|
var tablename = "";
|
150
|
if(objClass.getValue() == "DT")
|
151
|
{
|
152
|
tablename = "PHROM0031";
|
153
|
} else if(objClass.getValue() == "DE")
|
154
|
{
|
155
|
tablename = "PHROM0036";
|
156
|
}
|
157
|
Ext.Ajax.request({
|
158
|
async: false,
|
159
|
method: 'POST',
|
160
|
url: '/UserControl/GetStore',
|
161
|
params: {
|
162
|
tableName: tablename,
|
163
|
param: 'ObjectID[equal]' + obj.getValue() + ',ObjectClass[equal]' + objClass.getValue()
|
164
|
},
|
165
|
success: function (response) {
|
166
|
var results = Ext.decode(response.responseText);
|
167
|
var attNumb = results.totalRecords;
|
168
|
q.setValue(attNumb);
|
169
|
}
|
170
|
});
|
171
|
} else if(attVal.getValue() == "0")
|
172
|
{
|
173
|
q.setValue(0);
|
174
|
}
|
175
|
},
|
176
|
calDay: function(){
|
177
|
var attVal = Ext.ComponentQuery.query('[id=PHROM0033CalculateDay]')[0];
|
178
|
var obj = Ext.ComponentQuery.query('[id=PHROM0033ObjectID]')[0];
|
179
|
var objClass = Ext.ComponentQuery.query('[id=PHROM0033ObjectClass]')[0];
|
180
|
var q = Ext.ComponentQuery.query('[id=PHROM0033DayNumber]')[0];
|
181
|
if(attVal.getValue() == "1")
|
182
|
{
|
183
|
var tablename = "";
|
184
|
if(objClass.getValue() == "DT")
|
185
|
{
|
186
|
tablename = "PHROM0028";
|
187
|
} else if(objClass.getValue() == "DE")
|
188
|
{
|
189
|
tablename = "PHROM0035";
|
190
|
}
|
191
|
Ext.Ajax.request({
|
192
|
async: false,
|
193
|
method: 'POST',
|
194
|
url: '/UserControl/GetStore',
|
195
|
params: {
|
196
|
tableName: tablename,
|
197
|
param: 'ObjectID[equal]' + obj.getValue() + ',ObjectClass[equal]' + objClass.getValue()
|
198
|
},
|
199
|
success: function (response) {
|
200
|
var results = Ext.decode(response.responseText);
|
201
|
var attNumb = results.data;
|
202
|
var dur = 0;
|
203
|
Ext.each(attNumb, function(d) {
|
204
|
dur = dur + parseFloat(d.Duration);
|
205
|
});
|
206
|
q.setValue(dur);
|
207
|
}
|
208
|
});
|
209
|
} else if(attVal.getValue() == "0")
|
210
|
{
|
211
|
q.setValue(0);
|
212
|
}
|
213
|
},
|
214
|
deleteGrid: function()
|
215
|
{
|
216
|
var me = this;
|
217
|
var grid = Ext.getCmp('gridPHROM0033');
|
218
|
var selection = grid.getView().getSelectionModel()
|
219
|
var dt = selection.getSelection()[0];
|
220
|
if (dt) {
|
221
|
Ext.MessageBox.show({
|
222
|
title: 'Remove tab',
|
223
|
msg: MinovaMessageData('000007', ''),
|
224
|
buttons: Ext.MessageBox.YESNO,
|
225
|
fn: function (choice) {
|
226
|
if (choice === 'yes') {
|
227
|
var data = Ext.pluck(selection.selected.items, 'data');
|
228
|
var action = undefined;
|
229
|
$.grep(data, function (r) {
|
230
|
action = r.Action;
|
231
|
})
|
232
|
if(action == undefined)
|
233
|
{
|
234
|
Ext.Ajax.request({
|
235
|
async: false,
|
236
|
method: 'POST',
|
237
|
url: '/Devt/SaveTable',
|
238
|
params: {
|
239
|
tableName: 'PHROM0033',
|
240
|
data: Ext.encode(data),
|
241
|
action: 2
|
242
|
},
|
243
|
waitMsg: 'Saving Data...',
|
244
|
success: function (response) {
|
245
|
var result = Ext.decode(response.responseText);
|
246
|
if (result.success) {
|
247
|
MinovaMessage('', 'BSDEL', '', 'S');
|
248
|
var storeGrid = Ext.StoreMgr.lookup("storePHROM0033");
|
249
|
/*storeGrid.reload();*/
|
250
|
storeGrid.remove(dt);
|
251
|
}
|
252
|
else {
|
253
|
pnl.unmask();
|
254
|
MinovaMessage('', '000005', result.message.text, "E")
|
255
|
}
|
256
|
},
|
257
|
failure: function (response) {
|
258
|
var result = Ext.decode(response.responseText);
|
259
|
MinovaMessage('', '000005', result, "E")
|
260
|
|
261
|
}
|
262
|
});
|
263
|
} else if (action == 0)
|
264
|
{
|
265
|
var storeGrid = Ext.StoreMgr.lookup("storePHROM0033");
|
266
|
storeGrid.remove(dt);
|
267
|
MinovaMessage('', 'BSDEL', '', 'S');
|
268
|
}
|
269
|
var grid33 = Ext.ComponentQuery.query('[name=gridPHROM0033]')[0];
|
270
|
var gridSum = Ext.ComponentQuery.query('[name=PDSTRCOSTITEMSUM]')[0];
|
271
|
me.loadSummariesCost(grid33, gridSum);
|
272
|
}
|
273
|
}
|
274
|
});
|
275
|
}
|
276
|
},
|
277
|
editGridCostPattern: function(editor, e) {
|
278
|
var me = this;
|
279
|
var rec = e.record;
|
280
|
var curency = rec.data.Currency;
|
281
|
var calAtt = rec.data.CalculateAttendance;
|
282
|
var calEvent = rec.data.CalculateEvent;
|
283
|
var calDay = rec.data.CalculateDay;
|
284
|
var unitPrice = rec.data.UnitPrice;
|
285
|
var attNumb = rec.data.AttendanceNumber;
|
286
|
var dayNumb = rec.data.DayNumber;
|
287
|
if(curency == null ||
|
288
|
curency == undefined ||
|
289
|
curency == "")
|
290
|
{
|
291
|
alert("Currency is mandatory field ");
|
292
|
return;
|
293
|
}
|
294
|
if(calAtt == "1" && calDay == "1")
|
295
|
{
|
296
|
rec.data.Total = parseFloat(unitPrice) * parseFloat(attNumb) * parseFloat(dayNumb);
|
297
|
} else if(calAtt == "1")
|
298
|
{
|
299
|
rec.data.Total = parseFloat(unitPrice) * parseFloat(attNumb);
|
300
|
} else if(calDay == "1")
|
301
|
{
|
302
|
rec.data.Total = parseFloat(unitPrice) * parseFloat(dayNumb);
|
303
|
} else if(calAtt == "0" && calDay == "0" && calEvent == "1")
|
304
|
{
|
305
|
rec.data.Total = parseFloat(unitPrice);
|
306
|
} else
|
307
|
{
|
308
|
rec.data.Total = parseFloat(unitPrice) * 1;
|
309
|
}
|
310
|
var grid = Ext.ComponentQuery.query('[name=gridPHROM0033]')[0];
|
311
|
var gridSum = Ext.ComponentQuery.query('[name=PDSTRCOSTITEMSUM]')[0];
|
312
|
grid.view.refresh();
|
313
|
me.loadSummariesCost(grid, gridSum);
|
314
|
},
|
315
|
loadSummariesCost: function(grid, gridSum)
|
316
|
{
|
317
|
var total = 0;
|
318
|
var totalCost = 0;
|
319
|
gridSum.store.removeAll();
|
320
|
if(grid.store.count() == 0) gridSum.store.removeAll();
|
321
|
Ext.each(grid.store.getRange(), function(r) {
|
322
|
var cur = r.data.Currency;
|
323
|
total = parseFloat(r.data.Total);
|
324
|
var strSum = gridSum.store;
|
325
|
var idx = strSum.findExact('Currency', cur)
|
326
|
if(idx >= 0)
|
327
|
{
|
328
|
var recsum = strSum.findRecord('Currency', cur)
|
329
|
totalCost = total + parseFloat(recsum.data.Amount);
|
330
|
recsum.data.Amount = totalCost;
|
331
|
gridSum.view.refresh();
|
332
|
}
|
333
|
else
|
334
|
{
|
335
|
strSum.add({
|
336
|
Currency: cur,
|
337
|
Amount: total
|
338
|
});
|
339
|
gridSum.view.refresh();
|
340
|
}
|
341
|
});
|
342
|
},
|
343
|
save: function()
|
344
|
{
|
345
|
var pnl = Ext.ComponentQuery.query('[name=PHROM0033]')[0];
|
346
|
pnl.mask('Loading...');
|
347
|
var storeGrid = Ext.StoreMgr.lookup("storePHROM0033");
|
348
|
var storeCount_ = storeGrid.getCount();
|
349
|
if (storeCount_ > 0) {
|
350
|
var storeGrid = Ext.StoreMgr.lookup("storePHROM0033");
|
351
|
var dt = Ext.pluck(storeGrid.data.items, 'data');
|
352
|
dataAdd = $.grep(dt, function (r) {
|
353
|
return r.Action == '0'
|
354
|
});
|
355
|
dataEdit = $.grep(dt, function (r) {
|
356
|
return r.Action != '0'
|
357
|
});
|
358
|
Ext.Ajax.request({
|
359
|
async: false,
|
360
|
method: 'POST',
|
361
|
url: '/Devt/SaveEditTable',
|
362
|
params: {
|
363
|
tableName: 'PHROM0033',
|
364
|
dataAdd: Ext.encode(dataAdd),
|
365
|
dataEdit: Ext.encode(dataEdit)
|
366
|
},
|
367
|
waitMsg: 'Saving Data...',
|
368
|
success: function (response) {
|
369
|
var result = Ext.decode(response.responseText);
|
370
|
if (result.success) {
|
371
|
MinovaMessage('', '000006', '', 'S');
|
372
|
storeGrid.reload();
|
373
|
}
|
374
|
else {
|
375
|
pnl.unmask();
|
376
|
MinovaMessage('', '000005', result.message.text, "E")
|
377
|
}
|
378
|
},
|
379
|
failure: function (response) {
|
380
|
var result = Ext.decode(response.responseText);
|
381
|
MinovaMessage('', '000005', result, "E")
|
382
|
}
|
383
|
});
|
384
|
}
|
385
|
pnl.unmask();
|
386
|
}
|
387
|
});
|