|
@@ -54,8 +54,8 @@ function widget_balance(widget) {
|
|
|
fetchAccountInvoice: function() {
|
|
|
var self = this;
|
|
|
var defer = $.Deferred();
|
|
|
- var fields = ['id', 'name', 'date_invoice', 'amount_total'];
|
|
|
- var domain = [['state', 'not in', ['draft','cancel']],['type','=','in_invoice']];
|
|
|
+ var fields = ['id','type','date_invoice','amount_total'];
|
|
|
+ var domain = [['state', 'not in', ['draft','cancel']],['type','in',['in_invoice','out_invoice']]];
|
|
|
var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
AccountInvoice.query(fields).filter(domain).all().then(function(results) {
|
|
|
defer.resolve(results);
|
|
@@ -109,26 +109,49 @@ function widget_balance(widget) {
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- getTodayAccountInvoice:function() {
|
|
|
+ getTodayInAccountInvoice:function() {
|
|
|
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;
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM-DD') === date & inv.type == 'in_invoice';
|
|
|
}));
|
|
|
},
|
|
|
|
|
|
- getThisWeekAccountInvoice:function() {
|
|
|
+ getTodayOutAccountInvoice:function() {
|
|
|
+ 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 & inv.type == 'out_invoice';
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+ getThisWeekInAccountInvoice:function() {
|
|
|
+ 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') & inv.type == 'in_invoice';
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+ getThisWeekOutAccountInvoice:function() {
|
|
|
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');
|
|
|
+ return moment(inv.date_invoice).week() === week & moment(inv.date_invoice).format('YYYY')=== moment().format('YYYY') & inv.type == 'out_invoice';
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+ getThisMonthInAccountInvoice:function() {
|
|
|
+ var self = this;
|
|
|
+ return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM')=== moment().format('YYYY-MM') & inv.type == 'in_invoice';
|
|
|
}));
|
|
|
},
|
|
|
|
|
|
- getThisMonthAccountInvoice:function() {
|
|
|
+ getThisMonthOutAccountInvoice:function() {
|
|
|
var self = this;
|
|
|
return _.flatten(_.filter(self.AccountInvoice,function (inv) {
|
|
|
- return moment(inv.date_invoice).format('YYYY-MM')=== moment().format('YYYY-MM');
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM')=== moment().format('YYYY-MM') & inv.type == 'out_invoice';
|
|
|
}));
|
|
|
},
|
|
|
|
|
@@ -158,11 +181,13 @@ function widget_balance(widget) {
|
|
|
showToday: function () {
|
|
|
var self = this;
|
|
|
var amount_order = 0;
|
|
|
- var amount_invoice = 0;
|
|
|
+ var invoice_in_amount = 0;
|
|
|
+ var invoice_out_amount = 0;
|
|
|
var balance = 0;
|
|
|
var data = [];
|
|
|
var order = self.getTodayPosOrder();
|
|
|
- var invoice = self.getTodayAccountInvoice();
|
|
|
+ var in_invoice = self.getTodayInAccountInvoice();
|
|
|
+ var out_invoice = self.getTodayOutAccountInvoice();
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
if(order.length > 0){
|
|
|
amount_order = _.reduce(_.map(order, function (map) {
|
|
@@ -171,14 +196,21 @@ function widget_balance(widget) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- if(invoice.length > 0){
|
|
|
- amount_invoice = _.reduce(_.map(invoice, function (map) {
|
|
|
+ if(in_invoice.length > 0){
|
|
|
+ invoice_in_amount = _.reduce(_.map(in_invoice, function (map) {
|
|
|
+ return map.amount_total;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(out_invoice.length > 0){
|
|
|
+ invoice_out_amount = _.reduce(_.map(out_invoice, function (map) {
|
|
|
return map.amount_total;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- balance = amount_order - amount_invoice;
|
|
|
+ balance = (invoice_out_amount + amount_order) - invoice_in_amount;
|
|
|
self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
self.$el.find('.widget-content').find('a').text(accounting.formatMoney(balance, CurrencyBase.symbol, CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator))
|
|
|
},
|
|
@@ -186,11 +218,13 @@ function widget_balance(widget) {
|
|
|
showThisWeek: function () {
|
|
|
var self = this;
|
|
|
var amount_order = 0;
|
|
|
- var amount_invoice = 0;
|
|
|
+ var invoice_in_amount = 0;
|
|
|
+ var invoice_out_amount = 0;
|
|
|
var balance = 0;
|
|
|
var data = [];
|
|
|
var order = self.getThisWeekPosOrder();
|
|
|
- var invoice = self.getThisWeekAccountInvoice();
|
|
|
+ var in_invoice = self.getThisWeekInAccountInvoice();
|
|
|
+ var out_invoice = self.getThisWeekOutAccountInvoice();
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
if(order.length > 0){
|
|
|
amount_order = _.reduce(_.map(order, function (map) {
|
|
@@ -199,14 +233,21 @@ function widget_balance(widget) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- if(invoice.length > 0){
|
|
|
- amount_invoice = _.reduce(_.map(invoice, function (map) {
|
|
|
+ if(in_invoice.length > 0){
|
|
|
+ invoice_in_amount = _.reduce(_.map(in_invoice, function (map) {
|
|
|
+ return map.amount_total;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(out_invoice.length > 0){
|
|
|
+ invoice_out_amount = _.reduce(_.map(out_invoice, function (map) {
|
|
|
return map.amount_total;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- balance = amount_order - amount_invoice;
|
|
|
+ balance = (invoice_out_amount + amount_order) - invoice_in_amount;
|
|
|
self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
self.$el.find('.widget-content').find('a').text(accounting.formatMoney(balance, CurrencyBase.symbol, CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator))
|
|
|
},
|
|
@@ -214,11 +255,13 @@ function widget_balance(widget) {
|
|
|
showThisMonth: function () {
|
|
|
var self = this;
|
|
|
var amount_order = 0;
|
|
|
- var amount_invoice = 0;
|
|
|
+ var invoice_in_amount = 0;
|
|
|
+ var invoice_out_amount = 0;
|
|
|
var balance = 0;
|
|
|
var data = [];
|
|
|
var order = self.getThisMonthPosOrder();
|
|
|
- var invoice = self.getThisMonthAccountInvoice();
|
|
|
+ var in_invoice = self.getThisMonthInAccountInvoice();
|
|
|
+ var out_invoice = self.getThisMonthOutAccountInvoice();
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
if(order.length > 0){
|
|
|
amount_order = _.reduce(_.map(order, function (map) {
|
|
@@ -227,14 +270,21 @@ function widget_balance(widget) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- if(invoice.length > 0){
|
|
|
- amount_invoice = _.reduce(_.map(invoice, function (map) {
|
|
|
+ if(in_invoice.length > 0){
|
|
|
+ invoice_in_amount = _.reduce(_.map(in_invoice, function (map) {
|
|
|
+ return map.amount_total;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(out_invoice.length > 0){
|
|
|
+ invoice_out_amount = _.reduce(_.map(out_invoice, function (map) {
|
|
|
return map.amount_total;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- balance = amount_order - amount_invoice;
|
|
|
+ balance = (invoice_out_amount + amount_order) - invoice_in_amount;
|
|
|
self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
self.$el.find('.widget-content').find('a').text(accounting.formatMoney(balance, CurrencyBase.symbol, CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator))
|
|
|
},
|