Project

General

Profile

Bug #2135 » controller.wf.leave.leave(old).js

old - M Azid Wahyudi, 04/14/2023 11:00 AM

 
1
Ext.define('MinovaIS.ERP.Web.controller.wf.leave.leave', {
2
    extend: 'Ext.app.Controller',
3
    store: ['wf.leave.LeaveConf'],
4
    views: ['wf.leave.leave'],
5
    config: {
6
        delegate_mode: 2
7
    },
8
    init: function () {
9
        this.control({
10
            'wf-leave-leave': {
11
                afterrender: this.onAfterRender
12
            },
13
            'wf-leave-leave button[action=lookupEmpOnDelegateLeave]': {
14
                click: this.showEmployeeLeave
15
            },
16
            'wf-leave-leave combobox[name=main_absence_type]': {
17
                select: this.selectAbsenceType
18
            },
19
            'wf-leave-leave textfield[name=main_start_date]': {
20
                change: this.ValidasiMaksimaPengajuan
21
            },
22
            'wf-leave-leave textfield[name=main_end_date]': {
23
                change: this.changeDateRange
24
            },
25
            'employee_id textfield[name=employee_id]': {
26
                change: this.changeDateRange
27
            },
28
            'wf-leave-leave combo[name=list_of_delegate]': {
29
                select: this.selecttDelegation
30

    
31
            }
32
        });
33
    },
34
    onDocumentInit: function (me) {
35
        switch (me.config.delegate_mode) {
36
        case 0:
37
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=lookup_of_delegate]').hide();
38
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=list_of_delegate]').hide();
39
            break
40
        case 1:
41
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=lookup_of_delegate]').hide()
42
            break
43
        case 2:
44
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=list_of_delegate]').hide();
45
            break
46
        default:
47
            break
48
        }
49
        var btn_lookup_delegate = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=lookup_of_delegate]');
50
        btn_lookup_delegate.on('click', function () {
51
            var popupEmployee = this.getController('popup.employee.employee');
52
            popupEmployee.onSelect = function (recs) {
53
                MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=delegate_delegate_id]').setValue(recs.data.code);
54
                MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=delegate_delegate_name]').setValue(recs.data.desc);
55

    
56
            }
57
            popupEmployee.showPopup();
58
        }, me)
59

    
60
    },
61
    onDocumentReady: function (me) {
62
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
63
        var taskId = MinovaUtil.WORKFLOW.getTaskId();
64
        var listTaskFormEnabled = ['', 'create', 'start', 'revise_creator', 'creator_confirm', 'revise_after_confirm_dirspv', 'revise_after_rd', 'revise_creator_back']
65

    
66
        body.down('[name=main_absence_type]').store.load({
67
            params: {
68
                paramid: 'combobox_lv_absencetype',
69
                emp_id: MinovaUtil.WORKFLOW.getEmpId()
70
            },
71
            callback: function () {
72
                MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('combo[name=main_absence_type]').setValue(MinovaUtil.WORKFLOW.getRegValuesByName('main_absence_type'))
73
            }
74
        });
75

    
76
        if (listTaskFormEnabled.indexOf(taskId) < 0) {
77
            MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
78
        }
79

    
80
    },
81

    
82
    onDocumentBeforeSubmit: function (submit, taskId, me) {
83
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
84
        var absence_type = body.down('[name=main_absence_type]').getValue();
85
        var lvbolehbackdated = ['0001', '0002', '1100', '1200', '3900', 'CL5', 'CL6', 'CL7'];
86
        var qdeduc = body.down('[name=main_quota_deduction]').getValue();
87

    
88
        if (qdeduc = 'Y') {
89
            MinovaUtil.executeParamQuery({
90
                paramid: "leave_update_remaining_quota_save",
91
                emp_id: MinovaUtil.WORKFLOW.getEmpId(),
92
                landscape: '100',
93
                start_date: body.down('[name=main_quota_start_date]').getValue(),
94
                end_date: body.down('[name=main_quota_end_date]').getValue(),
95
                start_date2: body.down('[name=main_quota_start_date_2]').getValue(),
96
                end_date2: body.down('[name=main_quota_end_date_2]').getValue(),
97
                quota_type: body.down('[name=main_quota_type]').getValue(),
98
                quota_taken: body.down('[name=main_quota_taken]').getValue(),
99
                quota_taken2: body.down('[name=main_quota_taken_2]').getValue()
100
            }, function (s) {
101
                var data = Ext.decode(s.responseText).data[0];
102
                var formLeave = body.down('form[name=Leave_Main]').getForm();
103
                formLeave.setValues(data);
104
            }, function (f) {});
105
        }
106

    
107
        if (taskId === 'start' || taskId === '' || taskId === 'create') {
108
            var sdate = body.down('[name=main_start_date]');
109
            var edate = body.down('[name=main_end_date]');
110
            var now = Ext.Date.format(new Date(), 'Ymd');
111

    
112
            if (lvbolehbackdated.indexOf(absence_type) < 0 && (sdate.getValue() < now || edate.getValue() < now)) {
113
                alert("Leave Cannot be backdated. Please adjust field Start Date or End Date");
114
            } else
115
                me.validasi_cuti_tahunan(submit);
116
        } else
117
            me.validasi_cuti_tahunan(submit);
118

    
119
    },
