Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
28 kB
1
Indexable
Never
/** autogenerated **/
/**
 *
 **/
Ext._define('rh.ac.dayactivity.DayActivityGrid', {
    extend: 'core.RestfulGrid',

    restWindow: 'rh.ac.dayactivity.DayActivityWindow',


    getColumnModel: function() {
        if(!this._columnModel)
            this._columnModel = Ext._create(
                'Ext.grid.ColumnModel',
                [   
                    // sm,
                    // new Ext.grid.CheckboxSelectionModel(),
                    // Ext._create('Ext.grid.RowNumberer'),
                    {header: 'Cod', dataIndex: 'pk', width: 50, hidden: true},
                    {header: 'Descricao', dataIndex: 'unicode', id: 'autoExpandColumn',hidden: true},
                    {header: 'Data', dataIndex: 'date', width: 90, renderer: Ext.util.Format.dateRenderer('d/m/Y')},
                    {header: 'Dia', dataIndex: 'date', width: 45, renderer: function(value) { 
                        var n = value.getDay();
                        var weekday = new Array(7);
                        weekday[0] = "DOM";
                        weekday[1] = "SEG";
                        weekday[2] = "TER";
                        weekday[3] = "QUA";
                        weekday[4] = "QUI";
                        weekday[5] = "SEX";
                        weekday[6] = "SAB";
                        var day = weekday[n];
                        return (day); }}, 
                    {header: 'Expedinte', dataIndex: 'office_hour', width: 100},
                    // {header: 'Entrada', dataIndex: 'ticket_in', width: 90},
                    // {header: 'Saída', dataIndex: 'ticket_out', width: 90},
                    {header: 'Registros', dataIndex:'input_output',width:150},
                    {header: 'Minutos atraso', dataIndex: 'delay', width: 90},
                    {header: 'Atraso compensado', dataIndex: 'authorized_delay', width: 120},
                    {header: 'Minutos acúmulo', dataIndex: 'accumulation', width: 120},
                    {header: 'Acúmulo autorizado', dataIndex: 'authorized_accumulation', width: 120},
                    {header: 'Observacão', dataIndex: 'observation', width: 120},
                    {header: 'Dia autorizado', dataIndex: 'status', width: 90, renderer: function(value) { return (value ? 'SIM' : 'NÃO'); }}
                    /*{header: 'Autorização', dataIndex: 'authorization_unicode', width: 90}*/
                    
                ]
            );

        return this._columnModel;
    },

    getFooterbar: function(cfg){
        if(!this._footerbar)
            this._footerbar = Ext._create('Ext.PagingToolbar', {
                style: cfg.footerStyle,
                store: this.getStore(),
                pageSize: 31,
                items: [
                    '-',
                    this.userTextToolBar(),
                    '->',
                    // this.getBalanceTextItem(),
                ]                
            });

        this.getStore().on({
                scope: this,
                load: function(st, records, options, grid){
                    var valor = 0;
                    var patronal = 0;
                    var desconto = 0;
                    var status = 1;
                    console.info(st) ;
                    console.info('atualizou') ;
                    st.each(
                        function(record) {
                            //console.info(st) ;
                        }
                    );
                    this.updateGridBalance('Saldo atual -> teste    ');
                    // alert('teste');
                }
            });

        return this._footerbar;
    },    
    
    getToolbar: function(cfg) {
        var downloadComponent; 
        
        if(!this._toolbar) {
            cfg = core.nullValue(cfg, {});
            Ext.apply(cfg, {gridAutoLoad: false,});
            this._toolbar = rh.ac.dayactivity.DayActivityGrid.superclass.getToolbar.call(this, cfg);
            /*this._toolbar.insert(this._toolbar.items.length,
                {
                    xtype: 'button',
                    text: 'Localizar',
                    iconCls: true,
                    icon: '/' + global.Context + '/static/images/find.png',
                    handler: this.setFilterParams,
                    scope: this
                },
                {
                    xtype: 'combo',
                    store: new Ext.data.JsonStore({
                        proxy: new Ext.data.HttpProxy({
                            url: toolkit.util.Normalize.controller_action('ACDayActivity', 'anos_ponto'),
                            disableCaching: true,
                            method: 'GET'
                        }),
                        baseParams: {employee: 0},
                        root: 'root',
                        fields: ['pk', 'description']
                    }),
                    displayField: 'description',
                    valueFeild: 'pk',
                    emptyText: 'Ano para filtro',
                    width: 140,
                    triggerAction: 'all',
                    listeners: {
                        scope: this,
                        select: function(combo, record) {
                            var store = this.getStore();
                           
                        },
                        focus: function(combo, record) {
                            var store = combo.getStore();
                            store.baseParams['employee'] = this.getParams().employee;
                            store.load({});
                            //console.info(combo);
                        }
                    }
                }
            );
            this._dateStartField = new Ext.form.DateField({
                emptyText: 'Início',
                format: 'd/m/Y',
                width: 90,
                enableKeyEvents: true,
                listeners: {
                    scope: this,
                    keypress: function(text, event) {
                        if (event.getCharCode() == event.RETURN || event.getCharCode() == event.TAB) {
                            this.setFilterParams();
                        }
                    }
                }
            });
            
            this._dateEndField = new Ext.form.DateField({
                emptyText: 'Fim',
                format: 'd/m/Y',
                width: 90,
                enableKeyEvents: true,
                listeners: {
                    scope: this,
                    keypress: function(text, event) {
                        if (event.getCharCode() == event.RETURN || event.getCharCode() == event.TAB) {
                            this.setFilterParams();
                        }
                    }
                }
            });*/

            
            /*this._toolbar.insert(7,
                '-'
            );*/
            /*this._toolbar.insert(8,
                this._dateStartField
            );
            this._toolbar.insert(9,
                this._dateEndField
            );*/
            this._toolbar.insert(10,
                '-'
            );
            this._toolbar.insert(15,
                this.getSelectYear()
            );
            this._toolbar.insert(16,
                '-'
            );
            this._toolbar.insert(17,
                this.getSelectMonth()
            );
            
            
        
            this._toolbar.insert(this._toolbar.items.length,
                {
                    xtype: 'button',
                    text: 'Autorizar Acumulo',
                    iconCls: true,
                    icon: '/' + global.Context + '/static/images/quest.png',
                    handler: this.authorized_accumulation_select,
                    scope: this
                }
            );
            this._toolbar.insert(14,
                '-'
            );
            
            this._toolbar.insert(this._toolbar.items.length,
                {
                    xtype: 'button',
                    text: 'Autorizar Compensação',
                    iconCls: true,
                    icon: '/' + global.Context + '/static/images/quest.png',
                    handler: this.authorized_dalay_select,
                    scope: this
                }
            );

            this._toolbar.insert(14,
                '-'
            );
            
            this._toolbar.insert(this._toolbar.items.length,
                {
                    xtype: 'button',
                    text: 'Recalcular Dias',
                    iconCls: true,
                    icon: '/' + global.Context + '/static/images/quest.png',
                    handler: this.recalculate_dalay_select,
                    scope: this
                }
            );
            

            
            
            this._toolbar.insert(this._toolbar.items.length,
                '->'
            );
            this._toolbar.insert(this._toolbar.items.length,
                '-'
            );
            this._toolbar.insert(this._toolbar.items.length,
                this.getBalanceTextItem()
            );
            this._toolbar.insert(this._toolbar.items.length,
                '-'
            );
            
        }
        return this._toolbar;
    },

    getBalanceTextItem: function(){
        if(!this.balanceText){
            this.balanceText= new Ext.Toolbar.TextItem({
                text: 'Saldo: 05:00',
                width: 400,
                style: {
                    'color': '#14950E',
                    'font-weight': 'bold'
                }
            });
        }
        return this.balanceText;
    },

    updateGridBalance: function(saldo) {
        this.loadBalance();
    },

    getSelectYear: function(){ 
        if(!this._SelectYear){
        this._SelectYear = Ext._create('Ext.form.ComboBox', {  
            store: new Ext.data.JsonStore({
                proxy: new Ext.data.HttpProxy({
                    url: toolkit.util.Normalize.controller_action('ACDayActivity', 'anos_ponto'),
                    disableCaching: true,
                    method: 'GET'
                }),
                baseParams: {employee: 0},
                root: 'root',
                fields: ['pk', 'description']
            }),
            displayField: 'description',
            valueField: 'pk',
            emptyText: 'Ano para filtro',
            width: 140,
            triggerAction: 'all',
            value:new Date().getFullYear(),
            listeners: {
                scope: this,
                select: function(combo, record) {
                    var store = this.getStore();
                    var params = this.getParams(); 
                    var value = params['employee'];
                    var params =[]

                    this.values[1] = record.get('pk')
                   
                    if(!this.values[0] && this.values[0] != 0){
                         this.values[0] = new Date().getMonth()+1
                    }
                    console.log(this.values)
                    
                    if(record.get('pk') != 0  && this.values[0] != 0){
                        params.push({'property': 'employee', 'value': value, 'stage': 1000});
                        params.push({'property': 'month_activity__year', 'value': record.get('pk'), 'stage': 1001});
                        params.push({'property': 'month_activity__month', 'value': this.values[0], 'stage': 1002});
                        this.setFilter(params)
                    }else{
                        params = []
                        if(this.values[0] == 0 && this.values[1] == 0){
                            params.push({'property': 'employee', 'value': value, 'stage': 1004});

                        }else if(this.values[0] == 0){
                            params.push({'property': 'employee', 'value': value, 'stage': 1004});
                            params.push({'property': 'month_activity__year', 'value': record.get('pk'), 'stage': 1001});
                        }else{
                            params.push({'property': 'employee', 'value': value, 'stage': 1004});
                            params.push({'property': 'month_activity__month', 'value': this.values[0], 'stage': 1002});
                        }
                       
                        this.setFilter(params)
                    }
                    store.baseParams['limit'] = 31;
                    store.load({});
                
                },
                focus: function(combo, record) {
                    var store = combo.getStore();
                    store.baseParams['employee'] = this.getParams().employee;
                    console.log(this.getParams())
                    store.load({});
                }
            }
        });
    }
        return this._SelectYear
    },

    getSelectMonth: function(){
    if(!this._SelectMonth){
       this._SelectMonth = Ext._create('Ext.form.ComboBox', {
            store: [
                [ 0, 'TODOS'],
                [ 1, 'JANEIRO'],
                [ 2, 'FEVEREIRO'],
                [ 3, 'MARÇO'],
                [ 4, 'ABRIL'],
                [ 5, 'MAIO'],
                [ 6, 'JUNHO'],
                [ 7, 'JULHO'],
                [ 8, 'AGOSTO'],
                [ 9, 'SETEMBRO'],
                [10, 'OUTUBRO'],
                [11, 'NOVEMBRO'],
                [12, 'DEZEMBRO'],
            ],
            emptyText: 'Mês para filtro',
            width: 140,
            triggerAction: 'all',
            value:new Date().getMonth()+1,
            listeners: {
                scope: this,
                
                select: function(combo, record) {
                    var store = this.getStore();
                    var params = this.getParams(); 
                    var value = params['employee'];
                    console.log(this.getParams())
                    var params =[]

                    this.values[0] = record.get('field1')

                    if(!this.values[1] && this.values[1] != 0){
                        this.values[1] = new Date().getFullYear()
                    }

                    console.log(this.values)

                    
                    if(record.get('field1') != 0 && this.values[1] != 0){
                        params.push({'property': 'employee', 'value': value, 'stage': 1006});
                        params.push({'property': 'month_activity__year', 'value': this.values[1], 'stage': 1008});
                        params.push({'property': 'month_activity__month', 'value': record.get('field1'), 'stage': 1007});
                        this.setFilter(params);
                    
                        console.log(this.getSelectYear());
                        this.getSelectYear().setValue('Todos');
                        console.log(this.getSelectYear());
                    }else{
                        params = []
                        if (this.values[1] == 0 && this.values[0] == 0){
                            params.push({'property': 'employee', 'value': value, 'stage': 1004});
                        }else if(this.values[1] == 0){
                            params.push({'property': 'employee', 'value': value, 'stage': 1004});
                            params.push({'property': 'month_activity__month', 'value': record.get('field1'), 'stage': 1007});
                        }else{
                            params.push({'property': 'employee', 'value': value, 'stage': 1004});
                            params.push({'property': 'month_activity__year', 'value': this.values[1], 'stage': 1002});
                        }
                        
                        this.setFilter(params)
                    }
                    store.baseParams['limit'] = 31;
                    store.load({});
                }
            }
        });
    }
        return this._SelectMonth
    },

    authorized_accumulation_select: function(){ 
        var selection = this.getSelectionModel().getSelections();
        var mask = new Ext.LoadMask(this.getEl(), {msg: 'Buscando informações ...'});
        
        if(selection.length > 0) {
            rest = this.factoryRestful();
            pkset = selection.map(function(data) {
                return data.get('pk');
            });
            
            rest.doRequest(
                rest.getRoute('authorized_dayactivity_select', false, 'POST', {
                    scope: this,
                    params: {
                        pk__in: pkset , 
                        n_call : 1
                    },
                    callback: function() {
                        mask.hide();
                        mask = undefined;
                    },
                    success: function(xhr) {
                        var rst = Ext.decode(xhr.responseText);

                        if(rst.success) {
                            Ext.Msg.show({
                                title: 'Autorizar Acumulo',
                                icon: Ext.Msg.INFO,
                                buttons: Ext.Msg.OK,
                                msg: rst.message
                            });
                            this.getStore().reload();
                            
                        }
                        else
                            Ext.Msg.show({
                                title: 'Atenção',
                                icon: Ext.Msg.ERROR,
                                buttons: Ext.Msg.OK,
                                msg: rst.message
                            });
                    },
                    failure: function(xhr) {
                        Ext.Msg.show({
                            title: 'Atenção',
                            icon: Ext.Msg.ERROR,
                            buttons: Ext.Msg.OK,
                            msg: 'Recurso indisponível no momento.'
                        });
                    },
                })
            );
        }
        else {
            Ext.Msg.show({
                title: 'Atenção',
                icon: Ext.Msg.ERROR,
                buttons: Ext.Msg.OK,
                msg: 'Primeiro selecione um ou mais itens!'
            });
        }
    },
    
    authorized_dalay_select : function(){ 
        var selection = this.getSelectionModel().getSelections();
        var mask = new Ext.LoadMask(this.getEl(), {msg: 'Buscando informações...'});
        if(selection.length > 0) {
            rest = this.factoryRestful();
            pkset = selection.map(function(data) {
                return data.get('pk');
            });
            rest.doRequest(
                rest.getRoute('authorized_dayactivity_select', false, 'POST', {
                    scope: this,
                    params: {
                        pk__in: pkset , 
                        n_call : 2
                    },
                    callback: function() {
                        mask.hide();
                        mask = undefined;
                    },
                    success: function(xhr) {
                        var rst = Ext.decode(xhr.responseText);

                        if(rst.success) {
                            Ext.Msg.show({
                                title: 'Autorizar Compensação',
                                icon: Ext.Msg.INFO,
                                buttons: Ext.Msg.OK,
                                msg: rst.message
                            });
                            this.getStore().reload();
                            
                        }
                        else
                            Ext.Msg.show({
                                title: 'Atenção',
                                icon: Ext.Msg.ERROR,
                                buttons: Ext.Msg.OK,
                                msg: rst.message
                            });
                    },
                    failure: function(xhr) {
                        Ext.Msg.show({
                            title: 'Atenção',
                            icon: Ext.Msg.ERROR,
                            buttons: Ext.Msg.OK,
                            msg: 'Recurso indisponível no momento.'
                        });
                    },
                })
            );
        }
        else {
            Ext.Msg.show({
                title: 'Atenção',
                icon: Ext.Msg.ERROR,
                buttons: Ext.Msg.OK,
                msg: 'Primeiro selecione um ou mais itens!'
            });
        }
    },

    recalculate_dalay_select : function(){ 
        var selection = this.getSelectionModel().getSelections();
        var mask = new Ext.LoadMask(this.getEl(), {msg: 'Buscando informações...'});
        if(selection.length > 0) {
            rest = this.factoryRestful();
            pkset = selection.map(function(data) {
                return data.get('pk');
            });
            rest.doRequest(
                rest.getRoute('recalculate_dayactivity_select', false, 'POST', {
                    scope: this,
                    params: {
                        pk__in: pkset
                    },
                    callback: function() {
                        mask.hide();
                        mask = undefined;
                    },
                    success: function(xhr) {
                        var rst = Ext.decode(xhr.responseText);

                        if(rst.success) {
                            Ext.Msg.show({
                                title: 'Autorizar Compensação',
                                icon: Ext.Msg.INFO,
                                buttons: Ext.Msg.OK,
                                msg: rst.message
                            });
                            this.getStore().reload();
                            
                        }
                        else
                            Ext.Msg.show({
                                title: 'Atenção',
                                icon: Ext.Msg.ERROR,
                                buttons: Ext.Msg.OK,
                                msg: rst.message
                            });
                    },
                    failure: function(xhr) {
                        Ext.Msg.show({
                            title: 'Atenção',
                            icon: Ext.Msg.ERROR,
                            buttons: Ext.Msg.OK,
                            msg: 'Recurso indisponível no momento.'
                        });
                    },
                })
            );
        }
        else {
            Ext.Msg.show({
                title: 'Atenção',
                icon: Ext.Msg.ERROR,
                buttons: Ext.Msg.OK,
                msg: 'Primeiro selecione um ou mais itens!'
            });
        }
    },

    setFilterParams: function(){

        var store = this.getStore();
       
        var dateStart = Ext.util.Format.date(this._dateStartField.getValue(), 'Y-m-d');
        var dateEnd = Ext.util.Format.date(this._dateEndField.getValue(), 'Y-m-d');
        
        var params = this.getParams(); 
        var value = params['employee'];
        console.log(value)

        var params =[]

        params.push({'property': 'employee', 'value': value, 'stage': 1000});

        if(dateStart !== '' && dateEnd === ''){
            params.push({'property': 'date__gte', 'value': dateStart, 'stage': 1001});
        }else if(dateEnd !== '' && dateStart === ''){
            params.push({'property': 'date__lte', 'value': dateEnd, 'stage': 1001});
        }else if(dateStart !== '' && dateEnd !== ''){
            params.push({'property': 'date__gte', 'value': dateStart, 'stage': 1001});
            params.push({'property': 'date__lte', 'value': dateEnd, 'stage': 1002});
           
        }
        
        this.setFilter(params);
    }, 

    userTextToolBar: function(){
    	if(!this._userTextToolBar){
    		this._userTextToolBar = new Ext.form.DisplayField({
    			value: '',
    			width: 200,
    		});
    	}
    	return this._userTextToolBar;
    },



    getSaldoTextItem: function(){
        if(!this.saldoText){
            this.saldoText= new Ext.Toolbar.TextItem({
                text: 'Saldo disponivel referente ao periodo 00/0000 : 000000',
                width: 135,
                style: {
                    'color': '#15428B',
                    'font-weight': 'bold'
                }
            });
        }
        return this.saldoText;
    },

        loadBalance: function() {
            var rest = this.factoryRestful();
            var mask = new Ext.LoadMask(this.getEl(), {msg: 'Buscando informações de saldo...'});
            var parametros = this.getParams(); 
            var employee = parametros['employee'];

            mask.show();
            rest.doRequest(
                rest.getRoute('get_balance_employee', false, 'GET', {
                    scope: this,
                    params: {
                        employee: employee,
                    },
                    callback: function() {
                        mask.hide();
                        mask = undefined;
                    },
                    success: function(xhr) {
                        var rst = Ext.decode(xhr.responseText);

                        if(rst.success) {
                            this.getBalanceTextItem().setText('Saldo referente ao periodo ' +rst.month_reference+ '/'+ rst.year_reference + ' : ' + rst.saldo);
                            // alert(rst.saldo);
                            // this.ownerGrid.getStore().reload();
                            // this.getFormPanel().getForm().setValues(rst.instance);
                        }
                        // else
                        // console.log(rst);
                        //     // this.getFormPanel().disable();
                    },
                    failure: function() {
                        Ext.Msg.show({
                            title: 'Buscando informações',
                            icon: Ext.Msg.ERROR,
                            buttons: Ext.Msg.OK,
                            msg: 'Recurso indisponivel no momento.'
                        });

                        // this.close();
                    }
                })      
            );
        },
    


    constructor: function(cfg) {
        this.values = []
        cfg = core.nullValue(cfg, {});
            Ext.applyIf(cfg, {
                // sm: sm,
                viewConfig: {
                    getRowClass: function(record, rowIndex, rp, ds) { // rp = rowParams
                    if(record.data.delay > 0 && record.data.authorized_delay < record.data.delay &&  record.data.authorized_delay == 0 ){
                        return 'rowRed';   
                    }else if (record.data.delay > 0 && record.data.authorized_delay < record.data.delay &&  record.data.authorized_delay > 0){
                        return 'rowYellow';
                    }else{ 
                        return 'rowGreen';
                    }
                },


            },    
        

       });
       rh.ac.dayactivity.DayActivityGrid.superclass.constructor.call(this, cfg);
       
   
   },

});



core.RestfulGrid.register(
    'rh.ac.dayactivity.DayActivityRestful',
    'rh.ac.dayactivity.DayActivityGrid'
);