|
@@ -35,19 +35,69 @@ function chart_pos_order (widget) {
|
|
|
|
|
|
self.$el.find('.widget-content.widget-loading').css('display','flex');
|
|
self.$el.find('.widget-content.widget-loading').css('display','flex');
|
|
|
|
|
|
- self.fecthPosOrder().then(function (PosOrder) {
|
|
|
|
- return PosOrder;
|
|
|
|
|
|
+ self.fetchCurrentUser().then(function (CurrentUser) {
|
|
|
|
+ return CurrentUser;
|
|
|
|
+ }).then(function (CurrentUser) {
|
|
|
|
+ self.CurrentUser = CurrentUser;
|
|
|
|
+ return self.fetchResUser(CurrentUser);
|
|
|
|
+ }).then(function (ResUser) {
|
|
|
|
+ self.ResUser = ResUser;
|
|
|
|
+ return self.fetchAccountJournal();
|
|
|
|
+ }).then(function (AccountJournal) {
|
|
|
|
+ self.AccountJournal = AccountJournal;
|
|
|
|
+ return self.fetchPosOrder();
|
|
}).then(function (PosOrder) {
|
|
}).then(function (PosOrder) {
|
|
self.PosOrder = PosOrder;
|
|
self.PosOrder = PosOrder;
|
|
|
|
+ return self.fetchAccountInvoice();
|
|
|
|
+ }).then(function (AccountInvoice) {
|
|
|
|
+ self.AccountInvoice = AccountInvoice;
|
|
return self.showMonth();
|
|
return self.showMonth();
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+
|
|
|
|
+ fetchCurrentUser: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var ResUser = new model.web.Model('res.users');
|
|
|
|
+ return ResUser.call('get_user', {
|
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchResUser: function(id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var fields = ['id','name','store_id'];
|
|
|
|
+ var domain = [['id','=',id]];
|
|
|
|
+ var ResUser = new model.web.Model('res.users');
|
|
|
|
+ ResUser.query(fields).filter(domain).all().then(function (results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchAccountJournal: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var store_ids = self.ResUser[0].store_id[0];
|
|
|
|
+ var fields = ['id', 'name', 'store_ids'];
|
|
|
|
+ var domain = [['type','=','sale'],['store_ids','in',store_ids]];
|
|
|
|
+ var AccountJournal = new model.web.Model('account.journal');
|
|
|
|
+ AccountJournal.query(fields).filter(domain).all().then(function(results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
|
|
- fecthPosOrder: function() {
|
|
|
|
|
|
+ fetchPosOrder: function() {
|
|
var self = this;
|
|
var self = this;
|
|
var defer = $.Deferred();
|
|
var defer = $.Deferred();
|
|
|
|
+ var journal_ids = _.flatten(_.map(this.AccountJournal, function (item) {
|
|
|
|
+ return item.id;
|
|
|
|
+ }));
|
|
var fields = ['id','date_order','amount_total'];
|
|
var fields = ['id','date_order','amount_total'];
|
|
- var domain = [['state','not in',['draft','cancel']]];
|
|
|
|
|
|
+ var domain = [['state','not in',['draft','cancel']],['sale_journal','in',journal_ids] ];
|
|
var PosOrder = new model.web.Model('pos.order');
|
|
var PosOrder = new model.web.Model('pos.order');
|
|
PosOrder.query(fields).filter(domain).all().then(function (results) {
|
|
PosOrder.query(fields).filter(domain).all().then(function (results) {
|
|
defer.resolve(results);
|
|
defer.resolve(results);
|
|
@@ -56,6 +106,22 @@ function chart_pos_order (widget) {
|
|
return defer;
|
|
return defer;
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ fetchAccountInvoice: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var journal_ids = _.flatten(_.map(this.AccountJournal, function (item) {
|
|
|
|
+ return item.id;
|
|
|
|
+ }));
|
|
|
|
+ var fields = ['id', 'name', 'date_invoice', 'amount_total'];
|
|
|
|
+ var domain = [['state', 'not in', ['draft','cancel']],['type','=','out_invoice'],['journal_id','in',journal_ids]];
|
|
|
|
+ var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
|
+ AccountInvoice.query(fields).filter(domain).all().then(function(results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
getMonthPosOrder:function(mes) {
|
|
getMonthPosOrder:function(mes) {
|
|
var self = this;
|
|
var self = this;
|
|
if (mes < 10){
|
|
if (mes < 10){
|
|
@@ -83,20 +149,55 @@ function chart_pos_order (widget) {
|
|
return moment(inv.date_order).format('YYYY-MM-DD') === date;
|
|
return moment(inv.date_order).format('YYYY-MM-DD') === date;
|
|
}));
|
|
}));
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ getMonthAccountInvoice:function(mes) {
|
|
|
|
+ var self = this;
|
|
|
|
+ if (mes < 10){
|
|
|
|
+ var fecha = moment().format('YYYY')+'-'+'0'+mes;
|
|
|
|
+ }else{
|
|
|
|
+ var fecha = moment().format('YYYY')+'-'+mes;
|
|
|
|
+ }
|
|
|
|
+ return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM') === fecha;
|
|
|
|
+ }));
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getWeekAccountInvoice:function(day) {
|
|
|
|
+ var self = this;
|
|
|
|
+ var week = moment().week();
|
|
|
|
+ return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
|
+ return moment(inv.date_invoice).week() === week & moment(inv.date_invoice).isoWeekday() === day;
|
|
|
|
+ }));
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getDaysAccountInvoice:function(day) {
|
|
|
|
+ var self = this;
|
|
|
|
+ var date = moment().subtract(day, 'days').format('YYYY-MM-DD');
|
|
|
|
+ return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM-DD') === date;
|
|
|
|
+ }));
|
|
|
|
+ },
|
|
|
|
+
|
|
showMonth: function() {
|
|
showMonth: function() {
|
|
var self = this;
|
|
var self = this;
|
|
var order;
|
|
var order;
|
|
|
|
+ var invoice;
|
|
var title = ['Enero', 'Febrero', 'Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
|
|
var title = ['Enero', 'Febrero', 'Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
|
|
var data = [];
|
|
var data = [];
|
|
-
|
|
|
|
for (var i = 1; i <= 12; i++) {
|
|
for (var i = 1; i <= 12; i++) {
|
|
order = self.getMonthPosOrder(i);
|
|
order = self.getMonthPosOrder(i);
|
|
- var total = _.reduce(_.map(order,function(item) {
|
|
|
|
|
|
+ invoice = self.getMonthAccountInvoice(i);
|
|
|
|
+ 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;
|
|
return item.amount_total;
|
|
}),function(memo, num) {
|
|
}),function(memo, num) {
|
|
return memo + num;
|
|
return memo + num;
|
|
},0);
|
|
},0);
|
|
|
|
+ var total = order_total + invoice_total;
|
|
data.push(total);
|
|
data.push(total);
|
|
}
|
|
}
|
|
self.$el.unblock();
|
|
self.$el.unblock();
|
|
@@ -107,15 +208,23 @@ function chart_pos_order (widget) {
|
|
showWeek: function (){
|
|
showWeek: function (){
|
|
var self = this;
|
|
var self = this;
|
|
var order;
|
|
var order;
|
|
|
|
+ var invoice;
|
|
var title = ['Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo'];
|
|
var title = ['Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo'];
|
|
var data = [];
|
|
var data = [];
|
|
for (var i = 1; i <= 7; i++) {
|
|
for (var i = 1; i <= 7; i++) {
|
|
order = self.getWeekPosOrder(i);
|
|
order = self.getWeekPosOrder(i);
|
|
- var total = _.reduce(_.map(order,function(item) {
|
|
|
|
|
|
+ order = self.getWeekAccountInvoice(i);
|
|
|
|
+ var order_total = _.reduce(_.map(order,function(item) {
|
|
return item.amount_total;
|
|
return item.amount_total;
|
|
}),function(memo, num) {
|
|
}),function(memo, num) {
|
|
return memo + num;
|
|
return memo + num;
|
|
},0);
|
|
},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);
|
|
data.push(total);
|
|
}
|
|
}
|
|
self.$el.unblock();
|
|
self.$el.unblock();
|
|
@@ -126,15 +235,23 @@ function chart_pos_order (widget) {
|
|
showDays: function() {
|
|
showDays: function() {
|
|
var self = this;
|
|
var self = this;
|
|
var order;
|
|
var order;
|
|
|
|
+ var invoice;
|
|
var title = [];
|
|
var title = [];
|
|
var data = [];
|
|
var data = [];
|
|
for (var i = 15; i >= 0; i--) {
|
|
for (var i = 15; i >= 0; i--) {
|
|
order = self.getDaysPosOrder(i);
|
|
order = self.getDaysPosOrder(i);
|
|
- var total = _.reduce(_.map(order,function(item) {
|
|
|
|
|
|
+ invoice = self.getDaysAccountInvoice(i);
|
|
|
|
+ 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;
|
|
return item.amount_total;
|
|
}),function(memo, num) {
|
|
}),function(memo, num) {
|
|
return memo + num;
|
|
return memo + num;
|
|
},0);
|
|
},0);
|
|
|
|
+ var total = order_total + invoice_total;
|
|
data.push(total);
|
|
data.push(total);
|
|
title.push(moment().subtract(i, 'days').format('DD / MM'));
|
|
title.push(moment().subtract(i, 'days').format('DD / MM'));
|
|
}
|
|
}
|