| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823 |
- import { SelectionModel } from '@angular/cdk/collections';
- import { Component, ViewChild, AfterViewInit } from '@angular/core';
- import { MatPaginator } from '@angular/material/paginator';
- import { MatTableDataSource } from '@angular/material/table';
- import { MatDialog } from '@angular/material/dialog';
- import { MatSnackBar } from '@angular/material/snack-bar';
- import { FormGroup, FormControl } from '@angular/forms';
- import { ExportExcelService } from 'src/app/services/excel/export-excel.service';
- import { MESMREService } from 'src/app/services/mes/mesmre/mesmre.service';
- import { MESMREInterface } from 'src/app/interfaces/mes/mesmre/mesmre-interface';
- import { MESMPRService } from 'src/app/services/mes/mesmpr/mesmpr.service';
- import { MesmprInterface } from 'src/app/interfaces/mes/mesmpr/mesmpr-interface';
- import { ENCService } from 'src/app/services/enc/enc.service';
- import { IAMService } from 'src/app/services/iam/iam.service';
- import { USERInterface } from 'src/app/interfaces/user-interface';
- import { ValidationsService } from 'src/app/services/validations.service';
- import { lastValueFrom } from 'rxjs';
- @Component({
- selector: 'app-mesmre',
- templateUrl: './mesmre.component.html',
- styleUrls: ['./mesmre.component.css'],
- })
- export class MESMREComponent implements AfterViewInit {
- isLoading: Boolean = true;
- isReloading: Boolean = false;
- isFilter: Boolean = false;
- isFilterNull: Boolean = true;
- isUser: Boolean = false;
- role = '';
- fecha_inicio = '';
- fecha_fin = '';
- //DATES
- options: any = {
- year: 'numeric',
- month: 'long',
- day: 'numeric',
- };
- rango = new FormGroup({
- fecha_inicio: new FormControl(),
- fecha_fin: new FormControl(),
- });
- //Historial
- solicitudes: MESMREInterface[] = [];
- //Todos
- solicitudes_todos: MESMREInterface[] = [];
- empleados: MESMREInterface[] = [];
- empleado: MESMREInterface = {} as MESMREInterface;
- //Periodos
- periodos: MesmprInterface[] = [];
- nombre_usuario: string = '';
- opcionesSolicitudes = [
- { valor: 0, tipo: 'Mi historial' },
- { valor: 1, tipo: 'Todos' },
- ];
- opcionSolicitud = this.opcionesSolicitudes[0].valor;
- tipoSolicitud = this.opcionesSolicitudes[0].tipo;
- opcionesEstatus = [
- { estatus: 'Aprobadas' },
- { estatus: 'Rechazadas' },
- { estatus: 'Pendientes' },
- { estatus: 'Canceladas' },
- ];
- opcionEstatus = null;
- opcionPeriodo = null;
- displayedColumns: string[] = [
- 'select',
- 'numero_solicitud',
- 'nombre_empleado',
- 'fecha_inicio',
- 'fecha_fin',
- 'numero_dias',
- 'estatus',
- 'periodo_vacacional',
- 'vacaciones_antes',
- 'vacaciones_despues',
- ];
- dataSource = new MatTableDataSource<any>(this.solicitudes);
- selection = new SelectionModel<MESMREInterface>(true, []);
- @ViewChild(MatPaginator) paginator!: MatPaginator;
- constructor(
- public dialog: MatDialog,
- private _snackBar: MatSnackBar,
- private _iamService: IAMService,
- private __mesmreService: MESMREService,
- private __mesmprService: MESMPRService,
- public excel: ExportExcelService,
- private _encService: ENCService,
- private _validationService: ValidationsService
- ) {
- let usuario: USERInterface = JSON.parse(
- localStorage.getItem('TIMUSERENC')!
- );
- this.nombre_usuario = usuario.NOMBRE;
-
- if (this._encService.desencriptar(JSON.parse(localStorage.getItem('TIMUSERENC')!).PERFIL) === '1') {
- this.role = 'Administrador';
- } else if (this._encService.desencriptar(JSON.parse(localStorage.getItem('TIMUSERENC')!).PERFIL) !== '1') {
- this.opcionesSolicitudes = this.opcionesSolicitudes.slice(0, 1);
- this.isUser = true;
- this.role = 'Usuario';
- }
- }
- ngAfterViewInit(): void {
- this.obtener();
- this.obtenerEmpleados();
- this.obtenerPeriodos(
- this._encService.desencriptar(
- this.__mesmreService.usuario_session.IDUSUARIO
- )
- );
- }
- async obtener() {
- await lastValueFrom(this.__mesmreService.consultar()).then(
- (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;
- } 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');
- }
- }
- );
- this.cargarTabla(this.solicitudes);
- this.filtroEstatus();
- }
- async obtenerEmpleados() {
- if (this._encService.desencriptar(JSON.parse(localStorage.getItem('TIMUSERENC')!).PERFIL) === '1') {
- await lastValueFrom(this.__mesmreService.consultarTodos()).then(
- (res: any) => {
- if (res.error) {
- this._validationService.openSnackBar(
- 'Ocurrió un error inesperado, favor de intentarlo más tarde'
- );
- } else {
- this.empleados = res.response;
- }
- },
- (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');
- }
- }
- );
- 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
- )
- )
- );
- } else {
- await lastValueFrom(this.__mesmreService.consultarEmpleados()).then(
- (res: any) => {
- if (res.error) {
- this._validationService.openSnackBar(
- 'Ocurrió un error inesperado, favor de intentarlo más tarde'
- );
- } else {
- this.empleados = res.response;
- if (this.empleados.length > 0) {
- this.role = "Jefe Directo"
- }
- }
- },
- (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');
- }
- }
- );
-
- this.empleados = this.empleados.map(function(empleado) {
- return {NOMBREEMPLEADO: empleado.USUARIO}
- }) as MESMREInterface[];
- }
- }
- async obtenerPeriodos(usuario: any) {
- await lastValueFrom(this.__mesmprService.obtenerPeriodos(usuario)).then(
- (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;
- } 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');
- }
- }
- );
- this.periodos.map((periodo) => {
- periodo.PERIODO = this.formatoFechaPeriodo(periodo.PERIODO).join();
- });
- }
- async filtroSolicitudes(filtro: string) {
- if (this.role === 'Administrador' || this.role === 'Jefe Directo') {
- let aux_response: any;
- this.isReloading = true;
- this.tipoSolicitud = filtro;
- this.eliminarFiltros();
- switch (filtro) {
- case 'Mi historial':
- await lastValueFrom(this.__mesmreService.consultar()).then(
- (res: any) => {
- if (res.error) {
- this._validationService.openSnackBar(
- 'Ocurrió un error inesperado, favor de intentarlo más tarde'
- );
- } else {
- aux_response = res.response;
- }
- },
- (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');
- }
- }
- );
- this.obtenerPeriodos(
- this._encService.desencriptar(
- this.__mesmreService.usuario_session.IDUSUARIO
- )
- );
- this.cargarTabla(aux_response);
- this.filtroEstatus();
- break;
- case 'Todos':
- await lastValueFrom(this.__mesmreService.consultarTodos()).then(
- (res: any) => {
- if (res.error) {
- this._validationService.openSnackBar(
- 'Ocurrió un error inesperado, favor de intentarlo más tarde'
- );
- } else {
- aux_response = res.response;
- }
- },
- (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');
- }
- }
- );
- this.cargarTabla(aux_response);
- this.filtroEstatus();
- break;
- default:
- this._validationService.openSnackBar(
- 'Ocurrió un error inesperado, favor de intentarlo más tarde'
- );
- this.isReloading = false;
- break;
- }
- }
- }
- 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 usuario = empleado.NOMBREEMPLEADO.split('(')[1].replace(')', '');
- let aux_response: any;
- this.eliminarFiltros();
- await lastValueFrom(this.__mesmreService.consultarUsuario(usuario)).then(
- (res: any) => {
- if (res.error) {
- this._validationService.openSnackBar(
- 'Ocurrió un error inesperado, favor de intentarlo más tarde'
- );
- } else {
- this.tipoSolicitud = usuario;
- aux_response = res.response;
- }
- },
- (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');
- }
- }
- );
- this.obtenerPeriodos(usuario);
- this.cargarTabla(aux_response);
- this.filtroEstatus();
- } else {
- //No cargo los datos del id
- this._validationService.openSnackBar(
- 'Ocurrió un error inesperado, favor de intentarlo más tarde'
- );
- }
- }
- filtroEstatus() {
- let filtro_estatus = [
- ...new Map(
- this.solicitudes.map((solicitud) => [solicitud.ESTATUS, solicitud])
- ).values(),
- ];
- this.opcionesEstatus = [];
- filtro_estatus.forEach((estatus) => {
- this.opcionesEstatus.push({ estatus: estatus.ESTATUS });
- });
- }
- filtrosBusqueda() {
- if (this.solicitudes.length > 0) {
- let filtro_solicitudes: MESMREInterface[] = [];
- this.isFilter = true;
- //El filtro aplica a los rangos ?
- if (
- this.rango.value.fecha_inicio != null &&
- this.rango.value.fecha_fin != null
- ) {
- //Obtengo el tiempo transcurrido
- let rango_fecha_inicio = new Date(
- this.rango.value.fecha_inicio
- ).getTime();
- let rango_fecha_fin = new Date(this.rango.value.fecha_fin).getTime();
- //Las 2 fechas del rango son menores a la fecha inicio ? true
- //Las 2 fechas del rango son mayores a la fecha fin ? true
- //Si las fechas del rango no son menores ni mayores entonces son *false* las condiciones,
- //Se debe de enviar verdadero si no excede este rango !false
- filtro_solicitudes = this.solicitudes.filter(
- (solicitud) =>
- !(
- rango_fecha_inicio <
- Date.parse(
- this.formatoFecha(solicitud.FECHAINICIO).split('-0').join('-')
- ) &&
- rango_fecha_fin <
- Date.parse(
- this.formatoFecha(solicitud.FECHAINICIO).split('-0').join('-')
- )
- ) &&
- !(
- rango_fecha_inicio >
- Date.parse(
- this.formatoFecha(solicitud.FECHAFIN).split('-0').join('-')
- ) &&
- rango_fecha_fin >
- Date.parse(
- this.formatoFecha(solicitud.FECHAFIN).split('-0').join('-')
- )
- )
- );
- }
- //FILTROS
- //TODOS LOS FILTROS FUERON SOLICITADOS
- if (
- this.rango.value.fecha_inicio != null &&
- this.rango.value.fecha_fin != null &&
- this.opcionEstatus != null &&
- this.opcionPeriodo != null
- ) {
- filtro_solicitudes = filtro_solicitudes.filter(
- (solicitud) =>
- solicitud.ESTATUS == this.opcionEstatus &&
- solicitud.PERIODOVACACIONAL == this.opcionPeriodo
- );
- //RANGO FECHAS Y ESTATUS
- } else if (
- this.rango.value.fecha_inicio != null &&
- this.rango.value.fecha_fin != null &&
- this.opcionEstatus != null
- ) {
- 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.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
- );
- //ESTATUS
- } else if (this.opcionEstatus != null) {
- filtro_solicitudes = this.solicitudes.filter(
- (solicitud) => solicitud.ESTATUS == this.opcionEstatus
- );
- //PERIODO
- } else if (this.opcionPeriodo != null) {
- filtro_solicitudes = this.solicitudes.filter(
- (solicitud) => solicitud.PERIODOVACACIONAL == this.opcionPeriodo
- );
- }
- this.dataSource.data = filtro_solicitudes;
- this.selection = new SelectionModel<MESMREInterface>(
- true,
- filtro_solicitudes
- );
- this.isReloading = false;
- }
- }
- eliminarFiltrosGetData() {
- 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;
- }
- switch (this.opcionSolicitud) {
- case 0:
- this.__mesmreService.consultar().subscribe(
- (res: any) => {
- if (res.error) {
- this._validationService.openSnackBar(
- 'Ocurrió un error inesperado, favor de intentarlo más tarde'
- );
- } else {
- this.cargarTabla(res.response);
- }
- },
- (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 1:
- this.__mesmreService.consultarTodos().subscribe(
- (res: any) => {
- if (res.error) {
- this._validationService.openSnackBar(
- 'Ocurrió un error inesperado, favor de intentarlo más tarde'
- );
- } else {
- this.cargarTabla(res.response);
- }
- },
- (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');
- }
- }
- );
- break;
- case 2:
- this.__mesmreService.consultarUsuario(this.tipoSolicitud).subscribe(
- (res: any) => {
- if (res.error) {
- this._validationService.openSnackBar(
- 'Ocurrió un error inesperado, favor de intentarlo más tarde'
- );
- } else {
- this.cargarTabla(res.response);
- }
- },
- (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;
- default:
- this._validationService.openSnackBar(
- 'Ocurrió un error inesperado, favor de intentarlo más tarde'
- );
- break;
- }
- }
- }
- 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 (
- (this.rango.value.fecha_inicio != null &&
- this.rango.value.fecha_fin != null) ||
- this.opcionEstatus != null ||
- this.opcionPeriodo != null
- ) {
- this.isFilterNull = false;
- } else {
- this.isFilterNull = true;
- }
- }
- 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();
- }
- mapearTabla() {
- 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;
- }
- if (solicitud.VACACIONESDESPUES == null) {
- solicitud.VACACIONESDESPUES = 0;
- }
- solicitud.FECHAINICIO = this.formatoFecha(solicitud.FECHAINICIO);
- solicitud.FECHAFIN = this.formatoFecha(solicitud.FECHAFIN);
- solicitud.NUMERODIAS =
- solicitud.VACACIONESANTES - solicitud.VACACIONESDESPUES;
- return {
- IDSOLICITUD: solicitud.IDSOLICITUD,
- NOMBREEMPLEADO: solicitud.NOMBREEMPLEADO,
- FECHAINICIO: solicitud.FECHAINICIO,
- FECHAFIN: solicitud.FECHAFIN,
- NUMERODIAS: solicitud.NUMERODIAS,
- ESTATUS: solicitud.ESTATUS,
- PERIODOVACACIONAL: solicitud.PERIODOVACACIONAL,
- VACACIONESANTES: solicitud.VACACIONESANTES,
- VACACIONESDESPUES: solicitud.VACACIONESDESPUES,
- };
- });
- }
- applyFilter(filterValue: any) {
- this.dataSource.filter = filterValue.target.value.trim().toLowerCase();
- }
- isAllSelected() {
- const numSelected = this.selection.selected.length;
- const numRows = this.dataSource.data.length;
- return numSelected === numRows;
- }
- masterToggle() {
- if (this.isAllSelected()) {
- this.selection.clear();
- return;
- }
- this.selection.select(...this.dataSource.data);
- }
- checkboxLabel(row?: MESMREInterface): string {
- if (!row) {
- return `${this.isAllSelected() ? 'deselect' : 'select'} all`;
- }
- return `${this.selection.isSelected(row) ? 'deselect' : 'select'} row`;
- }
- generarExcel(): void {
- if (this.selection.selected.length > 0) {
- //let hoy = new Date(2022,1,1,1,1,1);
- let hoy = new Date();
- let anio = hoy.getFullYear();
- let mes = hoy.getMonth() + 1;
- let dia = hoy.getDate();
- let hora = hoy.getHours();
- let minuto = hoy.getMinutes();
- let segundos = hoy.getSeconds();
- let titulo = this.tipoSolicitud;
- let filename =
- 'reporte_' +
- this.tipoSolicitud.toLowerCase() +
- '_' +
- anio +
- (mes < 10 ? '0' : '') +
- mes +
- (dia < 10 ? '0' : '') +
- dia +
- '_' +
- (hora < 10 ? '0' : '') +
- hora +
- (minuto < 10 ? '0' : '') +
- minuto +
- (segundos < 10 ? '0' : '') +
- segundos;
- this.excel.generarExcel(this.selection.selected, filename, titulo);
- } else {
- this._validationService.openSnackBar(
- 'Para generar el Excel se debe seleccionar al menos una fila'
- );
- }
- }
- 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;
- }
- }
|