|
|
@@ -1,4 +1,4 @@
|
|
|
-import { Component, Inject, OnInit } from "@angular/core";
|
|
|
+import { Component, ElementRef, Inject, OnInit, ViewChild } from "@angular/core";
|
|
|
import { EnviarInfoService } from "../../../Administrador/services/enviar-info.service";
|
|
|
import { AbstractControl, FormBuilder, FormControl, FormGroup, ReactiveFormsModule, ValidationErrors, Validators,FormArray } from "@angular/forms";
|
|
|
import { MAT_DATE_LOCALE, MatOption, provideNativeDateAdapter } from "@angular/material/core";
|
|
|
@@ -928,6 +928,12 @@ export class RegistroAdComponent implements OnInit {
|
|
|
gradoCur: any;
|
|
|
Padre = JSON.parse(localStorage.getItem('userData') || '');
|
|
|
rutaArchivo=' ';
|
|
|
+ facturaDataOriginal: any = null;
|
|
|
+ nombreArchivoCargado: any;
|
|
|
+opcionFactura: string = 'No';
|
|
|
+isSaving: boolean = false;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
constructor(private _enviarInfo: EnviarInfoService, private fb: FormBuilder, public dialog: MatDialog, private _registroAdministrativo: RegistroAcademicoService,
|
|
|
private _router: Router, private _gradosEducativos: GradosEducativosService, private route: ActivatedRoute, private _registro: RegistroAcademicoService
|
|
|
@@ -936,6 +942,8 @@ export class RegistroAdComponent implements OnInit {
|
|
|
}
|
|
|
rutaArchivoSubido: string = '';
|
|
|
|
|
|
+@ViewChild('fileInput') fileInput!: ElementRef<HTMLInputElement>;
|
|
|
+
|
|
|
eliminarArchivo() {
|
|
|
if (!this.rutaArchivo) {
|
|
|
Swal.fire('Error', 'No hay archivo para eliminar', 'error');
|
|
|
@@ -944,7 +952,16 @@ eliminarArchivo() {
|
|
|
|
|
|
this._registroAdministrativo.eliminarArchivo(this.rutaArchivo).subscribe((res) => {
|
|
|
Swal.fire('Archivo eliminado', res.mensaje, 'success');
|
|
|
+
|
|
|
+ // Limpiar campos y variables
|
|
|
this.rutaArchivo = '';
|
|
|
+ this.selectedFile = null;
|
|
|
+ this.form2.get('constanciaFiscal')?.setValue(null);
|
|
|
+
|
|
|
+ // Limpiar visualmente el input file
|
|
|
+ if (this.fileInput && this.fileInput.nativeElement) {
|
|
|
+ this.fileInput.nativeElement.value = '';
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -998,102 +1015,133 @@ formulario() {
|
|
|
}
|
|
|
|
|
|
cargarFormulario() {
|
|
|
- this._registroAdministrativo.getOneRegistroAdmin(this.id).subscribe((data: any) => {
|
|
|
- this.isLoading = false;
|
|
|
- this.datos = data.registro[0];
|
|
|
- if (this.datos != undefined) {
|
|
|
- this.form.get('gradoCursar')?.setValue(this.datos.RegA_GradoCursar);
|
|
|
- this.form.get('mesInscripcion')?.setValue(this.datos.RegA_MesInscripcion);
|
|
|
- this.form.get('planPago')?.setValue(this.datos.RegA_PlanPagos);
|
|
|
- this.form.get('becaCurso')?.setValue(this.datos.RegA_BecaCurso);
|
|
|
- this.form.get('becaPorcentaje')?.setValue(this.datos.RegA_BecaPorcentaje);
|
|
|
-
|
|
|
- this.form2.get('factura')?.setValue(this.datos.RegA_RequiereFactura);
|
|
|
-
|
|
|
- // Actualiza controles según valor de factura
|
|
|
- this.factura({ value: this.datos.RegA_RequiereFactura });
|
|
|
-
|
|
|
- this.form2.get('metedoPago')?.setValue(this.datos.RegA_MetodoPago);
|
|
|
- this.form2.get('RFCFactura')?.setValue(this.datos.RegA_RfcFactura);
|
|
|
- this.form2.get('razonSocial')?.setValue(this.datos.RegA_NombreFactura);
|
|
|
- this.form2.get('domicilioFactura')?.setValue(this.datos.RegA_DireccionFactura);
|
|
|
- this.form2.get('correoFactura')?.setValue(this.datos.RegA_CorreoFactura);
|
|
|
- this.form2.get('cuentaPago')?.setValue(this.datos.RegA_CuentaPago);
|
|
|
-
|
|
|
- if (this.datos.RegA_RequiereFactura === 'No') {
|
|
|
- // Borra archivo porque ya no requiere factura
|
|
|
- this.selectedFile = null;
|
|
|
- this.form2.get('constanciaFiscal')?.setValue(null);
|
|
|
- } else {
|
|
|
- // Mostrar archivo si existe
|
|
|
- if (this.datos.RegA_ConstanciaFiscal) {
|
|
|
- this.form2.get('constanciaFiscal')?.setValue(this.datos.RegA_ConstanciaFiscal);
|
|
|
- }
|
|
|
- }
|
|
|
+ this.isLoading = true;
|
|
|
+
|
|
|
+ this._registroAdministrativo.getOneRegistroAdmin(this.id).subscribe({
|
|
|
+ next: (data: any) => {
|
|
|
+ this.isLoading = false;
|
|
|
+ this.datos = data.registro[0];
|
|
|
+
|
|
|
+ if (this.datos != undefined) {
|
|
|
+ // Datos normales
|
|
|
+ this.form.get('gradoCursar')?.setValue(this.datos.RegA_GradoCursar);
|
|
|
+ this.form.get('mesInscripcion')?.setValue(this.datos.RegA_MesInscripcion);
|
|
|
+ this.form.get('planPago')?.setValue(this.datos.RegA_PlanPagos);
|
|
|
+ this.form.get('becaCurso')?.setValue(this.datos.RegA_BecaCurso);
|
|
|
+ this.form.get('becaPorcentaje')?.setValue(this.datos.RegA_BecaPorcentaje);
|
|
|
+
|
|
|
+ // FACTURACIÓN
|
|
|
+ const requiereFactura = this.datos.RegA_RequiereFactura?.toLowerCase() || 'no';
|
|
|
+
|
|
|
+ this.form2.get('factura')?.setValue(requiereFactura);
|
|
|
+ this.factura({ value: requiereFactura }); // ← actualiza visibilidad
|
|
|
+
|
|
|
+ // Guardar datos originales por si el usuario cambia de idea
|
|
|
+ this.facturaDataOriginal = {
|
|
|
+ metodoPago: this.datos.RegA_MetodoPago,
|
|
|
+ RFC: this.datos.RegA_RfcFactura,
|
|
|
+ razonSocial: this.datos.RegA_NombreFactura,
|
|
|
+ domicilio: this.datos.RegA_DireccionFactura,
|
|
|
+ correo: this.datos.RegA_CorreoFactura,
|
|
|
+ cuenta: this.datos.RegA_CuentaPago,
|
|
|
+ archivo: this.datos.RegA_ConstanciaFiscal,
|
|
|
+ };
|
|
|
+
|
|
|
+ if (requiereFactura === 'sí') {
|
|
|
+ // Mostrar datos si hay
|
|
|
+ this.form2.get('metedoPago')?.setValue(this.datos.RegA_MetodoPago);
|
|
|
+ this.form2.get('RFCFactura')?.setValue(this.datos.RegA_RfcFactura);
|
|
|
+ this.form2.get('razonSocial')?.setValue(this.datos.RegA_NombreFactura);
|
|
|
+ this.form2.get('domicilioFactura')?.setValue(this.datos.RegA_DireccionFactura);
|
|
|
+ this.form2.get('correoFactura')?.setValue(this.datos.RegA_CorreoFactura);
|
|
|
+ this.form2.get('cuentaPago')?.setValue(this.datos.RegA_CuentaPago);
|
|
|
+ this.form2.get('constanciaFiscal')?.setValue(this.datos.RegA_ConstanciaFiscal);
|
|
|
+
|
|
|
+ this.rutaArchivo = this.datos.RegA_ConstanciaFiscal; // Mostrar archivo
|
|
|
+ } else {
|
|
|
+ // Limpiar si no requiere factura
|
|
|
+ this.form2.get('metedoPago')?.setValue('NA');
|
|
|
+ this.form2.get('RFCFactura')?.setValue('NA');
|
|
|
+ this.form2.get('razonSocial')?.setValue('NA');
|
|
|
+ this.form2.get('domicilioFactura')?.setValue('NA');
|
|
|
+ this.form2.get('correoFactura')?.setValue('NA');
|
|
|
+ this.form2.get('cuentaPago')?.setValue('NA');
|
|
|
+ this.form2.get('constanciaFiscal')?.setValue('NA');
|
|
|
+ this.selectedFile = null;
|
|
|
+ this.rutaArchivo = ''; // Ocultar archivo
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: (err) => {
|
|
|
+ this.isLoading = false;
|
|
|
+ console.error('Error al cargar formulario:', err);
|
|
|
+ Swal.fire('Error', 'No se pudo cargar el formulario', 'error');
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- factura(event: any) {
|
|
|
- if (event.value === 'No') {
|
|
|
- this.form2.get('metedoPago')?.setValue('EF');
|
|
|
- this.form2.get('RFCFactura')?.setValue('XAXX010101000');
|
|
|
- this.form2.get('razonSocial')?.setValue('PUBLICO EN GENERAL');
|
|
|
- this.form2.get('correoFactura')?.setValue('NA');
|
|
|
- this.form2.get('domicilioFactura')?.setValue('NA');
|
|
|
- this.form2.get('cuentaPago')?.setValue('00');
|
|
|
- this.form2.get('domicilioFactura')?.clearValidators();
|
|
|
- this.form2.get('correoFactura')?.clearValidators();
|
|
|
- this.form2.get('razonSocial')?.clearValidators();
|
|
|
- this.form2.get('RFCFactura')?.clearValidators();
|
|
|
- this.form2.get('metedoPago')?.clearValidators();
|
|
|
-
|
|
|
- this.form2.get('domicilioFactura')?.disable();
|
|
|
- this.form2.get('correoFactura')?.disable();
|
|
|
- this.form2.get('razonSocial')?.disable();
|
|
|
- this.form2.get('RFCFactura')?.disable();
|
|
|
- this.form2.get('metedoPago')?.disable();
|
|
|
-this.form2.get('constanciaFiscal')?.disable();
|
|
|
-this.selectedFile = null;
|
|
|
-this.form2.get('constanciaFiscal')?.setValue(null);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- } else {
|
|
|
- this.form2.get('metedoPago')?.setValue('');
|
|
|
- this.form2.get('RFCFactura')?.setValue('');
|
|
|
- this.form2.get('razonSocial')?.setValue('');
|
|
|
- this.form2.get('domicilioFactura')?.setValue('');
|
|
|
- this.form2.get('correoFactura')?.setValue('');
|
|
|
- this.form2.get('cuentaPago')?.setValue('01');
|
|
|
-
|
|
|
- this.form2.get('domicilioFactura')?.setValidators([Validators.required]);
|
|
|
- this.form2.get('correoFactura')?.setValidators([Validators.required, Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$')]);
|
|
|
- this.form2.get('razonSocial')?.setValidators([Validators.required]);
|
|
|
- this.form2.get('RFCFactura')?.setValidators([Validators.required]);
|
|
|
- this.form2.get('metedoPago')?.setValidators([Validators.required]);
|
|
|
-
|
|
|
- this.form2.get('domicilioFactura')?.enable();
|
|
|
- this.form2.get('correoFactura')?.enable();
|
|
|
- this.form2.get('razonSocial')?.enable();
|
|
|
- this.form2.get('RFCFactura')?.enable();
|
|
|
- this.form2.get('metedoPago')?.enable();
|
|
|
-this.form2.get('constanciaFiscal')?.enable();
|
|
|
- }
|
|
|
|
|
|
- this.form2.get('domicilioFactura')?.updateValueAndValidity();
|
|
|
- this.form2.get('correoFactura')?.updateValueAndValidity();
|
|
|
- this.form2.get('razonSocial')?.updateValueAndValidity();
|
|
|
- this.form2.get('RFCFactura')?.updateValueAndValidity();
|
|
|
- this.form2.get('metedoPago')?.updateValueAndValidity();
|
|
|
- this.form2.get('constanciaFiscal')?.updateValueAndValidity();
|
|
|
|
|
|
+factura(event: any) {
|
|
|
+ if (event.value === 'no') {
|
|
|
+ this.form2.get('metedoPago')?.setValue('NA');
|
|
|
+ this.form2.get('RFCFactura')?.setValue('NA');
|
|
|
+ this.form2.get('razonSocial')?.setValue('NA');
|
|
|
+ this.form2.get('domicilioFactura')?.setValue('NA');
|
|
|
+ this.form2.get('correoFactura')?.setValue('NA');
|
|
|
+ this.form2.get('cuentaPago')?.setValue('NA');
|
|
|
+
|
|
|
+ this.form2.get('constanciaFiscal')?.setValue(this.facturaDataOriginal?.archivo || '');
|
|
|
+
|
|
|
+ // Deshabilitamos campos pero no borramos constanciaFiscal
|
|
|
+ this.form2.get('domicilioFactura')?.disable();
|
|
|
+ this.form2.get('correoFactura')?.disable();
|
|
|
+ this.form2.get('razonSocial')?.disable();
|
|
|
+ this.form2.get('RFCFactura')?.disable();
|
|
|
+ this.form2.get('metedoPago')?.disable();
|
|
|
+ this.form2.get('constanciaFiscal')?.disable();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ this.form2.get('metedoPago')?.setValue(this.facturaDataOriginal?.metodoPago || '');
|
|
|
+ this.form2.get('RFCFactura')?.setValue(this.facturaDataOriginal?.RFC || '');
|
|
|
+ this.form2.get('razonSocial')?.setValue(this.facturaDataOriginal?.razonSocial || '');
|
|
|
+ this.form2.get('domicilioFactura')?.setValue(this.facturaDataOriginal?.domicilio || '');
|
|
|
+ this.form2.get('correoFactura')?.setValue(this.facturaDataOriginal?.correo || '');
|
|
|
+ this.form2.get('cuentaPago')?.setValue(this.facturaDataOriginal?.cuenta || '');
|
|
|
+
|
|
|
+ this.form2.get('constanciaFiscal')?.setValue(this.facturaDataOriginal?.archivo || '');
|
|
|
+
|
|
|
+ this.form2.get('domicilioFactura')?.enable();
|
|
|
+ this.form2.get('correoFactura')?.enable();
|
|
|
+ this.form2.get('razonSocial')?.enable();
|
|
|
+ this.form2.get('RFCFactura')?.enable();
|
|
|
+ this.form2.get('metedoPago')?.enable();
|
|
|
+ this.form2.get('constanciaFiscal')?.enable();
|
|
|
+
|
|
|
+ this.form2.get('domicilioFactura')?.setValidators([Validators.required]);
|
|
|
+ this.form2.get('correoFactura')?.setValidators([Validators.required, Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$')]);
|
|
|
+ this.form2.get('razonSocial')?.setValidators([Validators.required]);
|
|
|
+ this.form2.get('RFCFactura')?.setValidators([Validators.required]);
|
|
|
+ this.form2.get('metedoPago')?.setValidators([Validators.required]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Actualizamos las validaciones y el estado del formulario
|
|
|
+ this.form2.get('domicilioFactura')?.updateValueAndValidity();
|
|
|
+ this.form2.get('correoFactura')?.updateValueAndValidity();
|
|
|
+ this.form2.get('razonSocial')?.updateValueAndValidity();
|
|
|
+ this.form2.get('RFCFactura')?.updateValueAndValidity();
|
|
|
+ this.form2.get('metedoPago')?.updateValueAndValidity();
|
|
|
+ this.form2.get('constanciaFiscal')?.updateValueAndValidity();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
siguienteTap(index: number) {
|
|
|
if (this.form.invalid) {
|
|
|
this.form.markAllAsTouched();
|
|
|
@@ -1191,22 +1239,33 @@ async guardarFormulario() {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- try {
|
|
|
- // Habilita temporalmente los campos deshabilitados
|
|
|
+ try {
|
|
|
+ const requiereFactura = this.form2.get('requiereFactura')?.value;
|
|
|
+
|
|
|
+ // Activamos campos de factura para acceder a su valor
|
|
|
this.form2.get('domicilioFactura')?.enable();
|
|
|
this.form2.get('correoFactura')?.enable();
|
|
|
this.form2.get('razonSocial')?.enable();
|
|
|
this.form2.get('RFCFactura')?.enable();
|
|
|
this.form2.get('metedoPago')?.enable();
|
|
|
|
|
|
- // Combina los valores de ambos formularios
|
|
|
- const formularioCompleto = {
|
|
|
+ // Creamos un objeto combinado de form1 y form2
|
|
|
+ const formularioCompleto: any = {
|
|
|
...this.form.getRawValue(),
|
|
|
...this.form2.getRawValue(),
|
|
|
- idEscuela: 'COLEGIOABC',
|
|
|
+ idEscuela: 'COLEGIOABC'
|
|
|
};
|
|
|
|
|
|
- // Construir FormData
|
|
|
+ // Si el usuario seleccionó "No", seteamos manualmente los campos de factura como 'NA'
|
|
|
+ if (requiereFactura === 'No') {
|
|
|
+ formularioCompleto.domicilioFactura = 'NA';
|
|
|
+ formularioCompleto.correoFactura = 'NA';
|
|
|
+ formularioCompleto.razonSocial = 'NA';
|
|
|
+ formularioCompleto.RFCFactura = 'NA';
|
|
|
+ formularioCompleto.metedoPago = 'NA';
|
|
|
+ }
|
|
|
+
|
|
|
+ // Creamos FormData para envío (incluye datos y archivo)
|
|
|
const formData = new FormData();
|
|
|
for (const key in formularioCompleto) {
|
|
|
if (formularioCompleto[key] !== null && formularioCompleto[key] !== undefined) {
|
|
|
@@ -1214,23 +1273,24 @@ async guardarFormulario() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Si hay archivo seleccionado, lo agregamos al FormData
|
|
|
+ // Adjuntar archivo solo si seleccionaron uno nuevo
|
|
|
if (this.selectedFile) {
|
|
|
formData.append('constanciaFiscal', this.selectedFile, this.selectedFile.name);
|
|
|
}
|
|
|
|
|
|
- // Vuelve a deshabilitar los campos
|
|
|
+ // Desactivamos los campos de factura de nuevo
|
|
|
this.form2.get('domicilioFactura')?.disable();
|
|
|
this.form2.get('correoFactura')?.disable();
|
|
|
this.form2.get('razonSocial')?.disable();
|
|
|
this.form2.get('RFCFactura')?.disable();
|
|
|
this.form2.get('metedoPago')?.disable();
|
|
|
|
|
|
- // Decide si crear o actualizar
|
|
|
+ // Obtenemos si ya existe registro
|
|
|
this._registroAdministrativo.getOneRegistroAdmin(this.id).subscribe((data: any) => {
|
|
|
const idAlumno = this.form.get('idAlumno')?.value;
|
|
|
|
|
|
if (data.registro && data.registro.length > 0) {
|
|
|
+ // Ya existe => actualizar
|
|
|
this._registroAdministrativo.actualizarRegistroAdministrativo(formData, idAlumno).subscribe(
|
|
|
(res: any) => {
|
|
|
Swal.fire('Actualización exitosa', res.mensaje, 'success');
|
|
|
@@ -1242,6 +1302,7 @@ async guardarFormulario() {
|
|
|
}
|
|
|
);
|
|
|
} else {
|
|
|
+ // No existe => crear
|
|
|
this._registroAdministrativo.crearRegistroAdministrativo(formData).subscribe(
|
|
|
(res: any) => {
|
|
|
Swal.fire('Registro exitoso', res.mensaje, 'success');
|
|
|
@@ -1262,6 +1323,8 @@ async guardarFormulario() {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
Asistente() {
|
|
|
const asistente = this.dialog.open(Asistente, {
|
|
|
data: this.form2.getRawValue().domicilioFactura
|
|
|
@@ -1275,7 +1338,6 @@ async guardarFormulario() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Component({
|
|
|
selector: 'App-Asistente',
|
|
|
templateUrl: './Asistente.html',
|
|
|
@@ -1378,3 +1440,9 @@ export class Asistente {
|
|
|
this.maxCaracteres = this.form.get('referencia')?.value.length
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// los primeros bugs que tengo son cuando edito el apratodao de facturazon tiene un radio btn con opciones si y no.
|
|
|
+//supongamos que el registro que NO tengo problema con eso se completo exitosamente y la opcion fue "si" entonces:
|
|
|
+//a la hora de editar y cargar las respuestas con carga formulario la opcion del radio viene como "no" y con ello vienen en los campos llenos, enotnces al campiar la opcion a "si" se borran los datos de las respuestas
|