Quellcode durchsuchen

Agregar datos de clientes al historico de ventas

SEBAS vor 1 Woche
Ursprung
Commit
52f19971aa

+ 28 - 4
controller/helpers/account_invoice.py

@@ -109,7 +109,11 @@ def get_account_invoice_sale_type(): #historico de venta
             invoice.state,
             invoice.company_id,
             customer.ruc,
-            invoice.supplier_invoice_number
+            invoice.supplier_invoice_number,
+            customer.phone,
+            customer.mobile,
+            customer.city,
+            customer.email
         FROM account_invoice AS invoice
         LEFT JOIN res_store_journal_rel AS journal
         ON journal.journal_id = invoice.journal_id
@@ -144,7 +148,11 @@ def get_account_invoice_sale_type(): #historico de venta
             invoice.state,
             invoice.company_id,
             customer.ruc,
-            invoice.supplier_invoice_number
+            invoice.supplier_invoice_number,
+            customer.phone,
+            customer.mobile,
+            customer.city,
+            customer.email
     '''
 
     query2 = '''
@@ -169,7 +177,11 @@ def get_account_invoice_sale_type(): #historico de venta
             customer.ruc,
             invoice.supplier_invoice_number,
             invoice.contado,
-            invoice.credito
+            invoice.credito,
+            customer.phone,
+            customer.mobile,
+            customer.city,
+            customer.email
         FROM account_invoice AS invoice
         LEFT JOIN res_store_journal_rel AS journal
         ON journal.journal_id = invoice.journal_id
@@ -204,7 +216,11 @@ def get_account_invoice_sale_type(): #historico de venta
             invoice.state,
             invoice.company_id,
             customer.ruc,
-            invoice.supplier_invoice_number
+            invoice.supplier_invoice_number,
+            customer.phone,
+            customer.mobile,
+            customer.city,
+            customer.email
     '''
 
     r.cr.execute(validate_columns)
@@ -236,6 +252,10 @@ def get_account_invoice_sale_type(): #historico de venta
             'supplier_invoice_number':j[18],
             'contado':j[19],
             'credito':j[20],
+            'customer_phone':j[21],
+            'customer_mobile':j[22],
+            'customer_city':j[23],
+            'customer_email':j[24],
         } for j in r.cr.fetchall()]
     else:
         r.cr.execute(query1,(tuple([company_currency_rate,company_currency_rate])))
@@ -259,6 +279,10 @@ def get_account_invoice_sale_type(): #historico de venta
             'company_id':j[16],
             'customer_ruc':j[17],
             'supplier_invoice_number':j[18],
+            'customer_phone':j[19],
+            'customer_mobile':j[20],
+            'customer_city':j[21],
+            'customer_email':j[22],             
         } for j in r.cr.fetchall()]
 
 def get_account_invoice_sale_and_refund_type():

+ 14 - 4
controller/helpers/account_invoice_line.py

@@ -112,7 +112,8 @@ def get_account_invoice_line_out_invoice(): #analisis de venta
             template.product_brand_id,
             brand.name,
             line.discount,
-            line.name
+            line.name,
+            sales_partner.name
             FROM account_invoice AS invoice
             LEFT JOIN account_invoice_line AS line
             ON line.invoice_id = invoice.id
@@ -137,6 +138,10 @@ def get_account_invoice_line_out_invoice(): #analisis de venta
             ON partner.id = invoice.partner_id
             LEFT JOIN product_brand AS brand
             ON brand.id = template.product_brand_id
+            LEFT JOIN res_users AS sales_user
+                ON sales_user.id = invoice.user_id
+            LEFT JOIN res_partner AS sales_partner
+                ON sales_partner.id = sales_user.partner_id
             WHERE invoice.state NOT IN ('draft', 'cancel')
             AND invoice.type = 'out_invoice'
         GROUP BY
@@ -159,7 +164,8 @@ def get_account_invoice_line_out_invoice(): #analisis de venta
             invoice.journal_id,
             template.product_brand_id,
             brand.name,
-            line.name
+            line.name,
+            sales_partner.name
     '''
 
     query_without_brand = '''
@@ -191,7 +197,8 @@ def get_account_invoice_line_out_invoice(): #analisis de venta
             (array_agg(attr_value.name)) AS attr_value,
             (array_agg(attr.id)) AS attr,
             line.discount,
-            line.name
+            line.name,
+            sales_partner.name
             FROM account_invoice AS invoice
             LEFT JOIN account_invoice_line AS line
             ON line.invoice_id = invoice.id
@@ -234,7 +241,8 @@ def get_account_invoice_line_out_invoice(): #analisis de venta
             product.id,
             invoice.company_id,
             invoice.journal_id,
-            line.name
+            line.name,
+            sales_partner.name
     '''
 
     r.cr.execute(validate_brand)
@@ -271,6 +279,7 @@ def get_account_invoice_line_out_invoice(): #analisis de venta
                 'brand_name': j[23],
                 'discount': j[24],
                 'name': j[25],
+                'vendor_name': j[26],
             } for j in r.cr.fetchall()
         ]
     else:
@@ -301,6 +310,7 @@ def get_account_invoice_line_out_invoice(): #analisis de venta
                 'attribute_ids': j[21],
                 'discount': j[22],
                 'name': j[23],
+                'vendor_name': j[24],
             } for j in r.cr.fetchall()
         ]
 

+ 14 - 4
controller/helpers/pos_order_line.py

@@ -51,7 +51,8 @@ def get_pos_order_line():
             customer.ruc,
             customer.name,
             customer.id,
-            line.discount
+            line.discount,
+            sales_partner.name 
         FROM pos_order AS pos
         LEFT JOIN pos_order_line AS line
         ON pos.id = line.order_id
@@ -73,6 +74,10 @@ def get_pos_order_line():
         ON brand.id = template.product_brand_id
         LEFT JOIN res_partner AS customer
         ON customer.id = pos.partner_id
+        LEFT JOIN res_users AS sales_user
+            ON sales_user.id = pos.user_id
+        LEFT JOIN res_partner AS sales_partner
+            ON sales_partner.id = sales_user.partner_id
         WHERE pos.state NOT IN ('draft')
         GROUP BY
         	pos.id,
@@ -94,7 +99,8 @@ def get_pos_order_line():
             product.id,
             customer.ruc,
             customer.name,
-            customer.id
+            customer.id,
+            sales_partner.name
     '''
 
     query_without_brand = '''
@@ -125,7 +131,8 @@ def get_pos_order_line():
             customer.ruc,
             customer.name,
             customer.id,
-            line.discount
+            line.discount,
+            sales_partner.name
         FROM pos_order AS pos
         LEFT JOIN pos_order_line AS line
         ON pos.id = line.order_id
@@ -164,7 +171,8 @@ def get_pos_order_line():
             product.id,
             customer.ruc,
             customer.name,
