|
@@ -60,9 +60,9 @@ function chart_sale_by_store (widget) {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- /*
|
|
|
+ /*==============
|
|
|
IR MODULES
|
|
|
- */
|
|
|
+ ==============*/
|
|
|
|
|
|
fecthIrModuleModule: function(){
|
|
|
var self = this;
|
|
@@ -79,8 +79,8 @@ function chart_sale_by_store (widget) {
|
|
|
fetchAccountJournal: function() {
|
|
|
var self = this;
|
|
|
var defer = $.Deferred();
|
|
|
- var fields = ['id', 'name', 'store_ids'];
|
|
|
- var domain = [['type','=','sale']];
|
|
|
+ var fields = ['id', 'name', 'store_ids','type'];
|
|
|
+ var domain = [['type','=',['sale','sale_refund']]];
|
|
|
var AccountJournal = new model.web.Model('account.journal');
|
|
|
AccountJournal.query(fields).filter(domain).all().then(function(results) {
|
|
|
defer.resolve(results);
|
|
@@ -113,8 +113,8 @@ function chart_sale_by_store (widget) {
|
|
|
var defer = $.Deferred();
|
|
|
var desde = moment().format('YYYY-MM-01');
|
|
|
var hasta = moment().add(1,'months').format('YYYY-MM-01');
|
|
|
- var fields = ['id', 'name', 'date_invoice', 'amount_total','journal_id','currency_id'];
|
|
|
- var domain = [['date_invoice','>=',desde], ['date_invoice','<',hasta],['state', 'not in', ['draft','cancel']],['type','=','out_invoice']];
|
|
|
+ var fields = ['id', 'name', 'date_invoice', 'amount_total','journal_id','currency_id','type'];
|
|
|
+ var domain = [['date_invoice','>=',desde], ['date_invoice','<',hasta],['state', 'not in', ['draft','cancel']],['type','=',['out_invoice','out_refund']]];
|
|
|
var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
AccountInvoice.query(fields).filter(domain).all().then(function(results) {
|
|
|
defer.resolve(results);
|
|
@@ -224,10 +224,10 @@ function chart_sale_by_store (widget) {
|
|
|
ACCOUNT INVOICE
|
|
|
===============*/
|
|
|
|
|
|
- getMonthAccountInvoice:function(id) {
|
|
|
+ getMonthAccountInvoice:function(id,type) {
|
|
|
var self = this;
|
|
|
var journals = _.filter(self.AccountJournal,function (inv) {
|
|
|
- return inv.store_ids[0] === id;
|
|
|
+ return inv.store_ids[0] === id & inv.type == type;
|
|
|
});
|
|
|
if(journals.length > 0){
|
|
|
var journal_ids = _.flatten(_.map(journals, function (item) {
|
|
@@ -236,15 +236,16 @@ function chart_sale_by_store (widget) {
|
|
|
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]);
|
|
|
}));
|
|
|
+ }else{
|
|
|
+ return [];
|
|
|
}
|
|
|
-
|
|
|
},
|
|
|
|
|
|
- getWeekAccountInvoice:function(id) {
|
|
|
+ getWeekAccountInvoice:function(id,type) {
|
|
|
var self = this;
|
|
|
var week = moment().week();
|
|
|
var journals = _.filter(self.AccountJournal,function (inv) {
|
|
|
- return inv.store_ids[0] === id;
|
|
|
+ return inv.store_ids[0] === id & inv.type == type;
|
|
|
});
|
|
|
if(journals.length > 0){
|
|
|
var journal_ids = _.flatten(_.map(journals, function (item) {
|
|
@@ -253,14 +254,16 @@ function chart_sale_by_store (widget) {
|
|
|
return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
return moment(inv.date_invoice).week() === week & _.contains(journal_ids, inv.journal_id[0]);
|
|
|
}));
|
|
|
+ }else{
|
|
|
+ return [];
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- getTodayAccountInvoice:function(id) {
|
|
|
+ getTodayAccountInvoice:function(id,type) {
|
|
|
var self = this;
|
|
|
var today = moment().format('YYYY-MM-DD');
|
|
|
var journals = _.filter(self.AccountJournal,function (inv) {
|
|
|
- return inv.store_ids[0] === id;
|
|
|
+ return inv.store_ids[0] === id & inv.type == type;
|
|
|
});
|
|
|
if(journals.length > 0){
|
|
|
var journal_ids = _.flatten(_.map(journals, function (item) {
|
|
@@ -269,41 +272,75 @@ function chart_sale_by_store (widget) {
|
|
|
return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
return moment(inv.date_invoice).format('YYYY-MM-DD') === today & _.contains(journal_ids, inv.journal_id[0])
|
|
|
}));
|
|
|
+ }else{
|
|
|
+ return [];
|
|
|
}
|
|
|
},
|
|
|
|
|
|
showMonth: function() {
|
|
|
var self = this;
|
|
|
var order;
|
|
|
- var invoice;
|
|
|
+ var sale_invoice;
|
|
|
+ var sale_invoice_refund;
|
|
|
var title = [];
|
|
|
var data = [];
|
|
|
+ var array = [];
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
- _.each(self.ResStore, function(item){
|
|
|
- var array = [];
|
|
|
+ _.each(self.ResStore, function(item){
|
|
|
title.push(item.name);
|
|
|
order = self.getMonthPosOrder(item.id);
|
|
|
- invoice = self.getMonthAccountInvoice(item.id);
|
|
|
+ sale_invoice = self.getMonthAccountInvoice(item.id,'sale');
|
|
|
+ sale_invoice_refund = self.getMonthAccountInvoice(item.id,'sale_refund');
|
|
|
+
|
|
|
var order_total = _.reduce(_.map(order,function(item) {
|
|
|
return item.amount_total;
|
|
|
}),function(memo, num) {
|
|
|
return memo + num;
|
|
|
},0);
|
|
|
- _.each(invoice, function (item) {
|
|
|
+
|
|
|
+ /*================
|
|
|
+ SALE INVOICE
|
|
|
+ ================*/
|
|
|
+
|
|
|
+ array = [];
|
|
|
+ _.each(sale_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;
|
|
|
+ var sale_invoice_total = 0;
|
|
|
if(array.length > 0){
|
|
|
- invoice_total = _.reduce(_.map(array, function (map) {
|
|
|
+ sale_invoice_total = _.reduce(_.map(array, function (map) {
|
|
|
return map.amount;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- var total = order_total + invoice_total;
|
|
|
+
|
|
|
+ /*=======================
|
|
|
+ SALE INVOICE REFUND
|
|
|
+ =======================*/
|
|
|
+
|
|
|
+ array = [];
|
|
|
+ _.each(sale_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 sale_invoice_refund_total = 0;
|
|
|
+ if(array.length > 0){
|
|
|
+ sale_invoice_refund_total = _.reduce(_.map(array, function (map) {
|
|
|
+ return map.amount;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var total = (order_total + sale_invoice_total) - sale_invoice_refund_total;
|
|
|
+
|
|
|
data.push(total);
|
|
|
});
|
|
|
self.fetchChart(data,title,CurrencyBase);
|
|
@@ -312,7 +349,8 @@ function chart_sale_by_store (widget) {
|
|
|
showWeek: function () {
|
|
|
var self = this;
|
|
|
var order;
|
|
|
- var invoice;
|
|
|
+ var sale_invoice;
|
|
|
+ var sale_invoice_refund;
|
|
|
var title = [];
|
|
|
var data = [];
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
@@ -320,27 +358,56 @@ function chart_sale_by_store (widget) {
|
|
|
var array = [];
|
|
|
title.push(item.name);
|
|
|
order = self.getWeekPosOrder(item.id);
|
|
|
- invoice = self.getWeekAccountInvoice(item.id);
|
|
|
+ sale_invoice = self.getWeekAccountInvoice(item.id,'sale');
|
|
|
+ sale_invoice_refund = self.getWeekAccountInvoice(item.id,'sale_refund');
|
|
|
var order_total = _.reduce(_.map(order,function(item) {
|
|
|
return item.amount_total;
|
|
|
}),function(memo, num) {
|
|
|
return memo + num;
|
|
|
},0);
|
|
|
- _.each(invoice, function (item) {
|
|
|
+
|
|
|
+ /*================
|
|
|
+ SALE INVOICE
|
|
|
+ ================*/
|
|
|
+
|
|
|
+ array = [];
|
|
|
+ _.each(sale_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 sale_invoice_total = 0;
|
|
|
+ if(array.length > 0){
|
|
|
+ sale_invoice_total = _.reduce(_.map(array, function (map) {
|
|
|
+ return map.amount;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /*=======================
|
|
|
+ SALE INVOICE REFUND
|
|
|
+ =======================*/
|
|
|
+
|
|
|
+ array = [];
|
|
|
+ _.each(sale_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 = 0;
|
|
|
+ var sale_invoice_refund_total = 0;
|
|
|
if(array.length > 0){
|
|
|
- invoice_total = _.reduce(_.map(array, function (map) {
|
|
|
+ sale_invoice_refund_total = _.reduce(_.map(array, function (map) {
|
|
|
return map.amount;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- var total = order_total + invoice_total;
|
|
|
+
|
|
|
+
|
|
|
+ var total = (order_total + sale_invoice_total) - sale_invoice_refund_total;
|
|
|
data.push(total);
|
|
|
});
|
|
|
self.fetchChart(data,title,CurrencyBase);
|
|
@@ -349,7 +416,8 @@ function chart_sale_by_store (widget) {
|
|
|
showToday: function (){
|
|
|
var self = this;
|
|
|
var order;
|
|
|
- var invoice;
|
|
|
+ var sale_invoice;
|
|
|
+ var sale_invoice_refund;
|
|
|
var title = [];
|
|
|
var data = [];
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
@@ -357,28 +425,56 @@ function chart_sale_by_store (widget) {
|
|
|
var array = [];
|
|
|
title.push(item.name);
|
|
|
order = self.getTodayPosOrder(item.id);
|
|
|
- invoice = self.getTodayAccountInvoice(item.id);
|
|
|
+ sale_invoice = self.getTodayAccountInvoice(item.id,'sale');
|
|
|
+ sale_invoice_refund = self.getTodayAccountInvoice(item.id,'sale_refund');
|
|
|
var order_total = _.reduce(_.map(order,function(item) {
|
|
|
return item.amount_total;
|
|
|
}),function(memo, num) {
|
|
|
return memo + num;
|
|
|
},0);
|
|
|
- _.each(invoice, function (item) {
|
|
|
+
|
|
|
+ /*================
|
|
|
+ SALE INVOICE
|
|
|
+ ================*/
|
|
|
+
|
|
|
+ array = [];
|
|
|
+ _.each(sale_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;
|
|
|
+ var sale_invoice_total = 0;
|
|
|
if(array.length > 0){
|
|
|
- invoice_total = _.reduce(_.map(array, function (map) {
|
|
|
- return map.amount;
|
|
|
+ sale_invoice_total = _.reduce(_.map(array, function (map) {
|
|
|
+ return map.amount;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
- });
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
- var total = order_total + invoice_total;
|
|
|
+
|
|
|
+ /*=======================
|
|
|
+ SALE INVOICE REFUND
|
|
|
+ =======================*/
|
|
|
+
|
|
|
+ array = [];
|
|
|
+ _.each(sale_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 sale_invoice_refund_total = 0;
|
|
|
+ if(array.length > 0){
|
|
|
+ sale_invoice_refund_total = _.reduce(_.map(array, function (map) {
|
|
|
+ return map.amount;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var total = (order_total + sale_invoice_total) - sale_invoice_refund_total;
|
|
|
data.push(total);
|
|
|
});
|
|
|
self.fetchChart(data,title,CurrencyBase);
|
|
@@ -389,19 +485,19 @@ function chart_sale_by_store (widget) {
|
|
|
var label = title;
|
|
|
var body = data;
|
|
|
|
|
|
- // Chart.scaleService.updateScaleDefaults('linear', {
|
|
|
- // ticks: {
|
|
|
- // callback: function(tick) {
|
|
|
- // return tick.toLocaleString('de-DE');
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
+ Chart.scaleService.updateScaleDefaults('linear', {
|
|
|
+ ticks: {
|
|
|
+ callback: function(tick) {
|
|
|
+ return tick.toLocaleString('de-DE');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- // Chart.defaults.global.tooltips.callbacks.label = function(tooltipItem, data) {
|
|
|
- // var dataset = data.datasets[tooltipItem.datasetIndex];
|
|
|
- // var datasetLabel = dataset.label || '';
|
|
|
- // return datasetLabel + dataset.data[tooltipItem.index].toLocaleString('de-DE');
|
|
|
- // };
|
|
|
+ Chart.defaults.global.tooltips.callbacks.label = function(tooltipItem, data) {
|
|
|
+ var dataset = data.datasets[tooltipItem.datasetIndex];
|
|
|
+ var datasetLabel = dataset.label || '';
|
|
|
+ return datasetLabel + dataset.data[tooltipItem.index].toLocaleString('de-DE');
|
|
|
+ };
|
|
|
|
|
|
var chart = new Chart(this.$el.find(".widget-content").find('canvas'), {
|
|
|
type: 'horizontalBar',
|
|
@@ -447,6 +543,7 @@ function chart_sale_by_store (widget) {
|
|
|
rigth: 0,
|
|
|
}
|
|
|
},
|
|
|
+ events: ['click'],
|
|
|
tooltips: {
|
|
|
callbacks: {
|
|
|
label: function(tooltipItem, data) {
|