Project

General

Profile

Bug #1854 » ctr_pfdir.js

package_update - M Azid Wahyudi, 12/07/2022 11:18 AM

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

    
4
    views: ['wf.pmsperform.view'],
5
    viewID: null,
6
    init: function () {
7
    },
8
    onDocumentInit: function (me) {
9
        me.loadPeriod();
10
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
11
        var header = MinovaUtil.WORKFLOW.getViewHeaderWorkflow();
12

    
13
        var obh = header.down('textfield[name=employee_id]');
14
        if (obh !== undefined) {
15
            obh.on('change', me.changeEmpID, this);
16
        }
17

    
18
        var obperiod = body.down('combobox[name=h_period]');
19
        if (obperiod !== null) {
20
            obperiod.on('change', me.periodChange, me);
21
        }
22
        //take out validasi appraisal date
23
        //var obh_appr_date = body.down('datefield[name=h_appr_date]');
24
        //if (obh_appr_date !== null) {
25
        //    obh_appr_date.on('change', me.aprdate_check, me);
26
        //}
27

    
28
        me.getGridSubKPI().reconfigureWORKFLOW();
29
        var cb_pms_sub_kpi_id = Ext.widget({
30
            xtype: 'minovacombobox',
31
            displayField: 'name',
32
            valueField: 'object',
33
            listeners: {
34
                scope: me,
35
                'expand': function (field, opt) {
36
                    // koleksi KPI yang ada di grid KPI
37
                    var listOfKPI = []
38
                    Ext.each(me.getGridKPI().store.getRange(), function (r) {
39
                        listOfKPI.push(r.data.kpi_kpi_id)
40
                    });
41
                    // filter combo KPI sesuai koleksi
42
                    field.store.filter([
43
                        //{property: "email", value: /\.com$/},
44
                        {
45
                            filterFn: function (item) {
46
                                return listOfKPI.indexOf(item.get("object")) >= 0;
47
                            }
48
                        }
49
                    ]);
50
                },
51
                'select': function (field, records, opt) {
52
                    field.store.clearFilter();
53
                    // get and set KPI seq to SubKPI parentSeq
54
                    var rec_KPI = this.getGridKPI().store.findRecord('kpi_kpi_id', field.getValue());
55
                    var rec_SubKPI = this.getGridSubKPI().getSelectionModel().getSelection()[0];
56

    
57
                    rec_SubKPI.set('subkpi_kpi_seq', rec_KPI.get('kpi_seq'))
58
                }
59
            }
60
        });
61
        cb_pms_sub_kpi_id.store.load({
62
            params: {
63
                paramid: 'pms_kpi_id'
64
            }
65
        });
66
        var cb_pms_sub_sub_kpi_id = Ext.widget({
67
            xtype: 'minovacombobox',
68
            displayField: 'description'
69
        });
70
        cb_pms_sub_sub_kpi_id.store.load({
71
            params: {
72
                paramid: 'pms_subkpi_id'
73
            }
74
        });
75
        var cb_pms_sub_kpi_unit = Ext.widget({
76
            xtype: 'minovacombobox',
77
            displayField: 'code'
78
        });
79
        cb_pms_sub_kpi_unit.store.load({
80
            params: {
81
                paramid: 'pms_subkpi_unit'
82
            }
83
        });
84
        var store_0_5 = new Ext.data.Store({
85
            fields: ['code', 'desc'],
86
            data: [
87
                {
88
                    "desc": "0",
89
                    "code": "0"
90
                },
91
                {
92
                    "desc": "1",
93
                    "code": "1"
94
                },
95
                {
96
                    "desc": "2",
97
                    "code": "2"
98
                },
99
                {
100
                    "desc": "3",
101
                    "code": "3"
102
                },
103
                {
104
                    "desc": "4",
105
                    "code": "4"
106
                },
107
                {
108
                    "desc": "5",
109
                    "code": "5"
110
                }
111
            ]
112
        });
113
        var cb_combo_val = new Ext.widget({
114
            xtype: 'minovacombobox',
115
            store: store_0_5
116
        });
117
        var subkpi_app1_value = new Ext.widget({
118
            xtype: 'minovacombobox',
119
            store: store_0_5
120
        });
121
        var subkpi_app2_value = new Ext.widget({
122
            xtype: 'minovacombobox',
123
            store: store_0_5
124
        });
125
        var subkpi_app3_value = new Ext.widget({
126
            xtype: 'minovacombobox',
127
            store: store_0_5
128
        });
129
        var subkpi_app4_value = new Ext.widget({
130
            xtype: 'minovacombobox',
131
            store: store_0_5
132
        });
133
        var subkpi_app5_value = new Ext.widget({
134
            xtype: 'minovacombobox',
135
            store: store_0_5
136
        });
137
        var subkpi_self_value = new Ext.widget({
138
            xtype: 'minovacombobox',
139
            store: store_0_5
140
        });
141

    
142
        /*        var subkpi_app1_value = new Ext.widget({
143
         xtype: 'numberfield'
144
         });
145
         var subkpi_app2_value = new Ext.widget({
146
         xtype: 'numberfield'
147
         });
148
         var subkpi_app3_value = new Ext.widget({
149
         xtype: 'numberfield'
150
         });
151
         var subkpi_app4_value = new Ext.widget({
152
         xtype: 'numberfield'
153
         });
154
         var subkpi_app5_value = new Ext.widget({
155
         xtype: 'numberfield'
156
         });
157
         var subkpi_self_value = new Ext.widget({
158
         xtype: 'numberfield'
159
         });*/
160

    
161
        var kpi_app1_value = new Ext.widget({
162
            xtype: 'numberfield',
163
            maxValue: 5,
164
            minValue: 0
165
        });
166
        var kpi_app2_value = new Ext.widget({
167
            xtype: 'numberfield',
168
            maxValue: 5,
169
            minValue: 0
170
        });
171
        var kpi_app3_value = new Ext.widget({
172
            xtype: 'numberfield',
173
            maxValue: 5,
174
            minValue: 0
175
        });
176
        var kpi_app4_value = new Ext.widget({
177
            xtype: 'numberfield',
178
            maxValue: 5,
179
            minValue: 0
180
        });
181
        var kpi_app5_value = new Ext.widget({
182
            xtype: 'numberfield',
183
            maxValue: 5,
184
            minValue: 0
185
        });
186
        var kpi_self_value = new Ext.widget({
187
            xtype: 'numberfield',
188
            maxValue: 5,
189
            minValue: 0
190
        });
191

    
192
        me.getGridSubKPI().changeColumnEditor('subkpi_kpi_id', cb_pms_sub_kpi_id);
193
        me.getGridSubKPI().changeColumnEditor('subkpi_sub_kpi', cb_pms_sub_sub_kpi_id);
194
        me.getGridSubKPI().changeColumnEditor('subkpi_unit', cb_pms_sub_kpi_unit);
195
        me.getGridSubKPI().changeColumnEditor('subkpi_app1_value', subkpi_app1_value);
196
        me.getGridSubKPI().changeColumnEditor('subkpi_app2_value', subkpi_app2_value);
197
        me.getGridSubKPI().changeColumnEditor('subkpi_app3_value', subkpi_app3_value);
198
        me.getGridSubKPI().changeColumnEditor('subkpi_app4_value', subkpi_app4_value);
199
        me.getGridSubKPI().changeColumnEditor('subkpi_app5_value', subkpi_app5_value);
200
        me.getGridSubKPI().changeColumnEditor('subkpi_self_value', subkpi_self_value);
201

    
202
        var minovaGrid = Ext.widget({
203
            xtype: 'minovagrid'
204
        })
205
        me.getGridKPI().changeColumnEditor = minovaGrid.changeColumnEditor
206

    
207
        me.getGridKPI().changeColumnEditor('kpi_app1_value', kpi_app1_value);
208
        me.getGridKPI().changeColumnEditor('kpi_app2_value', kpi_app2_value);
209
        me.getGridKPI().changeColumnEditor('kpi_app3_value', kpi_app3_value);
210
        me.getGridKPI().changeColumnEditor('kpi_app4_value', kpi_app4_value);
211
        me.getGridKPI().changeColumnEditor('kpi_app5_value', kpi_app5_value);
212
        me.getGridKPI().changeColumnEditor('kpi_self_value', kpi_self_value);
213

    
214
        var toolbar = me.getGridSubKPI().down('[xtype=toolbar]')
215
        toolbar.add('->');
216
        toolbar.add({
217
            text: 'Calculate',
218
            name: 'calculate',
219
            action: 'subkpi_calculate'
220
        })
221

    
222
    },
223
    onDocumentReady: function (me) {
224

    
225
        MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('button').forEach(
226

    
227
            function (b) {
228
                b.on('click', me.buttonClick, me);
229
            });
230
        me.cekTaskIDrun();
231

    
232
    },
233
    onDocumentBeforeSubmit: function (submit, taskId, me) {
234
        var KPIVALUE ='0';    
235
        var RecKPI = me.getGridKPI().store.getRange();
236
        if (taskId === 'start' || taskId === ''){
237
			 KPIVALUE="1"; 
238
		} else {
239
			for (let i = 0; i < RecKPI.length; i++) {
240
                if(RecKPI [i].data.kpi_app1_value.toString()!="0"){
241
                    KPIVALUE="1";    
242
                }
243
			}  
244
		}
245
	   
246
	   
247
		if (taskId === 'start' || taskId === ''){
248
			var calculatedo =  "1";
249
		} else {
250
			var calculatedo =  MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('textfield[name=sum_calculated_kpi]').getValue();
251
		}
252
		
253
		
254
		
255
		if(calculatedo=='0'){
256
			return MinovaUtil.MESSAGE.error('Must be Calculate First')    
257
		}
258
        else if(KPIVALUE=="0"){
259
           return MinovaUtil.MESSAGE.error('Appraisal 1 must be input')     
260
        } else{
261
			if(MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=Appraiser]').store.count() ===0 )
262
				{
263
					return  MinovaUtil.MESSAGE.error('Appraiser must exist.');
264
				}
265
				else if (Ext.Array.contains(['apv_appraiser_reject', 'apv_appraiser_revise'], MinovaUtil.WORKFLOW.getFlowId())) {
266
					//submit();
267
					me.validasiReqOnGoing(submit);
268
				} else if (Ext.Array.contains(['400', '200', '100', '430'], MinovaUtil.WORKFLOW.getFlowType())) {
269
					//        if (!me.hasRecordKpi(me)) return MinovaUtil.MESSAGE.error('record not found on KPI/ SubKPI grid')
270
					var validasiWeightValNol = me.isValidDataWeightValNol(me);
271
					if (!validasiWeightValNol.success) return MinovaUtil.MESSAGE.error(validasiWeightValNol.msg);
272

    
273
					var validasiTotalWeightHarus100 = me.isValidDataWeightTotal100(me);
274
					if (!validasiTotalWeightHarus100.success) return MinovaUtil.MESSAGE.error(validasiTotalWeightHarus100.msg);
275
					//submit();
276
					me.validasiReqOnGoing(submit);
277
				} else {
278
					//submit();
279
					me.validasiReqOnGoing(submit);
280
				}                
281
        }  
282
            
283

    
284
    },
