|
@@ -0,0 +1,190 @@
|
|
|
|
+function widget_account_receivable(widget) {
|
|
|
|
+ "use strict";
|
|
|
|
+
|
|
|
|
+ var model = openerp;
|
|
|
|
+
|
|
|
|
+ widget.WidgetAccountReceivableWidget = widget.Base.extend({
|
|
|
|
+ template: 'WidgetAccountReceivable',
|
|
|
|
+
|
|
|
|
+ events: {
|
|
|
|
+ 'click .today': 'showToday',
|
|
|
|
+ 'click .thisWeek': 'showThisWeek',
|
|
|
|
+ 'click .expire': 'showExpire',
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ 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.fetchAccountMoveLine().then(function (AccountMoveLine) {
|
|
|
|
+ return AccountMoveLine;
|
|
|
|
+ }).then(function (AccountMoveLine) {
|
|
|
|
+ self.AccountMoveLine = _.filter(AccountMoveLine, function(item) {
|
|
|
|
+ return item.amount_residual > 0
|
|
|
|
+ });
|
|
|
|
+ return self.fetchAccountInvoice();
|
|
|
|
+ }).then(function(AccountInvoice) {
|
|
|
|
+ self.AccountInvoice = AccountInvoice;
|
|
|
|
+ return self.fetchResCompany();
|
|
|
|
+ }).then(function(ResCompany) {
|
|
|
|
+ self.ResCompany = ResCompany;
|
|
|
|
+ return self.fetchResCurrecy();
|
|
|
|
+ }).then(function(ResCurrecy) {
|
|
|
|
+ self.ResCurrecy = ResCurrecy;
|
|
|
|
+ return self.showExpire();
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchAccountMoveLine: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var fields = ['id', 'partner_id', 'amount_residual', 'credit', 'debit', 'date_maturity', 'invoice','ref', 'invoice', 'amount_residual_currency', 'currency_id'];
|
|
|
|
+ var domain = [['credit', '<=', 0],['date_maturity', '!=', false]];
|
|
|
|
+ var AccountMoveLine = new model.web.Model('account.move.line');
|
|
|
|
+ AccountMoveLine.query(fields).filter(domain).all().then(function(results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchAccountInvoice: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var ref = _.map(self.AccountMoveLine, function(map) {
|
|
|
|
+ return map.invoice[0];
|
|
|
|
+ });
|
|
|
|
+ var fields = ['id', 'currency_id', 'number', 'currency_id'];
|
|
|
|
+ var domain = [['id', 'in', ref]];
|
|
|
|
+ var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
|
+ AccountInvoice.query(fields).filter(domain).all().then(function(results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchResCompany: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var fields = ['id','name', 'currency_id'];
|
|
|
|
+ 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;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchResCurrecy : 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 ResCurrecy = new model.web.Model('res.currency');
|
|
|
|
+ ResCurrecy.query(fields).filter(domain).all().then(function(results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getResCurrency: function (id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ return _.filter(self.ResCurrecy,function (item) {
|
|
|
|
+ return item.id === id;
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getTodayAccountMoveLive:function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var date = moment().format('YYYY-MM-DD');
|
|
|
|
+ return _.flatten(_.filter(self.AccountMoveLine,function (inv) {
|
|
|
|
+ return moment(inv.date_maturity).format('YYYY-MM-DD') === date;
|
|
|
|
+ }));
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getThisWeekAccountMoveLive:function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var week = moment().week();
|
|
|
|
+ return _.flatten(_.filter(self.AccountMoveLine,function (inv) {
|
|
|
|
+ return moment(inv.date_maturity).week() === week & moment(inv.date_maturity).format('YYYY')=== moment().format('YYYY');
|
|
|
|
+ }));
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getExpireAccountMoveLive:function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ return _.flatten(_.filter(self.AccountMoveLine,function (inv) {
|
|
|
|
+ return moment(inv.date_maturity).format('YYYY-MM-DD') < moment().format('YYYY-MM-DD');
|
|
|
|
+ }));
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ showToday: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ var amount = 0;
|
|
|
|
+ var data = [];
|
|
|
|
+ var MoveLine = self.getTodayAccountMoveLive();
|
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
|
+ if(MoveLine.length > 0){
|
|
|
|
+ amount = _.reduce(_.map(MoveLine, function (map) {
|
|
|
|
+ return map.amount_residual;
|
|
|
|
+ }), 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.formatMoney(amount, CurrencyBase.symbol, CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator))
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ showThisWeek: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ var amount = 0;
|
|
|
|
+ var data = [];
|
|
|
|
+ var MoveLine = self.getThisWeekAccountMoveLive();
|
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
|
+ if(MoveLine.length > 0){
|
|
|
|
+ amount = _.reduce(_.map(MoveLine, function (map) {
|
|
|
|
+ return map.amount_residual;
|
|
|
|
+ }), 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.formatMoney(amount, CurrencyBase.symbol, CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator))
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ showExpire: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ var amount = 0;
|
|
|
|
+ var data = [];
|
|
|
|
+ var MoveLine = self.getExpireAccountMoveLive();
|
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
|
+ if(MoveLine.length > 0){
|
|
|
|
+ amount = _.reduce(_.map(MoveLine, function (map) {
|
|
|
|
+ return map.amount_residual;
|
|
|
|
+ }), 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.formatMoney(amount, CurrencyBase.symbol, CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator))
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+}
|