Browse Source

[ADD] filtros en el grafico de ventas por sucursal

Rodney Elpidio Enciso Arias 6 năm trước cách đây
mục cha
commit
d27aec60b1

+ 104 - 1
static/src/js/widgets/chart_sale_by_store.js

@@ -7,6 +7,9 @@ function chart_sale_by_store (widget) {
         template: 'ChartSaleByStore',
         data: [],
         events: {
+            'click .month': 'showMonth',
+            'click .week': 'showWeek',
+            'click .days': 'showToday',
         },
 
         init: function (parent) {
@@ -110,6 +113,28 @@ function chart_sale_by_store (widget) {
             }));
         },
 
+        getWeekPosOrder:function(id) {
+            var self = this;
+            var week = moment().week();
+            var journal_id  = _.filter(self.AccountJournal,function (inv) {
+                return inv.store_ids[0] === id;
+            });
+            return _.flatten(_.filter(self.PosOrder,function (inv) {
+                return moment(inv.date_order).week() === week & inv.sale_journal[0] == journal_id[0].id;
+            }));
+        },
+
+        getTodayPosOrder:function(id) {
+            var self = this;
+            var today = moment().format('YYYY-MM-DD');
+            var journal_id  = _.filter(self.AccountJournal,function (inv) {
+                return inv.store_ids[0] === id;
+            });
+            return _.flatten(_.filter(self.PosOrder,function (inv) {
+                return moment(inv.date_order).format('YYYY-MM-DD') === today & inv.sale_journal[0] == journal_id[0].id;
+            }));
+        },
+
         getMonthAccountInvoice:function(id) {
             var self = this;
             var journal_id  = _.filter(self.AccountJournal,function (inv) {
@@ -119,6 +144,28 @@ function chart_sale_by_store (widget) {
                 return moment(inv.date_invoice).format('YYYY-MM') === moment().format('YYYY-MM') & inv.journal_id[0] == journal_id[0].id;
             }));
         },
+
+        getWeekAccountInvoice:function(id) {
+            var self = this;
+            var week = moment().week();
+            var journal_id  = _.filter(self.AccountJournal,function (inv) {
+                return inv.store_ids[0] === id;
+            });
+            return _.flatten(_.filter(self.AccountInvoice,function (inv) {
+                return moment(inv.date_invoice).week() === week & inv.journal_id[0] == journal_id[0].id;
+            }));
+        },
+
+        getTodayAccountInvoice:function(id) {
+            var self = this;
+            var today = moment().format('YYYY-MM-DD');
+            var journal_id  = _.filter(self.AccountJournal,function (inv) {
+                return inv.store_ids[0] === id;
+            });
+            return _.flatten(_.filter(self.AccountInvoice,function (inv) {
+                return moment(inv.date_invoice).format('YYYY-MM-DD') === today & inv.journal_id[0] == journal_id[0].id;
+            }));
+        },
   
         showMonth: function() {
             var self = this;
@@ -148,6 +195,62 @@ function chart_sale_by_store (widget) {
             self.fetchChart(data,title);
         },
 
+        showWeek: function (){
+            var self = this;
+            var order;
+            var invoice;
+            var title = [];
+            var data = [];            
+            _.each(self.ResStore, function(item){
+                title.push(item.name);
+                order = self.getWeekPosOrder(item.id);
+                invoice = self.getWeekAccountInvoice(item.id);
+                var order_total = _.reduce(_.map(order,function(item) {
+                    return item.amount_total;
+                }),function(memo, num) {
+                    return memo + num;
+                },0);
+                var invoice_total = _.reduce(_.map(invoice,function(item) {
+                    return item.amount_total;
+                }),function(memo, num) {
+                    return memo + num;
+                },0);
+                var total = order_total + invoice_total;
+                data.push(total); 
+            });
+            self.$el.unblock();
+            self.$el.find('.widget-content.widget-loading').css('display','none');
+            self.fetchChart(data,title);
+        },
+
+        showToday: function (){
+            var self = this;
+            var order;
+            var invoice;
+            var title = [];
+            var data = [];            
+            _.each(self.ResStore, function(item){
+                title.push(item.name);
+                order = self.getTodayPosOrder(item.id);
+                invoice = self.getTodayAccountInvoice(item.id);
+                var order_total = _.reduce(_.map(order,function(item) {
+                    return item.amount_total;
+                }),function(memo, num) {
+                    return memo + num;
+                },0);
+                var invoice_total = _.reduce(_.map(invoice,function(item) {
+                    return item.amount_total;
+                }),function(memo, num) {
+                    return memo + num;
+                },0);
+                var total = order_total + invoice_total;
+                data.push(total); 
+            });
+            self.$el.unblock();
+            self.$el.find('.widget-content.widget-loading').css('display','none');
+            self.fetchChart(data,title);
+        },
+
         fetchChart: function (data,title) {
             var self = this;
             var label = title;
@@ -177,7 +280,7 @@ function chart_sale_by_store (widget) {
                             backgroundColor: '#e3f2fd',
                             borderColor: '#64b5f6',
                             borderWidth: 2,
-                            fill: true,
+                            fill: false,
                         }
                     ]
                 },

+ 1 - 2
static/src/js/widgets/widget_account_receivable.js

@@ -266,7 +266,6 @@ function widget_account_receivable(widget) {
 
             var moneda = self.ResCurrency.shift();
             var newmoveLine = self.data;
-            console.log(newmoveLine);
             var titleData = [
                 {
                     title: "Cuentas a Cobrar"
@@ -277,7 +276,7 @@ function widget_account_receivable(widget) {
                     title: "Cliente"
                 },
                 {
-                    title: "Numero de Factura"
+                    title: "Numero"
                 },
                 {
                     title: "Vencimiento"

+ 1 - 1
static/src/js/widgets/widget_account_to_pay.js

@@ -272,7 +272,7 @@ function widget_account_to_pay(widget) {
                     title: "Proveedor"
                 },
                 {
-                    title: "Numero de Factura"
+                    title: "Numero"
                 },
                 {
                     title: "Vencimiento"

+ 16 - 1
static/src/xml/widgets/chart_sale_by_store.xml

@@ -1,5 +1,4 @@
 <?xml version="1.0" encoding="UTF-8"?>
-
 <template xml:space="preserve">
     <t t-name="ChartSaleByStore">
         <t t-call="WidgetReportingBaseTemplate"> 
@@ -9,6 +8,22 @@
                         <i class="fa fa-bar-chart" aria-hidden="true"></i>
                         <span>Ventas por Sucursal</span> 
                     </div>
+                    <div class="col-xs-6">
+                        <div class="col-xs-6 col-xs-offset-10">
+                            <div class="btn-group btn-group-xs">
+                                <a type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+                                <span class="caret"></span>
+                                <span class="sr-only">Toggle Dropdown</span>
+                                </a>
+                                <ul class="dropdown-menu dropdown-menu-right">
+                                    <li><a class="days">Hoy</a></li>
+                                    <li><a class="week">Esta semana</a></li>
+                                    <li role="separator" class="divider"></li>
+                                    <li><a class="month">Meses</a></li>
+                                </ul>
+                            </div>
+                        </div>
+                    </div>
                 </div>
             </h2>
             <div class="widget-content">