285
    isValidDataWeightTotal100: function (me) {
286

    
287
        var RecARP = me.getGridAPR().store.getRange();
288
        var RecKPI = me.getGridKPI().store.getRange();
289
        var RecSubKPI = me.getGridSubKPI().store.getRange();
290

    
291
        if (!Ext.isEmpty(RecARP)) {
292
            var total = 0;
293
            var total2 = 0;
294
            Ext.each(RecARP, function (r) {
295
                total += Number(r.data.apr_weight_qual);
296
                total2 += Number(r.data.apr_weight_kpi);
297
            });
298
            if (total !== 100) return {
299
                success: false,
300
                msg: 'Weight competency on Appraiser not 100'
301
            }
302
            if (total2 !== 100) return {
303
                success: false,
304
                msg: 'Weight kpi on Appraiser not 100'
305
            }
306
        }
307

    
308
        if (!Ext.isEmpty(RecKPI)) {
309
            var total = 0;
310
            Ext.each(RecKPI, function (r) {
311
                total += Number(r.data.kpi_weight);
312
            });
313
            if (total !== 100) return {
314
                success: false,
315
                msg: 'Weight on KPI not 100'
316
            }
317
        }
318

    
319
        if (!Ext.isEmpty(RecSubKPI)) {
320
            var isValid = true;
321
            var _unique = [];
322
            Ext.each(RecSubKPI, function (r) {
323
                _unique.push(r.data.subkpi_kpi_id);
324
            });
325
            Ext.each(Ext.unique(_unique), function (kpi_id) {
326
                var total = 0;
327
                var recFiltered = Ext.Array.filter(RecSubKPI, function (r) {
328
                    return r.data.subkpi_kpi_id === kpi_id
329
                });
330
                Ext.each(recFiltered, function (r) {
331
                    total += Number(r.data.subkpi_weight);
332
                });
333
                if (total !== 100) return isValid = false
334
            });
335
            if (!isValid) return {
336
                success: false,
337
                msg: 'Weight on SubKPI not 100'
338
            }
339
        }
340
        return {
341
            success: true
342
        };
343
    },
344
    isValidDataWeightValNol: function (me) {
345
        var isValid = true;
346
        Ext.each(me.getGridKPI().store.getRange(), function (r) {
347
            var val = Number(r.data.kpi_weight);
348
            if (val === 0 || val === NaN) {
349
                isValid = false;
350
                return {
351
                    success: false,
352
                    msg: 'value 0 on KPI weight is\'t valid'
353
                };
354
            }
355
        });
356
        if (isValid) Ext.each(me.getGridSubKPI().store.getRange(), function (r) {
357
            var val = Number(r.data.subkpi_weight);
358
            if (val === 0 || val === NaN) {
359
                isValid = false;
360
                return {
361
                    success: false,
362
                    msg: 'value 0 on SubKPI weight is\'t valid'
363
                };
364
            }
365
        });
366
        return {
367
            success: true,
368
            msg: ''
369
        };
370
    },
371
    getGridAPR: function () {
372
        return MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=Appraiser]');
373
    },
374
    getGridKPI: function () {
375
        return MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=KPI]');
376
    },
377
    getGridSubKPI: function () {
378
        return MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=SubKPI]');
379
    },
380
    getGridQual: function () {
381
        return MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=QUAL]');
382
    },
383
    fillAdjustFromCalculate: function () {
384
        //add by irwan 20140226
385
        var a = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('textfield[name=sum_calculated_kpi]').getValue();
386
        var b = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('textfield[name=sum_calculated_competency]').getValue();
387
        MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('textfield[name=sum_final_kpi]').setValue(a);
388
        MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('textfield[name=sum_final_competency]').setValue(b);
389
    },
390
    buttonClick: function (_this) {
391
        switch (_this.action) {
392
            case 'kpi_calculate':
393
                this.calculateSubKPI_main();
394
                this.fillAdjustFromCalculate();
395
                this.calculateFS();
396
                break;
397
            case 'subkpi_calculate':
398
                this.calculateSubKPI_main();
399
                this.fillAdjustFromCalculate();
400
                this.calculateFS();
401
                break;
402
            case 'qual_calculate':
403
                this.calculateQUAL();
404
                this.fillAdjustFromCalculate();
405
                this.calculateFS();
406
                break;
407
            case 'cal_adjusted':
408
                this.calculateFS();
409
                break;
410
            default:
411
                break;
412

    
413
        }
414
    },
415
    validasiSubmit: function (submit) {
416
        if (Ext.Array.contains(['apv_appraiser_reject', 'apv_appraiser_revise'], MinovaUtil.WORKFLOW.getFlowId())) {
417
            submit();
418
        } else {
419
            var is_other = 0;
420
            var is_staff = 0;
421
            var qual_group = '';
422
            var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
423
            var not_submit = '0';
424
            var wei = 0;
425
            var wei_07 = 0;
426
            var wei_05 = 0;
427
            var wei_other = 0;
428

    
429
            var me = this;
430

    
431
            var warning_text = 'Silahkan cek kembali qualifikasi yang anda pilih';
432
            var w_sscore = 'Silahkan isi Self Score anda';
433
            var w_appraiser = 'Silahkan isi nilai appraiser anda';
434
            var w_qualweight_75 = 'Weight dari qualification harus total 100 untuk masing2 group';
435
            var w_qualweight = 'Weight dari qualification harus total 100';
436

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

    
439
            Body.down('grid[name=QUAL]').getStore().each(function (rec) {
440
                qual_group = rec.data.qual_qual_group;
441
                wei = parseInt(rec.data.qual_weight);
442

    
443
                //            if (qual_group === '00000007') {
444
                //                is_staff = 1;
445
                //                wei_07 = wei_07 + wei;
446
                //            } else if (qual_group === '00000005') {
447
                //                is_staff = 1;
448
                //                wei_05 = wei_05 + wei;
449
                //            } else {
450
                is_other = 1;
451
                wei_other = wei_other + wei;
452
                //            }
453

    
454
            });
455

    
456
            if (countkpi > 0) {
457
                if (is_staff > 0) {
458
                    alert(warning_text);
459
                    not_submit = '1';
460
                    return false;
461

    
462
                }
463
                //            else
464
                //                submit();
465
            } else {
466
                if (is_staff > 0) {
467
                    if (is_other > 0) {
468
                        alert(warning_text);
469
                        not_submit = '1';
470
                        return false;
471

    
472
                    }
473
                    //                else
474
                    //                    submit();
475
                }
476
                //            else
477
                //                submit();
478
            }
479

    
480
            if (is_staff > 0 && (wei_07 != 100 || wei_05 != 100)) {
481
                alert(w_qualweight_75);
482
                return false;
483
            } else if (wei_other != 100 && is_other > 0) {
484
                alert(w_qualweight);
485
                return false;
486
            }
487

    
488
            //Validasi per TASK
489
            var taskId = MinovaUtil.WORKFLOW.getTaskId();
490

    
491
            var qual1 = ['start', ''];
492
            var qual2 = ['apv_appraiser_many', 'apv_appraiser', 'result_appraiser1'];
493
            var qual3 = ['apv_nha', 'apv_appraiser', 'apv_nha_many'];
494
            var kpi_nilai = 0;
495
            var kpi_appaiserscore = '';
496
            var loginEmpID = MinovaUtil.SESSIONS.LOGIN.empId;
497
            var apr_nocode = '';
498

    
499
            if (qual1.indexOf(taskId) >= 0) {
500
                Body.down('grid[name=KPI]').getStore().each(function (rec) {
501
                    kpi_nilai = parseInt(rec.data.kpi_self_value);
502
					if (kpi_nilai = 'NaN'){
503
						alert(w_sscore);
504
                        not_submit = '1';
505
						return false;
506
					}
507
                    if (kpi_nilai <= 0 ) {
508
                        alert(w_sscore);
509
                        not_submit = '1';
510
                        return false;
511
                    }
512
                });
513

    
514
                if (not_submit === '1') return false;
515

    
516
                Body.down('grid[name=SubKPI]').getStore().each(function (rec) {
517
                    kpi_nilai = parseInt(rec.data.subkpi_self_value);
518
                    if (kpi_nilai <= 0) {
519
                        alert(w_sscore);
520
                        not_submit = '1';
521
                        return false;
522
                    }
523
                });
524
                if (not_submit === '1') return false;
525

    
526
                Body.down('grid[name=QUAL]').getStore().each(function (rec) {
527
                    kpi_nilai = parseInt(rec.data.qual_self_value);
528
					if (kpi_nilai = 'NaN'){
529
						alert(w_sscore);
530
                        not_submit = '1';
531
						return false;
532
					}
533
                    if (kpi_nilai <= 0) {
534
                        alert(w_sscore);
535
                        not_submit = '1';
536
                        return false;
537
                    }
538
                });
539
                if (not_submit === '1') return false;
540

    
541
            } else if (qual2.indexOf(taskId) >= 0) {
542
                Body.down('grid[name=Appraiser]').getStore().each(
543

    
544
                    function (rec) {
545
                        //console.log(rec.data.apr_appraiser_id);
546
                        var apr_no = rec.data.apr_appraiser_no;
547
                        var apr_id = rec.data.apr_appraiser_id;
548

    
549
                        if (apr_id === loginEmpID) {
550
                            apr_nocode = "app" + apr_no.substring(10);
551
                        }
552
                    });
553

    
554
                if (not_submit === '1') return false;
555
                Body.down('grid[name=KPI]').getStore().each(function (rec) {
556
                    kpi_nilai = parseInt(rec.data['kpi_' + apr_nocode + '_value']);
557
                    if (kpi_nilai <= 0) {
558
                        alert(w_appraiser);
559
                        not_submit = '1';
560
                        return false;
561
                    }
562
                });
563

    
564
                if (not_submit === '1') return false;
565
                Body.down('grid[name=SubKPI]').getStore().each(function (rec) {
566
                    kpi_nilai = parseInt(rec.data['subkpi_' + apr_nocode + '_value']);
567
                    if (kpi_nilai <= 0) {
568
                        alert(w_appraiser);
569
                        not_submit = '1';
570
                        return false;
571
                    }
572
                });
573

    
574
                if (not_submit === '1') return false;
575
                Body.down('grid[name=QUAL]').getStore().each(function (rec) {
576
                    kpi_nilai = parseInt(rec.data['qual_' + apr_nocode + '_value']);
577
                    if (kpi_nilai <= 0) {
578
                        alert(w_appraiser);
579
                        not_submit = '1';
580
                        return false;
581
                    }
582
                });
583
            }
584

    
585
            if (not_submit === '1') return false;
586
            else if (taskId === 'start' || taskId === 'create') {
587
                me.validasiHiringDate(submit);
588

    
589
            } else submit();
590
        }
591
    },
