Просмотр исходного кода

Filtro de reportes solucionado

Alan Garcia 3 лет назад
Родитель
Сommit
a7627008f3

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

@@ -102,7 +102,7 @@
             color="warn"
             class="mr-3"
             [disabled]="!isFilter"
-            (click)="eliminarFiltros()"
+            (click)="eliminarFiltrosGetData()"
             aria-label="Remover filtros"
             matTooltip="Remover filtros"
           >

+ 87 - 266
vacaciones/src/app/components/mes/mesmre/mesmre.component.ts

@@ -119,6 +119,7 @@ export class MESMREComponent implements AfterViewInit {
         JSON.parse(localStorage.getItem('TIMUSERENC')!).PERFIL
       ) == 'Usuario'
     ) {
+
       this.opcionesSolicitudes = this.opcionesSolicitudes.slice(0, 1);
       this.isUser = true;
       this.role = 'Usuario';
@@ -164,34 +165,9 @@ export class MESMREComponent implements AfterViewInit {
         }
       }
     );
+
     this.cargarTabla(this.solicitudes);
     this.filtroEstatus();
-
-    /* this.__mesmreService.consultar().subscribe(
-      (res: any) => {
-      if (res.status == 'Token is Expired') {
-        this._iamService.logout();
-        this._validationService.openSnackBar('Sesión expirada. Vuelva a iniciar sesión');
-      } else if (!res.status) {
-        this.solicitudes = res.response;
-        this.cargarTabla(this.solicitudes);
-        this.filtroEstatus();
-      } else {
-        this._validationService.openSnackBar(res.response.length > 0 ? res.msg : 'No hay datos para mostrar');
-      }
-      this.isLoading = false;
-
-    }, error => {
-      if (!error.ok) {
-        this._validationService.openSnackBar('Ocurrió un error inesperado');
-      }
-      if (error.error.msg != undefined) {
-        this._validationService.openSnackBar(error.error.msg);
-      }
-      if (error.status == 408) {
-        this._validationService.openSnackBar('Conexion lenta');
-      }
-    }); */
   }
 
   async obtenerEmpleados() {
@@ -208,7 +184,6 @@ export class MESMREComponent implements AfterViewInit {
             );
           } else {
             this.empleados = res.response;
-            
           }
         },
         (error: any) => {
@@ -232,6 +207,7 @@ export class MESMREComponent implements AfterViewInit {
           ])
         ).values(),
       ];
+
       this.empleados = this.empleados.filter(
         (solicitud) =>
           !solicitud.NOMBREEMPLEADO.includes(
@@ -240,50 +216,11 @@ export class MESMREComponent implements AfterViewInit {
             )
           )
       );
-     /*  this.__mesmreService.consultarTodos().subscribe(
-        (res: any) => {
-          if (res.error) {
-            this._validationService.openSnackBar(
-              'Ocurrió un error inesperado, favor de intentarlo más tarde'
-            );
-          } else {
-            this.empleados = res.response;
-            this.empleados = [
-              ...new Map(
-                this.empleados.map((empleado) => [
-                  empleado.NOMBREEMPLEADO,
-                  empleado,
-                ])
-              ).values(),
-            ];
-            this.empleados = this.empleados.filter(
-              (solicitud) =>
-                !solicitud.NOMBREEMPLEADO.includes(
-                  this._encService.desencriptar(
-                    this.__mesmreService.usuario_session.IDUSUARIO
-                  )
-                )
-            );
-          }
-        },
-        (error: any) => {
-          if (!error.ok) {
-            this._validationService.openSnackBar('Ocurrió un error inesperado');
-          }
-          if (error.error.msg != undefined) {
-            this._validationService.openSnackBar(error.error.msg);
-          }
-          if (error.status == 408) {
-            this._validationService.openSnackBar('Conexion lenta');
-          }
-        }
-      ); */
     } else if (
       this._encService.desencriptar(
         JSON.parse(localStorage.getItem('TIMUSERENC')!).PERFIL
       ) == 'Usuario'
     ) {
-
       await lastValueFrom(this.__mesmreService.consultarEmpleados()).then(
         (res: any) => {
           if (res.error) {
@@ -292,7 +229,6 @@ export class MESMREComponent implements AfterViewInit {
             );
           } else {
             this.empleados = res.response;
-            
           }
         },
         (error: any) => {
@@ -316,36 +252,6 @@ export class MESMREComponent implements AfterViewInit {
           ])
         ).values(),
       ];
