Ver Fonte

Report para Athletic

Rodney Enciso Arias há 7 anos atrás
pai
commit
9f1540d08d

+ 0 - 0
.scannerwork/.sonar_lock


+ 5 - 0
.scannerwork/report-task.txt

@@ -0,0 +1,5 @@
+projectKey=eiru:reporting
+serverUrl=http://181.40.66.126:9000
+dashboardUrl=http://181.40.66.126:9000/dashboard/index/eiru:reporting
+ceTaskId=AV9fLgk3LmS3QZZeLmuR
+ceTaskUrl=http://181.40.66.126:9000/api/ce/task?id=AV9fLgk3LmS3QZZeLmuR

BIN
__init__.pyc


BIN
controllers.pyc


BIN
models.pyc


+ 5 - 0
sonar-project.properties

@@ -0,0 +1,5 @@
+sonar.projectKey=eiru:reporting
+sonar.projectName=eiru_reporting
+sonar.projectVersion=1.0
+sonar.sources=.
+sonar.javascript.globals=openerp

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

@@ -35,6 +35,16 @@ function configuration_reporting (instance, widget) {
                 description: 'Permite visualizar un histórico de gastos realizado por la empresa.',
                 action: 'ReposrtExpenses'
             },
+            {
+                title: 'Histórico de gastos detallados',
+                description: 'Permite visualizar un histórico de gastos realizado por la empresa.',
+                action: 'ReposrtExpensesp'
+            },
+            {
+                title: 'Histórico de stock detallados',
+                description: 'Permite visualizar el stock detallados con diferentes filtros.',
+                action: 'ReportStockGral'
+            },
             {
                 title: 'Listado de productos',
                 description: 'Permite visualizar un listado de productos activos.',

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

@@ -13,6 +13,8 @@ openerp.eiru_reporting = function (instance) {
     report_resumen_ingresos(reporting);
     report_puchases(reporting);
     report_expenses(reporting);
+    report_expensesp(reporting);
+    report_stock_gral(reporting);
     // report_stock_location(reporting);
     report_stock_product(reporting);
 

+ 543 - 0
static/src/js/reports/report_expensesp.js

@@ -0,0 +1,543 @@
+function report_expensesp (reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReposrtExpensespWidget = reporting.Base.extend({
+            template: 'ReposrtExpensesp',
+            invoices: [],
+            invoiceLines: [],
+            Currency:[],
+            resCurrency :[],
+            resCompany:[],
+            productProdcut:[],
+            productCategory:[],
+            accountJournal:[],
+            supplier:[],
+            newInvoice:[],
+            rowsData :[],
+            // event
+            events:{
+                'click td > button' : 'clickOnAction',
+                'change #current-journal' : 'factSearch',
+                'change #current-currency' : 'factSearch',
+                'change #current-category' : 'factSearch',
+                'change #customer' : 'factSearch',
+                'change #from' : 'factSearch',
+                'change #to' : 'factSearch',
+                'click  #volver_btn' : 'volver',
+                'click-row.bs.table #table ' : 'ckickAnalysisDetail',
+            },
+            // 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();
+            },
+            // Analisis Detallado
+            ckickAnalysisDetail: function(e, row, $element,field){
+                if (field== 'number'){
+                    this.do_action({
+                        name:"Listado de Gastos Detallados",
+                        type: 'ir.actions.act_window',
+                        res_model: "account.invoice",
+                        views: [[false,'form']],
+                        target: 'new',
+                        domain: [['type', '=', 'in_invoice'],['id','=', row.id]],
+                        context: {},
+                        flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                        res_id: row.id,
+                    });
+                }
+                e.stopImmediatePropagation();
+            },
+            // 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 (invoices){
+                    self.invoices = invoices;
+                    return self.fetchInvoiceLines(invoices);
+                }).then(function (invoiceLines) {
+                    self.invoiceLines = invoiceLines;
+                    return self.fecthProduct(invoiceLines);
+                }).then(function(productProdcut){
+                    self.productProdcut = productProdcut;
+                    return self.fecthCategory();
+                }).then(function(productCategory){
+                    self.productCategory = productCategory;
+                    self.$el.find('#current-category').append('<option value="9999999">TODAS LAS CAT.</option>');
+                    _.each(productCategory, function (item) {
+                        self.$el.find('#current-category').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+                    return self.fetchSupplier();
+                }).then(function(supplier){
+                    self.supplier=supplier;
+                    return self.fecthComanyCurrency();
+                }).then(function(resCompany){
+                    self.resCompany = resCompany;
+                    self.inicializarBuscadorsup();
+                    return self.fect_generar(self.invoices);
+                });
+            },
+            // 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', 'invoice_line', '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;
+            },
+
+            // Invoice line (Linea de Factura)
+            fetchInvoiceLines: function (invoices) {
+              var defer = $.Deferred();
+              var linesIds = _.flatten(_.map(invoices, function (item) {
+                return item.invoice_line;
+              }));
+              var InvoiceLines = new instance.web.Model('account.invoice.line');
+              InvoiceLines.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', 'standard_price','type','categ_id'];
+                ProductProdcut.query(fields).filter([['id', 'in', porductIDS]]).all().then(function (results) {
+                    defer.resolve(results);
+                });
+                return defer;
+            },
+
+            // Obtener las lineas de las Facturas
+            getProduct: function(pro_id){
+                return _.find(this.productProdcut, function(prod){
+                    return _.contains(pro_id, prod.id);
+                });
+            },
+
+            // Buscar Category
+            fecthCategory: function () {
+                var self = this;
+                var defer = $.Deferred();
+                var productCategory = new instance.web.Model('product.category');
+                productCategory.query(['id', 'name', 'type']).filter([['type', '=', 'normal']]).all().then(function (results) {
+                    defer.resolve(results);
+                });
+                return defer;
+            },
+
+            // Obtener Detalles de la Factura
+            getInvoice: function (id_line){
+                return _.find(this.invoices, function (inv) {
+                    return _.contains(inv.invoice_line, id_line);
+                });
+            },
+
+            // 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(){
+                var self = this;
+                var data = [];
+                var invoice;
+                var item;
+                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 =="service"){
+                        data.push({
+                            number : (invoice.number),
+                            supplier_invoice_number: self.valorNull(invoice.supplier_invoice_number),
+                            name : (producto.name_template),
+                            date: moment(invoice.date_invoice).format("DD/MM/YYYY"),
+                            date_invoice: invoice.date_invoice,
+                            user: invoice.user_id[1],
+                            quantity : accounting.formatNumber((item.quantity),2, ".", ","),
+                            standar_price : accounting.formatNumber((item.price_unit),0, ".", ","),
+                            standar_tot : accounting.formatNumber((item.quantity * item.price_unit),0, ".", ","),
+                            journal_id : invoice.journal_id[0],
+                            currency_id : invoice.currency_id[0],
+                            partner_id : (invoice.partner_id[0]),
+                            categ_id : (producto.categ_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 cat = this.$el.find('#current-category').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]);
+                    });
+                }
+                // Buscar por moneda
+                if(currency != 9999999){
+                    newInvoice = _.filter(newInvoice,function(inv){
+                        return inv.currency_id == currency;
+                    });
+                }
+                // Buscar por proveedor
+                if (prov != ""){
+                    newInvoice = _.filter(newInvoice, function(inv){
+                        return inv.partner_id == prov[0];
+                    });
+                }
+                if (cat != 9999999){
+                    newInvoice=_.filter(newInvoice, function (inv){
+                        return inv.categ_id == cat;
+                    });
+                }
+                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);
+                var pdf_table = rowsTable;
+            },
+
+            getInvoice1 : function(currency_id){
+               var self = this;
+               return _.filter(self.rowsData, function(item){
+                   return item.currency_id === currency_id;
+               });
+            },
+
+            // Crear Objeto PDF
+            getObjetPdf: function(rowsTable){
+                var self = this;
+                var rows=[];
+                var amount_total=0;
+                var amount=0;
+
+                for (var i = 0; i < self.rowsData.length; i++) {
+                    var newInvoice = self.rowsData[i];
+                    rows.push({
+                        number: newInvoice.number,
+                        supplier_invoice_number: self.valorNull(newInvoice.supplier_invoice_number),
+                        name: newInvoice.name,
+                        quantity : newInvoice.quantity,
+                        standar_price : newInvoice.standar_price,
+                        standar_tot : newInvoice.standar_tot,
+                        date: moment(newInvoice.date_invoice).format("DD/MM/YYYY"),
+                        date_invoice: newInvoice.date_invoice,
+                        partner_id : newInvoice.partner_id
+                    });
+                    amount_total+=parseInt(newInvoice.standar_tot.replace(".",""));
+                }
+                rows.push({
+                    name : 'Total:',
+                    quantity : '',
+                    standard_price : '',
+                    standar_tot: accounting.formatNumber(amount_total,0,".",","),
+                });
+                return rows;
+            },
+
+            clickOnAction: function (e) {
+                var self = this;
+                var rowsNew;
+                var action = self.$el.find(e.target).val();
+                var table = self.$el.find("#table");
+                var data2 = table.bootstrapTable('getVisibleColumns');
+                var getColumns=[];
+                var rows=[];
+                rowsNew = self.getObjetPdf();
+
+                if (action === 'pdf') {
+                    var dataNEW = _.map(data2, function (val){
+                        return val.field;
+                        console.log(dataNEW);
+                    });
+                    _.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 cat = this.$el.find('#current-category 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:{
+                        number : {columnWidth: '8px'},
+                        supplier_invoice_number : {columnWidth: '8px'},
+                        name : {columnWidth: '8px'},
+                        standar_price : {halign:'right',columnWidth: '8px'},
+                        quantity :{halign:'right',columnWidth: '6px'},
+                        standar_tot : {halign:'right',columnWidth: '8px'},
+                    },
+                    margin: { top: 16, horizontal: 7},
+
+                    addPageContent: function (data2) {
+                        pdfDoc.setFontSize(12);
+                        pdfDoc.setFontStyle('bold');
+                        pdfDoc.setTextColor(40);
+                        pdfDoc.text('Histórico de gastos detallados ', data2.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, data2.settings.margin.left,14);
+                        }
+                        // FOOTER
+                        var str = "Pagina  " + data2.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, data2.settings.margin.left, pdfDoc.internal.pageSize.height - 5);
+                        }
+                });
+
+                if (typeof pdfDoc.putTotalPages === 'function') {
+                    pdfDoc.putTotalPages(totalPagesExp);
+                }
+                pdfDoc.save('Histórico de gastos detallados.pdf')
+            },
+    });
+}