592
    validasiHiringDate: function (submit) {
593

    
594
        var me = this;
595
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
596
        var emp_id = MinovaUtil.WORKFLOW.getEmpId();
597
        var landscape = '100';
598
        var appraisal_date = Body.down('datefield[name=h_appr_date]').getValue();
599

    
600
        MinovaUtil.executeParamQuery({
601
            paramid: 'pms_val_review_final_hiringdate',
602
            emp_id: emp_id,
603
            appraisal_date: appraisal_date,
604
            now: me.now8()
605
        }, function (s) {
606
            try {
607
                var result = Ext.decode(s.responseText).data[0];
608
                var warning = result.warning;
609
                if (warning === '1') {
610
                    var warning_type = result.warning_type;
611
                    var is_submit = result.is_submit;
612
                    var warning_text = result.warning_text;
613
                    if (warning_type === '1') {
614
                        MinovaUtil.MESSAGE.confirm(warning_text, function (b) {
615
                            if (b === 'yes') {
616
                                new submit();
617

    
618
                            } else {
619
                            }
620
                        });
621
                    } else if (warning_type === '2') {
622
                        MinovaUtil.MESSAGE.alert(warning_text);
623
                    }
624
                } else {
625
                    new submit();
626

    
627
                }
628
            } catch (e) {
629
            }
630

    
631
        }, function (e) {
632
        });
633

    
634
    },
635
    calculateFS: function () {
636

    
637
        var sumkpi = 0;
638
        var sumqual = 0;
639
        var sumcal = 0;
640
        var is_staff = 0;
641
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
642

    
643
        //qualification FS calculate Data
644
        var score_weighted = parseFloat('0.00');
645
        var qual_TargetStaff = parseFloat('0.00');
646
        var qual_KompetensiStaff = parseFloat('0.00');
647
        var qual_group = '';
648

    
649
        MinovaUtil.executeParamQuery({
650
            paramid: 'pms_kpi_qual_weight'
651
        }, function (s) {
652
            var data = Ext.decode(s.responseText).data;
653
            var qual_weight = data[0].qual_weight;
654
            var kpi_weight = data[0].kpi_weight;
655
            Body.down('textfield[name=sum_kpi_weight]').setValue(kpi_weight);
656
            Body.down('textfield[name=sum_comp_weight]').setValue(qual_weight);
657

    
658
        });
659

    
660
        var kw = parseFloat(Body.down('textfield[name=sum_kpi_weight]').getValue());
661
        var qw = parseFloat(Body.down('textfield[name=sum_comp_weight]').getValue());
662
        var fkpi = parseFloat(Body.down('textfield[name=sum_final_kpi]').getValue());
663
        var fqual = parseFloat(Body.down('textfield[name=sum_final_competency]').getValue());
664

    
665
        var tw = kw + qw;
666

    
667
        if (is_staff === 1) {
668
            sumkpi = qual_TargetStaff;
669
            sumqual = qual_KompetensiStaff;
670
        } else {
671
            Body.down('grid[name=KPI]').getStore().each(function (rec) {
672
                var ks = parseFloat(rec.data.kpi_kpi_score_weighted);
673
                sumkpi = sumkpi + ks;
674
            });
675

    
676
            Body.down('grid[name=QUAL]').getStore().each(function (rec) {
677
                var kq = parseFloat(rec.data.qual_qual_score_weighted);
678
                sumqual = sumqual + kq;
679
            });
680
        }
681

    
682
        sumkpi = sumkpi * kw / tw;
683
        sumqual = sumqual * qw / tw;
684
        sumcal = sumkpi + sumqual;
685

    
686
        sumkpi = Math.round(sumkpi * 100) / 100;
687
        sumqual = Math.round(sumqual * 100) / 100;
688
        sumcal = Math.round(sumcal * 100) / 100;
689

    
690
        var fs = fkpi + fqual;
691
        Body.down('textfield[name=sum_calculated_kpi]').setValue(sumkpi);
692
        Body.down('textfield[name=sum_calculated_competency]').setValue(sumqual);
693
        Body.down('textfield[name=sum_calculated_score]').setValue(sumcal);
694
        Body.down('textfield[name=sum_final_score]').setValue(fs);
695

    
696
        MinovaUtil.executeParamQuery({
697
            paramid: 'pms_index_score',
698
            sumfinal: sumcal,
699
            finalscore: fs
700
        }, function (s) {
701
            var data = Ext.decode(s.responseText).data;
702
            if (data.length === 0) return;
703
            var sindex = data[0].sindex;
704
            var findex = data[0].findex;
705
            Body.down('textfield[name=sum_calculated_index]').setValue(sindex);
706
            Body.down('textfield[name=sum_final_index]').setValue(findex);
707

    
708
        });
709

    
710
    },
711
    calculateQUAL: function () {
712

    
713
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
714

    
715
        var period = '4';
716
        var qualData = '';
717
        var aprVal = '';
718
        var aprWeight = '';
719
        var qualTarget = '';
720
        var qualWeight = '';
721
        var aprNumber = '';
722
        var pmsType = 'P';
723

    
724
        var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
725
        if (bizproc.substring(0, 9) === 'PMS_FINAL') {
726
            pmsType = 'F';
727
        }
728

    
729
        period = MinovaUtil.WORKFLOW.getViewBodyWorkflow().up().up().query('datefield[name=h_appr_date]')[0].getValue();
730
        period = period.substring(4, 2);
731

    
732
        Body.down('grid[name=Appraiser]').getStore().sort({
733
            property: 'apr_appraiser_no',
734
            direction: 'ASC'
735
        });
736

    
737
        var countApr = Body.down('grid[name=Appraiser]').getStore().count();
738
        var i = 1;
739

    
740
        Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
741
            var apr_no = rec.data.apr_appraiser_no;
742
            var apr_nocode = apr_no.substring(10);
743
            var apr_weight_qual = rec.data.apr_weight_qual;
744
            //            console.log(apr_no + ' ' + apr_nocode);
745

    
746
            aprNumber = aprNumber + apr_nocode;
747
            aprWeight = aprWeight + apr_weight_qual;
748
            if (i < countApr) {
749
                aprNumber = aprNumber + '|';
750
                aprWeight = aprWeight + '|';
751
                //                console.log(aprNumber);
752
            }
753
            i = i + 1;
754
        });
755

    
756
        var me = this;
757
        var countQUAL = Body.down('grid[name=QUAL]').getStore().count();
758
        i = 1;
759
        Body.down('grid[name=QUAL]').getStore().each(function (rec) {
760
            var id = rec.data.qual_qual_id;
761
            var tar = rec.data.qual_target;
762
            var wei = rec.data.qual_weight;
763
            var val = rec.data.qual_weight;
764
            var apr1_val = rec.data.qual_app1_value;
765
            var apr2_val = rec.data.qual_app2_value;
766
            var apr3_val = rec.data.qual_app3_value;
767
            var apr4_val = rec.data.qual_app4_value;
768
            var apr5_val = rec.data.qual_app5_value;
769

    
770
            var j = 1;
771
            Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
772
                var apr_no = rec.data.apr_appraiser_no;
773
                var apr_nocode = apr_no.substring(10);
774

    
775
                switch (apr_nocode) {
776
                    case '1':
777
                        aprVal = aprVal + apr1_val;
778
                        break;
779
                    case '2':
780
                        aprVal = aprVal + apr2_val;
781
                        break;
782
                    case '3':
783
                        aprVal = aprVal + apr3_val;
784
                        break;
785
                    case '4':
786
                        aprVal = aprVal + apr4_val;
787
                        break;
788
                    case '5':
789
                        aprVal = aprVal + apr5_val;
790
                        break;
791
                    default:
792
                        break;
793
                }
794

    
795
                if (j < countApr) {
796
                    aprVal = aprVal + '|';
797
                }
798
                j = j + 1;
799

    
800
            });
801

    
802
            qualData = qualData + id;
803
            qualTarget = qualTarget + '0';
804
            qualWeight = qualWeight + wei;
805

    
806
            if (i < countQUAL) {
807
                qualData = qualData + '|';
808
                qualTarget = qualTarget + '|';
809
                qualWeight = qualWeight + '|';
810
                aprVal = aprVal + ';';
811
                //                console.log(qualWeight);
812
            }
813
            i = i + 1;
814
        });
815

    
816
        MinovaUtil.executeParamQuery({
817
            paramid: 'pms_qual_calculate',
818
            pmsType: pmsType,
819
            period: period,
820
            qualData: qualData,
821
            aprVal: aprVal,
822
            aprWeight: aprWeight,
823
            qualTarget: qualTarget,
824
            qualWeight: qualWeight,
825
            aprNumber: aprNumber
826
        }, function (s) {
827
            var result = Ext.decode(s.responseText).data;
828
            var _view = MinovaUtil.WORKFLOW.getViewWorkflow();
829

    
830
            var setorQUAL = Body.down('grid[name=QUAL]').store;
831

    
832
            Ext.each(result, function (d) {
833
                // search and update record
834
                var idx = setorQUAL.findExact('qual_qual_id', d.id);
835

    
836
                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') {
837
                    setorQUAL.getAt(idx).set("qual_" + d.name_field, d.val);
838
                }
839
                //setorQUAL.getAt(idx).set("qual_" + d.name_field, d.val);
840
            });
841

    
842
            me.calculateFS();
843
        }, function (f) {
844
        });
845

    
846
    },
847
    calculateAll: function () {
848
        var me = this;
849
        me.calculateKPI();
850
        me.calculateQUAL();
851

    
852
    },
