Project

General

Profile

Bug #1925 » controller.wf.pmsperform.ctr_pfdir_v2.js

ctr_pfdir_v2 - M Azid Wahyudi, 01/12/2023 03:20 PM

 
1
	Ext.define('MinovaIS.ERP.Web.controller.wf.pmsperform.ctr_pfdir_v2', {
2
			extend: 'Ext.app.Controller',
3

    
4
			views: ['wf.pmsperform.view'],
5
			viewID: null,
6
			init: function () {},
7
			onDocumentInit: function (me) {
8
				me.loadPeriod();
9
				var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
10
				var header = MinovaUtil.WORKFLOW.getViewHeaderWorkflow();
11
				body.query('textfield[name=qual_total_score]')[0].setValue('0');
12
				body.query('textfield[name=qual_total_final]')[0].setValue('0');
13
				body.query('textfield[name=kpi_total_final]')[0].setValue('0');
14
				header.query('textfield[name=subject]')[0].setReadOnly(true);
15
				header.query('textfield[name=description]')[0].hide(true);
16

    
17
				var taskId = MinovaUtil.WORKFLOW.getTaskId();
18
				var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
19

    
20
				var obh = header.down('textfield[name=employee_id]');
21
				if (obh !== undefined) {
22
					obh.on('change', me.changeEmpID, this);
23
				}
24

    
25
				var minovaGridAPR = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('minovagrid[name=Appraiser]');
26
				minovaGridAPR.reconfigureWORKFLOW();
27

    
28
				var cb_apr_id = Ext.widget({
29
					xtype: 'minovacombobox',
30
					displayField: 'description',
31
					valueField: 'emp_id',
32
					listeners: {
33
						select: function (_this, recs) {
34
							var records = _this.up('grid').getSelectionModel().getSelection();
35
							records[0].set('apr_appraiser_name', recs[0].get('description'));
36
						}
37
					}
38
				});
39
				cb_apr_id.store.load({
40
					params: {
41
						paramid: 'pms_appraiser_id'
42
					}
43
				});
44

    
45
				var cb_pms_appraiser_type = Ext.widget({
46
					xtype: 'minovacombobox',
47
					displayField: 'description',
48
					valueField: 'description'
49
				});
50
				cb_pms_appraiser_type.store.load({
51
					params: {
52
						paramid: 'pms_appraiser_type'
53
					}
54
				});
55
				var cb_apr_appraiser_no = Ext.widget({
56
					xtype: 'minovacombobox',
57
					displayField: 'desc',
58
					valueField: 'desc',
59
					store: Ext.create('Ext.data.Store', {
60
						fields: ['code', 'desc'],
61
						data: [{
62
								"desc": "Appraiser 1",
63
								"code": "app1"
64
							}, {
65
								"desc": "Appraiser 2",
66
								"code": "app2"
67
							}, {
68
								"desc": "Appraiser 3",
69
								"code": "app3"
70
							}
71
						]
72
					})
73
				});
74

    
75
				minovaGridAPR.changeColumnEditor('apr_appraiser_id', cb_apr_id);
76
				minovaGridAPR.changeColumnEditor('apr_appraiser_type', cb_pms_appraiser_type);
77
				minovaGridAPR.changeColumnEditor('apr_appraiser_no', cb_apr_appraiser_no);
78

    
79
				//KPI
80
				me.getGridKPI().reconfigureWORKFLOW();
81

    
82
				var cb_pms_kpi_id = Ext.widget({
83
					xtype: 'minovacombobox',
84
					displayField: 'name',
85
					valueField: 'object',
86
					listeners: {
87
						select: function (_this, recs) {
88
							var name = recs[0].data.name;
89
							var grp = recs[0].data.kpi_group_desc;
90
							var records = _this.up('grid').getSelectionModel().getSelection();
91

    
92
							Ext.each(records, function (rec) {
93
								rec.set('kpi_kpi_name', name);
94
								rec.set('kpi_kpi_group', grp);
95
							});
96
						}
97
					}
98
				});
99
				cb_pms_kpi_id.store.load({
100
					params: {
101
						paramid: 'pms_kpi_id'
102
					}
103
				});
104

    
105
				var cb_pms_kpi_group = Ext.widget({
106
					xtype: 'minovacombobox',
107
					displayField: 'description',
108
					valueField: 'description',
109
					readOnly: true
110
				});
111
				cb_pms_kpi_group.store.load({
112
					params: {
113
						paramid: 'pms_kpi_group'
114
					}
115
				});
116
				var cb_pms_kpi_unit = Ext.widget({
117
					xtype: 'minovacombobox',
118
					displayField: 'measurement',
119
					valueField: 'measurement'
120
				});
121
				cb_pms_kpi_unit.store.load({
122
					params: {
123
						paramid: 'pms_kpi_measurement'
124
					}
125
				});
126

    
127
				var toolbar = me.getGridKPI().down('[xtype=toolbar]')
128
					toolbar.add('->');
129
				toolbar.add({
130
					text: 'Calculate',
131
					name: 'calculate',
132
					action: 'kpi_calculate'
133
				})
134

    
135
				me.getGridKPI().changeColumnEditor('kpi_kpi_id', cb_pms_kpi_id);
136
				me.getGridKPI().changeColumnEditor('kpi_kpi_group', cb_pms_kpi_group);
137
				me.getGridKPI().changeColumnEditor('kpi_unit', cb_pms_kpi_unit);
138

    
139
				//QUAL
140

    
141
				me.getGridQual().reconfigureWORKFLOW();
142

    
143
				var toolbar = me.getGridQual().down('[xtype=toolbar]')
144
					toolbar.add('->');
145
				toolbar.add({
146
					text: 'Calculate',
147
					name: 'calculate',
148
					action: 'qual_calculate'
149
				})
150

    
151
				var cb_pms_qual_qual_id = Ext.widget({
152
					xtype: 'minovacombobox',
153
					displayField: 'name',
154
					valueField: 'object',
155
					listeners: {
156
						select: {
157
							fn: function (_this, recs) {
158
								var name = recs[0].data.name;
159
								var grp = recs[0].data.qual_group_desc;
160
								var grpid = recs[0].data.qual_group;
161
								var records = _this.up('grid').getSelectionModel().getSelection();
162
								Ext.each(records, function (rec) {
163
									rec.set('qual_qual_group', grpid);
164
								});
165
							}
166
						}
167
					}
168
				});
169

    
170
				cb_pms_qual_qual_id.store.load({
171
					params: {
172
						paramid: 'pms_qual_id'
173
					}
174
				});
175

    
176
				var cb_pms_qual_group = Ext.widget({
177
					xtype: 'minovacombobox',
178
					displayField: 'description',
179
					valueField: 'code',
180
					readOnly: true
181
				});
182

    
183
				var cb_pms_qual_appraiser = Ext.widget({
184
					xtype: 'minovacombobox',
185
					valueField: 'code',
186
					displayField: 'description'
187
				});
188
				cb_pms_qual_appraiser.store.load({
189
					params: {
190
						paramid: 'pms_qual_appraiser'
191
					}
192
				});
193

    
194
				me.getGridQual().changeColumnEditor('qual_qual_id', cb_pms_qual_qual_id);
195
				me.getGridQual().changeColumnEditor('qual_qual_group', cb_pms_qual_group);
196
				me.getGridQual().changeColumnEditor('qual_app1_score', cb_pms_qual_appraiser);
197
				me.getGridQual().changeColumnEditor('qual_app2_score', cb_pms_qual_appraiser);
198
				Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_id]').setWidth(800);
199
				////SubKPI
200
				//me.getGridSubKPI().reconfigureWORKFLOW();
201
				var cb_pms_sub_kpi_id = Ext.widget({
202
					xtype: 'minovacombobox',
203
					displayField: 'name',
204
					valueField: 'object',
205
					listeners: {
206
						scope: me,
207
						'expand': function (field, opt) {
208
							// koleksi KPI yang ada di grid KPI
209
							var listOfKPI = []
210
							Ext.each(me.getGridKPI().store.getRange(), function (r) {
211
								listOfKPI.push(r.data.kpi_kpi_id)
212
							});
213
							// filter combo KPI sesuai koleksi
214
							field.store.filter([
215
									//{property: "email", value: /\.com$/},
216
									{
217
										filterFn: function (item) {
218
											return listOfKPI.indexOf(item.get("object")) >= 0;
219
										}
220
									}
221
								]);
222
						},
223
						'select': function (field, records, opt) {
224
							field.store.clearFilter();
225
							// get and set KPI seq to SubKPI parentSeq
226
							var rec_KPI = this.getGridKPI().store.findRecord('kpi_kpi_id', field.getValue());
227
							var rec_SubKPI = this.getGridSubKPI().getSelectionModel().getSelection()[0];
228

    
229
							rec_SubKPI.set('subkpi_kpi_seq', rec_KPI.get('kpi_seq'))
230
						}
231
					}
232
				});
233
				cb_pms_sub_kpi_id.store.load({
234
					params: {
235
						paramid: 'pms_kpi_id'
236
					}
237
				});
238
				var cb_pms_sub_sub_kpi_id = Ext.widget({
239
					xtype: 'minovacombobox',
240
					displayField: 'description'
241
				});
242
				cb_pms_sub_sub_kpi_id.store.load({
243
					params: {
244
						paramid: 'pms_subkpi_id'
245
					}
246
				});
247
				var cb_pms_sub_kpi_unit = Ext.widget({
248
					xtype: 'minovacombobox',
249
					displayField: 'code'
250
				});
251
				cb_pms_sub_kpi_unit.store.load({
252
					params: {
253
						paramid: 'pms_subkpi_unit'
254
					}
255
				});
256
				var store_0_5 = new Ext.data.Store({
257
					fields: ['code', 'desc'],
258
					data: [{
259
							"desc": "0",
260
							"code": "0"
261
						}, {
262
							"desc": "1",
263
							"code": "1"
264
						}, {
265
							"desc": "2",
266
							"code": "2"
267
						}, {
268
							"desc": "3",
269
							"code": "3"
270
						}, {
271
							"desc": "4",
272
							"code": "4"
273
						}, {
274
							"desc": "5",
275
							"code": "5"
276
						}
277
					]
278
				});
279
				var cb_combo_val = new Ext.widget({
280
					xtype: 'minovacombobox',
281
					store: store_0_5
282
				});
283
				var subkpi_app1_value = new Ext.widget({
284
					xtype: 'minovacombobox',
285
					store: store_0_5
286
				});
287
				var subkpi_app2_value = new Ext.widget({
288
					xtype: 'minovacombobox',
289
					store: store_0_5
290
				});
291
				var subkpi_app3_value = new Ext.widget({
292
					xtype: 'minovacombobox',
293
					store: store_0_5
294
				});
295
				var subkpi_app4_value = new Ext.widget({
296
					xtype: 'minovacombobox',
297
					store: store_0_5
298
				});
299
				var subkpi_app5_value = new Ext.widget({
300
					xtype: 'minovacombobox',
301
					store: store_0_5
302
				});
303
				var subkpi_self_value = new Ext.widget({
304
					xtype: 'minovacombobox',
305
					store: store_0_5
306
				});
307
				var qual_self_value = new Ext.widget({
308
					xtype: 'minovacombobox',
309
					store: store_0_5
310
				});
311
				var kpi_self_value = new Ext.widget({
312
					xtype: 'minovacombobox',
313
					store: store_0_5
314
				});
315

    
316
				/*        var subkpi_app1_value = new Ext.widget({
317
				xtype: 'numberfield'
318
				});
319
				var subkpi_app2_value = new Ext.widget({
320
				xtype: 'numberfield'
321
				});
322
				var subkpi_app3_value = new Ext.widget({
323
				xtype: 'numberfield'
324
				});
325
				var subkpi_app4_value = new Ext.widget({
326
				xtype: 'numberfield'
327
				});
328
				var subkpi_app5_value = new Ext.widget({
329
				xtype: 'numberfield'
330
				});
331
				var subkpi_self_value = new Ext.widget({
332
				xtype: 'numberfield'
333
				});*/
334

    
335
				me.getGridSubKPI().changeColumnEditor('subkpi_kpi_id', cb_pms_sub_kpi_id);
336
				me.getGridSubKPI().changeColumnEditor('subkpi_sub_kpi', cb_pms_sub_sub_kpi_id);
337
				me.getGridSubKPI().changeColumnEditor('subkpi_unit', cb_pms_sub_kpi_unit);
338
				me.getGridSubKPI().changeColumnEditor('subkpi_app1_value', subkpi_app1_value);
339
				me.getGridSubKPI().changeColumnEditor('subkpi_app2_value', subkpi_app2_value);
340
				me.getGridSubKPI().changeColumnEditor('subkpi_app3_value', subkpi_app3_value);
341
				me.getGridSubKPI().changeColumnEditor('subkpi_app4_value', subkpi_app4_value);
342
				me.getGridSubKPI().changeColumnEditor('subkpi_app5_value', subkpi_app5_value);
343
				me.getGridSubKPI().changeColumnEditor('subkpi_self_value', subkpi_self_value);
344
				me.getGridQual().changeColumnEditor('qual_self_value', qual_self_value);
345
				me.getGridKPI().changeColumnEditor('kpi_self_value', kpi_self_value);
346

    
347
				var toolbar = me.getGridSubKPI().down('[xtype=toolbar]')
348
					toolbar.add('->');
349
				toolbar.add({
350
					text: 'Calculate',
351
					name: 'calculate',
352
					action: 'subkpi_calculate'
353
				});
354
				if (taskId == "apv_appraiser" || taskId == "revise_created_appraiser") {
355
					console.log("PLAY ondoc " + taskId);
356
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textarea[name=kom_appraiser]')[0].setReadOnly(false);
357
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textarea[name=kom_usulan]')[0].setReadOnly(false);
358
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textarea[name=kom_ind_dev_plan]')[0].setReadOnly(false);
359
					console.log("END PLAY ondoc " + taskId);
360
				}
361
				setTimeout(function () {
362
					me.getGridQual().view.refresh();
363
				}, 3000);
364

    
365
			},
366
			onDocumentReady: function (me) {
367

    
368
				MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('button').forEach(
369

    
370
					function (b) {
371
					b.on('click', me.buttonClick, me);
372
				});
373

    
374
				var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
375

    
376
				var obperiod = body.down('combobox[name=h_period]');
377
				if (obperiod !== null) {
378
					obperiod.on('change', me.periodChange, me);
379
				}
380

    
381
				var obh_appr_date = body.down('datefield[name=h_appr_date]');
382
				if (obh_appr_date !== null) {
383
					obh_appr_date.on('change', me.aprdate_check, me);
384
				}
385

    
386
				me.cekTaskIDrun();
387

    
388
			},
389
			onDocumentBeforeSubmit: function (submit, taskId, me) {
390
				//        if (!me.hasRecordKpi(me)) return MinovaUtil.MESSAGE.error('record not found on KPI/ SubKPI grid')
391
				console.log('masukondocbeforesumbit');
392
				var revise = MinovaUtil.WORKFLOW.getFlowId();
393
				if (revise == "apv_appraiser1_revise" || revise == "apv_nha_many_revise" || revise == "apv_nha_revise") {
394
					submit();
395
				} else {
396
					console.log('validasi');
397
					me.validasiSubmit(submit);
398

    
399
					var validasiWeightValNol = me.isValidDataWeightValNol(me);
400
					if (!validasiWeightValNol.success) {
401
						return MinovaUtil.MESSAGE.error(validasiWeightValNol.msg);
402
					}
403

    
404
					var validasiTotalWeightHarus100 = me.isValidDataWeightTotal100(me);
405
					if (!validasiTotalWeightHarus100.success) {
406
						return MinovaUtil.MESSAGE.error(validasiTotalWeightHarus100.msg)			
407
					}
408
				}
409
			},
410
			isValidDataWeightTotal100: function (me) {
411

    
412
				var RecARP = me.getGridARP().store.getRange();
413
				var RecKPI = me.getGridKPI().store.getRange();
414
				var RecSubKPI = me.getGridSubKPI().store.getRange();
415

    
416
				if (!Ext.isEmpty(RecARP)) {
417
					var total = 0;
418
					var total2 = 0;
419
					Ext.each(RecARP, function (r) {
420
						total += Number(r.data.apr_weight_qual);
421
						total2 += Number(r.data.apr_weight_kpi);
422
					});
423
					if (total !== 100)
424
						return {
425
							success: false,
426
							msg: 'Weight competency on Appraiser not 100'
427
						}
428
					if (total2 !== 100)
429
						return {
430
							success: false,
431
							msg: 'Weight kpi on Appraiser not 100'
432
						}
433
				}
434

    
435
				// if (!Ext.isEmpty(RecKPI)) {
436
					// var total = 0;
437
					// Ext.each(RecKPI, function (r) {
438
						// total += Number(r.data.kpi_weight);
439
					// });
440
					// if (total !== 100)
441
						// return {
442
							// success: false,
443
							// msg: 'Weight on KPI not 100'
444
						// }
445
				// }
446

    
447
				if (!Ext.isEmpty(RecSubKPI)) {
448
					var isValid = true;
449
					var _unique = [];
450
					Ext.each(RecSubKPI, function (r) {
451
						_unique.push(r.data.subkpi_kpi_id);
452
					});
453
					Ext.each(Ext.unique(_unique), function (kpi_id) {
454
						var total = 0;
455
						var recFiltered = Ext.Array.filter(RecSubKPI, function (r) {
456
							return r.data.subkpi_kpi_id === kpi_id
457
						});
458
						Ext.each(recFiltered, function (r) {
459
							total += Number(r.data.subkpi_weight);
460
						});
461
						if (total !== 100)
462
							return isValid = false
463
					});
464
					if (!isValid)
465
						return {
466
							success: false,
467
							msg: 'Weight on SubKPI not 100'
468
						}
469
				}
470
				return {
471
					success: true
472
				};
473
			},
474
			isValidDataWeightValNol: function (me) {
475
				var isValid = true;
476
				Ext.each(me.getGridKPI().store.getRange(), function (r) {
477
					var val = Number(r.data.kpi_weight);
478
					if (val === 0 || val === NaN) {
479
						isValid = false;
480
						return {
481
							success: false,
482
							msg: 'value 0 on KPI weight is\'t valid'
483
						};
484
					}
485
				});
486
				if (isValid)
487
					Ext.each(me.getGridSubKPI().store.getRange(), function (r) {
488
						var val = Number(r.data.subkpi_weight);
489
						if (val === 0 || val === NaN) {
490
							isValid = false;
491
							return {
492
								success: false,
493
								msg: 'value 0 on SubKPI weight is\'t valid'
494
							};
495
						}
496
					});
497
				return {
498
					success: true,
499
					msg: ''
500
				};
501
			},
502
			getGridARP: function () {
503
				return MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=Appraiser]');
504
			},
