123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- (function() {
- openerp.widgetInstanceUnity = null;
- openerp.parentInstanceUnity = {};
- var instance = openerp.web;
- openerp.payslipPaymentsUnity = openerp.Widget.extend({
- template: 'eiru_payslip_payments.PayslipUnityWidget',
- id: undefined,
- hrPayslip: [],
- payslipLine: [],
- accountJournal: [],
- resCompany: [],
- resCurrency: [],
- /* init */
- init: function (parent) {
- this._super(parent);
- this.buttons = parent.$buttons;
- },
- /* Start */
- start: function () {
- var self = this;
- this.$el.click(function(){
- self.fetchPaymentInit();
- });
- 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');
- });
- },
- /* Actualizar ID */
- updateId: function(id) {
- var self = this;
- self.id = id;
- },
- /* ---------------------------------------------------------------------
- * Description: Funcione Inicial Pagos de Nominas
- * -------------------------------------------------------------------*/
- /* Método Inicial */
- fetchPaymentInit: function() {
- var self = this;
- self.fetchPayslip().then(function(hrPayslip) {
- return hrPayslip;
- }).then(function(hrPayslip) {
- self.hrPayslip = hrPayslip;
- return self.fetchPayslipLine();
- }).then(function(payslipLine) {
- self.payslipLine = payslipLine;
- return self.fecthJournal();
- }).then(function(accountJournal) {
- self.accountJournal = accountJournal;
- return self.fecthCompany();
- }).then(function(resCompany) {
- self.resCompany = resCompany;
- return self.fecthCurrency();
- }).then(function(resCurrency) {
- self.resCurrency = resCurrency;
- return self.showPayslipPayments();
- }).then(function() {
- return self.reloadLine();
- });
- },
- /* Consultar nominas de funcionario */
- fetchPayslip: function() {
- var self = this;
- var fields = ['id', 'name', 'employee_id', 'date_from', 'date_to', 'move_id', 'number', 'line_ids', 'journal_id'];
- var domain = [['id', '=', self.id]];
- var payslip = new instance.Model('hr.payslip');
- return payslip.query(fields).filter(domain).all();
- },
- /* Consultar detalles nominas de funcionario */
- fetchPayslipLine: function() {
- var self = this;
- var fields = ['id', 'name', 'code', 'total', 'amount', 'slip_id'];
- var domain = [['slip_id', '=', self.id], ['code', '=', 'NET']];
- var payslipLine = new instance.Model('hr.payslip.line');
- return payslipLine.query(fields).filter(domain).all();
- },
- /* Consultar método de pagos */
- fecthJournal: function() {
- var fields = ['id', 'name', 'code', 'type', 'currency', 'default_debit_account_id', 'default_credit_account_id'];
- var domain = [['active', '=', true], ['type', 'in', ['bank', 'cash']], ['currency', '=', false]];
- var journalSalario = new instance.Model('account.journal');
- return journalSalario.query(fields).filter(domain).all();
- },
- /* Consultar Compania */
- fecthCompany: function() {
- var fields = ['id','name', 'currency_id'];
- var domain = [['id', '=', 1]];
- var resCompanyIds = new instance.Model('res.company');
- return resCompanyIds.query(fields).filter(domain).all();
- },
- /* Consultar Moneda Activas */
- fecthCurrency : function() {
- var fields = ['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
- var domain = [['active','=', true]];
- var resCurrecy = new instance.Model('res.currency');
- return resCurrecy.query(fields).filter(domain).all();
- },
- /* Filtar moneda de la compania*/
- getCurrencyCompany: function(id) {
- var self = this;
- return _.filter(self.resCurrency, function(item) {
- return item.id === id;
- });
- },
- /* Activar el modal de pagos */
- showPayslipPayments: function(payslip, currency) {
- var self = this;
- var defer = $.Deferred();
- var hrPayslip = self.hrPayslip.shift();
- var payslipLine = self.payslipLine.shift();
- var company = self.resCompany.shift();
- var currency = self.getCurrencyCompany(company.currency_id[0]).shift();
- // cabecera
- var headerModalName = [{
- name: hrPayslip.name
- }];
- // ítem cuerpo
- var dataPayslip = [{
- employee: hrPayslip.employee_id[1],
- periodo: moment(hrPayslip.date_from).format('DD/MM/YYYY')+" - "+moment(hrPayslip.date_to).format('DD/MM/YYYY'),
- ref: hrPayslip.number,
- amount: accounting.formatMoney(payslipLine.amount, currency.symbol, currency.decimal_places, currency.thousands_separator, currency.decimal_separator)
- }];
- var payslipPayment = instance.qweb.render('EiruPayslipPaymentsModal', {
- data: dataPayslip,
- dataName: headerModalName,
- journal: self.accountJournal
- });
- $('.openerp_webclient_container').after(payslipPayment);
- $('.expired-account-modal').modal();
- var buttonPayment =$('.expired-account-modal').find('.payments-payslip');
- var journal_ref = $('.expired-account-modal').find('.journal-ref');
- var journal = $('.expired-account-modal').find('.current-journal');
- /* Cerrar el modal */
- $('.expired-account-modal').on('hidden.bs.modal', function (e) {
- defer.resolve(false);
- self.removeModal(e);
- });
- /* payments */
- buttonPayment.click(function(e) {
- if (!journal.val()) {
- instance.notification.do_warn("Atención","Seleccione un método de pago.");
- journal.css('border-color','red');
- return;
- }
- journal.css('border-color','#ccc');
- var payslip = new instance.Model('hr.payslip');
- payslip.call('create_from_prayslip', [
- {
- id: hrPayslip.id,
- journal_id: journal.val(),
- journal_ref: journal_ref.val()
- }
- ],{
- context: new instance.CompoundContext()
- }).then(function(results) {
- defer.resolve(results);
- if (results.length > 0){
- instance.notification.do_warn("Atención","No se pudo completar el pago de "+hrPayslip.name+" , porque ya se encuentra en un registros de caja/extractos bancarios (Referencia:"+results+")", true);
- }
- });
- self.removeModal(e);
- });
- return defer;
- },
- /* Remover la ventana modal */
- removeModal: function() {
- $('.expired-account-modal').remove();
- $('.modal-backdrop').remove();
- },
- /* Recargar la vista */
- reloadLine: function() {
- openerp.parentInstanceUnity.reload();
- },
- });
- if (openerp.web && openerp.web.FormView) {
- openerp.web.FormView.include({
- load_record: function(record) {
- this._super.apply(this, arguments);
- if (this.model !== 'hr.payslip')
- return;
- if (this.$el.find('.oe_form_sheet.oe_form_sheet_width').closest('.modal-content.openerp').length !== 0)
- return;
- openerp.parentInstanceUnity = this;
- if (openerp.widgetInstanceUnity) {
- openerp.widgetInstanceUnity.updateId(record.id);
- }
- if (this.$el.find('.payments-unity').length !== 0 )
- return;
- openerp.widgetInstanceUnity = new openerp.payslipPaymentsUnity(this);
- var elemento = this.$el.find('.oe_form_sheet.oe_form_sheet_width');
- elemento = elemento.find('.payslip-payment-unity');
- openerp.widgetInstanceUnity.appendTo(elemento[0]);
- openerp.widgetInstanceUnity.updateId(record.id);
- }
- });
- }
- })();
|