853
    calculateKPI: function () {
854
        //alert('AAAA');
855

    
856
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
857

    
858
        var period = '4';
859
        var kpiData = '';
860
        var kpiSeq = '';
861
        var aprVal = '';
862
        var aprWeight = '';
863
        var kpiTarget = '';
864
        var kpiWeight = '';
865
        var aprNumber = '';
866
        var pmsType = 'P';
867

    
868
        var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
869
        if (bizproc.substring(0, 9) === 'PMS_FINAL' || bizproc.substring(0, 9) === 'PMS_FINAL_Direct') {
870
            pmsType = 'F';
871
        }
872

    
873
        period = MinovaUtil.WORKFLOW.getViewBodyWorkflow().up().up().query('datefield[name=h_appr_date]')[0].getValue();
874
        period = period.substring(4, 2);
875

    
876
        // DECLARE @pmsType AS VARCHAR(1) = 'P'
877
        // DECLARE @period AS VARCHAR(8) = '4'
878
        // DECLARE @kpiData AS VARCHAR(100) =
879
        // '00000001|00000007|00000009|00000011' kpi_kpi_id
880

    
881
        // DECLARE @aprVal AS VARCHAR(MAX)
882
        // SET @aprVal = '8|7|6;7|6|5;9|8|10;4|3|2' kpi_app1_value
883
        // --SET @aprVal = '6;5;10;2'
884
        // DECLARE @aprWeight AS VARCHAR(100) = '40|30|30' apr_weight_kpi
885
        // DECLARE @kpiTarget AS VARCHAR(MAX) = '20|8|12|5' kpi_target
886
        // DECLARE @kpiWeight AS VARCHAR(100) = '30|20|40|10' kpi_weight
887
        // DECLARE @aprNumber AS VARCHAR(100) = '1|2|4'
888

    
889
        Body.down('grid[name=Appraiser]').getStore().sort({
890
            property: 'apr_appraiser_no',
891
            direction: 'ASC'
892
        });
893

    
894
        var countApr = Body.down('grid[name=Appraiser]').getStore().count();
895
        var i = 1;
896

    
897
        Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
898
            var apr_no = rec.data.apr_appraiser_no;
899
            var apr_nocode = apr_no.substring(10);
900
            var apr_weight_kpi = rec.data.apr_weight_kpi;
901
            //            console.log(apr_no + ' ' + apr_nocode);
902

    
903
            aprNumber = aprNumber + apr_nocode;
904
            aprWeight = aprWeight + apr_weight_kpi;
905
            if (i < countApr) {
906
                aprNumber = aprNumber + '|';
907
                aprWeight = aprWeight + '|';
908
                //                console.log(aprNumber);
909
            }
910
            i = i + 1;
911
        });
912

    
913
        var me = this;
914
        var countKPI = Body.down('grid[name=KPI]').getStore().count();
915
        i = 1;
916
        Body.down('grid[name=KPI]').getStore().each(function (rec) {
917
            var id = rec.data.kpi_kpi_id;
918
            var tar = rec.data.kpi_target;
919
            var wei = rec.data.kpi_weight;
920
            var val = rec.data.kpi_weight;
921
            var apr1_val = rec.data.kpi_app1_value;
922
            var apr2_val = rec.data.kpi_app2_value;
923
            var apr3_val = rec.data.kpi_app3_value;
924
            var apr4_val = rec.data.kpi_app4_value;
925
            var apr5_val = rec.data.kpi_app5_value;
926
            var seq = rec.data.kpi_seq;
927

    
928
            var j = 1;
929
            Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
930
                var apr_no = rec.data.apr_appraiser_no;
931
                var apr_nocode = apr_no.substring(10);
932

    
933
                switch (apr_nocode) {
934
                    case '1':
935
                        aprVal = aprVal + apr1_val;
936
                        break;
937
                    case '2':
938
                        aprVal = aprVal + apr2_val;
939
                        break;
940
                    case '3':
941
                        aprVal = aprVal + apr3_val;
942
                        break;
943
                    case '4':
944
                        aprVal = aprVal + apr4_val;
945
                        break;
946
                    case '5':
947
                        aprVal = aprVal + apr5_val;
948
                        break;
949
                    default:
950
                        break;
951
                }
952

    
953
                if (j < countApr) {
954
                    aprVal = aprVal + '|';
955
                }
956
                j = j + 1;
957

    
958
            });
959

    
960
            kpiData = kpiData + id;
961
            kpiTarget = kpiTarget + tar;
962
            kpiWeight = kpiWeight + wei;
963
            kpiSeq = kpiSeq + seq;
964

    
965
            if (i < countKPI) {
966
                kpiData = kpiData + '|';
967
                kpiTarget = kpiTarget + '|';
968
                kpiWeight = kpiWeight + '|';
969
                kpiSeq = kpiSeq + '|';
970
                aprVal = aprVal + ';';
971
                //                console.log(kpiWeight);
972
            }
973
            i = i + 1;
974
        });
975

    
976
        MinovaUtil.executeParamQuery({
977
            paramid: 'pms_kpi_calculate',
978
            pmsType: pmsType,
979
            period: period,
980
            kpiData: kpiData,
981
            aprVal: aprVal,
982
            aprWeight: aprWeight,
983
            kpiTarget: kpiTarget,
984
            kpiWeight: kpiWeight,
985
            aprNumber: aprNumber,
986
            kpiSeq: kpiSeq
987
        }, function (s) {
988
            var result = Ext.decode(s.responseText).data;
989
            var _view = MinovaUtil.WORKFLOW.getViewWorkflow();
990

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

    
993
            Ext.each(result, function (d) {
994
                // search and update record
995
                //var idx = setorKPI.findExact('kpi_kpi_id', d.id);
996
                var idx = setorKPI.findExact('kpi_seq', parseInt(d.id));
997

    
998
                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') {
999
                    setorKPI.getAt(idx).set("kpi_" + d.name_field, d.val);
1000
                }
1001
            });
1002

    
1003
            me.calculateFS();
1004
        }, function (f) {
1005
        });
1006
    },
1007
    cekTaskIDrun: function () {
1008
        var me = this;
1009
        var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1010
        var loginEmpID = MinovaUtil.SESSIONS.LOGIN.empId;
1011

    
1012
        var taskId = MinovaUtil.WORKFLOW.getTaskId();
1013
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1014

    
1015
        if (MinovaUtil.WORKFLOW.isArchive()) {
1016
            Body.down('grid[name=Appraiser]').getStore().each(
1017

    
1018
                function (rec) {
1019

    
1020
                    var apr_no = rec.data.apr_appraiser_no;
1021
                    var apr_id = rec.data.apr_appraiser_id;
1022
                    var apr_nocode = "app" + apr_no.substring(10);
1023

    
1024
                    Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_value]').show();
1025
                    Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_percent]').show();
1026

    
1027
                    //QUAL
1028
                    Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_value]').show();
1029
                    Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_percent]').show();
1030

    
1031
                    //SUBKPI
1032
                    Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_value]').show();
1033
                    Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_percent]').show();
1034

    
1035
                });
1036
        }
1037

    
1038
        if (taskId === 'start' || taskId === '' || taskId === 'revise_creator') {
1039
            if (taskId !== 'revise_creator') {
1040
                me.loadHeader();
1041
            }
1042
            //me.loadPeriod();
1043
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=KPI]').down('button[name=calculate]').hide(true);
1044

    
1045
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=QUAL]').down('button[name=calculate]').hide(true);
1046
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=SubKPI]').down('button[name=calculate]').hide(true);
1047

    
1048
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=KPI]').down('button[name=add]').setDisabled(false);
1049
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=KPI]').down('button[name=copy]').setDisabled(false);
1050
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=KPI]').down('button[name=remove]').setDisabled(false);
1051
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=SubKPI]').down('button[name=add]').setDisabled(false);
1052
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=SubKPI]').down('button[name=copy]').setDisabled(false);
1053
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=SubKPI]').down('button[name=remove]').setDisabled(false);
1054
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=add]').setDisabled(false);
1055
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=copy]').setDisabled(false);
1056
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=remove]').setDisabled(false);
1057

    
1058
		
1059
            // Body.down('grid[name=KPI]').down('[dataIndex=kpi_kpi_group]').getEditor().setReadOnly(false);
1060
            // Body.down('grid[name=KPI]').down('[dataIndex=kpi_kpi_id]').getEditor().setReadOnly(false);
1061
            // Body.down('grid[name=KPI]').down('[dataIndex=kpi_weight]').getEditor().setReadOnly(false);
1062
            // Body.down('grid[name=KPI]').down('[dataIndex=kpi_description]').getEditor().setReadOnly(false);
1063
            // Body.down('grid[name=KPI]').down('[dataIndex=kpi_unit]').getEditor().setReadOnly(false);
1064

    
1065
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_kpi_id]').getEditor().setReadOnly(false);
1066
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_sub_kpi]').getEditor().setReadOnly(false);
1067
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_description]').getEditor().setReadOnly(false);
1068
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_weight]').getEditor().setReadOnly(false);
1069
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_target]').getEditor().setReadOnly(false);
1070
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_unit]').getEditor().setReadOnly(false);
1071

    
1072
            Body.down('button[name=cal_adjusted]').setDisabled(true);
1073

    
1074
            var pmsType = 'P';
1075
            var pmsTypeDesc = 'Performance Review';
1076
            var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1077
            if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1078
                pmsType = 'F';
1079
                pmsTypeDesc = 'Final Review';
1080
            }
1081
            if (taskId !== 'revise_creator') {
1082
                MinovaUtil.WORKFLOW.getViewBodyWorkflow().up().up().query('textfield[name=h_appr_type]')[0].setValue(pmsType);
1083
                MinovaUtil.WORKFLOW.getViewBodyWorkflow().up().up().query('textfield[name=h_appr_type_desc]')[0].setValue(pmsTypeDesc);
1084
                me.loadKPI_QUAL_weight();
1085
            }
1086
            Body.down('form[name=KOMENTAR]').setVisible(false);
1087

    
1088
        } else if (taskId === "apv_appraiser_many" || taskId === "apv_appraiser" || taskId === "result_appraiser1" || taskId === "apv_appraiser1" || taskId === "revise_ds") {
1089

    
1090
            MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
1091

    
1092
            Body.down('grid[name=Appraiser]').columns.forEach(function (i) {
1093
                if (i.getEditor() !== undefined) i.getEditor().setReadOnly(true);
1094
            });
1095

    
1096
            Body.down('grid[name=KPI]').columns.forEach(function (i) {
1097
                if (i.getEditor() !== undefined) i.getEditor().setReadOnly(true);
1098
            });
1099

    
1100
            Body.down('grid[name=SubKPI]').columns.forEach(function (i) {
1101
                if (i.getEditor() !== undefined) i.getEditor().setReadOnly(true);
1102
            });
1103

    
1104
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_final_score]').show();
1105
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_kpi_score_weighted]').show();
1106
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_remark]').show();
1107
            Body.down('grid[name=KPI]').down('button[name=calculate]').setDisabled(false);
1108

    
1109
            Body.down('grid[name=QUAL]').down('[dataIndex=qual_final_score]').show();
1110
            Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_score_weighted]').show();
1111
            Body.down('grid[name=QUAL]').down('button[name=calculate]').setDisabled(false);
1112

    
1113
            //Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_final_score]').show();
1114
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_subkpi_score_weighted]').show();
1115
            Body.down('grid[name=SubKPI]').down('button[name=calculate]').setDisabled(false);
1116

    
1117
            //            Body.down('button[name=cal_adjusted]').setDisabled(true);