505
			getGridKPI: function () {
506
				return MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=KPI]');
507
			},
508
			getGridSubKPI: function () {
509
				return MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=SubKPI]');
510
			},
511
			getGridQual: function () {
512
				return MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=QUAL]');
513
			},
514
			buttonClick: function (_this) {
515
				switch (_this.action) {
516
				case 'kpi_calculate':
517
					this.calculateSubKPI_main();
518
					break;
519
				case 'subkpi_calculate':
520
					this.calculateSubKPI_main();
521
					break;
522
				case 'qual_calculate':
523
					this.calculateQUAL();
524
					break;
525
				case 'cal_adjusted':
526
					this.calculateFS();
527
					break;
528
				default:
529
					break;
530

    
531
				}
532
			},
533
			validasiSubmit: function (submit) {
534
				var is_other = 0;
535
				var is_staff = 0;
536
				var qual_group = '';
537
				var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
538
				var not_submit = '0';
539
				var wei = 0;
540
				var wei_07 = 0;
541
				var wei_05 = 0;
542
				var wei_other = 0;
543

    
544
				var warning_text = 'Silahkan cek kembali qualifikasi yang anda pilih';
545
				var w_sscore = 'Silahkan isi Self Score anda';
546
				var w_appraiser = 'Silahkan isi nilai appraiser anda';
547
				var w_qualweight_75 = 'Weight dari qualification harus total 100 untuk masing2 group';
548
				var w_qualweight = 'Weight dari qualification harus total 100';
549

    
550
				var countkpi = Body.down('grid[name=KPI]').getStore().count();
551

    
552
				Body.down('grid[name=QUAL]').getStore().each(function (rec) {
553
					qual_group = rec.data.qual_qual_group;
554
					wei = parseFloat(rec.data.qual_weight);
555

    
556
					//            if (qual_group === '00000007') {
557
					//                is_staff = 1;
558
					//                wei_07 = wei_07 + wei;
559
					//            } else if (qual_group === '00000005') {
560
					//                is_staff = 1;
561
					//                wei_05 = wei_05 + wei;
562
					//            } else {
563
					//                is_other = 1;
564
					//                wei_other = wei_other + wei;
565
					//            }
566

    
567
					is_other = 1;
568
					wei_other = wei_other + wei;
569

    
570
				});
571

    
572
				if (countkpi > 0) {
573
					if (is_staff > 0) {
574
						alert(warning_text);
575
						not_submit = '1';
576
						//return false;
577

    
578
					}
579

    
580
				} else {
581
					if (is_staff > 0) {
582
						if (is_other > 0) {
583
							alert(warning_text);
584
							not_submit = '1';
585
							//return false;
586

    
587
						}
588

    
589
					}
590

    
591
				}
592

    
593
				if (is_staff > 0 && (wei_07 != 100 || wei_05 != 100)) {
594
					alert(w_qualweight_75);
595
					not_submit = '1';
596
					//return false;
597
				} else if (wei_other != 100 && is_other > 0) {
598
					alert(w_qualweight);
599
					not_submit = '1';
600
					//return false;
601
				}
602

    
603
				//Validasi per TASK
604
				var taskId = MinovaUtil.WORKFLOW.getTaskId();
605

    
606
				var qual1 = ['start', ''];
607
				var qual2 = ['apv_appraiser_many', 'apv_appraiser', 'result_appraiser1', 'revise_created_appraiser'];
608
				var qual3 = ['apv_nha', 'apv_appraiser', 'apv_nha_many', 'revise_created_appraiser'];
609
				var kpi_nilai = 0;
610
				var qual_nilai = 0;
611
				var kpi_appaiserscore = '';
612
				var loginEmpID = MinovaUtil.SESSIONS.LOGIN.empId;
613
				var apr_nocode = '';
614

    
615
				if (qual1.indexOf(taskId) >= 0) {
616
					//Body.down('grid[name=KPI]').getStore().each(function(rec) {
617
					//    kpi_nilai = parseInt(rec.data.kpi_self_value);
618
					//    if (kpi_nilai <= 0) {
619
					//        alert(w_sscore);
620
					//        not_submit = '1';
621
					//        return false;
622
					//    }
623
					//});
624

    
625
					//Body.down('grid[name=SubKPI]').getStore().each(function(rec) {
626
					//    kpi_nilai = parseInt(rec.data.subkpi_self_value);
627
					//    if (kpi_nilai <= 0) {
628
					//        alert(w_sscore);
629
					//        not_submit = '1';
630
					//        return false;
631
					//    }
632
					//});
633
					//if (not_submit === '1') return false;
634

    
635
					Body.down('grid[name=QUAL]').getStore().each(function (rec) {
636
						qual_nilai = parseFloat(rec.data.qual_self_value) || 0;
637
						if (qual_nilai <= 0) {
638
							alert(w_sscore);
639
							not_submit = '1';
640
							return false;
641
						}
642
					});
643

    
644
				}
645

    
646
				if (qual2.indexOf(taskId) >= 0) {
647
					Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
648
						//console.log(rec.data.apr_appraiser_id);
649
						var apr_no = rec.data.apr_appraiser_no;
650
						var apr_id = rec.data.apr_appraiser_id;
651

    
652
						if (apr_id === loginEmpID) {
653
							apr_nocode = "app" + apr_no.substring(10);
654
						} else {
655
							apr_nocode = "app" + apr_no.substring(10);
656
						}
657
					});