120
    selecttDelegation: function (_this, recs, opt) {
121
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
122
        Body.down('textfield[name=delegate_delegate_id]').setValue(recs[0].data.emp_id);
123
        Body.down('textfield[name=delegate_delegate_name]').setValue(recs[0].data.fullname);
124
    },
125

    
126
    now8: function () {
127
        Ext.global.console.log('>>now8');
128
        return Ext.Date.format(new Date(), 'Ymd');
129
    },
130
    GetDateDiff: function (EndDate, StartDate) {
131
        var DateI = new Date(EndDate.substring(4, 6) + "/" + EndDate.substring(6, 8) + "/" + EndDate.substring(0, 4));
132
        var Date2 = new Date(StartDate.substring(4, 6) + "/" + StartDate.substring(6, 8) + "/" + StartDate.substring(0, 4));
133
        var DiffDays = parseInt((DateI - Date2) / (1000 * 60 * 60 * 24));
134
        return DiffDays;
135
    },
136

    
137
    onAfterRender: function (_this) {
138
        Ext.global.console.log('>>onAfterRender', _this);
139
        var me = this;
140
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow()
141

    
142
            body.down('combo[name=main_absence_type]').store.on('beforeload', function (store, operation, eOpts) {
143
                store.proxy.extraParams = {
144
                    paramid: 'combobox_lv_absencetype',
145
                    emp_id: MinovaUtil.WORKFLOW.getEmpId()
146
                };
147
            });
148
        var header = _this.up('panel[name=content]').down('panel[name=wf_form_header]');
149

    
150
        var taskId = header.down('textfield[name=task_id_run]');
151
        var empId = header.down('textfield[name=employee_id]');
152
        if (empId !== undefined)
153
            empId.on('change', me.onBehalfEmpId, me);
154
        Ext.global.console.log('<<onAfterRender', _this);
155
    },
156

    
157
    onBehalfEmpId: function (field, newValue, oldValue, eOpts) {
158
        this.changeDelegate(field, newValue, oldValue, eOpts);
159
        Ext.global.console.log('>>onBehalfEmpId', field);
160
        this.getDelegate(field, newValue, oldValue, eOpts);
161
        this.getStoreAbsence(field, newValue, oldValue, eOpts);
162
        if (MinovaUtil.WORKFLOW.isRequest()) {
163
            this.clearMainForm(field, newValue, oldValue, eOpts);
164
        }
165
        this.changeValue(
166
            field.up().up().up().query('wf-leave-leave textfield[name=main_remaining_quota]')[0], newValue, oldValue, eOpts);
167
        Ext.global.console.log('<<onBehalfEmpId', field);
168
    },
169

    
170
    changeDelegate: function (_this, newVal, oldVal) {
171
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
172
        var main_delegate = body.down('textfield[name=main_delegate_emp_from]');
173
        main_delegate.setValue(newVal);
174
    },
175
    onBehalfTaskId: function (field, newValue, oldValue, eOpts) {
176
        Ext.global.console.log('>>onBehalfTaskId', field);
177
        this.leaveConfSet(field, newValue, oldValue, eOpts);
178
        Ext.global.console.log('<<onBehalfTaskId', field);
179
    },
