|
@@ -104,8 +104,8 @@ function widget_sale(widget) {
|
|
|
var self = this;
|
|
|
var defer = $.Deferred();
|
|
|
var store_ids = self.ResUser[0].store_id[0];
|
|
|
- var fields = ['id','name','store_ids'];
|
|
|
- var domain = [['active','=',true],['type','=','sale'],['store_ids','in',store_ids]];
|
|
|
+ var fields = ['id','name','store_ids','type'];
|
|
|
+ var domain = [['active','=',true],['type','in',['sale','sale_refund']],['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);
|
|
@@ -142,8 +142,8 @@ function widget_sale(widget) {
|
|
|
return item.id;
|
|
|
}));
|
|
|
var date = moment().format('YYYY-01-01');
|
|
|
- var fields = ['id','name','amount_total','date_invoice','currency_id'];
|
|
|
- var domain = [['state', 'not in', ['draft','cancel']],['type','=','out_invoice'],['journal_id','in',journal_ids],['date_invoice','>=',date]];
|
|
|
+ var fields = ['id','name','amount_total','date_invoice','currency_id','journal_id'];
|
|
|
+ var domain = [['state', 'not in', ['draft','cancel']],['type','in',['out_invoice','out_refund']],['journal_id','in',journal_ids],['date_invoice','>=',date]];
|
|
|
var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
AccountInvoice.query(fields).filter(domain).all().then(function(results) {
|
|
|
defer.resolve(results);
|
|
@@ -249,43 +249,76 @@ function widget_sale(widget) {
|
|
|
ACCOUNT INVOICE
|
|
|
===================*/
|
|
|
|
|
|
- getTodayAccountInvoice:function() {
|
|
|
+ getTodayAccountInvoice:function(type) {
|
|
|
var self = this;
|
|
|
var date = moment().format('YYYY-MM-DD');
|
|
|
- return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
- return moment(inv.date_invoice).format('YYYY-MM-DD') === date;
|
|
|
- }));
|
|
|
+ var journals = _.filter(self.AccountJournal,function (inv) {
|
|
|
+ return inv.type == type;
|
|
|
+ });
|
|
|
+ if(journals.length > 0){
|
|
|
+ var journal_ids = _.flatten(_.map(journals, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM-DD') === date & _.contains(journal_ids, inv.journal_id[0]);
|
|
|
+ }));
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
- getThisWeekAccountInvoice:function() {
|
|
|
+ getThisWeekAccountInvoice:function(type) {
|
|
|
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).format('YYYY')=== moment().format('YYYY');
|
|
|
- }));
|
|
|
+ var journals = _.filter(self.AccountJournal,function (inv) {
|
|
|
+ return inv.type == type;
|
|
|
+ });
|
|
|
+ if(journals.length > 0){
|
|
|
+ var journal_ids = _.flatten(_.map(journals, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
+ return moment(inv.date_invoice).week() === week & moment(inv.date_invoice).format('YYYY')=== moment().format('YYYY') & _.contains(journal_ids, inv.journal_id[0]);
|
|
|
+ }));
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
- getThisMonthAccountInvoice:function() {
|
|
|
+ getThisMonthAccountInvoice:function(type) {
|
|
|
var self = this;
|
|
|
- return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
- return moment(inv.date_invoice).format('YYYY-MM')=== moment().format('YYYY-MM');
|
|
|
- }));
|
|
|
+ var journals = _.filter(self.AccountJournal,function (inv) {
|
|
|
+ return inv.type == type;
|
|
|
+ });
|
|
|
+ if(journals.length > 0){
|
|
|
+ var journal_ids = _.flatten(_.map(journals, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM') === moment().format('YYYY-MM') & _.contains(journal_ids, inv.journal_id[0]);
|
|
|
+ }));
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/*============================
|
|
|
ACCOUNT INVOICE BY MONTH
|
|
|
============================*/
|
|
|
|
|
|
- getMonthAccountInvoice:function(mes) {
|
|
|
+ getMonthAccountInvoice:function(mes, type) {
|
|
|
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;
|
|
|
- }));
|
|
|
+ var journals = _.filter(self.AccountJournal,function (inv) {
|
|
|
+ return inv.type == type;
|
|
|
+ });
|
|
|
+ if(journals.length > 0){
|
|
|
+ var journal_ids = _.flatten(_.map(journals, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM') === fecha & _.contains(journal_ids, inv.journal_id[0]);
|
|
|
+ }));
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/*
|
|
@@ -297,9 +330,11 @@ function widget_sale(widget) {
|
|
|
var amount = 0;
|
|
|
var pos_amount = 0;
|
|
|
var invoice_amount = 0;
|
|
|
+ var invoice_amount_refund = 0;
|
|
|
var data = [];
|
|
|
var pos_order = self.getTodayPosOrder();
|
|
|
- var account_invoice = self.getTodayAccountInvoice();
|
|
|
+ var account_invoice = self.getThisWeekAccountInvoice('sale');
|
|
|
+ var account_invoice_refund = self.getThisWeekAccountInvoice('sale_refund');
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
if(pos_order.length > 0){
|
|
|
pos_amount = _.reduce(_.map(pos_order, function (map) {
|
|
@@ -309,6 +344,7 @@ function widget_sale(widget) {
|
|
|
});
|
|
|
}
|
|
|
if(account_invoice.length > 0){
|
|
|
+ data = [];
|
|
|
_.each(account_invoice, function (item) {
|
|
|
var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
data.push({
|
|
@@ -321,7 +357,21 @@ function widget_sale(widget) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- amount = pos_amount + invoice_amount;
|
|
|
+ if(account_invoice_refund.length > 0){
|
|
|
+ data = [];
|
|
|
+ _.each(account_invoice_refund, function (item) {
|
|
|
+ var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
+ data.push({
|
|
|
+ amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ invoice_amount_refund = _.reduce(_.map(data, function (map) {
|
|
|
+ return map.amount;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ amount = pos_amount + invoice_amount - invoice_amount_refund;
|
|
|
self.today = amount;
|
|
|
},
|
|
|
|
|
@@ -334,9 +384,11 @@ function widget_sale(widget) {
|
|
|
var amount = 0;
|
|
|
var pos_amount = 0;
|
|
|
var invoice_amount = 0;
|
|
|
+ var invoice_amount_refund = 0;
|
|
|
var data = [];
|
|
|
var pos_order = self.getThisWeekPosOrder();
|
|
|
- var account_invoice = self.getThisWeekAccountInvoice();
|
|
|
+ var account_invoice = self.getThisWeekAccountInvoice('sale');
|
|
|
+ var account_invoice_refund = self.getThisWeekAccountInvoice('sale_refund');
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
if(pos_order.length > 0){
|
|
|
pos_amount = _.reduce(_.map(pos_order, function (map) {
|
|
@@ -346,6 +398,7 @@ function widget_sale(widget) {
|
|
|
});
|
|
|
}
|
|
|
if(account_invoice.length > 0){
|
|
|
+ data = [];
|
|
|
_.each(account_invoice, function (item) {
|
|
|
var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
data.push({
|
|
@@ -358,7 +411,21 @@ function widget_sale(widget) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- amount = pos_amount + invoice_amount;
|
|
|
+ if(account_invoice_refund.length > 0){
|
|
|
+ data = [];
|
|
|
+ _.each(account_invoice_refund, function (item) {
|
|
|
+ var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
+ data.push({
|
|
|
+ amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ invoice_amount_refund = _.reduce(_.map(data, function (map) {
|
|
|
+ return map.amount;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ amount = pos_amount + invoice_amount - invoice_amount_refund;
|
|
|
self.week = amount;
|
|
|
},
|
|
|
|
|
@@ -375,10 +442,12 @@ function widget_sale(widget) {
|
|
|
}
|
|
|
var pos_amount = 0;
|
|
|
var invoice_amount = 0;
|
|
|
+ var invoice_amount_refund = 0;
|
|
|
var amount = 0;
|
|
|
var data = [];
|
|
|
var pos_order = self.getThisMonthPosOrder();
|
|
|
- var account_invoice = self.getThisMonthAccountInvoice();
|
|
|
+ var account_invoice = self.getThisMonthAccountInvoice('sale');
|
|
|
+ var account_invoice_refund = self.getThisMonthAccountInvoice('sale_refund');
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
if(pos_order.length > 0){
|
|
|
pos_amount = _.reduce(_.map(pos_order, function (map) {
|
|
@@ -389,6 +458,7 @@ function widget_sale(widget) {
|
|
|
}
|
|
|
|
|
|
if(account_invoice.length > 0){
|
|
|
+ data = [];
|
|
|
_.each(account_invoice, function (item) {
|
|
|
var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
data.push({
|
|
@@ -402,7 +472,22 @@ function widget_sale(widget) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- amount = pos_amount + invoice_amount;
|
|
|
+ if(account_invoice_refund.length > 0){
|
|
|
+ data = [];
|
|
|
+ _.each(account_invoice_refund, function (item) {
|
|
|
+ var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
+ data.push({
|
|
|
+ amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ invoice_amount_refund = _.reduce(_.map(data, function (map) {
|
|
|
+ return map.amount;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ amount = pos_amount + invoice_amount - invoice_amount_refund;
|
|
|
self.month = amount;
|
|
|
|
|
|
if(self.objective > 0){
|
|
@@ -429,26 +514,34 @@ function widget_sale(widget) {
|
|
|
var self = this;
|
|
|
var order;
|
|
|
var invoice;
|
|
|
+ var invoice_refund;
|
|
|
var title = ['Ene', 'Feb', 'Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'];
|
|
|
var data = [];
|
|
|
+ var array = [];
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
for (var i = 1; i <= 12; i++) {
|
|
|
- var array = [];
|
|
|
+
|
|
|
order = self.getMonthPosOrder(i);
|
|
|
- invoice = self.getMonthAccountInvoice(i);
|
|
|
+ invoice = self.getMonthAccountInvoice(i, 'sale');
|
|
|
+ invoice_refund = self.getMonthAccountInvoice(i, 'sale_refund');
|
|
|
+
|
|
|
var order_total = _.reduce(_.map(order,function(item) {
|
|
|
return item.amount_total;
|
|
|
}),function(memo, num) {
|
|
|
return memo + num;
|
|
|
},0);
|
|
|
-
|
|
|
+
|
|
|
+ /*
|
|
|
+ SALE INVOICE
|
|
|
+ */
|
|
|
+
|
|
|
+ array = [];
|
|
|
_.each(invoice, function (item) {
|
|
|
var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
array.push({
|
|
|
amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
})
|
|
|
});
|
|
|
-
|
|
|
var invoice_total = 0;
|
|
|
if(array.length > 0){
|
|
|
invoice_total = _.reduce(_.map(array, function (map) {
|
|
@@ -457,7 +550,28 @@ function widget_sale(widget) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- var total = order_total + invoice_total;
|
|
|
+
|
|
|
+ /*
|
|
|
+ SALE REFUND
|
|
|
+ */
|
|
|
+
|
|
|
+ array = [];
|
|
|
+ _.each(invoice_refund, function (item) {
|
|
|
+ var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
+ array.push({
|
|
|
+ amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ var invoice_total_refund = 0;
|
|
|
+ if(array.length > 0){
|
|
|
+ invoice_total_refund = _.reduce(_.map(array, function (map) {
|
|
|
+ return map.amount;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ var total = order_total + invoice_total - invoice_total_refund;
|
|
|
data.push(total);
|
|
|
}
|
|
|
self.data = data;
|