658

    
659
					//Body.down('grid[name=KPI]').getStore().each(function(rec) {
660
					//    kpi_nilai = parseInt(rec.data['kpi_' + apr_nocode + '_value']);
661
					//    if (kpi_nilai <= 0) {
662
					//       alert(w_appraiser);
663
					//        not_submit = '1';
664
					//        //return false;
665
					//    }
666
					//});
667

    
668
					//Body.down('grid[name=SubKPI]').getStore().each(function(rec) {
669
					//    kpi_nilai = parseInt(rec.data['subkpi_' + apr_nocode + '_value']);
670
					//    if (kpi_nilai <= 0) {
671
					//        alert(w_sscore);
672
					//        not_submit = '1';
673
					//        return false;
674
					//    }
675
					//});
676
					//
677
					//if (not_submit === '1') return false;
678
					Body.down('grid[name=QUAL]').getStore().each(function (rec) {
679
						qual_nilai = (rec.data['qual_' + apr_nocode + '_score']);
680
						if (qual_nilai == '') {
681
							qual_nilai = 0;
682
						} else {
683
							qual_nilai = parseFloat(qual_nilai);
684
						}
685
						if (qual_nilai <= 0) {
686
							alert(w_appraiser);
687
							not_submit = '1';
688
							return false;
689
						}
690
					});
691
				}
692
				if (taskId === "apv_appraiser" || taskId == "revise_created_appraiser") {
693
					if (parseFloat(Body.query('textfield[name=qual_total_final]')[0].getValue()) <= 0) {
694
						alert('mohon calculate terlebih dahulu');
695
						not_submit = '1';
696
					}
697
				}
698

    
699
				if (not_submit === '1') {
700
					console.log('not_submit = ' + not_submit);
701
				} else {
702
					console.log('not_submit = ' + not_submit + ' submit()');
703
					submit();
704
				}
705

    
706
			},
707
			calculateFS: function () {
708

    
709
				var sumkpi = 0;
710
				var sumqual = 0;
711
				var sumcal = 0;
712
				var is_staff = 0;
713
				var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
714

    
715
				//qualification FS calculate Data
716
				var score_weighted = parseFloat('0.00');
717
				var qual_TargetStaff = parseFloat('0.00');
718
				var qual_KompetensiStaff = parseFloat('0.00');
719
				var qual_group = '';
720

    
721
				var kw = parseFloat(Body.down('textfield[name=sum_kpi_weight]').getValue());
722
				var qw = parseFloat(Body.down('textfield[name=sum_comp_weight]').getValue());
723
				var fkpi = parseFloat(Body.down('textfield[name=sum_final_kpi]').getValue());
724
				var fqual = parseFloat(Body.down('textfield[name=sum_final_competency]').getValue());
725

    
726
				var tw = kw + qw;
727
				//alert('7' + tw);
728
				//Qualification Target Staff Checking
729
				Body.down('grid[name=QUAL]').getStore().each(function (rec) {
730
					qual_group = rec.data.qual_qual_group;
731
					score_weighted = parseFloat(rec.data.qual_qual_score_weighted);
732

    
733
					//            if (qual_group === '00000007' || qual_group === '00000005') {
734
					//                is_staff = 1;
735
					//            }
736
					//            if (qual_group === '00000007') {
737
					//                qual_TargetStaff = qual_TargetStaff + score_weighted;
738
					//            } else if (qual_group === '00000005') {
739
					//                qual_KompetensiStaff = qual_KompetensiStaff + score_weighted;
740
					//            }
741

    
742
				});
743
				//end
744

    
745
				if (is_staff === 1) {
746
					sumkpi = qual_TargetStaff;
747
					sumqual = qual_KompetensiStaff;
748
				} else {
749
					Body.down('grid[name=KPI]').getStore().each(function (rec) {
750
						var ks = parseFloat(rec.data.kpi_kpi_score_weighted);
751
						sumkpi = sumkpi + ks;
752
					});
753

    
754
					Body.down('grid[name=QUAL]').getStore().each(function (rec) {
755
						var kq = parseFloat(rec.data.qual_qual_score_weighted);
756
						sumqual = sumqual + kq;
757
					});
758
				}
759
				//alert(kw);
760
				sumkpi = sumkpi * kw / tw;
761
				sumqual = sumqual * qw / tw;
762
				sumcal = sumkpi + Body.down('textfield[name=sum_calculated_competency]').getValue();
763
				//sumcal = sumkpi + sumqual;
764
				//alert(sumkpi);
765
				sumkpi = Math.round(sumkpi * 100) / 100;
766
				sumqual = Math.round(sumqual * 100) / 100;
767
				sumcal = Math.round(sumcal * 100) / 100;
768

    
769
				var fs = fkpi + fqual;
770
				Body.down('textfield[name=sum_calculated_kpi]').setValue(sumkpi);
771
				//Body.down('textfield[name=sum_calculated_competency]').setValue(sumqual);
772
				Body.down('textfield[name=sum_calculated_score]').setValue(sumcal);
773
				Body.down('textfield[name=sum_final_score]').setValue(fs);
774
				//Body.down('textfield[name=sum_final_index]').setValue(0);
775

    
776
				MinovaUtil.executeParamQuery({
777
					paramid: 'pms_index_score',
778
					sumfinal: sumcal,
779
					finalscore: fs
780
				}, function (s) {
781
					var data = Ext.decode(s.responseText).data;
782
					if (data.length === 0)
783
						return;
784
					var sindex = data[0].sindex;
785
					var findex = data[0].findex;
786
					Body.down('textfield[name=sum_calculated_index]').setValue(sindex);
787
					Body.down('textfield[name=sum_final_index]').setValue(0);
788

    
789
				});
790

    
791
			},
792
			calculateQUAL: function () {
793

    
794
				var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
795

    
796
				console.log("CALCULATEST");
797
				MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textarea[name=kom_appraiser]')[0].setReadOnly(false);
798
				MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textarea[name=kom_usulan]')[0].setReadOnly(false);
799
				MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textarea[name=kom_ind_dev_plan]')[0].setReadOnly(false);
800
				MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textarea[name=kom_nha]')[0].setReadOnly(true);
801
				console.log("CALCULATEND");
802

    
803
				var period = '4';
804
				var qualData = '';
805
				var aprVal = '';
806
				var aprWeight = '';
807
				var qualTarget = '';
808
				var qualWeight = '';
809
				var aprNumber = '';
810
				var pmsType = 'P';
811

    
812
				var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
813
				if (bizproc.substring(0, 9) === 'PMS_FINAL') {
814
					pmsType = 'F';
815
				}
816

    
817
				period = MinovaUtil.WORKFLOW.getViewBodyWorkflow().up().up().query('datefield[name=h_appr_date]')[0].getValue();
818
				period = period.substring(4, 2);
819

    
820
				Body.down('grid[name=Appraiser]').getStore().sort({
821
					property: 'apr_appraiser_no',
822
					direction: 'ASC'
823
				});
824

    
825
				var countApr = Body.down('grid[name=Appraiser]').getStore().count();
826
				var i = 1;
827

    
828
				Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
829
					var apr_no = rec.data.apr_appraiser_no;
830
					var apr_nocode = apr_no.substring(10);
831
					var apr_weight_qual = rec.data.apr_weight_qual;
832
					//            console.log(apr_no + ' ' + apr_nocode);
833

    
834
					aprNumber = aprNumber + apr_nocode;
835
					aprWeight = aprWeight + apr_weight_qual;
836
					if (i < countApr) {
837
						aprNumber = aprNumber + '|';
838
						aprWeight = aprWeight + '|';
839
						//                console.log(aprNumber);
840
					}
841
					i = i + 1;
842
				});
843

    
844
				var me = this;
845
				var countQUAL = Body.down('grid[name=QUAL]').getStore().count();
