|
@@ -7,23 +7,26 @@ function monthly_purchases(widget) {
|
|
|
template: 'MonthlyPurchases',
|
|
|
accountVoucher:[],
|
|
|
accountInvoice:[],
|
|
|
- currencyRate :[],
|
|
|
+ resCurrecy :[],
|
|
|
resCompany:[],
|
|
|
|
|
|
events: {
|
|
|
'click a': 'showCustomers',
|
|
|
'click h2': 'showCustomers',
|
|
|
},
|
|
|
+
|
|
|
init: function (parent) {
|
|
|
this._super(parent, {
|
|
|
width : 3,
|
|
|
height: 2
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
start: function () {
|
|
|
var self = this;
|
|
|
self.fetchInitial();
|
|
|
},
|
|
|
+
|
|
|
fetchInitial: function(){
|
|
|
var self = this;
|
|
|
self.$el.find('#morosidad').block({
|
|
@@ -33,6 +36,7 @@ function monthly_purchases(widget) {
|
|
|
}
|
|
|
});
|
|
|
self.$el.find('.widget-content.widget-loading').css('display','flex');
|
|
|
+
|
|
|
self.fetchAccountVoucher().then(function (accountVoucher) {
|
|
|
return accountVoucher;
|
|
|
}).then(function (accountVoucher) {
|
|
@@ -40,17 +44,13 @@ function monthly_purchases(widget) {
|
|
|
return self.fetchAccountInvoice(accountVoucher);
|
|
|
}).then(function(accountInvoice){
|
|
|
self.accountInvoice = accountInvoice;
|
|
|
- return self.fetchCurrency();
|
|
|
- }).then(function(currencyRate){
|
|
|
- self.currencyRate = currencyRate;
|
|
|
return self.fetchResCompany();
|
|
|
}).then(function(resCompany){
|
|
|
self.resCompany = resCompany;
|
|
|
- return self.fetchResCurrecy(resCompany);
|
|
|
+ return self.fetchResCurrecy();
|
|
|
}).then(function(resCurrecy){
|
|
|
self.resCurrecy = resCurrecy;
|
|
|
return self.fetchReduceVoucher();
|
|
|
-
|
|
|
});
|
|
|
},
|
|
|
// Account Voucher Pagos a facturas Proveedores
|
|
@@ -62,9 +62,11 @@ function monthly_purchases(widget) {
|
|
|
var fields = ['id', 'amount', 'currency_id', 'payment_rate_currency_id', 'reference'];
|
|
|
var domain= [['type', '=', 'payment'],['state', '=', 'posted'],['date', '>=',desde],['date','<',hasta]];
|
|
|
var accountVoucher = new model.web.Model('account.voucher');
|
|
|
+
|
|
|
accountVoucher.query(fields).filter(domain).all().then(function(results){
|
|
|
defer.resolve(results);
|
|
|
});
|
|
|
+
|
|
|
return defer;
|
|
|
},
|
|
|
// invoice
|
|
@@ -75,19 +77,11 @@ function monthly_purchases(widget) {
|
|
|
var fields = ['id','number','date_invoice','origin'];
|
|
|
var domain = [['type', '=', 'in_invoice'],['origin', '!=', false ],['number', 'in', number]];
|
|
|
var accountInvoice= new model.web.Model('account.invoice');
|
|
|
+
|
|
|
accountInvoice.query(fields).filter(domain).all().then(function(results){
|
|
|
defer.resolve(results);
|
|
|
});
|
|
|
- return defer;
|
|
|
- },
|
|
|
- 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;
|
|
|
},
|
|
|
//Comapnia
|
|
@@ -105,72 +99,63 @@ function monthly_purchases(widget) {
|
|
|
return defer;
|
|
|
},
|
|
|
// Res currecy
|
|
|
- fetchResCurrecy : function(company){
|
|
|
+ fetchResCurrecy : function(){
|
|
|
var self = this;
|
|
|
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');
|
|
|
|
|
|
resCurrecy.query(fields).filter(domain).all().then(function(results){
|
|
|
defer.resolve(results);
|
|
|
});
|
|
|
+
|
|
|
return defer;
|
|
|
},
|
|
|
|
|
|
fetchReduceVoucher: function () {
|
|
|
- var self = this;
|
|
|
- var newVoucher;
|
|
|
+ var self = this
|
|
|
var voucher=[];
|
|
|
- var cat = 0;
|
|
|
+ var newVoucher = self.getVoucherInvoice();
|
|
|
var itemVoucher;
|
|
|
- var itemCurrencyRate;
|
|
|
- var company;
|
|
|
- var moneda = self.resCurrecy.shift();
|
|
|
- newVoucher = self.getVoucherInvoice();
|
|
|
+ var currencyVoucher;
|
|
|
+ var cat = 0;
|
|
|
+ var company = self.resCompany.shift();
|
|
|
+ var currencyBase = self.getCurrency(company.currency_id[0]).shift();
|
|
|
+
|
|
|
for (var i = 0; i < newVoucher.length; i++) {
|
|
|
itemVoucher = newVoucher[i];
|
|
|
- itemCurrencyRate = self.getCutrrencyRate(itemVoucher.payment_rate_currency_id[0]);
|
|
|
- if(!itemCurrencyRate){
|
|
|
- itemCurrencyRate={};
|
|
|
- itemCurrencyRate.rate=1;
|
|
|
+ currencyVoucher = self.getCurrency(itemVoucher.payment_rate_currency_id[0]).shift();
|
|
|
+
|
|
|
+ if(!currencyVoucher){
|
|
|
+ currencyVoucher={};
|
|
|
+ currencyVoucher.rate=currencyBase.rate_silent;
|
|
|
}
|
|
|
voucher.push({ ammount : itemVoucher.amount,
|
|
|
- amount_rate :(itemVoucher.amount/itemCurrencyRate.rate)
|
|
|
+ amount_rate :(itemVoucher.amount* (currencyBase.rate_silent/currencyVoucher.rate_silent))
|
|
|
});
|
|
|
}
|
|
|
- if (voucher.length >0){
|
|
|
+
|
|
|
+ if (voucher.length > 0){
|
|
|
cat = _.reduce(_.map(voucher, function (map) {
|
|
|
return map.amount_rate;
|
|
|
}), function (memo, num) {
|
|
|
return memo + num;
|
|
|
});
|
|
|
}
|
|
|
- company = _.map(self.resCompany, function (map) {
|
|
|
- return map.currency_id[1];
|
|
|
- });
|
|
|
|
|
|
- if (moneda.id != 166){
|
|
|
- cat = accounting.formatNumber(cat,2, ".", ",");
|
|
|
- }else{
|
|
|
- cat = accounting.formatNumber(cat, ",", ".");
|
|
|
- }
|
|
|
self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
- self.$el.find('.widget-content').find('a').text(cat).append(' <small>'+moneda.symbol+'</small>');
|
|
|
- // self.$el.find('.widget-footer').find('span').text("Monto en "+ company);
|
|
|
+ self.$el.find('.widget-content').find('a').text(accounting.formatMoney(cat, currencyBase.symbol, currencyBase.decimal_places, currencyBase.thousands_separator, currencyBase.decimal_separator))
|
|
|
self.$el.find('#morosidad').unblock();
|
|
|
},
|
|
|
- getCutrrencyRate: function (currency_id) {
|
|
|
+ // Obtener la moneda
|
|
|
+ getCurrency: function (id) {
|
|
|
var self = this;
|
|
|
- return _.filter(self.currencyRate,function (item) {
|
|
|
- return item.currency_id[0] == currency_id
|
|
|
- }).shift();
|
|
|
+ return _.filter(self.resCurrecy,function (item) {
|
|
|
+ return item.id === id
|
|
|
+ })
|
|
|
},
|
|
|
+ // obtneer los pagos con origin
|
|
|
getVoucherInvoice:function(){
|
|
|
var self = this;
|
|
|
var number = _.map(self.accountInvoice, function(map){
|
|
@@ -180,6 +165,7 @@ function monthly_purchases(widget) {
|
|
|
return _.contains(number,item.reference);
|
|
|
}));
|
|
|
},
|
|
|
+ // modal
|
|
|
showCustomers: function (e) {
|
|
|
var self = this;
|
|
|
var hoy =moment().format('YYYY-MM-DD');
|