|
@@ -8,6 +8,11 @@ openerp.eiru_payslip_payments = function(instance, local) {
|
|
|
template: 'eiru_payslip_payments.PayslipWidget',
|
|
|
id: undefined,
|
|
|
payslip: [],
|
|
|
+ payslipLine: [],
|
|
|
+ accountJournal: [],
|
|
|
+ company: [],
|
|
|
+ currency: [],
|
|
|
+ payslipNew: [],
|
|
|
|
|
|
init: function(parent) {
|
|
|
this._super(parent);
|
|
@@ -16,40 +21,47 @@ openerp.eiru_payslip_payments = function(instance, local) {
|
|
|
var self = this;
|
|
|
this.$el.click(function(){
|
|
|
self.fectchInitial()
|
|
|
- // self.showPayments();
|
|
|
});
|
|
|
},
|
|
|
updateId: function(id) {
|
|
|
var self = this;
|
|
|
self.id = id;
|
|
|
},
|
|
|
-
|
|
|
+ // Metodo Inicial
|
|
|
fectchInitial: function() {
|
|
|
var self = this;
|
|
|
self.fectchHrPayslip().then(function(payslip) {
|
|
|
return payslip;
|
|
|
}).then(function(payslip) {
|
|
|
self.payslip = payslip;
|
|
|
- // console.log(self.payslip);
|
|
|
return self.fectchHrPayslipLine(payslip);
|
|
|
}).then(function(payslipLine) {
|
|
|
self.payslipLine = payslipLine;
|
|
|
- return self.fectchJournalSalario();
|
|
|
- }).then(function(journalSalario) {
|
|
|
- self.journalSalario = journalSalario;
|
|
|
- console.log(journalSalario);
|
|
|
-
|
|
|
- // console.log(payslipLine);
|
|
|
- // local.parentInstance.reload();
|
|
|
- // if (!payslip)
|
|
|
- // instance.web.notification.do_warn("Atención","No existe nomina para ser generada, en el periodo seleccionado");
|
|
|
+ return self.fectchJournal();
|
|
|
+ }).then(function(accountJournal) {
|
|
|
+ self.accountJournal = accountJournal;
|
|
|
+ return self.fectchCompany();
|
|
|
+ }).then(function(company) {
|
|
|
+ self.company = company;
|
|
|
+ return self.fectchCurency();
|
|
|
+ }).then(function(currency) {
|
|
|
+ self.currency = currency;
|
|
|
+ return self.joinPayslip();
|
|
|
+ }).then(function(payslipNew) {
|
|
|
+ self.payslipNew = payslipNew;
|
|
|
+ if (self.payslipNew.length <= 0) {
|
|
|
+ instance.web.notification.do_warn("Atención","No tienes nominas que pagar");
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return self.asyncPaymentsPayslip();
|
|
|
});
|
|
|
},
|
|
|
+ // payslip
|
|
|
fectchHrPayslip: function() {
|
|
|
var self = this;
|
|
|
var defer = $.Deferred();
|
|
|
var fields = ['id', 'name', 'employee_id', 'date_from', 'date_to', 'move_id', 'number', 'line_ids', 'journal_id'];
|
|
|
- var domain = [['payslip_run_id', 'in', [self.id]],['state', '=', 'done']];
|
|
|
+ var domain = [['payslip_run_id', 'in', [self.id]], ['state', '=', 'done']];
|
|
|
var payslip = new instance.web.Model('hr.payslip');
|
|
|
payslip.query(fields).filter(domain).all().then(function(results) {
|
|
|
defer.resolve(results);
|
|
@@ -59,13 +71,11 @@ openerp.eiru_payslip_payments = function(instance, local) {
|
|
|
},
|
|
|
// Hr payslip Line
|
|
|
fectchHrPayslipLine: function(payslip) {
|
|
|
- var self = this;
|
|
|
var defer = $.Deferred();
|
|
|
-
|
|
|
var payslip_id = _.map(payslip, function(map) {
|
|
|
return map.id;
|
|
|
});
|
|
|
- var fields = ['id', 'name', 'code', 'total', 'amount'];
|
|
|
+ var fields = ['id', 'name', 'code', 'total', 'amount', 'slip_id'];
|
|
|
var domain = [['slip_id', 'in', payslip_id], ['code', '=', 'NET']];
|
|
|
var payslipLine = new instance.web.Model('hr.payslip.line');
|
|
|
payslipLine.query(fields).filter(domain).all().then(function(results) {
|
|
@@ -75,15 +85,10 @@ openerp.eiru_payslip_payments = function(instance, local) {
|
|
|
return defer;
|
|
|
},
|
|
|
// Diario de Salario
|
|
|
- fectchJournalSalario: function() {
|
|
|
- var self = this;
|
|
|
+ fectchJournal: function() {
|
|
|
var defer = $.Deferred();
|
|
|
- var journal_id = _.map(self.payslip, function(map) {
|
|
|
- return map.journal_id[0];
|
|
|
- });
|
|
|
- console.log(journal_id);
|
|
|
var fields = ['id', 'name', 'code', 'type', 'currency', 'default_debit_account_id', 'default_credit_account_id'];
|
|
|
- var domain = [['id', 'in', journal_id]];
|
|
|
+ var domain = [['active', '=', true], ['type', 'in', ['bank', 'cash']], ['currency', '=', false]];
|
|
|
var journalSalario = new instance.web.Model('account.journal');
|
|
|
journalSalario.query(fields).filter(domain).all().then(function(results) {
|
|
|
defer.resolve(results);
|
|
@@ -91,31 +96,109 @@ openerp.eiru_payslip_payments = function(instance, local) {
|
|
|
|
|
|
return defer;
|
|
|
},
|
|
|
- // fectchGenerateNomina: function() {
|
|
|
- // var self = this;
|
|
|
- // var defer = $.Deferred();
|
|
|
- // var hr_payslip = new instance.web.Model('hr.payslip');
|
|
|
- //
|
|
|
- // hr_payslip.call('generate_payroll_eiru',[self.id], {
|
|
|
- // context: new instance.web.CompoundContext()
|
|
|
- // }).then(function(results) {
|
|
|
- // defer.resolve(results);
|
|
|
- // });
|
|
|
- // return defer;
|
|
|
- // },
|
|
|
-
|
|
|
- showPayments: function() {
|
|
|
+ // Company
|
|
|
+ fectchCompany: function() {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name', 'currency_id'];
|
|
|
+ var domain = [['id', '=', 1]];
|
|
|
+ var resCompanyIds = new instance.web.Model('res.company');
|
|
|
+ resCompanyIds.query(fields).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Res currecy
|
|
|
+ fectchCurency : function() {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
|
|
|
+ var domain = [['active','=', true]];
|
|
|
+ var resCurrecy = new instance.web.Model('res.currency');
|
|
|
+ resCurrecy.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // get payslipLine
|
|
|
+ getPayslipLine: function(slip_id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.payslipLine, function(filter) {
|
|
|
+ return filter.slip_id[0] === slip_id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Unir Payslip con payslipLine
|
|
|
+ joinPayslip: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var PayslipNew = [];
|
|
|
+ var line;
|
|
|
+ _.each(self.payslip, function(item) {
|
|
|
+ line = self.getPayslipLine(item.id).shift();
|
|
|
+ if (!line){
|
|
|
+ line = {};
|
|
|
+ line.total =0;
|
|
|
+ }
|
|
|
+ PayslipNew.push({
|
|
|
+ 'id': item.id,
|
|
|
+ 'name': item.name,
|
|
|
+ 'employee_id': item.employee_id[0],
|
|
|
+ 'employee': item.employee_id[1],
|
|
|
+ 'date_from': item.date_from,
|
|
|
+ 'date_to': item.date_to,
|
|
|
+ 'periodo': moment(item.date_from).format('DD/MM/YYYY')+" - "+moment(item.date_to).format('DD/MM/YYYY'),
|
|
|
+ 'number': item.number,
|
|
|
+ 'ammout': line.total
|
|
|
+ });
|
|
|
+ });
|
|
|
+ defer.resolve(PayslipNew);
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Moneda de la compania
|
|
|
+ getCurrencyCompany: function(id_currency) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.currency, function(item) {
|
|
|
+ return item.id === id_currency;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Async loop
|
|
|
+ asyncPaymentsPayslip: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var company = self.company.shift();
|
|
|
+ var currency = self.getCurrencyCompany(company.currency_id[0]).shift()
|
|
|
+
|
|
|
+ self.asyncLoopFactory(self.payslipNew.length, function(loop) {
|
|
|
+ var payslip = self.payslipNew[loop.iteration()];
|
|
|
+ self.showPayments(payslip, currency).then(function(results) {
|
|
|
+ self.reloadLine()
|
|
|
+ if (results){
|
|
|
+ loop.next();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }, function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // reloadLine
|
|
|
+ reloadLine: function() {
|
|
|
+ local.parentInstance.reload();
|
|
|
+ },
|
|
|
+ // Ejc. el Modal
|
|
|
+ showPayments: function(payslip, currency) {
|
|
|
var self = this;
|
|
|
- // Nomina Detalle
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var state = true;
|
|
|
var headerModalName = [{
|
|
|
- name: "Nómina salarial de Adrielso Kunert para diciembre-2017"
|
|
|
+ name: payslip.name
|
|
|
}];
|
|
|
- //
|
|
|
- dataPayslip = [{
|
|
|
- employee: 'Adrielso kunert',
|
|
|
- periodo: '01-10-2017 -30-10-2017',
|
|
|
- salario: '5.000.000',
|
|
|
- ref: ' SLIP/062'
|
|
|
+
|
|
|
+ var dataPayslip = [{
|
|
|
+ employee: payslip.employee,
|
|
|
+ periodo: payslip.periodo,
|
|
|
+ ref: payslip.number
|
|
|
}]
|
|
|
|
|
|
var modal = Qweb.render('EiruPayslipPaymentsModal', {
|
|
@@ -123,45 +206,102 @@ openerp.eiru_payslip_payments = function(instance, local) {
|
|
|
dataName: headerModalName,
|
|
|
});
|
|
|
|
|
|
-
|
|
|
$('.openerp_webclient_container').after(modal);
|
|
|
$('.expired-account-modal').modal();
|
|
|
-
|
|
|
+ // Total
|
|
|
+ $('.expired-account-modal').find('.amount-net').val(accounting.formatMoney(payslip.ammout, currency.symbol, currency.decimal_places, currency.thousands_separator, currency.decimal_separator))
|
|
|
+ // Referencia de Pago
|
|
|
+ var journal_ref = $('.expired-account-modal').find('.journal-ref');
|
|
|
// Cargara los metodo de pago
|
|
|
var journal = $('.expired-account-modal').find('.current-journal');
|
|
|
- console.log(journal);
|
|
|
- journal.append('<option value="1">TODAS LAS SUC.</option>');
|
|
|
- journal.append('<option value="2">TODAS LAS SUC.</option>');
|
|
|
- journal.append('<option value="3">TODAS LAS SUC.</option>');
|
|
|
- journal.append('<option value="4">TODAS LAS SUC.</option>');
|
|
|
- journal.append('<option value="5">TODAS LAS SUC.</option>');
|
|
|
- // Actualizar monto a pagar
|
|
|
- $('.expired-account-modal').find('.amount-net').val('5.000.000')
|
|
|
-
|
|
|
- // Selecion de Journal
|
|
|
- journal.click(function(e){
|
|
|
- $('.expired-account-modal').find('.amount-net').val(journal.val())
|
|
|
+ _.each(self.accountJournal, function(item) {
|
|
|
+ journal.append('<option value="'+item.id+'">'+item.name+'</option>');
|
|
|
})
|
|
|
// Click Cerrar
|
|
|
$('.expired-account-modal').on('hidden.bs.modal', function (e) {
|
|
|
+ // self.reloadLine()
|
|
|
+ defer.resolve(false);
|
|
|
self.removeModal(e);
|
|
|
- })
|
|
|
|
|
|
+ // return defer;
|
|
|
+ })
|
|
|
// clcik boton pagar
|
|
|
var contenido = $('.expired-account-modal').find('.payments-payslip');
|
|
|
- contenido.click(function (e) {
|
|
|
- // $(contenido).find('tr').removeClass('table-row-select');
|
|
|
- // $(e.target).closest('tr').addClass('table-row-select');
|
|
|
- // var chirdren_id =$(e.target).closest('tr').children()[0].textContent;
|
|
|
- // self.renderForm(chirdren_id);
|
|
|
- // console.log(e);
|
|
|
+ contenido.click(function(e) {
|
|
|
+
|
|
|
+ self.paymentsPayslip(payslip,journal.val(), journal_ref.val()).then(function(insert) {
|
|
|
+ return insert;
|
|
|
+ }).then(function(journal) {
|
|
|
+ if (!journal)
|
|
|
+ state = false;
|
|
|
+
|
|
|
+ // self.reloadLine()
|
|
|
+ defer.resolve(state);
|
|
|
+ })
|
|
|
+ self.removeModal(e);
|
|
|
});
|
|
|
+
|
|
|
+
|
|
|
+ return defer;
|
|
|
},
|
|
|
- // Remover <Modal></Modal>
|
|
|
- removeModal: function (e) {
|
|
|
+ // Remover
|
|
|
+ removeModal: function() {
|
|
|
$('.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
|
|
|
+ }
|
|
|
+ ],{
|
|
|
+ context: new instance.web.CompoundContext()
|
|
|
+ }).then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ /* ---------------------------------------------------------------------
|
|
|
+ * Description: Async loop util v2 written by Robert Gauto.
|
|
|
+ * --------------------------------------------------------------------*/
|
|
|
+ asyncLoopFactory: function (iterations, func, callback) {
|
|
|
+ var index = 0;
|
|
|
+ var done = false;
|
|
|
+ var loop = {
|
|
|
+ next: function() {
|
|
|
+ if (done) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (index < iterations) {
|
|
|
+ index++;
|
|
|
+ func(loop);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ done = true;
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ iteration: function () {
|
|
|
+ return index - 1;
|
|
|
+ },
|
|
|
+
|
|
|
+ break: function () {
|
|
|
+ done = true;
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ loop.next();
|
|
|
+ return loop;
|
|
|
+ },
|
|
|
});
|
|
|
|
|
|
if (instance.web && instance.web.FormView) {
|
|
@@ -191,4 +331,5 @@ openerp.eiru_payslip_payments = function(instance, local) {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
}
|