846
				i = 1;
847
				Body.down('grid[name=QUAL]').getStore().each(function (rec) {
848
					var id = rec.data.qual_qual_id;
849
					var tar = rec.data.qual_target;
850
					var wei = rec.data.qual_weight;
851
					var val = rec.data.qual_weight;
852
					var apr1_val = rec.data.qual_app1_value;
853
					var apr2_val = rec.data.qual_app2_value;
854
					var apr3_val = rec.data.qual_app3_value;
855
					var apr4_val = rec.data.qual_app4_value;
856
					var apr5_val = rec.data.qual_app5_value;
857

    
858
					var j = 1;
859
					Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
860
						var apr_no = rec.data.apr_appraiser_no;
861
						var apr_nocode = apr_no.substring(10);
862

    
863
						switch (apr_nocode) {
864
						case '1':
865
							aprVal = aprVal + apr1_val;
866
							break;
867
						case '2':
868
							aprVal = aprVal + apr2_val;
869
							break;
870
						case '3':
871
							aprVal = aprVal + apr3_val;
872
							break;
873
						case '4':
874
							aprVal = aprVal + apr4_val;
875
							break;
876
						case '5':
877
							aprVal = aprVal + apr5_val;
878
							break;
879
						default:
880
							break;
881
						}
882

    
883
						if (j < countApr) {
884
							aprVal = aprVal + '|';
885
						}
886
						j = j + 1;
887

    
888
					});
889

    
890
					qualData = qualData + id;
891
					qualTarget = qualTarget + '0';
892
					qualWeight = qualWeight + wei;
893

    
894
					if (i < countQUAL) {
895
						qualData = qualData + '|';
896
						qualTarget = qualTarget + '|';
897
						qualWeight = qualWeight + '|';
898
						aprVal = aprVal + ';';
899
						//                console.log(qualWeight);
900
					}
901
					i = i + 1;
902
				});
903

    
904
				var _grid = Body.query('gridpanel[name=QUAL]')[0];
905
				var _models = _grid.getStore().getRange();
906
				var count = _grid.store.data.length;
907
				var j = 0;
908
				var qual_self_value = 0;
909
				var sum_sw = 0;
910
				var param_grupid = '';
911
				var param_sw = '';
912
				while (j < count) {
913
					var a = parseFloat(_models[j].get('qual_app1_score'));
914
					var grupid = _models[j].get('qual_qual_group');
915
					if (isNaN(a))
916
						a = 0;
917
					var qual_weight = parseFloat(_models[j].get('qual_weight'));
918
					var qual_proficiency = parseFloat(_models[j].get('qual_proficiency'));
919
					/* taken out by mae 20190426 CR */
920
					//var fs = a/qual_proficiency ;
921
					/* taken out by mae 20190426 CR */
922
					var fs = a;
923

    
924
					if (isNaN(fs))
925
						fs = 0;
926
					var sw = fs * qual_weight;
927
					param_grupid += grupid + '|';
928
					param_sw += sw + '|';
929
					sum_sw += sw;
930
					_models[j].set('qual_final_score', fs);
931
					_models[j].set('qual_qual_score_weighted', sw);
932
					//var b = parseFloat(_models[j].get('qual_final_score'));
933
					var b = parseFloat(_models[j].get('qual_qual_score_weighted'));
934
					qual_self_value += b;
935
					j = j + 1;
936
				}
937
				MinovaUtil.executeParamQuery({
938
					paramid: 'pms_qual_final_score',
939
					param_grupid: param_grupid,
940
					param_sw: param_sw
941
				}, function (s) {
942
					var data = Ext.decode(s.responseText);
943
					if (data.data.length != 0) {
944
						Body.query('textfield[name=qual_total_final]')[0].setValue(data.data[0].final_scor);
945
						Body.down('textfield[name=sum_calculated_competency]').setValue(data.data[0].final_scor);
946
					}
947
				});
948
				//viewNya.query('textfield[name=qual_total_weight]')[0].setValue(qual_weight);
949
				Body.query('textfield[name=qual_total_score]')[0].setValue(qual_self_value);
950
				//Body.query('textfield[name=qual_total_score]')[0].setValue('90');
951
				var final = sum_sw / Body.query('textfield[name=qual_total_weight]')[0].getValue();
952

    
953
				var tot_weight = Body.query('textfield[name=qual_total_weight]')[0].getValue();
954
				var tot_score = Body.query('textfield[name=qual_total_score]')[0].getValue();
955

    
956
				Body.query('textfield[name=qual_total_final]')[0].setValue(tot_score / tot_weight);
957
				//Body.query('textfield[name=qual_total_final]')[0].setValue('98');
958
				var compwght = parseFloat(Body.down('textfield[name=sum_comp_weight]').getValue());
959
				var finsc = Body.query('textfield[name=qual_total_final]')[0].getValue();
960
				Body.query('textfield[name=sum_calculated_competency]')[0].setValue(finsc * compwght);
961
				//Body.query('textfield[name=sum_calculated_competency]')[0].setValue('99');
962

    
963
				//Body.query('textfield[name=qual_total_final]')[0].setValue(final.toFixed(2));
964
				me.calculateFS();
965
				//MinovaUtil.executeParamQuery({
966
				//    paramid: 'pms_qual_calculate',
967
				//    pmsType: pmsType,
968
				//    period: period,
969
				//    qualData: qualData,
970
				//    aprVal: aprVal,
971
				//   aprWeight: aprWeight,
972
				//    qualTarget: qualTarget,
973
				//    qualWeight: qualWeight,
974
				//    aprNumber: aprNumber
975
				//}, function(s) {
976
				//    var result = Ext.decode(s.responseText).data;
977
				//    var _view = MinovaUtil.WORKFLOW.getViewWorkflow();
978

    
979
				//    var setorQUAL = Body.down('grid[name=QUAL]').store;
980

    
981
				//    Ext.each(result, function(d) {
982
				//        // search and update record
983
				//        var idx = setorQUAL.findExact('qual_qual_id', d.id);
984

    
985
				//        if (idx >= 0 && d.name_field !== 'app1_value' && d.name_field !== 'app2_value' && d.name_field !== 'app3_value' && d.name_field !== 'app4_value' && d.name_field !== 'app5_value') {
986
				//           setorQUAL.getAt(idx).set("qual_" + d.name_field, d.val);
987
				//        }
988
				//        //setorQUAL.getAt(idx).set("qual_" + d.name_field, d.val);
989
				//    });
990

    
991
				//    me.calculateFS();
992
				//}, function(f) {});
993

    
994
			},
995
			calculateAll: function () {
996
				var me = this;
997
				me.calculateKPI();
998
				me.calculateQUAL();
999

    
1000
			},
1001
			calculateKPI: function () {
1002
				//alert('AAAA');
1003

    
1004
				var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1005

    
1006
				var period = '4';
1007
				var kpiData = '';
1008
				var kpiSeq = '';
1009
				var aprVal = '';
1010
				var aprWeight = '';
1011
				var kpiTarget = '';
1012
				var kpiWeight = '';
1013
				var aprNumber = '';
1014
				var pmsType = 'P';
1015

    
1016
				var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1017
				if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1018
					pmsType = 'F';
1019
				}
1020

    
1021
				period = MinovaUtil.WORKFLOW.getViewBodyWorkflow().up().up().query('datefield[name=h_appr_date]')[0].getValue();
1022
				period = period.substring(4, 2);
1023

    
1024
				// DECLARE @pmsType AS VARCHAR(1) = 'P'
1025
				// DECLARE @period AS VARCHAR(8) = '4'
1026
				// DECLARE @kpiData AS VARCHAR(100) =
1027
				// '00000001|00000007|00000009|00000011' kpi_kpi_id
1028

    
1029
				// DECLARE @aprVal AS VARCHAR(MAX)
1030
				// SET @aprVal = '8|7|6;7|6|5;9|8|10;4|3|2' kpi_app1_value
1031
				// --SET @aprVal = '6;5;10;2'
1032
				// DECLARE @aprWeight AS VARCHAR(100) = '40|30|30' apr_weight_kpi
1033
				// DECLARE @kpiTarget AS VARCHAR(MAX) = '20|8|12|5' kpi_target
1034
				// DECLARE @kpiWeight AS VARCHAR(100) = '30|20|40|10' kpi_weight
1035
				// DECLARE @aprNumber AS VARCHAR(100) = '1|2|4'
1036

    
1037
				Body.down('grid[name=Appraiser]').getStore().sort({
1038
					property: 'apr_appraiser_no',
1039
					direction: 'ASC'
1040
				});
1041

    
1042
				var countApr = Body.down('grid[name=Appraiser]').getStore().count();
1043
				var i = 1;
1044

    
1045
				Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
1046
					var apr_no = rec.data.apr_appraiser_no;
1047
					var apr_nocode = apr_no.substring(10);
1048
					var apr_weight_kpi = rec.data.apr_weight_kpi;
1049
					//            console.log(apr_no + ' ' + apr_nocode);
1050

    
1051
					aprNumber = aprNumber + apr_nocode;
1052
					aprWeight = aprWeight + apr_weight_kpi;
1053
					if (i < countApr) {
1054
						aprNumber = aprNumber + '|';
1055
						aprWeight = aprWeight + '|';
1056
						//                console.log(aprNumber);
1057
					}
1058
					i = i + 1;
1059
				});
1060

    
1061
				var me = this;
1062
				var countKPI = Body.down('grid[name=KPI]').getStore().count();
1063
				i = 1;
1064
				Body.down('grid[name=KPI]').getStore().each(function (rec) {
1065
					var id = rec.data.kpi_kpi_id;
1066
					var tar = rec.data.kpi_target;
1067
					var wei = rec.data.kpi_weight;
1068
					var val = rec.data.kpi_weight;
1069
					var apr1_val = rec.data.kpi_app1_value;
1070
					var apr2_val = rec.data.kpi_app2_value;
1071
					var apr3_val = rec.data.kpi_app3_value;
1072
					var apr4_val = rec.data.kpi_app4_value;
1073
					var apr5_val = rec.data.kpi_app5_value;
1074
					var seq = rec.data.kpi_seq;
1075

    
1076
					var j = 1;
1077
					Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
1078
						var apr_no = rec.data.apr_appraiser_no;
1079
						var apr_nocode = apr_no.substring(10);
1080

    
1081
						switch (apr_nocode) {
1082
						case '1':
1083
							aprVal = aprVal + apr1_val;
1084
							break;
1085
						case '2':
1086
							aprVal = aprVal + apr2_val;
1087
							break;
1088
						case '3':
1089
							aprVal = aprVal + apr3_val;
1090
							break;
1091
						case '4':
1092
							aprVal = aprVal + apr4_val;
1093
							break;
1094
						case '5':
1095
							aprVal = aprVal + apr5_val;
1096
							break;
1097
						default:
1098
							break;
1099
						}
1100

    
1101
						if (j < countApr) {
1102
							aprVal = aprVal + '|';
1103
						}
1104
						j = j + 1;
1105

    
1106
					});