-      /* this.__mesmreService.consultarEmpleados().subscribe(
-        (res: any) => {
-          if (res.error) {
-            this._validationService.openSnackBar(
-              'Ocurrió un error inesperado, favor de intentarlo más tarde'
-            );
-          } else {
-            this.empleados = res.response;
-            this.empleados = [
-              ...new Map(
-                this.empleados.map((empleado) => [
-                  empleado.NOMBREEMPLEADO,
-                  empleado,
-                ])
-              ).values(),
-            ];
-          }
-        },
-        (error: any) => {
-          if (!error.ok) {
-            this._validationService.openSnackBar('Ocurrió un error inesperado');
-          }
-          if (error.error.msg != undefined) {
-            this._validationService.openSnackBar(error.error.msg);
-          }
-          if (error.status == 408) {
-            this._validationService.openSnackBar('Conexion lenta');
-          }
-        }
-      ); */
     }
   }
 
@@ -359,7 +265,6 @@ export class MESMREComponent implements AfterViewInit {
           );
         } else if (!res.status && res.response.length > 0) {
           this.periodos = res.response;
-         
         } else {
           if (res.msg !== 'EXITO') {
             this._validationService.openSnackBar(res.msg);
@@ -379,48 +284,20 @@ export class MESMREComponent implements AfterViewInit {
         }
       }
     );
+
     this.periodos.map((periodo) => {
       periodo.PERIODO = this.formatoFechaPeriodo(periodo.PERIODO).join();
     });
-    /* this.__mesmprService.obtenerPeriodos(usuario).subscribe(
-      (res: any) => {
-        if (res.status == 'Token is Expired') {
-          this._iamService.logout();
-          this._validationService.openSnackBar(
-            '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._validationService.openSnackBar(res.msg);
-          }
-        }
-        this.isLoading = false;
-      },
-      (error) => {
-        if (!error.ok) {
-          this._validationService.openSnackBar('Ocurrió un error inesperado');
-        }
-        if (error.error.msg != undefined) {
-          this._validationService.openSnackBar(error.error.msg);
-        }
-        if (error.status == 408) {
-          this._validationService.openSnackBar('Conexion lenta');
-        }
-      }
-    ); */
   }
 
   async filtroSolicitudes(filtro: string) {
     if (!this.isUser) {
+      let aux_response: any;
       this.isReloading = true;
       this.tipoSolicitud = filtro;
+
       this.eliminarFiltros();
-      let aux_response: any;
+
       switch (filtro) {
         case 'Mi historial':
           await lastValueFrom(this.__mesmreService.consultar()).then(
@@ -431,7 +308,6 @@ export class MESMREComponent implements AfterViewInit {
                 );
               } else {
                 aux_response = res.response
-               
               }
             },
             (error) => {
@@ -448,45 +324,11 @@ export class MESMREComponent implements AfterViewInit {
               }
             }
           );
-          this.cargarTablaConSelects(aux_response);
-          //this.mapearTabla();
+
+          this.obtenerPeriodos(this._encService.desencriptar( this.__mesmreService.usuario_session.IDUSUARIO));
+          this.cargarTabla(aux_response);
           this.filtroEstatus();
-          this.obtenerPeriodos(
-            this._encService.desencriptar(
-              this.__mesmreService.usuario_session.IDUSUARIO
-            )
-          );
-          /* this.__mesmreService.consultar().subscribe(
-            (res: any) => {
-              if (res.error) {
-                this._validationService.openSnackBar(
-                  'Ocurrió un error inesperado, favor de intentarlo más tarde'
-                );
-              } else {
-                this.cargarTablaConSelects(res.response);
-                this.mapearTabla();
-                this.filtroEstatus();
-                this.obtenerPeriodos(
-                  this._encService.desencriptar(
-                    this.__mesmreService.usuario_session.IDUSUARIO
-                  )
-                );
-              }
-            },
-            (error) => {
-              if (!error.ok) {
-                this._validationService.openSnackBar(
-                  'Ocurrió un error inesperado'
-                );
-              }
-              if (error.error.msg != undefined) {
-                this._validationService.openSnackBar(error.error.msg);
-              }
-              if (error.status == 408) {
-                this._validationService.openSnackBar('Conexion lenta');
-              }
-            }
-          ); */
+          
           break;
         case 'Todos':
           await lastValueFrom(this.__mesmreService.consultarTodos()).then(
@@ -497,7 +339,6 @@ export class MESMREComponent implements AfterViewInit {
                 );
               } else {
                 aux_response = res.response;
-                //Falta obtener todos los periodos
               }
             }, (error) => {
               if (!error.ok) {
@@ -513,29 +354,18 @@ export class MESMREComponent implements AfterViewInit {
               }
             }
           );
