[EDIT] LIMPIEZA DE CODIGO

parent 52e63a88
......@@ -58,17 +58,6 @@ interface interPersonal {
nombre : string ;
}
/*interface interDetallePasaje {
index: number;
lugarOrigen: string;
lugarDestino : string;
monto: number;
fecha: Date;
isNew: boolean;
isEdit : boolean;
acciones: boolean;
}*/
interface interFile{
tipoEvidencia: number;
file: File;
......@@ -115,13 +104,11 @@ interface interFile{
NgStyle,
truncarCaracteresDirective,
ordenSalidaComponent,
//AngularSignaturePadModule,
],
providers: [
provideNativeDateAdapter(),
DatePipe,
DecimalPipe,
//{ provide: MAT_DATE_FORMATS, useValue: MY_DATE_FORMATS },
{ provide: MAT_DATE_LOCALE, useValue: 'es-ES' }, // Configurar el idioma español
{ provide: DateAdapter, useClass: CustomDateAdapter } // Adaptador personalizado
],
......@@ -156,20 +143,14 @@ export class ConformidadComponent implements AfterViewInit {
listSedesAtencion : lugaresTrabajo[] = [];
listRequerimientos: interRequerimientos[] = [];
listTipoTrabajo: tiposTrabajo[] = [];
//listadoSedesTrabajo : lugaresTrabajo[] = []; // SEDE DE TRABAJO PARA PASAJES
listPersonal : interPersonal[] = [{ index: 0 , id: 0 , nombre: '' }];
idBotones: number = 0;
//indexPasaje : number = 0 ;
labelText: string = ''; // Texto que se muestra inicialmente
isFading: boolean = false; // Controla si la animación de desvanecimiento debe activarse
personalText : string = '';
personalFading : boolean = false ;
mostrarHoras : boolean = true ;
//activarPasajes : boolean = false;
obtenerFirma :boolean = false;
//lugarDestinoPasaje : string = '';
//columnasPasaje: string[] = ['lugarOrigen', 'lugarDestino', 'monto', 'fecha','accion'];
//dataSource: interDetallePasaje[] = [];
alertaPosicionHorizontal: MatSnackBarHorizontalPosition = 'center';
alertaPosicionVertical: MatSnackBarVerticalPosition = 'bottom';
......@@ -195,7 +176,6 @@ export class ConformidadComponent implements AfterViewInit {
maxFechaTrabajo : new FormControl<Date>(new Date(), Validators.required),
minHoraTrabajo : new FormControl<string | null>(''),
maxHoraTrabajo : new FormControl<string | null>(''),
//pasajeTotal: new FormControl<number>(0),
});
datos_servicio = new FormGroup({
......@@ -214,12 +194,6 @@ export class ConformidadComponent implements AfterViewInit {
existeMaterial : new FormControl(null ,Validators.required),
});
/*datos_pasajeAcumulado = new FormGroup<any>({});
datos_lugarOrigen : FormGroup = new FormGroup<any>({}) ;
datos_fechaPasaje : FormGroup = new FormGroup<any>({}) ;*/
// GROUPO DE FORMULARIO
constructor(
......@@ -287,33 +261,10 @@ export class ConformidadComponent implements AfterViewInit {
this.cargosU_list = cargosUnidos;
this.zona_list = [{ value: 1, viewValue: 'NORTE' },{ value: 2, viewValue: 'SUR' },{ value: 3, viewValue: 'ESTE' },{ value: 4, viewValue: 'CENTRO' }];
this.unidades_list = unidades;
//this.dataSource = []; // Inicializa la tabla de pasajes
//this.activarPasajes = false;
this.listRequerimientos = [];
const jsonTipoTrabajo = JSON.parse(tipoTrabajo);
this.listTipoTrabajo = jsonTipoTrabajo.data;
//this.habilitarSeccionPersonal(true);
// Detecta cambios en el formulario de Datos Personal exceptuando 'lugarDestinoPasaje' para desbloquear el boton de 'Agregar Pasaje'
/*this.datos_personal.valueChanges.subscribe(value => {
const controlesInvalidos = Object.keys(this.datos_personal.controls)
.filter(controlName => this.obtenerFormControl(this.datos_personal,controlName)?.invalid);
console.log('Controles inválidos con errores:', controlesInvalidos);
this.activarPasajes = controlesInvalidos.length === 0 ? true : false;
// En caso ya existan registros en la tabla de pasajes , se limpiará el listado y las filas existentes.
if(this.dataSource.length > 0 && !this.activarPasajes){
this.dataSource = [];
this.indexPasaje = 0;
this.datos_pasajeAcumulado.reset();
this.datos_fechaPasaje.reset();
this.datos_lugarOrigen.reset();
}
});*/
this.obtenerFormControl(this.datos_personal,'zonaPersonal')?.valueChanges.subscribe((value : any) => {
this.listSedesAtencion = this.sede_list.filter((item: any) => item.zona === value).map((item: any) => ({ value: item.id_local, viewValue: item.deslocal }));
});
......@@ -323,41 +274,6 @@ export class ConformidadComponent implements AfterViewInit {
this.personal_list = personal.filter((item: any) => cargos.includes(item.codcargo));
});
// Sincronizar el valor de 'sedePersonal' con los selects la tabla de pasaje
/*this.obtenerFormControl(this.datos_personal,'sedePersonal')?.valueChanges.subscribe((value : any) => {
this.lugarDestinoPasaje = this.listadoSedesTrabajo.find((item: any) => item.value === value)?.viewValue || '';
});*/
//Sincroniza todos los inputs de monto de pasaje con el total de pasajes
/*this.datos_pasajeAcumulado.valueChanges.subscribe(values => {
const inputControls = Object.keys(values).filter(key => key.includes('montoPasaje')); // OBTENIENDO TODAS LAS KEYS DE MONTOPASAJE
const sum : number = (inputControls.reduce((acc, key) => Number(this.decimalPipe.transform( (acc + (Number( this.decimalPipe.transform(values[key], '1.2-2') ) || 0) ) , '1.2-2' ) ) , 0) ) || 0;
this.datos_personal.get('pasajeTotal')?.setValue(sum, { emitEvent: false });
});*/
//Condicionar a todos los controladores de Lugar de Origen para que si se escoge el mismo lugar que el lugar de origen salga una advertencia
/*this.datos_lugarOrigen.valueChanges.subscribe(value => {
const lugarDestino = this.datos_personal.get('sedePersonal')?.value;
if(lugarDestino) {
const inputControls = Object.keys(value);
inputControls.forEach((idlugar) => {
const lugarOrigen = value[idlugar];
if (lugarOrigen) {
if (lugarOrigen === lugarDestino) {
this.datos_lugarOrigen.get(idlugar)?.setErrors({'incorrect': true});
}
}else{
this.datos_lugarOrigen.get(idlugar)?.setErrors({'incorrect': false});
}
});
}else{
this.datos_personal.get('sedePersonal')?.setErrors({'incorrect': true});
}
});*/
this.datos_personal.get('maxFechaTrabajo')?.valueChanges.subscribe((value) => {
let minFecha : any = this.datos_personal.get('minFechaTrabajo')?.value;
let maxFecha : any = value;
......@@ -376,26 +292,6 @@ export class ConformidadComponent implements AfterViewInit {
this.datos_personal.get('minHoraTrabajo')?.setValue('00:00');
this.datos_personal.get('maxHoraTrabajo')?.setValue('00:00');
/*
this.minFechaLimite = new Date(minFecha);
this.maxFechaLimite = new Date(maxFecha);
//Obtener todos los formControNames dentro del formGroup datos_fechaPasaje
const inputControls = Object.keys(this.datos_fechaPasaje.controls);
//Iterar sobre cada formControlName
inputControls.forEach((key) => {
let fechaPasaje = this.datos_fechaPasaje.get(key)?.value;
if(fechaPasaje){
let fechaPasajeDate = new Date(fechaPasaje);
if(fechaPasajeDate >= (this.minFechaLimite || new Date()) && fechaPasajeDate <= (this.maxFechaLimite|| new Date()) ){
this.datos_fechaPasaje.get(key)?.setErrors({'incorrect': false});
} else{
this.datos_fechaPasaje.get(key)?.setErrors({'incorrect': true});
this.datos_fechaPasaje.get(key)?.setValue('');
}
}
});*/
}
});
}
......@@ -424,56 +320,6 @@ export class ConformidadComponent implements AfterViewInit {
}
botonPrueba(){
/*Notiflix.Notify.success('ÉXITO DE CONFORMIDAD ', {
position: 'center-center', // Notificación en el centro de la pantalla
timeout: 1000, // 1 segundo
width: '400px',
fontSize: '24px',
fontAwesomeIconSize: '34px',
});
// Espera 1 segundo y recarga la página
setTimeout(() => {
window.location.reload();
}, 1000);*/
Notiflix.Report.failure(
"Error en subida",
`Fallaron 2 archivos después de 1 intentos.`,
"Cerrar"
);
//this.mostrarNotificacion();
/*Notiflix.Confirm.show(
"✅ ÉXITO DE CONFORMIDAD",
"Registro completado exitosamente",
"Cerrar",
() => {
setTimeout(() => {
window.location.reload(); // Recargar la página
}, 1000);
}
)*/
}
mostrarNotificacion() {
this.snackBar.open('Operación exitosa', 'Cerrar', {
duration: 1000, // 1 segundo
horizontalPosition: 'center',
verticalPosition: 'top', // Puedes cambiar a 'bottom' si prefieres
panelClass: ['success-snackbar'] // Clase CSS personalizada
});
// Espera 1 segundo y recarga la página
setTimeout(() => {
window.location.reload();
}, 1000);
}
//AL SELECCIONAR INFORMACION DE UN REQUERIMIENTO
async infoRequerimiento(valor: any){
const requerimientoInfo = await this.conformidadHelper.listadoGeneralHorizon({accion: 3, nombreValor: valor, sede: ''});
......@@ -582,190 +428,6 @@ export class ConformidadComponent implements AfterViewInit {
this.requerimientosFiltrados = mapeoResultado;
}
/*formatMontoPasaje(formGroup: FormGroup, formControlName: string) {
//const control = this.datos_pasajeAcumulado.get('montoPasaje'+index);
const control = this.obtenerFormControl(formGroup,formControlName);
if (control && control.value != null) {
const formattedValue = this.decimalPipe.transform(control.value, '1.2-2');
control.setValue(formattedValue, { emitEvent: false });
}
}*/
//AL SELECCIONAR LA OPCIÓN DE NUEVO PASAJE
/*onEventoNuevoPasaje(event : any){
const NuevaFila : interDetallePasaje = {
index: this.indexPasaje++,
lugarOrigen: '',
lugarDestino: '',
monto: 0,
fecha: new Date(),
isNew: true,
isEdit : false,
acciones: true
};
this.agregarFormControl(this.datos_pasajeAcumulado,'montoPasaje'+NuevaFila.index,new FormControl<String | null>(null,[ Validators.maxLength(6),Validators.pattern(/^[0-9.]*$/) ]));
this.agregarFormControl(this.datos_fechaPasaje,'fechaPasaje'+NuevaFila.index,new FormControl<Date | null>(null,[Validators.maxLength(12)]));
this.agregarFormControl(this.datos_lugarOrigen,'lugarOrigen'+NuevaFila.index,new FormControl<String | null>(null ,[Validators.maxLength(12)]));
this.dataSource.forEach((item) => {
if (item.index !== NuevaFila.index) {
item.isEdit = false;
item.isNew = false;
item.acciones = false;
}
});
this.dataSource = [...this.dataSource,NuevaFila];
this.activarPasajes = false;
this.habilitarSeccionPersonal(false);
}*/
/*onEventoConfirmarPasaje(event: any, elemento: any){
const lugarOrigen = this.obtenerFormControl(this.datos_lugarOrigen,`lugarOrigen${elemento.index}`)?.value;
const lugarDestino = this.obtenerFormControl(this.datos_personal,'sedePersonal')?.value || '';
const pasaje = this.obtenerFormControl(this.datos_pasajeAcumulado,`montoPasaje${elemento.index}`)?.value;
const fechaPasaje = this.obtenerFormControl(this.datos_fechaPasaje,`fechaPasaje${elemento.index}`)?.value;
//VALIDAR LOS VALORES OBTENIDOS ANTES DE REALIZAR UN REGISTRO
if(this.validarRegistroPasaje(elemento.index)){
// Agregar los datos recogidos de la fila para agregarlos en dataSource y actualizar la tabla
const index = this.dataSource.findIndex((item) => item.index === elemento.index);
this.dataSource[index] = {
index: elemento.index,
//lugarOrigen: this.sede_list.find((item: any) => item.codlocal === lugarOrigen)?.deslocal || '' ,
//lugarDestino: this.sede_list.find((item: any) => item.codlocal === lugarDestino)?.deslocal || '' ,
lugarOrigen : this.listadoSedesTrabajo.find((item: any) => item.value === lugarOrigen)?.viewValue || '',
lugarDestino : this.listadoSedesTrabajo.find((item: any) => item.value === lugarDestino)?.viewValue || '',
monto: pasaje,
fecha: fechaPasaje,
isNew: false,
isEdit : false,
acciones: true
};
this.dataSource.forEach((item) => {item.acciones = true; }); // VUELVE A ACTIVAR TODAS LAS ACCION
this.dataSource = [...this.dataSource];
this.activarPasajes = true;
this.habilitarSeccionPersonal(true);
this.barraAlerta.open( 'REGISTRO INGRESADO' , '' , {
horizontalPosition: this.alertaPosicionHorizontal,
verticalPosition: this.alertaPosicionVertical,
duration: this.alertaDuracion * 1000
});
}else{
this.barraAlerta.open( 'VALIDAR DATOS INGRESADOS' , '' , {
horizontalPosition: this.alertaPosicionHorizontal,
verticalPosition: this.alertaPosicionVertical,
duration: this.alertaDuracion * 1000
});
}
}*/
/*validarRegistroPasaje(index : number){
const lugarOrigen = this.datos_lugarOrigen.get('lugarOrigen'+index)?.value;
const lugarDestino = this.datos_personal.get('sedePersonal')?.value;
const fechaPasaje = this.datos_fechaPasaje.get('fechaPasaje'+index)?.value;
const montoPasaje = this.datos_pasajeAcumulado.get('montoPasaje'+index)?.value;
this.obtenerFormControl(this.datos_lugarOrigen,'lugarOrigen'+index)?.setErrors({'incorrect': !(lugarOrigen && lugarOrigen !== lugarDestino) , emitEvent: true});
this.obtenerFormControl(this.datos_fechaPasaje,'fechaPasaje'+index)?.setErrors({'incorrect': !fechaPasaje , emitEvent: true });
this.obtenerFormControl(this.datos_pasajeAcumulado,'montoPasaje'+index)?.setErrors({'incorrect': !(montoPasaje && montoPasaje > 0) , emitEvent: true });
return lugarOrigen && lugarDestino && fechaPasaje && montoPasaje && montoPasaje > 0 && lugarOrigen !== lugarDestino;
}*/
/*onEventoCancelarPasaje(event: any, elemento: any){
const index = this.dataSource.findIndex((item) => item.index === elemento.index);//Descubriendo el index
this.dataSource.forEach((item) => { item.acciones = true; }); // Que todas las filas vuelvan a tener las acciones
if(this.dataSource[index].isEdit){
this.dataSource[index].isEdit = false;
this.dataSource[index].isNew = false;
this.dataSource = [...this.dataSource];
}else{
this.dataSource = this.dataSource.filter((item) => item.index !== elemento.index);
this.removerFormControl(this.datos_pasajeAcumulado,'montoPasaje'+elemento.index);
this.removerFormControl(this.datos_fechaPasaje,'fechaPasaje'+elemento.index);
this.removerFormControl(this.datos_lugarOrigen,'lugarOrigen'+elemento.index);
}
this.habilitarSeccionPersonal(true);
this.activarPasajes = true
}*/
//Editar una fila de pasaje
/*onEventoEditarPasaje(event: any, elemento: any) {
const index = this.dataSource.findIndex((item) => item.index === elemento.index);//Descubriendo el index
this.dataSource.forEach((item) => {
if (item.index === elemento.index) {
item.isEdit = true;
item.isNew = true;
item.acciones = true;
} else {
item.isEdit = false;
item.isNew = false;
item.acciones = false;
}
});
this.dataSource = [...this.dataSource]; // Volviendo ha ingresar los datos para que la tabla se actualice y la fila cambie con las condiciones del HTML
this.activarPasajes = false;
}*/
/*onEventoEliminarPasaje(event: any, elemento: any){
//Al presionar el boton aparecerá un Dialog confirmando si desea eliminar el registro, al aceptar la fila del registro se eliminará.
const dialogRef = this.dialog.open(ConfirmarEliminacionComponent);
dialogRef.afterClosed().subscribe(result => {
if (result) {
const index = elemento.index;
if (index >= 0) {
this.dataSource = this.dataSource.filter((item) => item.index !== elemento.index);
this.removerFormControl(this.datos_pasajeAcumulado,'montoPasaje'+elemento.index);
this.removerFormControl(this.datos_fechaPasaje,'fechaPasaje'+elemento.index);
this.removerFormControl(this.datos_lugarOrigen,'lugarOrigen'+elemento.index);
}
}
});
}*/
/*habilitarSeccionPersonal(datos: boolean){
if(datos){
this.datos_personal.get('tecnicoPersonal')?.enable({ emitEvent: false });
this.datos_personal.get('areaPersonal')?.enable({ emitEvent: false });
this.datos_personal.get('sedePersonal')?.enable({ emitEvent: false });
this.datos_personal.get('maxFechaTrabajo')?.enable({ emitEvent: false });
this.datos_personal.get('minFechaTrabajo')?.enable({ emitEvent: false });
}else{
this.datos_personal.get('tecnicoPersonal')?.disable({ emitEvent: false });
this.datos_personal.get('areaPersonal')?.disable({ emitEvent: false });
this.datos_personal.get('sedePersonal')?.disable({ emitEvent: false });
this.datos_personal.get('maxFechaTrabajo')?.disable({ emitEvent: false });
this.datos_personal.get('minFechaTrabajo')?.disable({ emitEvent: false });
}
}*/
onEventoSubirArchivo(event: any, tipo : number = 1) {
const archivosSeleccionados: FileList = event.target.files;
......@@ -841,7 +503,7 @@ export class ConformidadComponent implements AfterViewInit {
}
}else{
this.archivosEvidencia.splice(index, 1); // Eliminar el archivo del array de archivosEP
this.archivosEvidencia.splice(index, 1); // Eliminar el archivo del array de archivosEP
}
}
......@@ -867,90 +529,6 @@ export class ConformidadComponent implements AfterViewInit {
Notiflix.Loading.standard('Cargando...');
//APLICAR EL REGISTRO DE CONFORMIDAD
/*const registroConformidad = await this.conformidadHelper.gestionConformidad({
opcion: 1,
codlocal: datosPersonal.sedePersonal + '',
fechainicio: this.formatoFechaRegistro(datosPersonal.minFechaTrabajo || new Date() ) ,
fechafin: this.formatoFechaRegistro(datosPersonal.maxFechaTrabajo || new Date() ) ,
descproblema: datosServicio.descripcionServicio,
desccausa: datosServicio.causaServicio,
codtipotrabajo: parseInt(datosTrabajo.tipoTrabajo || '1'),
desctrabajo: datosTrabajo.descripcionTrabajo,
minhoratrabajo : datosPersonal.minHoraTrabajo,
maxhoratrabajo : datosPersonal.maxHoraTrabajo,
avance : datosTrabajo.avanceTrabajo,
});
console.log(registroConformidad);
//RESPUESTA DEL REGISTRO DE CONFORMIDAD
const respuestaConformidad : any = JSON.parse(registroConformidad);
if(respuestaConformidad.status){
let codigoConformidad = respuestaConformidad.data.codconformidad;
const registroCarpeta = await this.conformidadHelper.creacionCarpeta({codconformidad: codigoConformidad});
if (registroCarpeta.status) {
//UNIR LOS DATOS archivosEP Y archivosES EN UN SOLO ARRAY
let statusEvidencias = true;
const registroArchivos = archivosEvidencias.map((item) => {
return {
codconformidad: codigoConformidad,
archivo: item.file,
idCarpeta: registroCarpeta.idCarpeta,
tipoEvidencia: item.tipoEvidencia,
nombreArchivo: (item.tipoEvidencia === 1) ? 'EVIDENCIA_PROBLEMA_' + codigoConformidad + "_" + (contadorEP++) :
(item.tipoEvidencia === 2) ? 'EVIDENCIA_SOLUCION_' + codigoConformidad + "_" + (contadorES++) :
(item.tipoEvidencia === 3) ? 'EVIDENCIA_ATS_' + codigoConformidad + "_" + (constadorATS++) :
(item.tipoEvidencia === 4) ? 'FIRMA_' + codigoConformidad + "_" + (contadorFirma++) : 'DATO_EXTRA_' + codigoConformidad + "_" + (contadorExtras++)
};
});
this.ConformidadService.progresoSubida.next(0); // Reiniciar progreso
const resultados : {status: boolean , mensaje : string} = await this.conformidadHelper.subidaEvidencia3(registroArchivos);
if(resultados.status){
Notiflix.Notify.success('Operación exitosa', {
position: 'center-center', // Notificación en el centro de la pantalla
timeout: 1000, // 1 segundo
width: '400px',
fontSize: '24px',
fontAwesomeIconSize: '34px',
});
// Espera 1 segundo y recarga la página
setTimeout(() => {
window.location.reload();
}, 1000);
}else{
Notiflix.Report.failure(
"Error en subida",
resultados.mensaje,
"Cerrar"
);
//Agregar el eliminar registro y eliminar Documento.
const eliminarConformidad = await this.conformidadHelper.eliminarDocumento({opcion: 1, codconformidad: codigoConformidad});
console.log(eliminarConformidad);
}
//Notiflix.Loading.remove();
} else {
this.mostrarAlerta('ERROR AL CREAR CARPETA DE EVIDENCIAS');
}
}else{
this.mostrarAlerta('ERROR AL REGISTRAR CONFORMIDAD');
}*/
//Notiflix.Loading.pulse(); // Muestra un loading
if (!this.validarDatosPersonales(datosPersonal)) {
this.mostrarAlerta('VALIDAR DATOS PERSONALES');
return;
......@@ -961,7 +539,6 @@ export class ConformidadComponent implements AfterViewInit {
return;
}
if(!this.validarArchivos(archivosEvidencias)){
return;
};
......@@ -1046,7 +623,6 @@ export class ConformidadComponent implements AfterViewInit {
if(statusPersonal) { // REGISTRO DE PERSONAL CONFIRMADO Y REGISTRADO
let statusRequerimientos = true;
if (requerimientoRelacionados.length > 0) {
......@@ -1069,6 +645,8 @@ export class ConformidadComponent implements AfterViewInit {
break;
}
}
}else{
statusRequerimientos = true;
}
if (statusRequerimientos) { // REGISTRO DE REQUERIMIENTOS VALIDADOS Y REGISTRADOS
......@@ -1201,10 +779,6 @@ export class ConformidadComponent implements AfterViewInit {
return personal.length > 0 && personal.every((item) => item.id != '0' && item.nombre != '');
}
/*validarPasajes(datosPasajes: any[]): boolean {
return (datosPasajes.length > 0 && datosPasajes.every((item) => item.lugarOrigen && item.lugarDestino && item.monto && item.fecha)) || datosPasajes.length === 0;
}*/
validarArchivos(archivosEvidencia : any[]): boolean {
let advertencia = '';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment