|
@@ -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,
|
|
|
}
|
|
|
]
|
|
|
},
|