UPDATE dev_object SET code_prod = 
'Ext.define(''MinovaIS.ERP.Web.controller.wf.leave.leave'', {
    extend: ''Ext.app.Controller'',
    store: [''wf.leave.LeaveConf''],
    views: [''wf.leave.leave''],
    config: {
        delegate_mode: 2
    },
    init: function() {
        this.control({
            ''wf-leave-leave'': {
                afterrender: this.onAfterRender
            },
            ''wf-leave-leave button[action=lookupEmpOnDelegateLeave]'': {
                click: this.showEmployeeLeave
            },
            ''wf-leave-leave combobox[name=main_absence_type]'': {
                select: this.selectAbsenceType
            },
            ''wf-leave-leave textfield[name=main_start_date]'': {
                change: this.ValidasiMaksimaPengajuan
            },
            ''wf-leave-leave textfield[name=main_end_date]'': {
                change: this.changeDateRange
            },
            ''employee_id textfield[name=employee_id]'': {
                change: this.changeDateRange
            },
            ''wf-leave-leave combo[name=list_of_delegate]'': {
                select: this.selecttDelegation

            }
        });
    },
    onDocumentInit: function(me) {
        switch (me.config.delegate_mode) {
        case 0:
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=lookup_of_delegate]'').hide();
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=list_of_delegate]'').hide();
            break
        case 1:
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=lookup_of_delegate]'').hide()
            break
        case 2:
            MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=list_of_delegate]'').hide();
            break
        default:
            break
        }
        var btn_lookup_delegate = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=lookup_of_delegate]'');
        btn_lookup_delegate.on(''click'', function() {
            var popupEmployee = this.getController(''popup.employee.employee'');
            popupEmployee.onSelect = function(recs) {
                MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=delegate_delegate_id]'').setValue(recs.data.code);
                MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=delegate_delegate_name]'').setValue(recs.data.desc);

            }
            popupEmployee.showPopup();
        }, me)

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

        body.down(''[name=main_absence_type]'').store.load({
            params: {
                paramid: ''combobox_lv_absencetype'',
                emp_id: MinovaUtil.WORKFLOW.getEmpId()
            },
            callback: function() {
                MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''combo[name=main_absence_type]'').setValue(MinovaUtil.WORKFLOW.getRegValuesByName(''main_absence_type''))
            }
        });

        if (listTaskFormEnabled.indexOf(taskId) < 0) {
            MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
        }

    },

    onDocumentBeforeSubmit: function(submit, taskId, me) {
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
        var absence_type = body.down(''[name=main_absence_type]'').getValue();
        var lvbolehbackdated = [''0001'', ''0002'', ''1100'', ''1200'', ''3900'', ''CL5'', ''CL6'', ''CL7''];
        var qdeduc = body.down(''[name=main_quota_deduction]'').getValue();
			
        if (qdeduc = ''Y'') {
            MinovaUtil.executeParamQuery({
                paramid: "leave_update_remaining_quota_save",
                emp_id: MinovaUtil.WORKFLOW.getEmpId(),
                landscape: ''100'',
                start_date: body.down(''[name=main_quota_start_date]'').getValue(),
                end_date: body.down(''[name=main_quota_end_date]'').getValue(),
                start_date2: body.down(''[name=main_quota_start_date_2]'').getValue(),
                end_date2: body.down(''[name=main_quota_end_date_2]'').getValue(),
                quota_type: body.down(''[name=main_quota_type]'').getValue(),
                quota_taken: body.down(''[name=main_quota_taken]'').getValue(),
                quota_taken2: body.down(''[name=main_quota_taken_2]'').getValue()
            }, function(s) {
                var data = Ext.decode(s.responseText).data[0];
                var formLeave = body.down(''form[name=Leave_Main]'').getForm();
                formLeave.setValues(data);
            }, function(f) {});
        }

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

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

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

    now8: function() {
        Ext.global.console.log(''>>now8'');
        return Ext.Date.format(new Date(), ''Ymd'');
    },
    GetDateDiff: function(EndDate, StartDate) {
        var DateI = new Date(EndDate.substring(4, 6) + "/" + EndDate.substring(6, 8) + "/" + EndDate.substring(0, 4));
        var Date2 = new Date(StartDate.substring(4, 6) + "/" + StartDate.substring(6, 8) + "/" + StartDate.substring(0, 4));
        var DiffDays = parseInt((DateI - Date2) / (1000 * 60 * 60 * 24));
        return DiffDays;
    },

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

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

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

    onBehalfEmpId: function(field, newValue, oldValue, eOpts) {
        this.changeDelegate(field, newValue, oldValue, eOpts);
        Ext.global.console.log(''>>onBehalfEmpId'', field);
        this.getDelegate(field, newValue, oldValue, eOpts);
        this.getStoreAbsence(field, newValue, oldValue, eOpts);
        if (MinovaUtil.WORKFLOW.isRequest()) {
            this.clearMainForm(field, newValue, oldValue, eOpts);
        }
        this.changeValue(
        field.up().up().up().query(''wf-leave-leave textfield[name=main_remaining_quota]'')[0], newValue, oldValue, eOpts);
        Ext.global.console.log(''<<onBehalfEmpId'', field);
    },

    changeDelegate: function(_this, newVal, oldVal) {
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
        var main_delegate = body.down(''textfield[name=main_delegate_emp_from]'');
        main_delegate.setValue(newVal);
    },
    onBehalfTaskId: function(field, newValue, oldValue, eOpts) {
        Ext.global.console.log(''>>onBehalfTaskId'', field);
        this.leaveConfSet(field, newValue, oldValue, eOpts);
        Ext.global.console.log(''<<onBehalfTaskId'', field);
    },

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

        switch (newValue) {
        case ''creator_confirm'':
            leaveConf.show();
            break;
        case ''apv_ds2'':
            leaveConf.show();
            leaveConf.setReadOnly(true);
            break;
        }
        Ext.global.console.log(''<<leaveConfSet'', field);
    },

    onLeaveInbox: function(field, newValue, oldValue, eOpts) {
        Ext.global.console.log(''>>onLeaveInbox'', field);
        this.getStoreAbsence(field, newValue, oldValue, eOpts);
        Ext.global.console.log(''<<onLeaveInbox'', field);
    },

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

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

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

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

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

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

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

    getDelegate: function(field, newValue, oldValue, eOpts) {
        Ext.global.console.log(''<<getDelegate'', field);
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
        var me = this;
        Ext.Ajax.request({
            scope: me,
            url: ''/Workflow/LoadDataQuery'',
            method: ''POST'',
            params: {
                paramid: ''##Autofill_leave_delegate'',
                emp_id: newValue
            },
            success: function(response, opts) {
                var obj = Ext.decode(response.responseText).data;
                if (obj === undefined || obj.length === 0) return;
                try {
                    var cbDelegate = Body.down(''combo[name=list_of_delegate]'');
                    cbDelegate.store.loadData(obj);
                    if (MinovaUtil.WORKFLOW.getTaskId() === ''start'') {
                        cbDelegate.select(obj[0].emp_id);
                        Body.down(''textfield[name=delegate_delegate_id]'').setValue(obj[0].emp_id);
                        Body.down(''textfield[name=delegate_delegate_name]'').setValue(obj[0].fullname);
                        return;
                    }

                } catch (comp) {}
            },
            failure: function(response, opts) {
            }
        });
        me.changeDateRange(field, newValue, oldValue, eOpts);
        Ext.global.console.log(''>>getDelegate'', field);
    },

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

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

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

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

    },

    calculateCutiKhusus: function() {

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

        if (start_cuti !== '''' && end_cuti !== '''') {
            MinovaUtil.executeParamQuery({
                paramid: "leave_cuti_khusus_calculation",
                absence_type: absence_type,
                start_cuti: start_cuti,
                end_cuti: end_cuti,
                emp_id: MinovaUtil.WORKFLOW.getEmpId(),
                reg_id: MinovaUtil.WORKFLOW.getRegId()
            }, function(s) {
                var data = Ext.decode(s.responseText).data[0];
                var formLeave = Body.down(''form[name=Leave_Main]'').getForm();
                MinovaUtil.WORKFLOW.setViewBodyWorkflowFormContent(data);

            }, function(f) {});
        }

    },

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

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

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

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

    expandAbsenceType: function(field, eOpts) {
        Ext.global.console.log(''<<expandAbsenceType'', field);
        var me = this;
        field.store.load({
            params: {
                emp_id: me.up().down(''wf-request-formHeader textfield[name=employee_id]'').value
            }
        });
        Ext.global.console.log(''<<expandAbsenceType'', field);
    },

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

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

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

    calculate: function(field, newValue, oldValue, eOpts) {
        var reg = MinovaUtil.WORKFLOW.getRegId();
        var reg_id = 0;
        if (reg != "") {
            reg_id = parseInt(reg);
        }

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

            MinovaUtil.executeParamQuery({
                paramid: "leave_check_date",
                emp_id: empid,
                landscape: landscape,
                start_date: sdt,
                end_date: edt,
                reg_id: reg_id
            }, function(s) {
                var obj = Ext.decode(s.responseText);
                if (obj.data[0].res == ''1'') {
                    MinovaUtil.MESSAGE.error(obj.data[0].msg);
                    field.setValue('''');
                } else {
                    abc();
                }
            }, function(f) {});
        }

        function abc() {
            try {
                scombo = field.up().query(''combobox[name=main_absence_type]'')[0].valueModels[0].data;
                if (scombo.quotadeduction == ''Y'') {
                    var formLeave = MinovaUtil.WORKFLOW.getViewWorkflow().down(''form[name=Leave_Main]'').getForm();
                    if ((formLeave.getValues().main_absence_type !== '''') && (formLeave.getValues().main_start_date !== '''') && (formLeave.getValues().main_end_date !== '''')) {
                        me.leave_detail_and_block(formLeave);
                    }
                } else {
                    field.up(''panel[name=content]'').down(''form[name=Leave_Main]'').getForm().setValues({
                        main_quota_lb_cont_2: ''1'',
                        main_quota_lb_cont: ''1'',
                        main_quota_sded: '''',
                        main_quota_eded: '''',
                        main_quota_sded2: '''',
                        main_quota_eded2: '''',
                        main_quota_start_date_2: '''',
                        main_quota_end_date_2: '''',
                        main_quota_seq_2: '''',
                        main_leave_quota: 0,
                        main_remaining_quota: 0,
                        main_quota_taken: 0,
                        main_total_remaining_quota: 0,
                        main_leave_quota_2: 0,
                        main_remaining_quota_2: 0,
                        main_quota_taken_2: 0,
                        main_total_remaining_quota_2: 0

                    })

                    me.calculateCutiKhusus();
                }

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

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

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

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

            leaveCheckDate();

        }
    },

    getFormHeader: function() {
        Ext.global.console.log(''>>getFormHeader'');
        var formHeader = Ext.ComponentQuery.query(''wf-request-formHeader'')[0];
        if (formHeader !== undefined) {
            formHeader = Ext.ComponentQuery.query(''wf-request-formHeader'')[0].getForm().getValues();
        } else {
            formHeader = Ext.ComponentQuery.query(''wf-run-formHeader'')[0].getForm().getValues();
        }
        Ext.global.console.log(''<<getFormHeader'');
        return formHeader;
    },
    leave_detail_and_block: function(formLeave) {
        var formValue = formLeave.getValues();
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();

        var reg = MinovaUtil.WORKFLOW.getRegId();
        var reg_id = 0;
        if (reg !== "") {
            reg_id = parseInt(reg);
        }

        MinovaUtil.executeParamQuery({
            paramid: "leave_detail_and_block",
            absence_type: formValue.main_absence_type,
            start_cuti: formValue.main_start_date,
            end_cuti: formValue.main_end_date,
            emp_id: MinovaUtil.WORKFLOW.getEmpId(),
            reg_id: reg_id,
            leaveblock_ListAbsenceType: ''AL1|AL2|AL3|AL4''
        }, function(Sxhr) {
            var result = Ext.decode(Sxhr.responseText);
            var data = result.data[0];
            if (data.warning_type === ''1'') {
                MinovaUtil.MESSAGE.error(data.warning_text);
                body.down(''[name=main_start_date]'').setValue('''');
            } else {
                formLeave.setValues(data);
            }

        }, function(f) {});
    },
    validasiHariLibur: function(submit) {
        var taskID = MinovaUtil.WORKFLOW.getTaskId();
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
        var sdate = Body.down(''datefield[name=main_start_date]'').getValue();
        var edate = Body.down(''datefield[name=main_end_date]'').getValue();
        var me = this;

        if (MinovaUtil.WORKFLOW.isRequest() || taskID === ''start'' || taskID === ''create'') {
            MinovaUtil.executeParamQuery({
                paramid: ''check_wc_like_off_by_dates'',
                sdate: sdate,
                edate: edate
            }, function(s) {
                try {
                    var value = Ext.decode(s.responseText).data[0].value;
                    if (value) {
                        MinovaUtil.MESSAGE.error("Tanggal cuti yang anda ajukan jatuh pada hari libur, mohon diperiksa kembali.");
                        return;
                    }
                    me.validasiProrateCuti(submit);
                } catch (e) {}

            }, function(e) {});
        }
    },
    validasiProrateCuti: function(submit) {
        var taskID = MinovaUtil.WORKFLOW.getTaskId();
        var Body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
        var emp_id = MinovaUtil.WORKFLOW.getEmpId();
        var startCuti = Body.down(''datefield[name=main_start_date]'').getValue();
        var main_leave_quota = Body.down(''textfield[name=main_leave_quota]'').getValue();
        var main_total_remaining_quota = Body.down(''numberfield[name=main_total_remaining_quota]'').getValue();
        var totalCuti = parseInt(main_leave_quota) - parseInt(main_total_remaining_quota);

        if (MinovaUtil.WORKFLOW.isRequest() || taskID === ''start'' || taskID === ''create'') {
            MinovaUtil.executeParamQuery({
                paramid: ''validasi_lv_prorate_cuti'',
                emp_id: emp_id,
                startCuti: startCuti,
                totalCuti: totalCuti
            }, function(s) {
                try {
                    var warning = Ext.decode(s.responseText).data[0].warning;
                    if (warning === ''1'') {
                        var warning_text = Ext.decode(s.responseText).data[0].warning_text;
                        MinovaUtil.MESSAGE.error(warning_text);
                        return;
                    }
                    new submit();
                } catch (e) {}

            }, function(e) {});
        }
    },
    validasiHariLibur2: function(submit) {
        var taskID = MinovaUtil.WORKFLOW.getTaskId();

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

            if (quotadeduc === "Y" && totquotataken === 0) {
                MinovaUtil.MESSAGE.error("Cuti tidak dapat dilakukan pada hari libur");
            } else {
                submit();
            }
        }
    },

    onTask_apv_conf_dir_spv: function(me) {
        me.disableConfirmation();
    },
    onTask_apv_ds3: function(me) {
        me.disableConfirmation();
    },
    onTask_apv_dir_spv: function(me) {
        MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
    },
    onTask_apv_ds1: function(me) {
        MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
    },
    onTask_apv_direct_spv: function(me) {
        MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
    },
    onTask_apv_confirm_direct_spv: function(me) {
        me.disableConfirmation();
        MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
    },
    onTask_conf_cond_revise_date_apv_dir_spv: function(me) {
        me.disableConfirmation();
        MinovaUtil.WORKFLOW.setReadOnlyViewBodyWorkflow();
    },
    onTask_creator_confirm: function(me) {
        me.showConfirmation();
    },
    showConfirmation: function() {
        var view = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
        view.down(''[name=main_leave_confirmation]'').show();
        view.down(''[name=main_leave_confirmation]'').allowBlank = false;
    },
    disableConfirmation: function() {
        this.showConfirmation();
        var view = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
        view.down(''[name=main_leave_confirmation]'').setReadOnly(true);
        view.down(''[name=main_leave_confirmation]'').allowBlank = true;
    },
    validasi_cuti_tahunan: function(submit) {
        var me = MinovaUtil.WORKFLOW.loadControllerByViewClass(MinovaUtil.WORKFLOW.getViewBodyWorkflow().$className)
        var absenceType = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=main_absence_type]'').getValue();
        var start_date = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=main_start_date]'').getValue();
        var quota_type = MinovaUtil.WORKFLOW.getViewBodyWorkflow().down(''[name=main_quota_type]'').getValue();


        if (absenceType === ''1000'') {
            MinovaUtil.executeParamQuery({
                paramid: ''leave_cek_cuti_tahunan'',
                emp_id: MinovaUtil.WORKFLOW.getEmpId(),
                start_date: start_date,
                quota_type: quota_type
            }, function(s) {
                var data = Ext.decode(s.responseText).data[0]
                if (data.warning === ''1'') {
                    MinovaUtil.MESSAGE.error(data.warning_text);
                } else {
                    submit()
                }
            }, function(f) {})
        } else {
            me.leave_validation(submit)
        }
    },
    leave_validation: function(submit) {
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow()
        var absenceType = body.down(''[name=main_absence_type]'').getValue();
        var emp_id = MinovaUtil.WORKFLOW.getEmpId();
        var sdate = body.down(''[name=main_start_date]'').getValue();
        var qdec = body.down(''[name=main_quota_deduction]'').getValue();

        if (qdec == ''Y'') {
            submit();
        } else {
            MinovaUtil.executeParamQuery({
                paramid: ''leave_validation'',
                absence_type: absenceType,
                start_cuti: sdate,
                emp_id: emp_id,
                reg_id: MinovaUtil.WORKFLOW.getRegId()
            }, function(s) {
                var data = Ext.decode(s.responseText).data[0]
                if (data != null) {
                    if (data.warn > 0) {
                        MinovaUtil.MESSAGE.error(data.msg)
                    }
                } else {
                    submit()
                }
            }, function(f) {})
        }
    },
    ValidasiMaksimaPengajuan: function(submit) {
        var taskID = MinovaUtil.WORKFLOW.getTaskId();
		var BizprocId =  MinovaUtil.WORKFLOW.getBizprocId();
        var body = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
        var Sd = body.down(''[name=main_start_date]'').getValue();
        var Ed = body.down(''[name=main_end_date]'').getValue();
        var NDate = null;
		var izin = '''';
		var absence_type = body.down(''[name=main_absence_type]'').getValue();
		if (taskID==''start'' && BizprocId ==''leave''){
		MinovaUtil.executeParamQuery({
		paramid: ''ValidasiLeaveSetahun'',
		emp_id: MinovaUtil.WORKFLOW.getEmpId()
		}, function(s) {
		var result = Ext.decode(s.responseText);
		var data = result.data[0];
		var obju =data ;
		if (obju !== undefined){
			izin= obju.IZIN;
		}
		}, function(f) {})			
			if (absence_type !=''CL3''){
				if (izin == ''no'' || izin == '''') {
                MinovaUtil.MESSAGE.error("Anda belum diperkenankan untuk melakukan pengajuan cuti");
                body.down(''[name=main_start_date]'').setValue('''');
				}
			}
		}

		
		
        MinovaUtil.executeParamQuery({
            paramid: ''now_date''
        }, function(s) {
            var data = Ext.decode(s.responseText).data[0]
            if (data != null) {
                NDate = data.NowDate;
            } else {
                NDate = me.now8();
            }
        }, function(f) {})
        var Duration = this.GetDateDiff(Sd, NDate);

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

        var CountDt = null;
        MinovaUtil.executeParamQuery({
            paramid: ''wf_leave_get_absentype'',
            abs_type: abs_type
        }, function(s) {
            var data = Ext.decode(s.responseText).data[0]
            if (data != null) {
                CountDt = data.Res;
            }
        }, function(f) {})

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

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

    block_leave: function(val, field) {
        var wfv = MinovaUtil.WORKFLOW.getViewBodyWorkflow();
        var a = wfv.down(''textfield[name=main_quota_start_date_2]'');
        var a1 = wfv.down(''textfield[name=main_quota_start_date]'');
        var b = wfv.down(''textfield[name=main_quota_lb_cont_2]'');
        var b1 = wfv.down(''textfield[name=main_quota_lb_cont]'');
        var c = wfv.down(''textfield[name=main_total_remaining_quota_2]'');
        var c1 = wfv.down(''textfield[name=main_total_remaining_quota]'');
        var d1 = wfv.down(''[name=main_quota_taken]'');
        var d = wfv.down(''[name=main_quota_taken_2]'');
        var dt = wfv.down(''[name=main_total_quota_taken]'');
        var absenceType = wfv.down(''[name=main_absence_type]'');
        if (absenceType.getValue() === ''1000'') {
            if ((a.getValue() !== '''' || a.getValue() !== ''0'') && b.getValue() === ''0'' && c.getValue() < 5 && c.getValue() !== null) {
                if (c.getValue() < 5 && dt.getValue() < 5 && dt.getValue() !== null) {
                    return false;
                }
            } else if ((a.getValue() === '''' || a.getValue() === ''0'') && b1.getValue() === ''0'' && c1.getValue() < 5 && c1.getValue() !== null) {
                if (c1.getValue() < 5 && dt.getValue() < 5 && dt.getValue() !== null) {
                    return false;
                }
            }
        }

        return true;
    },
    block_leaveText: ''Block leave must be taken'',
    total_taken: function(val, field) {
        var lv_block = Ext.ComponentQuery.query(''textfield[name=main_block_contain]'')[0];
        try {
            var q_taken = Ext.ComponentQuery.query(''textfield[name=main_total_quota_taken]'')[0];
            var q_remain = Ext.ComponentQuery.query(''textfield[name=main_total_remaining_quota]'')[0];
            if (lv_block.value === "0") {
                try {
                    if (q_taken.value < 5 && q_remain.value < 5) {
                        return false;
                    }
                } catch (e) {}
            }
            if (lv_block.value === "1") {
                try {
                    if (q_taken.value >= 5) {
                        return false;
                    }
                } catch (e) {}
            }
        } catch (e) {}
        return true;
    },
    total_takenText: ''Types of absences are included in the block leave and unused. Mandatory quotas taken at least 5''
});
Ext.QuickTips.init();
' 
WHERE        (name = 'controller.wf.leave.leave')