1118
            //            Body.down('textfield[name=sum_final_kpi]').setDisabled(true);
1119
            //            Body.down('textfield[name=sum_final_competency]').setDisabled(true);
1120

    
1121
            Body.query('textarea[name=kom_appraiser]')[0].setReadOnly(false);
1122
            Body.query('textarea[name=kom_usulan]')[0].setReadOnly(false);
1123
            Body.query('textarea[name=kom_ind_dev_plan]')[0].setReadOnly(false);
1124

    
1125
            //            if (taskId === "apv_appraiser" || taskId === "result_appraiser1") {
1126
            //                Body.down('button[name=cal_adjusted]').setDisabled(false);
1127
            //                Body.down('textfield[name=sum_final_kpi]').setReadOnly(false);
1128
            //                Body.down('textfield[name=sum_final_competency]').setReadOnly(false);
1129
            //
1130
            //            }
1131

    
1132
            Body.down('grid[name=Appraiser]').getStore().each(
1133

    
1134
                function (rec) {
1135
                    //                    console.log(rec.data.apr_appraiser_id);
1136
                    var apr_no = rec.data.apr_appraiser_no;
1137
                    var apr_id = rec.data.apr_appraiser_id;
1138
                    var apr_nocode = "app" + apr_no.substring(10);
1139
                    //                    console.log(apr_nocode);
1140

    
1141
                    Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_value]').show();
1142
                    Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_percent]').show();
1143

    
1144
                    //QUAL
1145
                    Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_value]').show();
1146
                    Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_percent]').show();
1147

    
1148
                    //SUBKPI
1149
                    Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_value]').show();
1150
                    Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_percent]').show();
1151

    
1152
                    if (apr_id === loginEmpID) {
1153
                        Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_value]').getEditor().setReadOnly(false);
1154
                        Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_value]').getEditor().setReadOnly(false);
1155
                        Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_value]').getEditor().setReadOnly(false);
1156
                    }
1157
                });
1158

    
1159
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_kpi_id]').getEditor().setReadOnly(false);
1160
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_weight]').getEditor().setReadOnly(false);
1161
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_description]').getEditor().setReadOnly(false);
1162
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_unit]').getEditor().setReadOnly(false);
1163

    
1164
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_kpi_id]').getEditor().setReadOnly(false);
1165
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_sub_kpi]').getEditor().setReadOnly(false);
1166
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_description]').getEditor().setReadOnly(false);
1167
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_weight]').getEditor().setReadOnly(false);
1168
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_target]').getEditor().setReadOnly(false);
1169
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_unit]').getEditor().setReadOnly(false);
1170

    
1171
            Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_id]').getEditor().setReadOnly(false);
1172
            Body.down('grid[name=QUAL]').down('[dataIndex=qual_weight]').getEditor().setReadOnly(false);
1173
            Body.down('grid[name=QUAL]').down('[dataIndex=qual_remark]').getEditor().setReadOnly(false);
1174

    
1175
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=KPI]').down('button[name=add]').setDisabled(false);
1176
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=KPI]').down('button[name=copy]').setDisabled(false);
1177
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=KPI]').down('button[name=remove]').setDisabled(false);
1178
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=SubKPI]').down('button[name=add]').setDisabled(false);
1179
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=SubKPI]').down('button[name=copy]').setDisabled(false);
1180
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=SubKPI]').down('button[name=remove]').setDisabled(false);
1181
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=add]').setDisabled(false);
1182
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=copy]').setDisabled(false);
1183
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=Appraiser]').down('button[name=remove]').setDisabled(false);
1184
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=QUAL]').down('button[name=add]').setDisabled(false);
1185
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=QUAL]').down('button[name=copy]').setDisabled(false);
1186
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('grid[name=QUAL]').down('button[name=remove]').setDisabled(false);
1187

    
1188
        } else if (taskId === "apv_nha" || taskId === "apv_nha_many" || taskId === "apv_nha_loop" || taskId === "apv_dept_branch_manager" || taskId === "apv_div_head" || taskId === "apv_hr_pms_admin" || taskId === "apv_appraiser1" || taskId === "revise_ds" || taskId === "apv_appraiser2") {
1189

    
1190
            MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
1191
            Body.down('grid[name=Appraiser]').columns.forEach(function (i) {
1192
                if (i.getEditor() !== undefined) i.getEditor().setReadOnly(true);
1193
            });
1194

    
1195
            Body.query('textarea[name=kom_ind_dev_plan]')[0].setReadOnly(false);
1196
            Body.query('textarea[name=kom_nha]')[0].setReadOnly(false);
1197
            Body.query('textarea[name=kom_usulan]')[0].setReadOnly(false);
1198

    
1199
            Body.down('grid[name=QUAL]').down('[dataIndex=qual_final_score]').show();
1200
            Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_score_weighted]').show();
1201
            Body.down('grid[name=QUAL]').down('button[name=calculate]').setDisabled(false);
1202

    
1203
            //Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_final_score]').show();
1204
            Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_subkpi_score_weighted]').show();
1205
            Body.down('grid[name=SubKPI]').down('button[name=calculate]').setDisabled(false);
1206

    
1207
            Body.down('grid[name=KPI]').columns.forEach(function (i) {
1208
                if (i.getEditor() !== undefined) i.getEditor().setReadOnly(true);
1209
            });
1210

    
1211
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_final_score]').show();
1212
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_kpi_score_weighted]').show();
1213
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_remark]').show();
1214
            Body.down('grid[name=KPI]').down('button[name=calculate]').setDisabled(false);
1215

    
1216
            Body.down('grid[name=Appraiser]').getStore().each(
1217

    
1218
                function (rec) {
1219

    
1220
                    var apr_no = rec.data.apr_appraiser_no;
1221
                    var apr_id = rec.data.apr_appraiser_id;
1222
                    var apr_nocode = "app" + apr_no.substring(10);
1223

    
1224
                    //KPI
1225
                    Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_value]').show();
1226
                    Body.down('grid[name=KPI]').down('[dataIndex=kpi_' + apr_nocode + '_percent]').show();
1227

    
1228
                    //QUAL
1229
                    Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_value]').show();
1230
                    Body.down('grid[name=QUAL]').down('[dataIndex=qual_' + apr_nocode + '_percent]').show();
1231

    
1232
                    //SUBKPI
1233
                    Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_value]').show();
1234
                    Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_' + apr_nocode + '_percent]').show();
1235

    
1236
                });
1237

    
1238
            if (taskId === "apv_div_head" || taskId === "apv_dept_branch_manager") {
1239

    
1240
                Body.down('button[name=cal_adjusted]').setDisabled(false);
1241
                Body.down('textfield[name=sum_final_kpi]').setReadOnly(false);
1242
                Body.down('textfield[name=sum_final_competency]').setReadOnly(false);
1243

    
1244
                Body.down('grid[name=QUAL]').down('button[name=calculate]').setDisabled(true);
1245
                Body.down('grid[name=KPI]').down('button[name=calculate]').setDisabled(true);
1246
                Body.down('grid[name=SubKPI]').down('button[name=calculate]').setDisabled(true);
1247
            } else if (taskId === "apv_nha_loop") {
1248
                Body.down('button[name=cal_adjusted]').setDisabled(true);
1249
                Body.down('textfield[name=sum_final_kpi]').setReadOnly(true);
1250
                Body.down('textfield[name=sum_final_competency]').setReadOnly(true);
1251

    
1252
                Body.down('grid[name=QUAL]').down('button[name=calculate]').setDisabled(true);
1253
                Body.down('grid[name=KPI]').down('button[name=calculate]').setDisabled(true);
1254
                Body.down('grid[name=SubKPI]').down('button[name=calculate]').setDisabled(true);
1255

    
1256
                Body.query('textarea[name=kom_ind_dev_plan]')[0].setReadOnly(true);
1257
                Body.query('textarea[name=kom_nha]')[0].setReadOnly(true);
1258
                Body.query('textarea[name=kom_usulan]')[0].setReadOnly(true);
1259
            } else if (taskId === "apv_hr_pms_admin") {
1260
                Body.down('button[name=cal_adjusted]').setDisabled(false);
1261
                Body.down('textfield[name=sum_final_kpi]').setReadOnly(false);
1262
                Body.down('textfield[name=sum_final_competency]').setReadOnly(false);
1263

    
1264
                Body.query('textarea[name=kom_ind_dev_plan]')[0].setReadOnly(true);
1265
                Body.query('textarea[name=kom_nha]')[0].setReadOnly(true);
1266
                Body.query('textarea[name=kom_usulan]')[0].setReadOnly(true);
1267

    
1268
                me.adminEnable();
1269
            }
1270
            else if (taskId === "apv_appraiser2") {
1271
                Body.down('button[name=cal_adjusted]').setDisabled(false);
1272
                Body.down('textfield[name=sum_final_kpi]').setReadOnly(false);
1273
            }
1274

    
1275
        } else {
1276
            MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
1277
        }
1278

    
1279
        if (MinovaUtil.SESSIONS.LOGIN.empId === 'admin') {
1280
            me.adminEnable();
1281
        }
1282

    
1283
        // add by irwan 20140226
1284

    
1285
        me.disableGridAppraisal(['start', 'create', 'apv_appraiser', 'apv_appraiser_many', 'revise_creator', 'apv_nha_loop', 'apv_dept_branch_manager', 'apv_hr_pms_admin']);
1286
        if (taskId === "start" || taskId === "create") {
1287
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_kpi_id]').getEditor().setReadOnly(true);
1288
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_weight]').getEditor().setReadOnly(true);
1289
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_description]').getEditor().setReadOnly(true);
1290
            //Body.down('grid[name=KPI]').down('[dataIndex=kpi_notes]').getEditor().setReadOnly(true);
1291
            // Body.down('grid[name=KPI]').down('[dataIndex=kpi_unit]').getEditor().setReadOnly(true);
1292
            // Body.down('grid[name=KPI]').down('[dataIndex=kpi_remark]').getEditor().setReadOnly(true);
1293

    
1294
            Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_id]').getEditor().setReadOnly(false);
1295
            Body.down('grid[name=QUAL]').down('[dataIndex=qual_weight]').getEditor().setReadOnly(false);
1296
			// Body.down('grid[name=QUAL]').down('[dataIndex=qual_qual_group]').getEditor().setReadOnly(false);
1297
            // Body.down('grid[name=QUAL]').down('[dataIndex=qual_remark]').getEditor().setReadOnly(true);
1298
        }
1299
        if (taskId === "apv_appraiser1" || taskId === "revise_ds") {
1300
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_app1_value]').getEditor().setReadOnly(false);
1301
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_app2_value]').getEditor().setReadOnly(true);
1302
            Body.down('grid[name=QUAL]').down('[dataIndex=qual_app1_value]').getEditor().setReadOnly(false);
1303
        }
