Browse Source

[FIX] Romper Codigo

Adrielso 7 years ago
parent
commit
b3c724903d

+ 70 - 0
static/src/js/configuration_reporting.js

@@ -0,0 +1,70 @@
+function configuration_reporting (instance, widget) {
+    "use strict";
+    var widgets = widget;
+
+
+
+    widget.ReportingWidget = instance.Widget.extend({
+        template: 'EiruReporting',
+        events: {
+            'click .report_action > button': 'clickOnReport',
+        },
+        reports: [
+            {
+                title: 'Resumen de ingresos',
+                description: 'Permite visualizar de forma global los ingresos obtenidos por la empresa.',
+                action: 'ReportResumenIngreso'
+            },
+            {
+                title: 'Resumen de egresos',
+                description: 'Permite visualizar de forma global los egresos realizado por la empresa.',
+                action: 'ReportResumenEngreso'
+            },
+            {
+                title: 'Utilidad de facturas detalladas',
+                description: 'Permite visualizar la ganancia de cada ítem de las facturas detalladamente.',
+                action: 'ReportInvoiceUtility'
+            },
+            {
+                title: 'Histórico de compras',
+                description: 'Permite visualizar un histórico de compras realizado por la empresa.',
+                action: 'AllPurchases'
+            },
+            {
+                title: 'Histórico de gastos',
+                description: 'Permite visualizar un histórico de gastos realizado por la empresa.',
+                action: 'ReposrtExpenses'
+            },
+            {
+                title: 'Listado de productos por ubicación',
+                description: 'Permite visualizar un listado de productos activos.',
+                action: 'ReportStockLocation'
+            }
+        ],
+        start: function () {
+        },
+
+        clickOnReport: function (e) {
+            var templateName = this.$el.find(e.target).val();
+            this.renderReport(templateName);
+        },
+
+        renderReport: function (templateName) {
+            var Widget = this.getWidgetFromTemplate(templateName);
+            var WidgetInstance = new Widget(this);
+            var container = this.$el.find('.oe_form_sheet.oe_form_sheet_width');
+            container.find('.report_view').hide({
+                effect: 'fade',
+                duration: 200,
+                complete: function () {
+                    WidgetInstance.appendTo(container);
+                }
+            });
+        },
+
+        getWidgetFromTemplate: function (templateName) {
+            var widgetName = `${templateName}Widget`;
+            return _.pick(widget, widgetName)[widgetName];
+        },
+    });
+}

+ 0 - 2765
static/src/js/eiru_reporting.js

