|
@@ -0,0 +1,733 @@
|
|
|
+function report_ventas_pos_orders(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportVentasPosOrdersWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportVentasPosOrders',
|
|
|
+ rowsData :[],
|
|
|
+ PosOrderLine: [],
|
|
|
+ content:[],
|
|
|
+
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #X' : 'fectSearch',
|
|
|
+ 'click #A' : 'fectSearch',
|
|
|
+ 'click #B' : 'fectSearch',
|
|
|
+ 'click #C' : 'fectSearch',
|
|
|
+ 'click #D' : 'fectSearch',
|
|
|
+ 'click #Z' : 'fectSearch',
|
|
|
+ 'change #from' : 'fectSearch',
|
|
|
+ 'change #to': 'fectSearch',
|
|
|
+ 'change #current-category' : 'fectSearch',
|
|
|
+ 'change #current-floor': 'fectSearch',
|
|
|
+ 'change #current-table': 'fectSearch',
|
|
|
+ 'change #current-store': 'fectSearch',
|
|
|
+ 'click-row.bs.table #table' : 'clickAnalysisDetail',
|
|
|
+ },
|
|
|
+
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function () {
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowData});
|
|
|
+ this.fecthFecha();
|
|
|
+ this.submitForm();
|
|
|
+ },
|
|
|
+
|
|
|
+ clickAnalysisDetail: function(e, row, $element, field){
|
|
|
+ if (field == 'order_name'){
|
|
|
+ this.do_action({
|
|
|
+ name : "Pedido",
|
|
|
+ type : 'ir.actions.act_window',
|
|
|
+ res_model : "pos.order",
|
|
|
+ views : [[false,'form']],
|
|
|
+ target : 'new',
|
|
|
+ domain : [['id','=', row.order_id]],
|
|
|
+ context : {},
|
|
|
+ flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id : row.order_id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (field == 'product_name'){
|
|
|
+ this.do_action({
|
|
|
+ name : "Productos",
|
|
|
+ type : 'ir.actions.act_window',
|
|
|
+ res_model : "product.product",
|
|
|
+ views : [[false,'form']],
|
|
|
+ target : 'new',
|
|
|
+ domain : [['id','=', row.product_id]],
|
|
|
+ context : {},
|
|
|
+ flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id : row.product_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;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor ="";
|
|
|
+ if (dato){
|
|
|
+ valor=dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ // Consultar
|
|
|
+ submitForm: function () {
|
|
|
+ var self = this;
|
|
|
+ this.fetchPosOrder().then(function(PosOrder) {
|
|
|
+ self.PosOrder = PosOrder;
|
|
|
+ return PosOrder;
|
|
|
+ }).then(function (PosOrder) {
|
|
|
+ return self.fetchPosOrderLine(PosOrder);
|
|
|
+ }).then(function (PosOrderLine) {
|
|
|
+ self.PosOrderLine = PosOrderLine;
|
|
|
+ return self.fetchProductProduct(PosOrderLine);
|
|
|
+ }).then(function (ProductProduct) {
|
|
|
+ self.ProductProduct = ProductProduct;
|
|
|
+ return self.fecthSalesOrder();
|
|
|
+ }).then(function (SalesOrder) {
|
|
|
+ self.SalesOrder = SalesOrder;
|
|
|
+ return self.fecthSalesOrderLine(SalesOrder);
|
|
|
+ }).then(function (SalesOrderLine) {
|
|
|
+ self.SalesOrderLine = SalesOrderLine;
|
|
|
+ return self.fetchResPartner();
|
|
|
+ }).then(function (ResPartner){
|
|
|
+ self.ResPartner = ResPartner;
|
|
|
+ self.searchProduct();
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // fecthResStore: function(){
|
|
|
+ // var self = this;
|
|
|
+ // var defer = $.Deferred();
|
|
|
+ // var field=['id', 'name'];
|
|
|
+ // var ResStore = new model.web.Model('res.store');
|
|
|
+ // ResStore.query(field).all().then(function(results){
|
|
|
+ // defer.resolve(results);
|
|
|
+ // });
|
|
|
+ // return defer;
|
|
|
+ // },
|
|
|
+
|
|
|
+ // fecthAccountJournal: function(){
|
|
|
+ // var self = this;
|
|
|
+ // var defer = $.Deferred();
|
|
|
+ // var field = ['id', 'name','store_ids'];
|
|
|
+ // var domain = [['active','=',true],['type','in',['sale','purchase']]];
|
|
|
+ // var AccountJournal = new model.web.Model('account.journal');
|
|
|
+ // AccountJournal.query(field).filter(domain).all().then(function(results){
|
|
|
+ // defer.resolve(results);
|
|
|
+ // });
|
|
|
+ // return defer;
|
|
|
+ // },
|
|
|
+
|
|
|
+ // Ventas (Point Of Sale)
|
|
|
+ fetchPosOrder: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name','date_order','lines','table_id','sale_journal'];
|
|
|
+ var domain = [['state', 'not in', ['draft','cancel']]];
|
|
|
+ var PosOrder = new model.web.Model('pos.order');
|
|
|
+ PosOrder.query(fields).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ // Lineas de venta (Point Of Sale)
|
|
|
+ fetchPosOrderLine: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var ids = _.flatten(_.map(self.PosOrder, function (item) {
|
|
|
+ return item.lines;
|
|
|
+ }));
|
|
|
+ var fields = ['id', 'name', 'order_id', 'product_id', 'qty', 'price_unit', 'price_subtotal_incl']
|
|
|
+ var domain = [['order_id', 'in', ids]];
|
|
|
+ var PosOrderLine = new model.web.Model('pos.order.line');
|
|
|
+ PosOrderLine.query().filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results)
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ // clientes
|
|
|
+ fetchResPartner: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name','ruc'];
|
|
|
+ var domain = [['active', '=', true],['customer', '=', true]];
|
|
|
+ var ResPartner = new model.web.Model('res.partner');
|
|
|
+ ResPartner.query(fields).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ // Productos
|
|
|
+ fetchProductProduct: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var porduct_ids = _.flatten(_.map(self.PosOrderLine, function (item) {
|
|
|
+ return item.product_id[0];
|
|
|
+ }));
|
|
|
+ var fields = ['id','name', 'default_code', 'name_template','ean13','lst_price','pos_categ_id', 'standard_price','type','attribute_str'];
|
|
|
+ var domain = [['id', 'in', porduct_ids]];
|
|
|
+ var ProductProduct = new model.web.Model('product.product');
|
|
|
+ ProductProduct.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ // fecthPosCategory: function(){
|
|
|
+ // var self = this;
|
|
|
+ // var defer = $.Deferred();
|
|
|
+ // var fields = ['id','name'];
|
|
|
+ // var PosCategory = new model.web.Model('pos.category');
|
|
|
+ // PosCategory.query(fields).filter().all().then(function (results) {
|
|
|
+ // defer.resolve(results)
|
|
|
+ // });
|
|
|
+ // return defer;
|
|
|
+ // },
|
|
|
+
|
|
|
+ // Mesa o delivery
|
|
|
+ // fetchPosTable: function(){
|
|
|
+ // var self = this;
|
|
|
+ // var defer = $.Deferred();
|
|
|
+ // var fields = ['id','name', 'floor_id'];
|
|
|
+ // var ProductProduct = new model.web.Model('pos.table');
|
|
|
+ // ProductProduct.query(fields).filter().all().then(function (results) {
|
|
|
+ // defer.resolve(results);
|
|
|
+ // });
|
|
|
+ // return defer;
|
|
|
+ // },
|
|
|
+
|
|
|
+ // Salon o Delivery
|
|
|
+ // fetchPosFloor: function(){
|
|
|
+ // var self = this;
|
|
|
+ // var defer = $.Deferred();
|
|
|
+ // var fields = ['id','name', 'table_ids'];
|
|
|
+ // var ProductProduct = new model.web.Model('pos.floor');
|
|
|
+ // ProductProduct.query(fields).filter().all().then(function (results) {
|
|
|
+ // defer.resolve(results);
|
|
|
+ // });
|
|
|
+ // return defer;
|
|
|
+ // },
|
|
|
+
|
|
|
+ getPosOrder: function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.PosOrder,function (item) {
|
|
|
+ return item.id == id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getSaleOrder: function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.SaleOrder,function (item) {
|
|
|
+ return item.id == id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // getPosTable: function(id){
|
|
|
+ // var self = this;
|
|
|
+ // return _.filter(self.PosTable,function (item) {
|
|
|
+ // return item.id == id;
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+
|
|
|
+ // Obtener las lineas de las Facturas
|
|
|
+ getProductProduct: function(id){
|
|
|
+ var self = this;
|
|
|
+ //return _.find(self.ProductProduct, function(item){
|
|
|
+ // return item.id == id;
|
|
|
+ //});
|
|
|
+ return _.filter(self.ProductProduct, function(item){
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // getPosCategory: function(id){
|
|
|
+ // var self = this;
|
|
|
+ // return _.filter(self.PosCategory, function(item){
|
|
|
+ // return item.id == id;
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+
|
|
|
+ // getAccountJournal: function (id) {
|
|
|
+ // var self = this;
|
|
|
+ // return _.filter(self.AccountJournal,function (item) {
|
|
|
+ // return item.id === id;
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+
|
|
|
+ // Obtener Pedido
|
|
|
+ fecthSalesOrder: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var modules = self.checkModel('sale');
|
|
|
+
|
|
|
+ if (modules.length <= 0){
|
|
|
+ self.showMensaje('sale');
|
|
|
+ return defer;
|
|
|
+ }
|
|
|
+
|
|
|
+ var fields = ['id', 'order_line', 'date_order'];
|
|
|
+ // var domain = [['date_order', '>=', desde], ['date_order', '<', hasta], ['state', 'in', ['paid','done','invoiced']]];
|
|
|
+ var domain = [ ['state', 'in', ['done', 'progress']]];
|
|
|
+ var SalesOrder = new instance.web.Model('sale.order');
|
|
|
+ SalesOrder.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Obtener linea de la factura
|
|
|
+ fecthSalesOrderLine: function(SalesOrder) {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var order_line = _.flatten(_.map(SalesOrder, function (item) {
|
|
|
+ return item.order_line;
|
|
|
+ }));
|
|
|
+ var fields = ['id', 'product_id', 'create_date', 'product_uom_qty', 'price_unit'];
|
|
|
+ var domain = [['id','in', order_line]];
|
|
|
+ var SalesOrderLine = new instance.web.Model('sale.order.line');
|
|
|
+ SalesOrderLine.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ BuildTable: function(){
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ var order;
|
|
|
+ var sale;
|
|
|
+ var itemsale;
|
|
|
+ var producto = [];
|
|
|
+ var saleproducto = [];
|
|
|
+ var category;
|
|
|
+ var item;
|
|
|
+ var category_name;
|
|
|
+ var category_id;
|
|
|
+ var store;
|
|
|
+
|
|
|
+ for (var i = 0; i < this.PosOrderLine.length; i++) {
|
|
|
+ item = this.PosOrderLine[i];
|
|
|
+ producto = self.getProductProduct(item.product_id[0]);
|
|
|
+ order = self.getPosOrder(item.order_id[0]).shift();
|
|
|
+ if(producto.length > 0){
|
|
|
+ data.push({
|
|
|
+ id : item.id,
|
|
|
+ order_id : item.order_id[0],
|
|
|
+ order_name : item.order_id[1],
|
|
|
+ date : order.date_order,
|
|
|
+ date_order : moment(order.date_order).format("DD/MM/YYYY"),
|
|
|
+ product_id : item.product_id[0],
|
|
|
+ product_name : item.product_id[1],
|
|
|
+ qty : accounting.formatNumber(item.qty,0,".",","),
|
|
|
+ price_unit : accounting.formatNumber(item.price_unit,0,".",","),
|
|
|
+ standard_price : accounting.formatNumber((producto[0].standard_price),0, ".", ","),
|
|
|
+ price_tot : accounting.formatNumber((item.qty * item.price_unit),0, ".", ","),
|
|
|
+ standar_tot : accounting.formatNumber((item.qty * producto[0].standard_price),0, ".", ","),
|
|
|
+ utility : accounting.formatNumber(((item.qty * item.price_unit) - (item.qty * producto[0].standard_price)),0, ".", ","),
|
|
|
+ qty_total : item.qty,
|
|
|
+ price_tot_tot : ((item.qty * item.price_unit)),
|
|
|
+ standar_tot_tot : ((item.qty * producto[0].standard_price)),
|
|
|
+ utility_tot : (((item.qty * item.price_unit) - (item.qty * producto[0].standard_price))),
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // for (var k = 0; k < this.SaleOrderLine.length; k++) {
|
|
|
+ // itemsale = this.SaleOrderLine[k];
|
|
|
+ // console.log(itemsale);
|
|
|
+ // saleproducto = self.getProductProduct(itemsale.product_id[0]);
|
|
|
+ // sale = self.getSaleOrder(itemsale.order_id[0]).shift();
|
|
|
+ // store = self.getAccountJournal(order.sale_journal[0]);
|
|
|
+ // category = self.getPosCategory(item.product_id[0]);
|
|
|
+ // if(category.length > 0){
|
|
|
+ // category_name = category[0].name;
|
|
|
+ // category_id = category[0].id;
|
|
|
+ // }else {
|
|
|
+ // category_name = '';
|
|
|
+ // category_id = '';
|
|
|
+ // }
|
|
|
+ // var place_id;
|
|
|
+ // var place_name;
|
|
|
+ // var floor;
|
|
|
+ // if(order.table_id){
|
|
|
+ // floor = self.getPosTable(order.table_id[0]).shift();
|
|
|
+ // floor = floor.floor_id[0];
|
|
|
+ // place_id = order.table_id[0];
|
|
|
+ // place_name = order.table_id[1];
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if(saleproducto.length > 0){
|
|
|
+ // data.push({
|
|
|
+ // id : itemsale.id,
|
|
|
+ // order_id : itemsale.order_id[0],
|
|
|
+ // order_name : itemsale.order_id[1],
|
|
|
+ // date : sale.create_date,
|
|
|
+ // date_order : moment(sale.create_date).format("DD/MM/YYYY"),
|
|
|
+ // product_id : itemsale.product_id[0],
|
|
|
+ // product_name : itemsale.product_id[1],
|
|
|
+ // qty : accounting.formatNumber(itemsale.product_uom_qty,0,".",","),
|
|
|
+ // price_unit : accounting.formatNumber(itemsale.price_unit,0,".",","),
|
|
|
+ // standard_price : accounting.formatNumber((saleproducto[0].standard_price),0, ".", ","),
|
|
|
+ // price_tot : accounting.formatNumber((itemsale.product_uom_qty * itemsale.price_unit),0, ".", ","),
|
|
|
+ // standar_tot : accounting.formatNumber((itemsale.product_uom_qty * saleproducto[0].standard_price),0, ".", ","),
|
|
|
+ // utility : accounting.formatNumber(((itemsale.product_uom_qty * itemsale.price_unit) - (itemsale.product_uom_qty * saleproducto[0].standard_price)),0, ".", ","),
|
|
|
+ // qty_total : itemsale.product_uom_qty,
|
|
|
+ // price_tot_tot : ((itemsale.product_uom_qty * itemsale.price_unit)),
|
|
|
+ // standar_tot_tot : ((itemsale.product_uom_qty * saleproducto[0].standard_price)),
|
|
|
+ // utility_tot : (((itemsale.product_uom_qty * itemsale.price_unit) - (itemsale.product_uom_qty * saleproducto[0].standard_price))),
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ this.rowsData=data;
|
|
|
+ self.content=data;
|
|
|
+ this.loadTable(data)
|
|
|
+ },
|
|
|
+
|
|
|
+ fectSearch: function(){
|
|
|
+ var self = this;
|
|
|
+ var hoy = moment().format('YYYY-MM-DD');
|
|
|
+ var floor =this.$el.find('#current-floor').val();
|
|
|
+ var table =this.$el.find('#current-table').val();
|
|
|
+ var category = this.$el.find('#current-category').val();
|
|
|
+ var store =this.$el.find('#current-store').val();
|
|
|
+ var desde =this.$el.find('#from').val();
|
|
|
+ var hasta =this.$el.find('#to').val();
|
|
|
+ var product = this.$el.find('#product').val().split('-');
|
|
|
+ var content = self.content;
|
|
|
+
|
|
|
+ // Hoy
|
|
|
+ if ($('#A').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.date == hoy;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#B').is(":checked")){
|
|
|
+ var date = hoy.split('-');
|
|
|
+ var ayer = date[2] - 1;
|
|
|
+ date.splice(2,0);
|
|
|
+ date[2] = '0'+ayer;
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.date == date[0]+'-'+date[1]+'-'+date[2];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#C').is(":checked")){
|
|
|
+ var date = hoy.split('-');
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ var mes = inv.date.split('-');
|
|
|
+ return mes[0]+'-'+mes[1] == date[0]+'-'+date[1];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#D').is(":checked")){
|
|
|
+ var date = hoy.split('-');
|
|
|
+ var mes = date[1] - 1;
|
|
|
+ var year;
|
|
|
+ date.splice(1,0);
|
|
|
+ if(date[1] == 1){
|
|
|
+ date[1] = '12';
|
|
|
+ year = date[0] - 1;
|
|
|
+ date[0] = year;
|
|
|
+ }else{
|
|
|
+
|
|
|
+ if(date[1] < 10){
|
|
|
+ date[1] = '0'+mes;
|
|
|
+ }else{
|
|
|
+ date[1] = mes;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ var mes = inv.date.split('-');
|
|
|
+ return mes[0]+'-'+mes[1] == date[0]+'-'+date[1];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#Z').is(":checked")){
|
|
|
+ $('#datepicker').css('display','block');
|
|
|
+ if (desde.length > 0){
|
|
|
+ var date= desde.split('/');
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.date >= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (hasta.length > 0){
|
|
|
+ var date= hasta.split('/');
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.date <= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $('#datepicker').css('display','none');
|
|
|
+ }
|
|
|
+
|
|
|
+ // Filtrar por piso o delivery
|
|
|
+ // if (floor != 9999999){
|
|
|
+ // content=_.filter(content, function (inv){
|
|
|
+ // return inv.floor_id == floor;
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // Filtrar por mesa o delivery
|
|
|
+ // if (table != 9999999){
|
|
|
+ // content=_.filter(content, function (inv){
|
|
|
+ // return inv.table_id == table;
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // Buscar Producto
|
|
|
+ if (product != ""){
|
|
|
+ content = _.filter(content, function(inv){
|
|
|
+ return inv.product_id == product[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // if(category != 9999999){
|
|
|
+ // content = _.filter(content,function(inv){
|
|
|
+ // return inv.category_id == category;
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (store != 9999999){
|
|
|
+ // content=_.filter(content, function (inv){
|
|
|
+ // return inv.store_id == store;
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ var qty_total_total = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.qty_total);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+ var price_total_total = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.price_tot_tot);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+ var standar_total_total = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.standar_tot_tot);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+ var utilidad_total_total = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.utility_tot);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+ content.push({
|
|
|
+ order_name: "Total",
|
|
|
+ qty: accounting.formatNumber((qty_total_total),0,".",","),
|
|
|
+ price_tot: accounting.formatNumber((price_total_total),0,".",","),
|
|
|
+ standar_tot: accounting.formatNumber((standar_total_total),0,".",","),
|
|
|
+ utility: accounting.formatNumber((utilidad_total_total),0,".",","),
|
|
|
+ });
|
|
|
+
|
|
|
+ self.loadTable(content)
|
|
|
+ },
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ 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=[];
|
|
|
+ var rows = self.rowsData;
|
|
|
+
|
|
|
+ // var qty =_.reduce(_.map(rows,function(map){
|
|
|
+ // return(map.qty_total);
|
|
|
+ // }),function(memo, num){
|
|
|
+ // return memo + num;
|
|
|
+ // },0);
|
|
|
+ //
|
|
|
+ // var price_tot =_.reduce(_.map(rows,function(map){
|
|
|
+ // return(map.price_tot_tot);
|
|
|
+ // }),function(memo, num){
|
|
|
+ // return memo + num;
|
|
|
+ // },0);
|
|
|
+ //
|
|
|
+ // var standar_tot =_.reduce(_.map(rows,function(map){
|
|
|
+ // return(map.standar_tot_tot);
|
|
|
+ // }),function(memo, num){
|
|
|
+ // return memo + num;
|
|
|
+ // },0);
|
|
|
+ //
|
|
|
+ // var utility =_.reduce(_.map(rows,function(map){
|
|
|
+ // return(map.utility_tot);
|
|
|
+ // }),function(memo, num){
|
|
|
+ // return memo + num;
|
|
|
+ // },0);
|
|
|
+ //
|
|
|
+ // if (rows.length > 0){
|
|
|
+ // rows.push({
|
|
|
+ // order_name : "Totales ",
|
|
|
+ // qty : accounting.formatNumber(qty,0,".",","),
|
|
|
+ // price_tot : accounting.formatNumber(price_tot,0,".",","),
|
|
|
+ // standar_tot : accounting.formatNumber(standar_tot,0,".",","),
|
|
|
+ // utility : accounting.formatNumber(utility,0,".",","),
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ return rows;
|
|
|
+ },
|
|
|
+
|
|
|
+ clickOnAction: function (e) {
|
|
|
+ var self = this;
|
|
|
+ var rowsNew;
|
|
|
+ var action = this.$el.find(e.target).val();
|
|
|
+ var table = this.$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
|
|
|
+ }]);
|
|
|
+ });
|
|
|
+ // Llamar al pdf
|
|
|
+ this.drawPDF(_.flatten(getColumns),rows)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ drawPDF: function (getColumns,rows) {
|
|
|
+ var self = this;
|
|
|
+ var desde =(this.$el.find('#from').val());
|
|
|
+ var hasta =(this.$el.find('#to').val());
|
|
|
+ var totalPagesExp = "{total_pages_count_string}";
|
|
|
+ var pdfDoc = new jsPDF('l');
|
|
|
+
|
|
|
+ pdfDoc.autoTable(getColumns, rows, {
|
|
|
+ styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
|
|
|
+ columnStyles: {
|
|
|
+ order_name: {halign:'left', fontStyle: 'bold'},
|
|
|
+ date_order :{halign:'left'},
|
|
|
+ product_name :{halign:'left' },
|
|
|
+ qty :{halign:'right' },
|
|
|
+ price_unit : {halign:'right' },
|
|
|
+ standard_price : {halign:'right' },
|
|
|
+ price_tot : {halign:'right' },
|
|
|
+ standar_tot : {halign:'right' },
|
|
|
+ utility : {halign:'right'}
|
|
|
+ },
|
|
|
+ margin: { top: 16, horizontal: 7},
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Análisis de Ventas generales', data.settings.margin.left, 10);
|
|
|
+
|
|
|
+ if(desde.length > 0 || hasta.length > 0){
|
|
|
+ var fecha='';
|
|
|
+ if(desde){
|
|
|
+ fecha=fecha.concat(' Desde '+desde);
|
|
|
+ }
|
|
|
+ if (hasta){
|
|
|
+ fecha=fecha.concat(' Hasta '+hasta);
|
|
|
+ }
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40)
|
|
|
+ pdfDoc.text(fecha, data.settings.margin.left,14);
|
|
|
+ }
|
|
|
+ // FOOTER
|
|
|
+ var str = "Pagina " + data.pageCount;
|
|
|
+ // Total page number plugin only available in jspdf v1.0+
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
+ str = str + " de " + totalPagesExp;
|
|
|
+ }
|
|
|
+ pdfDoc.setFontSize(9);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(str, data.settings.margin.left, pdfDoc.internal.pageSize.height - 5);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
+ pdfDoc.putTotalPages(totalPagesExp);
|
|
|
+ }
|
|
|
+ pdfDoc.save('Análisis de ventas generales.pdf')
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|