180

    
181
    leaveConfSet: function (field, newValue, oldValue, eOpts) {
182
        Ext.global.console.log('>>leaveConfSet', field);
183
        var leaveConf = field.up().up().up().query('wf-leave-leave combobox[name=main_leave_confirmation]')[0];
184

    
185
        switch (newValue) {
186
        case 'creator_confirm':
187
            leaveConf.show();
188
            break;
189
        case 'apv_ds2':
190
            leaveConf.show();
191
            leaveConf.setReadOnly(true);
192
            break;
193
        }
194
        Ext.global.console.log('<<leaveConfSet', field);
195
    },
196

    
197
    onLeaveInbox: function (field, newValue, oldValue, eOpts) {
198
        Ext.global.console.log('>>onLeaveInbox', field);
199
        this.getStoreAbsence(field, newValue, oldValue, eOpts);
200
        Ext.global.console.log('<<onLeaveInbox', field);
201
    },
202

    
203
    clearMainForm: function (field, newValue, oldValue, eOpts) {
204
        Ext.global.console.log('>>beforedestroyleaveConf', field);
205
        field.up().up().up().query('wf-leave-leave textfield[name=main_leave_quota]')[0].setValue(0);
206

    
207
        field.up().up().up().query('wf-leave-leave textfield[name=main_remaining_quota]')[0].setValue(0);
208

    
209
        field.up().up().up().query('wf-leave-leave textfield[name=main_total_remaining_quota]')[0].setValue(0);
210

    
211
        field.up().up().up().query('wf-leave-leave textfield[name=main_absence_type]')[0].setValue('');
212

    
213
        field.up().up().up().query('wf-leave-leave textfield[name=main_quota_type]')[0].setValue('');
214
        Ext.global.console.log('<<beforedestroyleaveConf', field);
215
    },
216

    
217
    getStoreAbsence: function (field, newValue, oldValue, eOpts) {
218
        var me = this;
219
        Ext.global.console.log('>>getStoreAbsence', field);
220
        MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('combo[name=main_absence_type]').store.load();
221

    
222
        me.changeDateRange(field, newValue, oldValue, eOpts);
223
        Ext.global.console.log('<<getStoreAbsence', field);
224
    },
225

    
226
    getDelegate: function (field, newValue, oldValue, eOpts) {
227
        Ext.global.console.log('<<getDelegate', field);
228
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
229
        var me = this;
230
        Ext.Ajax.request({
231
            scope: me,
232
            url: '/Workflow/LoadDataQuery',
233
            method: 'POST',
234
            params: {
235
                paramid: '##Autofill_leave_delegate',
236
                emp_id: newValue
237
            },
238
            success: function (response, opts) {
239
                var obj = Ext.decode(response.responseText).data;
240
                if (obj === undefined || obj.length === 0)
241
                    return;
242
                try {
243
                    var cbDelegate = Body.down('combo[name=list_of_delegate]');
244
                    cbDelegate.store.loadData(obj);
245
                    if (MinovaUtil.WORKFLOW.getTaskId() === 'start') {
246
                        cbDelegate.select(obj[0].emp_id);
247
                        Body.down('textfield[name=delegate_delegate_id]').setValue(obj[0].emp_id);
248
                        Body.down('textfield[name=delegate_delegate_name]').setValue(obj[0].fullname);
249
                        return;
250
                    }
251

    
252
                } catch (comp) {}
253
            },
254
            failure: function (response, opts) {}
255
        });
256
        me.changeDateRange(field, newValue, oldValue, eOpts);
257
        Ext.global.console.log('>>getDelegate', field);
258
    },
259

    
260
    changeValue: function (field, newValue, oldValue, eOpts) {
261
        Ext.global.console.log('>>changeValue', field);
262
        try {
263
            var remainQuota = field.up().query('textfield[name=main_remaining_quota]')[0].value;
264
            var totalTakenQuota = field.up().query('textfield[name=main_total_quota_taken]')[0].value;
265
            field.up().query('textfield[name=main_total_remaining_quota]')[0].setValue(remainQuota - totalTakenQuota);
266
        } catch (e) {}
267

    
268
        Ext.global.console.log('<<changeValue', field);
269
    },
270

    
271
    changeDateRange: function (field, newValue, oldValue, eOpts) {
272
        if (!MinovaUtil.WORKFLOW.isRequest())
273
            if (Ext.isEmpty(oldValue) || oldValue == 0)
274
                return;
275

    
276
        var me = this;
277
        me.calculate(field, newValue, oldValue, eOpts);
278
        var taskid = MinovaUtil.WORKFLOW.getTaskId();
279

    
280
    },