@@ -1,2765 +0,0 @@
-"use strict";
-
-openerp.eiru_reporting = function (instance, local) {
-    var QWeb = instance.web.qweb;
-    var number= instance.web;
-    local.ReportingWidget = instance.Widget.extend({
-        template: 'EiruReporting',
-        events: {
-            'click .report_action > button': 'clickOnReport',
-        },
-        reports: [
-            {
-                title: 'Resumen de ingresos',
-                description: 'Permite visualizar de forma global los ingresos obtenidos por la empresa.',
-                action: 'ReportResumenIngreso'
-            },
-            {
-                title: 'Resumen de egresos',
-                description: 'Permite visualizar de forma global los egresos realizado por la empresa.',
-                action: 'ReportResumenEngreso'
-            },
-            {
-                title: 'Utilidad de facturas detalladas',
-                description: 'Permite visualizar la ganancia de cada ítem de las facturas detalladamente.',
-                action: 'ReportInvoiceUtility'
-            },
-            {
-                title: 'Histórico de compras',
-                description: 'Permite visualizar un histórico de compras realizado por la empresa.',
-                action: 'AllPurchases'
-            },
-            {
-                title: 'Histórico de gastos',
-                description: 'Permite visualizar un histórico de gastos realizado por la empresa.',
-                action: 'ReposrtExpenses'
-            },
-            {
-                title: 'Listado de productos por ubicación',
-                description: 'Permite visualizar un listado de productos activos.',
-                action: 'ReportStockLocation'
-            }
-        ],
-        start: function () {
-        },
-
-        clickOnReport: function (e) {
-            var templateName = this.$el.find(e.target).val();
-            this.renderReport(templateName);
-        },
-
-        renderReport: function (templateName) {
-            var Widget = this.getWidgetFromTemplate(templateName);
-            var WidgetInstance = new Widget(this);
-            var container = this.$el.find('.oe_form_sheet.oe_form_sheet_width');
-            container.find('.report_view').hide({
-                effect: 'fade',
-                duration: 200,
-                complete: function () {
-                    WidgetInstance.appendTo(container);
-                }
-            });
-        },
-        getWidgetFromTemplate: function (templateName) {
-            var widgetName = `${templateName}Widget`;
-            return _.pick(local, widgetName)[widgetName];
-        },
-    });
-    // InvoiceUtility
-    local.ReportInvoiceUtilityWidget = instance.Widget.extend({
-        template: 'ReportInvoiceUtility',
-        invoices: [],
-        invoiceLines: [],
-        productProduct:[],
-        Currency:[],
-        rowsData :[],
-        rowOrigin:[],
-        accountJournal:[],
-        resCompany:[],
-
-        events:{
-            'click #toolbar > button' : 'clickOnAction',
-            'change #current-journal': 'fectSearch',
-            'change #from' : 'fectSearch',
-            'change #to': 'fectSearch',
-            'click #volver_btn': 'volver',
-        },
-        init : function(parent){
-          this._super(parent);
-        },
-        start: function () {
-            var table = this.$el.find('#table');
-            table.bootstrapTable({data : self.rowOrigin});
-            this.fecthFecha();
-            this.submitForm();
-        },
-        // volver
-        volver: function(){
-            this.$el.find('#volver').empty();
-            this.$el.find('#grafico').empty();
-            this.$el.find('.bootstrap-table').show({
-                effect: 'drop',
-                direction: 'down',
-                duration: 200,
-            });
-        },
-        // Cansultar
-        submitForm: function () {
-            var self = this;
-            this.fetchCurency().then(function(Currency) {
-                self.Currency = Currency;
-                return Currency;
-            }).then(function (Currency) {
-                return self.fetchJournal();
-            }).then(function (journal) {
-                self.accountJournal =journal;
-                self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
-                _.each(journal, function (item) {
-                  self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
-                });
-                return self.fetchInvoiceV2();
-            }).then(function (invoices){
-                self.invoices = invoices;
-                return self.fetchInvoiceLine(invoices);
-            }).then(function (invoiceLines) {
-                self.invoiceLines = invoiceLines;
-                return self.fecthProduct(invoiceLines);
-            }).then(function(productProduct){
-                self.productProduct = productProduct;
-                return self.fecthComanyCurrency();
-            }).then(function(resCompany){
-                self.resCompany = resCompany;
-                return self.invoice_Currency();
-            });
-        },
-        // company_curency
-        fecthComanyCurrency: function(){
-            var self = this;
-            var defer = $.Deferred();
-            var currency = new instance.web.Model('res.company');
-            var field=['id', 'currency_id'];
-            var domain=[['id','=',1]];
-            currency.query(field).filter(domain).all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Fecha
-        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;
-            }
-          },
-        // Buscar Diario
-        fetchJournal: function () {
-            var self = this;
-            var defer = $.Deferred();
-            var Journal = new instance.web.Model('account.journal');
-            Journal.query(['id', 'name']).filter([['type', '=', 'sale'], ['active', '=', true]]).all().then(function (results) {
-                defer.resolve(results);
-            });
-              return defer;
-        },
-        // Buscar Cambio de Monedas USD,PYG,ARG,BRL
-        fetchCurency: function () {
-            var defer = $.Deferred();
-            var currency_Rate = new instance.web.Model('res.currency.rate');
-            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
-            var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
-            currency_Rate.query(fields).filter(domain).all().then(function (results) {
-                defer.resolve(results);
-            });
-            return defer;
-          },
-        // Invoice (FACTURAS)
-        fetchInvoiceV2: function () {
-            var filter ="[['state', 'in',['open','paid']],['type', '=', 'out_invoice']";
-            var journal_ids = _.flatten(_.map(this.accountJournal, function (item) {
-                return item.id;
-            }));
-            if (journal_ids){
-                filter=filter.concat(",['journal_id', 'in',["+journal_ids+"]]");
-            }
-            filter=filter.concat("]");
-            var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'invoice_line','date_invoice'];
-            var defer = $.Deferred();
-            var Invoice = new instance.web.Model('account.invoice');
-            Invoice.query(field).filter(filter).all().then(function (results) {
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Invoice line (Linea de Factura)
-        fetchInvoiceLine: function (invoices) {
-            var defer = $.Deferred();
-            var linesIds = _.flatten(_.map(invoices, function (item) {
-                return item.invoice_line;
-            }));
-            var InvoiceLine = new instance.web.Model('account.invoice.line');
-            InvoiceLine.query(['id', 'quantity', 'price_unit', 'discount', 'name', 'product_id', 'origin','invoice_id']).filter([['id', 'in', linesIds]]).all().then(function (results) {
-                defer.resolve(results)
-            });
-            return defer;
-        },
-        // Product Product
-        fecthProduct: function(invoiceLines){
-            var defer = $.Deferred();
-            var porductIDS = _.flatten(_.map(invoiceLines, function (item) {
-                return item.product_id[0];
-            }));
-            var ProductProdcut =  new instance.web.Model('product.product');
-            var fields = ['id', 'default_code', 'name_template','ean13', 'standard_price','type'];
-            ProductProdcut.query(fields).filter([['id', 'in', porductIDS]]).all().then(function (results) {
-                defer.resolve(results)
-            });
-            return defer;
-        },
-        // Obtener Monedas de la Factura
-        getCutrrency: function (id){
-            return _.find(this.Currency,function (curr) {
-                return _.contains(curr.currency_id,id);
-            });
-        },
-        // Actualizar cambio de las moneda de Factura
-        invoice_Currency: function(){
-            for (var i = 0; i < this.invoices.length; i++) {
-                var currency_new;
-                var item = this.invoices[i];
-                var id = item.currency_id[0];
-                currency_new = this.getCutrrency(id);
-                if (!currency_new){
-                    currency_new={};
-                    currency_new.rate=1;
-                }
-                this.invoices[i].rate=(currency_new.rate);
-            }
-            return this.fectUtility();
-        },
-        // Obtener la Detalles de la Factura
-        getInvoice: function (id_line){
-            return _.find(this.invoices, function (inv) {
-                return _.contains(inv.invoice_line, id_line);
-            });
-          },
-        // Obtener las lineas de las Facturas
-        getProduct: function(pro_id){
-            return _.find(this.productProduct, function(prod){
-                return _.contains(pro_id, prod.id);
-            });
-        },
-        // unir los objetos
-        fectUtility: function(){
-            var data=[];
-            var item;
-            var invoice;
-            var producto;
-
-            for (var i = 0; i < this.invoiceLines.length; i++) {
-                item = this.invoiceLines[i];
-                invoice = this.getInvoice(item.id);
-                producto =this.getProduct(item.product_id);
-                if (!producto){
-                    producto={};
-                    producto.standard_price=0;
-                }
-                if (producto.type =="product"){
-                    data.push({
-                            number : (invoice.number),
-                            name : (item.name),
-                            quantity : accounting.formatNumber((item.quantity),0, ".", ","),
-                            price_unity : accounting.formatNumber((item.price_unit / invoice.rate),2, ".", ","),
-                            standar_price : accounting.formatNumber((producto.standard_price),2, ".", ","),
-                            price_tot : accounting.formatNumber((item.quantity * (item.price_unit / invoice.rate)),2, ".", ","),
-                            standar_tot : accounting.formatNumber((item.quantity * producto.standard_price),2, ".", ","),
-                            utility : accounting.formatNumber(((item.quantity * (item.price_unit / invoice.rate)) - (item.quantity * producto.standard_price)),2, ".", ","),
-                            journal_id :(invoice.journal_id[0]),
-                            journal_name :(invoice.journal_id[1]),
-                            date_invoice : (invoice.date_invoice),
-                    });
-                }
-          }
-          this.rowsData=data;
-          this.rowOrigin=data;
-          this.loadTable(data)
-        },
-        // Buscar
-        fectSearch: function(){
-            var self = this;
-            var desde =this.$el.find('#from').val();
-            var hasta =this.$el.find('#to').val();
-            var suc =this.$el.find('#current-journal').val();
-            self.rowsData=self.rowOrigin;
-            if (suc != 9999999){
-                self.rowsData=_.filter(self.rowsData, function (inv){ return inv.journal_id == suc});
-            }
-            if (desde){
-                var date= desde.split('/')
-                self.rowsData=_.filter(self.rowsData, function (inv){
-                    return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0])
-                });
-            }
-            if (hasta){
-                var date= hasta.split('/')
-                self.rowsData=_.filter(self.rowsData, function (inv){
-                    return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0])
-                });
-            }
-            self.loadTable(self.rowsData);
-        },
-        // cargara la tabla
-        loadTable:function(rowsTable){
-            var table = this.$el.find('#table');
-            table.bootstrapTable('load', rowsTable);
-        },
-        // imprimir PDF
-        clickOnAction: function (e) {
-            var action = this.$el.find(e.target).val();
-            var self = this;
-            var getColumns=[];
-            var rows=[];
-            var table = this.$el.find("#table");
-            var data2 = table.bootstrapTable('getVisibleColumns');
-            if (action === 'pdf') {
-                var dataNEW = _.map(data2, function (val){ return val.field});
-                _.each(this.rowsData,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
-                                }]);
-                });
-                // Llamar al pdf
-                this.drawPDF(_.flatten(getColumns),rows)
-            }
-            if (action === 'chart'){
-                var suc =this.$el.find('#current-journal').val();
-                if (suc == 9999999){
-                    self.fectCharFilter();
-                }else{
-                    $("#dialog" ).dialog({
-                        autoOpen: true,
-                        resizable: false,
-                        modal: true,
-                        title: 'Atención',
-                        open: function() {
-                            $(this).html('Para Generar el Gráfico debes Seleccionar todas las Sucursales');
-                        },
-                        show: {
-                            effect: "shake",
-                            duration: 300
-                        },
-                        hide: {
-                            effect: "fade",
-                            duration: 300
-                        },
-                        buttons: {
-                            Aceptar: function() {
-                                $(this).dialog('close');
-                            }
-                        }
-                    });
-                }
-            }
-        },
-        // Generar pdfDoc
-        drawPDF: function (getColumns,rows) {
-            var self = this;
-            var rowsPdf=[];
-            var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
-            var desde =(this.$el.find('#from').val());
-            var hasta =(this.$el.find('#to').val());
-            var totalPagesExp = "{total_pages_count_string}";
-            var pdfDoc = new jsPDF();
-
-            // rows=this.rowsData;
-            var quantity=_.reduce(_.map(rows,function(item){
-                var valor=0;
-                if (item.quantity){valor = parseFloat(((item.quantity.replace(".","")).replace(",",".")))}return valor}), function(memo, num){ return memo + num; },0);
-            var precio_unit=_.reduce(_.map(rows,function(item){
-                var valor =0;
-                if (item.price_unity){valor=parseFloat(((item.price_unity.replace(".","")).replace(",",".")))} return valor}), function(memo, num){ return memo + num; },0);
-            var precio_cost=_.reduce(_.map(rows,function(item){
-                var valor=0;
-                if(item.standar_price){valor=parseFloat(((item.standar_price.replace(".","")).replace(",",".")))} return valor}), function(memo, num){ return memo + num;},0);
-            var tot_unit=_.reduce(_.map(rows,function(item){
-                var valor=0;
-                if (item.price_tot){valor=parseFloat(((item.price_tot.replace(".","")).replace(",",".")))}return valor}), function(memo, num){ return memo + num; },0);
-            var tol_cost=_.reduce(_.map(rows,function(item){
-                var valor=0;
-                if (item.standar_tot){valor=parseFloat(((item.standar_tot.replace(".","")).replace(",",".")))} return valor }), function(memo, num){ return memo + num; },0);
-            var utility=_.reduce(_.map(rows,function(item){
-                var valor=0;
-                if (item.utility){valor=parseFloat(((item.utility.replace(".","")).replace(",",".")))}return valor }), function(memo, num){ return memo + num; },0);
-
-            rowsPdf=rows;
-
-            var company = _.map(self.resCompany, function (map) {
-                return map.currency_id[1];
-            });
-            rowsPdf.push({
-                        number : "  ",
-                        name : "TOTAL "+company,
-                        quantity: accounting.formatNumber(quantity,0, ".", ","),
-                        price_unity : accounting.formatNumber(precio_unit,2, ".", ","),
-                        standar_price : accounting.formatNumber(precio_cost,2, ".", ","),
-                        price_tot : accounting.formatNumber(tot_unit,2, ".", ","),
-                        standar_tot : accounting.formatNumber(tol_cost,2, ".", ","),
-                        utility : accounting.formatNumber(utility,2, ".", ",")
-                    });
-
-            rowsPdf.unshift({
-                        number : "  ",
-                        name : "TOTAL "+company,
-                        quantity: accounting.formatNumber(quantity,0, ".", ","),
-                        price_unity : accounting.formatNumber(precio_unit,2, ".", ","),
-                        standar_price : accounting.formatNumber(precio_cost,2, ".", ","),
-                        price_tot : accounting.formatNumber(tot_unit,2, ".", ","),
-                        standar_tot : accounting.formatNumber(tol_cost,2, ".", ","),
-                        utility : accounting.formatNumber(utility,2, ".", ",")
-                    });
-
-            pdfDoc.autoTable(getColumns, rowsPdf, {
-                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
-                columnStyles: {
-                              number: {fontStyle: 'bold'},
-                              name :{columnWidth: '10px'},
-                              quantity :{halign:'right' },
-                              price_unity : {halign:'right' },
-                              standar_price : {halign:'right' },
-                              price_tot : {halign:'right' },
-                              standar_tot : {halign:'right' },
-                              utility : {halign:'right'},
-                          },
-                margin: { top: 16, horizontal: 7},
-                addPageContent: function (data) {
-                    pdfDoc.setFontSize(12);
-                    pdfDoc.setFontStyle('bold');
-                    pdfDoc.setTextColor(40);
-                    pdfDoc.text('Utilidad de facturas detalladas por '+ sucusal, 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('Utilidad de facturas detalladas.pdf')
-        },
-        // Chart Filter
-        fectCharFilter: function(){
-          var self = this;
-          var dataBody=[];
-          var dataHeader=[];
-
-          var canvas="<canvas id='graf_resume'></canvas>";
-          this.$el.find('#grafico').append(canvas);
-
-          _.each(self.accountJournal, function(journal){
-            dataHeader.push(journal.name);
-            var utility=_.reduce(_.map(_.filter(self.rowsData, function (inv){ return inv.journal_id == journal.id}),function(item){
-              return parseFloat(((item.utility.replace(".","")).replace(",",".")))}), function(memo, num){ return memo + num; },0);
-            dataBody.push(accounting.toFixed((utility),2));
-          });
-          var selector ="<button type='button' class='oe_button oe_form_button oe_highlight' id='volver_btn' name='volver_btn'><span>Atras</span></button>";
-
-          this.$el.find('#volver').append(selector);
-
-          this.$el.find('.bootstrap-table').hide({
-              effect: 'drop',
-              direction: 'up',
-              duration: 200,
-              complete: function () {
-                self.drawChart(dataHeader,dataBody);
-              }
-          });
-        },
-        // Chart
-        drawChart: function (dataHeader,dataBody) {
-            var barChart = new Chart(this.$el.find('#graf_resume'), {
-                type: 'doughnut',
-                data: {
-                    labels: dataHeader,
-                    datasets: [
-                        {
-                            labels: dataHeader,
-                            backgroundColor: [
-                                'rgba(255, 99, 132, 0.2)',
-                                'rgba(54, 162, 235, 0.2)',
-                                'rgba(255, 206, 86, 0.2)',
-                                'rgba(75, 192, 192, 0.2)',
-                                'rgba(153, 102, 255, 0.2)',
-                            ],
-                            borderColor: [
-                                'rgba(255,99,132,1)',
-                                'rgba(54, 162, 235, 1)',
-                                'rgba(255, 206, 86, 1)',
-                                'rgba(75, 192, 192, 1)',
-                                'rgba(153, 102, 255, 1)',
-                            ],
-                            borderWidth: 1,
-                            data: dataBody,
-                        }
-                    ]
-                },
-                options: {
-                    maintainAspectRatio: false,
-                    layout: {
-                        padding: 30
-                    }
-                },
-            });
-        },
-    });
-    // ResumenEngreso
-    local.ReportResumenEngresoWidget = instance.Widget.extend({
-        template :'ReportResumenEngreso',
-        accountVoucher:[],
-        resCurrency:[],
-        accountJournal:[],
-        dataVoucher:[],
-        currencyRate:[],
-        companyCurrency:[],
-        modules:[],
-
-        events:{
-            'click  #toolbar > button' : 'clickOnAction',
-            'change #current-journal': 'fectSearch',
-            'change #current-currency': 'fectSearch',
-            'change #from' : 'fectSearch',
-            'change #to': 'fectSearch',
-            'click #volver_btn': 'volver',
-        },
-
-        init:function(parent){
-            this._super(parent);
-        },
-        start: function(){
-            var self = this;
-            var table = this.$el.find('#table');
-            table.bootstrapTable({data : self.dataVoucher});
-            self.fecthFecha();
-            self.fecthInitial();
-        },
-        // 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
-        },
-        // Fecha
-        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;
-            }
-         },
-        //  Metodo inicial
-        fecthInitial: function(){
-            var self = this;
-
-            self.fecthIrModuleModule().then(function(modules){
-                self.modules = modules;
-                return modules;
-            }).then(function(modules){
-                return self.fecthJournalStore();
-            }).then(function(accountJournal){
-                self.accountJournal=accountJournal;
-                self.$el.find('#current-journal').append('<option value="9999999">Todas las SUC.</option>');
-                _.each(accountJournal,function(item){
-                    self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
-                });
-                return self.fecthCurrency();
-            }).then(function(resCurrency){
-                self.$el.find('#current-currency').append('<option value="999">Todas las Monedas</option>');
-                _.each(resCurrency,function(item){
-                    self.$el.find('#current-currency').append('<option value="'+item.id+'">'+item.name +' '+item.symbol+'</option>');
-                });
-                self.resCurrency =resCurrency;
-                return self.fecthCurrencyRate();
-            }).then(function(currencyRate){
-                self.currencyRate =currencyRate;
-                return self.fecthVoucher();
-            }).then(function(accountVoucher){
-                self.accountVoucher =accountVoucher;
-                return self.fecthComanyCurrency();
-            }).then(function(companyCurrency){
-                self.companyCurrency = companyCurrency;
-                return self.fecthDataVoucher(self.accountVoucher,self.accountJournal);
-            });
-            // return self.renderReport()
-        },
-        // 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;
-        },
-        // Journal
-        fecthJournalStore: function(){
-            var self = this;
-            var defer = $.Deferred();
-            var modules = _.flatten(self.checkModel('multi_store'));
-
-            if (modules.length <= 0){
-                self.showMensaje('multi_store');
-                return defer;
-            }
-
-            var journal = new instance.web.Model('res.store');
-            var field=['id', 'name','journal_ids'];
-
-            journal.query(field).order_by('id').all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // company_curency
-        fecthComanyCurrency: function(){
-            var self = this;
-            var defer = $.Deferred();
-            var currency = new instance.web.Model('res.company');
-            var field=['id', 'currency_id'];
-            var domain=[['id','=',1]];
-            currency.query(field).filter(domain).all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Moneda
-        fecthCurrency:function(){
-            var self = this;
-            var defer = $.Deferred();
-            var currency = new instance.web.Model('res.currency');
-            var field = ['id', 'name', 'symbol'];
-            var domain = [['active','=', true]];
-            currency.query(field).filter(domain).order_by('id').all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Cambio de la moneda
-        fecthCurrencyRate:function(){
-            var defer = $.Deferred();
-            var currency_Rate = new instance.web.Model('res.currency.rate');
-            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
-            var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
-            currency_Rate.query(fields).filter(domain).all().then(function (results) {
-              defer.resolve(results);
-            });
-            return defer;
-        },
-        // Voucher -
-        fecthVoucher:function(){
-            var self= this;
-            var defer = $.Deferred();
-            var voucher = new instance.web.Model('account.voucher');
-            var field = ['id', 'reference', 'number', 'partner_id', 'payment_rate_currency_id', 'currency_id', 'company_id','state','pre_line', 'payment_rate', 'type', 'date', 'name', 'journal_id', 'amount'];
-            var domain =[['type', '=', 'payment']];
-            voucher.query(field).filter(domain).order_by('id').all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Verificar Valor null
-        valorNull:function(dato){
-            var valor ="";
-            if (dato){
-                valor=dato;
-            }
-            return valor;
-        },
-        // Join object
-        fecthDataVoucher:function(objVoucher,objJournal){
-            var self=this;
-            var item;
-            var journal;
-            var voucherLine;
-            var voucherItem;//Contenido del voucher
-            var sumaAmount; //Guardar la suma de los pagos
-            var voucherObject=[];
-            var voucherObjectItem=[];
-            var cutrrencyRate; //Valor del cambio
-            var total=0;
-            var sumaAmountTot=0;
-            var  itemVoucher;
-            for (var i = 0; i < objJournal.length; i++) {
-                voucherObjectItem=[];
-                journal=objJournal[i];
-                //Generar la Cabezera con el nombre de la sucursal
-                for (var f = 0; f < journal.journal_ids.length; f++) {
-                    voucherLine = journal.journal_ids[f];
-                    voucherItem = self.getVoucherjournal(objVoucher,voucherLine)
-                    if (voucherItem.length > 0){
-                        sumaAmount=_.reduce(_.map(voucherItem,function(item){return item.amount}), function(memo, num){ return memo + num; },0);
-                        itemVoucher = voucherItem.shift();
-                        cutrrencyRate=self.getCutrrencyRate(itemVoucher.currency_id[0]);
-                        if (!cutrrencyRate){
-                            cutrrencyRate={};
-                            cutrrencyRate.rate=1;
-                        }
-                        // Guardar item
-                        voucherObjectItem.push({    journal : " ",
-                                                method  :self.valorNull(itemVoucher.journal_id[1]),
-                                                amount  : accounting.formatNumber(self.valorNull(sumaAmount),2, ".", ","),
-                                                currency_name : self.valorNull(itemVoucher.currency_id[0]),
-                                                currency_id : self.valorNull(itemVoucher.currency_id[1]),
-                                                rate : cutrrencyRate.rate,
-                                                amountBase : self.valorNull(sumaAmount / cutrrencyRate.rate),
-                                                journal_id: journal.id,
-                                                journal_name: journal.name,
-                                                graficar: false
-                                        })
-                    }
-                }
-                if (voucherObjectItem.length > 0){
-                    var company = _.map(self.companyCurrency, function (map) {
-                        return map.currency_id[1];
-                    });
-
-                    sumaAmountTot=_.reduce(_.map(voucherObjectItem,function(item){return (item.amountBase)}), function(memo, num){ return memo + num; },0);
-                    total=total+sumaAmountTot;
-                    voucherObjectItem.push({journal : " ",
-                                            method  :"Total " + company,
-                                            amount  : accounting.formatNumber(self.valorNull(sumaAmountTot),2, ".", ","),
-                                            currency_name : "",
-                                            currency_id : "",
-                                            rate : "cutrrencyRate.rate",
-                                            amountBase:"",
-                                            journal_id: journal.id,
-                                            journal_name: journal.name,
-                                            graficar: true
-                                    });
-                    // Generarl la Cabezera
-                    voucherObjectItem.unshift({ journal : journal.name, method  :"", amount  :"", voucherLine_name :"", voucherLine_id :"",rate :"",amountBase :"",journal_id:journal.id, journal_name:journal.name, graficar:false});
-                    // Generar Objeto Principal
-                    voucherObject=voucherObject.concat(voucherObjectItem);
-                }
-            }
-            if (voucherObject.length >0){
-                voucherObject.push({journal : " Total de Egreso",
-                                        method  :"",
-                                        amount  : accounting.formatNumber(self.valorNull(total),2, ".", ","),
-                                        currency_name : "",
-                                        currency_id : "",
-                                        rate : "",
-                                        amountBase:"",
-                                        journal_id: journal.id,
-                                        journal_name: journal.name,
-                                        graficar: false
-                                });
-            }
-            self.loadTable(voucherObject);
-        },
-        // Obtener Voucher
-        getVoucherjournal:function(objVoucher,journal_id){
-            return _.map(_.filter(objVoucher, function (inv){return inv.journal_id[0] === journal_id}),function(item){return item});
-        },
-        // Obtener Cambio
-        getCutrrencyRate: function(currency_id){
-            return _.filter(this.currencyRate, function(rate){return rate.currency_id[0] === currency_id}).shift();
-        },
-        // Generar la tabla
-        loadTable:function(rowsTable){
-            this.dataVoucher=rowsTable;
-            var table = this.$el.find('#table');
-            table.bootstrapTable('load' ,rowsTable);
-        },
-        // Buscar
-        fectSearch: function(){
-            var self = this;
-            var desde =this.$el.find('#from').val();
-            var hasta =this.$el.find('#to').val();
-            var journal =this.$el.find('#current-journal').val();
-            var currency =this.$el.find('#current-currency').val();
-            var newJournal= self.accountJournal; //copia del Diario
-            var newVoucher= self.accountVoucher; //copia del Vouacher
-
-            if (journal != 9999999){
-                var botonChart =this.$el.find('#chart').attr("disabled", true);
-                 newJournal=_.filter(newJournal, function (inv){ return inv.id == journal});
-            }else {
-                var botonChart =this.$el.find('#chart').attr("disabled", false);
-            }
-
-            if(currency != 999){
-                 newVoucher=_.filter(newVoucher, function (inv){ return inv.currency_id[0] == currency});
-            }
-
-            if (desde){
-                 var date= desde.split('/')
-                 newVoucher=_.filter(newVoucher, function (inv){return inv.date >= (date[2]+"-"+date[1]+"-"+date[0])});
-            }
-
-            if (hasta){
-                var date= hasta.split('/')
-                newVoucher=_.filter(newVoucher, function (inv){return inv.date <= (date[2]+"-"+date[1]+"-"+date[0])});
-           }
-            self.fecthDataVoucher(newVoucher,newJournal);
-        },
-        // volver
-        volver: function(){
-            this.$el.find('#volver').empty();
-            this.$el.find('#grafico').empty();
-            this.$el.find('.bootstrap-table').show({
-                effect: 'drop',
-                direction: 'down',
-                duration: 200,
-            });
-            this.$el.find('#toolbar').show({
-                effect: 'drop',
-                direction: 'down',
-                duration: 200,
-            });
-        },
-        // Click pdf -Grafic
-        clickOnAction: function (e) {
-            var action = this.$el.find(e.target).val();
-            var self = this;
-            var getColumns=[];
-            var rows=[];
-            var table = this.$el.find("#table");
-            var data2 = table.bootstrapTable('getVisibleColumns');
-            if (action === 'pdf') {
-              var dataNEW = _.map(data2, function (val){ return val.field});
-              _.each(this.dataVoucher,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}]);
-              });
-              // Llamar al pdf
-              this.drawPDF(_.flatten(getColumns),rows)
-            }
-            if (action === 'chart'){
-                var self = this;
-                var objetChar;
-                objetChar = _.filter(self.dataVoucher,function(item){return item.graficar === true});
-                self.fectCharFilter(objetChar);
-            }
-        },
-        // pdfDoc
-        drawPDF:function(getColumns,rows){
-            var self = this;
-            var fechaActu= new Date();
-            var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
-            var desde =(this.$el.find('#from').val());
-            var hasta =(this.$el.find('#to').val());
-            var totalPagesExp = "{total_pages_count_string}";
-            var pdfDoc = new window.jsPDF();
-
-            pdfDoc.autoTable(getColumns, rows, {
-                    styles: { overflow: 'linebreak', fontSize:10 , columnWidth: 'wrap'},
-                   columnStyles:{ journal: {fontStyle: 'bold'},
-                                  method :{columnWidth: '10px'},
-                                  amount : {halign:'right'},
-                                },
-                   margin: { top: 16, horizontal: 7},
-                addPageContent: function (data) {
-                    pdfDoc.setFontSize(12);
-                    pdfDoc.setFontStyle('bold');
-                    pdfDoc.setTextColor(40);
-                    pdfDoc.text('Resumen de Egreso de '+ sucusal, 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 +"\n  Día de Expedición  "+fechaActu.getDate()+"/"+fechaActu.getMonth()+"/"+fechaActu.getFullYear();
-                    }
-                    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('Resumen de Egreso.pdf');
-        },
-        // Char filter
-        fectCharFilter: function(objetChar){
-            var self = this;
-            var dataBody=[];
-            var dataHeader=[];
-            // objetChar
-            var canvas="<canvas id='graf_resume'></canvas>";
-              this.$el.find('#grafico').append(canvas);
-            _.each(objetChar,function(voucher){
-                dataHeader.push(voucher.journal_name);
-                dataBody.push(parseFloat(((voucher.amount.replace(".","")).replace(",","."))));
-            });
-          var selector ="<button type='button' class='oe_button oe_form_button oe_highlight' id='volver_btn' name='volver_btn'><span>Atras</span></button>";
-          this.$el.find('#volver').append(selector);
-          this.$el.find('.bootstrap-table').hide({
-              effect: 'drop',
-              direction: 'up',
-              duration: 200,
-              complete: function () {
-                self.drawChart(dataHeader,dataBody);
-              }
-          });
-          this.$el.find('#toolbar').hide({
-              effect: 'drop',
-              direction: 'up',
-              duration: 200,
-              complete: function () {
-                self.drawChart(dataHeader,dataBody);
-              }
-          });
-        },
-        //Chart
-        drawChart: function (dataHeader,dataBody) {
-            var barChart = new Chart(this.$el.find('#graf_resume'), {
-                type: 'doughnut',//bar, doughnut
-                data: {
-                    labels: dataHeader,
-                    datasets: [
-                        {
-                            labels: dataHeader,
-                            backgroundColor: [
-                                'rgba(255, 99, 132, 0.2)',
-                                'rgba(54, 162, 235, 0.2)',
-                                'rgba(255, 206, 86, 0.2)',
-                                'rgba(75, 192, 192, 0.2)',
-                                'rgba(153, 102, 255, 0.2)',
-                            ],
-                            borderColor: [
-                                'rgba(255,99,132,1)',
-                                'rgba(54, 162, 235, 1)',
-                                'rgba(255, 206, 86, 1)',
-                                'rgba(75, 192, 192, 1)',
-                                'rgba(153, 102, 255, 1)',
-                            ],
-                            borderWidth: 1,
-                            data: dataBody,
-                        }
-                    ]
-                },
-                options: {
-                    maintainAspectRatio: false,
-                    layout: {
-                        padding: 30
-                    }
-                },
-            });
-        },
-    });
-    // ResumenIngreso
-    local.ReportResumenIngresoWidget = instance.Widget.extend({
-        template :'ReportResumenIngreso',
-        accountVoucher:[],
-        resCurrency:[],
-        accountJournal:[],
-        dataVoucher:[],
-        currencyRate:[],
-        resCompany:[],
-        modules:[],
-
-        events:{
-          'click #toolbar > button' : 'clickOnAction',
-          'change #current-journal': 'fectSearch',
-          'change #current-currency': 'fectSearch',
-          'change #from' : 'fectSearch',
-          'change #to': 'fectSearch',
-          'click #volver_btn': 'volver',
-        },
-
-        init:function(parent){
-            this._super(parent);
-        },
-        start: function(){
-            var self = this;
-            var table = this.$el.find('#table');
-            table.bootstrapTable({data : self.dataVoucher});
-            self.fecthFecha();
-            self.fecthInitial();
-        },
-        // 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
-        },
-        // Fecha
-        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;
-            }
-         },
-        //  Metodo inicial
-        fecthInitial: function(){
-            var self = this;
-
-            self.fecthIrModuleModule().then(function(modules){
-                self.modules = modules;
-                return modules;
-            }).then(function(modules){
-                return self.fecthJournalStore();
-            }).then(function(accountJournal){
-                self.accountJournal=accountJournal;
-                self.$el.find('#current-journal').append('<option value="9999999">Todas las SUC.</option>');
-                _.each(accountJournal,function(item){
-                    self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
-                });
-                return self.fecthCurrency();
-            }).then(function(resCurrency){
-                self.$el.find('#current-currency').append('<option value="999">Todas las Monedas</option>');
-                _.each(resCurrency,function(item){
-                    self.$el.find('#current-currency').append('<option value="'+item.id+'">'+item.name +' '+item.symbol+'</option>');
-                });
-                self.resCurrency =resCurrency;
-                return self.fecthCurrencyRate();
-            }).then(function(currencyRate){
-                self.currencyRate =currencyRate;
-                return self.fecthVoucher();
-            }).then(function(accountVoucher){
-                self.accountVoucher =accountVoucher;
-                return self.fecthComanyCurrency();
-            }).then(function(resCompany){
-                self.resCompany = resCompany;
-                return self.fecthDataVoucher(self.accountVoucher,self.accountJournal);
-            });
-            // return self.renderReport();
-        },
-        // 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;
-        },
-        // company_curency
-        fecthComanyCurrency: function(){
-            var self = this;
-            var defer = $.Deferred();
-            var currency = new instance.web.Model('res.company');
-            var field=['id', 'currency_id'];
-            var domain=[['id','=',1]];
-            currency.query(field).filter(domain).all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Journal
-        fecthJournalStore: function(){
-            var self = this;
-            var defer = $.Deferred();
-            var modules = self.checkModel('multi_store');
-            //
-            if (modules.length <= 0){
-                self.showMensaje('multi_store');
-                return defer;
-            }
-
-            var journal = new instance.web.Model('res.store');
-            var field=['id', 'name','journal_ids'];
-
-            journal.query(field).order_by('id').all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Moneda
-        fecthCurrency:function(){
-            var self = this;
-            var defer = $.Deferred();
-            var currency = new instance.web.Model('res.currency');
-            var field = ['id', 'name', 'symbol'];
-            var domain = [['active','=', true]];
-            currency.query(field).filter(domain).order_by('id').all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Cambio de la moneda
-        fecthCurrencyRate:function(){
-            var defer = $.Deferred();
-            var currency_Rate = new instance.web.Model('res.currency.rate');
-            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
-            var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
-            currency_Rate.query(fields).filter(domain).all().then(function (results) {
-              defer.resolve(results);
-            });
-            return defer;
-        },
-        // Voucher -
-        fecthVoucher:function(){
-            var self= this;
-            var defer = $.Deferred();
-            var voucher = new instance.web.Model('account.voucher');
-            var field = ['id', 'reference', 'number', 'partner_id', 'payment_rate_currency_id', 'currency_id', 'company_id','state','pre_line', 'payment_rate', 'type', 'date', 'name', 'journal_id', 'amount'];
-            var domain =[['type', '=', 'receipt']];
-            voucher.query(field).filter(domain).order_by('id').all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Verificar Valor null
-        valorNull:function(dato){
-            var valor ="";
-            if (dato){
-                valor=dato;
-            }
-            return valor;
-        },
-        // Join object
-        fecthDataVoucher:function(objVoucher,objJournal){
-            var self=this;
-            var item;
-            var journal;
-            var voucherLine;
-            var voucherItem;//Contenido del voucher
-            var sumaAmount; //Guardar la suma de los pagos
-            var voucherObject=[];
-            var voucherObjectItem=[];
-            var cutrrencyRate; //Valor del cambio
-            var total=0;
-            var sumaAmountTot=0;
-            var  itemVoucher;
-            for (var i = 0; i < objJournal.length; i++) {
-                voucherObjectItem=[];
-                journal=objJournal[i];
-                //Generar la Cabezera con el nombre de la sucursal
-                for (var f = 0; f < journal.journal_ids.length; f++) {
-                    voucherLine = journal.journal_ids[f];
-                    voucherItem = self.getVoucherjournal(objVoucher,voucherLine)
-                    if (voucherItem.length > 0){
-                        sumaAmount=_.reduce(_.map(voucherItem,function(item){return item.amount}), function(memo, num){ return memo + num; },0);
-                        itemVoucher = voucherItem.shift();
-                        cutrrencyRate=self.getCutrrencyRate(itemVoucher.currency_id[0]);
-                        if (!cutrrencyRate){
-                            cutrrencyRate={};
-                            cutrrencyRate.rate=1;
-                        }
-                        // Guardar item
-                        voucherObjectItem.push({    journal : " ",
-                                                method  :self.valorNull(itemVoucher.journal_id[1]),
-                                                amount  : accounting.formatNumber(self.valorNull(sumaAmount),2, ".", ","),
-                                                currency_name : self.valorNull(itemVoucher.currency_id[0]),
-                                                currency_id : self.valorNull(itemVoucher.currency_id[1]),
-                                                rate : cutrrencyRate.rate,
-                                                amountBase : self.valorNull(sumaAmount / cutrrencyRate.rate),
-                                                journal_id: journal.id,
-                                                journal_name: journal.name,
-                                                graficar: false
-                                        })
-                    }
-                }
-                var company = _.map(self.resCompany, function (map) {
-                    return map.currency_id[1];
-                });
-                if (voucherObjectItem.length > 0){
-                    sumaAmountTot=_.reduce(_.map(voucherObjectItem,function(item){return (item.amountBase)}), function(memo, num){ return memo + num; },0);
-                    total=total+sumaAmountTot;
-                    voucherObjectItem.push({journal : " ",
-                                            method  :"Total "+ company,
-                                            amount  : accounting.formatNumber(self.valorNull(sumaAmountTot),2, ".", ","),
-                                            currency_name : "",
-                                            currency_id : "",
-                                            rate : "cutrrencyRate.rate",
-                                            amountBase:"",
-                                            journal_id: journal.id,
-                                            journal_name: journal.name,
-                                            graficar: true
-                                    });
-                    // Generarl la Cabezera
-                    voucherObjectItem.unshift({ journal : journal.name, method  :"", amount  :"", voucherLine_name :"", voucherLine_id :"",rate :"",amountBase :"",journal_id:journal.id, journal_name:journal.name, graficar:false});
-                    // Generar Objeto Principal
-                    voucherObject=voucherObject.concat(voucherObjectItem);
-                }
-            }
-            if (voucherObject.length > 0){
-                voucherObject.push({journal : " Total de Ingreso",
-                                        method  :"",
-                                        amount  : accounting.formatNumber(self.valorNull(total),2, ".", ","),
-                                        currency_name : "",
-                                        currency_id : "",
-                                        rate : "",
-                                        amountBase:"",
-                                        journal_id: journal.id,
-                                        journal_name: journal.name,
-                                        graficar: false
-                                });
-            }
-            self.loadTable(voucherObject);
-        },
-        // Obtener Voucher
-        getVoucherjournal:function(objVoucher,journal_id){
-            return _.map(_.filter(objVoucher, function (inv){return inv.journal_id[0] === journal_id}),function(item){return item});
-        },
-        // Obtener Cambio
-        getCutrrencyRate: function(currency_id){
-            return _.filter(this.currencyRate, function(rate){return rate.currency_id[0] === currency_id}).shift();
-        },
-        // Generar la table
-        loadTable:function(rowsTable){
-            var self = this;
-            self.dataVoucher=rowsTable
-            var table = this.$el.find('#table');
-            table.bootstrapTable('load' ,rowsTable);
-        },
-        // Buscar
-        fectSearch: function(){
-            var self = this;
-            var desde =this.$el.find('#from').val();
-            var hasta =this.$el.find('#to').val();
-            var journal =this.$el.find('#current-journal').val();
-            var currency =this.$el.find('#current-currency').val();
-            var newJournal= self.accountJournal; //copia del Diario
-            var newVoucher= self.accountVoucher; //copia del Vouacher
-
-            if (journal != 9999999){
-                var botonChart =this.$el.find('#chart').attr("disabled", true);
-                 newJournal=_.filter(newJournal, function (inv){ return inv.id == journal});
-            }else {
-                var botonChart =this.$el.find('#chart').attr("disabled", false);
-            }
-
-            if(currency != 999){
-                 newVoucher=_.filter(newVoucher, function (inv){ return inv.currency_id[0] == currency});
-            }
-
-            if (desde){
-                 var date= desde.split('/')
-                 newVoucher=_.filter(newVoucher, function (inv){return inv.date >= (date[2]+"-"+date[1]+"-"+date[0])});
-            }
-
-            if (hasta){
-                var date= hasta.split('/')
-                newVoucher=_.filter(newVoucher, function (inv){return inv.date <= (date[2]+"-"+date[1]+"-"+date[0])});
-           }
-            self.fecthDataVoucher(newVoucher,newJournal);
-        },
-        // volver
-        volver: function(){
-            this.$el.find('#volver').empty();
-            this.$el.find('#grafico').empty();
-            this.$el.find('.bootstrap-table').show({
-                effect: 'drop',
-                direction: 'down',
-                duration: 200,
-            });
-        },
-        // Click pdf -Grafic
-        clickOnAction: function (e) {
-            var action = this.$el.find(e.target).val();
-            var self = this;
-            var getColumns=[];
-            var rows=[];
-            var table = this.$el.find("#table");
-            var data2 = table.bootstrapTable('getVisibleColumns');
-            if (action === 'pdf') {
-                var dataNEW = _.map(data2, function (val){ return val.field});
-                _.each(this.dataVoucher,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}]);
-                });
-                // Llamar al pdf
-                this.drawPDF(_.flatten(getColumns),rows)
-            }
-            if (action === 'chart'){
-                var self = this;
-                var objetChar;
-                objetChar = _.filter(self.dataVoucher,function(item){return item.graficar === true});
-                self.fectCharFilter(objetChar);
-            }
-        },
-        // pdfDoc
-        drawPDF:function(getColumns,rows){
-            var self = this;
-            var fechaActu= new Date();
-            var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
-            var desde =(this.$el.find('#from').val());
-            var hasta =(this.$el.find('#to').val());
-            var totalPagesExp = "{total_pages_count_string}";
-            var pdfDoc = new window.jsPDF();
-
-            pdfDoc.autoTable(getColumns, rows, {
-                    styles: { overflow: 'linebreak', fontSize:10 , columnWidth: 'wrap'},
-                    columnStyles:{ journal: {fontStyle: 'bold'},
-                                    method :{columnWidth: '10px'},
-                                    amount : {halign:'right'},
-                                },
-                   margin: {
-                            top: 16,
-                            horizontal: 7
-                        },
-                addPageContent: function (data) {
-                    pdfDoc.setFontSize(12);
-                    pdfDoc.setFontStyle('bold');
-                    pdfDoc.setTextColor(40);
-                    pdfDoc.text('Resumen de Ingreso de '+ sucusal, 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 +"\n  Día de Expedición  "+fechaActu.getDate()+"/"+fechaActu.getMonth()+"/"+fechaActu.getFullYear();
-                    }
-                    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('Resumen de Ingreso.pdf');
-        },
-        // Char filter
-        fectCharFilter: function(objetChar){
-            var self = this;
-            var dataBody=[];
-            var dataHeader=[];
-            // objetChar
-            var canvas="<canvas id='graf_resume'></canvas>";
-            this.$el.find('#grafico').append(canvas);
-            _.each(objetChar,function(voucher){
-                dataHeader.push(voucher.journal_name);
-                dataBody.push(parseFloat(((voucher.amount.replace(".","")).replace(",","."))));
-            });
-            var selector ="<button type='button' class='oe_button oe_form_button oe_highlight' id='volver_btn' name='volver_btn'><span>Atras</span></button>";
-            this.$el.find('#volver').append(selector);
-            this.$el.find('.bootstrap-table').hide({
-                    effect: 'drop',
-                    direction: 'up',
-                    duration: 200,
-                    complete: function () {
-                        self.drawChart(dataHeader,dataBody);
-                    }
-                });
-        },
-        //Chart
-        drawChart: function (dataHeader,dataBody) {
-            var barChart = new Chart(this.$el.find('#graf_resume'), {
-                type: 'doughnut',//bar, doughnut
-                data: {
-                    labels: dataHeader,
-                    datasets: [
-                        {
-                            labels: dataHeader,
-                            backgroundColor: [
-                                'rgba(255, 99, 132, 0.2)',
-                                'rgba(54, 162, 235, 0.2)',
-                                'rgba(255, 206, 86, 0.2)',
-                                'rgba(75, 192, 192, 0.2)',
-                                'rgba(153, 102, 255, 0.2)',
-                            ],
-                            borderColor: [
-                                'rgba(255,99,132,1)',
-                                'rgba(54, 162, 235, 1)',
-                                'rgba(255, 206, 86, 1)',
-                                'rgba(75, 192, 192, 1)',
-                                'rgba(153, 102, 255, 1)',
-                            ],
-                            borderWidth: 1,
-                            data: dataBody,
-                        }
-                    ]
-                },
-                options: {
-                    maintainAspectRatio: false,
-                    layout: {
-                        padding: 30
-                    }
-                },
-            });
-        },
-    });
-    // StockLocation
-    local.ReportStockLocationWidget = instance.Widget.extend({
-        template : 'ReportStockLocation',
-        stockLocation : [],
-        stockQuant : [],
-        productProduct : [],
-        prodcut:[],
-
-        events : {
-            'click #toolbar > button' : 'clickOnAction',
-            'change #current-location': 'fecthSearch',
-        },
-        init : function(parent){
-            this._super(parent);
-        },
-        start : function(){
-            var self = this;
-            var dato=[];
-            var table = this.$el.find('#table');
-            table.bootstrapTable({data : self.prodcut});
-            self.fecthInitial();
-        },
-        // Consulta Inicial
-        fecthInitial: function(){
-            var self = this;
-            self.fecthLocation().then(function(stockLocation){
-                self.stockLocation=stockLocation
-                return stockLocation;
-            }).then(function(stockLocation){
-                self.$el.find('#current-location').append('<option value="9999999">Todas las Ubicación.</option>');
-                _.each(stockLocation,function(item){
-                    self.$el.find('#current-location').append('<option value="' + item.id + '">' + item.location_id[1]+" / "+item.name + '</option>');
-                });
-                return self.fecthStockQuant();
-            }).then(function(stockQuant){
-                self.stockQuant = stockQuant;
-                return self.fecthProduct(stockQuant);
-            }).then(function(productProduct){
-                self.productProduct = productProduct;
-                return self.fecthProducto(self.stockQuant, self.stockLocation);
-            });
-        },
-        // Ubicacion
-        fecthLocation : function(){
-            var self = this;
-            var defer = $.Deferred();
-            var location = new instance.web.Model('stock.location');
-            var fields = ['id', 'name', 'company_id', 'location_id'];
-            var domain =[['active', '=', true],['usage', '=', 'internal']];
-            location.query(fields).filter(domain).order_by('id').all().then(function(results){
-                defer.resolve(results);
-            })
-            return defer;
-        },
-        // quant
-        fecthStockQuant : function(){
-            var self = this;
-            var defer = $.Deferred();
-            var location = _.flatten(_.map(self.stockLocation,function(item){
-                return item.id;
-            }));
-            var company_id =(_.map(self.stockLocation, function(item){
-                return item.company_id[0];
-            })).shift();
-            var quant = new instance.web.Model('stock.quant');
-            var fields = ['id', 'product_id', 'qty', 'cost','location_id'];
-            var domain =[['company_id', '=', company_id],['location_id', 'in',location]];
-            quant.query(fields).filter(domain).all().then(function(results){
-                defer.resolve(results);
-            })
-            return defer;
-        },
-        // ProductProduct
-        fecthProduct: function(quant){
-            var defer = $.Deferred();
-            var porductIDS = _.flatten(_.map(quant, function (item) {
-                return item.product_id[0];
-            }));
-            var ProductProdcut =  new instance.web.Model('product.product');
-            var fields = ['id','name','name_template', 'standard_price','type','attribute_value_ids'];
-            ProductProdcut.query(fields).filter([['id', 'in', porductIDS]]).all().then(function (results) {
-              defer.resolve(results)
-            });
-            return defer;
-        },
-        // Union de Modulos
-        fecthProducto : function(stockQuant,stockLocation){
-            var self = this;
-            var stock=[];
-            var itemLocation;
-            var itemProduct;
-            var itemQuant;
-            var productProduct;
-            var cat = 0;
-            var quant;
-            for (var i = 0; i < stockLocation.length; i++) {
-                itemLocation = stockLocation[i];
-                productProduct = self.getProdcutoProduct(self.productProduct,stockQuant, itemLocation.id);
-                for (var f = 0; f < productProduct.length; f++) {
-                    itemProduct = productProduct[f];
-                    itemQuant = self.getQuantProduct(itemLocation.id, itemProduct.id, stockQuant);
-                    if (itemQuant.length >0){
-                        cat = _.reduce(_.map(itemQuant,function(item){
-                            return item.qty;
-                        }),function(mamo, num){
-                            return mamo + num;
-                        },0);
-                        quant=itemQuant.shift();
-                        stock.push({prodcut : quant.product_id[1],
-                                    qty : cat,
-                                    location :(itemLocation.location_id[1]+" / "+itemLocation.name)});
-                    }
-                }
-            }
-            self.loadTable(stock);
-        },
-        // Obtener Producto Por quant y locations
-        getProdcutoProduct: function(productProduct, stockQuant, location_id){
-            var self = this;
-            var product_ids= _.flatten(_.map(_.filter(stockQuant, function(item){
-                return item.location_id[0] === location_id;
-            }),function(map){
-                return map.product_id[0];
-            }));
-            return _.filter(productProduct,function(prod){return _.contains(product_ids, prod.id)});
-        },
-        // Obtener  Qaunt  por productos
-        getQuantProduct: function(location_id, product_id, quantObjs){
-            var self = this;
-            var quantProdcut = quantObjs;
-            if (location_id){
-                quantProdcut = _.filter(quantProdcut, function(item){
-                    return item.location_id[0] === location_id;
-                });
-            }
-            if (product_id){
-                quantProdcut = _.filter(quantProdcut, function(item){
-                    return item.product_id[0] === product_id;
-                });
-            }
-            return quantProdcut;
-        },
-        // Buscar
-        fecthSearch: function(){
-            var self = this;
-            var location =this.$el.find('#current-location').val();
-            var locationObjs = self.stockLocation;
-            var quantObjs = self.stockQuant;
-            if (location != 9999999){
-                locationObjs=_.filter(locationObjs, function (inv){
-                    return inv.id == location;
-                });
-                quantObjs=_.filter(quantObjs, function (inv){
-                    return inv.location_id[0] == location;
-                });
-            }
-            self.fecthProducto(quantObjs,locationObjs)
-        },
-        // Generar la table
-        loadTable:function(rowsTable){
-            var self = this;
-            this.prodcut=rowsTable;
-            var table = this.$el.find('#table');
-            table.bootstrapTable('load' ,rowsTable);
-        },
-        // Click pdf -Grafic
-        clickOnAction: function (e) {
-            var self = this;
-            var action = self.$el.find(e.target).val();
-            var getColumns=[];
-            var rows=[];
-            var table = self.$el.find("#table");
-            var data2 = table.bootstrapTable('getVisibleColumns');
-            if (action === 'pdf') {
-                var dataNEW = _.map(data2, function (val){
-                    return val.field;
-                });
-                _.each(self.prodcut,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
-                                }]);
-                });
-                self.drawPDF(_.flatten(getColumns),rows)
-            }
-        },
-        // pdfDoc
-        drawPDF:function(getColumns,rows){
-            var self = this;
-            var fechaActu= new Date();
-            var location = this.sucDescrip = this.$el.find('#current-location option:selected').text();
-            var totalPagesExp = "{total_pages_count_string}";
-            var pdfDoc = new jsPDF();
-            pdfDoc.autoTable(getColumns, rows, {
-                    styles: { overflow: 'linebreak', fontSize:8 , columnWidth: 'wrap'},
-                   columnStyles:{
-                                    prodcut :{columnWidth: '8px'},
-                                   location :{columnWidth: '8px'},
-                                   qty : {halign:'center'},
-                                },
-                   margin: { top: 16, horizontal: 7},
-                addPageContent: function (data) {
-                    pdfDoc.setFontSize(12);
-                    pdfDoc.setFontStyle('bold');
-                    pdfDoc.setTextColor(40);
-                    pdfDoc.text('Listado de productos de '+ location, data.settings.margin.left, 10);
-                    // FOOTER
-                    var str = "Pagina  " + data.pageCount;
-                    if (typeof pdfDoc.putTotalPages === 'function') {
-                        str = str + " de " + totalPagesExp +"\n  Día de Expedición  "+fechaActu.getDate()+"/"+fechaActu.getMonth()+"/"+fechaActu.getFullYear();
-                    }
-                    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('Listado de productos de '+location+'.pdf');
-        }
-    });
-    // AllPurchases Listado de Compras
-    local.AllPurchasesWidget = instance.Widget.extend({
-        template: 'AllPurchases',
-        invoice: [],
-        Currency:[],
-        resCurrency :[],
-        resCompany:[],
-        accountJournal:[],
-        supplier:[],
-        newInvoice:[],
-        rowsData :[],
-        // event
-        events:{
-            'click #toolbar > button' : 'clickOnAction',
-            'change #current-journal' : 'factSearch',
-            'change #current-currency' : 'factSearch',
-            'change #from' : 'factSearch',
-            'change #to' : 'factSearch',
-            'click  #volver_btn' : 'volver',
-        },
-        // Initil
-        init : function(parent){
-            this._super(parent);
-        },
-        // start
-        start: function () {
-            var self = this;
-            var table = this.$el.find('#table');
-            table.bootstrapTable({data : self.rowsData});
-            this.fecthFecha();
-            this.submitForm();
-        },
-        // volver
-        volver: function(){
-            this.$el.find('#volver').empty();
-            this.$el.find('.bootstrap-table').show({
-                effect: 'drop',
-                direction: 'down',
-                duration: 200,
-            });
-        },
-        // Consultar
-        submitForm: function () {
-            var self = this;
-            self.fetchResCurency().then(function(resCurrency) {
-                return resCurrency;
-            }).then(function (resCurrency) {
-                self.resCurrency = resCurrency;
-                self.$el.find('#current-currency').append('<option value="9999999">Todas las monedas</option>');
-               _.each(resCurrency, function (item) {
-                   self.$el.find('#current-currency').append('<option value="' + item.id + '">' + item.name + '</option>');
-               });
-                return self.fetchCurency(resCurrency);
-            }).then(function(Currency){
-                self.Currency = Currency;
-                return self.fetchJournal();
-            }).then(function (journal) {
-                self.accountJournal =journal;
-                self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
-                _.each(journal, function (item) {
-                    self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
-                });
-                return self.fetchInvoiceP2();
-            }).then(function (invoice){
-                self.invoice = invoice;
-                return self.fetchSupplier(invoice);
-            }).then(function(supplier){
-                self.supplier=supplier;
-                return self.fecthComanyCurrency();
-            }).then(function(resCompany){
-                self.resCompany = resCompany;
-                self.inicializarBuscadorsup();
-                return self.fect_generar(self.invoice);
-            });
-        },
-        // Fecha
-        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;
-            }
-        },
-        // Buscar Diario
-        fetchJournal: function () {
-            var self = this;
-            var defer = $.Deferred();
-            var Journal = new instance.web.Model('account.journal');
-            Journal.query(['id', 'name']).filter([['type', '=', 'purchase']]).all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Buscar Cambio de Monedas USD,PYG,ARG,BRL
-        fetchCurency: function (currency) {
-            var defer = $.Deferred();
-            var currency_id = _.flatten(_.map(currency,function(map){
-                return map.id;
-            }))
-            var currency_Rate = new instance.web.Model('res.currency.rate');
-            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
-            var domain = [['currency_id', 'in', currency_id]];
-            currency_Rate.query(fields).filter(domain).all().then(function (results) {
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Moneda
-        fetchResCurency: function () {
-            var defer = $.Deferred();
-            var currency = new instance.web.Model('res.currency');
-            var fields = ['id', 'name'];
-            var domain = [['active', '=', true]];
-            currency.query(fields).filter(domain).all().then(function (results) {
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Invoice (FACTURAS)
-        fetchInvoiceP2: function () {
-            var journal_ids = _.flatten(_.map(this.accountJournal, function (item) {
-                return item.id;
-            }));
-            var filter =[['state', 'in',['open','paid']],['type', '=', 'in_invoice'],['origin', '!=', false],['journal_id', 'in',journal_ids]];
-            var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'supplier_invoice_number','date_invoice','partner_id','amount_total','user_id'];
-            var defer = $.Deferred();
-            var Invoice = new instance.web.Model('account.invoice');
-            Invoice.query(field).filter(filter).all().then(function (results) {
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // company_curency
-        fecthComanyCurrency: function(){
-            var self = this;
-            var defer = $.Deferred();
-            var currency = new instance.web.Model('res.company');
-            var field=['id', 'currency_id'];
-            var domain=[['id','=',1]];
-            currency.query(field).filter(domain).all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Partner (Proveeedor)
-        fetchSupplier: function() {
-            var self = this;
-            var defer = $.Deferred();
-            var supplier = new instance.web.Model('res.partner');
-            supplier.query(['id', 'name', 'ruc', 'active', 'supplier']).filter([['active', '=', true], ['supplier', '=', true]]).all().then(function (results) {
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Obtener el Cambio de la Moneda
-        getCurrency: function (id){
-            return _.find(this.Currency,function (curr) {
-                return _.contains(curr.currency_id,id);
-            });
-        },
-        // Verificar si los Valores no son nulos
-        valorNull:function(dato){
-            var valor ="";
-            if (dato){
-                valor=dato;
-            }
-            return valor;
-        },
-        // Buscador
-        inicializarBuscadorsup: function () {
-            var self = this;
-            var results = self.supplier;
-            results = _.map(results, function (item) {
-                return {
-                        label: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc),
-                        value: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc)
-                }
-            });
-            self.$('#customer').autocomplete({
-                source: results,
-                minLength:0,
-                search: function(event, ui) {
-                    if (!(self.$('#customer').val())){
-                        self.factSearch();
-                    }
-                },
-                close: function( event, ui ) {
-                        self.factSearch();
-                },
-                select: function(event, ui) {
-                    self.factSearch();
-                }
-            });
-        },
-        // unir los objetos
-        fect_generar: function(invoices){
-            var self = this;
-            var data = [];
-            _.each(invoices, function(invoice){
-                data.push({
-                        number: invoice.number,
-                        supplier_invoice_number: self.valorNull(invoice.supplier_invoice_number),
-                        partner: invoice.partner_id[1],
-                        date: moment(invoice.date_invoice).format("DD/MM/YYYY"),
-                        date_invoice: invoice.date_invoice,
-                        user: invoice.user_id[1],
-                        currency: invoice.currency_id[1],
-                        amount_total: accounting.formatNumber(invoice.amount_total,2,".",","),
-                        amount: invoice.amount_total,
-                        journal_id : invoice.journal_id[0],
-                        currency_id : invoice.currency_id[0],
-                        partner_id : invoice.partner_id[0]
-                    });
-            });
-            self.newInvoice = data;
-            this.loadTable(data);
-        },
-        // Buscar
-        factSearch: function(){
-            var self = this;
-            var desde =this.$el.find('#from').val();
-            var hasta =this.$el.find('#to').val();
-            var suc =this.$el.find('#current-journal').val();
-            var currency =this.$el.find('#current-currency').val();
-            var prov= this.$el.find('#customer').val().split('-');
-            var newInvoice = self.newInvoice;
-            // Buscar por Sucursales
-            if (suc != 9999999){
-                newInvoice=_.filter(newInvoice, function (inv){
-                    return inv.journal_id == suc;
-                });
-            }
-            // Buscar por fecha Desde
-            if (desde.length > 0){
-                var date= desde.split('/');
-                newInvoice = _.filter(newInvoice, function (inv){
-                    return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
-                });
-            }
-            // Buscar por Fechas Hasta
-            if (hasta.length > 0){
-                var date= hasta.split('/');
-                newInvoice = _.filter(newInvoice, function (inv){
-                    return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
-                });
-            }
-            // Busacar por moneda
-            if(currency != 9999999){
-                newInvoice = _.filter(newInvoice,function(inv){
-                    return inv.currency_id == currency;
-                });
-            }
-            // Busacara por proveedor
-            if (prov != ""){
-                newInvoice = _.filter(newInvoice, function(inv){
-                    return inv.partner_id == prov[0];
-                });
-            }
-            self.loadTable(newInvoice)
-        },
-        // cargara la tabla
-        loadTable:function(rowsTable){
-            var self = this;
-            self.rowsData = rowsTable;
-            var table = this.$el.find('#table');
-            table.bootstrapTable('load',rowsTable);
-        },
-        // Obtener Invoice por Monedad
-        getInvoice : function(currency_id){
-            var self = this;
-            return _.filter(self.rowsData, function(item){
-                return item.currency_id === currency_id;
-            });
-        },
-        // Crear Objete PDF
-        getObjetPdf: function(rowsTable){
-            var self = this;
-            var rowsPdf=[];
-            var rows=[];
-            var itemCurrecy;
-            var itenRow;
-            var item;
-            var curreRate;
-            var amount_total=0;
-            var amount=0;
-            var company = _.map(self.resCompany,function(map){return map.currency_id[1]});
-
-            for (var i = 0; i < self.resCurrency.length; i++) {
-                itemCurrecy = self.resCurrency[i];
-                itenRow = self.getInvoice(itemCurrecy.id);
-                rowsPdf=[];
-                if (itenRow.length > 0){
-                    rowsPdf.push({number: itemCurrecy.name, supplier_invoice_number: "", partner: "", date: "", date_invoice: "", user: "", currency: "", amount_total: "", journal_id : "", currency_id : "", partner_id : ""});
-                    _.each(itenRow, function(item){
-                        rowsPdf.push({
-                                    number: item.number,
-                                    supplier_invoice_number: self.valorNull(item.supplier_invoice_number),
-                                    partner: item.partner,
-                                    date: moment(item.date_invoice).format("DD/MM/YYYY"),
-                                    date_invoice: item.date_invoice,
-                                    user: item.user,
-                                    currency: item.currency,
-                                    amount_total: accounting.formatNumber((item.amount),2,".",","),
-                                    amount: item.amount,
-                                    journal_id : item.journal_id,
-                                    currency_id : item.currency_id,
-                                    partner_id : item.partner_id
-                                });
-                    });
-                    curreRate = self.getCurrency(itemCurrecy.id);
-                    if (!curreRate){
-                        curreRate={};
-                        curreRate.rate=1;
-                    }
-                    amount_total= _.reduce(_.map(itenRow,function(map){
-                                    return(map.amount);
-                            }),function(memo, num){
-                                return memo + num;
-                            },0);
-                    amount = amount+(amount_total/curreRate.rate);
-                    rowsPdf.push({
-                            number: "Sub - Total "+itemCurrecy.name,
-                            supplier_invoice_number: "",
-                            partner: "",
-                            date: "",
-                            date_invoice: "",
-                            user: "",
-                            currency: "",
-                            amount_total: accounting.formatNumber((amount_total),2,".",","),
-                            journal_id : "",
-                            currency_id : "",
-                            partner_id : ""
-                        });
-                }
-                if (rowsPdf.length >0){
-                    rows = rows.concat(rowsPdf);
-                }
-            }
-            if (rows.length > 0){
-                rows.push({
-                            number: "Total en "+company,
-                            supplier_invoice_number: "",
-                            partner: "",
-                            date: "",
-                            date_invoice: "",
-                            user: "",
-                            currency: "",
-                            amount_total: accounting.formatNumber((amount),2,".",","),
-                            journal_id : "",
-                            currency_id : "",
-                            partner_id : ""
-                        });
-            }
-            return rows;
-        },
-        // imprimir PDF
-        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);
-            }
-        },
-        // Generar pdfDoc
-        drawPDF: function (getColumns,rows) {
-            var self = this;
-            var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
-            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: {
-                    number : {columnWidth: '8px'},
-                    supplier_invoice_number : {columnWidth: '8px'},
-                    partner : {columnWidth: '8px'},
-                    date : {columnWidth: '8px'},
-                    user : {columnWidth: '8px'},
-                    currency : {columnWidth: '8px'},
-                    amount_total: {halign:'right',columnWidth: '8px'},
-                },
-                margin: { top: 16, horizontal: 7},
-
-                addPageContent: function (data) {
-                    pdfDoc.setFontSize(12);
-                    pdfDoc.setFontStyle('bold');
-                    pdfDoc.setTextColor(40);
-                    pdfDoc.text('Histórico de compras de '+ sucusal, 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('Histórico de compras.pdf')
-        },
-    });
-    // ReposrtExpenses Listado de Gastos
-    local.ReposrtExpensesWidget = instance.Widget.extend({
-        template: 'ReposrtExpenses',
-        invoice: [],
-        Currency:[],
-        resCurrency :[],
-        resCompany:[],
-        accountJournal:[],
-        supplier:[],
-        newInvoice:[],
-        rowsData :[],
-        // event
-        events:{
-            'click #toolbar > button' : 'clickOnAction',
-            'change #current-journal' : 'factSearch',
-            'change #current-currency' : 'factSearch',
-            'change #from' : 'factSearch',
-            'change #to' : 'factSearch',
-            'click  #volver_btn' : 'volver',
-        },
-        // Initil
-        init : function(parent){
-            this._super(parent);
-        },
-        // start
-        start: function () {
-            var self = this;
-            var table = this.$el.find('#table');
-            table.bootstrapTable({data : self.rowsData});
-            this.fecthFecha();
-            this.submitForm();
-        },
-        // volver
-        volver: function(){
-            this.$el.find('#volver').empty();
-            this.$el.find('.bootstrap-table').show({
-                effect: 'drop',
-                direction: 'down',
-                duration: 200,
-            });
-        },
-        // Consultar
-        submitForm: function () {
-            var self = this;
-            self.fetchResCurency().then(function(resCurrency) {
-                return resCurrency;
-            }).then(function (resCurrency) {
-                self.resCurrency = resCurrency;
-                self.$el.find('#current-currency').append('<option value="9999999">Todas las monedas</option>');
-               _.each(resCurrency, function (item) {
-                   self.$el.find('#current-currency').append('<option value="' + item.id + '">' + item.name + '</option>');
-               });
-                return self.fetchCurency(resCurrency);
-            }).then(function(Currency){
-                self.Currency = Currency;
-                return self.fetchJournal();
-            }).then(function (journal) {
-                self.accountJournal =journal;
-                self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
-                _.each(journal, function (item) {
-                    self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
-                });
-                return self.fetchInvoiceP2();
-            }).then(function (invoice){
-                self.invoice = invoice;
-                return self.fetchSupplier(invoice);
-            }).then(function(supplier){
-                self.supplier=supplier;
-                return self.fecthComanyCurrency();
-            }).then(function(resCompany){
-                self.resCompany = resCompany;
-                self.inicializarBuscadorsup();
-                return self.fect_generar(self.invoice);
-            });
-        },
-        // Fecha
-        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;
-            }
-        },
-        // Buscar Diario
-        fetchJournal: function () {
-            var self = this;
-            var defer = $.Deferred();
-            var Journal = new instance.web.Model('account.journal');
-            Journal.query(['id', 'name']).filter([['type', '=', 'purchase']]).all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Buscar Cambio de Monedas USD,PYG,ARG,BRL
-        fetchCurency: function (currency) {
-            var defer = $.Deferred();
-            var currency_id = _.flatten(_.map(currency,function(map){
-                return map.id;
-            }))
-            var currency_Rate = new instance.web.Model('res.currency.rate');
-            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
-            var domain = [['currency_id', 'in', currency_id]];
-            currency_Rate.query(fields).filter(domain).all().then(function (results) {
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Moneda
-        fetchResCurency: function () {
-            var defer = $.Deferred();
-            var currency = new instance.web.Model('res.currency');
-            var fields = ['id', 'name'];
-            var domain = [['active', '=', true]];
-            currency.query(fields).filter(domain).all().then(function (results) {
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Invoice (FACTURAS)
-        fetchInvoiceP2: function () {
-            var journal_ids = _.flatten(_.map(this.accountJournal, function (item) {
-                return item.id;
-            }));
-            var filter =[['state', 'in',['open','paid']],['type', '=', 'in_invoice'],['origin', '=', false],['journal_id', 'in',journal_ids]];
-            var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'supplier_invoice_number','date_invoice','partner_id','amount_total','user_id'];
-            var defer = $.Deferred();
-            var Invoice = new instance.web.Model('account.invoice');
-            Invoice.query(field).filter(filter).all().then(function (results) {
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // company_curency
-        fecthComanyCurrency: function(){
-            var self = this;
-            var defer = $.Deferred();
-            var currency = new instance.web.Model('res.company');
-            var field=['id', 'currency_id'];
-            var domain=[['id','=',1]];
-            currency.query(field).filter(domain).all().then(function(results){
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Partner (Proveeedor)
-        fetchSupplier: function() {
-            var self = this;
-            var defer = $.Deferred();
-            var supplier = new instance.web.Model('res.partner');
-            supplier.query(['id', 'name', 'ruc', 'active', 'supplier']).filter([['active', '=', true], ['supplier', '=', true]]).all().then(function (results) {
-                defer.resolve(results);
-            });
-            return defer;
-        },
-        // Obtener el Cambio de la Moneda
-        getCurrency: function (id){
-            return _.find(this.Currency,function (curr) {
-                return _.contains(curr.currency_id,id);
-            });
-        },
-        // Verificar si los Valores no son nulos
-        valorNull:function(dato){
-            var valor ="";
-            if (dato){
-                valor=dato;
-            }
-            return valor;
-        },
-        // Buscador
-        inicializarBuscadorsup: function () {
-            var self = this;
-            var results = self.supplier;
-            results = _.map(results, function (item) {
-                return {
-                        label: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc),
-                        value: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc)
-                }
-            });
-            self.$('#customer').autocomplete({
-                source: results,
-                minLength:0,
-                search: function(event, ui) {
-                    if (!(self.$('#customer').val())){
-                        self.factSearch();
-                    }
-                },
-                close: function( event, ui ) {
-                        self.factSearch();
-                },
-                select: function(event, ui) {
-                    self.factSearch();
-                }
-            });
-        },
-        // unir los objetos
-        fect_generar: function(invoices){
-            var self = this;
-            var data = [];
-            _.each(invoices, function(invoice){
-                data.push({
-                        number: invoice.number,
-                        supplier_invoice_number: self.valorNull(invoice.supplier_invoice_number),
-                        partner: invoice.partner_id[1],
-                        date: moment(invoice.date_invoice).format("DD/MM/YYYY"),
-                        date_invoice: invoice.date_invoice,
-                        user: invoice.user_id[1],
-                        currency: invoice.currency_id[1],
-                        amount_total: accounting.formatNumber(invoice.amount_total,2,".",","),
-                        amount: invoice.amount_total,
-                        journal_id : invoice.journal_id[0],
-                        currency_id : invoice.currency_id[0],
-                        partner_id : invoice.partner_id[0]
-                    });
-            });
-            self.newInvoice = data;
-            this.loadTable(data);
-        },
-        // Buscar
-        factSearch: function(){
-            var self = this;
-            var desde =this.$el.find('#from').val();
-            var hasta =this.$el.find('#to').val();
-            var suc =this.$el.find('#current-journal').val();
-            var currency =this.$el.find('#current-currency').val();
-            var prov= this.$el.find('#customer').val().split('-');
-            var newInvoice = self.newInvoice;
-            // Buscar por Sucursales
-            if (suc != 9999999){
-                newInvoice=_.filter(newInvoice, function (inv){
-                    return inv.journal_id == suc;
-                });
-            }
-            // Buscar por fecha Desde
-            if (desde.length > 0){
-                var date= desde.split('/');
-                newInvoice = _.filter(newInvoice, function (inv){
-                    return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
-                });
-            }
-            // Buscar por Fechas Hasta
-            if (hasta.length > 0){
-                var date= hasta.split('/');
-                newInvoice = _.filter(newInvoice, function (inv){
-                    return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
-                });
-            }
-            // Busacar por moneda
-            if(currency != 9999999){
-                newInvoice = _.filter(newInvoice,function(inv){
-                    return inv.currency_id == currency;
-                });
-            }
-            // Busacara por proveedor
-            if (prov != ""){
-                newInvoice = _.filter(newInvoice, function(inv){
-                    return inv.partner_id == prov[0];
-                });
-            }
-            self.loadTable(newInvoice)
-        },
-        // cargara la tabla
-        loadTable:function(rowsTable){
-            var self = this;
-            self.rowsData = rowsTable;
-            var table = this.$el.find('#table');
-            table.bootstrapTable('load',rowsTable);
-        },
-        // Obtener Invoice por Monedad
-        getInvoice : function(currency_id){
-            var self = this;
-            return _.filter(self.rowsData, function(item){
-                return item.currency_id === currency_id;
-            });
-        },
-        // Crear Objete PDF
-        getObjetPdf: function(rowsTable){
-            var self = this;
-            var rowsPdf=[];
-            var rows=[];
-            var itemCurrecy;
-            var itenRow;
-            var item;
-            var curreRate;
-            var amount_total=0;
-            var amount=0;
-            var company = _.map(self.resCompany,function(map){return map.currency_id[1]});
-
-            for (var i = 0; i < self.resCurrency.length; i++) {
-                itemCurrecy = self.resCurrency[i];
-                itenRow = self.getInvoice(itemCurrecy.id);
-                rowsPdf=[];
-                if (itenRow.length > 0){
-                    rowsPdf.push({number: itemCurrecy.name, supplier_invoice_number: "", partner: "", date: "", date_invoice: "", user: "", currency: "", amount_total: "", journal_id : "", currency_id : "", partner_id : ""});
-                    _.each(itenRow, function(item){
-                        rowsPdf.push({
-                                    number: item.number,
-                                    supplier_invoice_number: self.valorNull(item.supplier_invoice_number),
-                                    partner: item.partner,
-                                    date: moment(item.date_invoice).format("DD/MM/YYYY"),
-                                    date_invoice: item.date_invoice,
-                                    user: item.user,
-                                    currency: item.currency,
-                                    amount_total: accounting.formatNumber((item.amount),2,".",","),
-                                    amount: item.amount,
-                                    journal_id : item.journal_id,
-                                    currency_id : item.currency_id,
-                                    partner_id : item.partner_id
-                                });
-                    });
-                    curreRate = self.getCurrency(itemCurrecy.id);
-                    if (!curreRate){
-                        curreRate={};
-                        curreRate.rate=1;
-                    }
-                    amount_total= _.reduce(_.map(itenRow,function(map){
-                                    return(map.amount);
-                            }),function(memo, num){
-                                return memo + num;
-                            },0);
-                    amount = amount+(amount_total/curreRate.rate);
-                    rowsPdf.push({
-                            number: "Sub - Total "+itemCurrecy.name,
-                            supplier_invoice_number: "",
-                            partner: "",
-                            date: "",
-                            date_invoice: "",
-                            user: "",
-                            currency: "",
-                            amount_total: accounting.formatNumber((amount_total),2,".",","),
-                            journal_id : "",
-                            currency_id : "",
-                            partner_id : ""
-                        });
-                }
-                if (rowsPdf.length >0){
-                    rows = rows.concat(rowsPdf);
-                }
-            }
-            if (rows.length > 0){
-                rows.push({
-                            number: "Total en "+company,
-                            supplier_invoice_number: "",
-                            partner: "",
-                            date: "",
-                            date_invoice: "",
-                            user: "",
-                            currency: "",
-                            amount_total: accounting.formatNumber((amount),2,".",","),
-                            journal_id : "",
-                            currency_id : "",
-                            partner_id : ""
-                        });
-            }
-            return rows;
-        },
-        // imprimir PDF
-        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);
-            }
-        },
-        // Generar pdfDoc
-        drawPDF: function (getColumns,rows) {
-            var self = this;
-            var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
-            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: {
-                    number : {columnWidth: '8px'},
-                    supplier_invoice_number : {columnWidth: '8px'},
-                    partner : {columnWidth: '8px'},
-                    date : {columnWidth: '8px'},
-                    user : {columnWidth: '8px'},
-                    currency : {columnWidth: '8px'},
-                    amount_total: {halign:'right',columnWidth: '8px'},
-                },
-                margin: { top: 16, horizontal: 7},
-
-                addPageContent: function (data) {
-                    pdfDoc.setFontSize(12);
-                    pdfDoc.setFontStyle('bold');
-                    pdfDoc.setTextColor(40);
-                    pdfDoc.text('Histórico de gastos de '+ sucusal, 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('Histórico de gastos.pdf')
-        },
-    });
-    // Proximo Report
-    instance.web.client_actions.add('eiru_reporting.action_report', 'instance.eiru_reporting.ReportingWidget');
-}

+ 20 - 0
static/src/js/main.js

@@ -0,0 +1,20 @@
+openerp.eiru_reporting = function (instance) {
+    "use strict";
+
+    var reporting = instance.eiru_reporting;
+
+    //reportingBase
+    reporting_base(instance,reporting);
+    configuration_reporting(instance,reporting);
+
+    // Lista de Reporte
+    report_invoice_utility(reporting);
+    report_resumen_engreso(reporting);
+    report_resumen_ingresos(reporting);
+    report_puchases(reporting);
+    report_expenses(reporting);
+    report_stock_location(reporting);
+
+
+    instance.web.client_actions.add('eiru_reporting.action_report', 'instance.eiru_reporting.ReportingWidget');
+}

+ 22 - 0
static/src/js/reporting_base.js

@@ -0,0 +1,22 @@
+function reporting_base (instance, widget) {
+    "use strict";
+
+    widget.Base = instance.Widget.extend({
+
+        position: 0,
+
+        init: function (parent, position) {
+            this._super(parent);
+            this.position = position || this.position;
+        },
+        start: function () {
+            // console.log('Reporting Locoo');
+        },
+        getPosition: function () {
+            return this.position;
+        },
+        setPosition: function (position) {
+            this.position = position;
+        }
+    });
+}

+ 475 - 0
static/src/js/reports/report_expenses.js

@@ -0,0 +1,475 @@
+function report_expenses (reporting){
+    "use strict";
+    
+    var instance = openerp;
+
+    reporting.ReposrtExpensesWidget = reporting.Base.extend({
+        template: 'ReposrtExpenses',
+        invoice: [],
+        Currency:[],
+        resCurrency :[],
+        resCompany:[],
+        accountJournal:[],
+        supplier:[],
+        newInvoice:[],
+        rowsData :[],
+        // event
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'change #current-journal' : 'factSearch',
+            'change #current-currency' : 'factSearch',
+            'change #from' : 'factSearch',
+            'change #to' : 'factSearch',
+            'click  #volver_btn' : 'volver',
+        },
+        // Initil
+        init : function(parent){
+            this._super(parent);
+        },
+        // start
+        start: function () {
+            var self = this;
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowsData});
+            this.fecthFecha();
+            this.submitForm();
+        },
+        // volver
+        volver: function(){
+            this.$el.find('#volver').empty();
+            this.$el.find('.bootstrap-table').show({
+                effect: 'drop',
+                direction: 'down',
+                duration: 200,
+            });
+        },
+        // Consultar
+        submitForm: function () {
+            var self = this;
+            self.fetchResCurency().then(function(resCurrency) {
+                return resCurrency;
+            }).then(function (resCurrency) {
+                self.resCurrency = resCurrency;
+                self.$el.find('#current-currency').append('<option value="9999999">Todas las monedas</option>');
+               _.each(resCurrency, function (item) {
+                   self.$el.find('#current-currency').append('<option value="' + item.id + '">' + item.name + '</option>');
+               });
+                return self.fetchCurency(resCurrency);
+            }).then(function(Currency){
+                self.Currency = Currency;
+                return self.fetchJournal();
+            }).then(function (journal) {
+                self.accountJournal =journal;
+                self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
+                _.each(journal, function (item) {
+                    self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+                return self.fetchInvoiceP2();
+            }).then(function (invoice){
+                self.invoice = invoice;
+                return self.fetchSupplier(invoice);
+            }).then(function(supplier){
+                self.supplier=supplier;
+                return self.fecthComanyCurrency();
+            }).then(function(resCompany){
+                self.resCompany = resCompany;
+                self.inicializarBuscadorsup();
+                return self.fect_generar(self.invoice);
+            });
+        },
+        // Fecha
+        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;
+            }
+        },
+        // Buscar Diario
+        fetchJournal: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var Journal = new instance.web.Model('account.journal');
+            Journal.query(['id', 'name']).filter([['type', '=', 'purchase']]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Buscar Cambio de Monedas USD,PYG,ARG,BRL
+        fetchCurency: function (currency) {
+            var defer = $.Deferred();
+            var currency_id = _.flatten(_.map(currency,function(map){
+                return map.id;
+            }))
+            var currency_Rate = new instance.web.Model('res.currency.rate');
+            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
+            var domain = [['currency_id', 'in', currency_id]];
+            currency_Rate.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Moneda
+        fetchResCurency: function () {
+            var defer = $.Deferred();
+            var currency = new instance.web.Model('res.currency');
+            var fields = ['id', 'name'];
+            var domain = [['active', '=', true]];
+            currency.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Invoice (FACTURAS)
+        fetchInvoiceP2: function () {
+            var journal_ids = _.flatten(_.map(this.accountJournal, function (item) {
+                return item.id;
+            }));
+            var filter =[['state', 'in',['open','paid']],['type', '=', 'in_invoice'],['origin', '=', false],['journal_id', 'in',journal_ids]];
+            var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'supplier_invoice_number','date_invoice','partner_id','amount_total','user_id'];
+            var defer = $.Deferred();
+            var Invoice = new instance.web.Model('account.invoice');
+            Invoice.query(field).filter(filter).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // company_curency
+        fecthComanyCurrency: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var currency = new instance.web.Model('res.company');
+            var field=['id', 'currency_id'];
+            var domain=[['id','=',1]];
+            currency.query(field).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Partner (Proveeedor)
+        fetchSupplier: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var supplier = new instance.web.Model('res.partner');
+            supplier.query(['id', 'name', 'ruc', 'active', 'supplier']).filter([['active', '=', true], ['supplier', '=', true]]).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Obtener el Cambio de la Moneda
+        getCurrency: function (id){
+            return _.find(this.Currency,function (curr) {
+                return _.contains(curr.currency_id,id);
+            });
+        },
+        // Verificar si los Valores no son nulos
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+        // Buscador
+        inicializarBuscadorsup: function () {
+            var self = this;
+            var results = self.supplier;
+            results = _.map(results, function (item) {
+                return {
+                        label: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc),
+                        value: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc)
+                }
+            });
+            self.$('#customer').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#customer').val())){
+                        self.factSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.factSearch();
+                },
+                select: function(event, ui) {
+                    self.factSearch();
+                }
+            });
+        },
+        // unir los objetos
+        fect_generar: function(invoices){
+            var self = this;
+            var data = [];
+            _.each(invoices, function(invoice){
+                data.push({
+                        number: invoice.number,
+                        supplier_invoice_number: self.valorNull(invoice.supplier_invoice_number),
+                        partner: invoice.partner_id[1],
+                        date: moment(invoice.date_invoice).format("DD/MM/YYYY"),
+                        date_invoice: invoice.date_invoice,
+                        user: invoice.user_id[1],
+                        currency: invoice.currency_id[1],
+                        amount_total: accounting.formatNumber(invoice.amount_total,2,".",","),
+                        amount: invoice.amount_total,
+                        journal_id : invoice.journal_id[0],
+                        currency_id : invoice.currency_id[0],
+                        partner_id : invoice.partner_id[0]
+                    });
+            });
+            self.newInvoice = data;
+            this.loadTable(data);
+        },
+        // Buscar
+        factSearch: function(){
+            var self = this;
+            var desde =this.$el.find('#from').val();
+            var hasta =this.$el.find('#to').val();
+            var suc =this.$el.find('#current-journal').val();
+            var currency =this.$el.find('#current-currency').val();
+            var prov= this.$el.find('#customer').val().split('-');
+            var newInvoice = self.newInvoice;
+            // Buscar por Sucursales
+            if (suc != 9999999){
+                newInvoice=_.filter(newInvoice, function (inv){
+                    return inv.journal_id == suc;
+                });
+            }
+            // Buscar por fecha Desde
+            if (desde.length > 0){
+                var date= desde.split('/');
+                newInvoice = _.filter(newInvoice, function (inv){
+                    return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
+                });
+            }
+            // Buscar por Fechas Hasta
+            if (hasta.length > 0){
+                var date= hasta.split('/');
+                newInvoice = _.filter(newInvoice, function (inv){
+                    return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
+                });
+            }
+            // Busacar por moneda
+            if(currency != 9999999){
+                newInvoice = _.filter(newInvoice,function(inv){
+                    return inv.currency_id == currency;
+                });
+            }
+            // Busacara por proveedor
+            if (prov != ""){
+                newInvoice = _.filter(newInvoice, function(inv){
+                    return inv.partner_id == prov[0];
+                });
+            }
+            self.loadTable(newInvoice)
+        },
+        // cargara la tabla
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load',rowsTable);
+        },
+        // Obtener Invoice por Monedad
+        getInvoice : function(currency_id){
+            var self = this;
+            return _.filter(self.rowsData, function(item){
+                return item.currency_id === currency_id;
+            });
+        },
+        // Crear Objete PDF
+        getObjetPdf: function(rowsTable){
+            var self = this;
+            var rowsPdf=[];
+            var rows=[];
+            var itemCurrecy;
+            var itenRow;
+            var item;
+            var curreRate;
+            var amount_total=0;
+            var amount=0;
+            var company = _.map(self.resCompany,function(map){return map.currency_id[1]});
+
+            for (var i = 0; i < self.resCurrency.length; i++) {
+                itemCurrecy = self.resCurrency[i];
+                itenRow = self.getInvoice(itemCurrecy.id);
+                rowsPdf=[];
+                if (itenRow.length > 0){
+                    rowsPdf.push({number: itemCurrecy.name, supplier_invoice_number: "", partner: "", date: "", date_invoice: "", user: "", currency: "", amount_total: "", journal_id : "", currency_id : "", partner_id : ""});
+                    _.each(itenRow, function(item){
+                        rowsPdf.push({
+                                    number: item.number,
+                                    supplier_invoice_number: self.valorNull(item.supplier_invoice_number),
+                                    partner: item.partner,
+                                    date: moment(item.date_invoice).format("DD/MM/YYYY"),
+                                    date_invoice: item.date_invoice,
+                                    user: item.user,
+                                    currency: item.currency,
+                                    amount_total: accounting.formatNumber((item.amount),2,".",","),
+                                    amount: item.amount,
+                                    journal_id : item.journal_id,
+                                    currency_id : item.currency_id,
+                                    partner_id : item.partner_id
+                                });
+                    });
+                    curreRate = self.getCurrency(itemCurrecy.id);
+                    if (!curreRate){
+                        curreRate={};
+                        curreRate.rate=1;
+                    }
+                    amount_total= _.reduce(_.map(itenRow,function(map){
+                                    return(map.amount);
+                            }),function(memo, num){
+                                return memo + num;
+                            },0);
+                    amount = amount+(amount_total/curreRate.rate);
+                    rowsPdf.push({
+                            number: "Sub - Total "+itemCurrecy.name,
+                            supplier_invoice_number: "",
+                            partner: "",
+                            date: "",
+                            date_invoice: "",
+                            user: "",
+                            currency: "",
+                            amount_total: accounting.formatNumber((amount_total),2,".",","),
+                            journal_id : "",
+                            currency_id : "",
+                            partner_id : ""
+                        });
+                }
+                if (rowsPdf.length >0){
+                    rows = rows.concat(rowsPdf);
+                }
+            }
+            if (rows.length > 0){
+                rows.push({
+                            number: "Total en "+company,
+                            supplier_invoice_number: "",
+                            partner: "",
+                            date: "",
+                            date_invoice: "",
+                            user: "",
+                            currency: "",
+                            amount_total: accounting.formatNumber((amount),2,".",","),
+                            journal_id : "",
+                            currency_id : "",
+                            partner_id : ""
+                        });
+            }
+            return rows;
+        },
+        // imprimir PDF
+        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);
+            }
+        },
+        // Generar pdfDoc
+        drawPDF: function (getColumns,rows) {
+            var self = this;
+            var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
+            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: {
+                    number : {columnWidth: '8px'},
+                    supplier_invoice_number : {columnWidth: '8px'},
+                    partner : {columnWidth: '8px'},
+                    date : {columnWidth: '8px'},
+                    user : {columnWidth: '8px'},
+                    currency : {columnWidth: '8px'},
+                    amount_total: {halign:'right',columnWidth: '8px'},
+                },
+                margin: { top: 16, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Histórico de gastos de '+ sucusal, 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('Histórico de gastos.pdf')
+        },
+    });
+}

+ 505 - 0
static/src/js/reports/report_invoice_utility.js

@@ -0,0 +1,505 @@
+function report_invoice_utility (reporting){
+    "use strict";
+
+    var model = openerp;
+
+    reporting.ReportInvoiceUtilityWidget = reporting.Base.extend({
+        template: 'ReportInvoiceUtility',
+        invoices: [],
+        invoiceLines: [],
+        productProduct:[],
+        Currency:[],
+        rowsData :[],
+        rowOrigin:[],
+        accountJournal:[],
+        resCompany:[],
+
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'change #current-journal': 'fectSearch',
+            'change #from' : 'fectSearch',
+            'change #to': 'fectSearch',
+            'click #volver_btn': 'volver',
+        },
+        init : function(parent){
+          this._super(parent);
+        },
+        start: function () {
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowOrigin});
+            this.fecthFecha();
+            this.submitForm();
+        },
+        // volver
+        volver: function(){
+            this.$el.find('#volver').empty();
+            this.$el.find('#grafico').empty();
+            this.$el.find('.bootstrap-table').show({
+                effect: 'drop',
+                direction: 'down',
+                duration: 200,
+            });
+        },
+        // Cansultar
+        submitForm: function () {
+            var self = this;
+            this.fetchCurency().then(function(Currency) {
+                self.Currency = Currency;
+                return Currency;
+            }).then(function (Currency) {
+                return self.fetchJournal();
+            }).then(function (journal) {
+                self.accountJournal =journal;
+                self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
+                _.each(journal, function (item) {
+                  self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+                return self.fetchInvoiceV2();
+            }).then(function (invoices){
+                self.invoices = invoices;
+                return self.fetchInvoiceLine(invoices);
+            }).then(function (invoiceLines) {
+                self.invoiceLines = invoiceLines;
+                return self.fecthProduct(invoiceLines);
+            }).then(function(productProduct){
+                self.productProduct = productProduct;
+                return self.fecthComanyCurrency();
+            }).then(function(resCompany){
+                self.resCompany = resCompany;
+                return self.invoice_Currency();
+            });
+        },
+        // company_curency
+        fecthComanyCurrency: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var currency = new model.web.Model('res.company');
+            var field=['id', 'currency_id'];
+            var domain=[['id','=',1]];
+            currency.query(field).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Fecha
+        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;
+            }
+          },
+        // Buscar Diario
+        fetchJournal: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var Journal = new model.web.Model('account.journal');
+            Journal.query(['id', 'name']).filter([['type', '=', 'sale'], ['active', '=', true]]).all().then(function (results) {
+                defer.resolve(results);
+            });
+              return defer;
+        },
+        // Buscar Cambio de Monedas USD,PYG,ARG,BRL
+        fetchCurency: function () {
+            var defer = $.Deferred();
+            var currency_Rate = new model.web.Model('res.currency.rate');
+            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
+            var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
+            currency_Rate.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+          },
+        // Invoice (FACTURAS)
+        fetchInvoiceV2: function () {
+            var filter ="[['state', 'in',['open','paid']],['type', '=', 'out_invoice']";
+            var journal_ids = _.flatten(_.map(this.accountJournal, function (item) {
+                return item.id;
+            }));
+            if (journal_ids){
+                filter=filter.concat(",['journal_id', 'in',["+journal_ids+"]]");
+            }
+            filter=filter.concat("]");
+            var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'invoice_line','date_invoice'];
+            var defer = $.Deferred();
+            var Invoice = new model.web.Model('account.invoice');
+            Invoice.query(field).filter(filter).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Invoice line (Linea de Factura)
+        fetchInvoiceLine: function (invoices) {
+            var defer = $.Deferred();
+            var linesIds = _.flatten(_.map(invoices, function (item) {
+                return item.invoice_line;
+            }));
+            var InvoiceLine = new model.web.Model('account.invoice.line');
+            InvoiceLine.query(['id', 'quantity', 'price_unit', 'discount', 'name', 'product_id', 'origin','invoice_id']).filter([['id', 'in', linesIds]]).all().then(function (results) {
+                defer.resolve(results)
+            });
+            return defer;
+        },
+        // Product Product
+        fecthProduct: function(invoiceLines){
+            var defer = $.Deferred();
+            var porductIDS = _.flatten(_.map(invoiceLines, function (item) {
+                return item.product_id[0];
+            }));
+            var ProductProdcut =  new model.web.Model('product.product');
+            var fields = ['id', 'default_code', 'name_template','ean13', 'standard_price','type'];
+            ProductProdcut.query(fields).filter([['id', 'in', porductIDS]]).all().then(function (results) {
+                defer.resolve(results)
+            });
+            return defer;
+        },
+        // Obtener Monedas de la Factura
+        getCutrrency: function (id){
+            return _.find(this.Currency,function (curr) {
+                return _.contains(curr.currency_id,id);
+            });
+        },
+        // Actualizar cambio de las moneda de Factura
+        invoice_Currency: function(){
+            for (var i = 0; i < this.invoices.length; i++) {
+                var currency_new;
+                var item = this.invoices[i];
+                var id = item.currency_id[0];
+                currency_new = this.getCutrrency(id);
+                if (!currency_new){
+                    currency_new={};
+                    currency_new.rate=1;
+                }
+                this.invoices[i].rate=(currency_new.rate);
+            }
+            return this.fectUtility();
+        },
+        // Obtener la Detalles de la Factura
+        getInvoice: function (id_line){
+            return _.find(this.invoices, function (inv) {
+                return _.contains(inv.invoice_line, id_line);
+            });
+          },
+        // Obtener las lineas de las Facturas
+        getProduct: function(pro_id){
+            return _.find(this.productProduct, function(prod){
+                return _.contains(pro_id, prod.id);
+            });
+        },
+        // unir los objetos
+        fectUtility: function(){
+            var data=[];
+            var item;
+            var invoice;
+            var producto;
+
+            for (var i = 0; i < this.invoiceLines.length; i++) {
+                item = this.invoiceLines[i];
+                invoice = this.getInvoice(item.id);
+                producto =this.getProduct(item.product_id);
+                if (!producto){
+                    producto={};
+                    producto.standard_price=0;
+                }
+                if (producto.type =="product"){
+                    data.push({
+                            number : (invoice.number),
+                            name : (item.name),
+                            quantity : accounting.formatNumber((item.quantity),0, ".", ","),
+                            price_unity : accounting.formatNumber((item.price_unit / invoice.rate),2, ".", ","),
+                            standar_price : accounting.formatNumber((producto.standard_price),2, ".", ","),
+                            price_tot : accounting.formatNumber((item.quantity * (item.price_unit / invoice.rate)),2, ".", ","),
+                            standar_tot : accounting.formatNumber((item.quantity * producto.standard_price),2, ".", ","),
+                            utility : accounting.formatNumber(((item.quantity * (item.price_unit / invoice.rate)) - (item.quantity * producto.standard_price)),2, ".", ","),
+                            journal_id :(invoice.journal_id[0]),
+                            journal_name :(invoice.journal_id[1]),
+                            date_invoice : (invoice.date_invoice),
+                    });
+                }
+          }
+          this.rowsData=data;
+          this.rowOrigin=data;
+          this.loadTable(data)
+        },
+        // Buscar
+        fectSearch: function(){
+            var self = this;
+            var desde =this.$el.find('#from').val();
+            var hasta =this.$el.find('#to').val();
+            var suc =this.$el.find('#current-journal').val();
+            self.rowsData=self.rowOrigin;
+            if (suc != 9999999){
+                self.rowsData=_.filter(self.rowsData, function (inv){ return inv.journal_id == suc});
+            }
+            if (desde){
+                var date= desde.split('/')
+                self.rowsData=_.filter(self.rowsData, function (inv){
+                    return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0])
+                });
+            }
+            if (hasta){
+                var date= hasta.split('/')
+                self.rowsData=_.filter(self.rowsData, function (inv){
+                    return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0])
+                });
+            }
+            self.loadTable(self.rowsData);
+        },
+        // cargara la tabla
+        loadTable:function(rowsTable){
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load', rowsTable);
+        },
+        // imprimir PDF
+        clickOnAction: function (e) {
+            var action = this.$el.find(e.target).val();
+            var self = this;
+            var getColumns=[];
+            var rows=[];
+            var table = this.$el.find("#table");
+            var data2 = table.bootstrapTable('getVisibleColumns');
+            if (action === 'pdf') {
+                var dataNEW = _.map(data2, function (val){ return val.field});
+                _.each(this.rowsData,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
+                                }]);
+                });
+                // Llamar al pdf
+                this.drawPDF(_.flatten(getColumns),rows)
+            }
+            if (action === 'chart'){
+                var suc =this.$el.find('#current-journal').val();
+                if (suc == 9999999){
+                    self.fectCharFilter();
+                }else{
+                    $("#dialog" ).dialog({
+                        autoOpen: true,
+                        resizable: false,
+                        modal: true,
+                        title: 'Atención',
+                        open: function() {
+                            $(this).html('Para Generar el Gráfico debes Seleccionar todas las Sucursales');
+                        },
+                        show: {
+                            effect: "shake",
+                            duration: 300
+                        },
+                        hide: {
+                            effect: "fade",
+                            duration: 300
+                        },
+                        buttons: {
+                            Aceptar: function() {
+                                $(this).dialog('close');
+                            }
+                        }
+                    });
+                }
+            }
+        },
+        // Generar pdfDoc
+        drawPDF: function (getColumns,rows) {
+            var self = this;
+            var rowsPdf=[];
+            var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
+            var desde =(this.$el.find('#from').val());
+            var hasta =(this.$el.find('#to').val());
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new jsPDF();
+
+            // rows=this.rowsData;
+            var quantity=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.quantity){valor = parseFloat(((item.quantity.replace(".","")).replace(",",".")))}return valor}), function(memo, num){ return memo + num; },0);
+            var precio_unit=_.reduce(_.map(rows,function(item){
+                var valor =0;
+                if (item.price_unity){valor=parseFloat(((item.price_unity.replace(".","")).replace(",",".")))} return valor}), function(memo, num){ return memo + num; },0);
+            var precio_cost=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if(item.standar_price){valor=parseFloat(((item.standar_price.replace(".","")).replace(",",".")))} return valor}), function(memo, num){ return memo + num;},0);
+            var tot_unit=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.price_tot){valor=parseFloat(((item.price_tot.replace(".","")).replace(",",".")))}return valor}), function(memo, num){ return memo + num; },0);
+            var tol_cost=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.standar_tot){valor=parseFloat(((item.standar_tot.replace(".","")).replace(",",".")))} return valor }), function(memo, num){ return memo + num; },0);
+            var utility=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.utility){valor=parseFloat(((item.utility.replace(".","")).replace(",",".")))}return valor }), function(memo, num){ return memo + num; },0);
+
+            rowsPdf=rows;
+
+            var company = _.map(self.resCompany, function (map) {
+                return map.currency_id[1];
+            });
+            rowsPdf.push({
+                        number : "  ",
+                        name : "TOTAL "+company,
+                        quantity: accounting.formatNumber(quantity,0, ".", ","),
+                        price_unity : accounting.formatNumber(precio_unit,2, ".", ","),
+                        standar_price : accounting.formatNumber(precio_cost,2, ".", ","),
+                        price_tot : accounting.formatNumber(tot_unit,2, ".", ","),
+                        standar_tot : accounting.formatNumber(tol_cost,2, ".", ","),
+                        utility : accounting.formatNumber(utility,2, ".", ",")
+                    });
+
+            rowsPdf.unshift({
+                        number : "  ",
+                        name : "TOTAL "+company,
+                        quantity: accounting.formatNumber(quantity,0, ".", ","),
+                        price_unity : accounting.formatNumber(precio_unit,2, ".", ","),
+                        standar_price : accounting.formatNumber(precio_cost,2, ".", ","),
+                        price_tot : accounting.formatNumber(tot_unit,2, ".", ","),
+                        standar_tot : accounting.formatNumber(tol_cost,2, ".", ","),
+                        utility : accounting.formatNumber(utility,2, ".", ",")
+                    });
+
+            pdfDoc.autoTable(getColumns, rowsPdf, {
+                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
+                columnStyles: {
+                              number: {fontStyle: 'bold'},
+                              name :{columnWidth: '10px'},
+                              quantity :{halign:'right' },
+                              price_unity : {halign:'right' },
+                              standar_price : {halign:'right' },
+                              price_tot : {halign:'right' },
+                              standar_tot : {halign:'right' },
+                              utility : {halign:'right'},
+                          },
+                margin: { top: 16, horizontal: 7},
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Utilidad de facturas detalladas por '+ sucusal, 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('Utilidad de facturas detalladas.pdf')
+        },
+        // Chart Filter
+        fectCharFilter: function(){
+          var self = this;
+          var dataBody=[];
+          var dataHeader=[];
+
+          var canvas="<canvas id='graf_resume'></canvas>";
+          this.$el.find('#grafico').append(canvas);
+
+          _.each(self.accountJournal, function(journal){
+            dataHeader.push(journal.name);
+            var utility=_.reduce(_.map(_.filter(self.rowsData, function (inv){ return inv.journal_id == journal.id}),function(item){
+              return parseFloat(((item.utility.replace(".","")).replace(",",".")))}), function(memo, num){ return memo + num; },0);
+            dataBody.push(accounting.toFixed((utility),2));
+          });
+          var selector ="<button type='button' class='oe_button oe_form_button oe_highlight' id='volver_btn' name='volver_btn'><span>Atras</span></button>";
+
+          this.$el.find('#volver').append(selector);
+
+          this.$el.find('.bootstrap-table').hide({
+              effect: 'drop',
+              direction: 'up',
+              duration: 200,
+              complete: function () {
+                self.drawChart(dataHeader,dataBody);
+              }
+          });
+        },
+        // Chart
+        drawChart: function (dataHeader,dataBody) {
+            var barChart = new Chart(this.$el.find('#graf_resume'), {
+                type: 'doughnut',
+                data: {
+                    labels: dataHeader,
+                    datasets: [
+                        {
+                            labels: dataHeader,
+                            backgroundColor: [
+                                'rgba(255, 99, 132, 0.2)',
+                                'rgba(54, 162, 235, 0.2)',
+                                'rgba(255, 206, 86, 0.2)',
+                                'rgba(75, 192, 192, 0.2)',
+                                'rgba(153, 102, 255, 0.2)',
+                            ],
+                            borderColor: [
+                                'rgba(255,99,132,1)',
+                                'rgba(54, 162, 235, 1)',
+                                'rgba(255, 206, 86, 1)',
+                                'rgba(75, 192, 192, 1)',
+                                'rgba(153, 102, 255, 1)',
+                            ],
+                            borderWidth: 1,
+                            data: dataBody,
+                        }
+                    ]
+                },
+                options: {
+                    maintainAspectRatio: false,
+                    layout: {
+                        padding: 30
+                    }
+                },
+            });
+        },
+    });
+}

