Kaynağa Gözat

[ADD] impresión de nominas de funcionario

adrielso 7 yıl önce
ebeveyn
işleme
35d341e265

+ 196 - 10
static/src/js/payslip_advancement.js

@@ -7,6 +7,7 @@
     openerp.PayslipAdvancement = openerp.Widget.extend({
         template: 'payslip_add.AdvancementWidget',
         id: undefined,
+        uid: undefined,
         row_id_select: undefined,
         row_code_select: undefined,
         hrPayslip: [],
@@ -14,28 +15,35 @@
         salaryRule: [],
         resCompany: [],
         resCurrency: [],
+        payslipInput: [],
         /* init */
         init: function (parent) {
             this._super(parent);
+            this.uid = parent.session.uid;
         },
         /* Start */
         start: function () {
             var self = this;
-            var addFaults = this.$el.find('.add-advancement');
-            var editFaults = this.$el.find('.edit-advancement');
-            var refreshFaults = this.$el.find('.refresh-advancement');
+            var addAdvancement = this.$el.find('.add-advancement');
+            var editAdvancement = this.$el.find('.edit-advancement');
+            var refreshAdvancement = this.$el.find('.refresh-advancement');
+            var printAdvancement = this.$el.find('.print-advancement');
             // create
-            addFaults.click(function() {
+            addAdvancement.click(function() {
                 self.fetchAddAdvancement();
             });
             // Edit/ unlink
-            editFaults.click(function() {
+            editAdvancement.click(function() {
                 self.fetchModifyAdvancement();
             });
             // Update
-            refreshFaults.click(function() {
+            refreshAdvancement.click(function() {
                 self.fetchRecomputeSheet();
-            })
+            });
+            // Imprimir Adelanto y comision
+            printAdvancement.click(function() {
+                self.fetchPrintAdvancement();
+            });
         },
         /* Actualizar ID */
         updateIdAdvancement: function(id) {
@@ -94,6 +102,7 @@
             self.salaryRule = [];
             self.resCompany = [];
             self.resCurrency = [];
+            self.payslipInput =[];
         },
         /* ---------------------------------------------------------------------
         ** Description : Crear Adealnto/ comision de Funcionario
@@ -130,7 +139,7 @@
         fetchPayslip: function() {
             var self = this;
             var payslip = new openerp.web.Model('hr.payslip');
-            return payslip.query(['name', 'employee_id', 'number']).filter([['id', '=', self.id]]).all();
+            return payslip.query(['name', 'employee_id', 'number','date_from','date_to']).filter([['id', '=', self.id]]).all();
         },
         /* Description: Consultar payslip Line (hr.payslip.line) */
         fetchPayslipLine: function() {
@@ -284,7 +293,7 @@
         /* Description: COnsultar Payslip Input (hr.payslip.input)*/
         fetchPayslipInput: function() {
             var self = this;
-            var fields = ['id','name', 'code', 'amount'];
+            var fields = ['id','name', 'code', 'amount','create_date'];
             var domain = [['payslip_id', '=', self.id]];
             var hrPayslipInput = new openerp.web.Model('hr.payslip.input');
             return hrPayslipInput.query(fields).filter(domain).all();
@@ -518,6 +527,184 @@
             });
             return defer;
         },
+        /* ---------------------------------------------------------------------
+         * Description : Imprimir adelanto y comisión de funcionario
+         * -------------------------------------------------------------------*/
+        /* Description : Metodo Inicial de imprecion */
+        fetchPrintAdvancement: function() {
+            var self = this;
+            self.fetchPayslip().then(function(hrPayslip) {
+                return hrPayslip;
+            }).then(function(hrPayslip) {
+                self.hrPayslip = hrPayslip;
+                return self.fetchPayslipInput();
+            }).then(function(payslipInput) {
+                self.payslipInput = payslipInput;
+                return self.fetchResCompany();
+            }).then(function(resCompany) {
+                self.resCompany = resCompany;
+                return self.fetchResCurrecy();
+            }).then(function(resCurrency) {
+                self.resCurrency = resCurrency;
+                return self.fetchResUser();
+            }).then(function(resUser){
+                self.resUser = resUser;
+                return self.fetchSalaryRule();
+            }).then(function(salaryRule) {
+                self.salaryRule = salaryRule;
+                return self.jsPdfPrintAdvancement();
+            });
+                //
+        },
+        /* Consultar Usuario (res.User) */
+        fetchResUser: function() {
+            var self = this;
+            var resUser = new openerp.web.Model('res.users');
+            return resUser.query(['name']).filter([['active', '=', true],['id', '=', self.uid]]).all();
+        },
+        /* Filtar Adelantos */
+        getpayslipInput: function() {
+            var self = this;
+            return _.filter(self.payslipInput, function(item) {
+                return item.code === "ADL";
+            });
+
+        },
+        /* Generar la impresion de Adelanto */
+        jsPdfPrintAdvancement: function() {
+            var self = this;
+            var payslipInput = self.getpayslipInput();
+
+            if (payslipInput.length === 0){
+                openerp.web.notification.do_warn("Atención","El funcionario no cuenta con adelantos registrado");
+                return;
+            }
+            var inputBody = [];
+            var inputHead = [
+                {
+                    title : 'Tipo de operación',
+                    dataKey : 'code_name'
+                },
+                {
+                    title : 'Descripción',
+                    dataKey : 'input_name'
+                },
+                {
+                    title : 'Importe',
+                    dataKey : 'amount_input'
+                },
+                {
+                    title : 'Fecha de operación',
+                    dataKey : 'date'
+                },
+            ];
+            var salaryRule;
+            var company = self.resCompany.shift();
+            var currency = self.getCurrencyCompany(company.currency_id[0]).shift();
+
+            _.each(payslipInput, function(input) {
+                salaryRule = self.getSalaryRule(input.code).shift();
+                if (!salaryRule){
+                    salaryRule ={};
+                    salaryRule.name="N/A";
+                }
+                inputBody.push({
+                    code_name :  salaryRule.name,
+                    input_name: input.name,
+                    amount_input: accounting.formatNumber((-1 * input.amount), currency.decimal_places, currency.thousands_separator, currency.decimal_separator),
+                    amount: (-1 * input.amount),
+                    date: moment(input.create_date).format('DD/MM/YYYY')
+                });
+            });
+            /* sumar los importe*/
+            var total = _.reduce(_.map(inputBody, function(map) {
+                return map.amount;
+            }),function(memo, num){
+                return memo + num;
+            }, 0);
+
+            inputBody.push({
+                code_name :  "",
+                input_name: 'Total' ,
+                amount_input: accounting.formatNumber(total, currency.decimal_places, currency.thousands_separator, currency.decimal_separator),
+                amount: total,
+                date: ""
+            });
+            self.drawPDF(inputHead, inputBody, total, currency);
+        },
+        /* Generar el pdf*/
+        drawPDF: function(inputHead, inputBody, total, currency) {
+            var self = this;
+            var hrPayslip = self.hrPayslip.shift();
+            var resUser = self.resUser.shift();
+            var pdfDoc = new jsPDF();
+            /* titulo */
+            pdfDoc.setFontType('bold');
+            pdfDoc.setFontSize(18);
+            pdfDoc.text(105, 20, "RECIBO DE ADELANTO", null, null, 'center');
+            /* Subtitulos*/
+            pdfDoc.setFontType('bold');
+            pdfDoc.setFontSize(12);
+            pdfDoc.text(20, 30, "Funcionario: ");
+            pdfDoc.text(20, 40, "Referencia: ");
+            pdfDoc.text(120, 40, "Periodo: ");
+            /* Detalles */
+            pdfDoc.setFontType('normal');
+            pdfDoc.setFontSize(12);
+            pdfDoc.text(50, 30, hrPayslip.employee_id[1]);
+            pdfDoc.text(50, 40, hrPayslip.number);
+            pdfDoc.text(150, 40, moment(hrPayslip.date_from).format('DD/MM/YYYY')+" - "+moment(hrPayslip.date_to).format('DD/MM/YYYY'));
+            /* Tabla */
+            pdfDoc.autoTable(inputHead, inputBody, {
+                margin: {
+                    top: 50,
+                    horizontal: 7
+                },
+                styles: { overflow: 'linebreak', fontSize: 10, columnWidth: 'wrap'},
+                columnStyles: {
+                    code_name: {columnWidth: 35},
+                    input_name: {columnWidth: 'auto'},
+                    amount_input: {columnWidth: 30, halign:'right'},
+                    date: {columnWidth: 40, halign:'center'},
+                },
+            });
+            var first = pdfDoc.autoTable.previous;
+            var fila = first.finalY;
+            var moneda = self.getNameCurrency(currency.name);
+            /*Final de la pagina*/
+            fila = fila + 20;
+            pdfDoc.setFontType('bold');
+            pdfDoc.setFontSize(12);
+            pdfDoc.text(10, fila, "TOTAL EN LETRAS ");
+
+            pdfDoc.setFontType('normal');
+            pdfDoc.setFontSize(12);
+            pdfDoc.text(50, fila, moneda+": "+openerp.web.num2word(total));
+
+            fila = fila + 20;
+            pdfDoc.setFontType('bold');
+            pdfDoc.setFontSize(10);
+            pdfDoc.text(10, fila, "Firma ......................................");
+            pdfDoc.text(150, fila, "Firma ......................................");
+
+            fila = fila + 5;
+            pdfDoc.text(10, fila,resUser.name);
+            pdfDoc.text(150, fila, hrPayslip.employee_id[1] );
+            /* Guardar */
+            pdfDoc.save('RECIBO DE ADELANTO de'+hrPayslip.employee_id[1]+'.pdf');
+
+        },
+        /* Obtener el nombre de la moneda */
+        getNameCurrency: function(code) {
+            var moneda = "";
+            if (code === 'PYG') {
+                moneda ="GUARANÍES"
+            }
+            if (code === 'USD') {
+                moneda ="DÓLARES AMERICANOS "
+            }
+            return moneda
+        }
     });
 
     if (openerp.web && openerp.web.FormView) {
@@ -532,7 +719,6 @@
                     return;
 
                 openerp.parentInstance = this;
-
                 if (openerp.widgetInstanceAdvancement) {
                     openerp.widgetInstanceAdvancement.updateIdAdvancement(record.id);
                 }

+ 5 - 1
static/src/xml/payslip_add_advancement.xml

@@ -10,9 +10,13 @@
                 <div class="stat_button_icon fa fa-plus-square-o"></div>
                 <div>Crear</div>
             </button>
-            <button class="oe_stat_button btn btn-default oe_inline edit-advancement" title="Modificar u eliminar los adelantos o las comisiones">
+            <!-- <button class="oe_stat_button btn btn-default oe_inline edit-advancement" title="Modificar u eliminar los adelantos o las comisiones">
                 <div class="stat_button_icon fa fa-pencil-square-o"></div>
                 <div>Editar/Eliminar</div>
+            </button> -->
+            <button class="oe_stat_button btn btn-default oe_inline print-advancement" title="Imprimir adelanto u comisión de funcionario">
+                <div class="stat_button_icon fa fa-print"></div>
+                <div>Imprimir</div>
             </button>
         </div>
   </t>