|
@@ -0,0 +1,377 @@
|
|
|
+
|
|
|
+openerp.eiru_payslip_payments = function(instance, local) {
|
|
|
+ local.widgetInstancePayslipPaymentsIPSE = null;
|
|
|
+ local.parentInstancePayslipPaymentsIPSE = null;
|
|
|
+ var Qweb = openerp.web.qweb;
|
|
|
+
|
|
|
+ local.PayslipPaymentsIPSE = instance.Widget.extend({
|
|
|
+ template: 'eiru_payslip_payments.IPSE',
|
|
|
+ id: undefined,
|
|
|
+ payslipIpse: [],
|
|
|
+ payslispRun: [],
|
|
|
+ accountJournal: [],
|
|
|
+ init: function(parent) {
|
|
|
+ this._super(parent);
|
|
|
+ this.buttons = parent.$buttons;
|
|
|
+ },
|
|
|
+ start: function() {
|
|
|
+ var self = this;
|
|
|
+ this.$el.click(function(){
|
|
|
+ self.fectchInitial()
|
|
|
+ });
|
|
|
+
|
|
|
+ self.buttons.click(function(e) {
|
|
|
+ /* E (Editar) */
|
|
|
+ if (e.target.accessKey === 'E')
|
|
|
+ self.$el.css('display','none');
|
|
|
+ /* S (Guarrdar) */
|
|
|
+ if (e.target.accessKey === 'S')
|
|
|
+ self.$el.css('display','flex');
|
|
|
+ /* D (Cancelar) */
|
|
|
+ if (e.target.accessKey === 'D')
|
|
|
+ self.$el.css('display','flex');
|
|
|
+ });
|
|
|
+ },
|
|
|
+ updateId: function(id) {
|
|
|
+ var self = this;
|
|
|
+ self.id = id;
|
|
|
+ },
|
|
|
+
|
|
|
+ /* Remover */
|
|
|
+ removeModal: function() {
|
|
|
+ $('.expired-account-modal').remove();
|
|
|
+ $('.modal-backdrop').remove();
|
|
|
+ },
|
|
|
+
|
|
|
+ /* Metodo Inicial */
|
|
|
+ fectchInitial: function() {
|
|
|
+ var self = this;
|
|
|
+ self.fetchPayslipPaymentsIpse(self.id).then(function(payslipIpse) {
|
|
|
+ return payslipIpse;
|
|
|
+ }).then(function(payslipIpse) {
|
|
|
+ self.payslipIpse = payslipIpse;
|
|
|
+ return self.fetchPayslipRun(self.id)
|
|
|
+ }).then(function(payslispRun) {
|
|
|
+ self.payslispRun = payslispRun;
|
|
|
+ return self.fetchAccountJournal();
|
|
|
+ }).then(function(accountJournal) {
|
|
|
+ self.accountJournal = accountJournal;
|
|
|
+ if (!self.payslipIpse.length){
|
|
|
+ instance.web.notification.do_warn("Atención","No existe registro de I.P,S, empleado a reconciliar.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return self.showPaymentsIpse()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* Get statement Available*/
|
|
|
+ fetchPayslipPaymentsIpse: function(id) {
|
|
|
+ var payslipRun = new openerp.web.Model('hr.payslip.run');
|
|
|
+ return payslipRun.call('eiru_get_payslip_payments_ipse',[id],{
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // payslip
|
|
|
+ fetchPayslipRun: function(id) {
|
|
|
+ var payslipRun = new openerp.web.Model('hr.payslip.run');
|
|
|
+ return payslipRun.call('eiru_get_payslip_run',[id],{
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Account Journal
|
|
|
+ fetchAccountJournal: function(id) {
|
|
|
+ var payslip = new openerp.web.Model('hr.payslip.run');
|
|
|
+ return payslip.call('eiru_get_payslip_account_journal',{
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // amoutn Formata currency
|
|
|
+ addAmountCurrency: function(){
|
|
|
+ var self = this;
|
|
|
+ _.each(self.payslipIpse, function(item) {
|
|
|
+ item.amountFormat = openerp.web.formatCurrency(item.amount, item.currency);
|
|
|
+ })
|
|
|
+ return self.payslipIpse;
|
|
|
+ },
|
|
|
+ /* Filter ips Payments */
|
|
|
+ getPayslipPayments: function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.payslipIpse, function(item) {
|
|
|
+ return item.slipId === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* Get Account Journal Select */
|
|
|
+ getAccountJournal: function(){
|
|
|
+ var self = this;
|
|
|
+ var journal = [];
|
|
|
+ _.each(self.accountJournal, function(item) {
|
|
|
+ journal.push({
|
|
|
+ 'id': item.id,
|
|
|
+ 'name': item.name,
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ if (journal.length) {
|
|
|
+ journal.unshift({
|
|
|
+ 'id': '',
|
|
|
+ 'name': ''
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return journal
|
|
|
+ },
|
|
|
+
|
|
|
+ /* Filter Journal select */
|
|
|
+ filterAccountJournal: function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.accountJournal, function(item){
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /* Modal */
|
|
|
+ showPaymentsIpse: function(payslip, currency, journal) {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var state = true;
|
|
|
+ var slipRun = self.payslispRun[0];
|
|
|
+ var currency = slipRun.currency;
|
|
|
+ var accountJournal = self.getAccountJournal();
|
|
|
+ var slip = self.addAmountCurrency();
|
|
|
+ var ipsPayments = []
|
|
|
+ var payslispRun = self.payslispRun[0];
|
|
|
+
|
|
|
+ var header = [];
|
|
|
+ if (payslispRun) {
|
|
|
+ header.push({
|
|
|
+ 'title': "Procesamiento "+ moment(payslispRun.date_start).format('DD/MM/YYYY')+" - "+moment(payslispRun.date_end).format('DD/MM/YYYY')
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ var modal = Qweb.render('eiruPayslipPayments.IPSEModal', {
|
|
|
+ 'slip': slip,
|
|
|
+ 'header': header,
|
|
|
+ 'journal': accountJournal,
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.openerp_webclient_container').after(modal);
|
|
|
+ $('.expired-account-modal').modal();
|
|
|
+
|
|
|
+ var selectIpsAll = $('.expired-account-modal').find('.select-ips-all');
|
|
|
+ var tableRow = $('.expired-account-modal').find('.table-tbody').find('tr');
|
|
|
+ /* amount */
|
|
|
+ var ipsTotal = $('.expired-account-modal').find('.amount-total');
|
|
|
+ /* journal && statement */
|
|
|
+ var journalSelected = $('.expired-account-modal').find('.journal-selected');
|
|
|
+ var statementSelected = $('.expired-account-modal').find('.statement-selected');
|
|
|
+ var refPaymsntIps = $('.expired-account-modal').find('.ref-paymsnt-ips');
|
|
|
+
|
|
|
+
|
|
|
+ /* button */
|
|
|
+ var buttonAccept = $('.expired-account-modal').find('.button-accept');
|
|
|
+ $('.expired-account-modal').find('.amount-symbol-payslip').text(currency[0].symbol);
|
|
|
+ $('.expired-account-modal').find('.ref-payments-ips-select').text("Nóminas seleccionadas\t"+ ipsPayments.length +"/"+ self.payslipIpse.length);
|
|
|
+
|
|
|
+ /* click */
|
|
|
+ selectIpsAll.click(function(e) {
|
|
|
+ var check = false;
|
|
|
+ if (e.target.checked === true) {
|
|
|
+ check = e.target.checked;
|
|
|
+ }
|
|
|
+
|
|
|
+ var amountTotal = 0;
|
|
|
+ ipsPayments = [];
|
|
|
+ /* Disabled Chech Moveline */
|
|
|
+ _.each(tableRow, function(tr) {
|
|
|
+ ($($(tr).children()[1]).find('.select-payments-ips'))[0].checked = check;
|
|
|
+
|
|
|
+ $(tr).removeClass('selected-ips');
|
|
|
+
|
|
|
+ if (check) {
|
|
|
+ idRow = parseInt(($(tr).children()[0].textContent).trim());
|
|
|
+ selectIps = self.getPayslipPayments(idRow).shift();
|
|
|
+
|
|
|
+ $(tr).addClass('selected-ips');
|
|
|
+
|
|
|
+ if (selectIps) {
|
|
|
+ ipsPayments.push({
|
|
|
+ 'slipId':selectIps.slipId,
|
|
|
+ 'amount': selectIps.amount,
|
|
|
+ 'employee_id': selectIps.slipEmployeeId
|
|
|
+ });
|
|
|
+ amountTotal += selectIps.amount;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ ipsTotal.val(openerp.web.formatCurrency(amountTotal, currency));
|
|
|
+ $('.expired-account-modal').find('.ref-payments-ips-select').text("Nóminas seleccionadas\t"+ ipsPayments.length +"/"+ self.payslipIpse.length)
|
|
|
+ });
|
|
|
+
|
|
|
+ /* Selecionar las cuotas */
|
|
|
+ tableRow.click(function(e) {
|
|
|
+ if (($(e.target).index() !== 0) ||(($(e.target).index() === 0) && ($(e.target)[0].className !== 'select-payments-ips')))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ selectIpsAll[0].checked = false;
|
|
|
+
|
|
|
+ if (e.target.checked === true) {
|
|
|
+ idRow = parseInt(($(e.target).closest('tr').children()[0].textContent).trim());
|
|
|
+ selectIps = self.getPayslipPayments(idRow).shift();
|
|
|
+
|
|
|
+ $(e.target).closest('tr').addClass('selected-ips');
|
|
|
+
|
|
|
+ ipsPayments.push({
|
|
|
+ 'slipId':selectIps.slipId,
|
|
|
+ 'amount': selectIps.amount,
|
|
|
+ 'employee_id': selectIps.slipEmployeeId
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ $(e.target).closest('tr').removeClass('selected-ips');
|
|
|
+
|
|
|
+ var indexSplice = undefined;
|
|
|
+ _.each(ipsPayments, function(item, index){
|
|
|
+ if (item.id === idRow)
|
|
|
+ indexSplice = index
|
|
|
+ })
|
|
|
+
|
|
|
+ ipsPayments.splice(indexSplice,1);
|
|
|
+ }
|
|
|
+
|
|
|
+ var amountTotal = _.reduce(_.map(ipsPayments, function(map){
|
|
|
+ return map.amount;
|
|
|
+ }), function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ }, 0);
|
|
|
+
|
|
|
+ ipsTotal.val(openerp.web.formatCurrency(amountTotal, currency));
|
|
|
+ $('.expired-account-modal').find('.ref-payments-ips-select').text("Nóminas seleccionadas\t"+ ipsPayments.length +"/"+ self.payslipIpse.length);
|
|
|
+ });
|
|
|
+
|
|
|
+ /* Journal Change */
|
|
|
+ journalSelected.change(function(e){
|
|
|
+ $('.expired-account-modal').find('.paymnet-payslip-statement-open').css('display','none');
|
|
|
+ statementSelected.empty();
|
|
|
+ if (!!journalSelected.val()) {
|
|
|
+ var statementjournal = self.filterAccountJournal(parseInt(journalSelected.val())).shift();
|
|
|
+ var statementOpen = statementjournal.statementOpen;
|
|
|
+
|
|
|
+ if (!!statementOpen.length){
|
|
|
+ $('.expired-account-modal').find('.paymnet-payslip-statement-open').css('display','flex');
|
|
|
+ statementSelected.append('<option value=""></option>');
|
|
|
+ _.each(statementOpen, function(item) {
|
|
|
+ statementSelected.append('<option value="' + item.id + '">' + item.name+" - "+moment(item.date).format("DD-MM-YYYY")+ '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ buttonAccept.click(function(e) {
|
|
|
+ if (!ipsPayments.length){
|
|
|
+ instance.web.notification.do_warn("Atención","Tienes que seleccionar al menos un ítem (ips) para continuar.");
|
|
|
+ tableRow.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!journalSelected.val()) {
|
|
|
+ instance.web.notification.do_warn("Atención","Tienes que seleccionar un método de pago para continuar.");
|
|
|
+ journalSelected.css('border-color','red');
|
|
|
+ journalSelected.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ journalSelected.css('border-color','#ccc');
|
|
|
+ var statementjournal = self.filterAccountJournal(parseInt(journalSelected.val())).shift();
|
|
|
+ var statementOpen = statementjournal.statementOpen;
|
|
|
+
|
|
|
+ if (!!statementOpen.length && !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');
|
|
|
+
|
|
|
+ if (!refPaymsntIps.val().trim()) {
|
|
|
+ instance.web.notification.do_warn("Atención","Debes ingresar una referencia de pago para continuar.");
|
|
|
+ refPaymsntIps.css('border-color','red');
|
|
|
+ refPaymsntIps.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ refPaymsntIps.css('border-color','#ccc');
|
|
|
+
|
|
|
+ var slipIds = _.map(ipsPayments, function(map){
|
|
|
+ return map.slipId;
|
|
|
+ });
|
|
|
+
|
|
|
+ paymenstIps = {
|
|
|
+ 'runId': self.id,
|
|
|
+ 'journalId': parseInt(journalSelected.val()),
|
|
|
+ 'statementId': parseInt(statementSelected.val()),
|
|
|
+ 'refPayments': refPaymsntIps.val().trim(),
|
|
|
+ 'slipIds': slipIds
|
|
|
+ }
|
|
|
+ /* Guardar */
|
|
|
+ $('.expired-account-modal').find('.widget-content.widget-loading-payments-ips').css('display','flex');
|
|
|
+ self.paymentsPayslipIps(paymenstIps).then(function(paymentsIps){
|
|
|
+ return paymentsIps;
|
|
|
+ }).then(function(paymentsIps) {
|
|
|
+ if (!paymentsIps.state) {
|
|
|
+ instance.web.notification.do_warn("Atención", paymentsIps.message, true);
|
|
|
+ }
|
|
|
+ $('.expired-account-modal').find('.widget-content.widget-loading-payments-ips').css('display','none');
|
|
|
+ self.removeModal(e);
|
|
|
+ defer.resolve(paymentsIps)
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ /* Click Cerrar */
|
|
|
+ $('.expired-account-modal').on('hidden.bs.modal', function (e) {
|
|
|
+ defer.resolve(false);
|
|
|
+ self.removeModal(e);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*Pagar nominas */
|
|
|
+ paymentsPayslipIps: function(paymenstIps) {
|
|
|
+ var payslipRun = new instance.web.Model('hr.payslip.run');
|
|
|
+ return payslipRun.call('eiru_payslip_payments_ipse', [paymenstIps],{
|
|
|
+ context: new instance.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ if (instance.web && instance.web.FormView) {
|
|
|
+ instance.web.FormView.include({
|
|
|
+ load_record: function(record) {
|
|
|
+ this._super.apply(this, arguments);
|
|
|
+
|
|
|
+ if (this.model !== 'hr.payslip.run')
|
|
|
+ return;
|
|
|
+
|
|
|
+ local.parentInstancePayslipPaymentsIPSE = this;
|
|
|
+
|
|
|
+ if (local.widgetInstancePayslipPaymentsIPSE) {
|
|
|
+ local.widgetInstancePayslipPaymentsIPSE.updateId(record.id);
|
|
|
+ if (this.$el.find('.payslip-payments-ipse').length !== 0){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.$el.find('.payslip-payments-ipse').length !== 0 )
|
|
|
+ return;
|
|
|
+
|
|
|
+ local.widgetInstancePayslipPaymentsIPSE = new local.PayslipPaymentsIPSE(this);
|
|
|
+
|
|
|
+ var elemento = this.$el.find('.oe_form').find('.eiru-payslip-payments');
|
|
|
+
|
|
|
+ local.widgetInstancePayslipPaymentsIPSE.appendTo(elemento);
|
|
|
+ local.widgetInstancePayslipPaymentsIPSE.updateId(record.id);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+}
|