1107

    
1108
					kpiData = kpiData + id;
1109
					kpiTarget = kpiTarget + tar;
1110
					kpiWeight = kpiWeight + wei;
1111
					kpiSeq = kpiSeq + seq;
1112

    
1113
					if (i < countKPI) {
1114
						kpiData = kpiData + '|';
1115
						kpiTarget = kpiTarget + '|';
1116
						kpiWeight = kpiWeight + '|';
1117
						kpiSeq = kpiSeq + '|';
1118
						aprVal = aprVal + ';';
1119
						//                console.log(kpiWeight);
1120
					}
1121
					i = i + 1;
1122
				});
1123

    
1124
				MinovaUtil.executeParamQuery({
1125
					paramid: 'pms_kpi_calculate',
1126
					pmsType: pmsType,
1127
					period: period,
1128
					kpiData: kpiData,
1129
					aprVal: aprVal,
1130
					aprWeight: aprWeight,
1131
					kpiTarget: kpiTarget,
1132
					kpiWeight: kpiWeight,
1133
					aprNumber: aprNumber,
1134
					kpiSeq: kpiSeq
1135
				}, function (s) {
1136
					var result = Ext.decode(s.responseText).data;
1137
					var _view = MinovaUtil.WORKFLOW.getViewWorkflow();
1138

    
1139
					var setorKPI = Body.down('grid[name=KPI]').store;
1140

    
1141
					Ext.each(result, function (d) {
1142
						// search and update record
1143
						//var idx = setorKPI.findExact('kpi_kpi_id', d.id);
1144
						var idx = setorKPI.findExact('kpi_seq', parseInt(d.id));
1145

    
1146
						if (d.name_field !== 'app1_value' && d.name_field !== 'app2_value' && d.name_field !== 'app3_value' && d.name_field !== 'app4_value' && d.name_field !== 'app5_value') {
1147
							setorKPI.getAt(idx).set("kpi_" + d.name_field, d.val);
1148
						}
1149
					});
1150

    
1151
					me.calculateFS();
1152
				}, function (f) {});
1153
			},
1154
			cekTaskIDrun: function () {
1155
				var me = this;
1156
				var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1157
				var loginEmpID = MinovaUtil.SESSIONS.LOGIN.empId;
1158

    
1159
				var taskId = MinovaUtil.WORKFLOW.getTaskId();
1160
				var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1161

    
1162
				Body.down('grid[name=SubKPI]').hide();
1163
				Body.down('grid[name=SubKPI_Total]').hide();
1164
				Body.down('grid[name=KPI]').hide();
1165
				Body.down('[name=TOTAL_KPI]').hide();
1166
				Body.down('grid[name=TALENT]').hide();
1167

    
1168
				MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=add]').setDisabled(true);
1169
				MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=copy]').setDisabled(true);
1170
				MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=remove]').setDisabled(true);
1171
				Body.down('grid[name=Appraiser]').columns.forEach(function (i) {
1172
					if (i.getEditor() !== undefined)
1173
						i.getEditor().setReadOnly(true);
1174
				});
1175

    
1176
				if (taskId === 'start' || taskId === '') {
1177
					me.loadHeader();
1178
					//me.loadPeriod();
1179

    
1180
					Body.down('[name=SUM]').hide();
1181
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=KPI]').down('button[name=calculate]').hide(true);
1182
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=QUAL]').down('button[name=calculate]').hide(true);
1183
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=SubKPI]').down('button[name=calculate]').hide(true);
1184

    
1185
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=KPI]').down('button[name=add]').setDisabled(false);
1186
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=KPI]').down('button[name=copy]').setDisabled(false);
1187
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=KPI]').down('button[name=remove]').setDisabled(false);
1188
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=SubKPI]').down('button[name=add]').setDisabled(false);
1189
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=SubKPI]').down('button[name=copy]').setDisabled(false);
1190
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=SubKPI]').down('button[name=remove]').setDisabled(false);
1191
					//MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=add]').setDisabled(false);
1192
					//MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=copy]').setDisabled(false);
1193
					//MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=remove]').setDisabled(false);
1194

    
1195
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_kpi_id]').getEditor().setReadOnly(true);
1196
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_weight]').getEditor().setReadOnly(true);
1197
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_target]').getEditor().setReadOnly(true);
1198
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_description]').getEditor().setReadOnly(false);
1199
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_unit]').getEditor().setReadOnly(false);
1200
					//Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_kpi_id]').getEditor().setReadOnly(false);
1201
					//Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_sub_kpi]').getEditor().setReadOnly(false);
1202
					//Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_description]').getEditor().setReadOnly(false);
1203
					//Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_weight]').getEditor().setReadOnly(false);
1204
					//Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_target]').getEditor().setReadOnly(false);
1205
					//Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_unit]').getEditor().setReadOnly(false);
1206
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_app1_score]').getEditor().setReadOnly(true);
1207

    
1208
					//Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_id]').setWidth(400);
1209
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_weight]').getEditor().setReadOnly(true);
1210
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_proficiency]').getEditor().setReadOnly(true);
1211
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_emp_id]').getEditor().setReadOnly(true);
1212
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_group]').getEditor().setReadOnly(true);
1213
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_id]').getEditor().setReadOnly(true);
1214

    
1215
					Body.down('button[name=cal_adjusted]').setDisabled(true);
1216

    
1217
					var pmsType = 'P';
1218
					var pmsTypeDesc = 'Performance Review';
1219
					var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1220
					if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1221
						pmsType = 'F';
1222
						pmsTypeDesc = 'Final Appraisal';
1223
					}
1224

    
1225
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().up().up().query('textfield[name=h_appr_type]')[0].setValue(pmsType);
1226
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().up().up().query('textfield[name=h_appr_type_desc]')[0].setValue(pmsTypeDesc);
1227

    
1228
					Body.down('form[name=KOMENTAR]').setVisible(false);
1229

    
1230
					me.loadKPI_QUAL_weight();
1231

    
1232
				} else if (taskId === "apv_appraiser_many" || taskId == "apv_appraiser" || taskId === "result_appraiser1" || taskId == "revise_created_appraiser") {
1233

    
1234
					Body.down('form[name=KOMENTAR]').setVisible(true);
1235

    
1236
					MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
1237
					//var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1238

    
1239
					//Body.down('grid[name=Appraiser]').columns.forEach(function(i) {
1240
					//    if (i.getEditor() !== undefined) i.getEditor().setReadOnly(true);
1241
					//});
1242

    
1243
					Body.down('grid[name=KPI]').columns.forEach(function (i) {
1244
						if (i.getEditor() !== undefined)
1245
							i.getEditor().setReadOnly(true);
1246
						// i.show()
1247
					});
1248

    
1249
					Body.down('grid[name=SubKPI]').columns.forEach(function (i) {
1250
						if (i.getEditor() !== undefined)
1251
							i.getEditor().setReadOnly(true);
1252
						// i.show()
1253
					});
1254

    
1255
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_final_score]').show();
1256
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_kpi_score_weighted]').show();
1257
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_remark]').show();
1258
					Body.down('grid[name=KPI]').down('button[name=calculate]').setDisabled(false);
1259

    
1260
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_final_score]').show();
1261
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_score_weighted]').show();
1262
					Body.down('grid[name=QUAL]').down('button[name=calculate]').setDisabled(false);
1263
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_app1_score]').getEditor().setReadOnly(false);
1264

    
1265
					//Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_id]').setWidth(400);
1266

    
1267
					Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_final_score]').show();
1268
					//Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_subkpi_score_weighted]').show();
1269
					Body.down('grid[name=SubKPI]').down('button[name=calculate]').setDisabled(false);
1270

    
1271
					//            Body.down('button[name=cal_adjusted]').setDisabled(true);
1272
					//            Body.down('textfield[name=sum_final_kpi]').setDisabled(true);
1273
					//            Body.down('textfield[name=sum_final_competency]').setDisabled(true);
1274

    
1275
					Body.query('textarea[name=kom_appraiser]')[0].setReadOnly(false);
1276
					Body.query('textarea[name=kom_usulan]')[0].setReadOnly(false);
1277
					Body.query('textarea[name=kom_ind_dev_plan]')[0].setReadOnly(false);
1278

    
1279
					//            if (taskId === "apv_appraiser" || taskId === "result_appraiser1") {
1280
					//                Body.down('button[name=cal_adjusted]').setDisabled(false);
1281
					//                Body.down('textfield[name=sum_final_kpi]').setReadOnly(false);
1282
					//                Body.down('textfield[name=sum_final_competency]').setReadOnly(false);
1283
					//
1284
					//            }
1285

    
1286
					Body.down('grid[name=Appraiser]').getStore().each(
1287

    
1288
						function (rec) {
1289
						//                    console.log(rec.data.apr_appraiser_id);
1290
						var apr_no = rec.data.apr_appraiser_no;
1291
						var apr_id = rec.data.apr_appraiser_id;
1292
						var apr_nocode = "app" + apr_no.substring(10);
1293
						//                    console.log(apr_nocode);
1294

    
1295
						Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_value]').show();
1296
						//Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_projected]').show();
1297
						Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_percent]').show();
1298

    
1299
						//QUAL
1300
						Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_value]').show();
1301
						Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_percent]').show();
1302

    
1303
						//SUBKPI
1304
						Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_value]').show();
1305
						Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_percent]').show();
1306

    
1307
						if (apr_id === loginEmpID) {
1308
							Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_value]').getEditor().setReadOnly(false);
1309
							Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_value]').getEditor().setReadOnly(false);
1310
							Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_value]').getEditor().setReadOnly(false);
1311
						}
1312
					});
1313

    
1314
				} else if (taskId === "apv_nha" || taskId === "apv_nha_many") {
1315

    
1316
					MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
1317
					//Body.down('grid[name=Appraiser]').columns.forEach(function(i) {
1318
					//    if (i.getEditor() !== undefined) i.getEditor().setReadOnly(true);
1319
					//});
1320
					Body.query('textarea[name=kom_ind_dev_plan]')[0].setReadOnly(false);
1321

    
1322
					Body.query('textarea[name=kom_nha]')[0].setReadOnly(false);
1323
					Body.query('textarea[name=kom_usulan]')[0].setReadOnly(false);
1324
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_final_score]').show();
1325
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_score_weighted]').show();
1326
					Body.down('grid[name=QUAL]').down('button[name=calculate]').setDisabled(false);
1327

    
1328
					//Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_id]').setWidth(800);
