|
@@ -105,7 +105,7 @@ function widget_balance(widget) {
|
|
|
var self = this;
|
|
|
var defer = $.Deferred();
|
|
|
var store_ids = self.ResUser[0].store_id[0];
|
|
|
- var fields = ['id', 'name', 'store_ids'];
|
|
|
+ var fields = ['id', 'name', 'store_ids','type'];
|
|
|
var domain = [['type','in',['sale','purchase','sale_refund']],['store_ids','in',store_ids]];
|
|
|
var AccountJournal = new model.web.Model('account.journal');
|
|
|
AccountJournal.query(fields).filter(domain).all().then(function(results) {
|
|
@@ -121,8 +121,8 @@ function widget_balance(widget) {
|
|
|
return item.id;
|
|
|
}));
|
|
|
var date = moment().add(-1, 'month').format('YYYY-MM-23 HH:mm:ss');
|
|
|
- var fields = ['id','type','date_invoice','amount_total','currency_id'];
|
|
|
- var domain = [['state', 'not in', ['draft','cancel']],['type','in',['in_invoice','out_invoice','in_refund']],['journal_id','in',journal_ids],['date_invoice','>',date]];
|
|
|
+ var fields = ['id','type','date_invoice','amount_total','currency_id','journal_id'];
|
|
|
+ var domain = [['state', 'not in', ['draft','cancel']],['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);
|
|
@@ -199,67 +199,60 @@ function widget_balance(widget) {
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- /*
|
|
|
- ACCOUNT INVOICE - TODAY
|
|
|
- */
|
|
|
-
|
|
|
- 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 & inv.type == 'in_invoice';
|
|
|
- }));
|
|
|
- },
|
|
|
+ /*===================
|
|
|
+ ACCOUNT INVOICE
|
|
|
+ ===================*/
|
|
|
|
|
|
- getTodayOutAccountInvoice: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 & inv.type == 'out_invoice';
|
|
|
- }));
|
|
|
- },
|
|
|
-
|
|
|
- /*
|
|
|
- ACCOUNT INVOICE - WEEK
|
|
|
- */
|
|
|
-
|
|
|
- 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';
|
|
|
- }));
|
|
|
+ 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 & inv.type == 'in_invoice';
|
|
|
+ }));
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
- getThisWeekOutAccountInvoice: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') & inv.type == 'out_invoice';
|
|
|
- }));
|
|
|
- },
|
|
|
-
|
|
|
- /*
|
|
|
- ACCOUNT INVOICE - MONTH
|
|
|
- */
|
|
|
-
|
|
|
- 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';
|
|
|
- }));
|
|
|
+ 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]);
|
|
|
+ }));
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
- getThisMonthOutAccountInvoice: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') & inv.type == 'out_invoice';
|
|
|
- }));
|
|
|
+ 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]);
|
|
|
+ }));
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
- /*
|
|
|
+ /*=============
|
|
|
POS ORDER
|
|
|
- */
|
|
|
+ =============*/
|
|
|
|
|
|
getTodayPosOrder:function() {
|
|
|
var self = this;
|
|
@@ -295,14 +288,17 @@ function widget_balance(widget) {
|
|
|
showToday: function () {
|
|
|
var self = this;
|
|
|
var amount_order = 0;
|
|
|
- var invoice_in_amount = 0;
|
|
|
- var invoice_out_amount = 0;
|
|
|
+ var sale_invoice_amount = 0;
|
|
|
+ var sale_invoice_refund_amount = 0;
|
|
|
+ var purchase_invoice_amount= 0;
|
|
|
var balance = 0;
|
|
|
- var in_array = [];
|
|
|
- var out_array = [];
|
|
|
+ var array = [];
|
|
|
var order = self.getTodayPosOrder();
|
|
|
- var in_invoice = self.getTodayInAccountInvoice();
|
|
|
- var out_invoice = self.getTodayOutAccountInvoice();
|
|
|
+
|
|
|
+ var sale_invoice = self.getTodayAccountInvoice('sale');
|
|
|
+ var sale_invoice_refund = self.getTodayAccountInvoice('sale_refund');
|
|
|
+ var purchase_invoice = self.getTodayAccountInvoice('purchase');
|
|
|
+
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
if(order.length > 0){
|
|
|
amount_order = _.reduce(_.map(order, function (map) {
|
|
@@ -312,35 +308,64 @@ function widget_balance(widget) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if(in_invoice.length > 0){
|
|
|
- _.each(in_invoice, function (item) {
|
|
|
+ /*
|
|
|
+ SALE INVOICE
|
|
|
+ */
|
|
|
+
|
|
|
+ if(sale_invoice.length > 0){
|
|
|
+ array = [];
|
|
|
+ _.each(sale_invoice, function (item) {
|
|
|
var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
- in_array.push({
|
|
|
+ array.push({
|
|
|
amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
})
|
|
|
});
|
|
|
- invoice_in_amount = _.reduce(_.map(in_array, function (map) {
|
|
|
+ sale_invoice_amount = _.reduce(_.map(array, function (map) {
|
|
|
return map.amount;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ /*
|
|
|
+ SALE INVOICE REFUND
|
|
|
+ */
|
|
|
|
|
|
- if(out_invoice.length > 0){
|
|
|
- _.each(out_invoice, function (item) {
|
|
|
+ if(sale_invoice_refund.length > 0){
|
|
|
+ array = [];
|
|
|
+ _.each(sale_invoice_refund, function (item) {
|
|
|
var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
- out_array.push({
|
|
|
+ array.push({
|
|
|
amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
})
|
|
|
});
|
|
|
- invoice_out_amount = _.reduce(_.map(out_array, function (map) {
|
|
|
+ sale_invoice_refund_amount = _.reduce(_.map(array, function (map) {
|
|
|
return map.amount;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ /*
|
|
|
+ PURCHASE INVOICE
|
|
|
+ */
|
|
|
|
|
|
- balance = (invoice_out_amount + amount_order) - invoice_in_amount;
|
|
|
+ if(purchase_invoice.length > 0){
|
|
|
+ array = [];
|
|
|
+ _.each(purchase_invoice, function (item) {
|
|
|
+ var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
+ array.push({
|
|
|
+ amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ purchase_invoice_amount = _.reduce(_.map(array, function (map) {
|
|
|
+ return map.amount;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ balance = (sale_invoice_amount + amount_order) - (sale_invoice_refund_amount + purchase_invoice_amount);
|
|
|
|
|
|
self.today = balance;
|
|
|
},
|
|
@@ -352,14 +377,17 @@ function widget_balance(widget) {
|
|
|
showThisWeek: function () {
|
|
|
var self = this;
|
|
|
var amount_order = 0;
|
|
|
- var invoice_in_amount = 0;
|
|
|
- var invoice_out_amount = 0;
|
|
|
+ var sale_invoice_amount = 0;
|
|
|
+ var sale_invoice_refund_amount = 0;
|
|
|
+ var purchase_invoice_amount= 0;
|
|
|
var balance = 0;
|
|
|
- var in_array = [];
|
|
|
- var out_array = [];
|
|
|
+ var array = [];
|
|
|
var order = self.getThisWeekPosOrder();
|
|
|
- var in_invoice = self.getThisWeekInAccountInvoice();
|
|
|
- var out_invoice = self.getThisWeekOutAccountInvoice();
|
|
|
+
|
|
|
+ var sale_invoice = self.getThisWeekAccountInvoice('sale');
|
|
|
+ var sale_invoice_refund = self.getThisWeekAccountInvoice('sale_refund');
|
|
|
+ var purchase_invoice = self.getThisWeekAccountInvoice('purchase');
|
|
|
+
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
if(order.length > 0){
|
|
|
amount_order = _.reduce(_.map(order, function (map) {
|
|
@@ -369,35 +397,64 @@ function widget_balance(widget) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if(in_invoice.length > 0){
|
|
|
- _.each(in_invoice, function (item) {
|
|
|
+ /*
|
|
|
+ SALE INVOICE
|
|
|
+ */
|
|
|
+
|
|
|
+ if(sale_invoice.length > 0){
|
|
|
+ array = [];
|
|
|
+ _.each(sale_invoice, function (item) {
|
|
|
var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
- in_array.push({
|
|
|
+ array.push({
|
|
|
amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
})
|
|
|
});
|
|
|
- invoice_in_amount = _.reduce(_.map(in_array, function (map) {
|
|
|
+ sale_invoice_amount = _.reduce(_.map(array, function (map) {
|
|
|
return map.amount;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ /*
|
|
|
+ SALE INVOICE REFUND
|
|
|
+ */
|
|
|
|
|
|
- if(out_invoice.length > 0){
|
|
|
- _.each(out_invoice, function (item) {
|
|
|
+ if(sale_invoice_refund.length > 0){
|
|
|
+ array = [];
|
|
|
+ _.each(sale_invoice_refund, function (item) {
|
|
|
var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
- out_array.push({
|
|
|
+ array.push({
|
|
|
+ amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ sale_invoice_refund_amount = _.reduce(_.map(array, function (map) {
|
|
|
+ return map.amount;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ PURCHASE INVOICE
|
|
|
+ */
|
|
|
+
|
|
|
+ if(purchase_invoice.length > 0){
|
|
|
+ array = [];
|
|
|
+ _.each(purchase_invoice, function (item) {
|
|
|
+ var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
+ array.push({
|
|
|
amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
})
|
|
|
});
|
|
|
- invoice_out_amount = _.reduce(_.map(out_array, function (map) {
|
|
|
+ purchase_invoice_amount = _.reduce(_.map(array, function (map) {
|
|
|
return map.amount;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- balance = (invoice_out_amount + amount_order) - invoice_in_amount;
|
|
|
+ balance = (sale_invoice_amount + amount_order) - (sale_invoice_refund_amount + purchase_invoice_amount);
|
|
|
self.week = balance;
|
|
|
},
|
|
|
|
|
@@ -407,7 +464,6 @@ function widget_balance(widget) {
|
|
|
|
|
|
showThisMonth: function () {
|
|
|
var self = this;
|
|
|
-
|
|
|
if(self.DashboardObjetive.length > 0){
|
|
|
self.objective = self.DashboardObjetive.shift().expected_profit;
|
|
|
}else{
|
|
@@ -415,14 +471,18 @@ function widget_balance(widget) {
|
|
|
}
|
|
|
|
|
|
var amount_order = 0;
|
|
|
- var invoice_in_amount = 0;
|
|
|
- var invoice_out_amount = 0;
|
|
|
+ var sale_invoice_amount = 0;
|
|
|
+ var sale_invoice_refund_amount = 0;
|
|
|
+ var purchase_invoice_amount = 0;
|
|
|
var balance = 0;
|
|
|
- var in_array = [];
|
|
|
+ var array = [];
|
|
|
var out_array = [];
|
|
|
var order = self.getThisMonthPosOrder();
|
|
|
- var in_invoice = self.getThisMonthInAccountInvoice();
|
|
|
- var out_invoice = self.getThisMonthOutAccountInvoice();
|
|
|
+
|
|
|
+ var sale_invoice = self.getThisMonthAccountInvoice('sale');
|
|
|
+ var sale_invoice_refund = self.getThisMonthAccountInvoice('sale_refund');
|
|
|
+ var purchase_invoice = self.getThisMonthAccountInvoice('purchase');
|
|
|
+
|
|
|
var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
|
|
|
if(order.length > 0){
|
|
@@ -433,35 +493,63 @@ function widget_balance(widget) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if(in_invoice.length > 0){
|
|
|
- _.each(in_invoice, function (item) {
|
|
|
+ /*
|
|
|
+ SALE INVOICE
|
|
|
+ */
|
|
|
+
|
|
|
+ if(sale_invoice.length > 0){
|
|
|
+ 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),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ sale_invoice_amount = _.reduce(_.map(array, function (map) {
|
|
|
+ return map.amount;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ SALE INVOICE REFUND
|
|
|
+ */
|
|
|
+
|
|
|
+ if(sale_invoice_refund.length > 0){
|
|
|
+ array = [];
|
|
|
+ _.each(sale_invoice_refund, function (item) {
|
|
|
var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
- in_array.push({
|
|
|
+ array.push({
|
|
|
amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
})
|
|
|
});
|
|
|
- invoice_in_amount = _.reduce(_.map(in_array, function (map) {
|
|
|
+ sale_invoice_refund_amount = _.reduce(_.map(array, function (map) {
|
|
|
return map.amount;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ /*
|
|
|
+ PURCHASE INVOICE
|
|
|
+ */
|
|
|
|
|
|
- if(out_invoice.length > 0){
|
|
|
- _.each(out_invoice, function (item) {
|
|
|
+ if(purchase_invoice.length > 0){
|
|
|
+ _.each(purchase_invoice, function (item) {
|
|
|
var currency = self.getResCurrency(item.currency_id[0]).shift();
|
|
|
out_array.push({
|
|
|
amount: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
})
|
|
|
});
|
|
|
- invoice_out_amount = _.reduce(_.map(out_array, function (map) {
|
|
|
+ purchase_invoice_amount = _.reduce(_.map(out_array, function (map) {
|
|
|
return map.amount;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- balance = (invoice_out_amount + amount_order) - invoice_in_amount;
|
|
|
+ balance = (sale_invoice_amount + amount_order) - (sale_invoice_refund_amount + purchase_invoice_amount);
|
|
|
self.month = balance;
|
|
|
if(self.objective > 0){
|
|
|
var percentage = (balance*100)/self.objective;
|