Browse Source

Formato de fechas y periodos en reportes Excel

Alan Garcia 3 years ago
parent
commit
61dcdc3a80

+ 2 - 2
vacaciones/src/app/components/mes/mesmre/mesmre.component.html

@@ -70,7 +70,7 @@
                 [value]="periodo.PERIODO" 
                 *ngFor="let periodo of periodos"
                 (click)="validarOpcionesFiltro()">
-                {{formatDate(periodo.PERIODO.split('|')[0])  + ' / ' + formatDate(periodo.PERIODO.split('|')[1])  }}
+                {{ periodo.PERIODO }}
               </mat-option>
             </mat-select>
           </mat-form-field>
@@ -231,7 +231,7 @@
           Periodo vacacional
         </th>
         <td mat-cell *matCellDef="let element">
-          {{ element.PERIODOVACACIONAL != 'N/A' ?  'De '+ formatDate(element.PERIODOVACACIONAL.split('|')[0])  + ' a ' + formatDate(element.PERIODOVACACIONAL.split('|')[1]) : 'N/A' }}
+          {{ element.PERIODOVACACIONAL }}
         </td>
       </ng-container>
   

+ 23 - 13
vacaciones/src/app/components/mes/mesmre/mesmre.component.ts

@@ -200,6 +200,9 @@ export class MESMREComponent implements AfterViewInit {
         this.snackAlert('Sesión expirada. Vuelva a iniciar sesión');
       }else if (!res.status && res.response.length > 0) {        
         this.periodos = res.response;
+        this.periodos.map((periodo) => {
+          periodo.PERIODO = this.formatoFechaPeriodo(periodo.PERIODO).join();
+        })
       }else{
         if (res.msg !== "EXITO") {
           this.snackAlert(res.msg);
@@ -345,10 +348,10 @@ export class MESMREComponent implements AfterViewInit {
         filtro_solicitudes = filtro_solicitudes.filter(solicitud => solicitud.ESTATUS == this.opcionEstatus);
       //RANGO FECHAS Y PERIODO
       }else if (this.rango.value.fecha_inicio != null && this.rango.value.fecha_fin != null && this.opcionPeriodo != null) {
-        filtro_solicitudes = filtro_solicitudes.filter(solicitud => solicitud.ESTATUS == this.opcionEstatus);
+        filtro_solicitudes = filtro_solicitudes.filter(solicitud => solicitud.PERIODOVACACIONAL == this.opcionPeriodo);
       //ESTATUS Y PERIODO
       }else if (this.opcionEstatus != null && this.opcionPeriodo != null) {
-      filtro_solicitudes = this.solicitudes.filter(solicitud => solicitud.ESTATUS == this.opcionEstatus && solicitud.PERIODOVACACIONAL == this.opcionPeriodo);
+        filtro_solicitudes = this.solicitudes.filter(solicitud => solicitud.ESTATUS == this.opcionEstatus && solicitud.PERIODOVACACIONAL == this.opcionPeriodo);
       //ESTATUS
       }else if (this.opcionEstatus != null) {
         filtro_solicitudes = this.solicitudes.filter(solicitud => solicitud.ESTATUS == this.opcionEstatus);
@@ -472,11 +475,13 @@ export class MESMREComponent implements AfterViewInit {
   }
 
   mapearTabla() {
-    this.solicitudes.map(function (
+    this.solicitudes.map((
       solicitud: MESMREInterface
-    ) {      
+    ) => {      
       if (solicitud.PERIODOVACACIONAL == null) {
         solicitud.PERIODOVACACIONAL = 'N/A';
+      } else {
+        solicitud.PERIODOVACACIONAL = this.formatoFechaPeriodo(solicitud.PERIODOVACACIONAL).join();
       }
       if (solicitud.VACACIONESANTES == null) {
         solicitud.VACACIONESANTES = 0;
@@ -484,6 +489,7 @@ export class MESMREComponent implements AfterViewInit {
       if (solicitud.VACACIONESDESPUES == null) {
         solicitud.VACACIONESDESPUES = 0;
       }
+
       return {
         IDSOLICITUD: solicitud.IDSOLICITUD,
         NOMBREEMPLEADO: solicitud.NOMBREEMPLEADO,
@@ -534,11 +540,6 @@ export class MESMREComponent implements AfterViewInit {
     this.mapearTabla();
   }
 
-  formatoFecha(fecha:string): string {
-    let split = fecha.split('-');
-    return `${split[2]}-${split[1]}-${split[0]}`
-  }
-
   applyFilter(filterValue: any) {
     this.dataSource.filter = filterValue.target.value.trim().toLowerCase();
   }
@@ -581,15 +582,24 @@ export class MESMREComponent implements AfterViewInit {
         + (dia < 10 ? '0': '') + dia + '_' + (hora < 10 ? '0': '') + hora 
         + (minuto < 10 ? '0': '') + minuto + (segundos < 10 ? '0': '') + segundos;
       
-      this.excel.generarExcel(this.selection.selected, filename, titulo)
+      this.excel.generarExcel(this.selection.selected, filename, titulo);
     } else {
       this.snackAlert('Para generar el Excel se debe seleccionar al menos una fila');
     }
   }
 
-  formatDate(fecha:string){
-    let arrFecha = fecha.split("-");
-    return `${arrFecha[2]}-${arrFecha[1]}-${arrFecha[0]}`;
+  formatoFecha(fecha:string): string {
+    let split = fecha.split('-');
+    return `${split[2]}-${split[1]}-${split[0]}`
+  }
+
+  formatoFechaPeriodo(item: any) {
+    let arrPeriodoVacacional = [];
+    let fechaPeriodo = item.split('|');
+
+    arrPeriodoVacacional.push('De ' + this.formatoFecha(fechaPeriodo[0]) + ' a ' +this.formatoFecha(fechaPeriodo[1]));
+
+    return arrPeriodoVacacional;
   }
 
   private snackAlert(mensaje: string) {

+ 10 - 12
vacaciones/src/app/services/excel/export-excel.service.ts

@@ -11,25 +11,18 @@ export class ExportExcelService {
   constructor() { }
 
   generarExcel(excelData:any, filename:string, titulo:string) {
-
     //Saber ultima celda para el filtrado de datos
     let ultimaCelda;
 
     const title = 'Reporte de periodos vacacionales';
     const header = ['Número de Solicitud', 'Nombre Empleado', 'Fecha Inicio', 'Fecha Fin', 'Número Días', 'Estatus', 'Periodo Vacacional', 'Vacaciones antes', 'Vacaciones después']
     
-    const data:MESMREInterface[] = excelData.map(function (
+    const data:MESMREInterface[] = excelData.map((
       solicitud: MESMREInterface
-    ) {
-      if (solicitud.PERIODOVACACIONAL == null) {
-        solicitud.PERIODOVACACIONAL = 'N/A';
-      }
-      if (solicitud.VACACIONESANTES == null) {
-        solicitud.VACACIONESANTES = 0;
-      }
-      if (solicitud.VACACIONESDESPUES == null) {
-        solicitud.VACACIONESDESPUES = 0;
-      }
+    ) => {
+      solicitud.FECHAINICIO = this.formatoFecha(solicitud.FECHAINICIO);
+      solicitud.FECHAFIN = this.formatoFecha(solicitud.FECHAFIN);
+
       return {
         IDSOLICITUD: solicitud.IDSOLICITUD,
         NOMBREEMPLEADO: solicitud.NOMBREEMPLEADO,
@@ -205,4 +198,9 @@ export class ExportExcelService {
     })
   }
 
+  formatoFecha(fecha:string): string {
+    let split = fecha.split('-');
+
+    return `${split[2]}-${split[1]}-${split[0]}`
+  }
 }