Ver código fonte

[FIX] forma de importar el pagos de Nómina en caja desde el Procesamientos de nóminas

adrielso 7 anos atrás
pai
commit
84f53e115b
1 arquivos alterados com 125 adições e 40 exclusões
  1. 125 40
      static/src/js/payslip_payments.js

+ 125 - 40
static/src/js/payslip_payments.js

@@ -13,6 +13,9 @@ openerp.eiru_payslip_payments = function(instance, local) {
         company: [],
         currency: [],
         payslipNew: [],
+        eiruAccountBankUtatementUtility: [],
+        statementConfig: [],
+        statementAvailable: [],
 
         init: function(parent) {
             this._super(parent);
@@ -59,6 +62,15 @@ openerp.eiru_payslip_payments = function(instance, local) {
                 return self.fectchCurency();
             }).then(function(currency) {
                 self.currency = currency;
+                return self.fetchVerifyModule('eiru_account_bank_statement_utility');
+            }).then(function(eiruAccountBankUtatementUtility) {
+                self.eiruAccountBankUtatementUtility = eiruAccountBankUtatementUtility;
+                return self.fetchStatementConfig();
+            }).then(function(statementConfig) {
+                self.statementConfig = statementConfig;
+                return self.fetchStatementAvailable();
+            }).then(function(statementAvailable) {
+                self.statementAvailable = statementAvailable;
                 return self.joinPayslip();
             }).then(function(payslipNew) {
                 self.payslipNew = payslipNew;
@@ -133,6 +145,34 @@ openerp.eiru_payslip_payments = function(instance, local) {
 
             return defer;
         },
+        /* Verificar modulo instalados */
+        fetchVerifyModule: function(module) {
+            if (!module)
+                return [];
+            var moduleModule =new openerp.web.Model('ir.module.module');
+            var fields = ['id', 'name', 'state'];
+            var domain = [['name', '=', module], ['state', '=', 'installed']];
+            return moduleModule.query(fields).filter(domain).all();
+        },
+        /* statement Config */
+        fetchStatementConfig: function() {
+            var self = this;
+            if (!self.eiruAccountBankUtatementUtility.length)
+                return [];
+
+            var fields = ['id','name', 'active', 'import_statement_payslip', 'import_statement_payslip'];
+            var domain = [['active', '=', true]];
+            var statementConfig = new openerp.web.Model('account.bank.statement.config');
+            return statementConfig.query(fields).filter(domain).all();
+        },
+        /* Get statement Available*/
+        fetchStatementAvailable: function() {
+            var self = this;
+            var statementAvailable = new openerp.web.Model('hr.payslip');
+            return statementAvailable.call('get_bank_statement_available',{
+                    context: new openerp.web.CompoundContext()
+            });
+        },
         // get payslipLine
         getPayslipLine: function(slip_id) {
             var self = this;
@@ -175,16 +215,30 @@ openerp.eiru_payslip_payments = function(instance, local) {
                 return item.id === id_currency;
             });
         },
+        /* GET statement JournalId*/
+        getStatementeJournal: function(journalId) {
+            var self = this;
+            return _.filter(self.statementAvailable, function(item){
+                return item.journalID === journalId;
+            });
+        },
         // Async loop
         asyncPaymentsPayslip: function() {
             var self = this;
             var defer = $.Deferred();
-            var company = self.company.shift();
+            var company = self.company[0];
             var currency = self.getCurrencyCompany(company.currency_id[0]).shift();
+            var journal = self.accountJournal;
 
+            if (!!journal){
+                journal.unshift({
+                    'id':'',
+                    'name':'',
+                });
+            }
             self.asyncLoopFactory(self.payslipNew.length, function(loop) {
                 var payslip = self.payslipNew[loop.iteration()];
-                self.showPayments(payslip, currency).then(function(results) {
+                self.showPayments(payslip, currency, journal).then(function(results) {
                     self.reloadLine();
                     if (results){
                         loop.next();
@@ -201,11 +255,12 @@ openerp.eiru_payslip_payments = function(instance, local) {
             local.parentInstance.reload();
         },
         // Ejc. el Modal
-        showPayments: function(payslip, currency) {
+        showPayments: function(payslip, currency, journal) {
             var self = this;
             var defer = $.Deferred();
             var state = true;
 
+
             var headerModalName = [{
                 name: payslip.name
             }];
@@ -219,37 +274,78 @@ openerp.eiru_payslip_payments = function(instance, local) {
             var modal = Qweb.render('EiruPayslipPaymentsModal', {
                 data: dataPayslip,
                 dataName: headerModalName,
-                journal: self.accountJournal
+                journal: journal
             });
 
             $('.openerp_webclient_container').after(modal);
             $('.expired-account-modal').modal();
-            // Referencia de Pago\
 
-            var journal_ref = $('.expired-account-modal').find('.journal-ref');
-            var journal =  $('.expired-account-modal').find('.current-journal');
-            // Click Cerrar
-            $('.expired-account-modal').on('hidden.bs.modal', function (e) {
-                defer.resolve(false);
-                self.removeModal(e);
+            var journal =  $('.expired-account-modal').find('.journal-selected');
+            var statementSelected =  $('.expired-account-modal').find('.statement-selected');
+
+            /*botTon*/
+            var buttonPayment =$('.expired-account-modal').find('.payments-payslip');
+
+            /* journal Change*/
+            journal.change(function(e) {
+                $('.expired-account-modal').find('.paymnet-payslip-statement-open').css('display','none');
+                statementSelected.empty();
+                if (journal.val() && self.eiruAccountBankUtatementUtility.length && self.statementConfig.length && self.statementAvailable.length) {
+                    if (self.statementConfig[0].import_statement_payslip === 'manual_import') {
+                        var statement = self.getStatementeJournal(parseInt(journal.val()));
+                        if (!!statement.length) {
+                            $('.expired-account-modal').find('.paymnet-payslip-statement-open').css('display','flex');
+                            statementSelected.append('<option value=""></option>');
+                            _.each(statement, function(item) {
+                                statementSelected.append('<option value="' + item.id + '">' + item.name+" - "+moment(item.date).format("DD-MM-YYYY")+ '</option>');
+                            });
+                        }
+                    }
+                }
             });
-
             // clcik boton pagar
-            var contenido = $('.expired-account-modal').find('.payments-payslip');
-            contenido.click(function(e) {
-                self.paymentsPayslip(payslip,journal.val(), journal_ref.val()).then(function(insert) {
-
-
-                    return insert;
-                }).then(function(insert) {
-                    if (!insert)
-                        state = false;
+            buttonPayment.click(function(e) {
+                if (!journal.val()) {
+                    instance.web.notification.do_warn("Atención","Tienes que seleccionar un método de pago para continuar.");
+                    journal.css('border-color','red');
+                    journal.focus();
+                    return false;
+                }
+                journal.css('border-color','#ccc');
+
+                var statement = self.getStatementeJournal(parseInt(journal.val()));
+                if (!!statement.length && self.eiruAccountBankUtatementUtility.length && self.statementConfig.length && self.statementAvailable.length) {
+                    if (self.statementConfig[0].import_statement_payslip === 'manual_import') {
+                        if (!statementSelected.val()) {
+                            instance.web.notification.do_warn("Atención","Tienes que seleccionar una caja para continuar.");
+                            statementSelected.css('border-color','red');
+                            statementSelected.focus();
+                            return false;
+                        }
+                        statementSelected.css('border-color','#ccc');
+                    }
+                }
+                values ={
+                    'id': payslip.id,
+                    'journalId': parseInt(journal.val()),
+                    'statementId': !!statementSelected.val() ? parseInt(statementSelected.val()) : ''
+                };
+
+                self.paymentsPayslip(values).then(function(paymentsPayslip){
+                    return paymentsPayslip;
+                }).then(function(paymentsPayslip) {
+                    if (!paymentsPayslip.state) {
+                        instance.web.notification.do_warn("Atención", paymentsPayslip.message, true);
+                    }
+                    defer.resolve(paymentsPayslip)
+                });
 
-                    if (insert.length > 0)
-                        instance.web.notification.do_warn("Atención","No se pudo completar el pago de  "+payslip.name+" , porque ya se encuentra en un registros de caja/extractos bancarios (Referencia:"+insert+")", true);
+                self.removeModal(e);
+            });
 
-                    defer.resolve(state);
-                })
+            // Click Cerrar
+            $('.expired-account-modal').on('hidden.bs.modal', function (e) {
+                defer.resolve(false);
                 self.removeModal(e);
             });
 
@@ -260,23 +356,12 @@ openerp.eiru_payslip_payments = function(instance, local) {
             $('.expired-account-modal').remove();
             $('.modal-backdrop').remove();
         },
-        // Pagara la Nomina
-        paymentsPayslip: function(payslip, journal, journal_ref) {
-            var defer = $.Deferred();
-            var  HrPayslip = new instance.web.Model('hr.payslip');
-            HrPayslip.call('create_from_prayslip',[
-                {
-                    id: payslip.id,
-                    journal_id: journal,
-                    journal_ref: journal_ref
-                }
-            ],{
+        // /*Pagar nominas */
+        paymentsPayslip: function(values){
+            var payslip = new  instance.web.Model('hr.payslip');
+            return payslip.call('create_from_prayslip', [values],{
                 context: new instance.web.CompoundContext()
-            }).then(function(results) {
-                defer.resolve(results);
             });
-
-            return defer;
         },
         /* ---------------------------------------------------------------------
         * Description: Async loop util v2 written by Robert Gauto.