+ 475 - 0
static/src/js/reports/report_puchases.js

@@ -0,0 +1,475 @@
+function report_puchases (reporting){
+    "use strict";
+    
+    var instance = openerp;
+
+    reporting.AllPurchasesWidget = reporting.Base.extend({
+        template: 'AllPurchases',
+        invoice: [],
+        Currency:[],
+        resCurrency :[],
+        resCompany:[],
+        accountJournal:[],
+        supplier:[],
+        newInvoice:[],
+        rowsData :[],
+        // event
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'change #current-journal' : 'factSearch',
+            'change #current-currency' : 'factSearch',
+            'change #from' : 'factSearch',
+            'change #to' : 'factSearch',
+            'click  #volver_btn' : 'volver',
+        },
+        // Initil
+        init : function(parent){
+            this._super(parent);
+        },
+        // start
+        start: function () {
+            var self = this;
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowsData});
+            this.fecthFecha();
+            this.submitForm();
+        },
+        // volver
+        volver: function(){
+            this.$el.find('#volver').empty();
+            this.$el.find('.bootstrap-table').show({
+                effect: 'drop',
+                direction: 'down',
+                duration: 200,
+            });
+        },
+        // Consultar
+        submitForm: function () {
+            var self = this;
+            self.fetchResCurency().then(function(resCurrency) {
+                return resCurrency;
+            }).then(function (resCurrency) {
+                self.resCurrency = resCurrency;
+                self.$el.find('#current-currency').append('<option value="9999999">Todas las monedas</option>');
+               _.each(resCurrency, function (item) {
+                   self.$el.find('#current-currency').append('<option value="' + item.id + '">' + item.name + '</option>');
+               });
+                return self.fetchCurency(resCurrency);
+            }).then(function(Currency){
+                self.Currency = Currency;
+                return self.fetchJournal();
+            }).then(function (journal) {
+                self.accountJournal =journal;
+                self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
+                _.each(journal, function (item) {
+                    self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+                return self.fetchInvoiceP2();
+            }).then(function (invoice){
+                self.invoice = invoice;
+                return self.fetchSupplier(invoice);
+            }).then(function(supplier){
+                self.supplier=supplier;
+                return self.fecthComanyCurrency();
+            }).then(function(resCompany){
+                self.resCompany = resCompany;
+                self.inicializarBuscadorsup();
+                return self.fect_generar(self.invoice);
+            });
+        },
+        // Fecha
+        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;
+            }
+        },
+        // Buscar Diario
+        fetchJournal: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var Journal = new instance.web.Model('account.journal');
+            Journal.query(['id', 'name']).filter([['type', '=', 'purchase']]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Buscar Cambio de Monedas USD,PYG,ARG,BRL
+        fetchCurency: function (currency) {
+            var defer = $.Deferred();
+            var currency_id = _.flatten(_.map(currency,function(map){
+                return map.id;
+            }))
+            var currency_Rate = new instance.web.Model('res.currency.rate');
+            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
+            var domain = [['currency_id', 'in', currency_id]];
+            currency_Rate.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Moneda
+        fetchResCurency: function () {
+            var defer = $.Deferred();
+            var currency = new instance.web.Model('res.currency');
+            var fields = ['id', 'name'];
+            var domain = [['active', '=', true]];
+            currency.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Invoice (FACTURAS)
+        fetchInvoiceP2: function () {
+            var journal_ids = _.flatten(_.map(this.accountJournal, function (item) {
+                return item.id;
+            }));
+            var filter =[['state', 'in',['open','paid']],['type', '=', 'in_invoice'],['origin', '!=', false],['journal_id', 'in',journal_ids]];
+            var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'supplier_invoice_number','date_invoice','partner_id','amount_total','user_id'];
+            var defer = $.Deferred();
+            var Invoice = new instance.web.Model('account.invoice');
+            Invoice.query(field).filter(filter).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // company_curency
+        fecthComanyCurrency: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var currency = new instance.web.Model('res.company');
+            var field=['id', 'currency_id'];
+            var domain=[['id','=',1]];
+            currency.query(field).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Partner (Proveeedor)
+        fetchSupplier: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var supplier = new instance.web.Model('res.partner');
+            supplier.query(['id', 'name', 'ruc', 'active', 'supplier']).filter([['active', '=', true], ['supplier', '=', true]]).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Obtener el Cambio de la Moneda
+        getCurrency: function (id){
+            return _.find(this.Currency,function (curr) {
+                return _.contains(curr.currency_id,id);
+            });
+        },
+        // Verificar si los Valores no son nulos
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+        // Buscador
+        inicializarBuscadorsup: function () {
+            var self = this;
+            var results = self.supplier;
+            results = _.map(results, function (item) {
+                return {
+                        label: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc),
+                        value: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc)
+                }
+            });
+            self.$('#customer').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#customer').val())){
+                        self.factSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.factSearch();
+                },
+                select: function(event, ui) {
+                    self.factSearch();
+                }
+            });
+        },
+        // unir los objetos
+        fect_generar: function(invoices){
+            var self = this;
+            var data = [];
+            _.each(invoices, function(invoice){
+                data.push({
+                        number: invoice.number,
+                        supplier_invoice_number: self.valorNull(invoice.supplier_invoice_number),
+                        partner: invoice.partner_id[1],
+                        date: moment(invoice.date_invoice).format("DD/MM/YYYY"),
+                        date_invoice: invoice.date_invoice,
+                        user: invoice.user_id[1],
+                        currency: invoice.currency_id[1],
+                        amount_total: accounting.formatNumber(invoice.amount_total,2,".",","),
+                        amount: invoice.amount_total,
+                        journal_id : invoice.journal_id[0],
+                        currency_id : invoice.currency_id[0],
+                        partner_id : invoice.partner_id[0]
+                    });
+            });
+            self.newInvoice = data;
+            this.loadTable(data);
+        },
+        // Buscar
+        factSearch: function(){
+            var self = this;
+            var desde =this.$el.find('#from').val();
+            var hasta =this.$el.find('#to').val();
+            var suc =this.$el.find('#current-journal').val();
+            var currency =this.$el.find('#current-currency').val();
+            var prov= this.$el.find('#customer').val().split('-');
+            var newInvoice = self.newInvoice;
+            // Buscar por Sucursales
+            if (suc != 9999999){
+                newInvoice=_.filter(newInvoice, function (inv){
+                    return inv.journal_id == suc;
+                });
+            }
+            // Buscar por fecha Desde
+            if (desde.length > 0){
+                var date= desde.split('/');
+                newInvoice = _.filter(newInvoice, function (inv){
+                    return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
+                });
+            }
+            // Buscar por Fechas Hasta
+            if (hasta.length > 0){
+                var date= hasta.split('/');
+                newInvoice = _.filter(newInvoice, function (inv){
+                    return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
+                });
+            }
+            // Busacar por moneda
+            if(currency != 9999999){
+                newInvoice = _.filter(newInvoice,function(inv){
+                    return inv.currency_id == currency;
+                });
+            }
+            // Busacara por proveedor
+            if (prov != ""){
+                newInvoice = _.filter(newInvoice, function(inv){
+                    return inv.partner_id == prov[0];
+                });
+            }
+            self.loadTable(newInvoice)
+        },
+        // cargara la tabla
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load',rowsTable);
+        },
+        // Obtener Invoice por Monedad
+        getInvoice : function(currency_id){
+            var self = this;
+            return _.filter(self.rowsData, function(item){
+                return item.currency_id === currency_id;
+            });
+        },
+        // Crear Objete PDF
+        getObjetPdf: function(rowsTable){
+            var self = this;
+            var rowsPdf=[];
+            var rows=[];
+            var itemCurrecy;
+            var itenRow;
+            var item;
+            var curreRate;
+            var amount_total=0;
+            var amount=0;
+            var company = _.map(self.resCompany,function(map){return map.currency_id[1]});
+
+            for (var i = 0; i < self.resCurrency.length; i++) {
+                itemCurrecy = self.resCurrency[i];
+                itenRow = self.getInvoice(itemCurrecy.id);
+                rowsPdf=[];
+                if (itenRow.length > 0){
+                    rowsPdf.push({number: itemCurrecy.name, supplier_invoice_number: "", partner: "", date: "", date_invoice: "", user: "", currency: "", amount_total: "", journal_id : "", currency_id : "", partner_id : ""});
+                    _.each(itenRow, function(item){
+                        rowsPdf.push({
+                                    number: item.number,
+                                    supplier_invoice_number: self.valorNull(item.supplier_invoice_number),
+                                    partner: item.partner,
+                                    date: moment(item.date_invoice).format("DD/MM/YYYY"),
+                                    date_invoice: item.date_invoice,
+                                    user: item.user,
+                                    currency: item.currency,
+                                    amount_total: accounting.formatNumber((item.amount),2,".",","),
+                                    amount: item.amount,
+                                    journal_id : item.journal_id,
+                                    currency_id : item.currency_id,
+                                    partner_id : item.partner_id
+                                });
+                    });
+                    curreRate = self.getCurrency(itemCurrecy.id);
+                    if (!curreRate){
+                        curreRate={};
+                        curreRate.rate=1;
+                    }
+                    amount_total= _.reduce(_.map(itenRow,function(map){
+                                    return(map.amount);
+                            }),function(memo, num){
+                                return memo + num;
+                            },0);
+                    amount = amount+(amount_total/curreRate.rate);
+                    rowsPdf.push({
+                            number: "Sub - Total "+itemCurrecy.name,
+                            supplier_invoice_number: "",
+                            partner: "",
+                            date: "",
+                            date_invoice: "",
+                            user: "",
+                            currency: "",
+                            amount_total: accounting.formatNumber((amount_total),2,".",","),
+                            journal_id : "",
+                            currency_id : "",
+                            partner_id : ""
+                        });
+                }
+                if (rowsPdf.length >0){
+                    rows = rows.concat(rowsPdf);
+                }
+            }
+            if (rows.length > 0){
+                rows.push({
+                            number: "Total en "+company,
+                            supplier_invoice_number: "",
+                            partner: "",
+                            date: "",
+                            date_invoice: "",
+                            user: "",
+                            currency: "",
+                            amount_total: accounting.formatNumber((amount),2,".",","),
+                            journal_id : "",
+                            currency_id : "",
+                            partner_id : ""
+                        });
+            }
+            return rows;
+        },
+        // imprimir PDF
+        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);
+            }
+        },
+        // Generar pdfDoc
+        drawPDF: function (getColumns,rows) {
+            var self = this;
+            var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
+            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: {
+                    number : {columnWidth: '8px'},
+                    supplier_invoice_number : {columnWidth: '8px'},
+                    partner : {columnWidth: '8px'},
+                    date : {columnWidth: '8px'},
+                    user : {columnWidth: '8px'},
+                    currency : {columnWidth: '8px'},
+                    amount_total: {halign:'right',columnWidth: '8px'},
+                },
+                margin: { top: 16, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Histórico de compras de '+ sucusal, 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('Histórico de compras.pdf')
+        },
+    });
+}

