|
@@ -0,0 +1,148 @@
|
|
|
+function payments_today_counters (widget) {
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model= openerp;
|
|
|
+
|
|
|
+ widget.PaymentsTodayCountersWidget = widget.Base.extend({
|
|
|
+ template: 'PaymentsTodayCounters',
|
|
|
+ accountVoucher: [],
|
|
|
+ resCompany: [],
|
|
|
+ currencyRate: [],
|
|
|
+
|
|
|
+ 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({
|
|
|
+ message: null,
|
|
|
+ overlayCSS: {
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$el.find('.widget-content.widget-loading').css('display','flex');
|
|
|
+ self.fetchAccountVoucher().then(function (accountVoucher) {
|
|
|
+ return accountVoucher;
|
|
|
+ }).then(function (accountVoucher) {
|
|
|
+ self.accountVoucher = accountVoucher;
|
|
|
+ return self.fetchResCompany();
|
|
|
+ }).then(function (resCompany) {
|
|
|
+ self.resCompany = resCompany;
|
|
|
+ return self.fetchCurrency();
|
|
|
+ }).then(function (currencyRate) {
|
|
|
+ self.currencyRate = currencyRate;
|
|
|
+ return self.fetchVoucherCurrency();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Account Voucher
|
|
|
+ fetchAccountVoucher: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var hoy =moment().format('YYYY-MM-DD');
|
|
|
+ var fields = ['id', 'amount', 'currency_id', 'payment_rate_currency_id'];
|
|
|
+ var domain = [['state', '=', 'posted'], ['type', '=', 'payment'], ['date', '=', hoy]];
|
|
|
+ var accountVoucher = new model.web.Model('account.voucher');
|
|
|
+
|
|
|
+ accountVoucher.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ //Comapnia
|
|
|
+ fetchResCompany: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields =['id','name', 'currency_id','logo'];
|
|
|
+ var domain =[['id', '=', 1]];
|
|
|
+ var resCompany = new model.web.Model('res.company');
|
|
|
+
|
|
|
+ resCompany.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ 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', '=', [166 , 20, 7, 3]]];
|
|
|
+
|
|
|
+ currency_Rate.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // voucherCurrencyRate
|
|
|
+ fetchVoucherCurrency: function () {
|
|
|
+ var self = this;
|
|
|
+ var newVoucher=[];
|
|
|
+ var itemvoucher;
|
|
|
+ var itemCurrencyRate;
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ newVoucher.push({ amount : itemvoucher.amount,
|
|
|
+ amount_rate : (itemvoucher.amount/itemCurrencyRate.rate)
|
|
|
+ });
|
|
|
+ }
|
|
|
+ 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];
|
|
|
+ });
|
|
|
+ if (newVoucher.length > 0) {
|
|
|
+ residual = _.reduce(_.map(newVoucher, function (map) {
|
|
|
+ return map.amount_rate;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
+ self.$el.find('.widget-content').find('a').text(accounting.formatNumber(residual, 2, ".", ","));
|
|
|
+ self.$el.find('.widget-footer').find('span').text("Monto en "+ company);
|
|
|
+ self.$el.find('#morosidad').unblock();
|
|
|
+ },
|
|
|
+ showCustomers: function (e) {
|
|
|
+ var hoy =moment().format('YYYY-MM-DD');
|
|
|
+
|
|
|
+ this.do_action({
|
|
|
+ name:"Cobros de Hoy",
|
|
|
+ type: 'ir.actions.act_window',
|
|
|
+ res_model: "account.voucher",
|
|
|
+ views: [[false, 'list']],
|
|
|
+ target: 'new',
|
|
|
+ domain: [['state', '=', 'posted'], ['type', '=', 'payment'], ['date', '=', hoy]],
|
|
|
+ context: {},
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|