1304
        if (taskId === "apv_appraiser2") {
1305
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_app1_value]').show();
1306
            Body.down('grid[name=QUAL]').down('[dataIndex=qual_app1_value]').show();
1307
        }if (taskId === "proc_data_md51_qual") {
1308
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_app1_value]').hide(true);
1309
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_app1_percent]').hide(true);
1310
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_app2_value]').hide(true);
1311
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_app2_percent]').hide(true);
1312
            Body.down('grid[name=KPI]').down('[dataIndex=kpi_remark]').hide(true);
1313
            Body.down('textfield[name=sum_calculated_kpi]').setValue('');
1314
            Body.down('textfield[name=sum_calculated_competency]').setValue('');
1315
            Body.down('textfield[name=sum_calculated_score]').setValue('');
1316
            Body.down('textfield[name=sum_calculated_index]').setValue('');
1317
            Body.down('textfield[name=sum_final_kpi]').setValue('');
1318
            Body.down('textfield[name=sum_final_competency]').setValue('');
1319
            Body.down('textfield[name=sum_final_score]').setValue('');
1320
            Body.down('textfield[name=sum_final_index]').setValue('');
1321
        }
1322

    
1323
    },
1324
    disableGridAppraisal: function (arrayTaskId) {
1325
        if (Ext.Array.contains(arrayTaskId, MinovaUtil.WORKFLOW.getTaskId())) MinovaUtil.WORKFLOW.setReadOnlyGridByName('Appraiser');
1326
    },
1327
    aprdate_check: function (_this, newVal, oldVal) {
1328
        var me = this;
1329
        var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1330
        var aprdate = newVal;
1331

    
1332
        var start_date = _this.up().up().query('datefield[name=h_start_date]')[0].getValue();
1333
        var end_date = _this.up().up().query('datefield[name=h_end_date]')[0].getValue();
1334
        var enddate_val = '';
1335

    
1336
        var pmsType = 'P';
1337

    
1338
        var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1339
        if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1340
            pmsType = 'F';
1341
        }
1342

    
1343
        if (pmsType === 'P') {
1344
            if (aprdate >= start_date && aprdate <= end_date) {
1345

    
1346
            } else if (aprdate !== '') {
1347
                alert('Appraisal Date must be between 1 January ' + start_date.substring(0, 4) + ' and 31 December ' + start_date.substring(0, 4));
1348
                _this.up().up().query('datefield[name=h_appr_date]')[0].setValue('');
1349
            }
1350
        } else {
1351
            var x = parseInt(start_date.substring(0, 4)) + 1;
1352
            enddate_val = x.toString() + '0331';
1353
            if (aprdate >= start_date && aprdate <= enddate_val) {
1354

    
1355
            } else if (aprdate !== '') {
1356
                alert('Appraisal Date must be between 1 January ' + start_date.substring(0, 4) + ' and 31 March ' + x);
1357
                _this.up().up().query('datefield[name=h_appr_date]')[0].setValue('');
1358
            }
1359
        }
1360
    },
1361
    changeEmpID: function () {
1362
        var me = this;
1363
        me.loadHeader();
1364
        //me.loadPeriod();
1365

    
1366
    },
1367
    loadPeriod: function () {
1368
        var mainSeq = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=main_seq]').getValue();
1369
        var empid = MinovaUtil.WORKFLOW.getEmpId();
1370

    
1371
        var me = this;
1372

    
1373
        var pmsType = 'P';
1374
        var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1375
        if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1376
            pmsType = 'F';
1377
        }
1378

    
1379
        var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1380
        viewNya.down('combobox[name=h_period]').store.load({
1381
            params: {
1382
                paramid: 'pms_getcomboperiod_pf_direct',
1383
                emp_id: empid,
1384
                start_date: mainSeq,
1385
                aprType: pmsType,
1386
                regid: MinovaUtil.WORKFLOW.getRegId()
1387
            }
1388
        });
1389

    
1390
    },
1391
    now8: function () {
1392
        Ext.global.console.log('>>now8');
1393
        return Ext.Date.format(new Date(), 'Ymd');
1394
    },
1395
    periodChange: function (_this, newVal, oldVal) {
1396
        if (!MinovaUtil.WORKFLOW.isRequest()) return;
1397
        var me = this;
1398
        var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1399
        var taskId = newVal;
1400
        var emp_id = MinovaUtil.WORKFLOW.getEmpId();
1401

    
1402
        var idx = _this.store.findExact('code', newVal);
1403
        var rec = _this.store.getAt(idx);
1404
        if (!rec) return;
1405
        var start_date = rec.data.start_date;
1406
        var end_date = rec.data.end_date;
1407
        var seq = rec.data.seq;
1408
        //        viewNya.down('textfield[name=main_seq]').setValue('1');
1409
        viewNya.down('datefield[name=h_start_date]').setValue(start_date);
1410
        viewNya.down('datefield[name=h_end_date]').setValue(end_date);
1411
        viewNya.down('datefield[name=h_appr_date]').setValue('');
1412

    
1413
        // set seq
1414
        var pmsType = 'P';
1415

    
1416
        var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1417
        if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1418
            pmsType = 'F';
1419
        }
1420
        MinovaUtil.executeParamQuery({
1421
            paramid: 'pms_final_perform_seq',
1422
            emp_id: emp_id,
1423
            start_date: start_date,
1424
            pmsType: pmsType
1425
        }, function (s) {
1426
            var result = Ext.decode(s.responseText).data[0].seq
1427
            result = Ext.isEmpty(result) ? '1' : result;
1428
            viewNya.down('textfield[name=main_seq]').setValue(result);
1429
        }, function (f) {
1430
        })
1431
        me.loadAppraiserKPI_def();
1432
        me.loadQual_def();
1433
        me.loadSubKPI_default(emp_id, start_date, end_date);
1434

    
1435
        me.updateGridHeaderSeq(_this, newVal, oldVal);
1436
    },
1437
    loadQual_def: function () {
1438
        var empid = MinovaUtil.WORKFLOW.getEmpId();
1439
        var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1440

    
1441
        var pmsType = 'P';
1442

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

    
1448
        viewNya.query('gridpanel[name=QUAL]')[0].store.proxy.url = '/Workflow/LoadDataQuery';
1449
        viewNya.query('gridpanel[name=QUAL]')[0].store.proxy.reader.root = 'data';
1450
        viewNya.down('gridpanel[name=QUAL]').store.load({
1451
            params: {
1452
                paramid: 'pms_qual_default',
1453
                emp_id: empid
1454
            }
1455
        });
1456
        Ext.each(viewNya.down('gridpanel[name=QUAL]').store.getRange(), function (r) {
1457
            r.set('qual_proficiency', '0');
1458
            r.set('qual_emp_id', empid);
1459
            r.set('qual_appraisal_type', pmsType);
1460
            r.set('qual_start_date', MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('datefield[name=h_start_date]')[0].getValue());
1461
            r.set('qual_end_date', MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('datefield[name=h_end_date]')[0].getValue());
1462
            r.set('qual_header_seq', MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textfield[name=main_seq]')[0].getValue());
1463
            r.set('qual_data_flag', 'C');
1464
            r.set('qual_self_value', '0');
1465
            r.set('qual_app1_value', '0');
1466
            r.set('qual_app2_value', '0');
1467
            r.set('qual_app3_value', '0');
1468
            r.set('qual_app4_value', '0');
1469
            r.set('qual_app5_value', '0');
1470
            r.set('qual_app6_value', '0');
1471
            r.set('qual_app7_value', '0');
1472
            r.set('qual_app8_value', '0');
1473
            r.set('qual_app9_value', '0');
1474
            r.set('qual_app10_value', '0');
1475
            r.set('qual_self_percent', '0');
1476
            r.set('qual_app1_percent', '0');
1477
            r.set('qual_app2_percent', '0');
1478
            r.set('qual_app3_percent', '0');
1479
            r.set('qual_app4_percent', '0');
1480
            r.set('qual_app5_percent', '0');
1481
            r.set('qual_app6_percent', '0');
1482
            r.set('qual_app7_percent', '0');
1483
            r.set('qual_app8_percent', '0');
1484
            r.set('qual_app9_percent', '0');
1485
            r.set('qual_app10_percent', '0');
1486
            r.set('qual_final_score', '0');
1487
            r.set('qual_qual_score_weighted', '0');
1488
            r.set('qual_remark', '');
1489

    
1490
        });
1491
    },
1492
    loadSubKPI_default: function (empId, sd, ed) {
1493
        var pmsType = 'P';
1494
        var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1495
        if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1496
            pmsType = 'F';
1497
        }
1498

    
1499
        this.getGridSubKPI().store.load({
1500
            params: {
1501
                paramid: 'pms_getsubkpi_G',
1502
                emp_id: empId,
1503
                start_date: sd,
1504
                end_date: ed,
1505
                aprType: pmsType,
1506
                header_seq: MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textfield[name=main_seq]')[0].getValue()
1507
            }
1508
        });
1509

    
1510
    },
1511
    loadHeader: function () {
1512
        var empid = MinovaUtil.WORKFLOW.getEmpId();
1513
        var me = this;
1514

    
1515
        MinovaUtil.executeParamQuery({
1516
            paramid: 'pms_get_headerdet',
1517
            emp_id: empid,
1518
            skarang: me.now8()
1519
        }, function (s) {
1520
            var result = Ext.decode(s.responseText);
1521
            var _view = MinovaUtil.WORKFLOW.getViewWorkflow();
1522

    
1523
            _view.query('form[name=MainForm]')[0].getForm().setValues({
1524
                main_emp_type: result.data[0].employee_type_desc,
1525
                main_emp_position: result.data[0].position_desc,
1526
                main_emp_job: result.data[0].job_desc,
1527
                main_emp_organization: result.data[0].organization_desc
1528
            });
1529
        }, function (f) {
1530
        });
1531
    },
1532
    loadAppraiserKPI_def: function () {
1533
        var empid = MinovaUtil.WORKFLOW.getEmpId();
1534
        var me = this;
1535
        var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
1536
        var start_date = viewNya.query('datefield[name=h_start_date]')[0].getValue();
1537
        var end_date = viewNya.query('datefield[name=h_end_date]')[0].getValue();
1538

    
1539
        var hp = viewNya.query('combobox[name=h_period]')[0];
1540
        var val = hp.getValue();
1541
        var idx = hp.store.findExact('code', val);
1542
        var rec = hp.store.getAt(idx);
1543
        var seq = rec.data.seq;
1544

    
1545
        var pmsType = 'P';
1546
        var header_seq = MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('textfield[name=main_seq]')[0].getValue();
1547
        var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1548
        if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1549
            pmsType = 'F';
1550
        }
1551
        viewNya.query('gridpanel[name=Appraiser]')[0].store.proxy.url = '/Workflow/LoadDataQuery';
