Forráskód Böngészése

FIX Report de utilidad de productos sobre ventas por compañia

Sebas 7 éve
szülő
commit
1f14b36813
2 módosított fájl, 105 hozzáadás és 91 törlés
  1. 101 91
      static/src/js/main.js
  2. 4 0
      static/src/reports/report_invoice_utility.xml

+ 101 - 91
static/src/js/main.js

@@ -38,6 +38,13 @@ openerp.eiru_utilidad_golden = function (instance,local) {
             this.fecthFecha();
             this.submitForm();
         },
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
         // Analisis Detallado
         ckickAnalysisDetail: function(e, row, $element, field){
 
@@ -100,6 +107,7 @@ openerp.eiru_utilidad_golden = function (instance,local) {
                 _.each(resCompany,function(item){
                     self.$el.find('#current-company').append('<option value="' + item.id + '">' + item.name + '</option>');
                 });
+                self.searchProduct();
                 return self.invoice_Currency();
             });
         },
@@ -215,6 +223,33 @@ openerp.eiru_utilidad_golden = function (instance,local) {
             });
             return defer;
         },
+
+        searchProduct: function () {
+            var self = this;
+            var results = self.productProduct;
+            results = _.map(results, function (item) {
+                return {
+                    label: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) ' ,
+                    value: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) '
+                }
+            });
+            self.$('#product').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#product').val())){
+                        self.fectSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.fectSearch();
+                },
+                select: function(event, ui) {
+                    self.fectSearch();
+                }
+            });
+        },
+
         // Obtener Monedas de la Factura
         getCutrrency: function (id){
             return _.find(this.Currency,function (curr) {
@@ -255,6 +290,7 @@ openerp.eiru_utilidad_golden = function (instance,local) {
             var data=[];
             var item;
             var invoice;
+            var attribute;
             var producto;
             var invoiceLines = self.invoiceLines;
 
@@ -262,6 +298,11 @@ openerp.eiru_utilidad_golden = function (instance,local) {
                 item = this.invoiceLines[i];
                 invoice = this.getInvoice(item.id);
                 producto =this.getProduct(item.product_id);
+                // if(producto.attribute_str){
+                //     attribute = '*' + item.attribute_str;
+                // }else{
+                //     attribute = ' ';
+                // }
                 if (!producto){
                     producto={};
                     producto.standard_price=0;
@@ -279,6 +320,10 @@ openerp.eiru_utilidad_golden = function (instance,local) {
                             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]),
+                            quantity_tot : (item.quantity),
+                            price_tot_tot : (item.quantity * (item.price_unit / invoice.rate)),
+                            standar_tot_tot : ((item.quantity * producto.standard_price)),
+                            utility_total : (((item.quantity * (item.price_unit / invoice.rate)) - (item.quantity * producto.standard_price))),
                             company_id :(invoice.company_id[0]),
                             company_name :(invoice.company_id[1]),
                             journal_name :(invoice.journal_id[1]),
@@ -286,7 +331,8 @@ openerp.eiru_utilidad_golden = function (instance,local) {
                             date: invoice.date_invoice
                     });
           }
-          self.rowsData = data;
+          this.rowsData=data;
+          self.content = data;
           this.loadTable(data);
         },
         // Buscar
@@ -298,10 +344,11 @@ openerp.eiru_utilidad_golden = function (instance,local) {
             var last_month = moment().add(-1, 'months').format('YYYY-MM');
             var desde = self.$el.find('#from').val();
             var hasta = self.$el.find('#to').val();
+            var product= this.$el.find('#product').val().split('-');
             var company = self.$el.find('#current-company').val().split('-');
 
             // var suc = self.$el.find('#current-journal').val();
-            var content = self.rowsData;
+            var content = self.content;
 
             if ($('#A').is(":checked")){
                 content = _.filter(content, function (inv){
@@ -351,27 +398,73 @@ openerp.eiru_utilidad_golden = function (instance,local) {
                     return inv.company_id == company;
                 });
             }
+            if (product != ""){
+                content = _.filter(content, function(inv){
+                    return inv.id_product == product[0];
+                });
+            }
+
+            var quantity_total = _.reduce(_.map(content,function(map){
+                return(map.quantity_tot);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+
+            var price_tot_total = _.reduce(_.map(content,function(map){
+                return(map.price_tot_tot);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+
+            var standar_tot_total = _.reduce(_.map(content,function(map){
+                return(map.standar_tot_tot);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+
+            var utility_total = _.reduce(_.map(content,function(map){
+                return(map.utility_total);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+
+            content.push({
+                number: "Total",
+                quantity: accounting.formatNumber((quantity_total),0,".",","),
+                price_tot: accounting.formatNumber((price_tot_total),2,".",","),
+                standar_tot: accounting.formatNumber((standar_tot_total),2,".",","),
+                utility: accounting.formatNumber((utility_total),2,".",","),
+            });
 
             self.loadTable(content);
         },
         // cargara la tabla
         loadTable:function(rowsTable){
             var self = this;
-            // self.rowsData = rowsTable;
+            self.rowsData = rowsTable;
             var table = this.$el.find('#table');
             table.bootstrapTable('load',rowsTable);
         },
         // imprimir PDF
+        getObjectPdf: function(){
+            var self = this;
+            var rows=[];
+            var rows = self.rowsData;
+
+            return rows;
+        },
         clickOnAction: function (e) {
-            var action = this.$el.find(e.target).val();
             var self = this;
+            var action = this.$el.find(e.target).val();
             var getColumns=[];
+            var rowsNew;
             var rows=[];
             var table = this.$el.find("#table");
             var data2 = table.bootstrapTable('getVisibleColumns');
+            rowsNew = self.getObjectPdf();
             if (action === 'pdf') {
                 var dataNEW = _.map(data2, function (val){ return val.field});
-                _.each(this.rowsData,function (item){
+                _.each(rowsNew,function (item){
                     rows.push(_.pick(item, dataNEW));
                 });
                 // Obtener los nombre de la Cabezera
@@ -385,35 +478,7 @@ openerp.eiru_utilidad_golden = function (instance,local) {
                 // 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) {
@@ -425,54 +490,12 @@ openerp.eiru_utilidad_golden = function (instance,local) {
             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, {
+            pdfDoc.autoTable(getColumns, rows, {
                 styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
                 columnStyles: {
                               number: {fontStyle: 'bold'},
@@ -489,21 +512,8 @@ openerp.eiru_utilidad_golden = function (instance,local) {
                     pdfDoc.setFontSize(12);
                     pdfDoc.setFontStyle('bold');
                     pdfDoc.setTextColor(40);
-                    pdfDoc.text('Utilidad de facturas detalladas por '+ sucusal, data.settings.margin.left, 10);
+                    pdfDoc.text('Utilidad de facturas detalladas', 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+

+ 4 - 0
static/src/reports/report_invoice_utility.xml

@@ -57,6 +57,10 @@
                                   <label for="current-company">Compania: </label>
                                   <select id="current-company" class="form-control ui-autocomplete-input" name="company"></select>
                               </div>
+                              <div class="form-group">
+                                  <label for="product">Buscar Producto:</label>
+                                  <input id="product" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ Referencia/ Codigo de barras"/>
+                              </div>
                           </div>
                       </div>
                   </div>