281

    
282
    calculateCutiKhusus: function () {
283

    
284
        var me = this;
285
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
286
        var absence_type = Body.down('[name=main_absence_type]').getValue();
287
        var start_cuti = Body.down('[name=main_start_date]').getValue();
288
        var end_cuti = Body.down('[name=main_end_date]').getValue();
289

    
290
        if (start_cuti !== '' && end_cuti !== '') {
291
            MinovaUtil.executeParamQuery({
292
                paramid: "leave_cuti_khusus_calculation",
293
                absence_type: absence_type,
294
                start_cuti: start_cuti,
295
                end_cuti: end_cuti,
296
                emp_id: MinovaUtil.WORKFLOW.getEmpId(),
297
                reg_id: MinovaUtil.WORKFLOW.getRegId()
298
            }, function (s) {
299
                var data = Ext.decode(s.responseText).data[0];
300
                var formLeave = Body.down('form[name=Leave_Main]').getForm();
301
                MinovaUtil.WORKFLOW.setViewBodyWorkflowFormContent(data);
302

    
303
            }, function (f) {});
304
        }
305

    
306
    },
307

    
308
    selectAbsenceType: function (combo, eOpts) {
309
        Ext.global.console.log('>>selectAbsenceType', combo);
310
        var me = this;
311
        var fHeader = me.getFormHeader();
312
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
313
        Body.down('[name=main_start_date]').setValue('');
314
        Body.down('[name=main_end_date]').setValue('');
315

    
316
        combo.up().up().query('textfield[name=main_quota_type]')[0].setValue(combo.displayTplData[0].quota_type);
317
        Body.down('[name=main_quota_deduction]').setValue(combo.displayTplData[0].quotadeduction);
318

    
319
        MinovaUtil.executeParamQuery({
320
            paramid: "combobox_lv_block_continue",
321
            emp_id: fHeader.requester_id,
322
            now: me.now8(),
323
            quota_type: combo.displayTplData[0].quota_type
324
        }, function (s) {
325
            var obj2 = Ext.decode(s.responseText).data[0];
326
            Body.down('[name=main_block_contain]').setValue(obj2.result);
327
        }, function (f) {});
328

    
329
        me.changeDateRange(combo, '', '', '');
330
        Ext.global.console.log('<<selectAbsenceType', combo);
331
    },
332

    
333
    expandAbsenceType: function (field, eOpts) {
334
        Ext.global.console.log('<<expandAbsenceType', field);
335
        var me = this;
336
        field.store.load({
337
            params: {
338
                emp_id: me.up().down('wf-request-formHeader textfield[name=employee_id]').value
339
            }
340
        });
341
        Ext.global.console.log('<<expandAbsenceType', field);
342
    },
343

    
344
    showEmployeeLeave: function (_this) {
345
        Ext.global.console.log('<<showEmployeeLeave', _this);
346
        var me = this;
347
        var viewID = _this.up('wf-leave-leave').id;
348
        me.viewNYA = Ext.ComponentQuery.query('wf-leave-leave[id=' + viewID + ']')[0];
349
        var _appname = 'MinovaIS.ERP.Web.';
350
        var _ctrlname = _appname + 'controller.popup.employee.employee';
351
        var _popUploadCtrl = this.getController(_ctrlname);
352
        var tempAbout = _popUploadCtrl.about();
353
        _popUploadCtrl.refCode = Ext.ComponentQuery.query('wf-leave-leave textfield[name=wfl_txt_delegate_id]')[0];
354
        _popUploadCtrl.refDesc = Ext.ComponentQuery.query('wf-leave-leave textfield[name=wfl_txt_delegate_name]')[0];
355

    
356
        var _popUploadView = Ext.create(_appname + 'view.' + _popUploadCtrl.views[0]);
357

    
358
        _popUploadView.show();
359
        Ext.global.console.log('<<showEmployeeLeave', _this);
360
    },
361

    
362
    calculate: function (field, newValue, oldValue, eOpts) {
363
        var reg = MinovaUtil.WORKFLOW.getRegId();
364
        var reg_id = 0;
365
        if (reg != "") {
366
            reg_id = parseInt(reg);
367
        }
368

    
369
        function leaveCheckDate() {
370
            var valSD = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=main_start_date]').getValue();
371
            var valED = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=main_end_date]').getValue();
