|  | @@ -0,0 +1,430 @@
 | 
											
												
													
														|  | 
 |  | +function ranking_pos_orders_product_cy (reporting) {
 | 
											
												
													
														|  | 
 |  | +    "use strict";
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    var instance = openerp;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    reporting.RankingPosOrdersProductcyWidget = reporting.Base.extend({
 | 
											
												
													
														|  | 
 |  | +        template: 'RankingPosOrdersProductcy',
 | 
											
												
													
														|  | 
 |  | +        data: [],
 | 
											
												
													
														|  | 
 |  | +        accountInvoice: [],
 | 
											
												
													
														|  | 
 |  | +        invoiceLine: [],
 | 
											
												
													
														|  | 
 |  | +        productProduct: [],
 | 
											
												
													
														|  | 
 |  | +        ranking: [],
 | 
											
												
													
														|  | 
 |  | +        content: [],
 | 
											
												
													
														|  | 
 |  | +        modelId: [],
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        events:{
 | 
											
												
													
														|  | 
 |  | +            'click #toolbar > button' : 'clickOnAction',
 | 
											
												
													
														|  | 
 |  | +            'click #X' : 'factSearch',
 | 
											
												
													
														|  | 
 |  | +            'click #A' : 'factSearch',
 | 
											
												
													
														|  | 
 |  | +            'click #B' : 'factSearch',
 | 
											
												
													
														|  | 
 |  | +            'click #C' : 'factSearch',
 | 
											
												
													
														|  | 
 |  | +            'click #D' : 'factSearch',
 | 
											
												
													
														|  | 
 |  | +            'click #Z' : 'factSearch',
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            'click #Y' : 'factSearch',
 | 
											
												
													
														|  | 
 |  | +            'change #from' : 'factSearch',
 | 
											
												
													
														|  | 
 |  | +            'change #to' : 'factSearch',
 | 
											
												
													
														|  | 
 |  | +            'click-row.bs.table #table ' : 'clickAnalysisDetail',
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        init : function(parent){
 | 
											
												
													
														|  | 
 |  | +            this._super(parent);
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        start: function () {
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            var table = this.$el.find('#table');
 | 
											
												
													
														|  | 
 |  | +            table.bootstrapTable({data : self.rowsData});
 | 
											
												
													
														|  | 
 |  | +            this.fecthFecha();
 | 
											
												
													
														|  | 
 |  | +            this.submitForm();
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        // Redirecionar
 | 
											
												
													
														|  | 
 |  | +        renderReport: function () {
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
 | 
											
												
													
														|  | 
 |  | +            this.$el.closest('.report_view').remove();
 | 
											
												
													
														|  | 
 |  | +            container.find('.report_view').show({
 | 
											
												
													
														|  | 
 |  | +                effect: 'fade',
 | 
											
												
													
														|  | 
 |  | +                duration: 200,
 | 
											
												
													
														|  | 
 |  | +            });
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        // Verificar el modelo
 | 
											
												
													
														|  | 
 |  | +        checkModel : function(model){
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            return _.filter(self.modules,function(item){return item.name === model});
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        // Lanzar el mensaje
 | 
											
												
													
														|  | 
 |  | +        showMensaje : function(modelos){
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            $("#dialog" ).dialog({
 | 
											
												
													
														|  | 
 |  | +                autoOpen: true,
 | 
											
												
													
														|  | 
 |  | +                resizable: false,
 | 
											
												
													
														|  | 
 |  | +                modal: true,
 | 
											
												
													
														|  | 
 |  | +                title: 'Atención',
 | 
											
												
													
														|  | 
 |  | +                width: 500,
 | 
											
												
													
														|  | 
 |  | +                open: function() {
 | 
											
												
													
														|  | 
 |  | +                    $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
 | 
											
												
													
														|  | 
 |  | +                },
 | 
											
												
													
														|  | 
 |  | +                show: {
 | 
											
												
													
														|  | 
 |  | +                    effect: "fade",
 | 
											
												
													
														|  | 
 |  | +                    duration: 200
 | 
											
												
													
														|  | 
 |  | +                },
 | 
											
												
													
														|  | 
 |  | +                hide: {
 | 
											
												
													
														|  | 
 |  | +                    effect: "fade",
 | 
											
												
													
														|  | 
 |  | +                    duration: 200
 | 
											
												
													
														|  | 
 |  | +                },
 | 
											
												
													
														|  | 
 |  | +                buttons: {
 | 
											
												
													
														|  | 
 |  | +                    Aceptar: function() {
 | 
											
												
													
														|  | 
 |  | +                        $(this).dialog('close');
 | 
											
												
													
														|  | 
 |  | +                        self.renderReport()
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +            });
 | 
											
												
													
														|  | 
 |  | +            return
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        submitForm: function () {
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            self.fecthIrModuleModule().then(function(modules){
 | 
											
												
													
														|  | 
 |  | +                self.modules = modules;
 | 
											
												
													
														|  | 
 |  | +                return modules;
 | 
											
												
													
														|  | 
 |  | +            }).then(function(modules){
 | 
											
												
													
														|  | 
 |  | +                return self.fecthPosOrder();
 | 
											
												
													
														|  | 
 |  | +            }).then(function (PosOrder) {
 | 
											
												
													
														|  | 
 |  | +                self.PosOrder = PosOrder;
 | 
											
												
													
														|  | 
 |  | +                return self.fecthPosOrderLine(PosOrder);
 | 
											
												
													
														|  | 
 |  | +            }).then(function (PosOrderLine) {
 | 
											
												
													
														|  | 
 |  | +                self.PosOrderLine = PosOrderLine;
 | 
											
												
													
														|  | 
 |  | +                return self.fecthProductProduct(PosOrderLine);
 | 
											
												
													
														|  | 
 |  | +            }).then(function(productProduct){
 | 
											
												
													
														|  | 
 |  | +                self.productProduct = productProduct;
 | 
											
												
													
														|  | 
 |  | +                return self.fetchProductRanking();
 | 
											
												
													
														|  | 
 |  | +            });
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        // Modelos instalados
 | 
											
												
													
														|  | 
 |  | +        fecthIrModuleModule: function(){
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            var defer = $.Deferred();
 | 
											
												
													
														|  | 
 |  | +            var fields = ['name','id'];
 | 
											
												
													
														|  | 
 |  | +            var domain=[['state','=','installed']];
 | 
											
												
													
														|  | 
 |  | +            var irModule = new instance.web.Model('ir.module.module');
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            irModule.query(fields).filter(domain).all().then(function(results){
 | 
											
												
													
														|  | 
 |  | +                defer.resolve(results);
 | 
											
												
													
														|  | 
 |  | +            });
 | 
											
												
													
														|  | 
 |  | +            return defer;
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        fecthFecha: function() {
 | 
											
												
													
														|  | 
 |  | +            var to;
 | 
											
												
													
														|  | 
 |  | +            var dateFormat1 = "mm/dd/yy",
 | 
											
												
													
														|  | 
 |  | +            from = $( "#from" )
 | 
											
												
													
														|  | 
 |  | +            .datepicker({
 | 
											
												
													
														|  | 
 |  | +                dateFormat: "dd/mm/yy",
 | 
											
												
													
														|  | 
 |  | +                changeMonth: true,
 | 
											
												
													
														|  | 
 |  | +                numberOfMonths: 1,
 | 
											
												
													
														|  | 
 |  | +            })
 | 
											
												
													
														|  | 
 |  | +            .on( "change", function() {
 | 
											
												
													
														|  | 
 |  | +                to.datepicker( "option", "minDate", getDate(this), "dd/mm/yyyy");
 | 
											
												
													
														|  | 
 |  | +            });
 | 
											
												
													
														|  | 
 |  | +            to = $( "#to" ).datepicker({
 | 
											
												
													
														|  | 
 |  | +                dateFormat: "dd/mm/yy",
 | 
											
												
													
														|  | 
 |  | +                defaultDate: "+7d",
 | 
											
												
													
														|  | 
 |  | +                changeMonth: true,
 | 
											
												
													
														|  | 
 |  | +                numberOfMonths: 1,
 | 
											
												
													
														|  | 
 |  | +            })
 | 
											
												
													
														|  | 
 |  | +            .on( "change", function() {
 | 
											
												
													
														|  | 
 |  | +                from.datepicker( "option", "maxDate", getDate(this));
 | 
											
												
													
														|  | 
 |  | +            });
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            function getDate( element ) {
 | 
											
												
													
														|  | 
 |  | +                var fechaSel =element.value.split('/');
 | 
											
												
													
														|  | 
 |  | +                var date;
 | 
											
												
													
														|  | 
 |  | +                try {
 | 
											
												
													
														|  | 
 |  | +                    date = $.datepicker.parseDate( dateFormat1, (fechaSel[1]+"/"+fechaSel[0]+"/"+fechaSel[2]));
 | 
											
												
													
														|  | 
 |  | +                } catch( error ) {
 | 
											
												
													
														|  | 
 |  | +                    date = null;
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                return date;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        // Obtener Pedido
 | 
											
												
													
														|  | 
 |  | +        fecthPosOrder: function() {
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            var desde = moment().format('YYYY-MM-01 00:00:00');
 | 
											
												
													
														|  | 
 |  | +            var hasta = moment().add(1,'months').format('YYYY-MM-01 00:00:00');
 | 
											
												
													
														|  | 
 |  | +            var defer = $.Deferred();
 | 
											
												
													
														|  | 
 |  | +            var modules = self.checkModel('point_of_sale');
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if (modules.length <= 0){
 | 
											
												
													
														|  | 
 |  | +                self.showMensaje('point_of_sale');
 | 
											
												
													
														|  | 
 |  | +                return defer;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var fields = ['id', 'lines', 'date_order'];
 | 
											
												
													
														|  | 
 |  | +            var domain = [['date_order', '>=', desde], ['date_order', '<', hasta], ['state', 'in', ['paid','done','invoiced']]];
 | 
											
												
													
														|  | 
 |  | +            var PosOrder = new model.web.Model('pos.order');
 | 
											
												
													
														|  | 
 |  | +            PosOrder.query(fields).filter(domain).all().then(function (results) {
 | 
											
												
													
														|  | 
 |  | +                defer.resolve(results);
 | 
											
												
													
														|  | 
 |  | +            });
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            return defer;
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        // Obtener linea de la factura
 | 
											
												
													
														|  | 
 |  | +        fecthPosOrderLine: function(PosOrder) {
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            var defer = $.Deferred();
 | 
											
												
													
														|  | 
 |  | +            var lines = _.flatten(_.map(PosOrder, function (item) {
 | 
											
												
													
														|  | 
 |  | +                return item.lines;
 | 
											
												
													
														|  | 
 |  | +            }));
 | 
											
												
													
														|  | 
 |  | +            var fields = ['id', 'product_id', 'qty'];
 | 
											
												
													
														|  | 
 |  | +            var domain = [['id','in', lines]];
 | 
											
												
													
														|  | 
 |  | +            var PosOrderLine = new model.web.Model('pos.order.line');
 | 
											
												
													
														|  | 
 |  | +            PosOrderLine.query(fields).filter(domain).all().then(function (results) {
 | 
											
												
													
														|  | 
 |  | +                defer.resolve(results);
 | 
											
												
													
														|  | 
 |  | +            });
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            return defer;
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        // Obtener Productos
 | 
											
												
													
														|  | 
 |  | +        fecthProductProduct: function (PosOrderLine) {
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            var defer = $.Deferred();
 | 
											
												
													
														|  | 
 |  | +            var product_id = _.flatten(_.map(PosOrderLine,function (item) {
 | 
											
												
													
														|  | 
 |  | +                return item.product_id[0];
 | 
											
												
													
														|  | 
 |  | +            }));
 | 
											
												
													
														|  | 
 |  | +            var fields = ['id', 'name_template', 'type','attribute_str'];
 | 
											
												
													
														|  | 
 |  | +            var domain = [['id', 'in', product_id]];
 | 
											
												
													
														|  | 
 |  | +            var ProductProduct = new model.web.Model('product.product');
 | 
											
												
													
														|  | 
 |  | +            ProductProduct.query(fields).filter(domain).all().then(function (results) {
 | 
											
												
													
														|  | 
 |  | +                defer.resolve(results);
 | 
											
												
													
														|  | 
 |  | +            });
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            return defer;
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        // get line
 | 
											
												
													
														|  | 
 |  | +        getPosOrderLine: function (product_id) {
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            return _.flatten(_.filter(self.PosOrderLine,function (item) {
 | 
											
												
													
														|  | 
 |  | +                return item.product_id[0] === product_id
 | 
											
												
													
														|  | 
 |  | +            }));
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        // Generear el ranking
 | 
											
												
													
														|  | 
 |  | +        fetchProductRanking: function() {
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            var itemProduct;
 | 
											
												
													
														|  | 
 |  | +            var itemLine;
 | 
											
												
													
														|  | 
 |  | +            var ranking = [];
 | 
											
												
													
														|  | 
 |  | +            var cat = 0;
 | 
											
												
													
														|  | 
 |  | +            var attribute;
 | 
											
												
													
														|  | 
 |  | +            var lineUnik;
 | 
											
												
													
														|  | 
 |  | +            console.log(self.productProduct);
 | 
											
												
													
														|  | 
 |  | +            for (var i = 0; i < self.productProduct.length; i++) {
 | 
											
												
													
														|  | 
 |  | +                itemProduct = self.productProduct[i];
 | 
											
												
													
														|  | 
 |  | +                itemLine = self.getPosOrderLine(itemProduct.id);
 | 
											
												
													
														|  | 
 |  | +                if (itemLine.length > 0) {
 | 
											
												
													
														|  | 
 |  | +                    cat = _.reduce(_.map(itemLine, function (map) {
 | 
											
												
													
														|  | 
 |  | +                        return map.qty
 | 
											
												
													
														|  | 
 |  | +                    }), function (meno,num) {
 | 
											
												
													
														|  | 
 |  | +                        return meno + num
 | 
											
												
													
														|  | 
 |  | +                    }, 0);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    lineUnik = itemLine.shift();
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    if(itemProduct.attribute_str){
 | 
											
												
													
														|  | 
 |  | +                        attribute = '*' + itemProduct.attribute_str;
 | 
											
												
													
														|  | 
 |  | +                    }else{
 | 
											
												
													
														|  | 
 |  | +                        attribute = ' ';
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                    ranking.push({
 | 
											
												
													
														|  | 
 |  | +                        product: itemProduct.name_template + ' ' + attribute,
 | 
											
												
													
														|  | 
 |  | +                        qty: cat,
 | 
											
												
													
														|  | 
 |  | +                        id: lineUnik.product_id[0],
 | 
											
												
													
														|  | 
 |  | +                        type: itemProduct.type
 | 
											
												
													
														|  | 
 |  | +                    });
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            // ranking.sort(function(a, b) {
 | 
											
												
													
														|  | 
 |  | +            //     return b.qty - a.qty
 | 
											
												
													
														|  | 
 |  | +            // });
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            self.content = data;
 | 
											
												
													
														|  | 
 |  | +            this.loadTable(data);
 | 
											
												
													
														|  | 
 |  | +            // self.$el.unblock();
 | 
											
												
													
														|  | 
 |  | +            // self.$el.find('.widget-content.widget-loading').css('display','none');
 | 
											
												
													
														|  | 
 |  | +            // var fecha = new Date();
 | 
											
												
													
														|  | 
 |  | +            // var meses = new Array ("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
 | 
											
												
													
														|  | 
 |  | +            // self.$el.find('.widget-title').find('span').text("Ranking de productos y servicios del mes de " + meses[fecha.getMonth()]);
 | 
											
												
													
														|  | 
 |  | +            // self.ranking = ranking;
 | 
											
												
													
														|  | 
 |  | +            // self.fetchChart(ranking);
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        factSearch: function(){
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            var hoy = moment().format('YYYY-MM-DD');
 | 
											
												
													
														|  | 
 |  | +            var desde =this.$el.find('#from').val();
 | 
											
												
													
														|  | 
 |  | +            var hasta =this.$el.find('#to').val();
 | 
											
												
													
														|  | 
 |  | +            var content = self.content;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if ($('#A').is(":checked")){
 | 
											
												
													
														|  | 
 |  | +                content = _.filter(content, function (inv){
 | 
											
												
													
														|  | 
 |  | +                    return inv.date == hoy;
 | 
											
												
													
														|  | 
 |  | +                });
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            if ($('#B').is(":checked")){
 | 
											
												
													
														|  | 
 |  | +                var date = hoy.split('-');
 | 
											
												
													
														|  | 
 |  | +                var ayer = date[2] - 1;
 | 
											
												
													
														|  | 
 |  | +                date.splice(2,0);
 | 
											
												
													
														|  | 
 |  | +                date[2] = '0'+ayer;
 | 
											
												
													
														|  | 
 |  | +                content = _.filter(content, function (inv){
 | 
											
												
													
														|  | 
 |  | +                    return inv.date == date[0]+'-'+date[1]+'-'+date[2];
 | 
											
												
													
														|  | 
 |  | +                });
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            if ($('#C').is(":checked")){
 | 
											
												
													
														|  | 
 |  | +                var date = hoy.split('-');
 | 
											
												
													
														|  | 
 |  | +                content = _.filter(content, function (inv){
 | 
											
												
													
														|  | 
 |  | +                    var mes = inv.date.split('-');
 | 
											
												
													
														|  | 
 |  | +                    return mes[0]+'-'+mes[1] == date[0]+'-'+date[1];
 | 
											
												
													
														|  | 
 |  | +                });
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            if ($('#D').is(":checked")){
 | 
											
												
													
														|  | 
 |  | +                var date = hoy.split('-');
 | 
											
												
													
														|  | 
 |  | +                var mes = date[1] - 1;
 | 
											
												
													
														|  | 
 |  | +                var year;
 | 
											
												
													
														|  | 
 |  | +                date.splice(1,0);
 | 
											
												
													
														|  | 
 |  | +                if(date[1] == 1){
 | 
											
												
													
														|  | 
 |  | +                    date[1] = '12';
 | 
											
												
													
														|  | 
 |  | +                    year = date[0] - 1;
 | 
											
												
													
														|  | 
 |  | +                    date[0] = year;
 | 
											
												
													
														|  | 
 |  | +                }else{
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                 if(date[1] < 10){
 | 
											
												
													
														|  | 
 |  | +                     date[1] = '0'+mes;
 | 
											
												
													
														|  | 
 |  | +                 }else{
 | 
											
												
													
														|  | 
 |  | +                     date[1] = mes;
 | 
											
												
													
														|  | 
 |  | +                 }
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                content = _.filter(content, function (inv){
 | 
											
												
													
														|  | 
 |  | +                    var mes = inv.date.split('-');
 | 
											
												
													
														|  | 
 |  | +                    return mes[0]+'-'+mes[1] == date[0]+'-'+date[1];
 | 
											
												
													
														|  | 
 |  | +                });
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            if ($('#Z').is(":checked")){
 | 
											
												
													
														|  | 
 |  | +                $('#datepicker').css('display','block');
 | 
											
												
													
														|  | 
 |  | +                if (desde.length > 0){
 | 
											
												
													
														|  | 
 |  | +                    var date= desde.split('/');
 | 
											
												
													
														|  | 
 |  | +                    content = _.filter(content, function (inv){
 | 
											
												
													
														|  | 
 |  | +                        return inv.date >= (date[2]+"-"+date[1]+"-"+date[0]);
 | 
											
												
													
														|  | 
 |  | +                    });
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                if (hasta.length > 0){
 | 
											
												
													
														|  | 
 |  | +                    var date= hasta.split('/');
 | 
											
												
													
														|  | 
 |  | +                    content = _.filter(content, function (inv){
 | 
											
												
													
														|  | 
 |  | +                        return inv.date <= (date[2]+"-"+date[1]+"-"+date[0]);
 | 
											
												
													
														|  | 
 |  | +                    });
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +            }else{
 | 
											
												
													
														|  | 
 |  | +                $('#datepicker').css('display','none');
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            self.loadTable(content)
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        loadTable:function(rowsTable){
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            self.rowsData = rowsTable;
 | 
											
												
													
														|  | 
 |  | +            var table = this.$el.find('#table');
 | 
											
												
													
														|  | 
 |  | +            table.bootstrapTable('load',rowsTable);
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        getObjetPdf: function(rowsTable){
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            var rows=self.rowsData;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            return rows;
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        clickOnAction: function (e) {
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            var rowsNew;
 | 
											
												
													
														|  | 
 |  | +            var action = self.$el.find(e.target).val();
 | 
											
												
													
														|  | 
 |  | +            var table = self.$el.find("#table");
 | 
											
												
													
														|  | 
 |  | +            var data2 = table.bootstrapTable('getVisibleColumns');
 | 
											
												
													
														|  | 
 |  | +            var getColumns=[];
 | 
											
												
													
														|  | 
 |  | +            var rows=[];
 | 
											
												
													
														|  | 
 |  | +            rowsNew = self.getObjetPdf();
 | 
											
												
													
														|  | 
 |  | +            if (action === 'pdf') {
 | 
											
												
													
														|  | 
 |  | +                var dataNEW = _.map(data2, function (val){
 | 
											
												
													
														|  | 
 |  | +                    return val.field;
 | 
											
												
													
														|  | 
 |  | +                });
 | 
											
												
													
														|  | 
 |  | +                _.each(rowsNew,function (item){
 | 
											
												
													
														|  | 
 |  | +                    rows.push(_.pick(item, dataNEW));
 | 
											
												
													
														|  | 
 |  | +                });
 | 
											
												
													
														|  | 
 |  | +                // Obtener los nombre de la Cabezera
 | 
											
												
													
														|  | 
 |  | +                _.each(_.map(data2,function(val){
 | 
											
												
													
														|  | 
 |  | +                        return val;
 | 
											
												
													
														|  | 
 |  | +                    }), function(item){
 | 
											
												
													
														|  | 
 |  | +                            getColumns.push([{
 | 
											
												
													
														|  | 
 |  | +                                        title: item.title,
 | 
											
												
													
														|  | 
 |  | +                                        dataKey: item.field
 | 
											
												
													
														|  | 
 |  | +                                    }]);
 | 
											
												
													
														|  | 
 |  | +                });
 | 
											
												
													
														|  | 
 |  | +                this.drawPDF(_.flatten(getColumns),rows);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +        drawPDF: function (getColumns,rows) {
 | 
											
												
													
														|  | 
 |  | +            var self = this;
 | 
											
												
													
														|  | 
 |  | +            var desde =(this.$el.find('#from').val());
 | 
											
												
													
														|  | 
 |  | +            var hasta =(this.$el.find('#to').val());
 | 
											
												
													
														|  | 
 |  | +            var totalPagesExp = "{total_pages_count_string}";
 | 
											
												
													
														|  | 
 |  | +            var pdfDoc = new jsPDF();
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            pdfDoc.autoTable(getColumns, rows, {
 | 
											
												
													
														|  | 
 |  | +                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
 | 
											
												
													
														|  | 
 |  | +                columnStyles: {
 | 
											
												
													
														|  | 
 |  | +                    product : {columnWidth: '10px'},
 | 
											
												
													
														|  | 
 |  | +                    qty : {halign:'right',columnWidth: '8px'},
 | 
											
												
													
														|  | 
 |  | +                    type : {halign:'left',columnWidth: '8px'},
 | 
											
												
													
														|  | 
 |  | +                },
 | 
											
												
													
														|  | 
 |  | +                margin: { top: 16, horizontal: 7},
 | 
											
												
													
														|  | 
 |  | +                addPageContent: function (data) {
 | 
											
												
													
														|  | 
 |  | +                    pdfDoc.setFontSize(12);
 | 
											
												
													
														|  | 
 |  | +                    pdfDoc.setFontStyle('bold');
 | 
											
												
													
														|  | 
 |  | +                    pdfDoc.setTextColor(40);
 | 
											
												
													
														|  | 
 |  | +                    pdfDoc.text('Producto más vendidos Punto de Venta ', data.settings.margin.left, 10);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    if(desde.length > 0 || hasta.length > 0){
 | 
											
												
													
														|  | 
 |  | +                        var fecha='';
 | 
											
												
													
														|  | 
 |  | +                        if(desde){
 | 
											
												
													
														|  | 
 |  | +                            fecha=fecha.concat(' Desde '+desde);
 | 
											
												
													
														|  | 
 |  | +                        }
 | 
											
												
													
														|  | 
 |  | +                        if (hasta){
 | 
											
												
													
														|  | 
 |  | +                            fecha=fecha.concat(' Hasta '+hasta);
 | 
											
												
													
														|  | 
 |  | +                        }
 | 
											
												
													
														|  | 
 |  | +                        pdfDoc.setFontSize(10);
 | 
											
												
													
														|  | 
 |  | +                        pdfDoc.setFontStyle('bold');
 | 
											
												
													
														|  | 
 |  | +                        pdfDoc.setTextColor(40)
 | 
											
												
													
														|  | 
 |  | +                        pdfDoc.text(fecha, data.settings.margin.left,14);
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                    // FOOTER
 | 
											
												
													
														|  | 
 |  | +                    var str = "Pagina  " + data.pageCount;
 | 
											
												
													
														|  | 
 |  | +                    // Total page number plugin only available in jspdf v1.0+
 | 
											
												
													
														|  | 
 |  | +                    if (typeof pdfDoc.putTotalPages === 'function') {
 | 
											
												
													
														|  | 
 |  | +                        str = str + " de " + totalPagesExp;
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                    pdfDoc.setFontSize(9);
 | 
											
												
													
														|  | 
 |  | +                    pdfDoc.setFontStyle('bold');
 | 
											
												
													
														|  | 
 |  | +                    pdfDoc.setTextColor(40);
 | 
											
												
													
														|  | 
 |  | +                    pdfDoc.text(str, data.settings.margin.left, pdfDoc.internal.pageSize.height - 5);
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +            });
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if (typeof pdfDoc.putTotalPages === 'function') {
 | 
											
												
													
														|  | 
 |  | +                pdfDoc.putTotalPages(totalPagesExp);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            pdfDoc.save('Producto más vendidos Punto de Venta.pdf')
 | 
											
												
													
														|  | 
 |  | +        },
 | 
											
												
													
														|  | 
 |  | +    });
 | 
											
												
													
														|  | 
 |  | +}
 |