|
@@ -0,0 +1,907 @@
|
|
|
+function report_customer_ratings(reporting){
|
|
|
+ "use strict";
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportCustomerRatingsWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportCustomerRatings',
|
|
|
+ rowsData :[],
|
|
|
+ content :[],
|
|
|
+
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #generate' : 'fetchGenerate',
|
|
|
+ 'change #current-company' : 'updateSelections',
|
|
|
+ 'change #current-period' : 'updatePeriodSelections',
|
|
|
+ 'change #current-date' : 'ShowDateRange',
|
|
|
+ },
|
|
|
+
|
|
|
+ init: function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function(){
|
|
|
+ var self = this;
|
|
|
+ var date = new model.eiru_reports.ReportDatePickerWidget(self);
|
|
|
+ date.fecthFecha();
|
|
|
+ this.fetchInitial();
|
|
|
+ },
|
|
|
+
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor = "";
|
|
|
+ if (dato){
|
|
|
+ valor = dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ ShowDateRange : function(){
|
|
|
+ var self = this;
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ if(date == 'range'){
|
|
|
+ self.$el.find('.datepicker').css('display','block');
|
|
|
+ }
|
|
|
+ if(date != 'range'){
|
|
|
+ self.$el.find('.datepicker').css('display','none');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInitial: function(){
|
|
|
+ var self = this;
|
|
|
+ self.fecthIrModuleModule().then(function(IrModuleModule){
|
|
|
+ return IrModuleModule;
|
|
|
+ }).then(function(IrModuleModule){
|
|
|
+ self.IrModuleModule = IrModuleModule;
|
|
|
+ return self.fetchResUser;
|
|
|
+ }).then(function (ResUser){
|
|
|
+ self.ResUser = ResUser;
|
|
|
+ return self.fetchResCompany();
|
|
|
+ }).then(function(ResCompany){
|
|
|
+ self.ResCompany = ResCompany;
|
|
|
+ if(ResCompany.length > 1){
|
|
|
+ self.$el.find('#current-company').append('<option value="9999999">Todas las empresas</option>');
|
|
|
+ _.each(ResCompany,function(item){
|
|
|
+ self.$el.find('#current-company').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.company').css('display','none');
|
|
|
+ }
|
|
|
+ return self.fetchResStore();
|
|
|
+ }).then(function(ResStore){
|
|
|
+ self.ResStore = ResStore;
|
|
|
+ if(ResStore.length > 1){
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
+ _.each(ResStore,function(item){
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.store').css('display','none');
|
|
|
+ }
|
|
|
+ return self.fetchAccountPeriod();
|
|
|
+ }).then(function(AccountPeriod){
|
|
|
+ self.AccountPeriod = AccountPeriod;
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todos los periodos</option>');
|
|
|
+ _.each(AccountPeriod,function(item){
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fetchResCurrency();
|
|
|
+ }).then(function(ResCurrency){
|
|
|
+ self.ResCurrency = ResCurrency;
|
|
|
+ return self.fetchResPartner();
|
|
|
+ }).then(function(ResPartner){
|
|
|
+ self.ResPartner = ResPartner;
|
|
|
+ self.$el.find('#current-partner').append('<option value="9999999">Todos los clientes</option>');
|
|
|
+ _.each(ResPartner,function(item){
|
|
|
+ self.$el.find('#current-partner').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fetchAccountJournal();
|
|
|
+ }).then(function(AccountJournal){
|
|
|
+ self.AccountJournal = AccountJournal;
|
|
|
+ });
|
|
|
+ self.$el.find('#generate').css('display','inline');
|
|
|
+ return;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchGenerate: function(){
|
|
|
+ var self = this;
|
|
|
+ self.$el.find('.search-form').block({
|
|
|
+ message: null,
|
|
|
+ overlayCSS: {
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$el.find('.report-form').block({
|
|
|
+ message: null,
|
|
|
+ overlayCSS: {
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ this.fetchAccountInvoice().then(function(AccountInvoice) {
|
|
|
+ return AccountInvoice;
|
|
|
+ }).then(function (AccountInvoice) {
|
|
|
+ self.AccountInvoice = AccountInvoice;
|
|
|
+ return self.fetchAccountMoveLine();
|
|
|
+ }).then(function (AccountMoveLine){
|
|
|
+ self.AccountMoveLine = AccountMoveLine;
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*=====================================================================
|
|
|
+ IR MODULE
|
|
|
+ =====================================================================*/
|
|
|
+ fecthIrModuleModule: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['name','id'];
|
|
|
+ var domain=[['state','=','installed']];
|
|
|
+ var IrModuleModule = new model.web.Model('ir.module.module');
|
|
|
+ IrModuleModule.query(fields).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ })
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*
|
|
|
+ =====================================================================
|
|
|
+ USER
|
|
|
+ =====================================================================
|
|
|
+ */
|
|
|
+ fetchResUser: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name','store_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);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*
|
|
|
+ =====================================================================
|
|
|
+ PARTNER
|
|
|
+ =====================================================================
|
|
|
+ */
|
|
|
+ fetchResPartner: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name'];
|
|
|
+ var domain = [
|
|
|
+ ['active','=', true],
|
|
|
+ ['customer','=', true]];
|
|
|
+ var ResPartner = new model.web.Model('res.partner');
|
|
|
+ ResPartner.query(fields).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ /*
|
|
|
+ =====================================================================
|
|
|
+ ACCOUNT PERIOD
|
|
|
+ =====================================================================
|
|
|
+ */
|
|
|
+ fetchAccountPeriod: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var domain = [['special','=',false]];
|
|
|
+ var field =['id', 'name', 'date_start','date_stop','company_id'];
|
|
|
+ var AccountPeriod = new model.web.Model('account.period');
|
|
|
+ AccountPeriod.query(field).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ /*
|
|
|
+ ====================================================================
|
|
|
+ RES STORE
|
|
|
+ ====================================================================
|
|
|
+ */
|
|
|
+ fetchResStore: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var field = ['id','name','company_id'];
|
|
|
+ var ResStore = new model.web.Model('res.store');
|
|
|
+ ResStore.query(field).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ /*
|
|
|
+ ====================================================================
|
|
|
+ ACCOUNT JOURNAL
|
|
|
+ ====================================================================
|
|
|
+ */
|
|
|
+ fetchAccountJournal: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var company = $('#current-company').val();
|
|
|
+ var store = $('#current-store').val();
|
|
|
+ var domain = [['active','=',true],['type','=','sale']];
|
|
|
+ if(company && company != 9999999){
|
|
|
+ domain.push(['company_id','=',parseFloat(company)]);
|
|
|
+ }
|
|
|
+ if(store && store != 9999999){
|
|
|
+ domain.push(['store_ids','=',parseFloat(store)]);
|
|
|
+ }
|
|
|
+ var field = ['id', 'name','store_ids'];
|
|
|
+ var AccountJournal = new model.web.Model('account.journal');
|
|
|
+ AccountJournal.query(field).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ /*
|
|
|
+ ====================================================================
|
|
|
+ ACCOUNT INVOICE
|
|
|
+ ====================================================================
|
|
|
+ */
|
|
|
+ fetchAccountInvoice: function(){
|
|
|
+ var self = this;
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var journal = self.$el.find('#current-journal').val();
|
|
|
+ var partner = self.$el.find('#current-partner').val();
|
|
|
+
|
|
|
+ if(store && store != 9999999){
|
|
|
+ var journal_ids = _.map(_.filter(self.AccountJournal,function(item){
|
|
|
+ return item.store_ids == store;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ var journal_ids = _.flatten(_.map(self.AccountJournal, function(item){
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ var domain = [
|
|
|
+ ['state', 'in',['open']],
|
|
|
+ ['type', '=', 'out_invoice'],
|
|
|
+ ['journal_id','in',journal_ids],
|
|
|
+ ];
|
|
|
+ if(journal && journal != 9999999){
|
|
|
+ domain.push(['journal_id','=',parseInt(journal)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(partner && partner != 9999999){
|
|
|
+ domain.push(['partner_id','=',parseInt(partner)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
+ return AccountInvoice.call('getAccountInvoice',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /*
|
|
|
+ ====================================================================
|
|
|
+ ACCOUNT INVOICE LINE
|
|
|
+ ====================================================================
|
|
|
+ */
|
|
|
+ fetchAccountMoveLine: function(){
|
|
|
+ var self = this;
|
|
|
+ var invoice_numbers = _.flatten(_.map(self.AccountInvoice, function(item){
|
|
|
+ return item.number;
|
|
|
+ }));
|
|
|
+ var domain = [
|
|
|
+ ['move_id','in',invoice_numbers],
|
|
|
+ ['debit','>',0],
|
|
|
+ ];
|
|
|
+
|
|
|
+ var AccountMoveLine = new model.web.Model('account.move.line');
|
|
|
+ return AccountMoveLine.call('getAccountMoveLine',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /*
|
|
|
+ ====================================================================
|
|
|
+ RES COMPANY
|
|
|
+ ====================================================================
|
|
|
+ */
|
|
|
+ fetchResCompany: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency = new model.web.Model('res.company');
|
|
|
+ var field=['id','name','currency_id','logo'];
|
|
|
+ currency.query(field).filter().all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ /*
|
|
|
+ ====================================================================
|
|
|
+ RES CURRENCY
|
|
|
+ ====================================================================
|
|
|
+ */
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*
|
|
|
+ ====================================================================
|
|
|
+ UPDATE SELECTIONS
|
|
|
+ ====================================================================
|
|
|
+ */
|
|
|
+ updateSelections: function(){
|
|
|
+ var self = this;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ if(company != 9999999){
|
|
|
+ /*===================
|
|
|
+ STORE SELECTION
|
|
|
+ ===================*/
|
|
|
+ var store = self.$el.find('#current-store').empty();
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
+ _.each(self.ResStore,function(item){
|
|
|
+ if(parseFloat(company) == item.company_id[0]){
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /*====================
|
|
|
+ PERIOD SELECTION
|
|
|
+ ====================*/
|
|
|
+ var period = self.$el.find('#current-period').empty();
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todos los periodos</option>');
|
|
|
+ _.each(self.AccountPeriod,function(item){
|
|
|
+ if(parseFloat(company) == item.company_id[0]){
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ /*===================
|
|
|
+ STORE SELECTION
|
|
|
+ ===================*/
|
|
|
+ var store = self.$el.find('#current-store').empty();
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
+ _.each(self.ResStore,function(item){
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ /*====================
|
|
|
+ PERIOD SELECTION
|
|
|
+ ====================*/
|
|
|
+ var period = self.$el.find('#current-period').empty();
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todos los periodos</option>');
|
|
|
+ _.each(self.AccountPeriod,function(item){
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updatePeriodSelections: function(){
|
|
|
+ var self = this;
|
|
|
+ var period = self.$el.find('#current-period').val();
|
|
|
+ if(period != 9999999){
|
|
|
+ self.$el.find('#current-date').val(9999999);
|
|
|
+ self.$el.find('#current-date').prop('disabled','disabled');
|
|
|
+ self.$el.find('.datepicker').css('display','none');
|
|
|
+ }else{
|
|
|
+ self.$el.find('#current-date').prop('disabled',false);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET RES COMPANY
|
|
|
+ ====================================================================*/
|
|
|
+ getResCompany: function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCompany,function(item){
|
|
|
+ return item.id == id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET RES CURRENCY BASE
|
|
|
+ ====================================================================*/
|
|
|
+ getResCurrency: function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency,function(item){
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET ACCOUNT MOVE LINE
|
|
|
+ ====================================================================*/
|
|
|
+ getAccountMoveLine: function(number){
|
|
|
+ var self = this;
|
|
|
+ var period = self.$el.find('#current-period').val();
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
+ var AccountMoveLine = _.filter(self.AccountMoveLine,function(item){
|
|
|
+ return item.move_id[1] == number;
|
|
|
+ });
|
|
|
+ var x = AccountMoveLine.length;
|
|
|
+ var i = AccountMoveLine.length;
|
|
|
+
|
|
|
+ var content =_.map(AccountMoveLine, function(item2){
|
|
|
+ if(item2.date_maturity != false){
|
|
|
+ item2.dues_name= 'Cuota ' + i +' / ' + x;
|
|
|
+ i--;
|
|
|
+ return item2;
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ if(date && date != 9999999){
|
|
|
+ if(date == 'range'){
|
|
|
+ if(desde){
|
|
|
+ var date = desde.split('/')
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ content = _.flatten(_.filter(content,function(item){
|
|
|
+ return item.date_maturity >= date;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(hasta){
|
|
|
+ var date = hasta.split('/')
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ content = _.flatten(_.filter(content,function(item){
|
|
|
+ return item.date_maturity <= date;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(date == 'today'){
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
+ content = _.flatten(_.filter(content,function(item){
|
|
|
+ return item.date_maturity == today;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'yesterday'){
|
|
|
+ var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
|
|
|
+ content = _.flatten(_.filter(content,function(item){
|
|
|
+ return item.date_maturity == yesterday;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(date == 'currentMonth'){
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
+ content = _.flatten(_.filter(content,function(item){
|
|
|
+ return moment(item.date_maturity,'YYYY-MM-DD').format('YYYY-MM') == currentMonth;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(date == 'lastMonth'){
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM');
|
|
|
+ content = _.flatten(_.filter(content,function(item){
|
|
|
+ return moment(item.date_maturity,'YYYY-MM-DD').format('YYYY-MM') == lastMonth;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(period && period != 9999999){
|
|
|
+ var periodo = _.flatten(_.filter(self.AccountPeriod,function (item) {
|
|
|
+ return item.id == period;
|
|
|
+ }));
|
|
|
+
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return moment(item.date_maturity,'YYYY-MM-DD').format('MM/YYYY') == periodo[0].name;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ content = _.filter(content,function(item){
|
|
|
+ return item != undefined;
|
|
|
+ })
|
|
|
+ return content;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ /*============================
|
|
|
+ GET INVOICE
|
|
|
+ ============================*/
|
|
|
+ getAccountInvoice:function(partner_id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.AccountInvoice,function(item){
|
|
|
+ return item.partner_id[0] === partner_id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ BUILD
|
|
|
+ ====================================================================*/
|
|
|
+ BuildTable: function(){
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ var company = $('#current-company').val();
|
|
|
+ var state = $('#current-state').val();
|
|
|
+
|
|
|
+ if(company && company != 9999999){
|
|
|
+ var ResCompany = self.getResCompany(company).shift();
|
|
|
+ var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
|
|
|
+ }else{
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+
|
|
|
+ var ResPartner = self.ResPartner;
|
|
|
+
|
|
|
+ _.each(ResPartner, function(item){
|
|
|
+ var info = [];
|
|
|
+ var due_qty=0;
|
|
|
+ var amount=0;
|
|
|
+
|
|
|
+ var AccountInvoice = self.getAccountInvoice(item.id);
|
|
|
+
|
|
|
+ _.each(AccountInvoice, function(item){
|
|
|
+
|
|
|
+ var AccountMoveLine = self.getAccountMoveLine(item.number);
|
|
|
+ var Currency = self.getResCurrency(item.invoice_currency[0]).shift();
|
|
|
+
|
|
|
+ _.each(AccountMoveLine, function(index){
|
|
|
+
|
|
|
+ var date;
|
|
|
+
|
|
|
+ var state = 'Vencido';
|
|
|
+ if(index.reconcile_ref){
|
|
|
+ if(index.amount_residual == 0){
|
|
|
+ state = 'Pagado';
|
|
|
+ }
|
|
|
+ if(index.amount_residual > 0){
|
|
|
+ var value = accounting.formatMoney(index.credit - index.amount_residual, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator);
|
|
|
+ state = 'Amortizado ' + ' (' + value + ')';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ date = moment(index.date_maturity,'YYYY-MM-DD').format('DD/MM/YYYY');
|
|
|
+ if(state != 'Pagado'){
|
|
|
+
|
|
|
+ if(index.date_maturity < moment().format('YYYY-MM-DD')){
|
|
|
+
|
|
|
+ due_qty++;
|
|
|
+
|
|
|
+ var days_of_delays = moment().diff(moment(index.date_maturity), 'days');
|
|
|
+
|
|
|
+ amount = amount + index.amount_residual;
|
|
|
+
|
|
|
+ info.push({
|
|
|
+ invoice_id : item.id,
|
|
|
+ invoice : item.number,
|
|
|
+ partner_ruc : self.valorNull(item.partner_id[2]),
|
|
|
+ partner_name : item.partner_id[1],
|
|
|
+ date : date,
|
|
|
+ name : index.dues_name,
|
|
|
+ state : state,
|
|
|
+ days_of_delays: days_of_delays,
|
|
|
+ amount : accounting.formatMoney(index.credit, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ residual : accounting.formatMoney(index.amount_residual, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ invoice_residual : accounting.formatMoney(item.residual, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+
|
|
|
+ invoice_residual_no_format : item.residual,
|
|
|
+ amount_no_format : index.credit,
|
|
|
+ residual_no_format : index.amount_residual,
|
|
|
+
|
|
|
+ decimal_places : CurrencyBase.decimal_places,
|
|
|
+ thousands_separator : CurrencyBase.thousands_separator,
|
|
|
+ decimal_separator : CurrencyBase.decimal_separator,
|
|
|
+ });
|
|
|
+
|
|
|
+ };
|
|
|
+ };
|
|
|
+
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ if(info.length > 0){
|
|
|
+
|
|
|
+ var max_days_of_delay= info.reduce((max, p) => p.days_of_delays > max ? p.days_of_delays : max, info[0].days_of_delays);
|
|
|
+
|
|
|
+ info.sort(function(a, b){
|
|
|
+ if(state == 'day_of_delay'){
|
|
|
+ var x = a.days_of_delays;
|
|
|
+ var y = b.days_of_delays;
|
|
|
+ };
|
|
|
+
|
|
|
+ if(state == 'amount_delay'){
|
|
|
+ var x = a.residual_no_format;
|
|
|
+ var y = b.residual_no_format;
|
|
|
+ };
|
|
|
+
|
|
|
+ if (x > y) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (x < y) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
+
|
|
|
+ data.push({
|
|
|
+ partner_name : item.name,
|
|
|
+ due_qty:due_qty,
|
|
|
+ max_days_of_delay: max_days_of_delay,
|
|
|
+ amount: accounting.formatMoney(amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+
|
|
|
+ amount_no_format: amount,
|
|
|
+
|
|
|
+ info: info,
|
|
|
+
|
|
|
+ decimal_places : CurrencyBase.decimal_places,
|
|
|
+ thousands_separator : CurrencyBase.thousands_separator,
|
|
|
+ decimal_separator : CurrencyBase.decimal_separator,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ data.sort(function(a, b){
|
|
|
+
|
|
|
+ if(state == 'day_of_delay'){
|
|
|
+ var x = a.max_days_of_delay;
|
|
|
+ var y = b.max_days_of_delay;
|
|
|
+ };
|
|
|
+ if(state == 'due_qty'){
|
|
|
+ var x = a.due_qty;
|
|
|
+ var y = b.due_qty;
|
|
|
+ }
|
|
|
+ if(state == 'amount_delay'){
|
|
|
+ var x = a.amount_no_format;
|
|
|
+ var y = b.amount_no_format;
|
|
|
+ };
|
|
|
+
|
|
|
+ if (x > y) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (x < y) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
+
|
|
|
+ self.content = data;
|
|
|
+ self.loadTable(data);
|
|
|
+ self.$el.find('.report-form').css('display','block');
|
|
|
+ self.$el.find('.search-form').unblock();
|
|
|
+ self.$el.find('.report-form').unblock();
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ LOAD BOOTSTRAP TABLE
|
|
|
+ ====================================================================*/
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+
|
|
|
+ table.bootstrapTable({
|
|
|
+ data:rowsTable,
|
|
|
+ detailView: true,
|
|
|
+ onExpandRow: function(index, row, $detail){
|
|
|
+ $detail.html('<div class="panel panel-first-style"><div class="panel-heading panel-header-first-style">Cuotas vencidas</div><table id="table2"></table></div>').find('table').bootstrapTable({
|
|
|
+ columns: [
|
|
|
+ {
|
|
|
+ field: 'invoice',
|
|
|
+ title: 'Factura',
|
|
|
+ align: 'center',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'name',
|
|
|
+ title: 'Cuota',
|
|
|
+ align: 'center',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'date',
|
|
|
+ title: 'Fecha Vencimiento',
|
|
|
+ align: 'center',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'state',
|
|
|
+ title: 'Estado',
|
|
|
+ align: 'center',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'days_of_delays',
|
|
|
+ title: 'Días atrasados',
|
|
|
+ align: 'center',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'amount',
|
|
|
+ title: 'Total',
|
|
|
+ align: 'right',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'residual',
|
|
|
+ title: 'Saldo',
|
|
|
+ align: 'right',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'invoice_residual',
|
|
|
+ title: 'Saldo Factura',
|
|
|
+ align: 'right',
|
|
|
+ }
|
|
|
+ ],
|
|
|
+
|
|
|
+ data:row.info,
|
|
|
+ })
|
|
|
+ $('#table2').removeClass('table-hover').addClass('table-no-bordered');
|
|
|
+ $('thead').css('background','none');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ table.bootstrapTable('load', rowsTable);
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ PRINT PDF
|
|
|
+ ====================================================================*/
|
|
|
+ clickOnAction: function(e){
|
|
|
+ var self = this;
|
|
|
+ var ResCompany;
|
|
|
+ var action = this.$el.find(e.target).val();
|
|
|
+ var company = $('#current-company').val();
|
|
|
+
|
|
|
+ if(company && company != 9999999){
|
|
|
+ ResCompany = self.getResCompany(company).shift();
|
|
|
+ }else{
|
|
|
+ ResCompany = self.ResCompany[0];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var table = this.$el.find("#table");
|
|
|
+ var row = table.bootstrapTable('getData');
|
|
|
+
|
|
|
+
|
|
|
+ if (action === 'pdf') {
|
|
|
+
|
|
|
+ var pdf_title = 'Calificación de Cliente.';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'calificacion_de_clientes_';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ invoice: {
|
|
|
+ columnWidth: 30,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ name: {
|
|
|
+ columnWidth: 18,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+
|
|
|
+ date: {
|
|
|
+ columnWidth: 22,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+
|
|
|
+ state: {
|
|
|
+ columnWidth: 20,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+
|
|
|
+ days_of_delays: {
|
|
|
+ columnWidth: 20,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+
|
|
|
+ amount: {
|
|
|
+ columnWidth: 25,
|
|
|
+ halign: 'right'
|
|
|
+ },
|
|
|
+
|
|
|
+ residual: {
|
|
|
+ columnWidth: 25,
|
|
|
+ halign: 'right'
|
|
|
+ },
|
|
|
+
|
|
|
+ invoice_residual: {
|
|
|
+ columnWidth: 25,
|
|
|
+ halign: 'right'
|
|
|
+ },
|
|
|
+ };
|
|
|
+ /*
|
|
|
+ ============================================================
|
|
|
+ LLAMAR FUNCION DE IMPRESION
|
|
|
+ ============================================================
|
|
|
+ */
|
|
|
+ var filter =self.getFilter();
|
|
|
+ var pdf = new reporting.ReportPdfWidget(self);
|
|
|
+ pdf.drawStarPdf(
|
|
|
+ row,
|
|
|
+ ResCompany,
|
|
|
+ pdf_title,
|
|
|
+ pdf_type,
|
|
|
+ pdf_name,
|
|
|
+ pdf_columnStyles,
|
|
|
+ filter
|
|
|
+ );
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ getFilter: function(){
|
|
|
+ var self = this;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var partner = self.$el.find('#current-partner').val();
|
|
|
+ var state = self.$el.find('#current-state').val();
|
|
|
+ var period = self.$el.find('#current-period').val();
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
+
|
|
|
+ var filter = [];
|
|
|
+
|
|
|
+ if(company && company != 9999999){
|
|
|
+ var ResCompany = _.filter(self.ResCompany, function(item){
|
|
|
+ return item.id == company;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title:'Empresa',
|
|
|
+ value: ResCompany[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(store && store != 9999999){
|
|
|
+ var ResStore = _.filter(self.ResStore,function(item){
|
|
|
+ return item.id == store;
|
|
|
+ });
|
|
|
+
|
|
|
+ filter.push({
|
|
|
+ title: 'Sucursal',
|
|
|
+ value: ResStore[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(partner && partner != 9999999){
|
|
|
+ var ResPartner = _.filter(self.ResPartner,function(item){
|
|
|
+ return item.id == partner;
|
|
|
+ });
|
|
|
+
|
|
|
+ filter.push({
|
|
|
+ title: 'Cliente',
|
|
|
+ value: ResPartner[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(state && state != 9999999){
|
|
|
+ filter.push({
|
|
|
+ title: 'Ordenado por',
|
|
|
+ value: $("#current-state option:selected").text(),
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(period && period != 9999999){
|
|
|
+
|
|
|
+ var AccountPeriod = _.filter(self.AccountPeriod,function(item){
|
|
|
+ return item.id == period;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Periodo',
|
|
|
+ value: AccountPeriod[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date && date != 9999999){
|
|
|
+ moment.locale('es', {
|
|
|
+ months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
|
|
|
+ });
|
|
|
+
|
|
|
+ if(date == 'range'){
|
|
|
+ filter.push({
|
|
|
+ title: 'Fecha',
|
|
|
+ value: desde +' al '+hasta,
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if(date == 'today'){
|
|
|
+ var fecha = moment().format('DD/MM/YYYY');
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'yesterday'){
|
|
|
+ var fecha = moment().add(-1,'days').format('DD/MM/YYYY');
|
|
|
+ }
|
|
|
+ if(date == 'currentMonth'){
|
|
|
+ var fecha = moment().format('MMMM/YYYY');
|
|
|
+ }
|
|
|
+ if(date == 'lastMonth'){
|
|
|
+ var fecha = moment().add(-1,'months').format('MMMM/YYYY');
|
|
|
+ }
|
|
|
+
|
|
|
+ filter.push({
|
|
|
+ title: 'Fecha',
|
|
|
+ value: fecha,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return filter;
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|