372
            if (Ext.isEmpty(valSD) || Ext.isEmpty(valED))
373
                return
374

    
375
                MinovaUtil.executeParamQuery({
376
                    paramid: "leave_check_date",
377
                    emp_id: empid,
378
                    landscape: landscape,
379
                    start_date: sdt,
380
                    end_date: edt,
381
                    reg_id: reg_id
382
                }, function (s) {
383
                    var obj = Ext.decode(s.responseText);
384
                    if (obj.data[0].res == '1') {
385
                        MinovaUtil.MESSAGE.error(obj.data[0].msg);
386
                        field.setValue('');
387
                    } else {
388
                        abc();
389
                    }
390
                }, function (f) {});
391
        }
392

    
393
        function abc() {
394
            try {
395
                scombo = field.up().query('combobox[name=main_absence_type]')[0].valueModels[0].data;
396
                if (scombo.quotadeduction == 'Y') {
397
                    var formLeave = MinovaUtil.WORKFLOW.getViewWorkflow().down('form[name=Leave_Main]').getForm();
398
                    if ((formLeave.getValues().main_absence_type !== '') && (formLeave.getValues().main_start_date !== '') && (formLeave.getValues().main_end_date !== '')) {
399
                        me.leave_detail_and_block(formLeave);
400
                    }
401
                } else {
402
                    field.up('panel[name=content]').down('form[name=Leave_Main]').getForm().setValues({
403
                        main_quota_lb_cont_2: '1',
404
                        main_quota_lb_cont: '1',
405
                        main_quota_sded: '',
406
                        main_quota_eded: '',
407
                        main_quota_sded2: '',
408
                        main_quota_eded2: '',
409
                        main_quota_start_date_2: '',
410
                        main_quota_end_date_2: '',
411
                        main_quota_seq_2: '',
412
                        main_leave_quota: 0,
413
                        main_remaining_quota: 0,
414
                        main_quota_taken: 0,
415
                        main_total_remaining_quota: 0,
416
                        main_leave_quota_2: 0,
417
                        main_remaining_quota_2: 0,
418
                        main_quota_taken_2: 0,
419
                        main_total_remaining_quota_2: 0
420

    
421
                    })
422

    
423
                    me.calculateCutiKhusus();
424
                }
425

    
426
            } catch (scombo) {
427
                Ext.global.console.log('<<main_total_quota_taken', 0);
428
                me.changeValue(
429
                    field.up().query('textfield[name=main_remaining_quota]')[0], newValue, oldValue, eOpts);
430
            }
431
            Ext.global.console.log('<<calculate', field);
432
        }
433

    
434
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
435
        var taskid = MinovaUtil.WORKFLOW.getTaskId();
436
        var sDate = Body.down('datefield[name=main_start_date]')
437
            var eDate = Body.down('datefield[name=main_end_date]')
438

    
439
            if (!sDate.isValid || !eDate.isValid)
440
                return null;
441

    
442
            if (Ext.isEmpty(taskid) || taskid === 'create' || taskid === 'start' || taskid === 'revise_creator' || taskid === 'creator_confirm' || taskid === 'revise_after_confirm_dirspv' || taskid === 'revise_after_rd' || taskid === 'revise_creator_back') {
443
                Ext.global.console.log('>>calculate', field);
444
                var me = this;
445
                var sdt = sDate.getValue();
446
                var edt = eDate.getValue();
447
                var empid = MinovaUtil.WORKFLOW.getEmpId();
448
                var landscape = '100';
449

    
450
                leaveCheckDate();
451

    
452
            }
453
    },
454

    
455
    getFormHeader: function () {
456
        Ext.global.console.log('>>getFormHeader');
457
        var formHeader = Ext.ComponentQuery.query('wf-request-formHeader')[0];
458
        if (formHeader !== undefined) {
459
            formHeader = Ext.ComponentQuery.query('wf-request-formHeader')[0].getForm().getValues();
460
        } else {
461
            formHeader = Ext.ComponentQuery.query('wf-run-formHeader')[0].getForm().getValues();
462
        }
463
        Ext.global.console.log('<<getFormHeader');
464
        return formHeader;
465
    },