1329

    
1330
					Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_final_score]').show();
1331
					//Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_subkpi_score_weighted]').show();
1332
					Body.down('grid[name=SubKPI]').down('button[name=calculate]').setDisabled(false);
1333

    
1334
					Body.down('grid[name=KPI]').columns.forEach(function (i) {
1335
						if (i.getEditor() !== undefined)
1336
							i.getEditor().setReadOnly(true);
1337
					});
1338

    
1339
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_final_score]').show();
1340
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_kpi_score_weighted]').show();
1341
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_remark]').show();
1342
					Body.down('grid[name=KPI]').down('button[name=calculate]').setDisabled(false);
1343

    
1344
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_app2_value]').show();
1345
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_app2_value]').getEditor().setReadOnly(false);
1346
					Body.down('grid[name=KPI]').down('[dataIndex=kpi_app2_percent]').show();
1347

    
1348
					Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_app2_value]').show();
1349
					Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_app2_value]').getEditor().setReadOnly(false);
1350
					Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_app2_percent]').show();
1351

    
1352
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_app2_value]').show();
1353
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_app2_value]').getEditor().setReadOnly(false);
1354
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_app2_percent]').show();
1355
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_app2_score]').show();
1356
					Body.down('grid[name=QUAL]').down('[dataIndex=qual_app2_score]').getEditor().setReadOnly(false);
1357

    
1358
					Body.down('grid[name=Appraiser]').getStore().each(
1359

    
1360
						function (rec) {
1361
						//                    console.log(rec.data.apr_appraiser_id);
1362
						var apr_no = rec.data.apr_appraiser_no;
1363
						var apr_id = rec.data.apr_appraiser_id;
1364
						var apr_nocode = "app" + apr_no.substring(10);
1365
						//                    console.log(apr_nocode);
1366

    
1367
						//KPI
1368
						Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_value]').show();
1369
						//Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_projected]').show();
1370
						Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_percent]').show();
1371

    
1372
						//QUAL
1373
						Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_value]').show();
1374
						Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_percent]').show();
1375

    
1376
						//SUBKPI
1377
						Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_value]').show();
1378
						Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_percent]').show();
1379

    
1380
					});
1381

    
1382
					Body.down('button[name=cal_adjusted]').setDisabled(false);
1383
					Body.down('textfield[name=sum_final_kpi]').setReadOnly(false);
1384
					Body.down('textfield[name=sum_final_competency]').setReadOnly(false);
1385

    
1386
				} else {
1387
					MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
1388
				}
1389

    
1390
				if (taskId == "apv_appraiser" || taskId == "revise_created_appraiser") {
1391
					console.log("PLAY " + taskId);
1392
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textarea[name=kom_appraiser]')[0].setReadOnly(false);
1393
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textarea[name=kom_usulan]')[0].setReadOnly(false);
1394
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textarea[name=kom_ind_dev_plan]')[0].setReadOnly(false);
1395
					MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textarea[name=kom_nha]')[0].setReadOnly(true);
1396
					console.log("END PLAY " + taskId);
1397
				}
1398

    
1399
			},
1400
			aprdate_check: function (_this, newVal, oldVal) {
1401
				var me = this;
1402
				var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1403
				var aprdate = newVal;
1404

    
1405
				var start_date = _this.up().up().query('datefield[name=h_start_date]')[0].getValue();
1406
				var end_date = _this.up().up().query('datefield[name=h_end_date]')[0].getValue();
1407
				var enddate_val = '';
1408

    
1409
				var pmsType = 'P';
1410

    
1411
				var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1412
				if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1413
					pmsType = 'F';
1414
				}
1415

    
1416
				if (pmsType === 'P') {
1417
					if (aprdate >= start_date && aprdate <= end_date) {}
1418
					else if (aprdate !== '') {
1419
						alert('Appraisal Date must be between 1 January ' + start_date.substring(0, 4) + ' and 31 December ' + start_date.substring(0, 4));
1420
						_this.up().up().query('datefield[name=h_appr_date]')[0].setValue('');
1421
					}
1422
				} else {
1423
					var x = parseInt(start_date.substring(0, 4)) + 1;
1424
					enddate_val = x.toString() + '0331';
1425
					if (aprdate >= start_date && aprdate <= enddate_val) {}
1426
					else if (aprdate !== '') {
1427
						alert('Appraisal Date must be between 1 January ' + start_date.substring(0, 4) + ' and 31 March ' + x);
1428
						_this.up().up().query('datefield[name=h_appr_date]')[0].setValue('');
1429
					}
1430
				}
1431
			},
1432
			changeEmpID: function () {
1433
				var me = this;
1434
				me.loadHeader();
1435
				//me.loadPeriod();
1436

    
1437
			},
1438
			loadPeriod: function () {
1439
				var mainSeq = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=main_seq]').getValue();
1440
				var empid = MinovaUtil.WORKFLOW.getEmpId();
1441

    
1442
				var me = this;
1443
				var pmsType = 'P';
1444
				var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1445
				if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1446
					pmsType = 'F';
1447
				}
1448

    
1449
				var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1450
				viewNya.down('combobox[name=h_period]').store.load({
1451
					params: {
1452
						paramid: 'pms_getcomboperiod_pf_direct',
1453
						emp_id: empid,
1454
						start_date: mainSeq,
1455
						aprType: pmsType,
1456
						regid: MinovaUtil.WORKFLOW.getRegId()
1457
					}
1458
				});
1459

    
1460
			},
1461
			now8: function () {
1462
				Ext.global.console.log('>>now8');
1463
				return Ext.Date.format(new Date(), 'Ymd');
1464
			},
1465
			periodChange: function (_this, newVal, oldVal) {
1466
				if (!MinovaUtil.WORKFLOW.isRequest())
1467
					return;
1468
				var me = this;
1469
				var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1470
				var taskId = newVal;
1471
				var emp_id = MinovaUtil.WORKFLOW.getEmpId();
1472

    
1473
				var idx = _this.store.findExact('code', newVal);
1474
				var rec = _this.store.getAt(idx);
1475
				if (!rec)
1476
					return;
1477
				var start_date = rec.data.start_date;
1478
				var end_date = rec.data.end_date;
1479
				var seq = rec.data.seq;
1480
				viewNya.down('textfield[name=h_emp_id]').setValue(emp_id);
1481
				viewNya.down('datefield[name=h_start_date]').setValue(start_date);
1482
				viewNya.down('datefield[name=h_end_date]').setValue(end_date);
1483
				viewNya.down('datefield[name=h_appr_date]').setValue('');
1484

    
1485
				// set seq
1486
				var pmsType = 'P';
1487

    
1488
				var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1489
				if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1490
					pmsType = 'F';
1491
				}
1492
				MinovaUtil.executeParamQuery({
1493
					paramid: 'pms_final_perform_seq',
1494
					emp_id: emp_id,
1495
					start_date: start_date,
1496
					pmsType: pmsType
1497
				}, function (s) {
1498
					var result = Ext.decode(s.responseText).data[0].seq
1499
						result = Ext.isEmpty(result) ? '1' : result;
1500
					viewNya.down('textfield[name=main_seq]').setValue(result);
1501
				}, function (f) {})
1502

    
1503
				var periodDesc = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=h_period]').getRawValue();
1504
				MinovaUtil.WORKFLOW.getViewHeaderWorkflow().query('textfield[name=subject]')[0].setValue('PMS ' + periodDesc);
1505

    
1506
				me.loadAppraiserKPI_def();
1507
				me.loadQual_def();
1508
				me.loadSubKPI_default(emp_id, start_date, end_date);
1509

    
1510
				me.updateGridHeaderSeq(_this, newVal, oldVal);
1511
			},
1512
			loadQual_def: function () {
1513
				var empid = MinovaUtil.WORKFLOW.getEmpId();
1514
				var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1515

    
1516
				var pmsType = 'P';
1517

    
1518
				var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1519
				if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1520
					pmsType = 'F';
1521
				}
1522

    
1523
				viewNya.query('gridpanel[name=QUAL]')[0].store.proxy.url = '/Workflow/LoadDataQuery';
1524
				viewNya.query('gridpanel[name=QUAL]')[0].store.proxy.reader.root = 'data';
1525
				viewNya.down('gridpanel[name=QUAL]').store.load({
1526
					params: {
1527
						paramid: 'pms_qual_default',
1528
						emp_id: empid
1529
					}
1530
				});
1531
				Ext.each(viewNya.down('gridpanel[name=QUAL]').store.getRange(), function (r) {
1532
					//r.set('qual_proficiency', '0');
1533
					r.set('qual_emp_id', empid);
1534
					r.set('qual_appraisal_type', pmsType);
1535
					r.set('qual_start_date', MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('datefield[name=h_start_date]')[0].getValue());
1536
					r.set('qual_end_date', MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('datefield[name=h_end_date]')[0].getValue());
1537
					r.set('qual_header_seq', MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textfield[name=main_seq]')[0].getValue());
1538
					r.set('qual_data_flag', 'C');
1539
					r.set('qual_self_value', '0');
1540
					r.set('qual_app1_value', '0');
1541
					r.set('qual_app2_value', '0');
1542
					r.set('qual_app3_value', '0');
1543
					r.set('qual_app4_value', '0');
1544
					r.set('qual_app5_value', '0');
1545
					r.set('qual_app6_value', '0');
1546
					r.set('qual_app7_value', '0');
1547
					r.set('qual_app8_value', '0');
1548
					r.set('qual_app9_value', '0');
1549
					r.set('qual_app10_value', '0');
1550
					r.set('qual_self_percent', '0');
1551
					r.set('qual_app1_percent', '0');
1552
					r.set('qual_app2_percent', '0');
1553
					r.set('qual_app3_percent', '0');
1554
					r.set('qual_app4_percent', '0');
1555
					r.set('qual_app5_percent', '0');
1556
					r.set('qual_app6_percent', '0');
1557
					r.set('qual_app7_percent', '0');
1558
					r.set('qual_app8_percent', '0');
1559
					r.set('qual_app9_percent', '0');
1560
					r.set('qual_app10_percent', '0');
1561
					r.set('qual_final_score', '0');
1562
					r.set('qual_qual_score_weighted', '0');
1563
					r.set('qual_remark', '');
1564

    
1565
					var _grid = viewNya.query('gridpanel[name=QUAL]')[0];
1566
					var _models = _grid.getStore().getRange();
1567
					var count = _grid.store.data.length;
1568
					var j = 0;
1569
					var qual_weight = 0;
1570
					var qual_self_value = 0;
1571
					while (j < count) {
1572
						qual_weight += parseFloat(_models[j].get('qual_weight'));
1573
						//qual_self_value += parseFloat(_models[j].get('qual_self_value'));
1574
						qual_self_value += parseFloat(_models[j].get('qual_qual_score_weighted'));
1575
						j = j + 1;
1576
					}
1577
					viewNya.query('textfield[name=qual_total_weight]')[0].setValue(qual_weight);
1578
					//viewNya.query('textfield[name=qual_total_score]')[0].setValue(qual_self_value);
1579
					//viewNya.query('textfield[name=qual_total_final]')[0].setValue(qual_self_value / count);
1580
				});
1581
			},