1552
        viewNya.query('gridpanel[name=Appraiser]')[0].store.proxy.reader.root = 'data';
1553
        viewNya.query('gridpanel[name=Appraiser]')[0].store.load({
1554
            params: {
1555
                paramid: 'pms_getappraiser_pf_direct',
1556
                emp_id: empid,
1557
                startdate: start_date,
1558
                enddate: end_date,
1559
                seq: seq
1560
            }
1561
        });
1562
        Ext.each(viewNya.query('gridpanel[name=Appraiser]')[0].store.getRange(), function (r) {
1563
            r.set('apr_appraisal_type', pmsType);
1564
            //r.set('apr_header_seq', '1');
1565
            r.set('apr_data_flag', 'C');
1566
            r.set('apr_header_seq', header_seq);
1567
        });
1568

    
1569
        viewNya.query('gridpanel[name=KPI]')[0].store.proxy.url = '/Workflow/LoadDataQuery';
1570
        viewNya.query('gridpanel[name=KPI]')[0].store.proxy.reader.root = 'data';
1571
        viewNya.query('gridpanel[name=KPI]')[0].store.load({
1572
            params: {
1573
                paramid: 'pms_getkpi_pf_direct',
1574
                emp_id: empid,
1575
                start_date: start_date,
1576
                end_date: end_date,
1577
                seq: seq,
1578
                aprType: pmsType
1579
            }
1580
        });
1581
        Ext.each(viewNya.query('gridpanel[name=KPI]')[0].store.getRange(), function (r) {
1582
            r.set('kpi_data_flag', 'C');
1583
            r.set('kpi_self_value', '0');
1584
            r.set('kpi_app1_value', '0');
1585
            r.set('kpi_app2_value', '0');
1586
            r.set('kpi_app3_value', '0');
1587
            r.set('kpi_app4_value', '0');
1588
            r.set('kpi_app5_value', '0');
1589
            r.set('kpi_app6_value', 0);
1590
            r.set('kpi_app7_value', 0);
1591
            r.set('kpi_app8_value', 0);
1592
            r.set('kpi_app9_value', 0);
1593
            r.set('kpi_app10_value', 0);
1594
            r.set('kpi_self_projected', 0);
1595
            r.set('kpi_app1_projected', 0);
1596
            r.set('kpi_app2_projected', 0);
1597
            r.set('kpi_app3_projected', 0);
1598
            r.set('kpi_app4_projected', 0);
1599
            r.set('kpi_app5_projected', 0);
1600
            r.set('kpi_app6_projected', 0);
1601
            r.set('kpi_app7_projected', 0);
1602
            r.set('kpi_app8_projected', 0);
1603
            r.set('kpi_app9_projected', 0);
1604
            r.set('kpi_app10_projected', 0);
1605
            r.set('kpi_self_percent', 0);
1606
            r.set('kpi_app1_percent', 0);
1607
            r.set('kpi_app2_percent', 0);
1608
            r.set('kpi_app3_percent', 0);
1609
            r.set('kpi_app4_percent', 0);
1610
            r.set('kpi_app5_percent', 0);
1611
            r.set('kpi_app6_percent', 0);
1612
            r.set('kpi_app7_percent', 0);
1613
            r.set('kpi_app8_percent', 0);
1614
            r.set('kpi_app9_percent', 0);
1615
            r.set('kpi_app10_percent', 0);
1616
            r.set('kpi_final_score', 0);
1617
            r.set('kpi_kpi_score_weighted', 0);
1618
            r.set('kpi_header_seq', header_seq);
1619
        });
1620
    },
1621
    updateGridHeaderSeq: function (obj, newVal, oldVal) {
1622
        var mainSeq = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=main_seq]').getValue();
1623
        var x = obj.store.findExact('code', newVal),
1624
            rec = obj.store.getAt(x);
1625
        if (Ext.isEmpty(rec)) return;
1626

    
1627
        var sd = rec.data.start_date,
1628
            ed = rec.data.end_date;
1629

    
1630
        Ext.each(this.getGridAPR().store.getRange(), function (r) {
1631
            r.set('apr_header_seq', mainSeq);
1632
            r.set('apr_start_date', sd);
1633
            r.set('apr_end_date', ed);
1634
        });
1635
        Ext.each(this.getGridKPI().store.getRange(), function (r) {
1636
            r.set('kpi_header_seq', mainSeq);
1637
            r.set('kpi_start_date', sd);
1638
            r.set('kpi_end_date', ed);
1639
        });
1640
        Ext.each(this.getGridSubKPI().store.getRange(), function (r) {
1641
            r.set('subkpi_header_seq', mainSeq);
1642
            r.set('subkpi_sub_kpi_start', sd);
1643
            r.set('subkpi_start_date', sd);
1644
            r.set('subkpi_sub_kpi_end', ed);
1645
            r.set('subkpi_end_date', ed);
1646
        });
1647
        Ext.each(this.getGridQual().store.getRange(), function (r) {
1648
            r.set('qual_header_seq', mainSeq);
1649
            r.set('qual_start_date', sd);
1650
            r.set('qual_end_date', ed);
1651
        });
1652

    
1653
    },
1654

    
1655
    loadKPI_QUAL_weight: function () {
1656
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1657
        Body.down('textfield[name=sum_calculated_kpi]').setValue(0);
1658
        Body.down('textfield[name=sum_calculated_competency]').setValue(0);
1659
        Body.down('textfield[name=sum_calculated_score]').setValue(0);
1660
        Body.down('textfield[name=sum_calculated_index]').setValue(0);
1661
        Body.down('textfield[name=sum_final_kpi]').setValue(0);
1662
        Body.down('textfield[name=sum_final_competency]').setValue(0);
1663
        Body.down('textfield[name=sum_final_score]').setValue(0);
1664
        Body.down('textfield[name=sum_final_index]').setValue(0);
1665

    
1666
        MinovaUtil.executeParamQuery({
1667
            paramid: 'pms_kpi_qual_weight'
1668
        }, function (s) {
1669
            var data = Ext.decode(s.responseText).data;
1670
            var qual_weight = data[0].qual_weight;
1671
            var kpi_weight = data[0].kpi_weight;
1672
            Body.down('textfield[name=sum_kpi_weight]').setValue(kpi_weight);
1673
            Body.down('textfield[name=sum_comp_weight]').setValue(qual_weight);
1674

    
1675
        });
1676

    
1677
    },
1678
    calculateSubKPI: function () {
1679
        //alert('AAAA');
1680

    
1681
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1682

    
1683
        var period = '4';
1684
        var kpiData = '';
1685
        var aprVal = '';
1686
        var aprWeight = '';
1687
        var subKpiData = '';
1688
        var subKpiTarget = '';
1689
        var subKpiWeight = '';
1690

    
1691
        var aprNumber = '';
1692
        var pmsType = 'P';
1693

    
1694
        var bizproc = MinovaUtil.WORKFLOW.getBizprocId();
1695
        if (bizproc.substring(0, 9) === 'PMS_FINAL') {
1696
            pmsType = 'F';
1697
        }
1698

    
1699
        period = MinovaUtil.WORKFLOW.getViewBodyWorkflow().up().up().query('datefield[name=h_appr_date]')[0].getValue();
1700
        period = period.substring(4, 2);
1701

    
1702
        //        DECLARE @pmsType AS VARCHAR(1) = 'P'
1703
        //        DECLARE @period AS VARCHAR(8) = '4'
1704
        //        DECLARE @kpiData AS VARCHAR(100) = '00000001|00000001|00000003|00000003|00000002' --darisubkpi
1705
        //
1706
        //        DECLARE @aprVal AS VARCHAR(MAX)
1707
        //        SET @aprVal = '4|3|3.8|4|5;5|4|2|3.2|4'
1708
        //        DECLARE @aprWeight AS VARCHAR(100) = '40|60'
1709

    
1710
        //        DECLARE @aprNumber AS VARCHAR(100) = '1|3'
1711

    
1712
        //        //DECLARE @subKpiData AS VARCHAR(MAX) = '1|2|3|4|5'
1713
        //        DECLARE @subKpiWeight AS VARCHAR(MAX) = '40|60|50|50|100'
1714
        //        DECLARE @subKpiTarget AS VARCHAR(MAX) = '5|5|5|5|5'
1715

    
1716
        Body.down('grid[name=Appraiser]').getStore().sort({
1717
            property: 'apr_appraiser_no',
1718
            direction: 'ASC'
1719
        });
1720

    
1721
        var countApr = Body.down('grid[name=Appraiser]').getStore().count();
1722
        var i = 1;
1723

    
1724
        Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
1725
            var apr_no = rec.data.apr_appraiser_no;
1726
            var apr_nocode = apr_no.substring(10);
1727
            var apr_weight_kpi = rec.data.apr_weight_kpi;
1728
            //            console.log(apr_no + ' ' + apr_nocode);
1729

    
1730
            aprNumber = aprNumber + apr_nocode;
1731
            aprWeight = aprWeight + apr_weight_kpi;
1732
            if (i < countApr) {
1733
                aprNumber = aprNumber + '|';
1734
                aprWeight = aprWeight + '|';
1735
                //                console.log(aprNumber);
1736
            }
1737
            i = i + 1;
1738
        });
1739

    
1740
        var me = this;
1741
        var countSubKPI = Body.down('grid[name=SubKPI]').getStore().count();
1742
        i = 1;
1743
        Body.down('grid[name=SubKPI]').getStore().each(function (rec) {
1744
            var sid = rec.data.subkpi_seq;
1745
            var kid = rec.data.subkpi_kpi_id;
1746
            var tar = rec.data.subkpi_target;
1747
            var wei = rec.data.subkpi_weight;
1748
            var val = rec.data.subkpi_weight;
1749
            var apr1_val = rec.data.subkpi_app1_value;
1750
            var apr2_val = rec.data.subkpi_app2_value;
1751
            var apr3_val = rec.data.subkpi_app3_value;
1752
            var apr4_val = rec.data.subkpi_app4_value;
1753
            var apr5_val = rec.data.subkpi_app5_value;
1754

    
1755
            var j = 1;
1756
            Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
1757
                var apr_no = rec.data.apr_appraiser_no;
1758
                var apr_nocode = apr_no.substring(10);
1759

    
1760
                switch (apr_nocode) {
1761
                    case '1':
1762
                        aprVal = aprVal + apr1_val;
1763
                        break;
1764
                    case '2':
1765
                        aprVal = aprVal + apr2_val;
1766
                        break;
1767
                    case '3':
1768
                        aprVal = aprVal + apr3_val;
1769
                        break;
1770
                    case '4':
1771
                        aprVal = aprVal + apr4_val;
1772
                        break;
1773
                    case '5':
1774
                        aprVal = aprVal + apr5_val;
1775
                        break;
1776
                    default:
1777
                        break;
1778
                }
1779

    
1780
                if (j < countApr) {
1781
                    aprVal = aprVal + '|';
1782
                }
1783
                j = j + 1;
1784

    
1785
            });