-            customer.id
+            customer.id,
+            sales_partner.name
     '''
 
     r.cr.execute(validate)
@@ -207,6 +215,7 @@ def get_pos_order_line():
                     'customer_name': j[22],
                     'customer_id': j[23],
                     'discount': j[24],
+                    'vendor_name': j[25],
                 } for j in r.cr.fetchall()
             ]
         else:
@@ -236,6 +245,7 @@ def get_pos_order_line():
                     'customer_name': j[20],
                     'customer_id': j[21],
                     'discount': j[22],
+                    'vendor_name': j[23],
                 } for j in r.cr.fetchall()
             ]
     else:

+ 1 - 0
models.py

@@ -58,6 +58,7 @@ class AccountInvoice(models.Model):
                 'amount_untaxed': invoice.amount_untaxed,
                 'origin': invoice.origin,
 				'comment': invoice.comment,
+				'timbrado_name': invoice.timbrado_name,				
                 'residual': invoice.residual,
                 'amount_tax': invoice.amount_tax,
 				'amount_total': invoice.amount_total,

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

@@ -31,6 +31,7 @@ openerp.eiru_reports = function (instance) {
         */
         report_sale(reporting);
         report_sale_analytic(reporting);
+        report_sale_baco_analytic(reporting);
         report_customer(reporting);
         report_customer_ranking(reporting);
         report_sale_ranking_product(reporting);
@@ -136,6 +137,13 @@ openerp.eiru_reports = function (instance) {
      */
     instance.web.client_actions.add('eiru_reports.sale_analytic_action', 'instance.eiru_reports.ReportSaleAnalyticWidget');
 
+    /*
+    ================================================================================
+        ANALISIS DE VENTAS
+    ================================================================================
+     */
+    instance.web.client_actions.add('eiru_reports.sale_baco_analytic_action', 'instance.eiru_reports.ReportSaleBacoAnalyticWidget');
+
     /*
     ================================================================================
         CLIENTES

+ 2 - 2
static/src/js/reports/report_daily_sale.js

@@ -331,7 +331,7 @@ function report_daily_sale(reporting){
               }
             }
 
-            var PosOrder = new model.web.Model('account.invoice');
+            var PosOrder = new model.web.Model('pos.order');
             return PosOrder.call('getPosOrder',[domain], {
               context: new model.web.CompoundContext()
             });
@@ -354,7 +354,7 @@ function report_daily_sale(reporting){
 
         var modules = self.checkModel('point_of_sale');
         if (modules.length > 0){
-          var PosOrderLine = new model.web.Model('account.invoice.line');
+          var PosOrderLine = new model.web.Model('pos.order.line');
           return PosOrderLine.call('getPosOrderLine',[domain], {
               context: new model.web.CompoundContext()
           });

+ 8 - 0
static/src/js/reports/report_sale.js

@@ -524,6 +524,10 @@ function report_sale(reporting){
                     untaxed:accounting.formatMoney(item.amount_untaxed,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
                     tax:accounting.formatMoney(item.amount - item.amount_untaxed,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
                     total:accounting.formatMoney(item.amount,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
+                    customer_phone:self.valorNull(item.customer_phone),
+                    customer_mobile:self.valorNull(item.customer_mobile),
+                    customer_city:self.valorNull(item.customer_city),
+                    customer_email:self.valorNull(item.customer_email),
                     /*
                     ===========================
                         NO FORMAT
@@ -603,6 +607,10 @@ function report_sale(reporting){
                     untaxed:accounting.formatMoney(item.amount - item.amount_tax,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
                     tax:accounting.formatMoney(item.amount_tax,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
                     total:accounting.formatMoney(totalamount,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
+                    customer_phone:self.valorNull(item.customer_phone),
+                    customer_mobile:self.valorNull(item.customer_mobile),
+                    customer_city:self.valorNull(item.customer_city),
+                    customer_email:self.valorNull(item.customer_email),
                     /*
                     =======================
                         NO FORMAT

+ 3 - 0
static/src/js/reports/report_sale_analytic.js

@@ -611,6 +611,7 @@ function report_sale_analytic(reporting){
                     untaxed:accounting.formatMoney(item.subtotal, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
                     tax:accounting.formatMoney(item.tax, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
                     total:accounting.formatMoney(item.subtotal + item.tax, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    vendor_name:self.valorNull(item.vendor_name),
                     /*
                     =============================
                         NO FORMAT
@@ -666,6 +667,7 @@ function report_sale_analytic(reporting){
                     untaxed:accounting.formatMoney(item.subtotal, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
                     tax:accounting.formatMoney(item.tax, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
                     total:accounting.formatMoney(item.subtotal + item.tax, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    vendor_name:self.valorNull(item.vendor_name),
                     /*
                     =============================
                         NO FORMAT
@@ -784,6 +786,7 @@ function report_sale_analytic(reporting){
                     untaxed:{columnWidth: 20, halign:'right'},
                     tax:{columnWidth: 20, halign:'right'},
                     total:{columnWidth: 20, halign:'right'},
+                    vendor_name:{columnWidth: 20, halign:'right'},
                 };
                 /*
                 ============================================================

+ 955 - 0
static/src/js/reports/report_sale_baco_analytic.js

@@ -0,0 +1,955 @@
+function report_sale_baco_analytic(reporting){
+    "use strict";
+
+    var model = openerp;
+
+    reporting.ReportSaleBacoAnalyticWidget = reporting.Base.extend({
+        template: 'ReportSaleBacoAnalytic',
+        rowsData :[],
+        content :[],
+        modules: ['product_brand','point_of_sale'],
+
+        events:{
+            'click .print-report' : 'clickOnAction',
+            'click #generate' : 'fetchGenerate',
+            'change #current-company' : 'updateSelections',
+            'change #current-attribute' : 'updateAttributeSelections',
+            'change #current-store' : 'updateJournalSelections',
+            'change #current-date' : 'ShowDateRange',
+        },
+
+        init : function(parent){
+            this._super(parent);
+        },
+
+        start: function () {
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowsData});
+            var date = new reporting.ReportDatePickerWidget(self);
+            date.fecthFecha();
+            this.fetchInitial();
+        },
+
+        checkModule : function(model){
+            var self = this;
+            return _.filter(self.IrModuleModule,function(item){
+                return item.name === model;
+            });
+        },
+
+        valorNull:function(dato){
+            var valor = "";
+            if (dato){
+                valor = dato;
+            }
+            return valor;
+        },
+
+        ShowDateRange : function(){
+            var self = this;
+            var date = self.$el.find('#current-date').val();
+            if(date == 'range'){
+                self.$el.find('.datepicker').css('display','block');
+            }
+            if(date != 'range'){
+                self.$el.find('.datepicker').css('display','none');
+            }
+        },
+
+        fetchInitial: function () {
+            var self = this;
+            self.fetchIntialSQL().then(function (IntialSQL) {
+                return IntialSQL;
+            }).then(function(IntialSQL) {
+                /*
+                =================================
+                    RES COMPANY
+                =================================
+                */
+                self.ResCompany = IntialSQL.companies;
+                self.CompanyLogo = IntialSQL.logo;
+                if(self.ResCompany.length > 1){
+                    self.$el.find('#current-company').append('<option value="9999999">Todas las empresas</option>');
+                    _.each(self.ResCompany,function(item){
+                        self.$el.find('#current-company').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.company').css('display','none');
+                }
+                /*
+                =================================
+                    RES STORE
+                =================================
+                */
+                self.ResStore = IntialSQL.stores;
+                if(self.ResStore.length > 1){
+                    self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
+                    _.each(self.ResStore,function(item){
+                        self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.store').css('display','none');
+                }
+                /*
+                =================================
+                    ACCOUNT JOURNAL
+                =================================
+                */
+                self.AccountJournal = IntialSQL.journals;
+                var journal = _.flatten(_.filter(self.AccountJournal,function (item) {
+                    return item.type == 'sale';
+                }));
+                if(journal.length > 1){
+                    self.$el.find('#current-journal').append('<option value="9999999">Todas las facturas</option>');
+                    _.each(self.AccountJournal,function(item){
+                        if(item.type == 'sale'){
+                            self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                        }
+                    });
+                }else{
+                    self.$el.find('.journal').css('display','none');
+                }
+                /*
+                =================================
+                    PRODUCT CATEGORY
+                =================================
+                */
+                self.ProductCategory = IntialSQL.categories;
+                if(self.ProductCategory.length > 1){
+                    self.$el.find('#current-category').append('<option value="9999999">Todas las Categorias</option>');
+                    _.each(self.ProductCategory,function(item){
+                        self.$el.find('#current-category').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }
+                /*
+                =================================
+                    PRODUCT BRAND
+                =================================
+                */
+                self.ProductBrand = IntialSQL.brands;
+                if(self.ProductBrand.length > 1){
+                    self.$el.find('#current-brand').append('<option value="9999999">Todas las Marcas</option>');
+                    _.each(self.ProductBrand,function(item){
+                        self.$el.find('#current-brand').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.brand').css('display','none');
+                }
+                self.ProductAttribute = IntialSQL.attributes;
+                if(self.ProductAttribute.length > 1){
+                    self.$el.find('#current-attribute').append('<option value="9999999">Todos los atributos</option>');
+                    _.each(self.ProductAttribute,function(item){
+                        self.$el.find('#current-attribute').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.attribute').css('display','none');
+                }
+                self.ProductAttributeValue = IntialSQL.attribute_values;
+                if(self.ProductAttributeValue.length > 1){
+                    self.$el.find('#current-attribute-value').append('<option value="9999999">Todos los valores de atributos</option>');
+                    _.each(self.ProductAttributeValue,function(item){
+                        self.$el.find('#current-attribute-value').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.attribute-value').css('display','none');
+                }
+                return self.fetchIrModuleModule();
+            }).then(function(IrModuleModule) {
+                self.IrModuleModule = IrModuleModule;
+                return self.fetchCheckType();
+            });
+            self.$el.find('#generate').css('display','inline');
+            return;
+        },
+
+        fetchGenerate: function () {
+            var self = this;
+            self.$el.find('.search-form').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+            self.$el.find('.report-form').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+            this.fetchDataSQL().then(function(DataSQL) {
+                return DataSQL;
+            }).then(function (DataSQL) {
+                self.AccountInvoiceLine = DataSQL.invoice_lines;
+                self.PosOrderLine = DataSQL.order_lines;
+                return self.BuildTable();
+            });
+        },
+
+        fetchIntialSQL: function() {
+            var self = this;
+            var data = $.get('/report-filter-data');
+            return data;
+        },
+
+        fetchDataSQL: function() {
+            var self = this;
+            var data = $.get('/report-sale-analytic');
+            return data;
+        },
+
+        fetchIrModuleModule: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['name','id'];
+            var domain=[['state','=','installed'],['name','in',self.modules]];
+            var IrModuleModule = new model.web.Model('ir.module.module');
+            IrModuleModule.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        fetchCheckType: function(){
+            var self = this;
+            var modules = self.checkModule('point_of_sale');
+            if(modules.length == 0){
+                self.$el.find('.type').css('display','none');
+            }
+        },
+
+        /*====================================================================
+            UPDATE SELECTIONS
+        ====================================================================*/
+        updateSelections: function () {
+            var self = this;
+            var store;
+            var company = self.$el.find('#current-company').val();
+            if(company != 9999999){
+                store = self.$el.find('#current-store').empty();
+                self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
+                _.each(self.ResStore,function(item){
+                    if(parseFloat(company) == item.company_id){
+                        self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    }
+                });
+            }else{
+                store = self.$el.find('#current-store').empty();
+                self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
+                _.each(self.ResStore,function(item){
+                    self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+            }
+        },
+
+        updateAttributeSelections: function () {
+            var self = this;
+            var attribute_value;
+            var attribute = self.$el.find('#current-attribute').val();
+            if(attribute != 9999999){
+                attribute_value = self.$el.find('#current-attribute-value').empty();
+                self.$el.find('#current-attribute-value').append('<option value="9999999">Todos los valores de atributos</option>');
+                _.each(self.ProductAttributeValue,function(item){
+                    if(parseFloat(attribute) == item.attribute_id){
+                        self.$el.find('#current-attribute-value').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    }
+                });
+            }else{
+                attribute_value = self.$el.find('#current-attribute-value').empty();
+                self.$el.find('#current-attribute-value').append('<option value="9999999">Todos los valores de atributos</option>');
+                _.each(self.ProductAttributeValue,function(item){
+                    self.$el.find('#current-attribute-value').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+            }
+        },
+
+        updateJournalSelections: function () {
+            var self = this;
+            var journal;
+            var store = self.$el.find('#current-store').val();
+            if(store != 9999999){
+                journal = self.$el.find('#current-journal').empty();
+                self.$el.find('#current-journal').append('<option value="9999999">Todas las facturas</option>');
+                _.each(self.AccountJournal,function(item){
+                    if(parseFloat(store) == item.store_id){
+                        self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    }
+                });
+            }else{
+                journal = self.$el.find('#current-journal').empty();
+                self.$el.find('#current-journal').append('<option value="9999999">Todas las facturas</option>');
+                _.each(self.AccountJournal,function(item){
+                    self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+            }
+        },
+
+        getProductCategory: function (id) {
+            var self = this;
+            var category;
+            category =  _.filter(self.ProductCategory,function (item) {
+                return item.id == id;
+            });
+            if(category.length > 0)
+                return category[0].name;
+        },
+
+        getPosOrderLine:function() {
+            var self = this;
+            var content = self.PosOrderLine;
+            var company = self.$el.find('#current-company').val();
+            var store = self.$el.find('#current-store').val();
+            var type = self.$el.find('#current-type').val();
+            var journal = self.$el.find('#current-journal').val();
+            var category = self.$el.find('#current-category').val();
+            var brand = self.$el.find('#current-brand').val();
+            var attribute = self.$el.find('#current-attribute').val();
+            var attribute_value = self.$el.find('#current-attribute-value').val();
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+
+            if((store && store == 9999999)||(company && company == 9999999)){
+                var store_ids = _.flatten(_.map(self.ResStore, function (item) {
+                    return item.id;
+                }));
+                var company_ids = _.flatten(_.map(self.ResCompany, function (item) {
+                    return item.id;
+                }));
+                content = _.flatten(_.filter(content,function (item) {
+                    return _.contains(store_ids, item.store_id) && _.contains(company_ids, item.company_id);
+                }));
+            }
+
+            if(company && company != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.company_id == company;
+                }));
+            }
+            if(store && store != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.store_id == store;
+                }));
+            }
+            if(type && type != 9999999){
+                if(type == 'sale'){
+                    content = [];
+                }
+            }
+            if(journal && journal != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.journal_id == journal;
+                }));
+            }
+            if(date && date != 9999999){
+                if(date == 'range'){
+                    if(desde){
+                        date = desde.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                            utc = moment(utc._d).format('YYYY-MM-DD');
+                            return moment(utc).format('YYYY-MM-DD') >= date;
+                        }));
+                    }
+                    if(hasta){
+                        date = hasta.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                            utc = moment(utc._d).format('YYYY-MM-DD');
+                            return moment(utc).format('YYYY-MM-DD') <= date;
+                        }));
+                    }
+                }
+                if(date == 'today'){
+                    var today = moment().format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                        utc = moment(utc._d).format('YYYY-MM-DD');
+                        return moment(utc).format('YYYY-MM-DD') === today;
+                    }));
+                }
+                if(date == 'yesterday'){
+                    var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                        utc = moment(utc._d).format('YYYY-MM-DD');
+                        return moment(utc).format('YYYY-MM-DD') === yesterday;
+                    }));
+                }
+                if(date == 'currentMonth'){
+                    var currentMonth = moment().format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                        utc = moment(utc._d).format('YYYY-MM-DD');
+                        return moment(utc).format('YYYY-MM') === currentMonth;
+                    }));
+                }
+                if(date == 'lastMonth'){
+                    var lastMonth = moment().add(-1,'months').format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                        utc = moment(utc._d).format('YYYY-MM-DD');
+                        return moment(utc).format('YYYY-MM') === lastMonth;
+                    }));
+                }
+            }
+            if(category && category != 9999999){
+                var category_ids = _.map(_.filter(self.ProductCategory,function (item) {
+                    return item.id == category || item.parent_id == category;
+                }), function(map){
+                    return map.id;
+                });
+                var category_children_ids = _.map(_.filter(self.ProductCategory,function (item) {
+                    return _.contains(category_ids, item.parent_id) || item.id == category;
+                }), function(map){
+                    return map.id;
+                });
+                var category_grandchildren_ids = _.map(_.filter(self.ProductCategory,function (item) {
+                    return _.contains(category_children_ids, item.parent_id) || item.id == category;
+                }), function(map){
+                    return map.id;
+                });
+                var categ_ids =  _.map(_.filter(self.ProductCategory,function (item) {
+                    return _.contains(category_grandchildren_ids, item.parent_id) || item.id == category;
+                }), function(map){
+                    return map.id;
+                });
+                content = _.flatten(_.filter(content,function (inv) {
+                    return _.contains(categ_ids, inv.categ_id);
+                }));
+            }
+            if(brand && brand != 9999999){
+                content = _.filter(content,function (item) {
+                    return item.product_brand_id == parseInt(brand);
+                });
+            }
+            if(attribute && attribute != 9999999){
+                content = _.filter(content,function (item) {
+                    return _.contains(item.attribute_ids, parseInt(attribute));
+                });
+            }
+            if(attribute_value && attribute_value != 9999999){
+                content = _.filter(content,function (item) {
+                    return _.contains(item.attribute_value_ids, parseInt(attribute_value));
+                });
+            }
+            return content;
+        },
+
+        getAccountInvoiceLine:function() {
+            var self = this;
+            var content = self.AccountInvoiceLine;
+            var company = self.$el.find('#current-company').val();
+            var store = self.$el.find('#current-store').val();
+            var type = self.$el.find('#current-type').val();
+            var journal = self.$el.find('#current-journal').val();
+            var category = self.$el.find('#current-category').val();
+            var brand = self.$el.find('#current-brand').val();
+            var attribute = self.$el.find('#current-attribute').val();
+            var attribute_value = self.$el.find('#current-attribute-value').val();
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+
+            if((store && store == 9999999)||(company && company == 9999999)){
+                var store_ids = _.flatten(_.map(self.ResStore, function (item) {
+                    return item.id;
+                }));
+                var company_ids = _.flatten(_.map(self.ResCompany, function (item) {
+                    return item.id;
+                }));
+                content = _.flatten(_.filter(content,function (item) {
+                    return _.contains(store_ids, item.store_id) && _.contains(company_ids, item.company_id);
+                }));
+            }
+
+            if(company && company != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.company_id == company;
+                }));
+            }
+            if(store && store != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.store_id == store;
+                }));
+            }
+            if(type && type != 9999999){
+                if(type == 'tpv'){
+                    content = [];
+                }
+            }
+            if(journal && journal != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.journal_id == journal;
+                }));
+            }
+            if(date && date != 9999999){
+                if(date == 'range'){
+                    if(desde){
+                        date = desde.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            return moment(inv.date).format('YYYY-MM-DD') >= date;
+                        }));
+                    }
+                    if(hasta){
+                        date = hasta.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            return moment(inv.date).format('YYYY-MM-DD') <= date;
+                        }));
+                    }
+                }
+                if(date == 'today'){
+                    var today = moment().format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM-DD') === today;
+                    }));
+                }
+                if(date == 'yesterday'){
+                    var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM-DD') === yesterday;
+                    }));
+                }
+                if(date == 'currentMonth'){
+                    var currentMonth = moment().format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM') === currentMonth;
+                    }));
+                }
+                if(date == 'lastMonth'){
+                    var lastMonth = moment().add(-1,'months').format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM') === lastMonth;
+                    }));
+                }
+            }
+            if(category && category != 9999999){
+                var category_ids = _.map(_.filter(self.ProductCategory,function (item) {
+                    return item.id == category || item.parent_id == category;
+                }), function(map){
+                    return map.id;
+                });
+                var category_children_ids = _.map(_.filter(self.ProductCategory,function (item) {
+                    return _.contains(category_ids, item.parent_id) || item.id == category;
+                }), function(map){
+                    return map.id;
+                });
+                var category_grandchildren_ids = _.map(_.filter(self.ProductCategory,function (item) {
+                    return _.contains(category_children_ids, item.parent_id) || item.id == category;
+                }), function(map){
+                    return map.id;
+                });
+                var categ_ids =  _.map(_.filter(self.ProductCategory,function (item) {
+                    return _.contains(category_grandchildren_ids, item.parent_id) || item.id == category;
+                }), function(map){
+                    return map.id;
+                });
+                content = _.flatten(_.filter(content,function (inv) {
+                    return _.contains(categ_ids, inv.categ_id);
+                }));
+            }
+            if(brand && brand != 9999999){
+                content = _.filter(content,function (item) {
+                    return item.product_brand_id == parseInt(brand);
+                });
+            }
+            if(attribute && attribute != 9999999){
+                content = _.filter(content,function (item) {
+                    return _.contains(item.attribute_ids, parseInt(attribute));
+                });
+            }
+            if(attribute_value && attribute_value != 9999999){
+                content = _.filter(content,function (item) {
+                    return _.contains(item.attribute_value_ids, parseInt(attribute_value));
+                });
+            }
+            return content;
+        },
+
+        BuildTable: function(){
+            var self = this;
+            var data = [];
+
+            var CurrencyBase = self.ResCompany[0].currency_id;
+            var PosOrderLine = self.getPosOrderLine();
+            var display_name;
+            var discount_amount;
+            var monto_discount;
+            var delivery_amount;
+            var modules = self.checkModule('product_brand');
+            _.each(PosOrderLine,function(item) {
+                monto_discount = 0;
+                delivery_amount = 0;
+                var category = self.getProductCategory(item.categ_id);
+                if(item.attribute_values[0] == null){
+                    display_name = item.product_name;
+                }else{
+                    display_name = item.product_name + ' (' + _.uniq(item.attribute_values) + ')';
+                }
+                if(modules.length > 0){
+                    if(item.product_brand_id != null){
+                        display_name = display_name + ' ( ' + item.brand_name + ')';
+                    }
+                }
+                discount_amount = 0;
+                if(item.discount > 0){
+                    discount_amount = ((item.quantity * item.price_unit) * item.discount)/100;
+                }
+
+                if(item.product_id == 3160 || item.product_id == 3066 || item.product_id == 6404 || item.product_id == 6505){
+                     delivery_amount = delivery_amount + (item.quantity * item.price_unit);
+                }
+
+                // if(item.product_id == 5101){
+                //     monto_discount  = (item.quantity * item.price_unit);
+                // }
+
+                data.push({
+                    id : item.order_line_id,
+                    number:item.name,
+                    date:moment(item.date).format('DD/MM/YYYY'),
+                    ruc : self.valorNull(item.partner_ruc),
+                    customer_name:self.valorNull(item.customer_name),
+                    product_name:display_name,
+                    product_category:category,
+                    discount:accounting.formatNumber(item.discount,2,'.',',') + '%',
+                    discount_amount:accounting.formatMoney(discount_amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    price_unit:accounting.formatMoney(item.price_unit, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    quantity:accounting.formatNumber(item.quantity,2,'.',','),
+                    untaxed:accounting.formatMoney(item.subtotal, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    tax:accounting.formatMoney(item.tax, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    total:accounting.formatMoney(item.subtotal + item.tax, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    delivery_amount:accounting.formatMoney(delivery_amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    // monto_discount:accounting.formatMoney(monto_discount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    /*
+                    =============================
+                        NO FORMAT
+                    =============================
+                    */
+                    date_no_format:item.date,
+                    price_unit_no_format:item.price_unit,
+                    quantity_no_format:item.quantity,
+                    discount_amount_no_format:discount_amount,
+                    untaxed_no_format:item.subtotal,
+                    tax_no_format:item.tax,
+                    total_no_format:item.subtotal + item.tax,
+                    delivery_amount_no_format:delivery_amount,
+                    // monto_discount_no_format:monto_discount,
+                    /*
+                    ==============================
+                        FOOTER
+                    ==============================
+                    */
+                    decimal_places:CurrencyBase.decimal_places,
+                    thousands_separator:CurrencyBase.thousands_separator,
+                    decimal_separator:CurrencyBase.decimal_separator,
+                });
+            });
+            var AccountInvoiceLine = self.getAccountInvoiceLine();
+            _.each(AccountInvoiceLine,function(item) {
+              monto_discount = 0;
+              delivery_amount = 0;
+                var category = self.getProductCategory(item.categ_id);
+                if(item.attribute_values[0] == null){
+                    display_name = item.product_name;
+                }else{
+                    display_name = item.product_name + ' (' + _.uniq(item.attribute_values) + ')';
+                }
+                if(modules.length > 0){
+                    if(item.product_brand_id != null){
+                        display_name = display_name + ' ( ' + item.brand_name + ')';
+                    }
+                }
+                discount_amount = 0;
+                if(item.discount > 0){
+                    discount_amount = ((item.quantity * item.price_unit) * item.discount)/100;
+                }
+                if(item.product_id == 3160 || item.product_id == 3066 || item.product_id == 6404 || item.product_id == 6505){
+                     delivery_amount = delivery_amount + (item.quantity * item.price_unit);
+                }
+
+                // if(item.product_id == 5101){
+                //     monto_discount  = (item.quantity * item.price_unit);
+                // }
+
+                data.push({
+                    id : item.invoice_line_id,
+                    number:item.number,
+                    date:moment(item.date).format('DD/MM/YYYY'),
+                    ruc : self.valorNull(item.partner_ruc),
+                    customer_name:self.valorNull(item.partner_name),
+                    //product_name: display_name,
+                    product_name: !!display_name ?display_name : item.name,
+                    product_category:category,
+                    discount:accounting.formatNumber(item.discount,2,'.',',') + '%',
+                    discount_amount:accounting.formatMoney(discount_amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    price_unit:accounting.formatMoney(item.price_unit, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    quantity:accounting.formatNumber(item.quantity,2,'.',','),
+                    untaxed:accounting.formatMoney(item.subtotal, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    tax:accounting.formatMoney(item.tax, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    total:accounting.formatMoney(item.subtotal + item.tax, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    delivery_amount:accounting.formatMoney(delivery_amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    // monto_discount:accounting.formatMoney(monto_discount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    /*
+                    =============================
+                        NO FORMAT
+                    =============================
+                    */
+                    date_no_format:item.date,
+                    price_unit_no_format:item.price_unit,
+                    quantity_no_format:item.quantity,
+                    discount_amount_no_format: discount_amount,
+                    untaxed_no_format:item.subtotal,
+                    tax_no_format:item.tax,
+                    total_no_format:item.subtotal + item.tax,
+                    delivery_amount_no_format:delivery_amount,
+                    // monto_discount_no_format:monto_discount,
+                    /*
+                    ==============================
+                        FOOTER
+                    ==============================
+                    */
+                    decimal_places:CurrencyBase.decimal_places,
+                    thousands_separator:CurrencyBase.thousands_separator,
+                    decimal_separator:CurrencyBase.decimal_separator,
+                });
+            });
+            data.sort(function (a, b) {
+                if (a.date_no_format > b.date_no_format) {
+                    return -1;
+                }
+                if (a.date_no_format < b.date_no_format) {
+                    return 1;
+                }
+                return 0;
+            });
+            self.content = data;
+
+            self.loadTable(data);
+            self.$el.find('.report-form').css('display','block');
+            self.$el.find('.search-form').unblock();
+            self.$el.find('.report-form').unblock();
+        },
+
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load', rowsTable);
+        },
+
+        /*====================================================================
+            PRINT PDF
+        ====================================================================*/
+        clickOnAction: function (e) {
+            var self = this;
+            var ResCompany;
+            var CurrencyBase;
+            var action = this.$el.find(e.target).val();
+            var company = $('#current-company').val();
+            if(company && company != 9999999){
+                ResCompany = _.flatten(_.filter(self.CompanyLogo,function (inv) {
+                    return inv.id == company;
+                }));
+                ResCompany = CompanyLogo[0];
+                CurrencyBase = ResCompany[0].currency_id;
+            }else{
+                ResCompany = self.CompanyLogo[0];
+                CurrencyBase = self.ResCompany[0].currency_id;
+            }
+            var getColumns = [];
+            var rows = [];
+            var table = this.$el.find("#table");
+            var column = table.bootstrapTable('getVisibleColumns');
+            var row = table.bootstrapTable('getData');
+
+            var price_unit = PriceUnitFooter(row);
+            var quantity = QuantityFooter(row);
+            var tax = TaxFooter(row);
+            var untaxed = UntaxedFooter(row);
+            var total = TotalFooter(row);
+            var delivery_amount = DeliveryAmountFooter(row);
+            // var monto_discount = MontoDiscountFooter(row);
+
+            row.push({
+                number : 'Totales',
+                price_unit : price_unit,
+                quantity : quantity,
+                tax : tax,
+                untaxed : untaxed,
+                total : total,
+                delivery_amount : delivery_amount,
+            });
+
+            if (action === 'pdf') {
+                var data = _.map(column, function (val){
+                    return val.field;
+                });
+                _.each(_.map(column,function(val){
+                    return val;
+                }), function(item){
+                    getColumns.push([{
+                        title: item.title,
+                        dataKey: item.field
+                    }]);
+                });
+                /*
+                ============================================================
+                    CONFIGURACION DEL PDF
+                ============================================================
+                */
+                var pdf_title = 'Analisis de Venta.';
+                var pdf_type = 'l';
+                var pdf_name = 'analisis_de_venta_';
+                var pdf_columnStyles = {
+                    number:{columnWidth: 25, halign:'center'},
+                    date:{columnWidth: 20, halign:'center'},
+                    ruc:{columnWidth: 20, halign:'center'},
+                    customer_name:{halign:'center'},
+                    product_name:{columnWidth: 'auto', halign:'left'},
+                    product_category:{columnWidth: 40, halign:'left'},
+                    price_unit:{columnWidth: 20, halign:'right'},
+                    quantity:{columnWidth: 20, halign:'right'},
+                    untaxed:{columnWidth: 20, halign:'right'},
+                    tax:{columnWidth: 20, halign:'right'},
+                    total:{columnWidth: 20, halign:'right'},
+                    delivery_amount:{columnWidth: 20, halign:'right'},
+                };
+                /*
+                ============================================================
+                    LLAMAR FUNCION DE IMPRESION
+                ============================================================
+                */
+                var filter = self.getFilter();
+                var pdf = new reporting.ReportPdfWidget(self);
+                pdf.drawPDF(
+                    _.flatten(getColumns),
+                    row,
+                    ResCompany,
+                    pdf_title,
+                    pdf_type,
+                    pdf_name,
+                    pdf_columnStyles,
+                    filter
+               );
+            }
+        },
+        getFilter: function(){
+            var self = this;
+            var company = self.$el.find('#current-company').val();
+            var store = self.$el.find('#current-store').val();
+            var journal = self.$el.find('#current-journal').val();
+            var type = self.$el.find('#current-type').val();
+            var category = self.$el.find('#current-category').val();
+            var brand = self.$el.find('#current-brand').val();
+            var attribute = self.$el.find('#current-attribute').val();
+            var attribute_value = self.$el.find('#current-attribute-value').val();
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+            var filter = [];
+            if(company && company != 9999999){
+                var ResCompany = _.filter(self.ResCompany, function(item){
+                    return item.id == company;
+                });
+                filter.push({
+                    title:'Empresa',
+                    value: ResCompany[0].name,
+                });
+            }
+            if(store && store != 9999999){
+                var ResStore =  _.filter(self.ResStore,function (item) {
+                    return item.id == store;
+                });
+                filter.push({
+                    title: 'Sucursal',
+                    value:  ResStore[0].name,
+                });
+            }
+            if(journal && journal != 9999999){
+                var AccountJournal = _.filter(self.AccountJournal, function(item){
+                  return item.id == journal;
+                });
+                filter.push({
+                  title: 'Factura',
+                  value: AccountJournal[0].name,
+                });
+            }
+            if(type && type != 9999999){
+                filter.push({
+                    title: 'Tipo de Venta',
+                    value: $('#current-type option:selected').text(),
+                });
+            }
+            if(category && category != 9999999){
+                var categ =  _.filter(self.ProductCategory,function (item) {
+                    return item.id == category;
+                });
+                filter.push({
+                    title: 'Categoría',
+                    value: categ[0].name,
+               });
+            }
+            if(brand && brand != 9999999){
+                var ProductBrand =  _.filter(self.ProductBrand,function (item) {
+                    return item.id == brand;
+                });
+                filter.push({
+                    title: 'Marca',
+                    value: ProductBrand[0].name,
+                });
+            }
+            if(attribute && attribute != 9999999){
+                var attr =  _.filter(self.ProductAttribute,function (item) {
+                    return item.id == attribute;
+                });
+                filter.push({
+                    title: 'Atributo',
+                    value: attr[0].name,
+                });
+            }
+            if(attribute_value && attribute_value != 9999999){
+                var attr_value =  _.filter(self.ProductAttributeValue,function (item) {
+                    return item.id == attribute_value;
+                });
+                filter.push({
+                    title: 'Valor de Atributo',
+                    value: attr_value[0].name,
+                });
+            }
+            if(date && date != 9999999){
+                moment.locale('es', {
+                    months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
+                });
+                if(date == 'range'){
+                    filter.push({
+                        title: 'Fecha',
+                        value:  desde +' al '+hasta,
+                    });
+                }else {
+                    var fecha;
+                    if(date == 'today'){
+                        fecha = moment().format('DD/MM/YYYY');
+                    }
+                    if(date == 'yesterday'){
+                        fecha = moment().add(-1,'days').format('DD/MM/YYYY');
+                    }
+                    if(date == 'currentMonth'){
+                        fecha = moment().format('MMMM/YYYY');
+                    }
+                    if(date == 'lastMonth'){
+                        fecha = moment().add(-1,'months').format('MMMM/YYYY');
+                    }
+                    filter.push({
+                        title: 'Fecha',
+                        value:  fecha,
+                    });
+                }
+            }
+            return filter;
+        },
+    });
+}

+ 11 - 6
static/src/js/reports/report_sale_journal.js

@@ -332,6 +332,7 @@ function report_sale_journal(reporting){
         ====================================================================*/
         fetchPosOrder: function () {
             var self = this;
+            console.log(self);
             var type = $('#current-type').val();
             var modules = self.checkModel('point_of_sale');
             if (type && modules.length > 0){
@@ -377,7 +378,7 @@ function report_sale_journal(reporting){
                             }
                         }
                     }
-                    var PosOrder = new model.web.Model('account.invoice');
+                    var PosOrder = new model.web.Model('pos.order');
                     return PosOrder.call('getPosOrder',[domain], {
                         context: new model.web.CompoundContext()
                     });
@@ -624,7 +625,9 @@ function report_sale_journal(reporting){
             ==========================================
             */
             var PosOrder = self.getPosOrder();
+
             _.each(PosOrder, function(item){
+
                 var gravada = 0;
                 var impuesto = 0;
                 var exenta = 0;
@@ -644,6 +647,7 @@ function report_sale_journal(reporting){
                     =======================*/
                     number : item.name,
                     supplier_invoice_number: self.valorNull(item.supplier_invoice_number),
+                    timbrado_name: '',
                     date_invoice : moment(utc._d).format('DD/MM/YYYY'),
                     date : item.date_order,
                     partner_id : self.valorNull(item.partner_id[1]),
@@ -699,6 +703,7 @@ function report_sale_journal(reporting){
                         =======================*/
                         number : item.number,
                         supplier_invoice_number: self.valorNull(item.supplier_invoice_number),
+                        timbrado_name: self.valorNull(item.timbrado_name),
                         date_invoice : moment(item.date_invoice).format('DD/MM/YYYY'),
                         date : item.date_invoice,
                         partner_id : self.valorNull(item.partner_id[1]),
@@ -728,10 +733,7 @@ function report_sale_journal(reporting){
                     });
                 });
             }
-            // data.sort(function(a,b){
-            //     // return new Date(a.date) - new Date(b.date);
-            //     return new Date(b.date) - new Date(a.date);
-            // });
+
 
             data.sort(function (a, b) {
                 if (a.date > b.date) {
@@ -833,6 +835,7 @@ function report_sale_journal(reporting){
             row.push({
                 number : 'Items: ',
                 supplier_invoice_number: row.length,
+                timbrado_name : ' ',
                 date_invoice : ' ',
                 partner_id : 'TOTALES: ',
                 partner_ruc : ' ',
@@ -865,12 +868,13 @@ function report_sale_journal(reporting){
                     var pdf_columnStyles = {
                         number :{columnWidth: 27, halign:'center'},
                         supplier_invoice_number: {columnWidth: 24, halign:'center'},
+                        timbrado_name: {columnWidth: 20, halign:'center'},
                         date_invoice :{columnWidth: 24, halign:'center'},
                         partner_id :{columnWidth: 52, halign:'left'},
                         partner_ruc : {columnWidth: 18, halign:'left'},
                         gravada_total : {columnWidth: 24.2, halign:'right'},
                         percetage_total : {columnWidth: 8.9, halign:'right'},
-                        tax_total : {columnWidth: 24, halign:'right'},
+                        tax_total : {columnWidth: 23, halign:'right'},
                         exenta_total : {columnWidth: 21, halign:'right'},
                         ret_iva_total : {columnWidth: 18, halign:'right'},
                         ret_renta_total : {columnWidth: 20, halign:'right'},
@@ -881,6 +885,7 @@ function report_sale_journal(reporting){
                     var pdf_columnStyles = {
                         number :{columnWidth: 25, halign:'center'},
                         supplier_invoice_number: {columnWidth: 24, halign:'center'},
+                        timbrado_name: {columnWidth: 20, halign:'center'},
                         date_invoice :{columnWidth: 16, halign:'center'},
                         partner_id :{columnWidth: 35, halign:'left'},
                         partner_ruc : {columnWidth: 16.8, halign:'left'},

+ 12 - 0
static/src/reports/report_sale.xml

@@ -161,6 +161,18 @@
                                     data-footer-formatter="TotalFooter"
                                     data-width="180"
                                     >Total</th>
+                                <th data-field="customer_phone"
+                                    data-align="left"
+                                    >Teléfono</th>
+                                <th data-field="customer_mobile"
+                                    data-align="left"
+                                    >Celular</th>
+                                <th data-field="customer_city"
+                                    data-align="left"
+                                    >Ciudad</th> 
+                                <th data-field="customer_email"
+                                    data-align="left"
+                                    >Email</th>
                             </tr>
                         </thead>
                     </table>

+ 6 - 1
static/src/reports/report_sale_analytic.xml

@@ -122,6 +122,7 @@
                                     >Fecha</th>
                                 <th data-field="ruc"
                                     data-align="left"
+                                    data-width="60px"                                    
                                     >Cliente</th>
                                 <th data-field="customer_name"
                                     data-align="left"
@@ -167,8 +168,12 @@
                                 <th data-field="total"
                                     data-align="right"
                                     data-footer-formatter="TotalFooter"
-                                    data-width="150"
+                                    data-width="100"
                                     >Total</th>
+                                <th data-field="vendor_name"
+                                    data-align="left"
+                                    data-width="100"
+                                    >Vendedor</th>
                             </tr>
                         </thead>
                     </table>

+ 305 - 0
static/src/reports/report_sale_baco_analytic.xml

@@ -0,0 +1,305 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportSaleBacoAnalytic">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1 class="report_title"> Análisis de Ventas</h1>
+            </div>
+            <div class="container search-form" style="border-bottom:1px solid #eee; width:95%;">
+                <div class="row">
+                    <div class="col-lg-3 company filter-style">
+                        <label>Empresa</label>
+                        <select id="current-company" class="form-control form-control-sm"></select>
+                    </div>
+                    <div class="col-lg-3 store filter-style">
+                        <label>Sucursal</label>
+                        <select id="current-store" class="form-control form-control-sm">
+                        </select>
+                    </div>
+                    <div class="col-lg-3 journal filter-style">
+                        <label>Factura</label>
+                        <select id="current-journal" class="form-control form-control-sm">
+                        </select>
+                    </div>
+                    <div class="col-lg-3 type filter-style">
+                        <label>Tipo de Venta</label>
+                        <select id="current-type" class="form-control form-control-sm">
+                            <option value="9999999">Todos los Tipos</option>
+                            <option value="tpv">Terminal</option>
+                            <option value="sale">Normal</option>
+                        </select>
+                    </div>
+                    <div class="col-lg-3 filter-style">
+                        <label>Categoria</label>
+                        <select id="current-category" class="form-control form-control-sm">
+                        </select>
+                    </div>
+                    <div class="col-lg-3 brand filter-style">
+                        <label>Marca</label>
+                        <select id="current-brand" class="form-control form-control-sm">
+                        </select>
+                    </div>
+                    <div class="col-lg-3 attribute filter-style">
+                        <label>Atributo</label>
+                        <select id="current-attribute" class="form-control form-control-sm">
+                        </select>
+                    </div>
+                    <div class="col-lg-3 attribute-value filter-style">
+                        <label>Valor del Atributo</label>
+                        <select id="current-attribute-value" class="form-control form-control-sm">
+                        </select>
+                    </div>
+                    <div class="col-lg-3 filter-style">
+                        <label>Fechas</label>
+                        <select id="current-date" class="form-control form-control-sm">
+                            <option value="9999999">Sin fechas</option>
+                            <option value="today">Hoy</option>
+                            <option value="yesterday">Ayer</option>
+                            <option value="currentMonth">Mes Actual</option>
+                            <option value="lastMonth">Mes Pasado</option>
+                            <option value="range">Busqueda Avanzada</option>
+                        </select>
+                    </div>
+                </div>
+                <div class="row" >
+                    <div class="datepicker" style="display:none;">
+                        <div class="col-lg-3 filter-style col-md-offset-3">
+                            <div class="input-group">
+                                <span class="input-group-addon" id="basic-addon1">Desde</span>
+                                <input type="text" id="from" class="form-control" aria-describedby="basic-addon1"/>
+                            </div>
+                        </div>
+                        <div class="col-lg-3 filter-style">
+                            <div class="input-group">
+                                <span class="input-group-addon" id="basic-addon1">Hasta</span>
+                                <input type="text" id="to" class="form-control" aria-describedby="basic-addon1"/>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+                <div class="row">
+                    <div class="text-center" style="padding-top:20px;">
+                        <button id="generate" class="myButton" aria-label="Left Align" style="color:#fff;display:none;">
+                            Generar
+                        </button>
+                    </div>
+                    <br/>
+                </div>
+            </div>
+
+            <div class="report-form" style="display:none;">
+                <div id="toolbar">
+                    <button class="myButton print-report" value="pdf">Imprimir Informe</button>
+                </div>
+                <div class="container" style="width:95%;">
+                    <table id="table"
+                        data-pagination="true"
+                        data-toggle="table"
+                        data-toolbar="#toolbar"
+                        data-show-columns="true"
+                        data-classes="table table-condensed"
+                        data-search="true"
+                        data-show-export="true"
+                        data-show-toggle="true"
+                        data-pagination-detail-h-align="left"
+                        data-show-footer="true"
+                        data-pagination-v-align="top"
+                        data-footer-style="footerStyle"
+                        data-buttons-class="oe_button myButton"
+                        data-show-pagination-switch="true"
+                        data-page-size="10"
+                        data-search-on-enter-key="true"
+                        data-undefined-text=" "
+                        >
+                        <thead style="background:none;">
+                            <tr>
+                                <th data-field="number"
+                                    data-align="center"
+                                    data-footer-formatter="Totales"
+                                    >Factura</th>
+                                <th data-field="date"
+                                    data-align="center"
+                                    >Fecha</th>
+                                <th data-field="ruc"
+                                    data-align="left"
+                                    >Cliente</th>
+                                <th data-field="customer_name"
+                                    data-align="left"
+                                    >CIN/RUC</th>
+                                <th data-field="product_name"
+                                    data-align="left"
+                                    data-width="200px"
+                                    >Producto</th>
+                                <th data-field="product_category"
+                                    data-align="left"
+                                    data-width="200px"
+                                    >Categoria</th>
+                                <th data-field="price_unit"
+                                    data-align="right"
+                                    data-footer-formatter="PriceUnitFooter"
+                                    data-width="150"
+                                    >Precio Unitario</th>
+                                <th data-field="quantity"
+                                    data-align="right"
+                                    data-footer-formatter="QuantityFooter"
+                                    data-width="100px"
+                                    >Cantidad</th>
+                                <th data-field="discount"
+                                    data-align="center"
+                                    data-visible="false"
+                                    >Descuento (%)</th>
+                                <th data-field="discount_amount"
+                                    data-align="right"
+                                    data-visible="false"
+                                    data-footer-formatter="DiscountFooter"
+                                    data-width="150"
+                                    >Descuento (Monto)</th>
+                                <th data-field="untaxed"
+                                    data-align="right"
+                                    data-footer-formatter="UntaxedFooter"
+                                    data-width="150"
+                                    >SubTotal</th>
+                                <th data-field="tax"
+                                    data-align="right"
+                                    data-footer-formatter="TaxFooter"
+                                    data-width="150"
+                                    >Impuesto</th>
+                                <th data-field="total"
+                                    data-align="right"
+                                    data-footer-formatter="TotalFooter"
+                                    data-width="150"
+                                    >Total</th>
+                                <th data-field="delivery_amount"
+                                    data-align="right"
+                                    data-footer-formatter="DeliveryAmountFooter"
+                                    data-width="150"
+                                    >T. Delivery</th>
+                            </tr>
+                        </thead>
+                    </table>
+                </div>
+            </div>
+
+
+            <script>
+
+                <!--
+                    PRICE UNIT
+                -->
+                function PriceUnitFooter(rowsTable) {
+                    var decimal_places = 0;
+                    var thousands_separator = '.';
+                    var decimal_separator = ',';
+                    if(rowsTable.length > 0){
+                        decimal_places = rowsTable[0].decimal_places;
+                        thousands_separator = rowsTable[0].thousands_separator;
+                        decimal_separator = rowsTable[0].decimal_separator;
+                    }
+                    var total =  _.reduce(_.map(rowsTable,function(item){
+                        return item.price_unit_no_format;
+                    }), function(memo, num){
+                        return memo + num;
+                    },0);
+                    return accounting.formatNumber(total,decimal_places,thousands_separator,decimal_separator);
+                }
+                <!--
+                    QUANTITY
+                -->
+                function QuantityFooter(rowsTable) {
+                    var total =  _.reduce(_.map(rowsTable,function(item){
+                        return item.quantity_no_format;
+                    }), function(memo, num){
+                        return memo + num;
+                    },0);
+                    return accounting.formatNumber(total,2,'.',',');
+                }
+                <!--
+                    DISCOUNT AMOUNT
+                -->
+                function DiscountFooter(rowsTable) {
+                    var decimal_places = 0;
+                    var thousands_separator = '.';
+                    var decimal_separator = ',';
+                    if(rowsTable.length > 0){
+                        decimal_places = rowsTable[0].decimal_places;
+                        thousands_separator = rowsTable[0].thousands_separator;
+                        decimal_separator = rowsTable[0].decimal_separator;
+                    }
+                    var total =  _.reduce(_.map(rowsTable,function(item){
+                        return item.discount_amount_no_format;
+                    }), function(memo, num){
+                        return memo + num;
+                    },0);
+                    return accounting.formatNumber(total,decimal_places,thousands_separator,decimal_separator);
+                }
+                <!--
+                    SUBTOTAL
+                -->
+                function UntaxedFooter(rowsTable) {
+                    var decimal_places = 0;
+                    var thousands_separator = '.';
+                    var decimal_separator = ',';
+                    if(rowsTable.length > 0){
+                        decimal_places = rowsTable[0].decimal_places;
+                        thousands_separator = rowsTable[0].thousands_separator;
+                        decimal_separator = rowsTable[0].decimal_separator;
+                    }
+                    var total =  _.reduce(_.map(rowsTable,function(item){
+                        return item.untaxed_no_format;
+                    }), function(memo, num){
+                        return memo + num;
+                    },0);
+                    return accounting.formatNumber(total,decimal_places,thousands_separator,decimal_separator);
+                }
+                <!--
+                    TAX
+                -->
+                function TaxFooter(rowsTable) {
+                    var decimal_places = 0;
+                    var thousands_separator = '.';
+                    var decimal_separator = ',';
+                    if(rowsTable.length > 0){
+                        decimal_places = rowsTable[0].decimal_places;
+                        thousands_separator = rowsTable[0].thousands_separator;
+                        decimal_separator = rowsTable[0].decimal_separator;
+                    }
+                    var total =  _.reduce(_.map(rowsTable,function(item){
+                        return item.tax_no_format;
+                    }), function(memo, num){
+                        return memo + num;
+                    },0);
+                    return accounting.formatNumber(total,decimal_places,thousands_separator,decimal_separator);
+                }
+                <!--
+                    TOTAL
+                -->
+                function TotalFooter(rowsTable) {
+                    var decimal_places = 0;
+                    var thousands_separator = '.';
+                    var decimal_separator = ',';
+                    if(rowsTable.length > 0){
+                        decimal_places = rowsTable[0].decimal_places;
+                        thousands_separator = rowsTable[0].thousands_separator;
+                        decimal_separator = rowsTable[0].decimal_separator;
+                    }
+                    var total =  _.reduce(_.map(rowsTable,function(item){
+                        return item.total_no_format;
+                    }), function(memo, num){
+                        return memo + num;
+                    },0);
+                    return accounting.formatNumber(total,decimal_places,thousands_separator,decimal_separator);
+                }
+                <!--
+                    FOOTER STYLE
+                -->
+                function footerStyle(row, index) {
+                    return {
+                        css: {
+                          "font-weight": "bold"
+                        }
+                    };
+                };
+            </script>
+        </div>
+    </t>
+</template>

+ 1 - 0
static/src/reports/report_sale_journal.xml

@@ -114,6 +114,7 @@
                             <tr>
                                 <th data-field="number" data-align="center" data-footer-formatter="Items:">Num.</th>
                                 <th data-field="supplier_invoice_number" data-align="center" data-footer-formatter="itemsCount">N° Fact.</th>
+                                <th data-field="timbrado_name" data-align="center">Timbrado</th>
                                 <th data-field="date_invoice" data-align="center">Fecha</th>
                                 <th data-field="partner_id" data-align="left" data-width="15%" data-footer-formatter="TOTALES:">Razón Social</th>
                                 <th data-field="partner_ruc" data-align="left" data-width="10%">RUC</th>

+ 5 - 0
templates.xml

@@ -54,6 +54,11 @@
                     ==============================-->
                     <script type="text/javascript" src="/eiru_reports/static/src/js/reports/report_sale_analytic.js"/>
 
+                    <!--=============================
+                        Analisis de ventas Baco
+                    ==============================-->
+                    <script type="text/javascript" src="/eiru_reports/static/src/js/reports/report_sale_baco_analytic.js"/>
+
                     <!--=============================
                         Clientes
                     ==============================-->

+ 8 - 0
views/actions.xml

@@ -72,6 +72,14 @@
 	            <field name="tag">eiru_reports.sale_analytic_action</field>
 	        </record>
 
+					<!--======================
+							ANALISIS DE VENTAS BACO
+					=======================-->
+					<record id="sale_baco_analytic_action" model="ir.actions.client">
+							<field name="name">Análisis de Ventas Baco</field>
+							<field name="tag">eiru_reports.sale_baco_analytic_action</field>
+					</record>
+
 	        <!--======================
 	            CLIENTES
 	        =======================-->

+ 6 - 0
views/menus.xml

@@ -63,6 +63,12 @@
             ======================-->
             <menuitem id="sale_analytic_menu" parent="sale_parent_menu" name="Análisis de Ventas" action="sale_analytic_action" sequence="2"/>
 
+            <!--=====================
+               Analisis de ventas
+            ======================-->
+            <menuitem id="sale_baco_analytic_menu" parent="sale_parent_menu" name="Análisis de Ventas Baco" action="sale_baco_analytic_action" sequence="2"/>
+
+
             <!--=====================
                Clientes
             ======================-->