|
@@ -0,0 +1,1345 @@
|
|
|
+(function() {
|
|
|
+
|
|
|
+ openerp.widgetInstancePaymentsInvoices = null;
|
|
|
+ openerp.parentInstancePaymentsInvoices = {};
|
|
|
+ var QWeb = openerp.web.qweb;
|
|
|
+ var instanceWeb = openerp.web;
|
|
|
+
|
|
|
+ openerp.EiruPaymentsInvoices = openerp.Widget.extend({
|
|
|
+ template: 'eiruPaymentsInvoices.Invoices',
|
|
|
+ id: undefined,
|
|
|
+ buttons: undefined,
|
|
|
+ accountInvoice: [],
|
|
|
+ resPartner: [],
|
|
|
+ accountJournal: [],
|
|
|
+ resCompany: [],
|
|
|
+ resCurrency: [],
|
|
|
+ currencySelect: [],
|
|
|
+ ResUser: [],
|
|
|
+ statementOpen: [],
|
|
|
+
|
|
|
+ accountMoveLine: [],
|
|
|
+ moveLine:[],
|
|
|
+ movePayments: [],
|
|
|
+
|
|
|
+ resBankType: [],
|
|
|
+ resBank: [],
|
|
|
+ bankPayments: [],
|
|
|
+ resBankChequeType: [],
|
|
|
+ fieldsAllowed: [],
|
|
|
+
|
|
|
+ interestLine: [],
|
|
|
+ interestConfig: [],
|
|
|
+
|
|
|
+ statementConfig: [],
|
|
|
+
|
|
|
+ eiruBankPaymentsReferences: [],
|
|
|
+ eiruAccountBankStatementUtility: [],
|
|
|
+ eiruAccountInterest: [],
|
|
|
+
|
|
|
+ init: function(parent) {
|
|
|
+ this._super(parent);
|
|
|
+ this.buttons = parent.$buttons;
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ this.$el.click(function() {
|
|
|
+ self.fetchInitial();
|
|
|
+ });
|
|
|
+ self.buttons.click(function(e) {
|
|
|
+
|
|
|
+ if (e.target.accessKey === 'C')
|
|
|
+ self.$el.css('display','none');
|
|
|
+
|
|
|
+ if (e.target.accessKey === 'E')
|
|
|
+ self.$el.css('display','none');
|
|
|
+
|
|
|
+ if (e.target.accessKey === 'S')
|
|
|
+ self.$el.css('display','flex');
|
|
|
+
|
|
|
+ if (e.target.accessKey === 'D')
|
|
|
+ self.$el.css('display','flex');
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ updateId: function(id) {
|
|
|
+ var self = this;
|
|
|
+ self.id = id;
|
|
|
+ },
|
|
|
+
|
|
|
+ reloadPage: function() {
|
|
|
+ openerp.parentInstancePaymentsInvoices.reload();
|
|
|
+ },
|
|
|
+
|
|
|
+ removeModal: function() {
|
|
|
+ $('.expired-account-modal').remove();
|
|
|
+ $('.modal-backdrop').remove();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInitial: function() {
|
|
|
+ var self = this;
|
|
|
+ self.fetchAccountInvoice(self.id).then(function(accountInvoice) {
|
|
|
+ return accountInvoice;
|
|
|
+ }).then(function(accountInvoice) {
|
|
|
+ self.accountInvoice = accountInvoice;
|
|
|
+ console.log(accountInvoice);
|
|
|
+ return self.fetchVerifyModule('eiru_bank_payments_references');
|
|
|
+ }).then(function(eiruBankPaymentsReferences) {
|
|
|
+ self.eiruBankPaymentsReferences = eiruBankPaymentsReferences;
|
|
|
+ return self.fetchResPartner();
|
|
|
+ }).then(function(resPartner) {
|
|
|
+ self.resPartner = resPartner;
|
|
|
+ return self.fetchAccountjournal();
|
|
|
+ }).then(function(accountJournal) {
|
|
|
+ self.accountJournal = accountJournal;
|
|
|
+ return self.fetchResCompany();
|
|
|
+ }).then(function(resCompany) {
|
|
|
+ self.resCompany = resCompany;
|
|
|
+ return self.fetchResCurrency();
|
|
|
+ }).then(function(resCurrency) {
|
|
|
+ self.resCurrency = resCurrency;
|
|
|
+ return self.fetchResBanktype();
|
|
|
+ }).then(function(resBankType) {
|
|
|
+ self.resBankType= resBankType;
|
|
|
+ return self.fetchResBankChecktype();
|
|
|
+ }).then(function(resBankChequeType) {
|
|
|
+ self.resBankChequeType = resBankChequeType;
|
|
|
+ return self.fetchResBank();
|
|
|
+ }).then(function(resBank) {
|
|
|
+ self.resBank = resBank;
|
|
|
+ return self.fetchBankPayments();
|
|
|
+ }).then(function(bankPayments) {
|
|
|
+ self.bankPayments = bankPayments;
|
|
|
+ return self.fetchMoveLine();
|
|
|
+ }).then(function(accountMoveLine) {
|
|
|
+ self.accountMoveLine = accountMoveLine;
|
|
|
+ return self.fetchVerifyModule('eiru_account_interest');
|
|
|
+ }).then(function(eiruAccountInterest) {
|
|
|
+ self.eiruAccountInterest = eiruAccountInterest;
|
|
|
+ return self.fetchInterestLine();
|
|
|
+ }).then(function(interestLine) {
|
|
|
+ self.interestLine = interestLine;
|
|
|
+ return self.fetchInterestConfig()
|
|
|
+ }).then(function(interestConfig) {
|
|
|
+ self.interestConfig = interestConfig;
|
|
|
+ return self.fetchVerifyModule('eiru_account_bank_statement_utility');
|
|
|
+ }).then(function(eiruAccountBankStatementUtility) {
|
|
|
+ self.eiruAccountBankStatementUtility = eiruAccountBankStatementUtility;
|
|
|
+ return self.fetchStatementConfig();
|
|
|
+ }).then(function(statementConfig) {
|
|
|
+ self.statementConfig = statementConfig;
|
|
|
+ return self.fetchStatement();
|
|
|
+ }).then(function(statementOpen) {
|
|
|
+ self.statementOpen = statementOpen;
|
|
|
+ return self.generateMoveLine();
|
|
|
+ }).then(function(moveLine) {
|
|
|
+ self.moveLine = moveLine;
|
|
|
+ return self.showModalPayments();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ 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();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchAccountInvoice: function(ids) {
|
|
|
+ var accountInvoice = new openerp.web.Model('account.invoice');
|
|
|
+ var fields = ['id', 'number', 'date_invoice', 'amount_total', 'residual', 'partner_id', 'currency_id', 'type' ,'seq_invoice'];
|
|
|
+ var domain = [['id', '=', ids],['state', '=', 'open']];
|
|
|
+ return accountInvoice.query(fields).filter(domain).all();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResPartner: function() {
|
|
|
+ var self = this;
|
|
|
+ if (!self.accountInvoice || !self.accountInvoice.length)
|
|
|
+ return;
|
|
|
+ var partnerId = self.accountInvoice[0].partner_id[0];
|
|
|
+ var resPartner = new openerp.web.Model('res.partner');
|
|
|
+ var fields = ['id', 'name','commercial_partner_id'];
|
|
|
+ var domain = [['id', '=', partnerId]];
|
|
|
+ return resPartner.query(fields).filter(domain).all();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchMoveLine: function() {
|
|
|
+ var self = this;
|
|
|
+ var invoiceMoveLine = new openerp.web.Model('account.invoice');
|
|
|
+ return invoiceMoveLine.call('get_moveline_invoice',[self.id], {
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInterestLine: function() {
|
|
|
+ var self = this;
|
|
|
+ if (!self.eiruAccountInterest.length)
|
|
|
+ return [];
|
|
|
+
|
|
|
+ var moveLineIDS = _.map(self.accountMoveLine, function(map) {
|
|
|
+ return map.id
|
|
|
+ });
|
|
|
+
|
|
|
+ var self = this;
|
|
|
+ var invoiceMoveLine = new openerp.web.Model('account.invoice');
|
|
|
+ return invoiceMoveLine.call('eiru_payments_account_interest_line',[moveLineIDS], {
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInterestConfig: function() {
|
|
|
+ var self = this;
|
|
|
+ if (!self.eiruAccountInterest.length)
|
|
|
+ return [];
|
|
|
+
|
|
|
+ var fields = ['id','name', 'lock_move_line'];
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
+ var accountInterestConfig = new openerp.web.Model('account.interest.config');
|
|
|
+ return accountInterestConfig.query(fields).filter(domain).all();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchBankPayments: function() {
|
|
|
+ var self = this;
|
|
|
+ if (!self.eiruBankPaymentsReferences.length)
|
|
|
+ return [];
|
|
|
+
|
|
|
+ var invoiceBankPayments = new openerp.web.Model('account.invoice');
|
|
|
+ return invoiceBankPayments.call('get_bank_payments', {
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchAccountjournal: function() {
|
|
|
+ var fields = ['id', 'name', 'code', 'type', 'currency', 'default_debit_account_id', 'default_credit_account_id'];
|
|
|
+ var domain = [['active', '=', true], ['type', 'in', ['bank', 'cash']]];
|
|
|
+ var journalSalario = new openerp.web.Model('account.journal');
|
|
|
+ return journalSalario.query(fields).filter(domain).all();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResCompany: function() {
|
|
|
+ var fields = ['id','name', 'currency_id'];
|
|
|
+ var domain = [['id', '=', 1]];
|
|
|
+ var resCompanyIds = new openerp.web.Model('res.company');
|
|
|
+ return resCompanyIds.query(fields).filter(domain).all();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResBanktype: function() {
|
|
|
+ var self = this;
|
|
|
+ if (!self.eiruBankPaymentsReferences.length)
|
|
|
+ return [];
|
|
|
+
|
|
|
+ var invoiceBankPayments = new openerp.web.Model('account.invoice');
|
|
|
+ return invoiceBankPayments.call('get_bank_payment_type', {
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResBankChecktype: function() {
|
|
|
+ var self = this;
|
|
|
+ if (!self.eiruBankPaymentsReferences.length)
|
|
|
+ return [];
|
|
|
+
|
|
|
+ var fields = ['id','name', 'code'];
|
|
|
+ var resBnakCheckType = new openerp.web.Model('res.bank.cheque.type');
|
|
|
+ return resBnakCheckType.query(fields).all();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResBank: function() {
|
|
|
+ var self = this;
|
|
|
+ if (!self.eiruBankPaymentsReferences.length)
|
|
|
+ return [];
|
|
|
+
|
|
|
+ var fields = ['id', 'name', 'ruc'];
|
|
|
+ var resBank = new openerp.web.Model('res.bank');
|
|
|
+ return resBank.query(fields).all();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResCurrency: function() {
|
|
|
+ var invoicesCurrencyPayments = new openerp.web.Model('account.invoice');
|
|
|
+ return invoicesCurrencyPayments.call('get_currency_payments_invoices', {
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchStatementConfig: function() {
|
|
|
+ var self = this;
|
|
|
+ if (!self.eiruAccountBankStatementUtility.length)
|
|
|
+ return [];
|
|
|
+
|
|
|
+ var fields = ['id','name', 'active', 'import_statement_payments'];
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
+ var statementConfig = new openerp.web.Model('account.bank.statement.config');
|
|
|
+ return statementConfig.query(fields).filter(domain).all();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchStatement: function(){
|
|
|
+ var invoiceStatement = new openerp.web.Model('account.invoice');
|
|
|
+ return invoiceStatement.call('get_statement', {
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ generateMoveLine: function() {
|
|
|
+ var self = this;
|
|
|
+ var moveLine = [];
|
|
|
+ var newMoveLine= [];
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currencyInvoice = self.getCurrency(self.accountInvoice[0].currency_id[0]).shift();
|
|
|
+ _.each(self.accountMoveLine, function(line){
|
|
|
+ moveLine.push({
|
|
|
+ 'id': line.id,
|
|
|
+ 'dateMaturity': moment(line.dateMaturity).format('DD/MM/YYYY'),
|
|
|
+ 'debit': line.amountCurrency,
|
|
|
+ 'residual': line.amountResidualCurrency,
|
|
|
+ 'currencyAmount': line.currencyAmount,
|
|
|
+ 'debitFormat': accounting.formatMoney((line.amountCurrency), currencyInvoice.symbol,currencyInvoice.decimalPlaces, currencyInvoice.thousandsSeparator, currencyInvoice.decimalSeparator),
|
|
|
+ 'residualFormat': accounting.formatMoney((line.amountResidualCurrency), currencyInvoice.symbol, currencyInvoice.decimalPlaces, currencyInvoice.thousandsSeparator, currencyInvoice.decimalSeparator)
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ newMoveLine = _.sortBy(moveLine, function(item){return new Date(item.dateMaturity.trim())});
|
|
|
+ defer.resolve(newMoveLine);
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ getMoveLine: function(ids) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.moveLine, function(line){
|
|
|
+ return _.contains(ids, line.id);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getMoveLineCurrency: function(currencyAmount, idCurrency) {
|
|
|
+ return _.filter(currencyAmount, function(currency){
|
|
|
+ return currency.id === idCurrency;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ generateSelectTotal:function(idSelect, idCurrency){
|
|
|
+ var self = this;
|
|
|
+ var movePayments = [];
|
|
|
+ var moveCurrency = [];
|
|
|
+ var residual = 0;
|
|
|
+ var move = self.getMoveLine(idSelect);
|
|
|
+
|
|
|
+ if (!move.length){
|
|
|
+ return movePayments;
|
|
|
+ }
|
|
|
+
|
|
|
+ _.each(move, function(line){
|
|
|
+ moveCurrency = self.getMoveLineCurrency(line.currencyAmount, idCurrency.id).shift();
|
|
|
+ residual += moveCurrency.amountCurencyResidual;
|
|
|
+ });
|
|
|
+
|
|
|
+ movePayments.push({
|
|
|
+ 'ids': idSelect,
|
|
|
+ 'amountResidual': residual,
|
|
|
+ 'amountResidualFormat': instanceWeb.formatCurrency(residual, idCurrency),
|
|
|
+ 'currencySymbol': idCurrency.symbol,
|
|
|
+ 'currencyRate': idCurrency.rate
|
|
|
+ });
|
|
|
+ return movePayments;
|
|
|
+ },
|
|
|
+
|
|
|
+ getCurrency: function(id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.resCurrency, function(item) {
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getCurrencySelect: function(id) {
|
|
|
+ var self = this;
|
|
|
+ var currency = [];
|
|
|
+ if (!id)
|
|
|
+ id = self.resCompany[0].currency_id[0];
|
|
|
+
|
|
|
+ currency = self.getCurrency(id);
|
|
|
+ return currency;
|
|
|
+ },
|
|
|
+
|
|
|
+ getJournal: function(code) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.accountJournal, function(item) {
|
|
|
+ return item.code === code;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getBankTypeFieldsAllowed: function(name) {
|
|
|
+ var self = this;
|
|
|
+ return _.contains(self.fieldsAllowed, name);
|
|
|
+ },
|
|
|
+
|
|
|
+ getResBank: function(id) {
|
|
|
+ var self= this;
|
|
|
+ return _.filter(self.resBank, function(bank) {
|
|
|
+ return bank.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getSelectedJournal: function(code) {
|
|
|
+ var self = this;
|
|
|
+ var currencySelect = []
|
|
|
+ var journal = self.getJournal(code).shift();
|
|
|
+ var company = self.resCompany;
|
|
|
+
|
|
|
+ if (!journal)
|
|
|
+ return [];
|
|
|
+
|
|
|
+ if (!journal.currency) {
|
|
|
+ currencySelect = self.getCurrency(company[0].currency_id[0]);
|
|
|
+ }else {
|
|
|
+ currencySelect = self.getCurrency(journal.currency[0]);
|
|
|
+ }
|
|
|
+ self.currencySelect = currencySelect;
|
|
|
+ return currencySelect;
|
|
|
+ },
|
|
|
+
|
|
|
+ checkNumber: function(bankId, numberCta, number) {
|
|
|
+
|
|
|
+ * [verificar si existe el numero de cheque en 'res.bank.paymnets' ]
|
|
|
+ * :param bankId: id de banco (res_bank.id).
|
|
|
+ * :param numberCta: numero de cuneta(res_bank_payments.number_cta).
|
|
|
+ * :param number: numero de cheque/boleta/vale (res_bank_payments.number)
|
|
|
+ * :return : [Objeto] si existe datos que satisfacer el filtro, vacio si no.
|
|
|
+ */
|
|
|
+ var self = this;
|
|
|
+ if (!self.bankPayments)
|
|
|
+ return [];
|
|
|
+
|
|
|
+ return _.filter(self.bankPayments, function(item) {
|
|
|
+ return item.bankId === bankId && item.numberCta === numberCta && item.number === number;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getStatementeJournal: function(journalId) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.statementOpen, function(item){
|
|
|
+ return item.journalID === journalId;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ filterTypeOperationBank: function(journal_id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.resBankType, function(item){
|
|
|
+ return _.contains(item.journal_ids, journal_id)
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getTypeOperation(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.resBankType, function(item){
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getBankChequeType: function(id){
|
|
|
+ var self= this;
|
|
|
+ return _.filter(self.resBankChequeType, function(item){
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ filterInterestLineId:function(moveId){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.interestLine, function(item) {
|
|
|
+ return item.moveLineId === moveId;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ * [ showModalPayments ]
|
|
|
+ */
|
|
|
+ showModalPayments: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer =$.Deferred();
|
|
|
+ var results = true;
|
|
|
+ var accountJournal = self.accountJournal;
|
|
|
+ var moveSelected = [];
|
|
|
+ var selectTotal = [];
|
|
|
+ var currencyId = [];
|
|
|
+ var idRow = [];
|
|
|
+
|
|
|
+ var bankId = undefined;
|
|
|
+ var numberName = 'Nº Comprobante';
|
|
|
+ var amountBalanceBank = undefined;
|
|
|
+ var typePayments = undefined;
|
|
|
+
|
|
|
+ accountJournal.unshift({
|
|
|
+ 'name': "",
|
|
|
+ 'code': ""
|
|
|
+ });
|
|
|
+
|
|
|
+ var modal = QWeb.render('eiruPaymentsInvoices.Modal',{
|
|
|
+ moveLine: self.moveLine,
|
|
|
+ journal: accountJournal,
|
|
|
+ });
|
|
|
+ $('.openerp_webclient_container').after(modal);
|
|
|
+ $('.expired-account-modal').modal();
|
|
|
+
|
|
|
+
|
|
|
+ var savePaymentsButton = $('.expired-account-modal').find('.save-payments-button');
|
|
|
+
|
|
|
+ var tableRow = $('.expired-account-modal').find('.table-tbody').find('tr');
|
|
|
+
|
|
|
+ var amountTotal = $('.expired-account-modal').find('.amount-total');
|
|
|
+ var amountTotalSymbol = $('.expired-account-modal').find('.amount-total-symbol');
|
|
|
+
|
|
|
+ var dateOperation = $('.expired-account-modal').find('.date-operation');
|
|
|
+
|
|
|
+ var journalSelect = $('.expired-account-modal').find('.journal-select');
|
|
|
+
|
|
|
+ var amountPayments = $('.expired-account-modal').find('.amount-payments');
|
|
|
+ var amountPaymentsSymbol = $('.expired-account-modal').find('.amount-payments-symbol');
|
|
|
+
|
|
|
+ var statementSelect = $('.expired-account-modal').find('.statement-select');
|
|
|
+
|
|
|
+ var bankTypeSelect = $('.expired-account-modal').find('.bank-type-select');
|
|
|
+
|
|
|
+ var bankingOperation = $('.expired-account-modal').find('.eiru-banking-operation');
|
|
|
+
|
|
|
+ amountPayments.attr("disabled", true);
|
|
|
+
|
|
|
+ dateOperation.val(moment().format("YYYY-MM-DD"));
|
|
|
+
|
|
|
+ var dateMin = undefined;
|
|
|
+ var rowselect = undefined;
|
|
|
+ var dateSelect = undefined;
|
|
|
+
|
|
|
+
|
|
|
+ var currencyInvoice = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
|
|
|
+ if (currencyInvoice) {
|
|
|
+ amountTotalSymbol.text(currencyInvoice.symbol);
|
|
|
+ amountPaymentsSymbol.text(currencyInvoice.symbol);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ _.each(tableRow, function(tr) {
|
|
|
+ var ckechk = ($($(tr).children()[1]).find('.select-move-payments'))[0].checked;
|
|
|
+ var dateMatu = new Date(($(tr).children()[2].textContent).trim());
|
|
|
+ if (!ckechk) {
|
|
|
+ if (!dateMin) {
|
|
|
+ dateMin = dateMatu.getTime();
|
|
|
+ } else {
|
|
|
+ $($(tr).children()[1]).find('.select-move-payments').attr("disabled", true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var idMove = parseInt(($(tr).children()[0].textContent).trim());
|
|
|
+ if (!!self.interestConfig.length && self.interestConfig[0].lock_move_line) {
|
|
|
+ var move = self.filterInterestLineId(idMove);
|
|
|
+ var moveState = _.map(move, function(map) {
|
|
|
+ return map.state
|
|
|
+ })
|
|
|
+
|
|
|
+ if (_.contains(moveState, 'open')) {
|
|
|
+ ($($(tr).children()[1]).find('.select-move-payments'))[0].checked = false;
|
|
|
+ $($(tr).children()[1]).find('.select-move-payments').attr("disabled", true);
|
|
|
+ $($(tr).children()[3]).text("Existe interés sobre la cuota vencida REF("+move[0].interest[0].name+").")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ tableRow.click(function(e) {
|
|
|
+ if ($(e.target).index() !== 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ idRow = parseInt(($(e.target).closest('tr').children()[0].textContent).trim());
|
|
|
+ if (e.target.checked === true) {
|
|
|
+ moveSelected.push(idRow);
|
|
|
+
|
|
|
+ currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
|
|
|
+ if (journalSelect.val()) {
|
|
|
+ currencyId = self.getSelectedJournal(journalSelect.val()).shift();
|
|
|
+ }
|
|
|
+
|
|
|
+ self.movePayments = self.generateSelectTotal(moveSelected,currencyId);
|
|
|
+
|
|
|
+ selectTotal = self.movePayments[0];
|
|
|
+ if (selectTotal) {
|
|
|
+
|
|
|
+ amountTotal.val(selectTotal.amountResidualFormat);
|
|
|
+ amountTotalSymbol.text(selectTotal.currencySymbol);
|
|
|
+
|
|
|
+ amountPayments.val(selectTotal.amountResidualFormat);
|
|
|
+ amountPaymentsSymbol.text(selectTotal.currencySymbol);
|
|
|
+ }
|
|
|
+
|
|
|
+ dateMin = undefined;
|
|
|
+ rowselect = undefined;
|
|
|
+ dateSelect = undefined;
|
|
|
+
|
|
|
+ _.each(tableRow, function(tr) {
|
|
|
+ var dateMatu = new Date(($(tr).children()[2].textContent).trim());
|
|
|
+ var ckechk = ($($(tr).children()[1]).find('.select-move-payments'))[0].checked;
|
|
|
+ if (ckechk) {
|
|
|
+ if (!rowselect) {
|
|
|
+ rowselect = $($(tr).children()[1]).find('.select-move-payments');
|
|
|
+ dateSelect = dateMatu.getTime();
|
|
|
+ } else {
|
|
|
+ if (dateMatu.getTime() > dateSelect) {
|
|
|
+ rowselect.attr("disabled", true);
|
|
|
+ rowselect = $($(tr).children()[1]).find('.select-move-payments');
|
|
|
+ dateSelect = dateMatu.getTime();
|
|
|
+ } else {
|
|
|
+ $($(tr).children()[1]).find('.select-move-payments').attr("disabled", true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!dateMin) {
|
|
|
+ dateMin = dateMatu.getTime();
|
|
|
+ var moveId = parseInt(($(tr).children()[0].textContent).trim());
|
|
|
+ $($(tr).children()[1]).find('.select-move-payments').removeAttr("disabled");
|
|
|
+
|
|
|
+ if (!!self.interestConfig.length && self.interestConfig[0].lock_move_line) {
|
|
|
+ var move = self.filterInterestLineId(moveId);
|
|
|
+ var moveState = _.map(move, function(map) {
|
|
|
+ return map.state;
|
|
|
+ });
|
|
|
+ if ((_.contains(moveState, 'open'))) {
|
|
|
+ $($(tr).children()[1]).find('.select-move-payments').attr("disabled", true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ var indexRow = undefined;
|
|
|
+ _.each(moveSelected, function(input, index) {
|
|
|
+ if (input === idRow) {
|
|
|
+ indexRow = index;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ moveSelected.splice(indexRow,1);
|
|
|
+ if (journalSelect.val()) {
|
|
|
+ currencyId = self.getSelectedJournal(journalSelect.val()).shift();
|
|
|
+ }else {
|
|
|
+ currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ self.movePayments = self.generateSelectTotal(moveSelected,currencyId);
|
|
|
+ selectTotal = self.movePayments[0];
|
|
|
+ if (selectTotal) {
|
|
|
+ amountTotal.val(selectTotal.amountResidualFormat);
|
|
|
+ amountTotalSymbol.text(selectTotal.currencySymbol);
|
|
|
+
|
|
|
+ amountPayments.val(selectTotal.amountResidualFormat);
|
|
|
+ amountPaymentsSymbol.text(selectTotal.currencySymbol);
|
|
|
+ } else {
|
|
|
+ amountTotal.val(0);
|
|
|
+ amountTotalSymbol.text(currencyId.symbol);
|
|
|
+
|
|
|
+ amountPayments.val(0);
|
|
|
+ amountPaymentsSymbol.text(currencyId.symbol);
|
|
|
+ }
|
|
|
+
|
|
|
+ dateMin = undefined;
|
|
|
+ rowselect = undefined;
|
|
|
+ dateSelect = undefined;
|
|
|
+ _.each(tableRow, function(tr) {
|
|
|
+ var dateMatu = new Date(($(tr).children()[2].textContent).trim());
|
|
|
+ var ckechk = ($($(tr).children()[1]).find('.select-move-payments'))[0].checked;
|
|
|
+ if (ckechk) {
|
|
|
+ rowselect = $($(tr).children()[1]).find('.select-move-payments');
|
|
|
+ dateSelect = dateMatu.getTime();
|
|
|
+ } else {
|
|
|
+ if (rowselect)
|
|
|
+ rowselect.removeAttr("disabled");
|
|
|
+ if (!dateMin) {
|
|
|
+ dateMin = dateMatu.getTime();
|
|
|
+ } else {
|
|
|
+ $($(tr).children()[1]).find('.select-move-payments').attr("disabled", true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ journalSelect.change(function(e) {
|
|
|
+ var journal = [];
|
|
|
+ bankingOperation.empty();
|
|
|
+ statementSelect.val('');
|
|
|
+
|
|
|
+ if (journalSelect.val()) {
|
|
|
+ journal = self.getJournal(journalSelect.val()).shift();
|
|
|
+ if (!!journal) {
|
|
|
+ amountPayments.removeAttr("disabled");
|
|
|
+
|
|
|
+ if (!!self.eiruAccountBankStatementUtility.length) {
|
|
|
+ if(!!self.statementConfig.length) {
|
|
|
+ if (self.statementConfig[0].import_statement_payments === 'manual_import') {
|
|
|
+ var statement = self.getStatementeJournal(journal.id);
|
|
|
+
|
|
|
+ $('.expired-account-modal').find('.statement-config').css('display','none');
|
|
|
+ statementSelect.empty();
|
|
|
+ if (!!statement.length) {
|
|
|
+ $('.expired-account-modal').find('.statement-config').css('display','flex');
|
|
|
+ var cashboxOpen = '<option value=""></option>';
|
|
|
+ _.each(statement, function(item) {
|
|
|
+ cashboxOpen += '<option value="'+item.id+'">'+item.name+'</option>';
|
|
|
+ });
|
|
|
+ statementSelect.append(cashboxOpen);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ typeOperationBank = self.filterTypeOperationBank(journal.id);
|
|
|
+ bankTypeSelect.empty();
|
|
|
+ self.fieldsBank = [];
|
|
|
+ $('.expired-account-modal').find('.type-select-bank').css('display','none');
|
|
|
+ if (!!typeOperationBank.length) {
|
|
|
+ $('.expired-account-modal').find('.type-select-bank').css('display','flex');
|
|
|
+ var typeOperation = '<option value=""></option>';
|
|
|
+ _.each(typeOperationBank, function(item) {
|
|
|
+ typeOperation += '<option value="'+item.id+'">'+item.name+'</option>';
|
|
|
+ });
|
|
|
+ bankTypeSelect.append(typeOperation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ currencyId = self.getSelectedJournal(journalSelect.val()).shift();
|
|
|
+ } else {
|
|
|
+ amountPayments.attr("disabled", true);
|
|
|
+ currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ self.movePayments = self.generateSelectTotal(moveSelected,currencyId);
|
|
|
+ selectTotal = self.movePayments[0];
|
|
|
+ if (selectTotal) {
|
|
|
+
|
|
|
+ amountTotal.val(selectTotal.amountResidualFormat);
|
|
|
+ amountTotalSymbol.text(selectTotal.currencySymbol);
|
|
|
+
|
|
|
+ amountPayments.val(selectTotal.amountResidualFormat);
|
|
|
+ amountPaymentsSymbol.text(selectTotal.currencySymbol);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ bankTypeSelect.change(function(e) {
|
|
|
+ bankingOperation.empty();
|
|
|
+ if (!bankTypeSelect.val())
|
|
|
+ return false;
|
|
|
+
|
|
|
+ var typeBank = self.getTypeOperation(parseInt(bankTypeSelect.val())).shift();
|
|
|
+ typePayments = typeBank;
|
|
|
+ var fields = '';
|
|
|
+ var cont = 0;
|
|
|
+ var fieldsBank = [];
|
|
|
+
|
|
|
+ _.each(typeBank.fields_allowed, function(item, index) {
|
|
|
+ if (cont === 0)
|
|
|
+ fields += '<div class="row">';
|
|
|
+ cont ++;
|
|
|
+ var fieldModel = [];
|
|
|
+ var typeText ="text";
|
|
|
+ var select = "payments-";
|
|
|
+ var classField = select.concat(item.name.replace(/_/g, '-'));
|
|
|
+
|
|
|
+ if (item.string.typeField === 'date')
|
|
|
+ typeText = "date";
|
|
|
+
|
|
|
+ fields += '<div class="col-xs-6">';
|
|
|
+ fields += '<label class="payments-invoice-label invoice-payment-label-select">'+item.label+'</label>';
|
|
|
+ fields += '<div class="payments-invoice-group invoice-payment-input-select">';
|
|
|
+
|
|
|
+ if (item.string.type === 'normal') {
|
|
|
+ if (item.string.typeField === 'float') {
|
|
|
+ fields += '<input type="'+typeText+'" class="form-control payments-invoice-input amount-currency '+classField+'" value="0"></input>';
|
|
|
+ fields += '<div class="payments-invoice-symbol">';
|
|
|
+ fields += '<span class="input-group-text amount-total-symbol">'+currencyId.symbol+'</span>';
|
|
|
+ fields += '</div>';
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ fields += '<input type="'+typeText+'" class="payments-invoice-input invoice-payment-input input-date '+classField+'" ></input>';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ var test = item.string.model.split(".");
|
|
|
+ var newModel = "";
|
|
|
+
|
|
|
+ _.each(test, function(item, index) {
|
|
|
+ if (index === 0 ){
|
|
|
+ newModel = item;
|
|
|
+ } else {
|
|
|
+ var newLetter = "";
|
|
|
+ _.each(item, function(inv, index) {
|
|
|
+ if (index === 0) {
|
|
|
+ newLetter = inv.toUpperCase();
|
|
|
+ }else {
|
|
|
+ newLetter = newLetter.concat(inv);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ newModel = newModel.concat(newLetter);
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ fieldModel = _.flatten(_.filter(self, function(element, index) {
|
|
|
+ return index === newModel;
|
|
|
+ }));
|
|
|
+
|
|
|
+ if (item.string.searchType === 'selection') {
|
|
|
+ fields += '<select class="payments-invoice-input invoice-payment-input '+classField+'">';
|
|
|
+ fields += '<option value=""></option>';
|
|
|
+ _.each(fieldModel, function(item) {
|
|
|
+ fields += '<option value="'+item.id+'">'+item.name+'</option>';
|
|
|
+ });
|
|
|
+
|
|
|
+ fields += '</select>';
|
|
|
+ } else {
|
|
|
+ fields += '<input type="text" class="form-control payments-invoice-input invoice-payment-input input-date ui-autocomplete-input '+classField+'" autocomplete="off" placeholder="'+item.label+'"></input>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fields += '</div>';
|
|
|
+ fields += '</div>';
|
|
|
+
|
|
|
+ if (cont === 2 || (index +1 ) === typeBank.fields_allowed.length) {
|
|
|
+ fields += '</div>';
|
|
|
+ cont = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ fieldsBank.push({
|
|
|
+ 'field': classField,
|
|
|
+ 'name': item.name,
|
|
|
+ 'required': item.string.required,
|
|
|
+ 'label': item.label,
|
|
|
+ 'type': item.string.typeField,
|
|
|
+ 'model': fieldModel,
|
|
|
+ 'modelAutoComplete': _.map(fieldModel, function(item) {
|
|
|
+ return {
|
|
|
+ label: item.id +" - "+ item.name,
|
|
|
+ value: item.id +" - "+ item.name
|
|
|
+ };
|
|
|
+ }),
|
|
|
+ 'searchType': item.string.searchType,
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ self.fieldsBank = fieldsBank;
|
|
|
+ bankingOperation.append(fields);
|
|
|
+
|
|
|
+
|
|
|
+ _.each(_.filter(fieldsBank, function(item){return item.searchType === 'autocomplete'}), function(autoComplete) {
|
|
|
+ var fieldComplete = $('.expired-account-modal').find('.'+autoComplete.field);
|
|
|
+ fieldComplete.autocomplete({
|
|
|
+ source: autoComplete.model,
|
|
|
+ minLength:0,
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ * [Keyup]
|
|
|
+ */
|
|
|
+ $('.expired-account-modal').keyup(function(e){
|
|
|
+ var nameClas = (($(e.target)[0].className).trim()).split(" ");
|
|
|
+
|
|
|
+ if (_.contains(nameClas, 'amount-currency')) {
|
|
|
+ var ammountBank = $('.expired-account-modal').find('.'+nameClas[nameClas.length -1]);
|
|
|
+ if (journalSelect.val()) {
|
|
|
+ currencyId = self.getSelectedJournal(journalSelect.val()).shift();
|
|
|
+ } else {
|
|
|
+ currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ var amount_add = instanceWeb.unFormatCurrency(ammountBank.val());
|
|
|
+ ammountBank.val(instanceWeb.formatCurrency(amount_add,currencyId));
|
|
|
+ ammountBank.css('border-color','#ccc');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_.contains(nameClas, 'ui-autocomplete-input')) {
|
|
|
+ _.each(_.filter(self.fieldsBank, function(item){return item.searchType === 'autocomplete'}), function(autoComplete) {
|
|
|
+ if (nameClas[nameClas.length -1] === autoComplete.field) {
|
|
|
+ var fieldComplete = $('.expired-account-modal').find('.'+autoComplete.field);
|
|
|
+ fieldComplete.autocomplete({
|
|
|
+ source: autoComplete.modelAutoComplete,
|
|
|
+ minLength:0,
|
|
|
+ select: function(e, ui) {
|
|
|
+ var id = undefined;
|
|
|
+ if (!!ui.item.value)
|
|
|
+ id = ui.item.value.split('-');
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ * [focusout]
|
|
|
+ */
|
|
|
+ $('.expired-account-modal').focusout(function(e){
|
|
|
+ var nameClas = (($(e.target)[0].className).trim()).split(" ");
|
|
|
+
|
|
|
+ * [Verify amount-total]
|
|
|
+ */
|
|
|
+ if (_.contains(nameClas, 'payments-amount-total')){
|
|
|
+ var ammountBank = $('.expired-account-modal').find('.'+nameClas[nameClas.length -1])
|
|
|
+
|
|
|
+ currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
|
|
|
+ if (journalSelect.val())
|
|
|
+ currencyId = self.getSelectedJournal(journalSelect.val()).shift();
|
|
|
+
|
|
|
+ var amount_add = instanceWeb.unFormatCurrency(ammountBank.val());
|
|
|
+ var paymentsAmount = instanceWeb.unFormatCurrency(amountPayments.val());
|
|
|
+ var paymentsTotal = instanceWeb.unFormatCurrency(amountTotal.val());
|
|
|
+
|
|
|
+ if (amount_add <= 0){
|
|
|
+ openerp.web.notification.do_warn("Atencion", "El valor debe ser mayor que 0");
|
|
|
+ ammountBank.css('border-color','red');
|
|
|
+ ammountBank.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (amount_add < paymentsAmount) {
|
|
|
+ amountPayments.val(instanceWeb.formatCurrency(amount_add, currencyId));
|
|
|
+ }
|
|
|
+ ammountBank.val(instanceWeb.formatCurrency(amount_add, currencyId));
|
|
|
+ }
|
|
|
+
|
|
|
+ * [Verify Bank Selected]
|
|
|
+ */
|
|
|
+ if (_.contains(nameClas, 'payments-bank-id')) {
|
|
|
+ var bankSelected = $('.expired-account-modal').find('.'+nameClas[nameClas.length -1]);
|
|
|
+ var valueBank = bankSelected.val();
|
|
|
+ if (_.contains(nameClas, 'ui-autocomplete-input'))
|
|
|
+ valueBank = (valueBank.split('-'))[0];
|
|
|
+
|
|
|
+ if (!bankSelected.val()) {
|
|
|
+ openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar un banco para continuar.");
|
|
|
+ bankSelected.css('border-color','red');
|
|
|
+ bankSelected.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var bankValue = self.getResBank(parseInt(valueBank)).shift();
|
|
|
+ if (!bankValue) {
|
|
|
+ openerp.web.notification.do_warn("Atencion", "El banco no existe, ingrese un banco valido.");
|
|
|
+ bankSelected.css('border-color','red');
|
|
|
+ bankSelected.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ bankSelected.css('border-color','#ccc');
|
|
|
+ bankId = bankValue.id
|
|
|
+ }
|
|
|
+
|
|
|
+ * [Verify Cheque type]
|
|
|
+ */
|
|
|
+ if (_.contains(nameClas, 'payments-cheque-type-id')){
|
|
|
+ var typeChequeSelected = $('.expired-account-modal').find('.'+nameClas[nameClas.length -1]);
|
|
|
+ var valuetype = typeChequeSelected.val();
|
|
|
+ if (_.contains(nameClas, 'ui-autocomplete-input'))
|
|
|
+ valuetype = (valuetype.split('-'))[0];
|
|
|
+
|
|
|
+ if (!typeChequeSelected.val()) {
|
|
|
+ openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar el tipo de cheque para continuar.");
|
|
|
+ typeChequeSelected.css('border-color','red');
|
|
|
+ typeChequeSelected.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var chequeTypeValue = self.getBankChequeType(parseInt(valuetype)).shift();
|
|
|
+ if (!chequeTypeValue) {
|
|
|
+ openerp.web.notification.do_warn("Atencion", "Tipo de cheque no existe , ingrese un tipo de cheque valido.");
|
|
|
+ typeChequeSelected.css('border-color','red');
|
|
|
+ typeChequeSelected.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ typeChequeSelected.css('border-color','#ccc');
|
|
|
+ }
|
|
|
+
|
|
|
+ * [Verify Bank Paymnets]
|
|
|
+ */
|
|
|
+ if ((_.contains(nameClas, 'payments-bank-id')) || (_.contains(nameClas, 'payments-number')) || (_.contains(nameClas, 'payments-number-cta'))){
|
|
|
+ var fieldsPayments = _.map(self.fieldsBank, function(map){
|
|
|
+ return map.field
|
|
|
+ });
|
|
|
+ if ((_.contains(fieldsPayments, 'payments-bank-id')) && (_.contains(fieldsPayments, 'payments-number')) && (_.contains(fieldsPayments, 'payments-number-cta'))){
|
|
|
+
|
|
|
+ var paymentsBankId = $('.expired-account-modal').find('.payments-bank-id');
|
|
|
+ var paymentsNumber = $('.expired-account-modal').find('.payments-number');
|
|
|
+ var paymentsNumberCta = $('.expired-account-modal').find('.payments-number-cta');
|
|
|
+
|
|
|
+ if (!!bankId && !!paymentsNumber.val() && paymentsNumberCta.val() && !(typePayments.allow_duplicate_operation)) {
|
|
|
+ var chechNumberCh = self.checkNumber(bankId, paymentsNumberCta.val().trim(), paymentsNumber.val().trim()).shift();
|
|
|
+ self.verifyOperacionBank(chechNumberCh, amountPayments, currencyId, typePayments);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ amountPayments.keyup(function(e) {
|
|
|
+ currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
|
|
|
+ if (journalSelect.val()) {
|
|
|
+ currencyId = self.getSelectedJournal(journalSelect.val()).shift();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (e.key === currencyId.decimalSeparator && currencyId.decimalPlaces > 0)
|
|
|
+ return false ;
|
|
|
+
|
|
|
+ var amount_add = instanceWeb.unFormatCurrency(amountPayments.val());
|
|
|
+ amountPayments.val(instanceWeb.formatCurrency(amount_add, currencyId));
|
|
|
+
|
|
|
+ amountPayments.css('border-color','#ccc');
|
|
|
+
|
|
|
+ if (e.keyCode === 13)
|
|
|
+ savePaymentsButton.focus();
|
|
|
+ });
|
|
|
+
|
|
|
+ amountPayments.focusout(function(e) {
|
|
|
+ currencyId = self.getCurrencySelect(self.accountInvoice[0].currency_id[0]).shift();
|
|
|
+ if (journalSelect.val()) {
|
|
|
+ currencyId = self.getSelectedJournal(journalSelect.val()).shift();
|
|
|
+ }
|
|
|
+
|
|
|
+ var amountTotalPayments = instanceWeb.unFormatCurrency(amountPayments.val());
|
|
|
+ var paymentsTotal = instanceWeb.unFormatCurrency(amountTotal.val());
|
|
|
+
|
|
|
+ if (amountTotalPayments <= 0) {
|
|
|
+ openerp.web.notification.do_warn("Atencion", "El monto a pagar no puede ser 0.");
|
|
|
+ amountPayments.css('border-color','red');
|
|
|
+ amountPayments.focus();
|
|
|
+ }
|
|
|
+
|
|
|
+ var fields = "";
|
|
|
+ $('.expired-account-modal').find('.ammount-returned').css('display','none');
|
|
|
+ $('.expired-account-modal').find('.ammount-returned').empty();
|
|
|
+ if (amountTotalPayments > paymentsTotal) {
|
|
|
+ var returned = (instanceWeb.formatCurrency((amountTotalPayments - paymentsTotal), currencyId));
|
|
|
+ $('.expired-account-modal').find('.ammount-returned').css('display','flex');
|
|
|
+ fields += '<label class="payments-invoice-label invoice-payment-label-select"> Vuelto </label>';
|
|
|
+ fields += '<div class="payments-invoice-group invoice-payment-input-select">';
|
|
|
+ fields += '<input type="text" class="form-control payments-invoice-input" readonly="readonly" value="'+returned+'"></input>';
|
|
|
+ fields += '<div class="payments-invoice-symbol">';
|
|
|
+ fields += '<span class="input-group-text amount-total-symbol">'+currencyId.symbol+'</span>';
|
|
|
+ fields += '</div>';
|
|
|
+ fields += '</div>';
|
|
|
+ $('.expired-account-modal').find('.ammount-returned').append(fields);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ savePaymentsButton.click(function(e) {
|
|
|
+ var savePayments = [];
|
|
|
+ var paymentsAmount = 0;
|
|
|
+ var currencyJournal = [];
|
|
|
+ var journal = [];
|
|
|
+ var chechNumberCh = [];
|
|
|
+
|
|
|
+
|
|
|
+ if (!self.movePayments ||!self.movePayments.length) {
|
|
|
+ openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar al menos una cuota para continuar.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!journalSelect.val()) {
|
|
|
+ openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar un método de pago para continuar.");
|
|
|
+ journalSelect.css('border-color','red');
|
|
|
+ journalSelect.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ journalSelect.css('border-color','#ccc');
|
|
|
+
|
|
|
+ journal = self.getJournal(journalSelect.val());
|
|
|
+ currencyJournal = self.getSelectedJournal(journalSelect.val()).shift();
|
|
|
+ paymentsAmount = instanceWeb.unFormatCurrency(amountPayments.val());
|
|
|
+
|
|
|
+
|
|
|
+ if (paymentsAmount <= 0 ) {
|
|
|
+ openerp.web.notification.do_warn("Atencion", "El monto a pagar no debe ser 0.");
|
|
|
+ amountPayments.css('border-color','red');
|
|
|
+ amountPayments.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ amountPayments.css('border-color','#ccc');
|
|
|
+
|
|
|
+ var statement = self.getStatementeJournal(journal[0].id);
|
|
|
+ if (!!self.eiruAccountBankStatementUtility.length){
|
|
|
+ if (!!self.statementConfig.length) {
|
|
|
+ if (!!statement.length && !statementSelect.val() && self.statementConfig[0].import_statement_payments === 'manual_import'){
|
|
|
+ openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar una caja para continuar.");
|
|
|
+ statementSelect.css('border-color','red');
|
|
|
+ statementSelect.val();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ statementSelect.css('border-color','#ccc');
|
|
|
+
|
|
|
+
|
|
|
+ typeOperationBank = self.filterTypeOperationBank(journal[0].id);
|
|
|
+ if (!!typeOperationBank.length && !bankTypeSelect.val()){
|
|
|
+ openerp.web.notification.do_warn("Atencion", "Tienes que seleccionar el tipo de pago para continuar .");
|
|
|
+ bankTypeSelect.css('border-color','red');
|
|
|
+ bankTypeSelect.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ bankTypeSelect.css('border-color','#ccc');
|
|
|
+
|
|
|
+
|
|
|
+ * [Verificar Datos de Operación bancarias]
|
|
|
+ */
|
|
|
+ var fieldsBankRequired = self.verifyFields().shift();
|
|
|
+ if (fieldsBankRequired) {
|
|
|
+ var fields = $('.expired-account-modal').find('.'+fieldsBankRequired.field);
|
|
|
+ if (fieldsBankRequired.required) {
|
|
|
+ openerp.web.notification.do_warn("Atencion", "El campo "+fieldsBankRequired.label+" es obligatorio.");
|
|
|
+ fields.css('border-color','red');
|
|
|
+ fields.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * [Verificar Operacion bancarias]
|
|
|
+ */
|
|
|
+ var fieldsPayments = _.map(self.fieldsBank, function(map){
|
|
|
+ return map.field
|
|
|
+ });
|
|
|
+ if ((_.contains(fieldsPayments, 'payments-bank-id')) && (_.contains(fieldsPayments, 'payments-number')) && (_.contains(fieldsPayments, 'payments-number-cta'))){
|
|
|
+
|
|
|
+ var paymentsBankId = $('.expired-account-modal').find('.payments-bank-id');
|
|
|
+ var paymentsNumber = $('.expired-account-modal').find('.payments-number');
|
|
|
+ var paymentsNumberCta = $('.expired-account-modal').find('.payments-number-cta');
|
|
|
+
|
|
|
+ if (!!bankId && !!paymentsNumber.val() && paymentsNumberCta.val() && !(typePayments.allow_duplicate_operation)) {
|
|
|
+ var chechNumberCh = self.checkNumber(bankId, paymentsNumberCta.val().trim(), paymentsNumber.val().trim()).shift();
|
|
|
+ if (! self.verifyOperacionBank(chechNumberCh, amountPayments, currencyId, typePayments))
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var bankOperation = {};
|
|
|
+ var fiedsConcat = '{';
|
|
|
+ var contobjetc=0
|
|
|
+ _.each(self.fieldsBank, function(item, index, list) {
|
|
|
+ var fieldwidget = $('.expired-account-modal').find('.'+item.field);
|
|
|
+ var fieldsValue = undefined;
|
|
|
+ if(!!fieldwidget.val())
|
|
|
+ fieldsValue = '"'+fieldwidget.val()+'"';
|
|
|
+
|
|
|
+ if (_.contains(['many2one', 'many2many', 'one2many'], item.type)) {
|
|
|
+ fieldsValue = parseInt(fieldwidget.val().trim());
|
|
|
+
|
|
|
+ if (item.searchType === 'autocomplete') {
|
|
|
+ var valueFieds = fieldwidget.val().split('-');
|
|
|
+ fieldsValue = parseInt(valueFieds[0].trim());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (_.contains(['float','int'], item.type)){
|
|
|
+ fieldsValue = instanceWeb.unFormatCurrency(fieldwidget.val());
|
|
|
+ if (fieldsValue <= 0)
|
|
|
+ fieldsValue = "";
|
|
|
+ }
|
|
|
+ if (!!fieldsValue){
|
|
|
+ if(contobjetc > 0)
|
|
|
+ fiedsConcat = fiedsConcat.concat(',');
|
|
|
+ fiedsConcat = fiedsConcat.concat('"'+item.name+'": '+fieldsValue);
|
|
|
+ contobjetc++
|
|
|
+ }
|
|
|
+ });
|
|
|
+ fiedsConcat = fiedsConcat.concat('}');
|
|
|
+ bankOperation = JSON.parse(fiedsConcat)
|
|
|
+
|
|
|
+ if (bankOperation) {
|
|
|
+ bankOperation.bank_payments_type_id = parseInt(bankTypeSelect.val())
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ savePayments = {
|
|
|
+ 'invoiceId': self.accountInvoice[0].id,
|
|
|
+ 'JournalId': journal[0].id,
|
|
|
+ 'partnerId': self.resPartner[0].id ,
|
|
|
+ 'amountPayments': self.movePayments[0].amountResidual < paymentsAmount ? self.movePayments[0].amountResidual : paymentsAmount,
|
|
|
+ 'moveLines': self.movePayments[0].ids,
|
|
|
+ 'JournalType': journal[0].type,
|
|
|
+ 'statementId': !!statementSelect.val() ? parseInt(statementSelect.val()) : '',
|
|
|
+ 'bankPayments': bankOperation,
|
|
|
+ 'voucherName' : !!($('.expired-account-modal').find('.voucher-name').val()).trim() ?$('.expired-account-modal').find('.voucher-name').val() : '',
|
|
|
+ 'voucherObs' : !!($('.expired-account-modal').find('.voucher-obs').val()).trim() ?$('.expired-account-modal').find('.voucher-obs').val() : '',
|
|
|
+ 'voucherSeq': self.accountInvoice[0].seq_invoice,
|
|
|
+ 'datePayments': dateOperation.val(),
|
|
|
+ };
|
|
|
+
|
|
|
+ $('.expired-account-modal').find('.widget-content.widget-loading-payments').css('display','flex');
|
|
|
+ self.savePaymentsInvoice(savePayments).then(function(resultsPayments) {
|
|
|
+ return resultsPayments;
|
|
|
+ }).then(function(resultsPayments) {
|
|
|
+ self.reloadPage();
|
|
|
+ $('.expired-account-modal').find('.widget-content.widget-loading-payments').css('display','none');
|
|
|
+ self.removeModal(e);
|
|
|
+ if (!resultsPayments)
|
|
|
+ results = false;
|
|
|
+ });
|
|
|
+
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ $('.expired-account-modal').on('hidden.bs.modal', function(e) {
|
|
|
+ results = false;
|
|
|
+ defer.resolve(results);
|
|
|
+ self.removeModal(e);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ verifyOperacionBank: function(chechNumberCh, amountPayments, currencyId, typePayments){
|
|
|
+ var self = this;
|
|
|
+ var paymentsChequeTypeId = $('.expired-account-modal').find('.payments-cheque-type-id');
|
|
|
+ var paymentsNameHolder = $('.expired-account-modal').find('.payments-name-holder');
|
|
|
+ var paymentsAmountTotal = $('.expired-account-modal').find('.payments-amount-total');
|
|
|
+ var paymentsDateMaturity = $('.expired-account-modal').find('.payments-date-maturity');
|
|
|
+
|
|
|
+
|
|
|
+ if (!chechNumberCh) {
|
|
|
+ if (paymentsChequeTypeId.length) {
|
|
|
+ paymentsChequeTypeId.removeAttr("disabled");
|
|
|
+ paymentsChequeTypeId.css('background-color', 'white');
|
|
|
+ }
|
|
|
+ if (paymentsNameHolder.length) {
|
|
|
+ paymentsNameHolder.removeAttr("disabled");
|
|
|
+ paymentsNameHolder.css('background-color', 'white');
|
|
|
+ }
|
|
|
+ if (paymentsAmountTotal.length) {
|
|
|
+ paymentsAmountTotal.removeAttr("disabled");
|
|
|
+ paymentsAmountTotal.css('background-color', 'white');
|
|
|
+ }
|
|
|
+ if (paymentsDateMaturity.length) {
|
|
|
+ paymentsDateMaturity.val(moment().format("YYYY-MM-DD"));
|
|
|
+ paymentsDateMaturity.removeAttr("disabled");
|
|
|
+ paymentsDateMaturity.css('background-color', 'white');
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ if(chechNumberCh.state !== 'available') {
|
|
|
+ openerp.web.notification.do_warn("Atencion", ""+typePayments.name+" no disponible ");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (paymentsChequeTypeId.length) {
|
|
|
+ var classPayments =((paymentsChequeTypeId[0].className).trim()).split(" ");
|
|
|
+ var typeCheque = chechNumberCh.chequeTypeId;
|
|
|
+
|
|
|
+ if (_.contains(classPayments, 'ui-autocomplete-input')){
|
|
|
+ var chequeTypeValue = self.getBankChequeType(parseInt(chechNumberCh.chequeTypeId)).shift();
|
|
|
+ if (chequeTypeValue)
|
|
|
+ typeCheque = chequeTypeValue.id+" - "+chequeTypeValue.name;
|
|
|
+ }
|
|
|
+ paymentsChequeTypeId.val(typeCheque);
|
|
|
+ paymentsChequeTypeId.attr("disabled", true);
|
|
|
+ paymentsChequeTypeId.css('background', '#eee');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (paymentsNameHolder.length) {
|
|
|
+ paymentsNameHolder.val(chechNumberCh.nameHolder);
|
|
|
+ paymentsNameHolder.attr("disabled", true);
|
|
|
+ paymentsNameHolder.css('background', '#eee');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (paymentsAmountTotal.length) {
|
|
|
+ paymentsAmountTotal.val(instanceWeb.formatCurrency(chechNumberCh.amountTotal, currencyId));
|
|
|
+ paymentsAmountTotal.attr("disabled", true);
|
|
|
+ paymentsAmountTotal.css('background', '#eee');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (paymentsDateMaturity.length) {
|
|
|
+ paymentsDateMaturity.val(chechNumberCh.dateMaturity);
|
|
|
+ paymentsDateMaturity.attr("disabled", true);
|
|
|
+ paymentsDateMaturity.css('background', '#eee');
|
|
|
+ }
|
|
|
+
|
|
|
+ var paymentsAmount = instanceWeb.unFormatCurrency(amountPayments.val());
|
|
|
+ var totalBank = 0;
|
|
|
+ var amountBank = 0;
|
|
|
+ var amountRefund = 0;
|
|
|
+ totalBank = chechNumberCh.amountTotal;
|
|
|
+
|
|
|
+
|
|
|
+ if ((self.accountInvoice[0].type === 'out_invoice') || (self.accountInvoice[0].type === 'in_refund')) {
|
|
|
+ amountBank = chechNumberCh.amountReceipt;
|
|
|
+ if (self.accountInvoice[0].type === 'in_refund')
|
|
|
+ amountRefund = chechNumberCh.amountReceipt;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ((self.accountInvoice[0].type === 'in_invoice') || (self.accountInvoice[0].type === 'out_refund')) {
|
|
|
+ amountBank = chechNumberCh.amountPayment;
|
|
|
+ if (self.accountInvoice[0].type === 'out_refund')
|
|
|
+ amountRefund = chechNumberCh.amountPayment;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (totalBank <= amountBank) {
|
|
|
+ openerp.web.notification.do_warn("Atencion", typePayments.name + " sin saldo disponible.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ amountBalanceBank = (totalBank - amountBank);
|
|
|
+ var amountBalanceBankFoirmat = instanceWeb.formatCurrency(amountBalanceBank, currencyId);
|
|
|
+ if (paymentsAmount > amountBalanceBank) {
|
|
|
+ openerp.web.notification.do_warn("Atencion", "El monto a pagar supera al saldo disponible del.\n Saldo disponible = "+amountBalanceBankFoirmat);
|
|
|
+ amountPayments.css('border-color','red');
|
|
|
+ amountPayments.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $('.expired-account-modal').find('.save-payments-button').focus();
|
|
|
+ return true
|
|
|
+ },
|
|
|
+
|
|
|
+ verifyFields: function(){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.fieldsBank, function(item) {
|
|
|
+ var field = $('.expired-account-modal').find('.'+item.field);
|
|
|
+ field.css('border-color','#ccc');
|
|
|
+ return item.required && !(field.val().trim());
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ savePaymentsInvoice: function(savePayments) {
|
|
|
+ var self = this;
|
|
|
+ var invoiceUpdate = new openerp.web.Model('account.invoice');
|
|
|
+ return invoiceUpdate.call('save_payments_invoice',[savePayments], {
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ if (openerp.web && openerp.web.FormView) {
|
|
|
+ openerp.web.FormView.include({
|
|
|
+ load_record: function(record) {
|
|
|
+ this._super.apply(this, arguments);
|
|
|
+
|
|
|
+ if (this.model !== 'account.invoice')
|
|
|
+ return;
|
|
|
+
|
|
|
+ openerp.parentInstancePaymentsInvoices = this;
|
|
|
+
|
|
|
+ if (record.state !== 'open')
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (openerp.widgetInstancePaymentsInvoices) {
|
|
|
+ openerp.widgetInstancePaymentsInvoices.updateId(record.id);
|
|
|
+ if (this.$el.find('.button-payments-invoices').length !== 0 )
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.$el.find('.button-payments-invoices').length !== 0 )
|
|
|
+ return;
|
|
|
+
|
|
|
+ openerp.widgetInstancePaymentsInvoices = new openerp.EiruPaymentsInvoices(this);
|
|
|
+ var element =this.$el.find('.oe_form').find('.eiru-payments-invoices');
|
|
|
+
|
|
|
+ openerp.widgetInstancePaymentsInvoices.appendTo(element[0]);
|
|
|
+ openerp.widgetInstancePaymentsInvoices.updateId(record.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+})();
|