|
@@ -0,0 +1,621 @@
|
|
|
+function report_product_pack_utilidad (reporting) {
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var instance = openerp;
|
|
|
+
|
|
|
+ reporting.ReportProductPackUtilidadWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportProductPackUtilidad',
|
|
|
+ data: [],
|
|
|
+ PosOrderLine: [],
|
|
|
+ PosOrder: [],
|
|
|
+ invoiceLine: [],
|
|
|
+ ProductProduct: [],
|
|
|
+ rowsData: [],
|
|
|
+ productPack: [],
|
|
|
+ productAtributo: [],
|
|
|
+ ranking: [],
|
|
|
+ content: [],
|
|
|
+ modelId: [],
|
|
|
+
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #X' : 'factSearch',
|
|
|
+ 'click #A' : 'factSearch',
|
|
|
+ 'click #B' : 'factSearch',
|
|
|
+ 'click #C' : 'factSearch',
|
|
|
+ 'click #D' : 'factSearch',
|
|
|
+ 'click #Z' : 'factSearch',
|
|
|
+ 'change #from' : 'factSearch',
|
|
|
+ 'change #to': 'factSearch',
|
|
|
+
|
|
|
+ 'click #Y' : 'factSearch',
|
|
|
+ 'click-row.bs.table #table ' : 'clickAnalysisDetail',
|
|
|
+ },
|
|
|
+
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
+ this.fecthFecha();
|
|
|
+ this.submitForm();
|
|
|
+ },
|
|
|
+
|
|
|
+ // Redirecionar
|
|
|
+ renderReport: function () {
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
|
|
|
+ this.$el.closest('.report_view').remove();
|
|
|
+ container.find('.report_view').show({
|
|
|
+ effect: 'fade',
|
|
|
+ duration: 200,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Verificar el modelo
|
|
|
+ checkModel : function(model){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.modules,function(item){return item.name === model});
|
|
|
+ },
|
|
|
+
|
|
|
+ // Lanzar el mensaje
|
|
|
+ showMensaje : function(modelos){
|
|
|
+ var self = this;
|
|
|
+ $("#dialog" ).dialog({
|
|
|
+ autoOpen: true,
|
|
|
+ resizable: false,
|
|
|
+ modal: true,
|
|
|
+ title: 'Atención',
|
|
|
+ width: 500,
|
|
|
+ open: function() {
|
|
|
+ $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
|
|
|
+ },
|
|
|
+ show: {
|
|
|
+ effect: "fade",
|
|
|
+ duration: 200
|
|
|
+ },
|
|
|
+ hide: {
|
|
|
+ effect: "fade",
|
|
|
+ duration: 200
|
|
|
+ },
|
|
|
+ buttons: {
|
|
|
+ Aceptar: function() {
|
|
|
+ $(this).dialog('close');
|
|
|
+ self.renderReport()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return
|
|
|
+ },
|
|
|
+
|
|
|
+ // Analisis Detallado
|
|
|
+ clickAnalysisDetail: function(e, row, $element, field){
|
|
|
+
|
|
|
+ if (field == 'product_main'){
|
|
|
+ this.do_action({
|
|
|
+ name : "Registro de Producto",
|
|
|
+ type : 'ir.actions.act_window',
|
|
|
+ res_model : "product.product",
|
|
|
+ views : [[false,'form']],
|
|
|
+ target : 'new',
|
|
|
+ domain : [['id','=', row.product_main_id]],
|
|
|
+ context : {},
|
|
|
+ flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id : row.product_main_id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ e.stopImmediatePropagation();
|
|
|
+ },
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ submitForm: function () {
|
|
|
+ var self = this;
|
|
|
+ self.fecthIrModuleModule().then(function(modules){
|
|
|
+ self.modules = modules;
|
|
|
+ return modules;
|
|
|
+ }).then(function(modules){
|
|
|
+ return self.fecthPosOrder();
|
|
|
+ }).then(function (PosOrder) {
|
|
|
+ self.PosOrder = PosOrder;
|
|
|
+ return self.fecthPosOrderLine(PosOrder);
|
|
|
+ }).then(function (PosOrderLine) {
|
|
|
+ self.PosOrderLine = PosOrderLine;
|
|
|
+ return self.fetchProductProduct();
|
|
|
+ }).then(function (ProductProduct) {
|
|
|
+ self.ProductProduct = ProductProduct;
|
|
|
+ return self.fetchProductPack();
|
|
|
+ }).then(function(productPack){
|
|
|
+ self.productPack = productPack;
|
|
|
+ self.search();
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ // Obtener Pedido ,['id', 'in', ['1065','1067']]
|
|
|
+ fecthPosOrder: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var modules = self.checkModel('point_of_sale');
|
|
|
+
|
|
|
+ if (modules.length <= 0){
|
|
|
+ self.showMensaje('point_of_sale');
|
|
|
+ return defer;
|
|
|
+ }
|
|
|
+
|
|
|
+ var fields = ['id', 'lines', 'date_order'];
|
|
|
+ var domain = [ ['state', 'in', ['paid','done','invoiced']]];
|
|
|
+ var PosOrder = new instance.web.Model('pos.order');
|
|
|
+ PosOrder.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Obtener linea de la factura
|
|
|
+ fecthPosOrderLine: function(PosOrder) {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var lines = _.flatten(_.map(PosOrder, function (item) {
|
|
|
+ return item.lines;
|
|
|
+ }));
|
|
|
+ var fields = ['id', 'product_id', 'create_date', 'qty'];
|
|
|
+ var domain = [['id','in', lines]];
|
|
|
+ var PosOrderLine = new instance.web.Model('pos.order.line');
|
|
|
+ PosOrderLine.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Obtener Productos ,['id', '=', 110]
|
|
|
+ fetchProductProduct: function (PosOrderLine) {
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var modules = self.checkModel('product_pack');
|
|
|
+
|
|
|
+ if (modules.length <= 0){
|
|
|
+ self.showMensaje('product_pack');
|
|
|
+ return defer;
|
|
|
+ }
|
|
|
+ var product_id = _.flatten(_.map(PosOrderLine,function (item) {
|
|
|
+ return item.product_id[0];
|
|
|
+ }));
|
|
|
+ var fields = ['id', 'name','name_template', 'pack_line_ids','type', 'ean13','attribute_str', 'standard_price', 'lst_price'];
|
|
|
+ var domain = [['active', '=', true],['pack', '=', true]];
|
|
|
+ var ProductProduct = new instance.web.Model('product.product');
|
|
|
+ ProductProduct.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor ="";
|
|
|
+ if (dato){
|
|
|
+ valor=dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ // Product Pack
|
|
|
+ fetchProductPack: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var ids = _.flatten(_.map(self.ProductProduct,function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ var fields = ['id','product_id', 'price','parent_product_id', 'quantity', 'subtotal'];
|
|
|
+ var domain = [['parent_product_id', 'in', ids]];
|
|
|
+ var ProductPack = new instance.web.Model('product.pack.line');
|
|
|
+ ProductPack.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ getProductPack: function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.productPack,function (item) {
|
|
|
+ return item.parent_product_id[0] == id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getPosOrder: function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.PosOrder,function (item) {
|
|
|
+ return item.id == id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getProductProduct: function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ProductProduct,function (item) {
|
|
|
+ return item.id == id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ search: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.ProductProduct;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
+ return {
|
|
|
+ label: item.id + '- '+ ' [ ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' + self.valorNull(item.attribute_str) + ' ) ' ,
|
|
|
+ value: item.id + '- '+ ' [ ' + 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.factSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.factSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // Obtener facturas por cada clientes
|
|
|
+ getPosOrderLiners:function(product_id) {
|
|
|
+ var self = this;
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
+ var PosOrderLine = self.PosOrderLine;
|
|
|
+ // Hoy
|
|
|
+ if ($('#A').is(":checked")){
|
|
|
+ PosOrderLine = _.filter(PosOrderLine, function (inv){
|
|
|
+ return moment(inv.create_date).format('YYYY-MM-DD') == moment().format('YYYY-MM-DD');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Ayer
|
|
|
+ if ($('#B').is(":checked")){
|
|
|
+ PosOrderLine = _.filter(PosOrderLine, function (inv){
|
|
|
+ return moment(inv.create_date).format('YYYY-MM-DD') == moment().add(-1,'days').format('YYYY-MM-DD');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Mes Actual
|
|
|
+ if ($('#C').is(":checked")){
|
|
|
+ PosOrderLine = _.filter(PosOrderLine, function (inv){
|
|
|
+ return moment(inv.create_date).format('MM') == moment().format('MM');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Mes Pasado
|
|
|
+ if ($('#D').is(":checked")){
|
|
|
+ PosOrderLine = _.filter(PosOrderLine, function (inv){
|
|
|
+ return moment(inv.create_date).format('MM') == moment().add(-1,'months').format('MM');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // Rango de fechas
|
|
|
+ if ($('#Z').is(":checked")){
|
|
|
+ $('#datepicker').css('display','block');
|
|
|
+ if (desde.length > 0){
|
|
|
+ var date = desde.split('/');
|
|
|
+ PosOrderLine = _.filter(PosOrderLine, function (inv){
|
|
|
+ return moment(inv.create_date).format('YYYY-MM-DD') >= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (hasta.length > 0){
|
|
|
+ var date= hasta.split('/');
|
|
|
+ PosOrderLine = _.filter(PosOrderLine, function (inv){
|
|
|
+ return moment(inv.create_date).format('YYYY-MM-DD') <= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $('#datepicker').css('display','none');
|
|
|
+ }
|
|
|
+
|
|
|
+ return _.flatten(_.filter(PosOrderLine,function (inv) {
|
|
|
+ return inv.product_id[0] === product_id;
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // Generar el ranking
|
|
|
+ // Generar el ranking
|
|
|
+ BuildTable: function() {
|
|
|
+ var self = this;
|
|
|
+ var itemProduct;
|
|
|
+ var itemLine;
|
|
|
+ var qty = 0;
|
|
|
+ var ProductProduct = self.ProductProduct;
|
|
|
+ var rankingCab = [];
|
|
|
+ var rankingItem = [];
|
|
|
+ var cat = 0;
|
|
|
+ var itemProductPack;
|
|
|
+ var countSalesOrder = 0;
|
|
|
+ var attribute;
|
|
|
+ var lineUnik;
|
|
|
+
|
|
|
+ // for (var i = 0; i < self.ProductProduct.length; i++) {
|
|
|
+ // itemProduct = self.ProductProduct[i];
|
|
|
+ // itemLine = self.getPosOrderLiners(itemProduct.id);
|
|
|
+ //
|
|
|
+ // //var itemLine = self.getPosOrderLiners(varitemProduct.id);
|
|
|
+ // console.log(itemLine);
|
|
|
+ // if (itemLine.length > 0) {
|
|
|
+ // cat = _.reduce(_.map(itemLine, function (map) {
|
|
|
+ // return map.qty
|
|
|
+ // }), function (meno,num) {
|
|
|
+ // return meno + num
|
|
|
+ // }, 0);
|
|
|
+ // }
|
|
|
+ // //lineUnik = itemLine.shift();
|
|
|
+ //
|
|
|
+ // if(itemProduct.attribute_str){
|
|
|
+ // attribute = ' ' + itemProduct.attribute_str;
|
|
|
+ // }else{
|
|
|
+ // attribute = ' ';
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // rankingItem.push({
|
|
|
+ // product_main: itemProduct.name_template+ attribute,
|
|
|
+ // price_venta: accounting.formatNumber(itemProduct.lst_price,0,".",","),
|
|
|
+ // price_costo: accounting.formatNumber(itemProduct.standard_price,0,".",","),
|
|
|
+ // product: "",
|
|
|
+ // price_insumo: "",
|
|
|
+ // qty_pos: cat,
|
|
|
+ // qty: "",
|
|
|
+ // subtotal_total_venta: accounting.formatNumber((itemProduct.lst_price*cat),0,".",","),
|
|
|
+ // subtotal_total: accounting.formatNumber((itemProduct.standard_price*cat),0,".",","),
|
|
|
+ // utilidad: accounting.formatNumber(((itemProduct.lst_price*cat)-(itemProduct.standard_price*cat)),0,".",","),
|
|
|
+ // countPack: "",
|
|
|
+ // product_main_id: itemProduct.id
|
|
|
+ // });
|
|
|
+ //
|
|
|
+ // itemProductPack = self.getProductPack(itemProduct.id);
|
|
|
+ //
|
|
|
+ // for (var i = 0; i < itemProductPack.length; i++) {
|
|
|
+ // if (itemProductPack.length > 0){
|
|
|
+ // rankingItem.push({
|
|
|
+ // product_main: "",
|
|
|
+ // price_venta: "",
|
|
|
+ // price_costo: "",
|
|
|
+ // product: itemProductPack[i].product_id[1],
|
|
|
+ // price_insumo: accounting.formatNumber(itemProductPack[i].price,0,".",","),
|
|
|
+ // qty_pos: cat,
|
|
|
+ // qty: accounting.formatNumber((itemProductPack[i].quantity*cat),3,".",","),
|
|
|
+ // subtotal_total_venta: "",
|
|
|
+ // subtotal_total: accounting.formatNumber((itemProductPack[i].price*itemProductPack[i].quantity*cat),0,".",","),
|
|
|
+ // subtotal: accounting.formatNumber(itemProductPack[i].subtotal,2,".",","),
|
|
|
+ // utilidad: "",
|
|
|
+ // //create_date: moment(itemLine.create_date).format("YYYY-MM-DD"),
|
|
|
+ // countPack: itemProductPack[i].quantity*cat,
|
|
|
+ // product_main_id: itemProductPack[i].parent_product_id[0],
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // Generar Objeto Principal
|
|
|
+ // rankingItem=rankingItem.concat(rankingCab);
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // self.content = rankingItem;
|
|
|
+ // self.loadTable(rankingItem);
|
|
|
+ //
|
|
|
+ // },
|
|
|
+
|
|
|
+ _.each(ProductProduct, function(item){
|
|
|
+
|
|
|
+ itemLine = self.getPosOrderLiners(item.id);
|
|
|
+ if (itemLine.length > 0) {
|
|
|
+ cat = _.reduce(_.map(itemLine, function (map) {
|
|
|
+ return map.qty
|
|
|
+ }), function (meno,num) {
|
|
|
+ return meno + num
|
|
|
+ }, 0);
|
|
|
+ }
|
|
|
+ if(item.attribute_str){
|
|
|
+ attribute = ' ' + item.attribute_str;
|
|
|
+ }else{
|
|
|
+ attribute = ' ';
|
|
|
+ }
|
|
|
+ itemProductPack = self.getProductPack(item.id);
|
|
|
+
|
|
|
+ rankingItem.push({
|
|
|
+ product_main: item.name_template+ attribute,
|
|
|
+ price_venta: accounting.formatNumber(item.lst_price,0,".",","),
|
|
|
+ price_costo: accounting.formatNumber(item.standard_price,0,".",","),
|
|
|
+ product: "",
|
|
|
+ price_insumo: "",
|
|
|
+ qty_pos: cat,
|
|
|
+ qty: "",
|
|
|
+ subtotal_total_venta: accounting.formatNumber((item.lst_price*cat),0,".",","),
|
|
|
+ subtotal_total: accounting.formatNumber((item.standard_price*cat),0,".",","),
|
|
|
+ utilidad: accounting.formatNumber(((item.lst_price*cat)-(item.standard_price*cat)),0,".",","),
|
|
|
+ countPack: "",
|
|
|
+ product_main_id: item.id
|
|
|
+ });
|
|
|
+
|
|
|
+ for (var i = 0; i < itemProductPack.length; i++) {
|
|
|
+
|
|
|
+
|
|
|
+ if (itemProductPack.length > 0){
|
|
|
+ rankingItem.push({
|
|
|
+ product_main: "",
|
|
|
+ price_venta: "",
|
|
|
+ price_costo: "",
|
|
|
+ product: itemProductPack[i].product_id[1],
|
|
|
+ price_insumo: accounting.formatNumber(itemProductPack[i].price,0,".",","),
|
|
|
+ qty_pos: cat,
|
|
|
+ qty: accounting.formatNumber((itemProductPack[i].quantity*cat),3,".",","),
|
|
|
+ subtotal_total_venta: "",
|
|
|
+ subtotal_total: accounting.formatNumber((itemProductPack[i].price*itemProductPack[i].quantity*cat),0,".",","),
|
|
|
+ subtotal: accounting.formatNumber(itemProductPack[i].subtotal,2,".",","),
|
|
|
+ utilidad: "",
|
|
|
+ //create_date: moment(itemLine.create_date).format("YYYY-MM-DD"),
|
|
|
+ countPack: itemProductPack[i].quantity*cat,
|
|
|
+ product_main_id: itemProductPack[i].parent_product_id[0],
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // Generar Objeto Principal
|
|
|
+ rankingItem=rankingItem.concat(rankingCab);
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ self.content = rankingItem;
|
|
|
+ self.loadTable(rankingItem);
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ factSearch: function(){
|
|
|
+ var self = this;
|
|
|
+ var product = this.$el.find('#product').val().split('-');
|
|
|
+ var content = self.content;
|
|
|
+
|
|
|
+ if (product != ""){
|
|
|
+ content = _.filter(content, function(inv){
|
|
|
+ return inv.product_main_id == product[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ self.loadTable(content)
|
|
|
+ },
|
|
|
+
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable('load',rowsTable);
|
|
|
+ },
|
|
|
+
|
|
|
+ getObjetPdf: function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ var rows=self.rowsData;
|
|
|
+
|
|
|
+ return rows;
|
|
|
+ },
|
|
|
+
|
|
|
+ clickOnAction: function (e) {
|
|
|
+ var self = this;
|
|
|
+ var rowsNew;
|
|
|
+ var action = self.$el.find(e.target).val();
|
|
|
+ var table = self.$el.find("#table");
|
|
|
+ var data2 = table.bootstrapTable('getVisibleColumns');
|
|
|
+ var getColumns=[];
|
|
|
+ var rows=[];
|
|
|
+ rowsNew = self.getObjetPdf();
|
|
|
+ if (action === 'pdf') {
|
|
|
+ var dataNEW = _.map(data2, function (val){
|
|
|
+ return val.field;
|
|
|
+ });
|
|
|
+ _.each(rowsNew,function (item){
|
|
|
+ rows.push(_.pick(item, dataNEW));
|
|
|
+ });
|
|
|
+ // Obtener los nombre de la Cabezera
|
|
|
+ _.each(_.map(data2,function(val){
|
|
|
+ return val;
|
|
|
+ }), function(item){
|
|
|
+ getColumns.push([{
|
|
|
+ title: item.title,
|
|
|
+ dataKey: item.field
|
|
|
+ }]);
|
|
|
+ });
|
|
|
+ this.drawPDF(_.flatten(getColumns),rows);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ drawPDF: function (getColumns,rows) {
|
|
|
+ var self = this;
|
|
|
+ var fechaActu= new Date();
|
|
|
+ var totalPagesExp = "{total_pages_count_string}";
|
|
|
+ var pdfDoc = new window.jsPDF();
|
|
|
+
|
|
|
+ pdfDoc.autoTable(getColumns, rows, {
|
|
|
+ styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
|
|
|
+ columnStyles: {
|
|
|
+ product_main : {columnWidth: '6px'},
|
|
|
+ product : {columnWidth: '8px'},
|
|
|
+ price_venta: {halign:'right',columnWidth: '6px'},
|
|
|
+ price_costo: {halign:'right',columnWidth: '6px'},
|
|
|
+ price_insumo : {halign:'right',columnWidth: '6px'},
|
|
|
+ qty_pos : {halign:'right',columnWidth: '5px'},
|
|
|
+ qty : {halign:'right',columnWidth: '5px'},
|
|
|
+ subtotal_total_venta : {halign:'right',columnWidth: '6px'},
|
|
|
+ subtotal_total : {halign:'right',columnWidth: '6px'},
|
|
|
+ utilidad : {halign:'right',columnWidth: '6px'},
|
|
|
+ },
|
|
|
+ margin: { top: 16, horizontal: 7},
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Análisis de Utilidad de Pack de Producto ', data.settings.margin.left, 10);
|
|
|
+ // 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('Análisis de Utilidad de Pack de Producto.pdf')
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|