Project

General

Profile

Feature #1365 » query untuk update validasi ESS Leave.sql

poin no.1 - Muhammad Bintar, 07/18/2022 04:06 PM

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

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

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

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

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

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

    
81
    },
82

    
83
    onDocumentBeforeSubmit: function(submit, taskId, me) {
84
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
85
        var absence_type = body.down(''[name=main_absence_type]'').getValue();
86
        var lvbolehbackdated = [''0001'', ''0002'', ''1100'', ''1200'', ''3900'', ''CL5'', ''CL6'', ''CL7''];
87
        var qdeduc = body.down(''[name=main_quota_deduction]'').getValue();
88
			
89
        if (qdeduc = ''Y'') {
90
            MinovaUtil.executeParamQuery({
91
                paramid: "leave_update_remaining_quota_save",
92
                emp_id: MinovaUtil.WORKFLOW.getEmpId(),
93
                landscape: ''100'',
94
                start_date: body.down(''[name=main_quota_start_date]'').getValue(),
95
                end_date: body.down(''[name=main_quota_end_date]'').getValue(),
96
                start_date2: body.down(''[name=main_quota_start_date_2]'').getValue(),
97
                end_date2: body.down(''[name=main_quota_end_date_2]'').getValue(),
98
                quota_type: body.down(''[name=main_quota_type]'').getValue(),
99
                quota_taken: body.down(''[name=main_quota_taken]'').getValue(),
100
                quota_taken2: body.down(''[name=main_quota_taken_2]'').getValue()
101
            }, function(s) {
102
                var data = Ext.decode(s.responseText).data[0];
103
                var formLeave = body.down(''form[name=Leave_Main]'').getForm();
104
                formLeave.setValues(data);
105
            }, function(f) {});
106
        }
107

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
266
        Ext.global.console.log(''<<changeValue'', field);
267
    },
268

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

    
272
        var me = this;
273
        me.calculate(field, newValue, oldValue, eOpts);
274
        var taskid = MinovaUtil.WORKFLOW.getTaskId();
275

    
276
    },
277

    
278
    calculateCutiKhusus: function() {
279

    
280
        var me = this;
281
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
282
        var absence_type = Body.down(''[name=main_absence_type]'').getValue();
283
        var start_cuti = Body.down(''[name=main_start_date]'').getValue();
284
        var end_cuti = Body.down(''[name=main_end_date]'').getValue();
285

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

    
299
            }, function(f) {});
300
        }
301

    
302
    },
303

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

    
312
        combo.up().up().query(''textfield[name=main_quota_type]'')[0].setValue(combo.displayTplData[0].quota_type);
313
        Body.down(''[name=main_quota_deduction]'').setValue(combo.displayTplData[0].quotadeduction);
314

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

    
325
        me.changeDateRange(combo, '''', '''', '''');
326
        Ext.global.console.log(''<<selectAbsenceType'', combo);
327
    },
328

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

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

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

    
354
        _popUploadView.show();
355
        Ext.global.console.log(''<<showEmployeeLeave'', _this);
356
    },
357

    
358
    calculate: function(field, newValue, oldValue, eOpts) {
359
        var reg = MinovaUtil.WORKFLOW.getRegId();
360
        var reg_id = 0;
361
        if (reg != "") {
362
            reg_id = parseInt(reg);
363
        }
364

    
365
        function leaveCheckDate() {
366
            var valSD = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=main_start_date]'').getValue();
367
            var valED = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=main_end_date]'').getValue();
368
            if (Ext.isEmpty(valSD) || Ext.isEmpty(valED)) return
369

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

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

    
416
                    })
417

    
418
                    me.calculateCutiKhusus();
419
                }
420

    
421
            } catch (scombo) {
422
                Ext.global.console.log(''<<main_total_quota_taken'', 0);
423
                me.changeValue(
424
                field.up().query(''textfield[name=main_remaining_quota]'')[0], newValue, oldValue, eOpts);
425
            }
426
            Ext.global.console.log(''<<calculate'', field);
427
        }
428

    
429
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
430
        var taskid = MinovaUtil.WORKFLOW.getTaskId();
431
        var sDate = Body.down(''datefield[name=main_start_date]'')
432
        var eDate = Body.down(''datefield[name=main_end_date]'')
433

    
434
        if (!sDate.isValid || !eDate.isValid) return null;
435

    
436
        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'') {
437
            Ext.global.console.log(''>>calculate'', field);
438
            var me = this;
439
            var sdt = sDate.getValue();
440
            var edt = eDate.getValue();
441
            var empid = MinovaUtil.WORKFLOW.getEmpId();
442
            var landscape = ''100'';
443

    
444
            leaveCheckDate();
445

    
446
        }
447
    },
448

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

    
464
        var reg = MinovaUtil.WORKFLOW.getRegId();
465
        var reg_id = 0;
466
        if (reg !== "") {
467
            reg_id = parseInt(reg);
468
        }
469

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

    
488
        }, function(f) {});
489
    },
490
    validasiHariLibur: function(submit) {
491
        var taskID = MinovaUtil.WORKFLOW.getTaskId();
492
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
493
        var sdate = Body.down(''datefield[name=main_start_date]'').getValue();
494
        var edate = Body.down(''datefield[name=main_end_date]'').getValue();
495
        var me = this;
496

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

    
512
            }, function(e) {});
513
        }
514
    },
515
    validasiProrateCuti: function(submit) {
516
        var taskID = MinovaUtil.WORKFLOW.getTaskId();
517
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
518
        var emp_id = MinovaUtil.WORKFLOW.getEmpId();
519
        var startCuti = Body.down(''datefield[name=main_start_date]'').getValue();
520
        var main_leave_quota = Body.down(''textfield[name=main_leave_quota]'').getValue();
521
        var main_total_remaining_quota = Body.down(''numberfield[name=main_total_remaining_quota]'').getValue();
522
        var totalCuti = parseInt(main_leave_quota) - parseInt(main_total_remaining_quota);
523

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

    
541
            }, function(e) {});
542
        }
543
    },
544
    validasiHariLibur2: function(submit) {
545
        var taskID = MinovaUtil.WORKFLOW.getTaskId();
546

    
547
        if (MinovaUtil.WORKFLOW.isRequest() || taskID === ''start'' || taskID === ''create'') {
548
            var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
549
            var quotadeduc = body.down(''textfield[name=main_quota_deduction]'').getValue();
550
            var totquotataken = body.down(''numberfield[name=main_total_quota_taken]'').getValue();
551

    
552
            if (quotadeduc === "Y" && totquotataken === 0) {
553
                MinovaUtil.MESSAGE.error("Cuti tidak dapat dilakukan pada hari libur");
554
            } else {
555
                submit();
556
            }
557
        }
558
    },
559

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

    
603

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

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

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

    
693
        var abs_type = body.down(''[name=main_absence_type]'').getValue();
694

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

    
706
        var Duration = this.GetDateDiff(Sd, NDate);
707
        var quotadeduc = body.down(''textfield[name=main_quota_deduction]'').getValue();
708

    
709
        if (taskID === ''start'' && CountDt >= 1 && Duration < 3) {
710
            MinovaUtil.MESSAGE.error("Maksimal 3 Hari Pengajuan");
711
            body.down(''[name=main_start_date]'').setValue('''');
712
        } else {
713
            this.changeDateRange();
714
        }
715
    }
716
});
717
Ext.apply(Ext.form.field.VTypes, {
718

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

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