466
    leave_detail_and_block: function (formLeave) {
467
        var formValue = formLeave.getValues();
468
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
469

    
470
        var reg = MinovaUtil.WORKFLOW.getRegId();
471
        var reg_id = 0;
472
        if (reg !== "") {
473
            reg_id = parseInt(reg);
474
        }
475

    
476
        MinovaUtil.executeParamQuery({
477
            paramid: "leave_detail_and_block",
478
            absence_type: formValue.main_absence_type,
479
            start_cuti: formValue.main_start_date,
480
            end_cuti: formValue.main_end_date,
481
            emp_id: MinovaUtil.WORKFLOW.getEmpId(),
482
            reg_id: reg_id,
483
            leaveblock_ListAbsenceType: 'AL1|AL2|AL3|AL4'
484
        }, function (Sxhr) {
485
            var result = Ext.decode(Sxhr.responseText);
486
            var data = result.data[0];
487
            if (data.warning_type === '1') {
488
                MinovaUtil.MESSAGE.error(data.warning_text);
489
                body.down('[name=main_start_date]').setValue('');
490
            } else {
491
                formLeave.setValues(data);
492
            }
493

    
494
        }, function (f) {});
495
    },
496
    validasiHariLibur: function (submit) {
497
        var taskID = MinovaUtil.WORKFLOW.getTaskId();
498
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
499
        var sdate = Body.down('datefield[name=main_start_date]').getValue();
500
        var edate = Body.down('datefield[name=main_end_date]').getValue();
501
        var me = this;
502

    
503
        if (MinovaUtil.WORKFLOW.isRequest() || taskID === 'start' || taskID === 'create') {
504
            MinovaUtil.executeParamQuery({
505
                paramid: 'check_wc_like_off_by_dates',
506
                sdate: sdate,
507
                edate: edate
508
            }, function (s) {
509
                try {
510
                    var value = Ext.decode(s.responseText).data[0].value;
511
                    if (value) {
512
                        MinovaUtil.MESSAGE.error("Tanggal cuti yang anda ajukan jatuh pada hari libur, mohon diperiksa kembali.");
513
                        return;
514
                    }
515
                    me.validasiProrateCuti(submit);
516
                } catch (e) {}
517

    
518
            }, function (e) {});
519
        }
520
    },
521
    validasiProrateCuti: function (submit) {
522
        var taskID = MinovaUtil.WORKFLOW.getTaskId();
523
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
524
        var emp_id = MinovaUtil.WORKFLOW.getEmpId();
525
        var startCuti = Body.down('datefield[name=main_start_date]').getValue();
526
        var main_leave_quota = Body.down('textfield[name=main_leave_quota]').getValue();
527
        var main_total_remaining_quota = Body.down('numberfield[name=main_total_remaining_quota]').getValue();
528
        var totalCuti = parseInt(main_leave_quota) - parseInt(main_total_remaining_quota);
529

    
530
        if (MinovaUtil.WORKFLOW.isRequest() || taskID === 'start' || taskID === 'create') {
531
            MinovaUtil.executeParamQuery({
532
                paramid: 'validasi_lv_prorate_cuti',
533
                emp_id: emp_id,
534
                startCuti: startCuti,
535
                totalCuti: totalCuti
536
            }, function (s) {
537
                try {
538
                    var warning = Ext.decode(s.responseText).data[0].warning;
539
                    if (warning === '1') {
540
                        var warning_text = Ext.decode(s.responseText).data[0].warning_text;
541
                        MinovaUtil.MESSAGE.error(warning_text);
542
                        return;
543
                    }
544
                    new submit();
545
                } catch (e) {}
546

    
547
            }, function (e) {});
548
        }
549
    },
550
    validasiHariLibur2: function (submit) {
551
        var taskID = MinovaUtil.WORKFLOW.getTaskId();
552

    
553
        if (MinovaUtil.WORKFLOW.isRequest() || taskID === 'start' || taskID === 'create') {
554
            var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
555
            var quotadeduc = body.down('textfield[name=main_quota_deduction]').getValue();
556
            var totquotataken = body.down('numberfield[name=main_total_quota_taken]').getValue();
557

    
558
            if (quotadeduc === "Y" && totquotataken === 0) {
559
                MinovaUtil.MESSAGE.error("Cuti tidak dapat dilakukan pada hari libur");
560
            } else {
561
                submit();
562
            }
563
        }
564
    },
565

    
566
    onTask_apv_conf_dir_spv: function (me) {
567
        me.disableConfirmation();
568
    },
569
    onTask_apv_ds3: function (me) {
570
        me.disableConfirmation();
571
    },