-          this.cargarTablaConSelects(aux_response);
-          //this.mapearTabla();
+          
+          this.cargarTabla(aux_response);
           this.filtroEstatus();
 
-          /* this.__mesmreService.consultarTodos().subscribe(
-            (res: any) => {
-            if (res.error) {
-              this._validationService.openSnackBar(
-                'Ocurrió un error inesperado, favor de intentarlo más tarde'
-              );
-            } else {
-              this.cargarTablaConSelects(res.response);
-              this.mapearTabla();
-              this.filtroEstatus();
-              //Falta obtener todos los periodos
-            }
-          }); */
           break;
         default:
           this._validationService.openSnackBar(
             'Ocurrió un error inesperado, favor de intentarlo más tarde'
           );
+
           this.isReloading = false;
+
           break;
       }
     }
@@ -543,13 +373,12 @@ export class MESMREComponent implements AfterViewInit {
 
   async filtroEmpleados(empleado: MESMREInterface) {
     //Se hace un split al primer parentesis, se obtiene la segunda posicion y se elimna el segundo parentesis
-    if (
-      empleado.NOMBREEMPLEADO.includes('(') &&
-      empleado.NOMBREEMPLEADO.includes(')')
-    ) {
-      let aux_response: any;
+    if (empleado.NOMBREEMPLEADO.includes('(') && empleado.NOMBREEMPLEADO.includes(')')) {
       let usuario = empleado.NOMBREEMPLEADO.split('(')[1].replace(')', '');
+      let aux_response: any;
+
       this.eliminarFiltros();
+
       await lastValueFrom(this.__mesmreService.consultarUsuario(usuario)).then(
         (res: any) => {
           if (res.error) {
@@ -573,38 +402,11 @@ export class MESMREComponent implements AfterViewInit {
           }
         }
       );
-
-      this.cargarTablaConSelects(aux_response);
-      //this.mapearTabla();
-      this.filtroEstatus();
+      
       this.obtenerPeriodos(usuario);
+      this.cargarTabla(aux_response);
+      this.filtroEstatus();
 
-      /* this.__mesmreService.consultarUsuario(usuario).subscribe(
-        (res: any) => {
-          if (res.error) {
-            this._validationService.openSnackBar(
-              'Ocurrió un error inesperado, favor de intentarlo más tarde'
-            );
-          } else {
-            this.tipoSolicitud = usuario;
-            this.cargarTablaConSelects(res.response);
-            this.mapearTabla();
-            this.filtroEstatus();
-            this.obtenerPeriodos(usuario);
-          }
-        },
-        (error) => {
-          if (!error.ok) {
-            this._validationService.openSnackBar('Ocurrió un error inesperado');
-          }
-          if (error.error.msg != undefined) {
-            this._validationService.openSnackBar(error.error.msg);
-          }
-          if (error.status == 408) {
-            this._validationService.openSnackBar('Conexion lenta');
-          }
-        }
-      ); */
     } else {
       //No cargo los datos del id
       this._validationService.openSnackBar(
@@ -669,9 +471,7 @@ export class MESMREComponent implements AfterViewInit {
             )
         );
       }
-
       //FILTROS
-
       //TODOS LOS FILTROS FUERON SOLICITADOS
       if (
         this.rango.value.fecha_inicio != null &&
@@ -730,7 +530,7 @@ export class MESMREComponent implements AfterViewInit {
     }
   }
 
-  eliminarFiltros() {
+  eliminarFiltrosGetData() {
     this.isFilter = false;
     this.isFilterNull = true;
     if (
@@ -754,6 +554,7 @@ export class MESMREComponent implements AfterViewInit {
       if (this.opcionPeriodo != null) {
         this.opcionPeriodo = null;
       }
+
       switch (this.opcionSolicitud) {
         case 0:
           this.__mesmreService.consultar().subscribe(
@@ -763,8 +564,7 @@ export class MESMREComponent implements AfterViewInit {
                   'Ocurrió un error inesperado, favor de intentarlo más tarde'
                 );
               } else {
-                this.cargarTablaConSelects(res.response);
-                //this.mapearTabla();
+                this.cargarTabla(res.response);
               }
             },
             (error) => {
@@ -790,9 +590,7 @@ export class MESMREComponent implements AfterViewInit {
                   'Ocurrió un error inesperado, favor de intentarlo más tarde'
                 );
               } else {
-                this.cargarTablaConSelects(res.response);
-                //this.mapearTabla();
-                //Falta obtener todos los periodos
+                this.cargarTabla(res.response);
               }
             },
             (error: any) => {
@@ -818,8 +616,7 @@ export class MESMREComponent implements AfterViewInit {
                   'Ocurrió un error inesperado, favor de intentarlo más tarde'
                 );
               } else {
-                this.cargarTablaConSelects(res.response);
-                //this.mapearTabla();
+                this.cargarTabla(res.response);
               }
             },
             (error) => {
@@ -846,6 +643,33 @@ export class MESMREComponent implements AfterViewInit {
     }
   }
 
+  eliminarFiltros() {
+    this.isFilter = false;
+    this.isFilterNull = true;
+    if (
+      this.rango.value.fecha_inicio != null ||
+      this.rango.value.fecha_fin != null ||
+      this.opcionesEstatus != null ||
+      this.opcionPeriodo != null
+    ) {
+      if (
+        this.rango.value.fecha_inicio != null ||
+        this.rango.value.fecha_fin != null
+      ) {
+        this.rango = new FormGroup({
+          fecha_inicio: new FormControl(),
+          fecha_fin: new FormControl(),
+        });
+      }
+      if (this.opcionEstatus != null) {
+        this.opcionEstatus = null;
+      }
+      if (this.opcionPeriodo != null) {
+        this.opcionPeriodo = null;
+      }
+    }
+  }
+
   validarOpcionesFiltro() {
     //Saber si los filtros estan nulos
     if (
@@ -860,11 +684,40 @@ export class MESMREComponent implements AfterViewInit {
     }
   }
 
-  cargarTablaConSelects(solicitudes: MESMREInterface[]) {
+  cargarTabla(solicitudes: MESMREInterface[]) {
+    this.isLoading = false;
     this.solicitudes = solicitudes;
-    this.dataSource.data = this.solicitudes;
+    this.dataSource = new MatTableDataSource<MESMREInterface>(this.solicitudes);
     this.selection = new SelectionModel<MESMREInterface>(true, solicitudes);
-    this.isReloading = false;
+
+    console.log(this.dataSource);
+
+    
+    this.dataSource.filterPredicate = function (
+      data: MESMREInterface,
+      filter: string
+    ): boolean {
+      return (
+        data.IDSOLICITUD.toString().toLowerCase().includes(filter) ||
+        data.NOMBREEMPLEADO.toLowerCase().includes(filter) ||
+        data.FECHAINICIO.toString().toLowerCase().includes(filter) ||
+        data.FECHAFIN.toString().toLowerCase().includes(filter) ||
+        data.NUMERODIAS.toString().toLowerCase().includes(filter) ||
+        data.ESTATUS.toLowerCase().includes(filter) ||
+        data.PERIODOVACACIONAL.toString().toLowerCase().includes(filter) ||
+        data.VACACIONESANTES.toString().toLowerCase().includes(filter) ||
+        data.VACACIONESDESPUES.toString().toLowerCase().includes(filter)
+      );
+    };
+
+    this.dataSource.paginator = this.paginator;
+    this.paginator._intl.itemsPerPageLabel = 'Datos por página';
+    this.paginator._intl.firstPageLabel = 'Primera Página';
+    this.paginator._intl.lastPageLabel = 'Últmina Página';
+    this.paginator._intl.nextPageLabel = 'Siguiente Página';
+    this.paginator._intl.previousPageLabel = 'Anterior Página';
+
+    this.mapearTabla();
   }
 
   mapearTabla() {
@@ -887,7 +740,7 @@ export class MESMREComponent implements AfterViewInit {
       solicitud.FECHAFIN = this.formatoFecha(solicitud.FECHAFIN);
 
       solicitud.NUMERODIAS =
-        solicitud.VACACIONESANTES - solicitud.VACACIONESDESPUES;
+      solicitud.VACACIONESANTES - solicitud.VACACIONESDESPUES;
 
       return {
         IDSOLICITUD: solicitud.IDSOLICITUD,
@@ -903,38 +756,6 @@ export class MESMREComponent implements AfterViewInit {
     });
   }
 
-  cargarTabla(solicitudes: MESMREInterface[]) {
-    this.isLoading = false;
-    this.solicitudes = solicitudes;
-    this.dataSource = new MatTableDataSource<MESMREInterface>(this.solicitudes);
-    this.selection = new SelectionModel<MESMREInterface>(true, solicitudes);
-
-    this.dataSource.filterPredicate = function (
-      data: MESMREInterface,
-      filter: string
-    ): boolean {
-      return (
-        data.IDSOLICITUD.toString().toLowerCase().includes(filter) ||
-        data.NOMBREEMPLEADO.toLowerCase().includes(filter) ||
-        data.FECHAINICIO.toString().toLowerCase().includes(filter) ||
-        data.FECHAFIN.toString().toLowerCase().includes(filter) ||
-        data.NUMERODIAS.toString().toLowerCase().includes(filter) ||
-        data.ESTATUS.toLowerCase().includes(filter) ||
-        data.PERIODOVACACIONAL.toString().toLowerCase().includes(filter) ||
-        data.VACACIONESANTES.toString().toLowerCase().includes(filter) ||
-        data.VACACIONESDESPUES.toString().toLowerCase().includes(filter)
-      );
-    };
-
-    this.dataSource.paginator = this.paginator;
-    this.paginator._intl.itemsPerPageLabel = 'Datos por página';
-    this.paginator._intl.firstPageLabel = 'Primera Página';
-    this.paginator._intl.lastPageLabel = 'Últmina Página';
-    this.paginator._intl.nextPageLabel = 'Siguiente Página';
-    this.paginator._intl.previousPageLabel = 'Anterior Página';
-
-    this.mapearTabla();
-  }
 
   applyFilter(filterValue: any) {
     this.dataSource.filter = filterValue.target.value.trim().toLowerCase();