1582
			loadSubKPI_default: function (empId, sd, ed) {
1583
				var pmsType = 'P';
1584
				var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1585
				if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1586
					pmsType = 'F';
1587
				}
1588

    
1589
				this.getGridSubKPI().store.load({
1590
					params: {
1591
						paramid: 'pms_getsubkpi_G',
1592
						emp_id: empId,
1593
						start_date: sd,
1594
						end_date: ed,
1595
						aprType: pmsType
1596
						/*,
1597
						header_seq: MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textfield[name=main_seq]')[0].getValue()*/
1598
					}
1599
				});
1600

    
1601
			},
1602
			loadHeader: function () {
1603
				var empid = MinovaUtil.WORKFLOW.getEmpId();
1604
				var me = this;
1605

    
1606
				MinovaUtil.executeParamQuery({
1607
					paramid: 'pms_get_headerdet',
1608
					emp_id: empid,
1609
					skarang: me.now8()
1610
				}, function (s) {
1611
					var result = Ext.decode(s.responseText);
1612
					var _view = MinovaUtil.WORKFLOW.getViewWorkflow();
1613

    
1614
					_view.query('form[name=MainForm]')[0].getForm().setValues({
1615
						main_emp_type: result.data[0].employee_type_desc,
1616
						main_emp_position: result.data[0].position_desc,
1617
						main_emp_job: result.data[0].job_desc,
1618
						main_emp_organization: result.data[0].organization_desc
1619
					});
1620
				}, function (f) {});
1621
			},
1622
			loadAppraiserKPI_def: function () {
1623
				var empid = MinovaUtil.WORKFLOW.getEmpId();
1624
				var me = this;
1625
				var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1626
				var start_date = viewNya.query('datefield[name=h_start_date]')[0].getValue();
1627
				var end_date = viewNya.query('datefield[name=h_end_date]')[0].getValue();
1628

    
1629
				var hp = viewNya.query('combobox[name=h_period]')[0];
1630
				var pcode = hp.getValue();
1631
				var idx = hp.store.findExact('code', pcode);
1632
				var rec = hp.store.getAt(idx);
1633
				var seq = rec.data.seq;
1634

    
1635
				var pmsType = 'P';
1636
				var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1637
				if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1638
					pmsType = 'F';
1639
				}
1640
				viewNya.query('gridpanel[name=Appraiser]')[0].store.proxy.url = '/Workflow/LoadDataQuery';
1641
				viewNya.query('gridpanel[name=Appraiser]')[0].store.proxy.reader.root = 'data';
1642
				viewNya.query('gridpanel[name=Appraiser]')[0].store.load({
1643
					params: {
1644
						//paramid: 'pms_getappraiser_G',
1645
						paramid: 'pms_getappraiser_pf_direct',
1646
						emp_id: empid,
1647
						startdate: start_date,
1648
						enddate: end_date,
1649
						seq: seq
1650
					}
1651
				});
1652

    
1653
				Ext.each(viewNya.query('gridpanel[name=Appraiser]')[0].store.getRange(), function (r) {
1654
					r.set('apr_appraisal_type', pmsType);
1655
					//r.set('apr_header_seq', '1');
1656
					r.set('apr_data_flag', 'C');
1657
				});
1658
				var _grid = viewNya.query('gridpanel[name=Appraiser]')[0];
1659
				var _models = _grid.getStore().getRange();
1660
				var j = 0;
1661
				var apr_weight_kpi = 0;
1662
				var apr_weight_qual = 0;
1663
				while (j < _grid.store.data.length) {
1664
					apr_weight_kpi += parseInt(_models[j].get('apr_weight_kpi'));
1665
					apr_weight_qual += parseInt(_models[j].get('apr_weight_qual'));
1666
					j = j + 1;
1667
				}
1668
				viewNya.query('textfield[name=appraiser_total_wkpi]')[0].setValue(apr_weight_kpi);
1669
				viewNya.query('textfield[name=appraiser_total_wqual]')[0].setValue(apr_weight_qual);
1670

    
1671
				viewNya.query('gridpanel[name=KPI]')[0].store.proxy.url = '/Workflow/LoadDataQuery';
1672
				viewNya.query('gridpanel[name=KPI]')[0].store.proxy.reader.root = 'data';
1673
				viewNya.query('gridpanel[name=KPI]')[0].store.load({
1674
					params: {
1675
						//paramid: 'pms_getkpi_G',
1676
						paramid: 'pms_getkpi_pf_direct',
1677
						emp_id: empid,
1678
						start_date: start_date,
1679
						end_date: end_date,
1680
						seq: seq,
1681
						aprType: pmsType
1682
					}
1683
				});
1684
				Ext.each(viewNya.query('gridpanel[name=KPI]')[0].store.getRange(), function (r) {
1685
					r.set('kpi_data_flag', 'C');
1686
					r.set('kpi_self_value', '0');
1687
					r.set('kpi_app1_value', '0');
1688
					r.set('kpi_app2_value', '0');
1689
					r.set('kpi_app3_value', '0');
1690
					r.set('kpi_app4_value', '0');
1691
					r.set('kpi_app5_value', '0');
1692
					r.set('kpi_app6_value', 0);
1693
					r.set('kpi_app7_value', 0);
1694
					r.set('kpi_app8_value', 0);
1695
					r.set('kpi_app9_value', 0);
1696
					r.set('kpi_app10_value', 0);
1697
					r.set('kpi_self_projected', 0);
1698
					r.set('kpi_app1_projected', 0);
1699
					r.set('kpi_app2_projected', 0);
1700
					r.set('kpi_app3_projected', 0);
1701
					r.set('kpi_app4_projected', 0);
1702
					r.set('kpi_app5_projected', 0);
1703
					r.set('kpi_app6_projected', 0);
1704
					r.set('kpi_app7_projected', 0);
1705
					r.set('kpi_app8_projected', 0);
1706
					r.set('kpi_app9_projected', 0);
1707
					r.set('kpi_app10_projected', 0);
1708
					r.set('kpi_self_percent', 0);
1709
					r.set('kpi_app1_percent', 0);
1710
					r.set('kpi_app2_percent', 0);
1711
					r.set('kpi_app3_percent', 0);
1712
					r.set('kpi_app4_percent', 0);
1713
					r.set('kpi_app5_percent', 0);
1714
					r.set('kpi_app6_percent', 0);
1715
					r.set('kpi_app7_percent', 0);
1716
					r.set('kpi_app8_percent', 0);
1717
					r.set('kpi_app9_percent', 0);
1718
					r.set('kpi_app10_percent', 0);
1719
					r.set('kpi_final_score', 0);
1720
					r.set('kpi_kpi_score_weighted', 0);
1721
					var grid = viewNya.query('gridpanel[name=KPI]')[0];
1722
					var models = grid.getStore().getRange();
1723
					var i = 0;
1724
					var tot_weight = 0;
1725
					var tot_score = 0;
1726
					while (i < grid.store.data.length) {
1727
						tot_weight += parseInt(models[i].get('kpi_weight'));
1728
						tot_score += parseInt(models[i].get('kpi_self_value'));
1729
						i = i + 1;
1730
					}
1731
					viewNya.query('textfield[name=kpi_total_weight]')[0].setValue(tot_weight);
1732
					viewNya.query('textfield[name=kpi_total_score]')[0].setValue(tot_score);
1733
				});
1734
			},
1735
			updateGridHeaderSeq: function (obj, newVal, oldVal) {
1736
				var mainSeq = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=main_seq]').getValue();
1737
				var x = obj.store.findExact('code', newVal),
1738
				rec = obj.store.getAt(x);
1739
				if (Ext.isEmpty(rec))
1740
					return;
1741

    
1742
				var sd = rec.data.start_date,
1743
				ed = rec.data.end_date;
1744

    
1745
				Ext.each(this.getGridARP().store.getRange(), function (r) {
1746
					r.set('apr_header_seq', mainSeq);
1747
					r.set('apr_start_date', sd);
1748
					r.set('apr_end_date', ed);
1749
				});
1750
				Ext.each(this.getGridKPI().store.getRange(), function (r) {
1751
					r.set('kpi_header_seq', mainSeq);
1752
					r.set('kpi_start_date', sd);
1753
					r.set('kpi_end_date', ed);
1754
				});
1755
				Ext.each(this.getGridSubKPI().store.getRange(), function (r) {
1756
					r.set('subkpi_header_seq', mainSeq);
1757
					r.set('subkpi_sub_kpi_start', sd);
1758
					r.set('subkpi_start_date', sd);
1759
					r.set('subkpi_sub_kpi_end', ed);
1760
					r.set('subkpi_end_date', ed);
1761
				});
1762
				Ext.each(this.getGridQual().store.getRange(), function (r) {
1763
					r.set('qual_header_seq', mainSeq);
1764
					r.set('qual_start_date', sd);
1765
					r.set('qual_end_date', ed);
1766
				});
1767

    
1768
			},
1769

    
1770
			loadKPI_QUAL_weight: function () {
1771
				var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1772
				Body.down('textfield[name=sum_calculated_kpi]').setValue(0);
1773
				Body.down('textfield[name=sum_calculated_competency]').setValue(0);
1774
				Body.down('textfield[name=sum_calculated_score]').setValue(0);
1775
				Body.down('textfield[name=sum_calculated_index]').setValue(0);
1776
				Body.down('textfield[name=sum_final_kpi]').setValue(0);
1777
				Body.down('textfield[name=sum_final_competency]').setValue(0);
1778
				Body.down('textfield[name=sum_final_score]').setValue(0);
1779
				Body.down('textfield[name=sum_final_index]').setValue(0);
1780

    
1781
				MinovaUtil.executeParamQuery({
1782
					paramid: 'pms_kpi_qual_weight'
1783
				}, function (s) {
1784
					var data = Ext.decode(s.responseText).data;
1785
					var qual_weight = data[0].qual_weight;
1786
					var kpi_weight = data[0].kpi_weight;
1787
					Body.down('textfield[name=sum_kpi_weight]').setValue(kpi_weight);
1788
					Body.down('textfield[name=sum_comp_weight]').setValue(qual_weight);
1789

    
1790
				});
1791

    
1792
			},
