Browse Source

[ADD] new widget

Adrielso 7 years ago
parent
commit
b304637112

+ 21 - 2
static/src/js/dashboard.js

@@ -30,12 +30,12 @@ function dashboard_widget (instance, widget) {
             wExpiredAccountNow.renderElement();
             wExpiredAccountNow.start();
             this.grid.addWidget(wExpiredAccountNow.$el, 0, 0, wExpiredAccountNow.size.width,  wExpiredAccountNow.size.height, true);
-            // Pagados oi
+            // Cobros de Hoy
             var wVocuherToday = new widgets.VoucherTodayCountersWidget(this);
             wVocuherToday.renderElement();
             wVocuherToday.start();
             this.grid.addWidget(wVocuherToday.$el, 0, 0, wVocuherToday.size.width,  wVocuherToday.size.height, true);
-
+            // Cantidad de Facturas Realizada en el dia
             var wInvoiceToday = new widgets.InvoiceTodayCountersWidget(this);
             wInvoiceToday.renderElement();
             wInvoiceToday.start();
@@ -45,6 +45,13 @@ function dashboard_widget (instance, widget) {
             wRankingProduct.renderElement();
             wRankingProduct.start();
             this.grid.addWidget(wRankingProduct.$el, 0, 0, wRankingProduct.size.width,  wRankingProduct.size.height, true);
+            //Ranking de clientes que mas compra
+            var wRankingPartner = new widgets.RankingSalesPartnerWidget(this);
+            wRankingPartner.renderElement();
+            wRankingPartner.start();
+            this.grid.addWidget(wRankingPartner.$el, 0, 0, wRankingPartner.size.width,  wRankingPartner.size.height, true);
+
+
             //Gasto por Mes
             var wMonthlyExpenses = new widgets.MonthlyExpensesWidget(this);
             wMonthlyExpenses.renderElement();
@@ -55,6 +62,18 @@ function dashboard_widget (instance, widget) {
             wMonthlyPurchases.renderElement();
             wMonthlyPurchases.start();
             this.grid.addWidget(wMonthlyPurchases.$el, 0, 0, wMonthlyPurchases.size.width,  wMonthlyPurchases.size.height, true);
+            //Cantidad de Prodcutos Faltantes
+            var wMissingProduct = new widgets.MissingProductWidget(this);
+            wMissingProduct.renderElement();
+            wMissingProduct.start();
+            this.grid.addWidget(wMissingProduct.$el, 0, 0, wMissingProduct.size.width,  wMissingProduct.size.height, true);
+            // Pagos de  Hoy
+            var wPaymentsToday = new widgets.PaymentsTodayCountersWidget(this);
+            wPaymentsToday.renderElement();
+            wPaymentsToday.start();
+            this.grid.addWidget(wPaymentsToday.$el, 0, 0, wPaymentsToday.size.width,  wPaymentsToday.size.height, true);
+            //
+
             // for (var i = 1; i <= 4; i++) {
             //     var widget = new widgets.CustomerCounterWidget(this);
             //     widget.renderElement();

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

@@ -17,8 +17,11 @@ openerp.eiru_dashboard = function (instance) {
     voucher_today_counters(dashboard);
     invoice_today_counters(dashboard);
     ranking_sales_product(dashboard);
+    ranking_sales_partner(dashboard);
     monthly_expenses(dashboard);
     monthly_purchases(dashboard);
+    missing_product(dashboard);
+    payments_today_counters(dashboard);
     // customer_counter(dashboard);
     // sales_in_the_week(dashboard);
     // top_sales_product(dashboard);

+ 22 - 4
static/src/js/widgets/expired_account_counters.js

@@ -5,11 +5,14 @@ function expired_account_counters (widget) {
 
     widget.ExpiredAccountCountersWidget = widget.Base.extend({
         template: 'ExpiredAccountCounters',
-        // data : [],
         resPartner : [],
         moveLine : [],
         resCompany : [],
 
+        events: {
+            'click a': 'showCustomers',
+            'click h2': 'showCustomers',
+        },
         init: function (parent) {
             this._super(parent, {
                 width : 3,
@@ -60,8 +63,6 @@ function expired_account_counters (widget) {
         // Move line
         fetchMoveLine: function (partner){
             var self = this;
-            // var fecha = new Date();
-            // var hoy = (fecha.getFullYear() + "-" + (fecha.getMonth() + 1) + "-" + fecha.getDate());
             var hoy =moment().format('YYYY-MM-DD');
             var defer = $.Deferred();
             var move_id = _.flatten(_.map(partner, function (map) {
@@ -87,7 +88,6 @@ function expired_account_counters (widget) {
             resCompany.query(fields).filter(domain).all().then(function (results) {
                 defer.resolve(results);
             });
-
             return defer;
         },
         // Reduce Move line
@@ -110,6 +110,24 @@ function expired_account_counters (widget) {
             self.$el.find('.widget-content').find('a').text(accounting.formatNumber(residual,2, ".", ","));
             self.$el.find('.widget-footer').find('span').text("Monto en " + company);
             self.$el.find('.grid-stack-item-content dashboard').unblock();
+        },
+        showCustomers: function (e) {
+            var self = this;
+            var hoy =moment().format('YYYY-MM-DD');
+            var move_id = _.flatten(_.map(self.moveLine, function (map) {
+                return map.id;
+            }));
+            this.do_action({
+                name:"Listado de Clientes con Deuda Atrasadas",
+                type: 'ir.actions.act_window',
+                res_model: "res.partner",
+                views: [[false, 'list']],
+                // views: [[false,'form']],
+                // view_mode: ['form,tree'],
+                target: 'new',
+                domain: [['unreconciled_aml_ids', '=', move_id]],
+                context: {},
+            });
         }
     });
 }

+ 28 - 9
static/src/js/widgets/expired_account_counters_now.js

@@ -5,11 +5,14 @@ function expired_account_counters_now (widget) {
 
     widget.ExpiredAccountCountersNowWidget = widget.Base.extend({
         template: 'ExpiredAccountCountersNow',
-        // data : [],
         resPartner : [],
         moveLine : [],
         resCompany : [],
 
+        events: {
+            'click a': 'showCustomers',
+            'click h2': 'showCustomers',
+        },
         init: function (parent) {
             this._super(parent, {
                 width : 3,
@@ -22,7 +25,6 @@ function expired_account_counters_now (widget) {
         },
         fetchInitial: function () {
             var self = this;
-
             self.$el.find('#morosidad').block({
                 message: null,
                 overlayCSS: {
@@ -43,8 +45,6 @@ function expired_account_counters_now (widget) {
                 self.resCompany=resCompany;
                 return self.fetchReduceMoveLine();
             });
-
-            return false;
         },
         // Partner
         fetchPartner: function () {
@@ -63,8 +63,6 @@ function expired_account_counters_now (widget) {
         // Move line
         fetchMoveLine: function (partner) {
             var self = this;
-            // var fecha = new Date();
-            // var hoy = (fecha.getFullYear() + "-" + (fecha.getMonth() + 1) + "-" + fecha.getDate());
             var hoy =moment().format('YYYY-MM-DD');
             var defer = $.Deferred();
             var move_id = _.flatten(_.map(partner, function (map) {
@@ -77,7 +75,6 @@ function expired_account_counters_now (widget) {
             moveLine.query(field).filter(domain).all().then(function (results) {
                 defer.resolve(results);
             });
-
             return defer;
         },
         //Comapnia
@@ -97,10 +94,16 @@ function expired_account_counters_now (widget) {
         fetchReduceMoveLine: function () {
             var self = this;
             var residual =0;
-            var company = _.map(self.resCompany, function(map){return map.currency_id[1]});
+            var company = _.map(self.resCompany, function(map){
+                return map.currency_id[1];
+            });
 
             if (self.moveLine.length > 0){
-                residual = _.reduce(_.map(self.moveLine, function(map){return map.amount_residual}),function(memo, num){return memo + num});
+                residual = _.reduce(_.map(self.moveLine, function(map){
+                    return map.amount_residual;
+                }),function(memo, num){
+                    return memo + num;
+                });
             }
 
             self.$el.find('.widget-content.widget-loading').css('display','none');
@@ -108,5 +111,21 @@ function expired_account_counters_now (widget) {
             self.$el.find('.widget-footer').find('span').text("Monto en " + company);
             self.$el.find('#morosidad').unblock()
         },
+        showCustomers: function (e) {
+            var self = this;
+            var hoy =moment().format('YYYY-MM-DD');
+            var move_id = _.flatten(_.map(self.moveLine, function (map) {
+                return map.id;
+            }));
+            this.do_action({
+                name:"Listado de Clientes por Cobrar Hoy",
+                type: 'ir.actions.act_window',
+                res_model: "res.partner",
+                views: [[false, 'list']],
+                target: 'new',
+                domain: [['unreconciled_aml_ids', '=', move_id]],
+                context: {},
+            });
+        }
     });
 }

+ 18 - 3
static/src/js/widgets/invoice_today_counters.js

@@ -5,6 +5,10 @@ function invoice_today_counters (widget) {
 
     widget.InvoiceTodayCountersWidget = widget.Base.extend({
         template: 'InvoiceTodayCounters',
+        events: {
+            'click a': 'showCustomers',
+            'click h2': 'showCustomers',
+        },
         init: function (parent) {
             this._super(parent, {
                 width : 3,
@@ -34,10 +38,7 @@ function invoice_today_counters (widget) {
         fetchAccountInvoice: function() {
             var self = this;
             var defer = $.Deferred();
-            // var fecha = new Date();
-            // var hoy = fecha.getFullYear() + "-" + (fecha.getMonth() +1 ) + "-" + fecha.getDate();
             var hoy =moment().format('YYYY-MM-DD');
-
             var fields = ['id', 'residual'];
             var domain = [['type', '=', 'out_invoice'], ['state', '=', ['open','paid']], ['date_invoice', '=', hoy]];
             var accountInvoice = new model.web.Model('account.invoice');
@@ -62,5 +63,19 @@ function invoice_today_counters (widget) {
             self.$el.find('.widget-footer').find('span').text("Facturas Creadas en "+ fecha.getDate() + "/" + (fecha.getMonth() + 1) + "/" + fecha.getFullYear());
             self.$el.find('#morosidad').unblock();
         },
+        showCustomers: function (e) {
+            var hoy =moment().format('YYYY-MM-DD');
+
+
+            this.do_action({
+                name:"Facturas Realizada Hoy",
+                type: 'ir.actions.act_window',
+                res_model: "account.invoice",
+                views: [[false, 'list']],
+                target: 'new',
+                domain: [['type', '=', 'out_invoice'], ['state', '=', ['open','paid']], ['date_invoice', '=', hoy]],
+                context: {},
+            });
+        }
     });
 }

+ 84 - 0
static/src/js/widgets/missing_product.js

@@ -0,0 +1,84 @@
+function missing_product (widget) {
+    "use strict";
+
+    var model= openerp;
+
+    widget.MissingProductWidget = widget.Base.extend({
+        template: 'MissingProduct',
+        stockQuant:[],
+        productProduct:[],
+        events: {
+            'click a': 'showCustomers',
+            'click h2': 'showCustomers',
+        },
+        init: function (parent) {
+            this._super(parent, {
+                width : 3,
+                height: 2
+            });
+        },
+        start: function () {
+            var self = this;
+            self.fetchInitial();
+        },
+        fetchInitial: function () {
+            var self = this;
+            self.$el.find('#morosidad').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+            self.$el.find('.widget-content.widget-loading').css('display','flex');
+            // Iniciar Consultas
+            self.fetchProductProduct().then(function(productProduct){
+                return productProduct;
+            }).then(function(productProduct){
+                self.productProduct = productProduct;
+                return self.fetchReduceProduct();
+            });
+        },
+        fetchProductProduct : function(stockQaunt){
+            var self = this;
+            var defer =$.Deferred();
+            var product_id = _.map(stockQaunt,function(map){return map.product_id[0]});
+            var fields = ['id', 'name_template', 'qty_available'];
+            var domain =[['qty_available', '<=', 0],['type', '=', 'product']];
+            var productProduct = new model.web.Model('product.product');
+            productProduct.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // // Reduce Move line
+        fetchReduceProduct: function () {
+            var self = this;
+            var cantidad;
+            cantidad= _.countBy(_.map(self.productProduct,function(map){
+                            return map.id;
+                        }),function(num){
+                            return num ? 'even': 'odd';
+                        });
+
+            if (!cantidad){
+                cantidad={};
+                cantidad.even=0;
+            }
+            self.$el.find('.widget-content.widget-loading').css('display','none');
+            self.$el.find('.widget-content').find('a').text(cantidad.even);
+            // self.$el.find('.widget-footer').find('span').text("");
+            self.$el.find('#morosidad').unblock();
+        },
+        showCustomers: function (e) {
+            this.do_action({
+                name:"Listado de Productos sin Stock",
+                type: 'ir.actions.act_window',
+                res_model: "product.product",
+                views: [[false, 'list']],
+                target: 'new',
+                domain: [['type', '=', 'product'],['qty_available','<=',0]],
+                context: {},
+            });
+        }
+    });
+}

+ 22 - 2
static/src/js/widgets/monthly_expenses.js

@@ -9,7 +9,10 @@ function monthly_expenses(widget) {
         accountInvoice:[],
         currencyRate :[],
         resCompany:[],
-
+        events: {
+            'click a': 'showCustomers',
+            'click h2': 'showCustomers',
+        },
         init: function (parent) {
             this._super(parent, {
                 width : 3,
@@ -106,7 +109,7 @@ function monthly_expenses(widget) {
             newVoucher = self.getVoucherInvoice();
             for (var i = 0; i < newVoucher.length; i++) {
                 itemVoucher = newVoucher[i];
-                itemCurrencyRate = self.getCutrrencyRate(itemVoucher.payment_rate_currency_id[0]);
+                itemCurrencyRate = self.getCutrrencyRate(itemVoucher.currency_id[0]);
                 if(!itemCurrencyRate){
                     itemCurrencyRate={};
                     itemCurrencyRate.rate=1;
@@ -145,5 +148,22 @@ function monthly_expenses(widget) {
                         return _.contains(number,item.reference);
                     }));
         },
+        showCustomers: function (e) {
+            var self = this;
+            var hoy =moment().format('YYYY-MM-DD');
+            var desde =moment().format('YYYY-MM-01');
+            var hasta =moment().add(1,'months').format('YYYY-MM-01');
+            var number = _.map(self.accountInvoice,function(map){return map.number});
+
+            this.do_action({
+                name:"Gastos del Mes",
+                type: 'ir.actions.act_window',
+                res_model: "account.voucher",
+                views: [[false, 'list']],
+                target: 'new',
+                domain: [['type', '=', 'payment'],['state', '=', 'posted'],['date', '>=',desde],['date','<',hasta],['reference','=',number]],
+                context: {},
+            });
+        }
     });
 }

+ 21 - 0
static/src/js/widgets/monthly_purchases.js

@@ -10,6 +10,10 @@ function monthly_purchases(widget) {
         currencyRate :[],
         resCompany:[],
 
+        events: {
+            'click a': 'showCustomers',
+            'click h2': 'showCustomers',
+        },
         init: function (parent) {
             this._super(parent, {
                 width : 3,
@@ -150,5 +154,22 @@ function monthly_purchases(widget) {
                         return _.contains(number,item.reference);
                     }));
         },
+        showCustomers: function (e) {
+            var self = this;
+            var hoy =moment().format('YYYY-MM-DD');
+            var desde =moment().format('YYYY-MM-01');
+            var hasta =moment().add(1,'months').format('YYYY-MM-01');
+            var number = _.map(self.accountInvoice,function(map){return map.number});
+
+            this.do_action({
+                name:"Compras del Mes ",
+                type: 'ir.actions.act_window',
+                res_model: "account.voucher",
+                views: [[false, 'list']],
+                target: 'new',
+                domain: [['type', '=', 'payment'],['state', '=', 'posted'],['date', '>=',desde],['date','<',hasta],['reference','=',number]],
+                context: {},
+            });
+        }
     });
 }

+ 148 - 0
static/src/js/widgets/payments_today_counters.js

@@ -0,0 +1,148 @@
+function payments_today_counters (widget) {
+    "use strict";
+
+    var model= openerp;
+
+    widget.PaymentsTodayCountersWidget = widget.Base.extend({
+        template: 'PaymentsTodayCounters',
+        accountVoucher: [],
+        resCompany: [],
+        currencyRate: [],
+
+        events: {
+            'click a': 'showCustomers',
+            'click h2': 'showCustomers',
+        },
+        init: function (parent) {
+            this._super(parent, {
+                width : 3,
+                height: 2
+            });
+        },
+        start: function () {
+            var self = this;
+            self.fetchInitial();
+        },
+        fetchInitial: function () {
+            var self = this;
+            self.$el.find('#morosidad').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+            self.$el.find('.widget-content.widget-loading').css('display','flex');
+            self.fetchAccountVoucher().then(function (accountVoucher) {
+                return accountVoucher;
+            }).then(function (accountVoucher) {
+                self.accountVoucher = accountVoucher;
+                return self.fetchResCompany();
+            }).then(function (resCompany) {
+                self.resCompany = resCompany;
+                return self.fetchCurrency();
+            }).then(function (currencyRate) {
+                self.currencyRate = currencyRate;
+                return self.fetchVoucherCurrency();
+            });
+        },
+        // Account Voucher
+        fetchAccountVoucher: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var hoy =moment().format('YYYY-MM-DD');
+            var fields = ['id', 'amount', 'currency_id', 'payment_rate_currency_id'];
+            var domain = [['state', '=', 'posted'], ['type', '=', 'payment'], ['date', '=', hoy]];
+            var accountVoucher = new model.web.Model('account.voucher');
+
+            accountVoucher.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        //Comapnia
+        fetchResCompany: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var fields =['id','name', 'currency_id','logo'];
+            var domain =[['id', '=', 1]];
+            var resCompany = new model.web.Model('res.company');
+
+            resCompany.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Buscar Cambio de Monedas USD,PYG,ARG,BRL
+        fetchCurrency: function () {
+            var defer = $.Deferred();
+            var currency_Rate = new model.web.Model('res.currency.rate');
+            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
+            var domain = [['currency_id', '=', [166 , 20, 7, 3]]];
+
+            currency_Rate.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+        //   voucherCurrencyRate
+        fetchVoucherCurrency: function () {
+            var self = this;
+            var newVoucher=[];
+            var itemvoucher;
+            var itemCurrencyRate;
+
+            for (var i = 0; i < self.accountVoucher.length; i++) {
+                itemvoucher = self.accountVoucher[i];
+                itemCurrencyRate = self.getCutrrencyRate(itemvoucher.currency_id[0]);
+                if(!itemCurrencyRate){
+                    itemCurrencyRate={};
+                    itemCurrencyRate.rate=1;
+                }
+                newVoucher.push({   amount : itemvoucher.amount,
+                                    amount_rate : (itemvoucher.amount/itemCurrencyRate.rate)
+                                });
+            }
+            self.fetchReduceMoveLine(newVoucher)
+        },
+        getCutrrencyRate: function (currency_id) {
+            var self = this;
+            return _.filter(self.currencyRate,function (item) {
+                return item.currency_id[0] == currency_id
+            }).shift();
+        },
+        // // Reduce Move line
+        fetchReduceMoveLine: function (newVoucher) {
+            var self = this;
+            var residual =0;
+            var company = _.map(self.resCompany, function (map) {
+                return map.currency_id[1];
+            });
+            if (newVoucher.length > 0) {
+                residual = _.reduce(_.map(newVoucher, function (map) {
+                    return map.amount_rate;
+                }), function (memo, num) {
+                    return memo + num;
+                });
+            }
+
+            self.$el.find('.widget-content.widget-loading').css('display','none');
+            self.$el.find('.widget-content').find('a').text(accounting.formatNumber(residual, 2, ".", ","));
+            self.$el.find('.widget-footer').find('span').text("Monto en "+ company);
+            self.$el.find('#morosidad').unblock();
+        },
+        showCustomers: function (e) {
+            var hoy =moment().format('YYYY-MM-DD');
+
+            this.do_action({
+                name:"Cobros de Hoy",
+                type: 'ir.actions.act_window',
+                res_model: "account.voucher",
+                views: [[false, 'list']],
+                target: 'new',
+                domain: [['state', '=', 'posted'], ['type', '=', 'payment'], ['date', '=', hoy]],
+                context: {},
+            });
+        }
+    });
+}

+ 179 - 0
static/src/js/widgets/ranking_sales_partner.js

@@ -0,0 +1,179 @@
+function ranking_sales_partner (widget) {
+    "use strict";
+
+    var model= openerp;
+
+    widget.RankingSalesPartnerWidget = widget.Base.extend({
+        template: 'RankingSalesPartner',
+        data : [],
+        accountInvoice : [],
+        resPartner : [],
+        // productProduct : [],
+        // ranking:[],
+
+        events: {
+            'click canvas': 'showCustomers'
+        },
+        init: function (parent) {
+            this._super(parent, {
+                width : 6,
+                height: 4
+            });
+        },
+        start: function () {
+            var self = this;
+            self.fetchInitial();
+        },
+        fetchInitial:function(){
+            var self = this;
+            self.$el.block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+            self.$el.find('.widget-content.widget-loading').css('display','flex');
+            self.fecthInvoice().then(function (accountInvoice) {
+                return accountInvoice;
+            }).then(function (accountInvoice) {
+                self.accountInvoice = accountInvoice;
+                return self.fecthPartner(accountInvoice);
+            }).then(function (resPartner) {
+                self.resPartner = resPartner;
+                return self.fetchProductRanking();
+            });
+        },
+        // Obtener factura
+        fecthInvoice: function(){
+            var self = this;
+            var desde =moment().format('YYYY-MM-01');
+            var hasta =moment().add(1,'months').format('YYYY-MM-01');
+            var defer = $.Deferred();
+            var fields = ['id', 'invoice_line', 'date_invoice','partner_id'];
+            var domain = [['type', '=', 'out_invoice'], ['date_invoice', '>=', desde], ['date_invoice', '<', hasta], ['state', '=', ['open','paid']]];
+            var invoice = new model.web.Model('account.invoice');
+            invoice.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Partner
+        fecthPartner: function(invoice){
+            var self = this;
+            var defer = $.Deferred();
+            var partner_id = _.map(invoice,function(map){
+                return map.partner_id[0];
+            });
+            var fields =['id', 'name'];
+            var domain =[['id', '=', partner_id],['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;
+        },
+        // Obtener facturas por cada clientes
+        getAccountInvoice:function(id_partner){
+            var self = this;
+            return _.flatten(_.filter(self.accountInvoice,function (inv) {
+                return inv.partner_id[0] === id_partner;
+            }));
+        },
+        fetchProductRanking: function(){
+            var self = this;
+            var itemPartner;
+            var itemInvoice;
+            var countInvoice = 0
+            var ranking = [];
+
+            for (var i = 0; i < self.resPartner.length; i++) {
+                itemPartner = self.resPartner[i];
+                itemInvoice = self.getAccountInvoice(itemPartner.id);
+                countInvoice =_.countBy(_.map(itemInvoice,function(map){
+                                    return map.id;
+                                }),function(num){
+                                    return num ? 'even': 'odd';
+                                });
+                // console.log(countInvoice);
+                ranking.push({ id : itemPartner.id,
+                               name: itemPartner.name,
+                               countInvoice :countInvoice.even
+                           });
+            }
+            ranking.sort(function (a, b) {
+                return b.countInvoice - a.countInvoice
+            });
+            console.log(ranking);
+            self.ranking=ranking;
+
+            self.$el.unblock();
+            self.$el.find('.widget-content.widget-loading').css('display','none');
+            self.$el.find('.widget-title').find('span').text("Ranking de Clientes Activos del Mes");
+            self.fetchChart(ranking);
+        },
+        // Generar Grafico
+        fetchChart: function (ranking){
+            var self = this;
+            var label = [];
+            var body = [];
+            var item;
+            var rank = 10;
+
+            for (var i = 0; i < rank; i++) {
+                if (ranking[i]){
+                    item = ranking[i];
+                } else {
+                    item = {};
+                    item.name = "N/A";
+                    item.countInvoice = 0;
+                }
+                label.push(item.name);
+                body.push(item.countInvoice);
+            }
+            var chart = new Chart(this.$el.find(".widget-content").find('canvas'), {
+                // type: 'doughnut',
+                type: 'horizontalBar',
+                // type: '',
+                data: {
+                    labels: label,
+                    datasets: [
+                        {
+                            backgroundColor: ['#7c7bad', '#7c7bad', '#7c7bad', '#7c7bad', '#7c7bad', '#7c7bad', '#7c7bad', '#7c7bad', '#7c7bad', '#7c7bad'],
+                            data: body,
+                        }
+                    ]
+                },
+                options: {
+                    maintainAspectRatio: false,
+                    layout: {
+                        padding: 20
+                    },
+                    scales: {
+                        xAxes: [{ stacked: true }],
+                        yAxes: [{ stacked: true }],
+                    },
+                    legend: {
+                        display: false,
+                    },
+                }
+            });
+        },
+
+        showCustomers: function (e) {
+            var self = this;
+            var hoy =moment().format('YYYY-MM-DD');
+            var partner_id= _.map(self.ranking,function(map){
+                return map.id;
+            })
+            this.do_action({
+                name:"Ranking de Clientes Activos del Mes",
+                type: 'ir.actions.act_window',
+                res_model: "res.partner",
+                views: [[false, 'list']],
+                target: 'new',
+                domain: [['id', '=', partner_id]],
+                context: {},
+            });
+        }
+    });
+}

+ 25 - 1
static/src/js/widgets/ranking_sales_product.js

@@ -9,6 +9,11 @@ function ranking_sales_product (widget) {
         accountInvoice : [],
         invoiceLine : [],
         productProduct : [],
+        ranking:[],
+
+        events: {
+            'click canvas': 'showCustomers'
+        },
         init: function (parent) {
             this._super(parent, {
                 width : 6,
@@ -109,7 +114,8 @@ function ranking_sales_product (widget) {
                         lineUnik = itemLine.shift();
                         ranking.push({
                             product: lineUnik.product_id[1],
-                            qty: cat
+                            qty: cat,
+                            id: lineUnik.product_id[0]
                         });
                     }
                 }
@@ -120,6 +126,7 @@ function ranking_sales_product (widget) {
             self.$el.unblock();
             self.$el.find('.widget-content.widget-loading').css('display','none');
             self.$el.find('.widget-title').find('span').text("Ranking de Producto mas Vendido del Mes");
+            self.ranking=ranking;
             self.fetchChart(ranking);
         },
         // get line
@@ -175,6 +182,23 @@ function ranking_sales_product (widget) {
                     },
                 }
             });
+        },
+
+        showCustomers: function (e) {
+            var self = this;
+            var hoy =moment().format('YYYY-MM-DD');
+            var product_id= _.map(self.ranking,function(map){
+                return map.id;
+            })
+            this.do_action({
+                name:"Ranking de Productos más Vendidos",
+                type: 'ir.actions.act_window',
+                res_model: "product.product",
+                views: [[false, 'list']],
+                target: 'new',
+                domain: [['id', '=', product_id],['type','=', 'product']],
+                context: {},
+            });
         }
     });
 }

+ 18 - 6
static/src/js/widgets/voucher_today_counters.js

@@ -8,6 +8,11 @@ function voucher_today_counters (widget) {
         accountVoucher: [],
         resCompany: [],
         currencyRate: [],
+
+        events: {
+            'click a': 'showCustomers',
+            'click h2': 'showCustomers',
+        },
         init: function (parent) {
             this._super(parent, {
                 width : 3,
@@ -31,7 +36,6 @@ function voucher_today_counters (widget) {
                 return accountVoucher;
             }).then(function (accountVoucher) {
                 self.accountVoucher = accountVoucher;
-                console.log(accountVoucher);
                 return self.fetchResCompany();
             }).then(function (resCompany) {
                 self.resCompany = resCompany;
@@ -45,8 +49,6 @@ function voucher_today_counters (widget) {
         fetchAccountVoucher: function () {
             var self = this;
             var defer = $.Deferred();
-            // var fecha = new Date();
-            // var hoy = fecha.getFullYear() + "-" + (fecha.getMonth() + 1) + "-" + fecha.getDate();
             var hoy =moment().format('YYYY-MM-DD');
             var fields = ['id', 'amount', 'currency_id', 'payment_rate_currency_id'];
             var domain = [['state', '=', 'posted'], ['type', '=', 'receipt'], ['date', '=', hoy]];
@@ -55,7 +57,6 @@ function voucher_today_counters (widget) {
             accountVoucher.query(fields).filter(domain).all().then(function (results) {
                 defer.resolve(results);
             });
-
             return defer;
         },
         //Comapnia
@@ -69,7 +70,6 @@ function voucher_today_counters (widget) {
             resCompany.query(fields).filter(domain).all().then(function (results) {
                 defer.resolve(results);
             });
-
             return defer;
         },
         // Buscar Cambio de Monedas USD,PYG,ARG,BRL
@@ -95,7 +95,6 @@ function voucher_today_counters (widget) {
             for (var i = 0; i < self.accountVoucher.length; i++) {
                 itemvoucher = self.accountVoucher[i];
                 itemCurrencyRate = self.getCutrrencyRate(itemvoucher.currency_id[0]);
-                // itemCurrencyRate = self.getCutrrencyRate(itemvoucher.payment_rate_currency_id[0]);
                 if(!itemCurrencyRate){
                     itemCurrencyRate={};
                     itemCurrencyRate.rate=1;
@@ -132,5 +131,18 @@ function voucher_today_counters (widget) {
             self.$el.find('.widget-footer').find('span').text("Monto en "+ company);
             self.$el.find('#morosidad').unblock();
         },
+        showCustomers: function (e) {
+            var hoy =moment().format('YYYY-MM-DD');
+
+            this.do_action({
+                name:"Cobros de Hoy",
+                type: 'ir.actions.act_window',
+                res_model: "account.voucher",
+                views: [[false, 'list']],
+                target: 'new',
+                domain: [['state', '=', 'posted'], ['type', '=', 'receipt'], ['date', '=', hoy]],
+                context: {},
+            });
+        }
     });
 }

+ 23 - 0
static/src/xml/widgets/missing_product.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<template xml:space="preserve">
+    <t t-name="MissingProduct">
+        <div>
+            <div class="grid-stack-item-content dashboard">
+                <h2 class="widget-title">
+                    <i class="fa fa-list-alt" aria-hidden="true"></i>
+                    Productos sin Stock
+                </h2>
+                <div class="widget-content">
+                    <a></a>
+                </div>
+                <div class="widget-footer">
+                    <span></span>
+                </div>
+                <div class="widget-content widget-loading">
+                    <i class='fa fa-cog fa-spin fa-3x fa-fw'></i>
+                </div>
+            </div>
+        </div>
+    </t>
+</template>

+ 1 - 1
static/src/xml/widgets/monthly_expenses.xml

@@ -6,7 +6,7 @@
             <div class="grid-stack-item-content dashboard">
                 <h2 class="widget-title">
                     <i class="fa fa-money" aria-hidden="true"> </i>
-                    Gastos del Mes 
+                    Gastos del Mes
                 </h2>
                 <div class="widget-content">
                     <a></a>

+ 23 - 0
static/src/xml/widgets/payments_today_counters.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<template xml:space="preserve">
+    <t t-name="PaymentsTodayCounters">
+        <div>
+            <div class="grid-stack-item-content dashboard">
+                <h2 class="widget-title">
+                    <i class="fa fa-money" aria-hidden="true"> </i>
+                    Pagos de Hoy
+                </h2>
+                <div class="widget-content">
+                    <a></a>
+                </div>
+                <div class="widget-footer">
+                    <span></span>
+                </div>
+                <div class="widget-content widget-loading">
+                    <i class='fa fa-cog fa-spin fa-3x fa-fw'></i>
+                </div>
+            </div>
+        </div>
+    </t>
+</template>

+ 18 - 0
static/src/xml/widgets/ranking_sales_partner.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<template xml:space="preserve">
+    <t t-name="RankingSalesPartner">
+        <t t-call="WidgetBaseTmpl">
+            <h2  class="widget-title">
+                <i class="fa fa-bar-chart" aria-hidden="true"></i>
+                <span>Ranking de Clientes Activos del Mes</span>
+            </h2>
+            <div class="widget-content">
+                <canvas></canvas>
+            </div>
+            <div class="widget-content widget-loading">
+                <i class='fa fa-cog fa-spin fa-3x fa-fw'></i>
+            </div>
+        </t>
+    </t>
+</template>

+ 1 - 1
static/src/xml/widgets/voucher_today_counters.xml

@@ -6,7 +6,7 @@
             <div class="grid-stack-item-content dashboard">
                 <h2 class="widget-title">
                     <i class="fa fa-money" aria-hidden="true"> </i>
-                    Cobros de hoy
+                    Cobros de Hoy
                 </h2>
                 <div class="widget-content">
                     <a></a>

+ 4 - 0
templates.xml

@@ -20,6 +20,10 @@
                 <script type="text/javascript" src="/eiru_dashboard/static/src/js/widgets/invoice_today_counters.js" />
                 <script type="text/javascript" src="/eiru_dashboard/static/src/js/widgets/monthly_expenses.js" />
                 <script type="text/javascript" src="/eiru_dashboard/static/src/js/widgets/monthly_purchases.js" />
+                <script type="text/javascript" src="/eiru_dashboard/static/src/js/widgets/missing_product.js" />
+                <script type="text/javascript" src="/eiru_dashboard/static/src/js/widgets/payments_today_counters.js" />
+                <script type="text/javascript" src="/eiru_dashboard/static/src/js/widgets/ranking_sales_partner.js" />
+
                 <!-- <script type="text/javascript" src="/eiru_dashboard/static/src/js/widgets/customer_counter.js" />
                 <script type="text/javascript" src="/eiru_dashboard/static/src/js/widgets/sales_in_the_week.js" />
                 <script type="text/javascript" src="/eiru_dashboard/static/src/js/widgets/top_sales_product.js" />