|
|
@@ -5,6 +5,10 @@ import { USERInterface } from 'src/app/interfaces/user-interface';
|
|
|
import { IAMService } from 'src/app/services/iam/iam.service';
|
|
|
import { MESMPRService } from 'src/app/services/mes/mesmpr/mesmpr.service';
|
|
|
import { MESMPRDetallesInterface } from 'src/app/interfaces/mes/mesmpr/mesmpr-detalles-interface';
|
|
|
+import { ENCService } from 'src/app/services/enc/enc.service';
|
|
|
+import { MesmprVacacionesInterface } from 'src/app/interfaces/mes/mesmpr/mesmpr-vacaciones-interface';
|
|
|
+import { TileStyler } from '@angular/material/grid-list/tile-styler';
|
|
|
+import { ResponseData } from 'src/app/interfaces/response-data';
|
|
|
@Component({
|
|
|
selector: 'app-mesmpr',
|
|
|
templateUrl: './mesmpr.component.html',
|
|
|
@@ -12,32 +16,40 @@ import { MESMPRDetallesInterface } from 'src/app/interfaces/mes/mesmpr/mesmpr-de
|
|
|
})
|
|
|
export class MESMPRComponent implements OnInit {
|
|
|
loading: Boolean = true;
|
|
|
- periodo: number;
|
|
|
- periodos: MesmprInterface[] = [];
|
|
|
|
|
|
- detalles: MESMPRDetallesInterface[] = [];
|
|
|
+ public detalles: Array<any> = [];
|
|
|
|
|
|
- anios_actuales: string = `${ new Date().getFullYear()-1 }-${ new Date().getFullYear() }`
|
|
|
- anios_anteriores: string = `${ new Date().getFullYear()-2 }-${ new Date().getFullYear()-1 }`
|
|
|
- periodo_actual_2: MesmprInterface = {} as MesmprInterface;
|
|
|
- periodo_anterior_2: MesmprInterface = {} as MesmprInterface;
|
|
|
- periodo_eayg: MesmprInterface = null!;
|
|
|
- dias_por_periodo_actual: number = 0;
|
|
|
- dias_por_periodo_anterior: number = 0;
|
|
|
- dias_tomados: number = 0;
|
|
|
- arr_detalles: any[] = [];
|
|
|
+ public periodos: Array<MesmprInterface> = [] as Array<MesmprInterface>;
|
|
|
|
|
|
- periodo_actual: any = null;
|
|
|
- periodo_actual_anios: String = '';
|
|
|
|
|
|
- periodo_anterior: any = null;
|
|
|
- periodo_anterior_anios: String = '';
|
|
|
+ public caso0: boolean = false;
|
|
|
+ public casoEAYG: boolean = false;
|
|
|
+ public casoActual: boolean = false;
|
|
|
+ public casoAnterior: boolean = false;
|
|
|
|
|
|
- dias_periodo = 0;
|
|
|
+ public periodoEAYG: string = "2020-2021";
|
|
|
+ public periodoActual: string = "2020-2021";
|
|
|
+ public periodoAnterior: string = "2020-2021";
|
|
|
|
|
|
- caso1: boolean = false;
|
|
|
- caso2: boolean = false;
|
|
|
- caso3: boolean = false;
|
|
|
+ public fechaVencimientoEAYG: string = "2020-2021";
|
|
|
+ public fechaVencimientoActual: string = "2020-2021";
|
|
|
+ public fechaVencimientoAnterior: string = "2020-2021";
|
|
|
+
|
|
|
+ public diasDisponiblesEAYG: number = 10;
|
|
|
+ public diasDisponiblesActual: number = 10;
|
|
|
+ public diasDisponiblesAnterior: number = 10;
|
|
|
+
|
|
|
+ public diasPeriodoEAYG: number = 5;
|
|
|
+ public diasPeriodoActual: number = 5;
|
|
|
+ public diasPeriodoAnterior: number = 5;
|
|
|
+
|
|
|
+ public diasTomadosEAYG: number = 5;
|
|
|
+ public diasTomadosActual: number = 5;
|
|
|
+ public diasTomadosAnterior: number = 5;
|
|
|
+
|
|
|
+ public diasSolicitadosEAYG: number = 0;
|
|
|
+ public diasSolicitadosActual: number = 0;
|
|
|
+ public diasSolicitadosAnterior: number = 0;
|
|
|
|
|
|
usuario: string = '';
|
|
|
usuario_session: USERInterface = JSON.parse(
|
|
|
@@ -47,103 +59,32 @@ export class MESMPRComponent implements OnInit {
|
|
|
constructor(
|
|
|
private _mesmprService: MESMPRService,
|
|
|
private _iamService: IAMService,
|
|
|
- private _snackBar: MatSnackBar
|
|
|
+ private _snackBar: MatSnackBar,
|
|
|
+ private _encService: ENCService
|
|
|
) {
|
|
|
- this.periodo = new Date().getFullYear();
|
|
|
this.usuario = this.usuario_session.NOMBRE;
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
this.obtener();
|
|
|
}
|
|
|
|
|
|
- obtenerDetalles(periodos: MesmprInterface[]){
|
|
|
- periodos.forEach( element0 => {
|
|
|
- if (element0.DETALLES.length !== 0 ) {
|
|
|
- element0.DETALLES.forEach( element1 => {
|
|
|
-
|
|
|
- if (element1.DIASTOMADOS !== 0) {
|
|
|
- this.arr_detalles.push({
|
|
|
- DIASTOMADOS: element1.DIASTOMADOS,
|
|
|
- FECHASVACACIONES: element1.FECHASVACACIONES,
|
|
|
- PERIODO: element0.PERIODO
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- obtenerPeriodoActual(periodos: MesmprInterface[]){
|
|
|
-
|
|
|
- let ultimo_periodo = periodos[periodos.length- 1];
|
|
|
-
|
|
|
- if (ultimo_periodo.ESEAYG != "Si") {
|
|
|
- this.periodo_actual_2 = ultimo_periodo;
|
|
|
- this.periodo_anterior_2 = periodos[periodos.length - 2];
|
|
|
- }else{
|
|
|
- if (periodos.length > 1 ) {
|
|
|
- this.periodo_actual_2 = periodos[periodos.length - 2];
|
|
|
- this.periodo_anterior_2 = periodos[periodos.length - 3];
|
|
|
- }else{
|
|
|
- this.periodo_actual_2 = periodos[periodos.length - 1];
|
|
|
- this.periodo_anterior_2 = periodos[periodos.length - 2];
|
|
|
- }
|
|
|
-
|
|
|
- this.periodo_eayg = ultimo_periodo;
|
|
|
- }
|
|
|
-
|
|
|
- this.dias_por_periodo_actual = this.periodo_actual_2.VACACIONESDISPONIBLES;
|
|
|
- this.dias_por_periodo_anterior = this.periodo_anterior_2.VACACIONESDISPONIBLES;
|
|
|
-
|
|
|
- this.periodo_actual_2.DETALLES.forEach(element => {
|
|
|
- this.dias_tomados += element.DIASTOMADOS;
|
|
|
- this.dias_por_periodo_actual += element.DIASTOMADOS;
|
|
|
- });
|
|
|
-
|
|
|
- this.periodo_anterior_2.DETALLES.forEach(element => {
|
|
|
- this.dias_por_periodo_anterior += element.DIASTOMADOS;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- construirPeriodo(periodo:String){
|
|
|
- let arr_periodo = periodo.split("|");
|
|
|
- let anio_inicio = arr_periodo[0].split("-")[0];
|
|
|
- let anio_final = arr_periodo[1].split("-")[0];
|
|
|
- return `${anio_inicio}-${anio_final}`
|
|
|
- }
|
|
|
-
|
|
|
- obtener() {
|
|
|
+ private async obtener() {
|
|
|
this._mesmprService.obtener().subscribe(
|
|
|
- (res: any) => {0
|
|
|
-
|
|
|
+ (res: ResponseData) => {
|
|
|
if (res.status == 'Token is Expired') {
|
|
|
this._iamService.logout();
|
|
|
this.snackAlert('Sesión expirada. Vuelva a iniciar sesión');
|
|
|
- }
|
|
|
- if (res.response.length == 0) {
|
|
|
- this.caso3 = true;
|
|
|
- }else if(res.response.length == 1 && res.response[0].DIASEAYGDISPONIBLES > 0){
|
|
|
- this.caso2 = true;
|
|
|
- this.caso3 = false;
|
|
|
-
|
|
|
- this.obtenerPeriodoActual( res.response);
|
|
|
}else{
|
|
|
- this.obtenerDetalles(res.response);
|
|
|
- this.obtenerPeriodoActual( res.response);
|
|
|
- this.caso1 = true;
|
|
|
+ let verPeriodos:MesmprInterface[] = res.response.filter((element:any) => element.CADUCADO === "No" && element.DETALLES.length > 0);
|
|
|
+
|
|
|
+ this.periodos = verPeriodos;
|
|
|
+ this.obtenerCasos(res.response);
|
|
|
+ this.loading = false;
|
|
|
}
|
|
|
-
|
|
|
- this.periodos = res.response;
|
|
|
-
|
|
|
- this.loading = false;
|
|
|
- this.filtroPeriodos();
|
|
|
},
|
|
|
(error) => {
|
|
|
+ console.log(error);
|
|
|
|
|
|
if (!error.ok) {
|
|
|
this.snackAlert('Ocurrió un error inesperado');
|
|
|
@@ -158,82 +99,128 @@ export class MESMPRComponent implements OnInit {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- filtroPeriodos() {
|
|
|
- if (this.periodos.length > 0) {
|
|
|
- //"2018-01-24|2019-01-24"
|
|
|
- //Split para separar las fechas, split para obtener el año
|
|
|
- let filtro_periodos: MesmprInterface[] = this.periodos.filter(
|
|
|
- (p:any) =>
|
|
|
- parseInt(p.PERIODO.split('|')[1].split('-')[0]) <= this.periodo &&
|
|
|
- p.VACACIONESDISPONIBLES > 0
|
|
|
- );
|
|
|
-
|
|
|
- if (filtro_periodos.length == 1) {
|
|
|
- this.periodo_actual = filtro_periodos[0];
|
|
|
- } else if (filtro_periodos.length > 1) {
|
|
|
- filtro_periodos.sort(function (a, b) {
|
|
|
- if (
|
|
|
- parseInt(a.PERIODO.split('|')[1].split('-')[0]) >
|
|
|
- parseInt(b.PERIODO.split('|')[1].split('-')[0])
|
|
|
- ) {
|
|
|
- return -1;
|
|
|
- }
|
|
|
- if (
|
|
|
- parseInt(a.PERIODO.split('|')[1].split('-')[0]) <
|
|
|
- parseInt(b.PERIODO.split('|')[1].split('-')[0])
|
|
|
- ) {
|
|
|
- return 1;
|
|
|
- }
|
|
|
- return 0;
|
|
|
- });
|
|
|
-
|
|
|
- //Obtener periodo actual
|
|
|
- this.periodo_actual = filtro_periodos[0];
|
|
|
-
|
|
|
- //Obtener periodo anterior
|
|
|
- this.periodo_anterior = filtro_periodos[1];
|
|
|
-
|
|
|
- //Asignar dias del periodo, tomados
|
|
|
- filtro_periodos[0].DETALLES.forEach((detalle) => {
|
|
|
- this.dias_periodo += detalle.DIASTOMADOS;
|
|
|
- });
|
|
|
- //Asignar dias disponibles
|
|
|
- this.dias_periodo += filtro_periodos[0].VACACIONESDISPONIBLES;
|
|
|
-
|
|
|
- //Formato años 2021-2022
|
|
|
- this.periodo_actual_anios = this.obtenerAnios(
|
|
|
- filtro_periodos[0].PERIODO
|
|
|
- );
|
|
|
-
|
|
|
- //Formato años periodo anterior
|
|
|
- this.periodo_anterior_anios = this.obtenerAnios(
|
|
|
- filtro_periodos[1].PERIODO
|
|
|
- );
|
|
|
+ private obtenerCasos(response: Array<MesmprInterface>){
|
|
|
+ let verPeriodos:MesmprInterface[] = response.filter(element => element.CADUCADO === "No");
|
|
|
+ if(verPeriodos.length == 0){
|
|
|
+ this.caso0 = true;
|
|
|
+ }else{
|
|
|
+ let periodoAux = verPeriodos;
|
|
|
+ periodoAux.map(element => {
|
|
|
+ if (element.DETALLES.length > 0) {
|
|
|
+ this.detalles = [...element.DETALLES];
|
|
|
+ }
|
|
|
+ return element;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (verPeriodos.some(element => element.ESEAYG === "Si")) {
|
|
|
+ let eayg:MesmprInterface = verPeriodos.pop()!;
|
|
|
+
|
|
|
+ this.periodoEAYG = this.formatoPeriodo(eayg.PERIODO) // Periodo en años 'Periodo EAYG'
|
|
|
+ this.fechaVencimientoEAYG = this.formatoFecha(eayg.PERIODO.split('|')[1]); // Fecha de vencimiento del periodo
|
|
|
+ this.diasPeriodoEAYG = this.obtenerDiasPeriodos(eayg.DETALLES) + eayg.VACACIONESDISPONIBLES; // Cantidad de días disponibles por periodo 'Días por periodo' EAYG
|
|
|
+ this.diasDisponiblesEAYG = eayg.VACACIONESDISPONIBLES; // Cantidad de 'Días disponibles' EAYG
|
|
|
+ this.diasTomadosEAYG = this.obtenerDiasTomados(eayg.DETALLES) // Cantidad de días tomados 'Días tomados' EAYG
|
|
|
+ this.diasSolicitadosEAYG = this.obtenerDiasSolicitados(eayg.DETALLES);
|
|
|
+ this.casoEAYG = true;
|
|
|
}
|
|
|
- //this.detalles = filtro_periodos.map((periodo) => periodo.DETALLES);
|
|
|
- let detalles_map = filtro_periodos.map(function (
|
|
|
- periodo: MesmprInterface
|
|
|
- ) {
|
|
|
- return {
|
|
|
- DETALLES: periodo.DETALLES,
|
|
|
- PERIODO_DIVIDER: periodo.PERIODO,
|
|
|
- };
|
|
|
+
|
|
|
+ if (verPeriodos.length > 0){
|
|
|
+ let actual:MesmprInterface = verPeriodos.pop()!;
|
|
|
+
|
|
|
+ this.periodoActual = this.formatoPeriodo(actual.PERIODO) ; // Periodo en años 'Periodo EAYG'
|
|
|
+ this.fechaVencimientoActual = this.formatoFecha(actual.PERIODO.split('|')[1]); // Fecha de vencimiento del periodo
|
|
|
+ this.diasPeriodoActual = this.obtenerDiasPeriodos(actual.DETALLES) + actual.VACACIONESDISPONIBLES; // Cantidad de días disponibles por periodo 'Días por periodo' EAYG
|
|
|
+ this.diasDisponiblesActual = actual.VACACIONESDISPONIBLES; // Cantidad de 'Días disponibles' EAYG
|
|
|
+ this.diasTomadosActual = this.obtenerDiasTomados(actual.DETALLES) // Cantidad de días tomados 'Días tomados' EAYG
|
|
|
+ this.casoActual = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (verPeriodos.length > 0){
|
|
|
+ let anterior:MesmprInterface = verPeriodos.pop()!;
|
|
|
+
|
|
|
+ this.periodoAnterior = this.formatoPeriodo(anterior.PERIODO) ; // Periodo en años 'Periodo EAYG'
|
|
|
+ this.fechaVencimientoAnterior = this.formatoFecha(anterior.PERIODO.split('|')[1]); // Fecha de vencimiento del periodo
|
|
|
+ this.diasPeriodoAnterior = this.obtenerDiasPeriodos(anterior.DETALLES) + anterior.VACACIONESDISPONIBLES; // Cantidad de días disponibles por periodo 'Días por periodo' EAYG
|
|
|
+ this.diasDisponiblesAnterior = anterior.VACACIONESDISPONIBLES; // Cantidad de 'Días disponibles' EAYG
|
|
|
+ this.diasTomadosAnterior = this.obtenerDiasTomados(anterior.DETALLES) // Cantidad de días tomados 'Días tomados' EAYG
|
|
|
+
|
|
|
+ this.casoAnterior = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private obtenerDiasPeriodos(detalles: Array<MesmprVacacionesInterface>){
|
|
|
+ if (detalles.length > 0) {
|
|
|
+ let total:number = 0;
|
|
|
+
|
|
|
+ detalles.map( detalle => {
|
|
|
+ if(detalle.DIASTOMADOS === 0){
|
|
|
+ total += detalle.DIASSOLICITADOS
|
|
|
+ }
|
|
|
+ total += detalle.DIASTOMADOS
|
|
|
+ });
|
|
|
+ return total;
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private obtenerDiasTomados(detalles: Array<MesmprVacacionesInterface>){
|
|
|
+ if (detalles.length > 0) {
|
|
|
+ let total:number = 0;
|
|
|
+ detalles.map( detalle => {
|
|
|
+ total += detalle.DIASTOMADOS
|
|
|
+ });
|
|
|
+ return total;
|
|
|
+ }else{
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public formatoDetalles(detalles: Array<MesmprVacacionesInterface>):Array<any>{
|
|
|
+ let respuesta = detalles.map(element => {
|
|
|
+ let arrFecha = element.FECHASVACACIONES.split('|');
|
|
|
+ return {
|
|
|
+ fecha_inicio: arrFecha[0],
|
|
|
+ fecha_fin: arrFecha[0],
|
|
|
+ dias_tomados: element.DIASTOMADOS
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return respuesta;
|
|
|
+ }
|
|
|
+
|
|
|
+ private obtenerDiasSolicitados(detalles:Array<MesmprVacacionesInterface> ){
|
|
|
+ if (detalles.length > 0) {
|
|
|
+ let total:number = 0;
|
|
|
+ detalles.map( detalle => {
|
|
|
+ total += detalle.DIASSOLICITADOS
|
|
|
});
|
|
|
+ return total;
|
|
|
+ }else{
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- this.detalles = detalles_map as MESMPRDetallesInterface[];
|
|
|
- this.detalles = this.detalles.filter(
|
|
|
- (detalle) =>
|
|
|
- detalle.DETALLES.filter((detalle) => detalle.DIASTOMADOS > 0).length >
|
|
|
- 0
|
|
|
- );
|
|
|
- }
|
|
|
+ construirPeriodo(periodo:String){
|
|
|
+ let arr_periodo = periodo.split("|");
|
|
|
+ let anio_inicio = arr_periodo[0].split("-")[0];
|
|
|
+ let anio_final = arr_periodo[1].split("-")[0];
|
|
|
+ return `${anio_inicio}-${anio_final}`
|
|
|
}
|
|
|
|
|
|
- obtenerAnios(periodo: String): String {
|
|
|
+
|
|
|
+ formatoPeriodo(periodo: String): string {
|
|
|
let anios = periodo.split('|');
|
|
|
return anios[0].split('-')[0] + '-' + anios[1].split('-')[0];
|
|
|
}
|
|
|
|
|
|
+ formatoDosPeriodo(periodo: String): string {
|
|
|
+ let anios = periodo.split('|');
|
|
|
+ return anios[0].split('/')[0]
|
|
|
+ }
|
|
|
+
|
|
|
formatoFecha(fecha: string): string {
|
|
|
let split = fecha.split('-');
|
|
|
return `${split[2]}-${split[1]}-${split[0]}`;
|