1793
			calculateSubKPI: function () {
1794
				//alert('AAAA');
1795

    
1796
				var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1797

    
1798
				var period = '4';
1799
				var kpiData = '';
1800
				var aprVal = '';
1801
				var aprWeight = '';
1802
				var subKpiData = '';
1803
				var subKpiTarget = '';
1804
				var subKpiWeight = '';
1805

    
1806
				var aprNumber = '';
1807
				var pmsType = 'P';
1808

    
1809
				var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1810
				if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1811
					pmsType = 'F';
1812
				}
1813

    
1814
				period = MinovaUtil.WORKFLOW.getViewBodyWorkflow().up().up().query('datefield[name=h_appr_date]')[0].getValue();
1815
				period = period.substring(4, 2);
1816

    
1817
				//        DECLARE @pmsType AS VARCHAR(1) = 'P'
1818
				//        DECLARE @period AS VARCHAR(8) = '4'
1819
				//        DECLARE @kpiData AS VARCHAR(100) = '00000001|00000001|00000003|00000003|00000002' --darisubkpi
1820
				//
1821
				//        DECLARE @aprVal AS VARCHAR(MAX)
1822
				//    	SET @aprVal = '4|3|3.8|4|5;5|4|2|3.2|4'
1823
				//		DECLARE @aprWeight AS VARCHAR(100) = '40|60'
1824

    
1825
				//		DECLARE @aprNumber AS VARCHAR(100) = '1|3'
1826

    
1827
				//		//DECLARE @subKpiData AS VARCHAR(MAX) = '1|2|3|4|5'
1828
				//		DECLARE @subKpiWeight AS VARCHAR(MAX) = '40|60|50|50|100'
1829
				//		DECLARE @subKpiTarget AS VARCHAR(MAX) = '5|5|5|5|5'
1830

    
1831
				Body.down('grid[name=Appraiser]').getStore().sort({
1832
					property: 'apr_appraiser_no',
1833
					direction: 'ASC'
1834
				});
1835

    
1836
				var countApr = Body.down('grid[name=Appraiser]').getStore().count();
1837
				var i = 1;
1838

    
1839
				Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
1840
					var apr_no = rec.data.apr_appraiser_no;
1841
					var apr_nocode = apr_no.substring(10);
1842
					var apr_weight_kpi = rec.data.apr_weight_kpi;
1843
					//            console.log(apr_no + ' ' + apr_nocode);
1844

    
1845
					aprNumber = aprNumber + apr_nocode;
1846
					aprWeight = aprWeight + apr_weight_kpi;
1847
					if (i < countApr) {
1848
						aprNumber = aprNumber + '|';
1849
						aprWeight = aprWeight + '|';
1850
						//                console.log(aprNumber);
1851
					}
1852
					i = i + 1;
1853
				});
1854

    
1855
				var me = this;
1856
				var countSubKPI = Body.down('grid[name=SubKPI]').getStore().count();
1857
				i = 1;
1858
				Body.down('grid[name=SubKPI]').getStore().each(function (rec) {
1859
					var sid = rec.data.subkpi_seq;
1860
					var kid = rec.data.subkpi_kpi_id;
1861
					var tar = rec.data.subkpi_target;
1862
					var wei = rec.data.subkpi_weight;
1863
					var val = rec.data.subkpi_weight;
1864
					var apr1_val = rec.data.subkpi_app1_value;
1865
					var apr2_val = rec.data.subkpi_app2_value;
1866
					var apr3_val = rec.data.subkpi_app3_value;
1867
					var apr4_val = rec.data.subkpi_app4_value;
1868
					var apr5_val = rec.data.subkpi_app5_value;
1869

    
1870
					var j = 1;
1871
					Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
1872
						var apr_no = rec.data.apr_appraiser_no;
1873
						var apr_nocode = apr_no.substring(10);
1874

    
1875
						switch (apr_nocode) {
1876
						case '1':
1877
							aprVal = aprVal + apr1_val;
1878
							break;
1879
						case '2':
1880
							aprVal = aprVal + apr2_val;
1881
							break;
1882
						case '3':
1883
							aprVal = aprVal + apr3_val;
1884
							break;
1885
						case '4':
1886
							aprVal = aprVal + apr4_val;
1887
							break;
1888
						case '5':
1889
							aprVal = aprVal + apr5_val;
1890
							break;
1891
						default:
1892
							break;
1893
						}
1894

    
1895
						if (j < countApr) {
1896
							aprVal = aprVal + '|';
1897
						}
1898
						j = j + 1;
1899

    
1900
					});
1901

    
1902
					kpiData = kpiData + kid;
1903
					subKpiData = subKpiData + sid;
1904
					subKpiTarget = subKpiTarget + tar;
1905
					subKpiWeight = subKpiWeight + wei;
1906

    
1907
					if (i < countSubKPI) {
1908
						kpiData = kpiData + '|';
1909
						subKpiData = subKpiData + '|';
1910
						subKpiTarget = subKpiTarget + '|';
1911
						subKpiWeight = subKpiWeight + '|';
1912
						aprVal = aprVal + ';';
1913
						//                console.log(subKpiWeight);
1914
					}
1915
					i = i + 1;
1916
				});
1917

    
1918
				MinovaUtil.executeParamQuery({
1919
					paramid: 'pms_subkpi_calculate',
1920
					pmsType: pmsType,
1921
					period: period,
1922
					kpiData: kpiData,
1923
					subKpiData: subKpiData,
1924
					aprVal: aprVal,
1925
					aprWeight: aprWeight,
1926
					aprNumber: aprNumber,
1927
					subKpiWeight: subKpiWeight,
1928
					subKpiTarget: subKpiTarget
1929

    
1930
				}, function (s) {
1931
					var result = Ext.decode(s.responseText).data;
1932
					if (result.length === 0)
1933
						return;
1934
					var _view = MinovaUtil.WORKFLOW.getViewWorkflow();
1935

    
1936
					var setorsubKPI = Body.down('grid[name=SubKPI]').store;
1937

    
1938
					Ext.each(result, function (d) {
1939
						// search and update record
1940
						var idx = setorsubKPI.findExact('subkpi_seq', parseInt(d.id));
1941
						if (idx >= 0 && d.name_field !== 'app1_value' && d.name_field !== 'app2_value' && d.name_field !== 'app3_value' && d.name_field !== 'app4_value' && d.name_field !== 'app5_value') {
1942
							setorsubKPI.getAt(idx).set("subkpi_" + d.name_field, d.val);
1943
						}
1944
					});
1945

    
1946
					me.calculateSubKPI_appraiser();
1947
				}, function (f) {});
1948
			},
1949
			calculateSubKPI_main: function () {
1950
				var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1951

    
1952
				var me = this;
1953
				var countSubKPI = Body.down('grid[name=SubKPI]').getStore().count();
1954

    
1955
				if (countSubKPI > 0) {
1956
					me.calculateSubKPI();
1957
					//me.calculateSubKPI_appraiser();
1958
				} else {
1959
					me.calculateKPI();
1960
				}
1961
			},
1962
			calculateSubKPI_appraiser: function () {
1963

    
1964
				var me = this;
1965
				var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1966
				var aprNumber = '';
1967
				var kid = '';
1968
				var sid = '';
1969
				var wei = '';
1970
				var val = '';
1971
				var subKPIData = '';
1972
				var apr = '';
1973

    
1974
				var countApr = Body.down('grid[name=Appraiser]').getStore().count();
1975
				var countSubKPI = Body.down('grid[name=SubKPI]').getStore().count();
1976
				var i = 1;
1977
				var j = 1;
1978

    
1979
				Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
1980
					var apr_no = rec.data.apr_appraiser_no;
1981
					var apr_nocode = apr_no.substring(10);
1982

    
1983
					j = 1;
1984

    
1985
					Body.down('grid[name=SubKPI]').getStore().each(function (rec) {
1986
						sid = rec.data.subkpi_seq;
1987
						kid = rec.data.subkpi_kpi_id;
1988
						wei = rec.data.subkpi_weight;
1989
						var apr1_val = rec.data.subkpi_app1_value;
1990
						var apr2_val = rec.data.subkpi_app2_value;
1991
						var apr3_val = rec.data.subkpi_app3_value;
1992
						var apr4_val = rec.data.subkpi_app4_value;
1993
						var apr5_val = rec.data.subkpi_app5_value;
1994

    
1995
						switch (apr_nocode) {
1996
						case '1':
1997
							val = apr1_val;
1998
							break;
1999
						case '2':
2000
							val = apr2_val;
2001
							break;
2002
						case '3':
2003
							val = apr3_val;
2004
							break;
2005
						case '4':
2006
							val = apr4_val;
2007
							break;
2008
						case '5':
2009
							val = apr5_val;
2010
							break;
2011
						default:
2012
							break;
2013
						}
2014

    
2015
						apr = apr + kid + '|' + sid + '|' + wei + '|' + val;
2016

    
2017
						if (i === 1) {
2018
							subKPIData = subKPIData + kid + '|' + sid;
2019
						}
2020

    
2021
						if (j < countSubKPI) {
2022
							apr = apr + '||';
2023
							if (i === 1) {
2024
								subKPIData = subKPIData + '||';
2025
							}
2026
						}
2027

    
2028
						j = j + 1;
2029
					});
2030

    
2031
					aprNumber = aprNumber + apr_nocode;
2032

    
2033
					if (i < countApr) {
2034
						aprNumber = aprNumber + '|';
2035
						apr = apr + ';';
2036
					}
2037
					i = i + 1;
2038
				});
2039

    
2040
				//        console.log(apr);
2041
				//        console.log(subKPIData);
2042

    
2043
				MinovaUtil.executeParamQuery({
2044
					paramid: 'pms_subkpi_calculate_appraiser',
2045
					subKPIData: subKPIData,
2046
					apr: apr,
2047
					aprNumber: aprNumber
2048

    
2049
				}, function (s) {
2050
					var result = Ext.decode(s.responseText).data;
2051
					var _view = MinovaUtil.WORKFLOW.getViewWorkflow();
2052

    
2053
					var setorKPI = Body.down('grid[name=KPI]').store;
2054

    
2055
					Ext.each(result, function (d) {
2056
						// search and update record
2057
						var idx = setorKPI.findExact('kpi_kpi_id', d.kpi);
2058
						var ddx = parseInt(d.val).toString();
2059
						setorKPI.getAt(idx).set("kpi_" + d.name_field, ddx);
2060
					});
2061

    
2062
					me.calculateKPI();
2063
				}, function (f) {});
2064
			}
2065
		});
2066
		//@ sourceURL=/erp/controller/wf/pmsperform/controller.js
2067
		//@ sourceURL=/erp/controller/wf/pmsperform/ctr_pfdir_v2.js
(3-3/3)