|
@@ -0,0 +1,299 @@
|
|
|
+openerp.payroll_print = function (instance, local) {
|
|
|
+ local.widgetInstance = null;
|
|
|
+ local.parentInstance = null;
|
|
|
+
|
|
|
+ local.PrintPayrollWidget = instance.Widget.extend({
|
|
|
+ template : "payroll_print.PrintPayroll",
|
|
|
+ resInvoice:[],
|
|
|
+ resPersonal:[],
|
|
|
+ personal:[],
|
|
|
+ pagare:[],
|
|
|
+ resInvoiceLine:[],
|
|
|
+ jsonDoc:[],
|
|
|
+
|
|
|
+
|
|
|
+ init:function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+
|
|
|
+ updateId : function(id){
|
|
|
+ var self = this;
|
|
|
+ self.id=id;
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ this.$el.click(function () {
|
|
|
+ self.fecthInitial();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fecthInitial: function(){
|
|
|
+ var id= openerp.webclient._current_state.id;
|
|
|
+ var self = this;
|
|
|
+ self.fecthInvoice(id).then(function(invoice){
|
|
|
+ return invoice;
|
|
|
+ }).then(function(invoice){
|
|
|
+ self.resInvoice = invoice;
|
|
|
+ return self.fetchInvoiceLine();
|
|
|
+ }).then(function(invoiceLine){
|
|
|
+ self.resInvoiceLine = invoiceLine;
|
|
|
+ return self.fetchPersonal();
|
|
|
+ }).then(function(personal){
|
|
|
+ self.resPersonal = personal;
|
|
|
+ return self.drawPDF();
|
|
|
+ });
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fecthInvoice: function(id){
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields =['id', 'name', 'number', 'employee_id', 'invoice_line', 'create_date', 'date_from','date_to'];
|
|
|
+ var domain=[['id', '=', id]];
|
|
|
+ var Invoice = new instance.web.Model('hr.payslip');
|
|
|
+ Invoice.query(fields).filter(domain).order_by('id').all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInvoiceLine: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var id = _.flatten(_.map(self.resInvoice,function(map){
|
|
|
+ return map.id;
|
|
|
+ }));
|
|
|
+ var domain=[['slip_id','=', id]];
|
|
|
+ var InvoiceLine = new instance.web.Model('hr.payslip.line');
|
|
|
+ InvoiceLine.query(['id', 'name', 'slip_id', 'total']).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fetchPersonal: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var employee_id = _.flatten(_.map(self.resInvoice,function(map){
|
|
|
+ return map.employee_id[0];
|
|
|
+ }));
|
|
|
+ var fields=['id','name_related','address_home_id','identification_id','job_id', 'address_id'];
|
|
|
+ var domain=[['id','=', employee_id]];
|
|
|
+ var Personal = new instance.web.Model('hr.employee');
|
|
|
+
|
|
|
+ Personal.query(fields).filter(domain).order_by('id').all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ getPartner: function(employee_id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.resPersonal,function(item){
|
|
|
+ return item.id === employee_id;
|
|
|
+ }).shift();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor ="";
|
|
|
+ if (dato){
|
|
|
+ valor=dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ drawPDF:function(){
|
|
|
+ var self = this;
|
|
|
+ var doc=[];
|
|
|
+ var docItem=[];
|
|
|
+ var getColumns=[];
|
|
|
+ var resInvoice = self.resInvoice;
|
|
|
+ var resInvoiceLine = self.resInvoiceLine;
|
|
|
+ var employee = self.getPartner(resInvoice[0].employee_id[0]);
|
|
|
+
|
|
|
+
|
|
|
+ var pdfDoc = new jsPDF();
|
|
|
+ doc.push({
|
|
|
+ id : resInvoice[0].id,
|
|
|
+ number : self.valorNull(resInvoice[0].number),
|
|
|
+ name : self.valorNull(resInvoice[0].name),
|
|
|
+ date : moment(resInvoice[0].create_date).format("DD [de] MMMM [de] YYYY"),
|
|
|
+ reference : resInvoice[0].name,
|
|
|
+ date_from : moment(resInvoice[0].date_from).format("DD[-]MM[-]YYYY"),
|
|
|
+ date_to : moment(resInvoice[0].date_to).format("DD[-]MM[-]YYYY"),
|
|
|
+ employee_id : self.valorNull(resInvoice[0].employee_id[1]),
|
|
|
+ address_home_id : self.valorNull(employee.address_home_id[0].address),
|
|
|
+ identification : self.valorNull(employee.identification_id[1]),
|
|
|
+ job_id : self.valorNull(employee.job_id[1])
|
|
|
+ });
|
|
|
+
|
|
|
+ for (var i = 0; i < resInvoiceLine.length; i++) {
|
|
|
+
|
|
|
+ docItem.push({
|
|
|
+ xnumber : i + 1,
|
|
|
+ line_name : resInvoiceLine[i].name,
|
|
|
+ line_price_total : accounting.formatNumber(resInvoiceLine[i].total,0,".",",")
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ getColumns.push({
|
|
|
+ title : 'Orden',
|
|
|
+ dataKey: 'xnumber'
|
|
|
+ });
|
|
|
+ getColumns.push({
|
|
|
+ title : 'Descripcion',
|
|
|
+ dataKey: 'line_name'
|
|
|
+ });
|
|
|
+ getColumns.push({
|
|
|
+ title : 'SubTotal',
|
|
|
+ dataKey: 'line_price_total'
|
|
|
+ });
|
|
|
+
|
|
|
+ var rows = docItem;
|
|
|
+ pdfDoc.autoTable(getColumns, rows, {
|
|
|
+
|
|
|
+ styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
|
|
|
+ columnStyles: {
|
|
|
+ xnumber : {halign:'left',columnWidth: '4px'},
|
|
|
+ line_name : {columnWidth: '10px'},
|
|
|
+ line_price_total : {halign:'right',columnWidth: '4px'},
|
|
|
+ },
|
|
|
+ margin: { top: 55, horizontal: 7},
|
|
|
+
|
|
|
+ addPageContent: function () {
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Fecha: ', 7, 15);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(doc[0].date, 21, 15);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Nómina: ', 7, 25);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(doc[0].number, 32, 25);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Descripción: ', 7, 30);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(doc[0].name, 35, 30);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Funcionario: ', 7, 35);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(doc[0].employee_id, 30, 35);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(135, 35,'Identificación N°: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(doc[0].identification, 170, 35);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Direccion: ', 7, 40);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(28,40, doc[0].address_home_id);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(135,40,'Cargo: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(147,40, doc[0].job_id);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Fecha desde: ', 7, 45);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(34,45, doc[0].date_from);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(135,45,'Fecha hasta: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(158,45, doc[0].date_to);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(135,128,'Firma: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(158,128,'.......................');
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ pdfDoc.save('Nómina.pdf')
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ if(instance.web && instance.web.FormView){
|
|
|
+ instance.web.FormView.include({
|
|
|
+ load_form: function (record) {
|
|
|
+ this._super.apply(this, arguments);
|
|
|
+ if (this.model !== 'hr.payslip') return
|
|
|
+ local.parentInstance = this;
|
|
|
+ if (local.widgetInstance) {
|
|
|
+ local.widgetInstance.updateId(record.id);
|
|
|
+ }
|
|
|
+ local.parentInstance = this;
|
|
|
+ if (local.widgetInstance) {
|
|
|
+ local.widgetInstance.updateId(record.id);
|
|
|
+ }
|
|
|
+ local.widgetInstance = new local.PrintPayrollWidget(this);
|
|
|
+ var elemento = this.$el.find('.oe_form_sheet.oe_form_sheet_width');
|
|
|
+ elemento = elemento.find('.oe_right.oe_button_box.payroll_button_box');
|
|
|
+ local.widgetInstance.appendTo(elemento);
|
|
|
+ local.widgetInstance.updateId(record.id);
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+}
|