|
@@ -7,22 +7,25 @@ function payments_today_counters (widget) {
|
|
template: 'PaymentsTodayCounters',
|
|
template: 'PaymentsTodayCounters',
|
|
accountVoucher: [],
|
|
accountVoucher: [],
|
|
resCompany: [],
|
|
resCompany: [],
|
|
- currencyRate: [],
|
|
|
|
|
|
+ resCurrecy: [],
|
|
|
|
|
|
events: {
|
|
events: {
|
|
'click a': 'showCustomers',
|
|
'click a': 'showCustomers',
|
|
'click h2': 'showCustomers',
|
|
'click h2': 'showCustomers',
|
|
},
|
|
},
|
|
|
|
+
|
|
init: function (parent) {
|
|
init: function (parent) {
|
|
this._super(parent, {
|
|
this._super(parent, {
|
|
width : 3,
|
|
width : 3,
|
|
height: 2
|
|
height: 2
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+
|
|
start: function () {
|
|
start: function () {
|
|
var self = this;
|
|
var self = this;
|
|
self.fetchInitial();
|
|
self.fetchInitial();
|
|
},
|
|
},
|
|
|
|
+
|
|
fetchInitial: function () {
|
|
fetchInitial: function () {
|
|
var self = this;
|
|
var self = this;
|
|
self.$el.find('#morosidad').block({
|
|
self.$el.find('#morosidad').block({
|
|
@@ -31,7 +34,9 @@ function payments_today_counters (widget) {
|
|
backgroundColor: '#FAFAFA'
|
|
backgroundColor: '#FAFAFA'
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
self.$el.find('.widget-content.widget-loading').css('display','flex');
|
|
self.$el.find('.widget-content.widget-loading').css('display','flex');
|
|
|
|
+
|
|
self.fetchAccountVoucher().then(function (accountVoucher) {
|
|
self.fetchAccountVoucher().then(function (accountVoucher) {
|
|
return accountVoucher;
|
|
return accountVoucher;
|
|
}).then(function (accountVoucher) {
|
|
}).then(function (accountVoucher) {
|
|
@@ -42,9 +47,6 @@ function payments_today_counters (widget) {
|
|
return self.fetchResCurrecy(resCompany);
|
|
return self.fetchResCurrecy(resCompany);
|
|
}).then(function(resCurrecy){
|
|
}).then(function(resCurrecy){
|
|
self.resCurrecy = resCurrecy;
|
|
self.resCurrecy = resCurrecy;
|
|
- return self.fetchCurrency();
|
|
|
|
- }).then(function (currencyRate) {
|
|
|
|
- self.currencyRate = currencyRate;
|
|
|
|
return self.fetchVoucherCurrency();
|
|
return self.fetchVoucherCurrency();
|
|
});
|
|
});
|
|
},
|
|
},
|
|
@@ -75,71 +77,45 @@ function payments_today_counters (widget) {
|
|
});
|
|
});
|
|
return defer;
|
|
return defer;
|
|
},
|
|
},
|
|
- // Buscar Cambio de Monedas USD,PYG,ARG,BRL
|
|
|
|
- fetchCurrency: function () {
|
|
|
|
- var defer = $.Deferred();
|
|
|
|
- var currency_Rate = new model.web.Model('res.currency.rate');
|
|
|
|
- var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
|
|
|
|
- var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
|
|
|
|
-
|
|
|
|
- currency_Rate.query(fields).filter(domain).all().then(function (results) {
|
|
|
|
- defer.resolve(results);
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- return defer;
|
|
|
|
- },
|
|
|
|
- // Res currecy
|
|
|
|
- fetchResCurrecy : function(company){
|
|
|
|
|
|
+ // Moneda
|
|
|
|
+ fetchResCurrecy : function(){
|
|
var self = this;
|
|
var self = this;
|
|
var defer = $.Deferred();
|
|
var defer = $.Deferred();
|
|
-
|
|
|
|
- var id_curency = _.flatten(_.map(company,function(map){
|
|
|
|
- return map.currency_id[0];
|
|
|
|
- }));
|
|
|
|
-
|
|
|
|
- var fields =['id','name', 'symbol'];
|
|
|
|
- var domain =[['id','in',id_curency]];
|
|
|
|
|
|
+ var fields =['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
|
|
|
|
+ var domain =[['active','=',true]];
|
|
var resCurrecy = new model.web.Model('res.currency');
|
|
var resCurrecy = new model.web.Model('res.currency');
|
|
|
|
|
|
resCurrecy.query(fields).filter(domain).all().then(function(results){
|
|
resCurrecy.query(fields).filter(domain).all().then(function(results){
|
|
defer.resolve(results);
|
|
defer.resolve(results);
|
|
});
|
|
});
|
|
|
|
+
|
|
return defer;
|
|
return defer;
|
|
},
|
|
},
|
|
// voucherCurrencyRate
|
|
// voucherCurrencyRate
|
|
fetchVoucherCurrency: function () {
|
|
fetchVoucherCurrency: function () {
|
|
var self = this;
|
|
var self = this;
|
|
- var newVoucher=[];
|
|
|
|
- var itemvoucher;
|
|
|
|
- var itemCurrencyRate;
|
|
|
|
|
|
+ var newVoucher = [];
|
|
|
|
+ var itemVoucher;
|
|
|
|
+ var residual = 0;
|
|
|
|
+ var company = self.resCompany.shift();
|
|
|
|
+ var currencyBase = self.getCutrrency(company.currency_id[0]).shift();
|
|
|
|
+ var currencyVoucher;
|
|
|
|
|
|
for (var i = 0; i < self.accountVoucher.length; i++) {
|
|
for (var i = 0; i < self.accountVoucher.length; i++) {
|
|
- itemvoucher = self.accountVoucher[i];
|
|
|
|
- itemCurrencyRate = self.getCutrrencyRate(itemvoucher.currency_id[0]);
|
|
|
|
- if(!itemCurrencyRate){
|
|
|
|
- itemCurrencyRate={};
|
|
|
|
- itemCurrencyRate.rate=1;
|
|
|
|
|
|
+ itemVoucher = self.accountVoucher[i];
|
|
|
|
+
|
|
|
|
+ currencyVoucher = self.getCutrrency(itemVoucher.payment_rate_currency_id[0]).shift();
|
|
|
|
+ if(!currencyVoucher){
|
|
|
|
+ currencyVoucher = {};
|
|
|
|
+ currencyVoucher.rate_silent = currencyBase.rate_silent;
|
|
}
|
|
}
|
|
- newVoucher.push({ amount : itemvoucher.amount,
|
|
|
|
- amount_rate : (itemvoucher.amount/itemCurrencyRate.rate)
|
|
|
|
- });
|
|
|
|
|
|
+
|
|
|
|
+ newVoucher.push({
|
|
|
|
+ amount : itemVoucher.amount,
|
|
|
|
+ amount_rate : (itemVoucher.amount * (currencyBase.rate_silent / currencyVoucher.rate_silent))
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- self.fetchReduceMoveLine(newVoucher)
|
|
|
|
- },
|
|
|
|
- getCutrrencyRate: function (currency_id) {
|
|
|
|
- var self = this;
|
|
|
|
- return _.filter(self.currencyRate,function (item) {
|
|
|
|
- return item.currency_id[0] == currency_id
|
|
|
|
- }).shift();
|
|
|
|
- },
|
|
|
|
- // // Reduce Move line
|
|
|
|
- fetchReduceMoveLine: function (newVoucher) {
|
|
|
|
- var self = this;
|
|
|
|
- var residual =0;
|
|
|
|
- var company = _.map(self.resCompany, function (map) {
|
|
|
|
- return map.currency_id[1];
|
|
|
|
- });
|
|
|
|
- var moneda = self.resCurrecy.shift();
|
|
|
|
|
|
+
|
|
if (newVoucher.length > 0) {
|
|
if (newVoucher.length > 0) {
|
|
residual = _.reduce(_.map(newVoucher, function (map) {
|
|
residual = _.reduce(_.map(newVoucher, function (map) {
|
|
return map.amount_rate;
|
|
return map.amount_rate;
|
|
@@ -148,16 +124,18 @@ function payments_today_counters (widget) {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- if (moneda.id != 166){
|
|
|
|
- residual = accounting.formatNumber(residual, 2, ".", ",");
|
|
|
|
- }else{
|
|
|
|
- residual = accounting.formatNumber(residual, ",", ".");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
- self.$el.find('.widget-content').find('a').text(residual).append(' <small>'+moneda.symbol+'</small>');
|
|
|
|
|
|
+ self.$el.find('.widget-content').find('a').text(accounting.formatMoney(residual, currencyBase.symbol, currencyBase.decimal_places, currencyBase.thousands_separator, currencyBase.decimal_separator))
|
|
self.$el.find('#morosidad').unblock();
|
|
self.$el.find('#morosidad').unblock();
|
|
},
|
|
},
|
|
|
|
+ // Obtener la moneda
|
|
|
|
+ getCutrrency: function (id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ return _.filter(self.resCurrecy,function (item) {
|
|
|
|
+ return item.id === id
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ // modal
|
|
showCustomers: function (e) {
|
|
showCustomers: function (e) {
|
|
var hoy =moment().format('YYYY-MM-DD');
|
|
var hoy =moment().format('YYYY-MM-DD');
|
|
|
|
|