|
@@ -18,23 +18,28 @@ function chart_ingreso_egreso (widget) {
|
|
|
width: 6,
|
|
|
height: 4
|
|
|
});
|
|
|
- },
|
|
|
+ },
|
|
|
+
|
|
|
start: function () {
|
|
|
var self = this;
|
|
|
self.fetchInitial();
|
|
|
},
|
|
|
+
|
|
|
fetchInitial:function() {
|
|
|
var self = this;
|
|
|
- self.fetchCurrentUser().then(function (CurrentUser) {
|
|
|
- return CurrentUser;
|
|
|
- }).then(function (CurrentUser) {
|
|
|
- self.CurrentUser = CurrentUser;
|
|
|
- return self.fetchResUser(CurrentUser);
|
|
|
+ self.fetchResUser().then(function (ResUser) {
|
|
|
+ return ResUser;
|
|
|
}).then(function (ResUser) {
|
|
|
self.ResUser = ResUser;
|
|
|
return self.fetchAccountJournal();
|
|
|
}).then(function (AccountJournal) {
|
|
|
self.AccountJournal = AccountJournal;
|
|
|
+ return self.fetchResCompany();
|
|
|
+ }).then(function(ResCompany) {
|
|
|
+ self.ResCompany = ResCompany;
|
|
|
+ return self.fetchResCurrency();
|
|
|
+ }).then(function(ResCurrency) {
|
|
|
+ self.ResCurrency = ResCurrency;
|
|
|
return self.fecthAccountBankStatementLine();
|
|
|
}).then(function (AccountBankStatementLine) {
|
|
|
self.AccountBankStatementLine = AccountBankStatementLine;
|
|
@@ -42,19 +47,11 @@ function chart_ingreso_egreso (widget) {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- 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) {
|
|
|
+ fetchResUser: function() {
|
|
|
var self = this;
|
|
|
var defer = $.Deferred();
|
|
|
var fields = ['id','name','store_id'];
|
|
|
- var domain = [['id','=',id]];
|
|
|
+ var domain = [['id','=',self.session.uid]];
|
|
|
var ResUser = new model.web.Model('res.users');
|
|
|
ResUser.query(fields).filter(domain).all().then(function (results) {
|
|
|
defer.resolve(results);
|
|
@@ -67,13 +64,12 @@ function chart_ingreso_egreso (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','currency'];
|
|
|
var domain = [['type','in',['bank','cash']],['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;
|
|
|
},
|
|
|
|
|
@@ -83,7 +79,7 @@ function chart_ingreso_egreso (widget) {
|
|
|
var journal_ids = _.flatten(_.map(self.AccountJournal, function (item) {
|
|
|
return item.id;
|
|
|
}));
|
|
|
- var fields = ['id','date','amount'];
|
|
|
+ var fields = ['id','date','amount','journal_id'];
|
|
|
var domain = [['journal_id','in',journal_ids]];
|
|
|
var AccountBankStatementLine = new model.web.Model('account.bank.statement.line');
|
|
|
AccountBankStatementLine.query(fields).filter(domain).all().then(function (results) {
|
|
@@ -92,7 +88,48 @@ function chart_ingreso_egreso (widget) {
|
|
|
return defer;
|
|
|
},
|
|
|
|
|
|
- // Obtener Lineas de caja por mes
|
|
|
+ fetchResCompany: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name', 'currency_id'];
|
|
|
+ var domain = [['id', '=', self.session.company_id]];
|
|
|
+ var ResCompany = new model.web.Model('res.company');
|
|
|
+ ResCompany.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResCurrency : function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
+ var ResCurrency = new model.web.Model('res.currency');
|
|
|
+ ResCurrency.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ getResCurrency: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountJournal: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.AccountJournal,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /*==================================
|
|
|
+ GET STATEMENTS LINES BY MONTHS
|
|
|
+ ==================================*/
|
|
|
|
|
|
getInAccountBankStatementLine:function(mes) {
|
|
|
var self = this;
|
|
@@ -118,7 +155,9 @@ function chart_ingreso_egreso (widget) {
|
|
|
}));
|
|
|
},
|
|
|
|
|
|
- // Obtener lineas de caja por esta semana
|
|
|
+ /*============================================
|
|
|
+ GET STATEMENTS LINES BY THE CURRENT WEEK
|
|
|
+ ============================================*/
|
|
|
|
|
|
getInWeekAccountBankStatementLine:function(day) {
|
|
|
var self = this;
|
|
@@ -136,7 +175,9 @@ function chart_ingreso_egreso (widget) {
|
|
|
}));
|
|
|
},
|
|
|
|
|
|
- // Obtener lineas de caja por dias
|
|
|
+ /*================================
|
|
|
+ GET STATEMENTS LINES BY DAYS
|
|
|
+ ================================*/
|
|
|
|
|
|
getInDaysAccountBankStatementLine:function(day) {
|
|
|
var self = this;
|
|
@@ -153,8 +194,10 @@ function chart_ingreso_egreso (widget) {
|
|
|
return moment(inv.date).format('YYYY-MM-DD') === date & inv.amount < 0;
|
|
|
}));
|
|
|
},
|
|
|
-
|
|
|
- // Mostrar por meses
|
|
|
+
|
|
|
+ /*===============
|
|
|
+ SHOW MONTHS
|
|
|
+ ===============*/
|
|
|
showMonths: function() {
|
|
|
var self = this;
|
|
|
var title = ['Ene', 'Feb', 'Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'];
|
|
@@ -163,95 +206,196 @@ function chart_ingreso_egreso (widget) {
|
|
|
var mes = 0;
|
|
|
var dataIn = [];
|
|
|
var dataOut = [];
|
|
|
+ var data = [];
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
for (var i = 1; i <= 12; i++) {
|
|
|
inStatement = self.getInAccountBankStatementLine(i);
|
|
|
- var total = _.reduce(_.map(inStatement,function(item) {
|
|
|
- return item.amount;
|
|
|
- }),function(memo, num) {
|
|
|
- return memo + num;
|
|
|
- },0);
|
|
|
- dataIn.push(total);
|
|
|
+ var in_amount = 0;
|
|
|
+ if(inStatement){
|
|
|
+ data = [];
|
|
|
+ _.each(inStatement, function (item) {
|
|
|
+ var journal = self.getAccountJournal(item.journal_id[0]).shift();
|
|
|
+ var currency;
|
|
|
+ if(journal.currency){
|
|
|
+ currency = self.getResCurrency(journal.currency[0]).shift();
|
|
|
+ }else{
|
|
|
+ currency = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ data.push({
|
|
|
+ amount: item.amount * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ var in_amount = _.reduce(_.map(data,function(item) {
|
|
|
+ return item.amount;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ }
|
|
|
+ dataIn.push(in_amount);
|
|
|
}
|
|
|
+ data = [];
|
|
|
for (var i = 1; i <= 12; i++) {
|
|
|
OutStatement = self.getOutAccountBankStatementLine(i);
|
|
|
- var total = _.reduce(_.map(OutStatement,function(item) {
|
|
|
- return item.amount;
|
|
|
- }),function(memo, num) {
|
|
|
- return memo + num;
|
|
|
- },0);
|
|
|
- dataOut.push(Math.abs(total));
|
|
|
+ var out_amount = 0;
|
|
|
+ if(OutStatement){
|
|
|
+ data = [];
|
|
|
+ _.each(OutStatement, function (item) {
|
|
|
+ var journal = self.getAccountJournal(item.journal_id[0]).shift();
|
|
|
+ var currency;
|
|
|
+ if(journal.currency){
|
|
|
+ currency = self.getResCurrency(journal.currency[0]).shift();
|
|
|
+ }else{
|
|
|
+ currency = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ data.push({
|
|
|
+ amount: item.amount * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ var out_amount = _.reduce(_.map(data,function(item) {
|
|
|
+ return item.amount;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ }
|
|
|
+ dataOut.push(Math.abs(out_amount));
|
|
|
}
|
|
|
- self.$el.unblock();
|
|
|
- self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
self.fetchChart(dataIn, dataOut, title);
|
|
|
},
|
|
|
|
|
|
- // Mostrar por semana Actual
|
|
|
+ /*=============
|
|
|
+ SHOW WEEK
|
|
|
+ =============*/
|
|
|
showWeeks: function() {
|
|
|
var self = this;
|
|
|
var title = ['Lunes', 'Martes', 'Miercoles','Jueves','Viernes','Sabado','Domingo'];
|
|
|
var inStatement;
|
|
|
var OutStatement;
|
|
|
- var mes = 0;
|
|
|
var dataIn = [];
|
|
|
var dataOut = [];
|
|
|
+ var data = [];
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
for (var i = 1; i <= 7; i++) {
|
|
|
inStatement = self.getInWeekAccountBankStatementLine(i);
|
|
|
- var total = _.reduce(_.map(inStatement,function(item) {
|
|
|
- return item.amount;
|
|
|
- }),function(memo, num) {
|
|
|
- return memo + num;
|
|
|
- },0);
|
|
|
- dataIn.push(total);
|
|
|
+ var in_amount = 0;
|
|
|
+ if(inStatement){
|
|
|
+ data = [];
|
|
|
+ _.each(inStatement, function (item) {
|
|
|
+ var journal = self.getAccountJournal(item.journal_id[0]).shift();
|
|
|
+ var currency;
|
|
|
+ if(journal.currency){
|
|
|
+ currency = self.getResCurrency(journal.currency[0]).shift();
|
|
|
+ }else{
|
|
|
+ currency = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ data.push({
|
|
|
+ amount: item.amount * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ var in_amount = _.reduce(_.map(data,function(item) {
|
|
|
+ return item.amount;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ }
|
|
|
+ dataIn.push(in_amount);
|
|
|
}
|
|
|
for (var i = 1; i <= 7; i++) {
|
|
|
OutStatement = self.getOutWeekAccountBankStatementLine(i);
|
|
|
- var total = _.reduce(_.map(OutStatement,function(item) {
|
|
|
- return item.amount;
|
|
|
- }),function(memo, num) {
|
|
|
- return memo + num;
|
|
|
- },0);
|
|
|
- dataOut.push(Math.abs(total));
|
|
|
+ var out_amount = 0;
|
|
|
+ if(OutStatement){
|
|
|
+ data = [];
|
|
|
+ _.each(OutStatement, function (item) {
|
|
|
+ var journal = self.getAccountJournal(item.journal_id[0]).shift();
|
|
|
+ var currency;
|
|
|
+ if(journal.currency){
|
|
|
+ currency = self.getResCurrency(journal.currency[0]).shift();
|
|
|
+ }else{
|
|
|
+ currency = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ data.push({
|
|
|
+ amount: item.amount * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ var out_amount = _.reduce(_.map(data,function(item) {
|
|
|
+ return item.amount;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ }
|
|
|
+ dataOut.push(Math.abs(out_amount));
|
|
|
}
|
|
|
- self.$el.unblock();
|
|
|
- self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
self.fetchChart(dataIn, dataOut, title);
|
|
|
},
|
|
|
|
|
|
- // Mostrar grafico por dias
|
|
|
+ /*=====================
|
|
|
+ SHOW LAST 15 DAYS
|
|
|
+ =====================*/
|
|
|
showDays: function() {
|
|
|
var self = this;
|
|
|
var title = [];
|
|
|
var inStatement;
|
|
|
var OutStatement;
|
|
|
- var mes = 0;
|
|
|
var dataIn = [];
|
|
|
var dataOut = [];
|
|
|
+ var data = [];
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
for (var i = 15; i >= 0; i--) {
|
|
|
inStatement = self.getInDaysAccountBankStatementLine(i);
|
|
|
- var total = _.reduce(_.map(inStatement,function(item) {
|
|
|
- return item.amount;
|
|
|
- }),function(memo, num) {
|
|
|
- return memo + num;
|
|
|
- },0);
|
|
|
- dataIn.push(total);
|
|
|
+ var in_amount = 0;
|
|
|
+ if(inStatement){
|
|
|
+ data = [];
|
|
|
+ _.each(inStatement, function (item) {
|
|
|
+ var journal = self.getAccountJournal(item.journal_id[0]).shift();
|
|
|
+ var currency;
|
|
|
+ if(journal.currency){
|
|
|
+ currency = self.getResCurrency(journal.currency[0]).shift();
|
|
|
+ }else{
|
|
|
+ currency = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ data.push({
|
|
|
+ amount: item.amount * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ var in_amount = _.reduce(_.map(data,function(item) {
|
|
|
+ return item.amount;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ }
|
|
|
+ dataIn.push(in_amount);
|
|
|
title.push(moment().subtract(i, 'days').format('DD / MM'));
|
|
|
}
|
|
|
for (var i = 15; i >= 0; i--) {
|
|
|
OutStatement = self.getOutDaysAccountBankStatementLine(i);
|
|
|
- var total = _.reduce(_.map(OutStatement,function(item) {
|
|
|
- return item.amount;
|
|
|
- }),function(memo, num) {
|
|
|
- return memo + num;
|
|
|
- },0);
|
|
|
- dataOut.push(Math.abs(total));
|
|
|
+ var out_amount = 0;
|
|
|
+ if(OutStatement){
|
|
|
+ data = [];
|
|
|
+ _.each(OutStatement, function (item) {
|
|
|
+ var journal = self.getAccountJournal(item.journal_id[0]).shift();
|
|
|
+ var currency;
|
|
|
+ if(journal.currency){
|
|
|
+ currency = self.getResCurrency(journal.currency[0]).shift();
|
|
|
+ }else{
|
|
|
+ currency = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ data.push({
|
|
|
+ amount: item.amount * (CurrencyBase.rate_silent / currency.rate_silent),
|
|
|
+ })
|
|
|
+ });
|
|
|
+ var out_amount = _.reduce(_.map(data,function(item) {
|
|
|
+ return item.amount;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ }
|
|
|
+ dataOut.push(Math.abs(out_amount));
|
|
|
}
|
|
|
- self.$el.unblock();
|
|
|
- self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
self.fetchChart(dataIn, dataOut, title);
|
|
|
},
|
|
|
|
|
|
- // Generar Grafico
|
|
|
+ /*=================
|
|
|
+ BUILD A CHART
|
|
|
+ =================*/
|
|
|
fetchChart: function (dataIn,dataOut,title) {
|
|
|
var self = this;
|
|
|
var label = title;
|