|
@@ -0,0 +1,524 @@
|
|
|
+function report_rrhh(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var instance = openerp;
|
|
|
+
|
|
|
+ reporting.ReportRrhhWidget = reporting.Base.extend({
|
|
|
+ template:'ReportRrhh',
|
|
|
+ resInvoice:[],
|
|
|
+ resPersonal:[],
|
|
|
+ personal:[],
|
|
|
+ pagare:[],
|
|
|
+ invoiceLines:[],
|
|
|
+ content:[],
|
|
|
+ rowsData :[],
|
|
|
+ modules:[],
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #X' : 'factSearch',
|
|
|
+ 'click #A' : 'factSearch',
|
|
|
+ 'click #B' : 'factSearch',
|
|
|
+ 'click #C' : 'factSearch',
|
|
|
+ 'click #D' : 'factSearch',
|
|
|
+ 'click #opportunity' : 'factSearch',
|
|
|
+ 'click #lead' : 'factSearch',
|
|
|
+ 'click #Z' : 'factSearch',
|
|
|
+
|
|
|
+ 'click #Y' : 'factSearch',
|
|
|
+ 'click #customer' : 'factSearch',
|
|
|
+ 'change #from' : 'factSearch',
|
|
|
+ 'change #to' : 'factSearch',
|
|
|
+ 'click-row.bs.table #table ' : 'clickAnalysisDetail',
|
|
|
+ },
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
+ this.fecthFecha();
|
|
|
+ this.submitForm();
|
|
|
+ },
|
|
|
+
|
|
|
+ // Redirecionar
|
|
|
+ renderReport: function () {
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
|
|
|
+ this.$el.closest('.report_view').remove();
|
|
|
+ container.find('.report_view').show({
|
|
|
+ effect: 'fade',
|
|
|
+ duration: 200,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Verificar el modelo
|
|
|
+ checkModel : function(model){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.modules,function(item){return item.name === model});
|
|
|
+ },
|
|
|
+ // Lanzar el mensaje
|
|
|
+ showMensaje : function(modelos){
|
|
|
+ var self = this;
|
|
|
+ $("#dialog" ).dialog({
|
|
|
+ autoOpen: true,
|
|
|
+ resizable: false,
|
|
|
+ modal: true,
|
|
|
+ title: 'Atención',
|
|
|
+ width: 500,
|
|
|
+ open: function() {
|
|
|
+ $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
|
|
|
+ },
|
|
|
+ show: {
|
|
|
+ effect: "fade",
|
|
|
+ duration: 200
|
|
|
+ },
|
|
|
+ hide: {
|
|
|
+ effect: "fade",
|
|
|
+ duration: 200
|
|
|
+ },
|
|
|
+ buttons: {
|
|
|
+ Aceptar: function() {
|
|
|
+ $(this).dialog('close');
|
|
|
+ self.renderReport()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return
|
|
|
+ },
|
|
|
+
|
|
|
+ clickAnalysisDetail: function(e, row, $element, field){
|
|
|
+ if (field == 'number'){
|
|
|
+ this.do_action({
|
|
|
+ name:"Nómina",
|
|
|
+ type: 'ir.actions.act_window',
|
|
|
+ res_model: "hr.payslip",
|
|
|
+ views: [[false,'form']],
|
|
|
+ target: 'new',
|
|
|
+ domain: [['id','=', row.id]],
|
|
|
+ context: {},
|
|
|
+ flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id: row.id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (field === 'personal'){
|
|
|
+ this.do_action({
|
|
|
+ name:"Registro",
|
|
|
+ type: 'ir.actions.act_window',
|
|
|
+ res_model: "hr.employee",
|
|
|
+ views: [[false,'form']],
|
|
|
+ target: 'new',
|
|
|
+ domain: [['id','=', row.employee_id]],
|
|
|
+ context: {},
|
|
|
+ flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id: row.employee_id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ e.stopImmediatePropagation();
|
|
|
+ },
|
|
|
+
|
|
|
+ submitForm: function () {
|
|
|
+ var self = this;
|
|
|
+ self.fecthIrModuleModule().then(function(modules){
|
|
|
+ self.modules = modules;
|
|
|
+ return modules;
|
|
|
+ }).then(function(modules){
|
|
|
+ return self.fecthInvoice();
|
|
|
+ }).then(function(invoice){
|
|
|
+ self.resInvoice = invoice;
|
|
|
+ return self.fetchInvoiceLine();
|
|
|
+ }).then(function(invoiceLine){
|
|
|
+ self.invoiceLines = invoiceLine;
|
|
|
+ return self.fetchPersonal();
|
|
|
+ }).then(function(personal){
|
|
|
+ self.resPersonal = personal;
|
|
|
+ self.search();
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // Modelos instalados
|
|
|
+ fecthIrModuleModule: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['name','id'];
|
|
|
+ var domain=[['state','=','installed']];
|
|
|
+ var irModule = new instance.web.Model('ir.module.module');
|
|
|
+
|
|
|
+ irModule.query(fields).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fecthFecha: function() {
|
|
|
+ var to;
|
|
|
+ var dateFormat1 = "mm/dd/yy",
|
|
|
+ from = $( "#from" )
|
|
|
+ .datepicker({
|
|
|
+ dateFormat: "dd/mm/yy",
|
|
|
+ changeMonth: true,
|
|
|
+ numberOfMonths: 1,
|
|
|
+ })
|
|
|
+ .on( "change", function() {
|
|
|
+ to.datepicker( "option", "minDate", getDate(this), "dd/mm/yyyy");
|
|
|
+ });
|
|
|
+ to = $( "#to" ).datepicker({
|
|
|
+ dateFormat: "dd/mm/yy",
|
|
|
+ defaultDate: "+7d",
|
|
|
+ changeMonth: true,
|
|
|
+ numberOfMonths: 1,
|
|
|
+ })
|
|
|
+ .on( "change", function() {
|
|
|
+ from.datepicker( "option", "maxDate", getDate(this));
|
|
|
+ });
|
|
|
+
|
|
|
+ function getDate( element ) {
|
|
|
+ var fechaSel =element.value.split('/');
|
|
|
+ var date;
|
|
|
+ try {
|
|
|
+ date = $.datepicker.parseDate( dateFormat1, (fechaSel[1]+"/"+fechaSel[0]+"/"+fechaSel[2]));
|
|
|
+ } catch( error ) {
|
|
|
+ date = null;
|
|
|
+ }
|
|
|
+ return date;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // Consultar Pagos
|
|
|
+ fecthInvoice: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var modules = self.checkModel('hr');
|
|
|
+ //
|
|
|
+ if (modules.length <= 0){
|
|
|
+ self.showMensaje('hr');
|
|
|
+ return defer;
|
|
|
+ }
|
|
|
+ var fields =['id', 'name', 'number', 'employee_id', 'line_ids', 'create_date', 'date_from','date_to','state'];
|
|
|
+ // var domain=[['id', '=', id]];
|
|
|
+ var Invoice = new instance.web.Model('hr.payslip');
|
|
|
+ Invoice.query(fields).filter().order_by('id').all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ // Invoice line (Linea de Factura)
|
|
|
+ fetchInvoiceLine: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var id = _.flatten(_.map(self.resInvoice,function(map){
|
|
|
+ return map.id;
|
|
|
+ }));
|
|
|
+ var domain=[['slip_id','in', id],['salary_rule_id', '=', 2]];
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ // Consultar Personal
|
|
|
+ fetchPersonal: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ 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().order_by('id').all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ // getPartner: function(id){
|
|
|
+ // var self = this;
|
|
|
+ // return _.filter(self.resPersonal,function(item){
|
|
|
+ // return item.id == id;
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+
|
|
|
+ getPartner: function(employee_id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.resPersonal,function(item){
|
|
|
+ return item.id === employee_id;
|
|
|
+ }).shift();
|
|
|
+ },
|
|
|
+
|
|
|
+ // Verificar si los Valores no son nulos
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor ="";
|
|
|
+ if (dato){
|
|
|
+ valor=dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ getPaySlip: function(slip_id){
|
|
|
+ var self = this;
|
|
|
+ return _.find(this.resInvoice,function (inv) {
|
|
|
+ return _.contains(inv.line_ids, slip_id);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ search: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.resPersonal;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
+ return {
|
|
|
+ label: item.id + '-'+ item.name_related,
|
|
|
+ value: item.id + '-'+ item.name_related
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$('#personal').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength:0,
|
|
|
+ search: function(event, ui) {
|
|
|
+ if (!(self.$('#personal').val())){
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.factSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ BuildTable: function(){
|
|
|
+ var self = this;
|
|
|
+ var data=[];
|
|
|
+ var getColumns=[];
|
|
|
+ var employee;
|
|
|
+ var item;
|
|
|
+ var state;
|
|
|
+ var invoice;
|
|
|
+
|
|
|
+ for (var i = 0; i < this.invoiceLines.length; i++) {
|
|
|
+ item = this.invoiceLines[i];
|
|
|
+ invoice = this.getPaySlip(item.id);
|
|
|
+ if(invoice.state=='done'){
|
|
|
+ state = 'Realizado'
|
|
|
+ }else{
|
|
|
+ state = 'Pagado'
|
|
|
+ }
|
|
|
+ employee = self.getPartner(invoice.employee_id[0]);
|
|
|
+
|
|
|
+ if (!employee){
|
|
|
+ employee={};
|
|
|
+ employee.identification_id="";
|
|
|
+ }
|
|
|
+
|
|
|
+ data.push({
|
|
|
+ id : invoice.id,
|
|
|
+ number : self.valorNull(invoice.number),
|
|
|
+ name : self.valorNull(invoice.name),
|
|
|
+ date: moment(invoice.create_date).format("YYYY-MM-DD"),
|
|
|
+ reference : invoice.name,
|
|
|
+ date_from : moment(invoice.date_from).format("DD[/]MM[/]YYYY"),
|
|
|
+ date_to : moment(invoice.date_to).format("DD[/]MM[/]YYYY"),
|
|
|
+ employee_id : self.valorNull(invoice.employee_id[0]),
|
|
|
+ employee_name : self.valorNull(invoice.employee_id[1]),
|
|
|
+ amount : accounting.formatNumber(self.valorNull(item.total),0, ".", ","),
|
|
|
+ amount_total: self.valorNull(item.total),
|
|
|
+ identification : self.valorNull(employee.identification_id),
|
|
|
+ state : state
|
|
|
+ // job_id : self.valorNull(employee.job_id[1])
|
|
|
+ });
|
|
|
+ }
|
|
|
+ self.content = data;
|
|
|
+ this.loadTable(data);
|
|
|
+ },
|
|
|
+
|
|
|
+ factSearch: function(){
|
|
|
+ var self = this;
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
+ var yesterday = moment().add(-1, 'days').format('YYYY-MM-DD');
|
|
|
+ var month = moment().format('YYYY-MM');
|
|
|
+ var last_month = moment().add(-1, 'months').format('YYYY-MM');
|
|
|
+ var desde = this.$el.find('#from').val();
|
|
|
+ var hasta = this.$el.find('#to').val();
|
|
|
+ var personal= this.$el.find('#personal').val().split('-');
|
|
|
+ var content = self.content;
|
|
|
+
|
|
|
+ if ($('#A').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') == today;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#B').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') == yesterday;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#C').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date).format('YYYY-MM') == month;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#D').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date).format('YYYY-MM') == last_month;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#Z').is(":checked")){
|
|
|
+ $('#datepicker').css('display','block');
|
|
|
+ if (desde.length > 0){
|
|
|
+ var date= desde.split('/');
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.date >= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (hasta.length > 0){
|
|
|
+ var date= hasta.split('/');
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.date <= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $('#datepicker').css('display','none');
|
|
|
+ }
|
|
|
+
|
|
|
+ // if ($('#lead').is(":checked")){
|
|
|
+ // content = _.filter(content, function (inv){
|
|
|
+ // return inv.crm_type == 'lead';
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // if ($('#opportunity').is(":checked")){
|
|
|
+ // content = _.filter(content, function (inv){
|
|
|
+ // return inv.crm_type == 'opportunity';
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ if (personal != ""){
|
|
|
+ content = _.filter(content, function(inv){
|
|
|
+ return inv.employee_id == personal[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ var amount_total_total = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.amount_total);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+ content.push({
|
|
|
+ name: "Total:",
|
|
|
+ amount: accounting.formatNumber((amount_total_total),0,".",","),
|
|
|
+ });
|
|
|
+ self.loadTable(content)
|
|
|
+ },
|
|
|
+
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable('load',rowsTable);
|
|
|
+ },
|
|
|
+
|
|
|
+ getObjetPdf: function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ var rowsPdf=[];
|
|
|
+ var rows=[];
|
|
|
+ var rows = self.rowsData;
|
|
|
+ return rows;
|
|
|
+ },
|
|
|
+
|
|
|
+ clickOnAction: function (e) {
|
|
|
+ var self = this;
|
|
|
+ var rowsNew;
|
|
|
+ var action = self.$el.find(e.target).val();
|
|
|
+ var table = self.$el.find("#table");
|
|
|
+ var data2 = table.bootstrapTable('getVisibleColumns');
|
|
|
+ var getColumns=[];
|
|
|
+ var rows=[];
|
|
|
+ rowsNew = self.getObjetPdf();
|
|
|
+ if (action === 'pdf') {
|
|
|
+ var dataNEW = _.map(data2, function (val){
|
|
|
+ return val.field;
|
|
|
+ });
|
|
|
+ _.each(rowsNew,function (item){
|
|
|
+ rows.push(_.pick(item, dataNEW));
|
|
|
+ });
|
|
|
+ // Obtener los nombre de la Cabecera
|
|
|
+ _.each(_.map(data2,function(val){
|
|
|
+ return val;
|
|
|
+ }), function(item){
|
|
|
+ getColumns.push([{
|
|
|
+ title: item.title,
|
|
|
+ dataKey: item.field
|
|
|
+ }]);
|
|
|
+ });
|
|
|
+ this.drawPDF(_.flatten(getColumns),rows);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ drawPDF: function (getColumns,rows) {
|
|
|
+ var self = this;
|
|
|
+ var desde =(this.$el.find('#from').val());
|
|
|
+ var hasta =(this.$el.find('#to').val());
|
|
|
+ var totalPagesExp = "{total_pages_count_string}";
|
|
|
+ var pdfDoc = new jsPDF('l');
|
|
|
+
|
|
|
+ pdfDoc.autoTable(getColumns, rows, {
|
|
|
+ styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
|
|
|
+ columnStyles: {
|
|
|
+ number : {columnWidth: '5px'},
|
|
|
+ identification : {columnWidth: '8px'},
|
|
|
+ employee_name : {columnWidth: '7px'},
|
|
|
+ reference : {columnWidth: '8px'},
|
|
|
+ date_from : {columnWidth: '10px'},
|
|
|
+ date_to: {columnWidth: '10px'},
|
|
|
+ amount : {columnWidth: '10px'},
|
|
|
+ state : {columnWidth: '11px'}
|
|
|
+ },
|
|
|
+ margin: { top: 16, horizontal: 7},
|
|
|
+
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Histórico de pago al personal', data.settings.margin.left, 10);
|
|
|
+
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(9);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40)
|
|
|
+
|
|
|
+ if(desde.length > 0 || hasta.length > 0){
|
|
|
+ var fecha='';
|
|
|
+ if(desde){
|
|
|
+ fecha=fecha.concat(' Desde '+desde);
|
|
|
+ }
|
|
|
+ if (hasta){
|
|
|
+ fecha=fecha.concat(' Hasta '+hasta);
|
|
|
+ }
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40)
|
|
|
+ pdfDoc.text(fecha, data.settings.margin.left,14);
|
|
|
+ }
|
|
|
+ // FOOTER
|
|
|
+ var str = "Pagina " + data.pageCount;
|
|
|
+ // Total page number plugin only available in jspdf v1.0+
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
+ str = str + " de " + totalPagesExp;
|
|
|
+ }
|
|
|
+ pdfDoc.setFontSize(9);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(str, data.settings.margin.left, pdfDoc.internal.pageSize.height - 5);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
+ pdfDoc.putTotalPages(totalPagesExp);
|
|
|
+ }
|
|
|
+ pdfDoc.save('Histórico de pagos al personal.pdf')
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|