+ 1 - 1
static/src/js/reports/report_puchases.js

@@ -300,7 +300,7 @@ function report_puchases (reporting){
                     return inv.currency_id == currency;
                 });
             }
-            // Busacara por proveedor
+            // Buscara por proveedor
             if (prov != ""){
                 newInvoice = _.filter(newInvoice, function(inv){
                     return inv.partner_id == prov[0];

+ 273 - 0
static/src/js/reports/report_stock_gral.js

@@ -0,0 +1,273 @@
+function report_stock_gral (reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportStockGralWidget = reporting.Base.extend({
+        template : 'ReportStockGral',
+        stockLocation : [],
+        stockQuant : [],
+        productProduct : [],
+        productTemplate : [],
+        productBrand : [],
+        productCategory : [],
+        product:[],
+
+        events : {
+            'click #toolbar > button' : 'clickOnAction',
+            'change #current-location': 'fecthSearch',
+            'change #current-category' : 'fecthSearch',
+            'change #current-brand' : 'fecthSearch',
+        },
+        init : function(parent){
+            this._super(parent);
+        },
+        start : function(){
+            var self = this;
+            var dato=[];
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.productProduct});
+            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 Ubicaciones.</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.fecthProductTemplate();
+            // }).then(function(productTemplate){
+            //     self.productTemplate = productTemplate;
+                return self.fecthProductBrand();
+            }).then(function(productBrand){
+                self.productBrand = productBrand;
+                self.$el.find('#current-brand').append('<option value="9999999">Todas las marcas</option>');
+                _.each(productBrand, function (item) {
+                    self.$el.find('#current-brand').append('<option value="' + item.id + '">' + item.name + '</option>');
+            });
+                return self.fecthCategory();
+            }).then(function(productCategory){
+                self.productCategory = productCategory;
+                self.$el.find('#current-category').append('<option value="9999999">Todas las cat.</option>');
+                _.each(productCategory, function (item) {
+                    self.$el.find('#current-category').append('<option value="' + item.id + '">' + item.name + '</option>');
+            });
+            return self.fecthProducto(self.stockQuant, self.stockLocation, self.productBrand);
+            });
+        },
+        // 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 productIDS = _.flatten(_.map(quant, function (item) {
+                return item.product_id[0];
+            }));
+            var ProductProduct =  new instance.web.Model('product.product');
+            var fields = ['id','name', 'standard_price','type','attribute_value_ids','product_brand_id','categ_id'];
+            ProductProduct.query(fields).filter([['id', 'in', productIDS]]).all().then(function (results) {
+              defer.resolve(results)
+            });
+            return defer;
+        },
+
+        // Buscar Category
+        fecthCategory: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var productCategory = new instance.web.Model('product.category');
+            productCategory.query(['id', 'name', 'type']).filter([['type', '=', 'normal']]).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        // Buscar marca
+        fecthProductBrand: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var productBrand = new instance.web.Model('product.brand');
+            productBrand.query(['id', 'name']).filter().all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+
+        // Verificar si los Valores no son nulos
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+
+        // Union de objetos
+        fecthProducto : function(stockQuant,stockLocation){
+            var self = this;
+            var stock=[];
+            var itemLocation;
+            var itemProduct;
+            var itemQuant;
+            var brand = this.$el.find('#current-brand').val();
+            var category = this.$el.find('#current-category').val();
+            var productProduct;
+            var categ;
+            var cat = 0;
+            var quant;
+            var valuation;
+           
+            // // console.log(this);
+            for (var i = 0; i < stockLocation.length; i++) {
+                itemLocation = stockLocation[i];
+                productProduct = self.getProductProduct(self.productProduct,stockQuant, itemLocation.id);
+                for (var f = 0; f < productProduct.length; f++) {
+                    itemProduct = productProduct[f];
+                    if(itemProduct.product_brand_id[0] == brand || brand == 9999999){
+                        if(itemProduct.categ_id[0] == category || category == 9999999){
+                            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();
+                                valuation = itemProduct.standard_price * cat
+                                stock.push({product : quant.product_id[1],
+                                            qty : cat,
+                                            brand : itemProduct.product_brand_id[1],
+                                            category : itemProduct.categ_id[1],
+                                            standard_price : accounting.formatNumber(itemProduct.standard_price,2, ".", ","),
+                                            valuation : accounting.formatNumber(valuation,2, ".", ","),
+                                            location :(itemLocation.location_id[1]+" / "+itemLocation.name)});
+                            }
+                        }   
+                    }
+                    
+                }
+            }
+            self.loadTable(stock);
+        },
+        // Obtener Producto Por quant y locations
+        getProductProduct: 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 quantProduct = quantObjs;
+            if (location_id){
+                quantProduct = _.filter(quantProduct, function(item){
+                    return item.location_id[0] === location_id;
+                });
+            }
+            if (product_id){
+                quantProduct = _.filter(quantProduct, function(item){
+                    return item.product_id[0] === product_id;
+                });
+            }
+
+            return quantProduct;
+        },
+
+        // Buscar
+        fecthSearch: function(){
+            var self = this;
+            var location =this.$el.find('#current-location').val();
+            var locationObjs = self.stockLocation;
+            var quantObjs = self.stockQuant;
+            var quant;
+            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.product=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.product,function (item){
+                    rows.push(_.pick(item, dataNEW));
+                });
+              // Obtener los nombre de la Cabecera
+                _.each(_.map(data2,function(val){return val}), function(item){
+                    getColumns.push([{
+                                    title: item.title,
+                                    dataKey: item.field
+                                }]);
+                });
+                self.drawPDF(_.flatten(getColumns),rows)
+            }
+        },
+    });
+}

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