572
    onTask_apv_dir_spv: function (me) {
573
        MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
574
    },
575
    onTask_apv_ds1: function (me) {
576
        MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
577
    },
578
    onTask_apv_direct_spv: function (me) {
579
        MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
580
    },
581
    onTask_apv_confirm_direct_spv: function (me) {
582
        me.disableConfirmation();
583
        MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
584
    },
585
    onTask_conf_cond_revise_date_apv_dir_spv: function (me) {
586
        me.disableConfirmation();
587
        MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
588
    },
589
    onTask_creator_confirm: function (me) {
590
        me.showConfirmation();
591
    },
592
    showConfirmation: function () {
593
        var view = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
594
        view.down('[name=main_leave_confirmation]').show();
595
        view.down('[name=main_leave_confirmation]').allowBlank = false;
596
    },
597
    disableConfirmation: function () {
598
        this.showConfirmation();
599
        var view = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
600
        view.down('[name=main_leave_confirmation]').setReadOnly(true);
601
        view.down('[name=main_leave_confirmation]').allowBlank = true;
602
    },
603
    validasi_cuti_tahunan: function (submit) {
604
        var me = MinovaUtil.WORKFLOW.loadControllerByViewClass(MinovaUtil.WORKFLOW.getViewBodyWorkflow().$className)
605
            var absenceType = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=main_absence_type]').getValue();
606
        var start_date = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=main_start_date]').getValue();
607
        var quota_type = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down('[name=main_quota_type]').getValue();
608

    
609
        if (absenceType === '1000') {
610
            MinovaUtil.executeParamQuery({
611
                paramid: 'leave_cek_cuti_tahunan',
612
                emp_id: MinovaUtil.WORKFLOW.getEmpId(),
613
                start_date: start_date,
614
                quota_type: quota_type
615
            }, function (s) {
616
                var data = Ext.decode(s.responseText).data[0]
617
                    if (data.warning === '1') {
618
                        MinovaUtil.MESSAGE.error(data.warning_text);
619
                    } else {
620
                        submit()
621
                    }
622
            }, function (f) {})
623
        } else {
624
            me.leave_validation(submit)
625
        }
626
    },
627
    leave_validation: function (submit) {
628
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow()
629
            var absenceType = body.down('[name=main_absence_type]').getValue();
630
        var emp_id = MinovaUtil.WORKFLOW.getEmpId();
631
        var sdate = body.down('[name=main_start_date]').getValue();
632
        var qdec = body.down('[name=main_quota_deduction]').getValue();
633

    
634
        if (qdec == 'Y') {
635
            submit();
636
        } else {
637
            MinovaUtil.executeParamQuery({
638
                paramid: 'leave_validation',
639
                absence_type: absenceType,
640
                start_cuti: sdate,
641
                emp_id: emp_id,
642
                reg_id: MinovaUtil.WORKFLOW.getRegId()
643
            }, function (s) {
644
                var data = Ext.decode(s.responseText).data[0]
645
                    if (data != null) {
646
                        if (data.warn > 0) {
647
                            MinovaUtil.MESSAGE.error(data.msg)
648
                        }
649
                    } else {
650
                        submit()
651
                    }
652
            }, function (f) {})
653
        }
654
    },