1786

    
1787
            kpiData = kpiData + kid;
1788
            subKpiData = subKpiData + sid;
1789
            subKpiTarget = subKpiTarget + tar;
1790
            subKpiWeight = subKpiWeight + wei;
1791

    
1792
            if (i < countSubKPI) {
1793
                kpiData = kpiData + '|';
1794
                subKpiData = subKpiData + '|';
1795
                subKpiTarget = subKpiTarget + '|';
1796
                subKpiWeight = subKpiWeight + '|';
1797
                aprVal = aprVal + ';';
1798
                //                console.log(subKpiWeight);
1799
            }
1800
            i = i + 1;
1801
        });
1802

    
1803

    
1804
        MinovaUtil.executeParamQuery({
1805
            paramid: 'pms_subkpi_calculate',
1806
            pmsType: pmsType,
1807
            period: period,
1808
            kpiData: kpiData,
1809
            subKpiData: subKpiData,
1810
            aprVal: aprVal,
1811
            aprWeight: aprWeight,
1812
            aprNumber: aprNumber,
1813
            subKpiWeight: subKpiWeight,
1814
            subKpiTarget: subKpiTarget
1815

    
1816
        }, function (s) {
1817
            var result = Ext.decode(s.responseText).data;
1818
            if (result.length === 0) return
1819
            var _view = MinovaUtil.WORKFLOW.getViewWorkflow();
1820

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

    
1823
            Ext.each(result, function (d) {
1824
                // search and update record
1825
                var idx = setorsubKPI.findExact('subkpi_seq', parseInt(d.id));
1826
                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') {
1827
                    setorsubKPI.getAt(idx).set("subkpi_" + d.name_field, d.val);
1828
                }
1829
            });
1830

    
1831
            me.calculateSubKPI_appraiser();
1832
        }, function (f) {
1833
        });
1834
    },
1835
    calculateSubKPI_main: function () {
1836
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1837

    
1838
        var me = this;
1839
        var countSubKPI = Body.down('grid[name=SubKPI]').getStore().count();
1840

    
1841
        if (countSubKPI > 0) {
1842
            me.calculateSubKPI();
1843
            //me.calculateSubKPI_appraiser();
1844
        } else {
1845
            me.calculateKPI();
1846
        }
1847
    },
1848
    calculateSubKPI_appraiser: function () {
1849

    
1850
        var me = this;
1851
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
1852
        var aprNumber = '';
1853
        var kid = '';
1854
        var sid = '';
1855
        var wei = '';
1856
        var val = '';
1857
        var subKPIData = '';
1858
        var apr = '';
1859

    
1860
        var countApr = Body.down('grid[name=Appraiser]').getStore().count();
1861
        var countSubKPI = Body.down('grid[name=SubKPI]').getStore().count();
1862
        var i = 1;
1863
        var j = 1;
1864

    
1865
        Body.down('grid[name=Appraiser]').getStore().each(function (rec) {
1866
            var apr_no = rec.data.apr_appraiser_no;
1867
            var apr_nocode = apr_no.substring(10);
1868

    
1869
            j = 1;
1870

    
1871
            Body.down('grid[name=SubKPI]').getStore().each(function (rec) {
1872
                sid = rec.data.subkpi_seq;
1873
                kid = rec.data.subkpi_kpi_id;
1874
                wei = rec.data.subkpi_weight;
1875
                var apr1_val = rec.data.subkpi_app1_value;
1876
                var apr2_val = rec.data.subkpi_app2_value;
1877
                var apr3_val = rec.data.subkpi_app3_value;
1878
                var apr4_val = rec.data.subkpi_app4_value;
1879
                var apr5_val = rec.data.subkpi_app5_value;
1880

    
1881
                switch (apr_nocode) {
1882
                    case '1':
1883
                        val = apr1_val;
1884
                        break;
1885
                    case '2':
1886
                        val = apr2_val;
1887
                        break;
1888
                    case '3':
1889
                        val = apr3_val;
1890
                        break;
1891
                    case '4':
1892
                        val = apr4_val;
1893
                        break;
1894
                    case '5':
1895
                        val = apr5_val;
1896
                        break;
1897
                    default:
1898
                        break;
1899
                }
1900

    
1901
                apr = apr + kid + '|' + sid + '|' + wei + '|' + val;
1902

    
1903
                if (i === 1) {
1904
                    subKPIData = subKPIData + kid + '|' + sid;
1905
                }
1906

    
1907
                if (j < countSubKPI) {
1908
                    apr = apr + '||';
1909
                    if (i === 1) {
1910
                        subKPIData = subKPIData + '||';
1911
                    }
1912
                }
1913

    
1914
                j = j + 1;
1915
            });
1916

    
1917
            aprNumber = aprNumber + apr_nocode;
1918

    
1919
            if (i < countApr) {
1920
                aprNumber = aprNumber + '|';
1921
                apr = apr + ';';
1922
            }
1923
            i = i + 1;
1924
        });
1925

    
1926
        //        console.log(apr);
1927
        //        console.log(subKPIData);
1928

    
1929
        MinovaUtil.executeParamQuery({
1930
            paramid: 'pms_subkpi_calculate_appraiser',
1931
            subKPIData: subKPIData,
1932
            apr: apr,
1933
            aprNumber: aprNumber
1934

    
1935

    
1936
        }, function (s) {
1937
            var result = Ext.decode(s.responseText).data;
1938
            var _view = MinovaUtil.WORKFLOW.getViewWorkflow();
1939

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

    
1942
            Ext.each(result, function (d) {
1943
                // search and update record
1944
                var idx = setorKPI.findExact('kpi_kpi_id', d.kpi);
1945
                var ddx = parseInt(d.val).toString();
1946
                setorKPI.getAt(idx).set("kpi_" + d.name_field, d.val);
1947
            });
1948

    
1949
            me.calculateKPI();
1950
        }, function (f) {
1951
        });
1952
    },
1953
    onTask_apv_appraiser: function (me) {
1954
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow()
1955
        Body.down('grid[name=KPI]').down('[dataIndex=kpi_notes]').getEditor().setReadOnly(false);
1956
        Body.down('grid[name=KPI]').down('[dataIndex=kpi_remark]').getEditor().setReadOnly(false);
1957
        Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_notes]').getEditor().setReadOnly(false);
1958
        Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_remark]').getEditor().setReadOnly(false);
1959
//20140320
1960
        Body.down('grid[name=KPI]').down('[dataIndex=kpi_app1_value]').getEditor().setReadOnly(false);
1961
        Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_app1_value]').getEditor().setReadOnly(false);
1962
        Body.down('grid[name=QUAL]').down('[dataIndex=qual_app1_value]').getEditor().setReadOnly(false);
1963

    
1964
    },
1965
    onTask_apv_appraiser_many: function (me) {
1966
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow()
1967
        Body.down('grid[name=KPI]').down('[dataIndex=kpi_notes]').getEditor().setReadOnly(false);
1968
        Body.down('grid[name=KPI]').down('[dataIndex=kpi_remark]').getEditor().setReadOnly(false);
1969
        Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_notes]').getEditor().setReadOnly(false);
1970
        Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_remark]').getEditor().setReadOnly(false);
1971
//20140320
1972
        Body.down('grid[name=KPI]').down('[dataIndex=kpi_app1_value]').getEditor().setReadOnly(false);
1973
        Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_app1_value]').getEditor().setReadOnly(false);
1974
        Body.down('grid[name=QUAL]').down('[dataIndex=qual_app1_value]').getEditor().setReadOnly(false);
1975

    
1976
    },
1977
    onTask_apv_hr_pms_admin: function (me) {
1978
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow()
1979
        //20140320
1980
        Body.down('grid[name=KPI]').down('[dataIndex=kpi_app1_value]').getEditor().setReadOnly(false);
1981
        Body.down('grid[name=SubKPI]').down('[dataIndex=subkpi_app1_value]').getEditor().setReadOnly(false);
1982
        Body.down('grid[name=QUAL]').down('[dataIndex=qual_app1_value]').getEditor().setReadOnly(false);
1983
    },
1984

    
1985
    adminEnable: function () {
1986
        var me = this;
1987
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow()
1988
        me.getGridKPI().down('[dataIndex=kpi_weight]').getEditor().setReadOnly(false);
1989
        me.getGridKPI().down('button[name=calculate]').show(true);
1990
        me.getGridKPI().down('button[name=calculate]').setDisabled(false);
1991

    
1992
        me.getGridSubKPI().down('[dataIndex=subkpi_weight]').getEditor().setReadOnly(false);
1993
        me.getGridSubKPI().down('button[name=calculate]').show(true);
1994
        me.getGridSubKPI().down('button[name=calculate]').setDisabled(false);
1995

    
1996
        me.getGridQual().down('[dataIndex=qual_weight]').getEditor().setReadOnly(false);
1997
        me.getGridQual().down('button[name=calculate]').show(true);
1998
        me.getGridQual().down('button[name=calculate]').setDisabled(false);
1999

    
2000
        Body.down('button[name=cal_adjusted]').setDisabled(false);
2001
        Body.down('textfield[name=sum_final_kpi]').setReadOnly(false);
2002
        Body.down('textfield[name=sum_final_competency]').setReadOnly(false);
2003

    
2004
    },
2005

    
2006
    validasiReqOnGoing: function(submit) {
2007
        var taskID = MinovaUtil.WORKFLOW.getTaskId();
2008
        var viewNya = MinovaUtil.WORKFLOW.getViewWorkflow();
2009
        var start_date = viewNya.query('datefield[name=h_start_date]')[0].getValue();
2010
        var year = start_date.substring(0,4);
2011
        if (MinovaUtil.WORKFLOW.isRequest() || taskID === 'start' || taskID === 'create') {
2012
            MinovaUtil.executeParamQuery({
2013
                paramid: 'pms_check_req_on_going',
2014
                emp_id: MinovaUtil.WORKFLOW.getEmpId(),
2015
                tahun: year
2016
            }, function(s) {
2017
                try {
2018
                    var warning_type = Ext.decode(s.responseText).data[0].warning_type;
2019
                    if (warning_type === '1') {
2020
                        var warning_text = Ext.decode(s.responseText).data[0].warning_text;
2021
                        MinovaUtil.MESSAGE.error(warning_text);
2022
                    } else {
2023
                        submit();
2024
                    }
2025
                } catch (e) {}
2026

    
2027
            }, function(e) {});
2028
        } else {
2029
            submit();
2030
        }
2031
    }
2032
});
(2-2/2)