+ 523 - 0
static/src/js/reports/report_resumen_egresos.js

@@ -0,0 +1,523 @@
+function report_resumen_engreso (reporting){
+
+    var instance = openerp;
+    
+    reporting.ReportResumenEngresoWidget = reporting.Base.extend({
+        template :'ReportResumenEngreso',
+        accountVoucher:[],
+        resCurrency:[],
+        accountJournal:[],
+        dataVoucher:[],
+        currencyRate:[],
+        companyCurrency:[],
+        modules:[],
+
+        events:{
+            'click  #toolbar > button' : 'clickOnAction',
+            'change #current-journal': 'fectSearch',
+            'change #current-currency': 'fectSearch',
+            'change #from' : 'fectSearch',
+            'change #to': 'fectSearch',
+            'click #volver_btn': 'volver',
+        },
+
+        init:function(parent){
+            this._super(parent);
+        },
+        start: function(){
+            var self = this;
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.dataVoucher});
+            self.fecthFecha();
+            self.fecthInitial();
+        },
+        // 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
+        },
+        // Fecha
+        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;
+            }
+         },
+        //  Metodo inicial
+        fecthInitial: function(){
+            var self = this;
+
+            self.fecthIrModuleModule().then(function(modules){
+                self.modules = modules;
+                return modules;
+            }).then(function(modules){
+                return self.fecthJournalStore();
+            }).then(function(accountJournal){
+                self.accountJournal=accountJournal;
+                self.$el.find('#current-journal').append('<option value="9999999">Todas las SUC.</option>');
+                _.each(accountJournal,function(item){
+                    self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+                return self.fecthCurrency();
+            }).then(function(resCurrency){
+                self.$el.find('#current-currency').append('<option value="999">Todas las Monedas</option>');
+                _.each(resCurrency,function(item){
+                    self.$el.find('#current-currency').append('<option value="'+item.id+'">'+item.name +' '+item.symbol+'</option>');
+                });
+                self.resCurrency =resCurrency;
+                return self.fecthCurrencyRate();
+            }).then(function(currencyRate){
+                self.currencyRate =currencyRate;
+                return self.fecthVoucher();
+            }).then(function(accountVoucher){
+                self.accountVoucher =accountVoucher;
+                return self.fecthComanyCurrency();
+            }).then(function(companyCurrency){
+                self.companyCurrency = companyCurrency;
+                return self.fecthDataVoucher(self.accountVoucher,self.accountJournal);
+            });
+            // return self.renderReport()
+        },
+        // 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;
+        },
+        // Journal
+        fecthJournalStore: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var modules = _.flatten(self.checkModel('multi_store'));
+
+            if (modules.length <= 0){
+                self.showMensaje('multi_store');
+                return defer;
+            }
+
+            var journal = new instance.web.Model('res.store');
+            var field=['id', 'name','journal_ids'];
+
+            journal.query(field).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // company_curency
+        fecthComanyCurrency: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var currency = new instance.web.Model('res.company');
+            var field=['id', 'currency_id'];
+            var domain=[['id','=',1]];
+            currency.query(field).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Moneda
+        fecthCurrency:function(){
+            var self = this;
+            var defer = $.Deferred();
+            var currency = new instance.web.Model('res.currency');
+            var field = ['id', 'name', 'symbol'];
+            var domain = [['active','=', true]];
+            currency.query(field).filter(domain).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Cambio de la moneda
+        fecthCurrencyRate:function(){
+            var defer = $.Deferred();
+            var currency_Rate = new instance.web.Model('res.currency.rate');
+            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
+            var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
+            currency_Rate.query(fields).filter(domain).all().then(function (results) {
+              defer.resolve(results);
+            });
+            return defer;
+        },
+        // Voucher -
+        fecthVoucher:function(){
+            var self= this;
+            var defer = $.Deferred();
+            var voucher = new instance.web.Model('account.voucher');
+            var field = ['id', 'reference', 'number', 'partner_id', 'payment_rate_currency_id', 'currency_id', 'company_id','state','pre_line', 'payment_rate', 'type', 'date', 'name', 'journal_id', 'amount'];
+            var domain =[['type', '=', 'payment']];
+            voucher.query(field).filter(domain).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Verificar Valor null
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+        // Join object
+        fecthDataVoucher:function(objVoucher,objJournal){
+            var self=this;
+            var item;
+            var journal;
+            var voucherLine;
+            var voucherItem;//Contenido del voucher
+            var sumaAmount; //Guardar la suma de los pagos
+            var voucherObject=[];
+            var voucherObjectItem=[];
+            var cutrrencyRate; //Valor del cambio
+            var total=0;
+            var sumaAmountTot=0;
+            var  itemVoucher;
+            for (var i = 0; i < objJournal.length; i++) {
+                voucherObjectItem=[];
+                journal=objJournal[i];
+                //Generar la Cabezera con el nombre de la sucursal
+                for (var f = 0; f < journal.journal_ids.length; f++) {
+                    voucherLine = journal.journal_ids[f];
+                    voucherItem = self.getVoucherjournal(objVoucher,voucherLine)
+                    if (voucherItem.length > 0){
+                        sumaAmount=_.reduce(_.map(voucherItem,function(item){return item.amount}), function(memo, num){ return memo + num; },0);
+                        itemVoucher = voucherItem.shift();
+                        cutrrencyRate=self.getCutrrencyRate(itemVoucher.currency_id[0]);
+                        if (!cutrrencyRate){
+                            cutrrencyRate={};
+                            cutrrencyRate.rate=1;
+                        }
+                        // Guardar item
+                        voucherObjectItem.push({    journal : " ",
+                                                method  :self.valorNull(itemVoucher.journal_id[1]),
+                                                amount  : accounting.formatNumber(self.valorNull(sumaAmount),2, ".", ","),
+                                                currency_name : self.valorNull(itemVoucher.currency_id[0]),
+                                                currency_id : self.valorNull(itemVoucher.currency_id[1]),
+                                                rate : cutrrencyRate.rate,
+                                                amountBase : self.valorNull(sumaAmount / cutrrencyRate.rate),
+                                                journal_id: journal.id,
+                                                journal_name: journal.name,
+                                                graficar: false
+                                        })
+                    }
+                }
+                if (voucherObjectItem.length > 0){
+                    var company = _.map(self.companyCurrency, function (map) {
+                        return map.currency_id[1];
+                    });
+
+                    sumaAmountTot=_.reduce(_.map(voucherObjectItem,function(item){return (item.amountBase)}), function(memo, num){ return memo + num; },0);
+                    total=total+sumaAmountTot;
+                    voucherObjectItem.push({journal : " ",
+                                            method  :"Total " + company,
+                                            amount  : accounting.formatNumber(self.valorNull(sumaAmountTot),2, ".", ","),
+                                            currency_name : "",
+                                            currency_id : "",
+                                            rate : "cutrrencyRate.rate",
+                                            amountBase:"",
+                                            journal_id: journal.id,
+                                            journal_name: journal.name,
+                                            graficar: true
+                                    });
+                    // Generarl la Cabezera
+                    voucherObjectItem.unshift({ journal : journal.name, method  :"", amount  :"", voucherLine_name :"", voucherLine_id :"",rate :"",amountBase :"",journal_id:journal.id, journal_name:journal.name, graficar:false});
+                    // Generar Objeto Principal
+                    voucherObject=voucherObject.concat(voucherObjectItem);
+                }
+            }
+            if (voucherObject.length >0){
+                voucherObject.push({journal : " Total de Egreso",
+                                        method  :"",
+                                        amount  : accounting.formatNumber(self.valorNull(total),2, ".", ","),
+                                        currency_name : "",
+                                        currency_id : "",
+                                        rate : "",
+                                        amountBase:"",
+                                        journal_id: journal.id,
+                                        journal_name: journal.name,
+                                        graficar: false
+                                });
+            }
+            self.loadTable(voucherObject);
+        },
+        // Obtener Voucher
+        getVoucherjournal:function(objVoucher,journal_id){
+            return _.map(_.filter(objVoucher, function (inv){return inv.journal_id[0] === journal_id}),function(item){return item});
+        },
+        // Obtener Cambio
+        getCutrrencyRate: function(currency_id){
+            return _.filter(this.currencyRate, function(rate){return rate.currency_id[0] === currency_id}).shift();
+        },
+        // Generar la tabla
+        loadTable:function(rowsTable){
+            this.dataVoucher=rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load' ,rowsTable);
+        },
+        // Buscar
+        fectSearch: function(){
+            var self = this;
+            var desde =this.$el.find('#from').val();
+            var hasta =this.$el.find('#to').val();
+            var journal =this.$el.find('#current-journal').val();
+            var currency =this.$el.find('#current-currency').val();
+            var newJournal= self.accountJournal; //copia del Diario
+            var newVoucher= self.accountVoucher; //copia del Vouacher
+
+            if (journal != 9999999){
+                var botonChart =this.$el.find('#chart').attr("disabled", true);
+                 newJournal=_.filter(newJournal, function (inv){ return inv.id == journal});
+            }else {
+                var botonChart =this.$el.find('#chart').attr("disabled", false);
+            }
+
+            if(currency != 999){
+                 newVoucher=_.filter(newVoucher, function (inv){ return inv.currency_id[0] == currency});
+            }
+
+            if (desde){
+                 var date= desde.split('/')
+                 newVoucher=_.filter(newVoucher, function (inv){return inv.date >= (date[2]+"-"+date[1]+"-"+date[0])});
+            }
+
+            if (hasta){
+                var date= hasta.split('/')
+                newVoucher=_.filter(newVoucher, function (inv){return inv.date <= (date[2]+"-"+date[1]+"-"+date[0])});
+           }
+            self.fecthDataVoucher(newVoucher,newJournal);
+        },
+        // volver
+        volver: function(){
+            this.$el.find('#volver').empty();
+            this.$el.find('#grafico').empty();
+            this.$el.find('.bootstrap-table').show({
+                effect: 'drop',
+                direction: 'down',
+                duration: 200,
+            });
+            this.$el.find('#toolbar').show({
+                effect: 'drop',
+                direction: 'down',
+                duration: 200,
+            });
+        },
+        // Click pdf -Grafic
+        clickOnAction: function (e) {
+            var action = this.$el.find(e.target).val();
+            var self = this;
+            var getColumns=[];
+            var rows=[];
+            var table = this.$el.find("#table");
+            var data2 = table.bootstrapTable('getVisibleColumns');
+            if (action === 'pdf') {
+              var dataNEW = _.map(data2, function (val){ return val.field});
+              _.each(this.dataVoucher,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}]);
+              });
+              // Llamar al pdf
+              this.drawPDF(_.flatten(getColumns),rows)
+            }
+            if (action === 'chart'){
+                var self = this;
+                var objetChar;
+                objetChar = _.filter(self.dataVoucher,function(item){return item.graficar === true});
+                self.fectCharFilter(objetChar);
+            }
+        },
+        // pdfDoc
+        drawPDF:function(getColumns,rows){
+            var self = this;
+            var fechaActu= new Date();
+            var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
+            var desde =(this.$el.find('#from').val());
+            var hasta =(this.$el.find('#to').val());
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new window.jsPDF();
+
+            pdfDoc.autoTable(getColumns, rows, {
+                    styles: { overflow: 'linebreak', fontSize:10 , columnWidth: 'wrap'},
+                   columnStyles:{ journal: {fontStyle: 'bold'},
+                                  method :{columnWidth: '10px'},
+                                  amount : {halign:'right'},
+                                },
+                   margin: { top: 16, horizontal: 7},
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Resumen de Egreso de '+ sucusal, 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 +"\n  Día de Expedición  "+fechaActu.getDate()+"/"+fechaActu.getMonth()+"/"+fechaActu.getFullYear();
+                    }
+                    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('Resumen de Egreso.pdf');
+        },
+        // Char filter
+        fectCharFilter: function(objetChar){
+            var self = this;
+            var dataBody=[];
+            var dataHeader=[];
+            // objetChar
+            var canvas="<canvas id='graf_resume'></canvas>";
+              this.$el.find('#grafico').append(canvas);
+            _.each(objetChar,function(voucher){
+                dataHeader.push(voucher.journal_name);
+                dataBody.push(parseFloat(((voucher.amount.replace(".","")).replace(",","."))));
+            });
+          var selector ="<button type='button' class='oe_button oe_form_button oe_highlight' id='volver_btn' name='volver_btn'><span>Atras</span></button>";
+          this.$el.find('#volver').append(selector);
+          this.$el.find('.bootstrap-table').hide({
+              effect: 'drop',
+              direction: 'up',
+              duration: 200,
+              complete: function () {
+                self.drawChart(dataHeader,dataBody);
+              }
+          });
+          this.$el.find('#toolbar').hide({
+              effect: 'drop',
+              direction: 'up',
+              duration: 200,
+              complete: function () {
+                self.drawChart(dataHeader,dataBody);
+              }
+          });
+        },
+        //Chart
+        drawChart: function (dataHeader,dataBody) {
+            var barChart = new Chart(this.$el.find('#graf_resume'), {
+                type: 'doughnut',//bar, doughnut
+                data: {
+                    labels: dataHeader,
+                    datasets: [
+                        {
+                            labels: dataHeader,
+                            backgroundColor: [
+                                'rgba(255, 99, 132, 0.2)',
+                                'rgba(54, 162, 235, 0.2)',
+                                'rgba(255, 206, 86, 0.2)',
+                                'rgba(75, 192, 192, 0.2)',
+                                'rgba(153, 102, 255, 0.2)',
+                            ],
+                            borderColor: [
+                                'rgba(255,99,132,1)',
+                                'rgba(54, 162, 235, 1)',
+                                'rgba(255, 206, 86, 1)',
+                                'rgba(75, 192, 192, 1)',
+                                'rgba(153, 102, 255, 1)',
+                            ],
+                            borderWidth: 1,
+                            data: dataBody,
+                        }
+                    ]
+                },
+                options: {
+                    maintainAspectRatio: false,
+                    layout: {
+                        padding: 30
+                    }
+                },
+            });
+        },
+    });
+}