655
    ValidasiMaksimaPengajuan: function (submit) {
656
        var taskID = MinovaUtil.WORKFLOW.getTaskId();
657
        var BizprocId = MinovaUtil.WORKFLOW.getBizprocId();
658
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
659
        var Sd = body.down('[name=main_start_date]').getValue();
660
        var Ed = body.down('[name=main_end_date]').getValue();
661
        var NDate = null;
662
        var izin = '';
663
        var absence_type = body.down('[name=main_absence_type]').getValue();
664
        if (taskID == 'start' && BizprocId == 'leave') {
665
            MinovaUtil.executeParamQuery({
666
                paramid: 'ValidasiLeaveSetahun',
667
                emp_id: MinovaUtil.WORKFLOW.getEmpId()
668
            }, function (s) {
669
                var result = Ext.decode(s.responseText);
670
                var data = result.data[0];
671
                var obju = data;
672
                if (obju !== undefined) {
673
                    izin = obju.IZIN;
674
                }
675
            }, function (f) {})
676
            if (absence_type != 'CL3') {
677
                if (izin == 'no' || izin == '') {
678
                    MinovaUtil.MESSAGE.error("Anda belum diperkenankan untuk melakukan pengajuan cuti");
679
                    body.down('[name=main_start_date]').setValue('');
680
                }
681
            }
682
        }
683

    
684
        MinovaUtil.executeParamQuery({
685
            paramid: 'now_date'
686
        }, function (s) {
687
            var data = Ext.decode(s.responseText).data[0]
688
                if (data != null) {
689
                    NDate = data.NowDate;
690
                } else {
691
                    NDate = me.now8();
692
                }
693
        }, function (f) {})
694
        var Duration = this.GetDateDiff(Sd, NDate);
695

    
696
        var abs_type = body.down('[name=main_absence_type]').getValue();
697

    
698
        var CountDt = null;
699
        MinovaUtil.executeParamQuery({
700
            paramid: 'wf_leave_get_absentype',
701
            abs_type: abs_type
702
        }, function (s) {
703
            var data = Ext.decode(s.responseText).data[0]
704
                if (data != null) {
705
                    CountDt = data.Res;
706
                }
707
        }, function (f) {})
708

    
709
        var Duration = this.GetDateDiff(Sd, NDate);
710
        var quotadeduc = body.down('textfield[name=main_quota_deduction]').getValue();
711

    
712
        if (taskID === 'start' || taskID === 'revisess_creator') {
713
            if (CountDt >= 1 && Duration < 3) {
714
                MinovaUtil.MESSAGE.error("Pengajuan ESS bisa dilakukan Maksimal 3 Hari berikutnya");
715
                body.down('[name=main_start_date]').setValue('');
716
            } else {
717
                this.changeDateRange();
718
            }
719
        }
720
    }
721
});
722
Ext.apply(Ext.form.field.VTypes, {
723

    
724
    block_leave: function (val, field) {
725
        var wfv = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
726
        var a = wfv.down('textfield[name=main_quota_start_date_2]');
727
        var a1 = wfv.down('textfield[name=main_quota_start_date]');
728
        var b = wfv.down('textfield[name=main_quota_lb_cont_2]');
729
        var b1 = wfv.down('textfield[name=main_quota_lb_cont]');
730
        var c = wfv.down('textfield[name=main_total_remaining_quota_2]');
731
        var c1 = wfv.down('textfield[name=main_total_remaining_quota]');
732
        var d1 = wfv.down('[name=main_quota_taken]');
733
        var d = wfv.down('[name=main_quota_taken_2]');
734
        var dt = wfv.down('[name=main_total_quota_taken]');
735
        var absenceType = wfv.down('[name=main_absence_type]');
736
        if (absenceType.getValue() === '1000') {
737
            if ((a.getValue() !== '' || a.getValue() !== '0') && b.getValue() === '0' && c.getValue() < 5 && c.getValue() !== null) {
738
                if (c.getValue() < 5 && dt.getValue() < 5 && dt.getValue() !== null) {
739
                    return false;
740
                }
741
            } else if ((a.getValue() === '' || a.getValue() === '0') && b1.getValue() === '0' && c1.getValue() < 5 && c1.getValue() !== null) {
742
                if (c1.getValue() < 5 && dt.getValue() < 5 && dt.getValue() !== null) {
743
                    return false;
744
                }
745
            }
746
        }
747

    
748
        return true;
749
    },
750
    block_leaveText: 'Block leave must be taken',
751
    total_taken: function (val, field) {
752
        var lv_block = Ext.ComponentQuery.query('textfield[name=main_block_contain]')[0];
753
        try {
754
            var q_taken = Ext.ComponentQuery.query('textfield[name=main_total_quota_taken]')[0];
755
            var q_remain = Ext.ComponentQuery.query('textfield[name=main_total_remaining_quota]')[0];
756
            if (lv_block.value === "0") {
757
                try {
758
                    if (q_taken.value < 5 && q_remain.value < 5) {
759
                        return false;
760
                    }
761
                } catch (e) {}
762
            }
763
            if (lv_block.value === "1") {
764
                try {
765
                    if (q_taken.value >= 5) {
766
                        return false;
767
                    }
768
                } catch (e) {}
769
            }
770
        } catch (e) {}
771
        return true;
772
    },
773
    total_takenText: 'Types of absences are included in the block leave and unused. Mandatory quotas taken at least 5'
774
});
775
Ext.QuickTips.init();
(2-2/3)