@@ -100,6 +100,7 @@ function report_stock_location (reporting){
             for (var i = 0; i < stockLocation.length; i++) {
                 itemLocation = stockLocation[i];
                 productProduct = self.getProdcutoProduct(self.productProduct,stockQuant, itemLocation.id);
+                console.log(productProduct);
                 for (var f = 0; f < productProduct.length; f++) {
                     itemProduct = productProduct[f];
                     itemQuant = self.getQuantProduct(itemLocation.id, itemProduct.id, stockQuant);

+ 20 - 64
static/src/js/reports/report_stock_product.js

@@ -9,7 +9,6 @@ function report_stock_product (reporting){
         stockQuant : [],
         productProduct : [],
         prodcut:[],
-        newStock:[],
 
         events : {
             'click #toolbar > button' : 'clickOnAction',
@@ -111,7 +110,6 @@ function report_stock_product (reporting){
             var productProduct;
             var cat = 0;
             var quant;
-            var total=0;
 
             productProduct = self.getProdcutoProduct(self.productProduct,stockQuant);
             for (var f = 0; f < productProduct.length; f++) {
@@ -124,17 +122,14 @@ function report_stock_product (reporting){
                         return mamo + num;
                     },0);
                     quant=itemQuant.shift();
-                    total = parseInt(cat * itemProduct.standard_price);
                     stock.push({ id : quant.product_id[0],
                                 product : quant.product_id[1],
                                 qty : cat,
-                                standard_price : accounting.formatNumber(itemProduct.standard_price,0, ".", ","),
-                                lst_price : accounting.formatNumber(itemProduct.lst_price,0, ".", ","),
-                                total: accounting.formatNumber(total,0,".",",")
+                                standard_price : accounting.formatNumber(itemProduct.standard_price,2, ".", ","),
+                                lst_price : accounting.formatNumber(itemProduct.lst_price,2, ".", ","),
                             });
                 }
             }
-            self.newStock = stock;
             self.loadTable(stock);
         },
         // Obtener Producto Por quant y locations
@@ -164,67 +159,31 @@ function report_stock_product (reporting){
             var table = this.$el.find('#table');
             table.bootstrapTable('load' ,rowsTable);
         },
-
-        // Cambiar la impresion del pdf
-
-        // Crear el objeto PDF
-        getObjetPdf: function(){
-            var self = this;
-            var rows=[];
-            var newStock = self.newStock;
-            var amount_total = 0;
-            var qty = 0;
-            for (var i = 0; i < newStock.length; i++) {
-                rows.push({
-                    product : newStock[i].product,
-                    qty : newStock[i].qty,
-                    standard_price : newStock[i].standard_price,
-                    lst_price : newStock[i].lst_price,
-                    total: newStock[i].total
-                });
-                qty+=parseInt(newStock[i].qty);
-                amount_total+=parseInt(newStock[i].total.replace(".",""));
-            }
-            rows.push({
-                product : 'Totales',
-                qty : accounting.formatNumber(qty,0,".",","),
-                standard_price : '',
-                lst_price : '',
-                total: accounting.formatNumber(amount_total,0,".",","),
-            });
-            return rows;
-        },
-
-        // imprimir PDF
+        // Click pdf -Grafic
         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();
+            var table = self.$el.find("#table");
+            var data2 = table.bootstrapTable('getVisibleColumns');
             if (action === 'pdf') {
                 var dataNEW = _.map(data2, function (val){
                     return val.field;
                 });
-                _.each(rowsNew,function (item){
+                _.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
-                                    }]);
+              // 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);
+                self.drawPDF(_.flatten(getColumns),rows)
             }
         },
-
         // pdfDoc
         drawPDF:function(getColumns,rows){
             var self = this;
@@ -234,14 +193,13 @@ function report_stock_product (reporting){
             var pdfDoc = new jsPDF();
             pdfDoc.autoTable(getColumns, rows, {
                     styles: { overflow: 'linebreak', fontSize:8 , columnWidth: 'wrap'},
-                    columnStyles:{
+                   columnStyles:{
                                     product :{columnWidth: '8px'},
-                                    qty : {halign:'center'},
-                                    standard_price : {halign:'right'},
-                                    lst_price : {halign:'right'},
-                                    total : {halign:'right'},
+                                   qty : {halign:'center'},
+                                   standard_price : {halign:'right'},
+                                   lst_price : {halign:'right'},
                                 },
-                    margin: { top: 16, horizontal: 7},
+                   margin: { top: 16, horizontal: 7},
                 addPageContent: function (data) {
                     pdfDoc.setFontSize(12);
                     pdfDoc.setFontStyle('bold');
@@ -250,8 +208,7 @@ function report_stock_product (reporting){
                     // 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();
+                        str = str + " de " + totalPagesExp +"\n  Día de Expedición  "+fechaActu.getDate()+"/"+fechaActu.getMonth()+"/"+fechaActu.getFullYear();
                     }
                     pdfDoc.setFontSize(9);
                     pdfDoc.setFontStyle('bold');
@@ -262,8 +219,7 @@ function report_stock_product (reporting){
             if (typeof pdfDoc.putTotalPages === 'function') {
                 pdfDoc.putTotalPages(totalPagesExp);
             }
-            pdfDoc.save('Listado de productos.pdf');
+           pdfDoc.save('Listado de productos de '+location+'.pdf');
         }
-
     });
 }

+ 93 - 0
static/src/reports/report_expensesp.xml

@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+    <template xml:space="preserve">
+      <t t-name="ReposrtExpensesp">
+        <div class="report_view">
+          <div class="reporting_page_header">
+            <h1>Listado de Gastos Detallados</h1>
+            <div id="volver"></div>
+            </div>
+            <div id="toolbar">
+                <table class="table table-condensed">
+                    <tbody>
+                        <tr>
+                            <td>
+                                <div class="form-group">
+                                    <label for="current-journal">Sucursal: </label>
+                                    <select id="current-journal" class="form-control ui-autocomplete-input"  name="journal"></select>
+                                </div>
+                            </td>
+                            <td>
+                                <div class="form-group">
+                                    <label for="current-currency">Moneda: </label>
+                                    <select id="current-currency" class="ui-autocomplete-input"  name="currency"></select>
+                                </div>
+                            </td>
+                            <td>
+                                <div class="form-group">
+                                    <label for="from">Desde: </label>
+                                    <input type="text" class="form-control" id="from" name="from"/>
+                                </div>
+                            </td>
+                            <td>
+                                <div class="form-group">
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text" class="form-control" id="to" name="to" />
+                                </div>
+                            </td>
+                        </tr>
+                        <tr>
+                            <td>
+                                <div class="form-group">
+                                  <label for="current-category">Categoria:</label>
+                                  <select id="current-category" class="form-control ui-autocomplete-input" name="category"></select>
+                                </div>
+                            </td>
+                            <td>
+                                <div class="form-group">
+                                    <label for="customer">Proveedor:</label>
+                                    <input id="customer" type="text" class="form-control" autocomplete="off" placeholder="Nombre o número de cédula"/>
+                                    <input id="customer-id" type="hidden" name="customer"/>
+                                </div>
+                            </td>
+                            <td></td>
+                        </tr>
+                        <tr>
+                            <td></td>
+                            <td></td>
+                            <td>
+                                <button class="oe_button oe_form_button oe_highlight btn-block" value="pdf">Exportar a PDF</button>
+                            </td>
+                            <td>
+
+                            </td>
+                        </tr>
+                    </tbody>
+                </table>
+            </div>
+            <table id="table"
+                data-pagination="true"
+                data-toggle="table"
+                data-reorderable-columns="true"
+                data-toolbar="#toolbar"
+                data-show-columns="true"
+                data-buttons-class="oe_button oe_form_button oe_highlight"
+                data-height="auto"
+                data-classes="table table-hover table-condensed"
+                data-row-style="rowStyle"
+                data-search="true">
+                <thead>
+                    <tr>
+                        <th data-field="number" data-sortable="true">Factura</th>
+                        <th data-field="supplier_invoice_number" data-sortable="true">Referencia</th>
+                        <th data-field="name" data-sortable="true">Producto</th>
+                        <th data-field="standar_price" data-sortable="true" data-align="right">Precio de Costo</th>
+                        <th data-field="quantity" data-sortable="true" data-align="right">Cant.</th>
+                        <th data-field="standar_tot" data-sortable="true" data-align="right">Total Costo</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+            <div id="dialog"></div>
+        </div>
+        </t>
+    </template>

+ 70 - 0
static/src/reports/report_stock_gral.xml

@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+    <template xml:space="preserve">
+        <t t-name="ReportStockGral">
+            <div class="report_view">
+                <div class="reporting_page_header">
+                    <h1>Listado de Stock Detallado</h1>
+                    <div id="volver"></div>
+                </div>
+                <!-- <div id="toolbar"> -->
+                    <table class="table table-condensed">
+                        <tbody>
+                            <tr>
+                                <td>
+                                    <div class="form-group">
+                                        <label for="current-location">Sucursal: </label>
+                                        <select id="current-location" class=" ui-autocomplete-input form-control"  name="journal"></select>
+                                    </div>
+                                </td>
+                                <td>
+                                    <div class="form-group">
+                                        <label for="current-brand">Marca: </label>
+                                        <select id="current-brand" class=" ui-autocomplete-input form-control"  name="brand"></select>
+                                    </div>
+                                </td>
+                                <td>
+                                    <div class="form-group">
+                                        <label for="current-category">Categoria:</label>
+                                        <select id="current-category" class="form-control ui-autocomplete-input" name="category"></select>
+                                    </div>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td></td>
+                                <td>
+                                    <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">Exportar a PDF</button>
+                                </td>
+                                <td>
+                                </td>
+                            </tr>
+                        </tbody>
+                    </table>
+                <!-- </div> -->
+                <table id="table"
+                       data-pagination="true"
+                       data-toggle="table"
+                       data-reorderable-columns="true"
+                       data-toolbar="#toolbar"
+                       data-show-columns="true"
+                       data-buttons-class="oe_button oe_form_button oe_highlight"
+                       data-height="auto"
+                       data-classes="table table-hover table-condensed"
+                       data-row-style="rowStyle"
+                       data-search="true">
+                    <thead>
+                        <tr>
+                            <th data-field="product" data-sortable="true" >Productos</th>
+                            <th data-field="brand" data-sortable="true" >Marca</th>
+                            <th data-field="category" data-sortable="true" >Categoria</th>
+                            <th data-field="qty" data-sortable="true" data-align="center">Cantidad</th>
+                            <th data-field="standard_price" data-sortable="true" data-align="right">Precio</th>
+                            <th data-field="valuation" data-sortable="true" data-align="right">Valoracion</th>
+                            <th data-field="location" data-sortable="true">Ubicación</th>
+                        </tr>
+                    </thead>
+                </table>
+                <div class="widget-content" id="grafico"></div>
+                <div id="dialog"></div>
+            </div>
+        </t>
+    </template>

+ 1 - 2
static/src/reports/report_stock_product.xml

@@ -7,7 +7,7 @@
                     <div id="volver"></div>
                 </div>
                 <div id="toolbar">
-                    <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">Exportar</button>
+                    <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">Exportar a PDF</button>
                 </div>
                 <table id="table" class="table_paint_first_row"
                        data-pagination="true"
@@ -27,7 +27,6 @@
                             <th data-field="qty" data-sortable="true" data-align="center">Cantidad</th>
                             <th data-field="standard_price" data-sortable="true" data-align="right">Precio de compra</th>
                             <th data-field="lst_price" data-sortable="true" data-align="right">Precio de venta </th>
-                            <th data-field="total" data-sortable="true" data-align="right">Valoración de stock</th>
                         </tr>
                     </thead>
                 </table>

+ 2 - 0
templates.xml

@@ -17,8 +17,10 @@
                 <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_expensesp.js" />
                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_stock_location.js" />
                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_stock_product.js" />
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_stock_gral.js" />
 
             </xpath>
         </template>