+ 514 - 0
static/src/js/reports/report_resumen_ingresos.js

@@ -0,0 +1,514 @@
+function report_resumen_ingresos (reporting){
+    "use strict";
+    
+    var instance = openerp;
+
+    reporting.ReportResumenIngresoWidget = reporting.Base.extend({
+        template :'ReportResumenIngreso',
+        accountVoucher:[],
+        resCurrency:[],
+        accountJournal:[],
+        dataVoucher:[],
+        currencyRate:[],
+        resCompany:[],
+        modules:[],
+
+        events:{
+          'click #toolbar > button' : 'clickOnAction',
+          'change #current-journal': 'fectSearch',
+          'change #current-currency': 'fectSearch',
+          'change #from' : 'fectSearch',
+          'change #to': 'fectSearch',
+          'click #volver_btn': 'volver',
+        },
+
+        init:function(parent){
+            this._super(parent);
+        },
+        start: function(){
+            var self = this;
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.dataVoucher});
+            self.fecthFecha();
+            self.fecthInitial();
+        },
+        // 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
+        },
+        // Fecha
+        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;
+            }
+         },
+        //  Metodo inicial
+        fecthInitial: function(){
+            var self = this;
+
+            self.fecthIrModuleModule().then(function(modules){
+                self.modules = modules;
+                return modules;
+            }).then(function(modules){
+                return self.fecthJournalStore();
+            }).then(function(accountJournal){
+                self.accountJournal=accountJournal;
+                self.$el.find('#current-journal').append('<option value="9999999">Todas las SUC.</option>');
+                _.each(accountJournal,function(item){
+                    self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+                return self.fecthCurrency();
+            }).then(function(resCurrency){
+                self.$el.find('#current-currency').append('<option value="999">Todas las Monedas</option>');
+                _.each(resCurrency,function(item){
+                    self.$el.find('#current-currency').append('<option value="'+item.id+'">'+item.name +' '+item.symbol+'</option>');
+                });
+                self.resCurrency =resCurrency;
+                return self.fecthCurrencyRate();
+            }).then(function(currencyRate){
+                self.currencyRate =currencyRate;
+                return self.fecthVoucher();
+            }).then(function(accountVoucher){
+                self.accountVoucher =accountVoucher;
+                return self.fecthComanyCurrency();
+            }).then(function(resCompany){
+                self.resCompany = resCompany;
+                return self.fecthDataVoucher(self.accountVoucher,self.accountJournal);
+            });
+            // return self.renderReport();
+        },
+        // 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;
+        },
+        // company_curency
+        fecthComanyCurrency: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var currency = new instance.web.Model('res.company');
+            var field=['id', 'currency_id'];
+            var domain=[['id','=',1]];
+            currency.query(field).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Journal
+        fecthJournalStore: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var modules = self.checkModel('multi_store');
+            //
+            if (modules.length <= 0){
+                self.showMensaje('multi_store');
+                return defer;
+            }
+
+            var journal = new instance.web.Model('res.store');
+            var field=['id', 'name','journal_ids'];
+
+            journal.query(field).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Moneda
+        fecthCurrency:function(){
+            var self = this;
+            var defer = $.Deferred();
+            var currency = new instance.web.Model('res.currency');
+            var field = ['id', 'name', 'symbol'];
+            var domain = [['active','=', true]];
+            currency.query(field).filter(domain).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Cambio de la moneda
+        fecthCurrencyRate:function(){
+            var defer = $.Deferred();
+            var currency_Rate = new instance.web.Model('res.currency.rate');
+            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
+            var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
+            currency_Rate.query(fields).filter(domain).all().then(function (results) {
+              defer.resolve(results);
+            });
+            return defer;
+        },
+        // Voucher -
+        fecthVoucher:function(){
+            var self= this;
+            var defer = $.Deferred();
+            var voucher = new instance.web.Model('account.voucher');
+            var field = ['id', 'reference', 'number', 'partner_id', 'payment_rate_currency_id', 'currency_id', 'company_id','state','pre_line', 'payment_rate', 'type', 'date', 'name', 'journal_id', 'amount'];
+            var domain =[['type', '=', 'receipt']];
+            voucher.query(field).filter(domain).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Verificar Valor null
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+        // Join object
+        fecthDataVoucher:function(objVoucher,objJournal){
+            var self=this;
+            var item;
+            var journal;
+            var voucherLine;
+            var voucherItem;//Contenido del voucher
+            var sumaAmount; //Guardar la suma de los pagos
+            var voucherObject=[];
+            var voucherObjectItem=[];
+            var cutrrencyRate; //Valor del cambio
+            var total=0;
+            var sumaAmountTot=0;
+            var  itemVoucher;
+            for (var i = 0; i < objJournal.length; i++) {
+                voucherObjectItem=[];
+                journal=objJournal[i];
+                //Generar la Cabezera con el nombre de la sucursal
+                for (var f = 0; f < journal.journal_ids.length; f++) {
+                    voucherLine = journal.journal_ids[f];
+                    voucherItem = self.getVoucherjournal(objVoucher,voucherLine)
+                    if (voucherItem.length > 0){
+                        sumaAmount=_.reduce(_.map(voucherItem,function(item){return item.amount}), function(memo, num){ return memo + num; },0);
+                        itemVoucher = voucherItem.shift();
+                        cutrrencyRate=self.getCutrrencyRate(itemVoucher.currency_id[0]);
+                        if (!cutrrencyRate){
+                            cutrrencyRate={};
+                            cutrrencyRate.rate=1;
+                        }
+                        // Guardar item
+                        voucherObjectItem.push({    journal : " ",
+                                                method  :self.valorNull(itemVoucher.journal_id[1]),
+                                                amount  : accounting.formatNumber(self.valorNull(sumaAmount),2, ".", ","),
+                                                currency_name : self.valorNull(itemVoucher.currency_id[0]),
+                                                currency_id : self.valorNull(itemVoucher.currency_id[1]),
+                                                rate : cutrrencyRate.rate,
+                                                amountBase : self.valorNull(sumaAmount / cutrrencyRate.rate),
+                                                journal_id: journal.id,
+                                                journal_name: journal.name,
+                                                graficar: false
+                                        })
+                    }
+                }
+                var company = _.map(self.resCompany, function (map) {
+                    return map.currency_id[1];
+                });
+                if (voucherObjectItem.length > 0){
+                    sumaAmountTot=_.reduce(_.map(voucherObjectItem,function(item){return (item.amountBase)}), function(memo, num){ return memo + num; },0);
+                    total=total+sumaAmountTot;
+                    voucherObjectItem.push({journal : " ",
+                                            method  :"Total "+ company,
+                                            amount  : accounting.formatNumber(self.valorNull(sumaAmountTot),2, ".", ","),
+                                            currency_name : "",
+                                            currency_id : "",
+                                            rate : "cutrrencyRate.rate",
+                                            amountBase:"",
+                                            journal_id: journal.id,
+                                            journal_name: journal.name,
+                                            graficar: true
+                                    });
+                    // Generarl la Cabezera
+                    voucherObjectItem.unshift({ journal : journal.name, method  :"", amount  :"", voucherLine_name :"", voucherLine_id :"",rate :"",amountBase :"",journal_id:journal.id, journal_name:journal.name, graficar:false});
+                    // Generar Objeto Principal
+                    voucherObject=voucherObject.concat(voucherObjectItem);
+                }
+            }
+            if (voucherObject.length > 0){
+                voucherObject.push({journal : " Total de Ingreso",
+                                        method  :"",
+                                        amount  : accounting.formatNumber(self.valorNull(total),2, ".", ","),
+                                        currency_name : "",
+                                        currency_id : "",
+                                        rate : "",
+                                        amountBase:"",
+                                        journal_id: journal.id,
+                                        journal_name: journal.name,
+                                        graficar: false
+                                });
+            }
+            self.loadTable(voucherObject);
+        },
+        // Obtener Voucher
+        getVoucherjournal:function(objVoucher,journal_id){
+            return _.map(_.filter(objVoucher, function (inv){return inv.journal_id[0] === journal_id}),function(item){return item});
+        },
+        // Obtener Cambio
+        getCutrrencyRate: function(currency_id){
+            return _.filter(this.currencyRate, function(rate){return rate.currency_id[0] === currency_id}).shift();
+        },
+        // Generar la table
+        loadTable:function(rowsTable){
+            var self = this;
+            self.dataVoucher=rowsTable
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load' ,rowsTable);
+        },
+        // Buscar
+        fectSearch: function(){
+            var self = this;
+            var desde =this.$el.find('#from').val();
+            var hasta =this.$el.find('#to').val();
+            var journal =this.$el.find('#current-journal').val();
+            var currency =this.$el.find('#current-currency').val();
+            var newJournal= self.accountJournal; //copia del Diario
+            var newVoucher= self.accountVoucher; //copia del Vouacher
+
+            if (journal != 9999999){
+                var botonChart =this.$el.find('#chart').attr("disabled", true);
+                 newJournal=_.filter(newJournal, function (inv){ return inv.id == journal});
+            }else {
+                var botonChart =this.$el.find('#chart').attr("disabled", false);
+            }
+
+            if(currency != 999){
+                 newVoucher=_.filter(newVoucher, function (inv){ return inv.currency_id[0] == currency});
+            }
+
+            if (desde){
+                 var date= desde.split('/')
+                 newVoucher=_.filter(newVoucher, function (inv){return inv.date >= (date[2]+"-"+date[1]+"-"+date[0])});
+            }
+
+            if (hasta){
+                var date= hasta.split('/')
+                newVoucher=_.filter(newVoucher, function (inv){return inv.date <= (date[2]+"-"+date[1]+"-"+date[0])});
+           }
+            self.fecthDataVoucher(newVoucher,newJournal);
+        },
+        // volver
+        volver: function(){
+            this.$el.find('#volver').empty();
+            this.$el.find('#grafico').empty();
+            this.$el.find('.bootstrap-table').show({
+                effect: 'drop',
+                direction: 'down',
+                duration: 200,
+            });
+        },
+        // Click pdf -Grafic
+        clickOnAction: function (e) {
+            var action = this.$el.find(e.target).val();
+            var self = this;
+            var getColumns=[];
+            var rows=[];
+            var table = this.$el.find("#table");
+            var data2 = table.bootstrapTable('getVisibleColumns');
+            if (action === 'pdf') {
+                var dataNEW = _.map(data2, function (val){ return val.field});
+                _.each(this.dataVoucher,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}]);
+                });
+                // Llamar al pdf
+                this.drawPDF(_.flatten(getColumns),rows)
+            }
+            if (action === 'chart'){
+                var self = this;
+                var objetChar;
+                objetChar = _.filter(self.dataVoucher,function(item){return item.graficar === true});
+                self.fectCharFilter(objetChar);
+            }
+        },
+        // pdfDoc
+        drawPDF:function(getColumns,rows){
+            var self = this;
+            var fechaActu= new Date();
+            var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
+            var desde =(this.$el.find('#from').val());
+            var hasta =(this.$el.find('#to').val());
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new window.jsPDF();
+
+            pdfDoc.autoTable(getColumns, rows, {
+                    styles: { overflow: 'linebreak', fontSize:10 , columnWidth: 'wrap'},
+                    columnStyles:{ journal: {fontStyle: 'bold'},
+                                    method :{columnWidth: '10px'},
+                                    amount : {halign:'right'},
+                                },
+                   margin: {
+                            top: 16,
+                            horizontal: 7
+                        },
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Resumen de Ingreso de '+ sucusal, 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 +"\n  Día de Expedición  "+fechaActu.getDate()+"/"+fechaActu.getMonth()+"/"+fechaActu.getFullYear();
+                    }
+                    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('Resumen de Ingreso.pdf');
+        },
+        // Char filter
+        fectCharFilter: function(objetChar){
+            var self = this;
+            var dataBody=[];
+            var dataHeader=[];
+            // objetChar
+            var canvas="<canvas id='graf_resume'></canvas>";
+            this.$el.find('#grafico').append(canvas);
+            _.each(objetChar,function(voucher){
+                dataHeader.push(voucher.journal_name);
+                dataBody.push(parseFloat(((voucher.amount.replace(".","")).replace(",","."))));
+            });
+            var selector ="<button type='button' class='oe_button oe_form_button oe_highlight' id='volver_btn' name='volver_btn'><span>Atras</span></button>";
+            this.$el.find('#volver').append(selector);
+            this.$el.find('.bootstrap-table').hide({
+                    effect: 'drop',
+                    direction: 'up',
+                    duration: 200,
+                    complete: function () {
+                        self.drawChart(dataHeader,dataBody);
+                    }
+                });
+        },
+        //Chart
+        drawChart: function (dataHeader,dataBody) {
+            var barChart = new Chart(this.$el.find('#graf_resume'), {
+                type: 'doughnut',//bar, doughnut
+                data: {
+                    labels: dataHeader,
+                    datasets: [
+                        {
+                            labels: dataHeader,
+                            backgroundColor: [
+                                'rgba(255, 99, 132, 0.2)',
+                                'rgba(54, 162, 235, 0.2)',
+                                'rgba(255, 206, 86, 0.2)',
+                                'rgba(75, 192, 192, 0.2)',
+                                'rgba(153, 102, 255, 0.2)',
+                            ],
+                            borderColor: [
+                                'rgba(255,99,132,1)',
+                                'rgba(54, 162, 235, 1)',
+                                'rgba(255, 206, 86, 1)',
+                                'rgba(75, 192, 192, 1)',
+                                'rgba(153, 102, 255, 1)',
+                            ],
+                            borderWidth: 1,
+                            data: dataBody,
+                        }
+                    ]
+                },
+                options: {
+                    maintainAspectRatio: false,
+                    layout: {
+                        padding: 30
+                    }
+                },
+            });
+        },
+    });
+}

+ 232 - 0
static/src/js/reports/report_stock_location.js

@@ -0,0 +1,232 @@
+function report_stock_location (reporting){
+    "use strict";
+    
+    var instance = openerp;
+
+    reporting.ReportStockLocationWidget = reporting.Base.extend({
+        template : 'ReportStockLocation',
+        stockLocation : [],
+        stockQuant : [],
+        productProduct : [],
+        prodcut:[],
+
+        events : {
+            'click #toolbar > button' : 'clickOnAction',
+            'change #current-location': 'fecthSearch',
+        },
+        init : function(parent){
+            this._super(parent);
+        },
+        start : function(){
+            var self = this;
+            var dato=[];
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.prodcut});
+            self.fecthInitial();
+        },
+        // Consulta Inicial
+        fecthInitial: function(){
+            var self = this;
+            self.fecthLocation().then(function(stockLocation){
+                self.stockLocation=stockLocation
+                return stockLocation;
+            }).then(function(stockLocation){
+                self.$el.find('#current-location').append('<option value="9999999">Todas las Ubicación.</option>');
+                _.each(stockLocation,function(item){
+                    self.$el.find('#current-location').append('<option value="' + item.id + '">' + item.location_id[1]+" / "+item.name + '</option>');
+                });
+                return self.fecthStockQuant();
+            }).then(function(stockQuant){
+                self.stockQuant = stockQuant;
+                return self.fecthProduct(stockQuant);
+            }).then(function(productProduct){
+                self.productProduct = productProduct;
+                return self.fecthProducto(self.stockQuant, self.stockLocation);
+            });
+        },
+        // Ubicacion
+        fecthLocation : function(){
+            var self = this;
+            var defer = $.Deferred();
+            var location = new instance.web.Model('stock.location');
+            var fields = ['id', 'name', 'company_id', 'location_id'];
+            var domain =[['active', '=', true],['usage', '=', 'internal']];
+            location.query(fields).filter(domain).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            })
+            return defer;
+        },
+        // quant
+        fecthStockQuant : function(){
+            var self = this;
+            var defer = $.Deferred();
+            var location = _.flatten(_.map(self.stockLocation,function(item){
+                return item.id;
+            }));
+            var company_id =(_.map(self.stockLocation, function(item){
+                return item.company_id[0];
+            })).shift();
+            var quant = new instance.web.Model('stock.quant');
+            var fields = ['id', 'product_id', 'qty', 'cost','location_id'];
+            var domain =[['company_id', '=', company_id],['location_id', 'in',location]];
+            quant.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            })
+            return defer;
+        },
+        // ProductProduct
+        fecthProduct: function(quant){
+            var defer = $.Deferred();
+            var porductIDS = _.flatten(_.map(quant, function (item) {
+                return item.product_id[0];
+            }));
+            var ProductProdcut =  new instance.web.Model('product.product');
+            var fields = ['id','name','name_template', 'standard_price','type','attribute_value_ids'];
+            ProductProdcut.query(fields).filter([['id', 'in', porductIDS]]).all().then(function (results) {
+              defer.resolve(results)
+            });
+            return defer;
+        },
+        // Union de Modulos
+        fecthProducto : function(stockQuant,stockLocation){
+            var self = this;
+            var stock=[];
+            var itemLocation;
+            var itemProduct;
+            var itemQuant;
+            var productProduct;
+            var cat = 0;
+            var quant;
+            for (var i = 0; i < stockLocation.length; i++) {
+                itemLocation = stockLocation[i];
+                productProduct = self.getProdcutoProduct(self.productProduct,stockQuant, itemLocation.id);
+                for (var f = 0; f < productProduct.length; f++) {
+                    itemProduct = productProduct[f];
+                    itemQuant = self.getQuantProduct(itemLocation.id, itemProduct.id, stockQuant);
+                    if (itemQuant.length >0){
+                        cat = _.reduce(_.map(itemQuant,function(item){
+                            return item.qty;
+                        }),function(mamo, num){
+                            return mamo + num;
+                        },0);
+                        quant=itemQuant.shift();
+                        stock.push({prodcut : quant.product_id[1],
+                                    qty : cat,
+                                    location :(itemLocation.location_id[1]+" / "+itemLocation.name)});
+                    }
+                }
+            }
+            self.loadTable(stock);
+        },
+        // Obtener Producto Por quant y locations
+        getProdcutoProduct: function(productProduct, stockQuant, location_id){
+            var self = this;
+            var product_ids= _.flatten(_.map(_.filter(stockQuant, function(item){
+                return item.location_id[0] === location_id;
+            }),function(map){
+                return map.product_id[0];
+            }));
+            return _.filter(productProduct,function(prod){return _.contains(product_ids, prod.id)});
+        },
+        // Obtener  Qaunt  por productos
+        getQuantProduct: function(location_id, product_id, quantObjs){
+            var self = this;
+            var quantProdcut = quantObjs;
+            if (location_id){
+                quantProdcut = _.filter(quantProdcut, function(item){
+                    return item.location_id[0] === location_id;
+                });
+            }
+            if (product_id){
+                quantProdcut = _.filter(quantProdcut, function(item){
+                    return item.product_id[0] === product_id;
+                });
+            }
+            return quantProdcut;
+        },
+        // Buscar
+        fecthSearch: function(){
+            var self = this;
+            var location =this.$el.find('#current-location').val();
+            var locationObjs = self.stockLocation;
+            var quantObjs = self.stockQuant;
+            if (location != 9999999){
+                locationObjs=_.filter(locationObjs, function (inv){
+                    return inv.id == location;
+                });
+                quantObjs=_.filter(quantObjs, function (inv){
+                    return inv.location_id[0] == location;
+                });
+            }
+            self.fecthProducto(quantObjs,locationObjs)
+        },
+        // Generar la table
+        loadTable:function(rowsTable){
+            var self = this;
+            this.prodcut=rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load' ,rowsTable);
+        },
+        // Click pdf -Grafic
+        clickOnAction: function (e) {
+            var self = this;
+            var action = self.$el.find(e.target).val();
+            var getColumns=[];
+            var rows=[];
+            var table = self.$el.find("#table");
+            var data2 = table.bootstrapTable('getVisibleColumns');
+            if (action === 'pdf') {
+                var dataNEW = _.map(data2, function (val){
+                    return val.field;
+                });
+                _.each(self.prodcut,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
+                                }]);
+                });
+                self.drawPDF(_.flatten(getColumns),rows)
+            }
+        },
+        // pdfDoc
+        drawPDF:function(getColumns,rows){
+            var self = this;
+            var fechaActu= new Date();
+            var location = this.sucDescrip = this.$el.find('#current-location option:selected').text();
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new jsPDF();
+            pdfDoc.autoTable(getColumns, rows, {
+                    styles: { overflow: 'linebreak', fontSize:8 , columnWidth: 'wrap'},
+                   columnStyles:{
+                                    prodcut :{columnWidth: '8px'},
+                                   location :{columnWidth: '8px'},
+                                   qty : {halign:'center'},
+                                },
+                   margin: { top: 16, horizontal: 7},
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Listado de productos de '+ location, data.settings.margin.left, 10);
+                    // FOOTER
+                    var str = "Pagina  " + data.pageCount;
+                    if (typeof pdfDoc.putTotalPages === 'function') {
+                        str = str + " de " + totalPagesExp +"\n  Día de Expedición  "+fechaActu.getDate()+"/"+fechaActu.getMonth()+"/"+fechaActu.getFullYear();
+                    }
+                    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('Listado de productos de '+location+'.pdf');
+        }
+    });
+}

+ 14 - 2
templates.xml

@@ -5,8 +5,20 @@
             <xpath expr="." position="inside">
                 <!-- Report style -->
                 <link rel="stylesheet" href="/eiru_reporting/static/src/css/eiru_reporting.css" />
-                <!-- Report javascript -->
-                <script type="text/javascript" src="/eiru_reporting/static/src/js/eiru_reporting.js" />
+
+                <!-- configuration < main > -->
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/main.js" />
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reporting_base.js" />
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/configuration_reporting.js" />
+
+                <!-- Reportes -->
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_invoice_utility.js" />
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_resumen_egresos.js" />
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_resumen_ingresos.js" />
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_puchases.js" />
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_expenses.js" />
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_stock_location.js" />
+
             </xpath>
         </template>