|
|
@@ -1,4 +1,4 @@
|
|
|
-import { Component, ElementRef, Inject, OnInit, ViewChild } from "@angular/core";
|
|
|
+import { ChangeDetectorRef, 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";
|
|
|
@@ -436,7 +436,7 @@ form4 = this.fb.group({
|
|
|
dataAlum: any;
|
|
|
nombreAlumno: any;
|
|
|
constructor(private _enviarInfo: EnviarInfoService, private fb: FormBuilder, private _registroAcademico: RegistroAcademicoService, private _router: Router,
|
|
|
- public dialog: MatDialog, private breakpointObserver: BreakpointObserver, private route: ActivatedRoute
|
|
|
+ public dialog: MatDialog, private breakpointObserver: BreakpointObserver, private route: ActivatedRoute, private cdr: ChangeDetectorRef
|
|
|
) {
|
|
|
this.todayDate.setFullYear(new Date().getFullYear(), 0, 1);
|
|
|
this.todayDate1.setFullYear(new Date().getFullYear() - 20, 0, 1);
|
|
|
@@ -703,6 +703,7 @@ isPersonaAutorizadaInvalid(index: number, campo: string): boolean {
|
|
|
});
|
|
|
this.form.get('idAlumno')?.setValue(this.id);
|
|
|
this.form.get('edad')?.disable();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
siguienteTap(index: number) {
|
|
|
@@ -908,6 +909,9 @@ export class RegistroAdComponent implements OnInit {
|
|
|
{ id: '11', nombre: 'Noviembre' },
|
|
|
{ id: '12', nombre: 'Diciembre' },
|
|
|
];
|
|
|
+ modoEdicion: boolean = false;
|
|
|
+ rutaArchivoOriginal: string = '';
|
|
|
+
|
|
|
selectedFile: File | null = null;
|
|
|
GradoCursar: any[] = [];
|
|
|
planPago: any[] = [];
|
|
|
@@ -936,7 +940,7 @@ 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
|
|
|
+ private _router: Router, private _gradosEducativos: GradosEducativosService, private route: ActivatedRoute, private _registro: RegistroAcademicoService, private cdr: ChangeDetectorRef
|
|
|
) {
|
|
|
this.formulario();
|
|
|
}
|
|
|
@@ -944,28 +948,56 @@ rutaArchivoSubido: string = '';
|
|
|
|
|
|
@ViewChild('fileInput') fileInput!: ElementRef<HTMLInputElement>;
|
|
|
|
|
|
-eliminarArchivo() {
|
|
|
- if (!this.rutaArchivo) {
|
|
|
- Swal.fire('Error', 'No hay archivo para eliminar', 'error');
|
|
|
- return;
|
|
|
- }
|
|
|
+ eliminarArchivo() {
|
|
|
+ if (!this.rutaArchivo) {
|
|
|
+ Swal.fire('Error', 'No hay archivo para eliminar', 'error');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Swal.fire({
|
|
|
+ title: '¿Estás seguro?',
|
|
|
+ text: 'El archivo será eliminado permanentemente',
|
|
|
+ icon: 'warning',
|
|
|
+ showCancelButton: true,
|
|
|
+ confirmButtonColor: '#d33',
|
|
|
+ cancelButtonColor: '#3085d6',
|
|
|
+ confirmButtonText: 'Sí, eliminar',
|
|
|
+ cancelButtonText: 'Cancelar'
|
|
|
+ }).then((result) => {
|
|
|
+ if (result.isConfirmed) {
|
|
|
+ this._registroAdministrativo.eliminarArchivo(this.rutaArchivo).subscribe((res) => {
|
|
|
+ Swal.fire('Archivo eliminado', res.mensaje, 'success');
|
|
|
|
|
|
- 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);
|
|
|
+ this.rutaArchivo = '';
|
|
|
+ this.rutaArchivoOriginal = '';
|
|
|
+ this.selectedFile = null;
|
|
|
+ this.form2.get('constanciaFiscal')?.setValue('');
|
|
|
|
|
|
- // Limpiar visualmente el input file
|
|
|
- if (this.fileInput && this.fileInput.nativeElement) {
|
|
|
- this.fileInput.nativeElement.value = '';
|
|
|
+ if (this.fileInput && this.fileInput.nativeElement) {
|
|
|
+ this.fileInput.nativeElement.value = '';
|
|
|
+ }
|
|
|
+
|
|
|
+ this.cdr.detectChanges();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- });
|
|
|
+
|
|
|
+ mostrarCambiarArchivo(): boolean {
|
|
|
+ return (!this.rutaArchivo || this.rutaArchivo.trim() === '') && !!this.selectedFile;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ mostrarEliminarArchivo(): boolean {
|
|
|
+ return !!this.rutaArchivo && this.rutaArchivo.trim() !== '' && !this.selectedFile;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+mostrarSeleccionarArchivo(): boolean {
|
|
|
+ return (!this.rutaArchivo || this.rutaArchivo.trim() === '') && !this.selectedFile;
|
|
|
+}
|
|
|
+
|
|
|
formulario() {
|
|
|
this.form = this.fb.group({
|
|
|
idAlumno: [''],
|
|
|
@@ -992,7 +1024,15 @@ formulario() {
|
|
|
this.form2.get('RFCFactura')?.disable();
|
|
|
this.form2.get('metedoPago')?.disable();
|
|
|
}
|
|
|
- onFileSelected(event: any) {
|
|
|
+ onFileSelected(event: any) {
|
|
|
+ if (this.rutaArchivo && this.rutaArchivo.trim() !== '') {
|
|
|
+ Swal.fire({
|
|
|
+ icon: 'warning',
|
|
|
+ title: 'Archivo ya existente',
|
|
|
+ text: 'Primero elimina el archivo actual antes de seleccionar uno nuevo.',
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
const file = event.target.files[0];
|
|
|
if (file) {
|
|
|
if (file.type !== 'application/pdf') {
|
|
|
@@ -1011,9 +1051,9 @@ formulario() {
|
|
|
|
|
|
this.selectedFile = file;
|
|
|
this.form2.get('constanciaFiscal')?.setValue(file.name);
|
|
|
+ this.cdr.detectChanges();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
cargarFormulario() {
|
|
|
this.isLoading = true;
|
|
|
|
|
|
@@ -1023,20 +1063,33 @@ cargarFormulario() {
|
|
|
this.datos = data.registro[0];
|
|
|
|
|
|
if (this.datos != undefined) {
|
|
|
- // Datos normales
|
|
|
this.form.get('gradoCursar')?.setValue(this.datos.RegA_GradoCursar);
|
|
|
+
|
|
|
+ const metodoPagoBD = this.datos.RegA_MetodoPago;
|
|
|
+ if (this.MetodoPago && metodoPagoBD) {
|
|
|
+ const match = this.MetodoPago.find((p: any) => p.idMetodoPago == metodoPagoBD);
|
|
|
+ if (match) {
|
|
|
+ this.form2.get('metedoPago')?.setValue(match.idMetodoPago);
|
|
|
+ } else {
|
|
|
+ this.form2.get('metedoPago')?.setValue('');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
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);
|
|
|
+
|
|
|
+ const beca = (this.datos.RegA_BecaCursar || '').toLowerCase();
|
|
|
+ if (beca === 'si' || beca === 'no') {
|
|
|
+ this.form.get('becaCurso')?.setValue(beca.charAt(0).toUpperCase() + beca.slice(1));
|
|
|
+ } else {
|
|
|
+ this.form.get('becaCurso')?.setValue('');
|
|
|
+ }
|
|
|
+
|
|
|
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,
|
|
|
@@ -1047,29 +1100,36 @@ cargarFormulario() {
|
|
|
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
|
|
|
+ if (requiereFactura === 'si') {
|
|
|
+ if (this.MetodoPago && metodoPagoBD) {
|
|
|
+ const match = this.MetodoPago.find((p: any) => p.idMetodoPago == metodoPagoBD);
|
|
|
+ if (match) {
|
|
|
+ this.form2.get('metedoPago')?.setValue(match.idMetodoPago);
|
|
|
+ } else {
|
|
|
+ this.form2.get('metedoPago')?.setValue('');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.form2.get('RFCFactura')?.setValue(this.datos.RegA_RfcFactura || '');
|
|
|
+ this.form2.get('razonSocial')?.setValue(this.datos.RegA_NombreFactura || '');
|
|
|
+ this.form2.get('correoFactura')?.setValue(this.datos.RegA_CorreoFactura || '');
|
|
|
+ this.form2.get('cuentaPago')?.setValue(this.datos.RegA_CuentaPago || '');
|
|
|
+
|
|
|
+ if (this.datos.RegA_DireccionFactura && this.datos.RegA_DireccionFactura.trim() !== '') {
|
|
|
+ this.form2.get('domicilioFactura')?.setValue(this.datos.RegA_DireccionFactura);
|
|
|
+ } else {
|
|
|
+ this.autocompletarDomicilio();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.datos.RegA_ConstanciaFiscal && this.datos.RegA_ConstanciaFiscal.trim() !== '') {
|
|
|
+ this.rutaArchivo = this.datos.RegA_ConstanciaFiscal;
|
|
|
+ this.rutaArchivoOriginal = this.datos.RegA_ConstanciaFiscal;
|
|
|
+ this.form2.get('constanciaFiscal')?.setValue(this.datos.RegA_ConstanciaFiscal);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ this.factura({ value: requiereFactura });
|
|
|
+ this.cdr.detectChanges();
|
|
|
}
|
|
|
},
|
|
|
error: (err) => {
|
|
|
@@ -1081,9 +1141,17 @@ cargarFormulario() {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
factura(event: any) {
|
|
|
- if (event.value === 'no') {
|
|
|
+ const requiereFactura = event.value;
|
|
|
+
|
|
|
+ if (requiereFactura === 'no') {
|
|
|
+ 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();
|
|
|
+
|
|
|
+ // Campos de facturación
|
|
|
this.form2.get('metedoPago')?.setValue('NA');
|
|
|
this.form2.get('RFCFactura')?.setValue('NA');
|
|
|
this.form2.get('razonSocial')?.setValue('NA');
|
|
|
@@ -1091,9 +1159,11 @@ factura(event: any) {
|
|
|
this.form2.get('correoFactura')?.setValue('NA');
|
|
|
this.form2.get('cuentaPago')?.setValue('NA');
|
|
|
|
|
|
- this.form2.get('constanciaFiscal')?.setValue(this.facturaDataOriginal?.archivo || '');
|
|
|
+ if (!this.rutaArchivo || this.rutaArchivo.trim() === '') {
|
|
|
+ this.form2.get('constanciaFiscal')?.setValue('');
|
|
|
+ }
|
|
|
|
|
|
- // Deshabilitamos campos pero no borramos constanciaFiscal
|
|
|
+ // Deshabilitar campos
|
|
|
this.form2.get('domicilioFactura')?.disable();
|
|
|
this.form2.get('correoFactura')?.disable();
|
|
|
this.form2.get('razonSocial')?.disable();
|
|
|
@@ -1102,15 +1172,6 @@ factura(event: any) {
|
|
|
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();
|
|
|
@@ -1118,26 +1179,50 @@ factura(event: any) {
|
|
|
this.form2.get('metedoPago')?.enable();
|
|
|
this.form2.get('constanciaFiscal')?.enable();
|
|
|
|
|
|
+ if (!this.form2.get('metedoPago')?.value || this.form2.get('metedoPago')?.value === 'NA') {
|
|
|
+ this.form2.get('metedoPago')?.setValue(this.facturaDataOriginal?.metodoPago || '');
|
|
|
+ }
|
|
|
+ if (!this.form2.get('RFCFactura')?.value || this.form2.get('RFCFactura')?.value === 'NA') {
|
|
|
+ this.form2.get('RFCFactura')?.setValue(this.facturaDataOriginal?.RFC || '');
|
|
|
+ }
|
|
|
+ if (!this.form2.get('razonSocial')?.value || this.form2.get('razonSocial')?.value === 'NA') {
|
|
|
+ this.form2.get('razonSocial')?.setValue(this.facturaDataOriginal?.razonSocial || '');
|
|
|
+ }
|
|
|
+ if (!this.form2.get('domicilioFactura')?.value || this.form2.get('domicilioFactura')?.value === 'NA') {
|
|
|
+ this.form2.get('domicilioFactura')?.setValue(this.facturaDataOriginal?.domicilio || '');
|
|
|
+ }
|
|
|
+ if (!this.form2.get('correoFactura')?.value || this.form2.get('correoFactura')?.value === 'NA') {
|
|
|
+ this.form2.get('correoFactura')?.setValue(this.facturaDataOriginal?.correo || '');
|
|
|
+ }
|
|
|
+ if (!this.form2.get('cuentaPago')?.value || this.form2.get('cuentaPago')?.value === 'NA') {
|
|
|
+ this.form2.get('cuentaPago')?.setValue(this.facturaDataOriginal?.cuenta || '');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.facturaDataOriginal?.archivo && (!this.form2.get('constanciaFiscal')?.value || this.form2.get('constanciaFiscal')?.value === '')) {
|
|
|
+ this.form2.get('constanciaFiscal')?.setValue(this.facturaDataOriginal.archivo);
|
|
|
+ this.rutaArchivo = this.facturaDataOriginal.archivo;
|
|
|
+ }
|
|
|
+
|
|
|
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('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();
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
+ this.cdr.detectChanges();
|
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1182,82 +1267,139 @@ factura(event: any) {
|
|
|
}
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
- let idNivel: any;
|
|
|
- this._enviarInfo.currentTextColor.subscribe(textColor => {
|
|
|
- this.textColor = textColor;
|
|
|
- });
|
|
|
- this._enviarInfo.currentColor.subscribe(color => {
|
|
|
- this.color = color;
|
|
|
- });
|
|
|
+ let idNivel: any;
|
|
|
|
|
|
- this.route.paramMap.subscribe(params => {
|
|
|
- const id = params.get('id');
|
|
|
+ this._enviarInfo.currentTextColor.subscribe(textColor => {
|
|
|
+ this.textColor = textColor;
|
|
|
+ });
|
|
|
|
|
|
- this.id = atob(id || '');
|
|
|
- });
|
|
|
- this.form.get('idAlumno')?.setValue(this.id);
|
|
|
- this._registro.getOne(this.id).subscribe((data: any) => {
|
|
|
- this.dataAlum = data;
|
|
|
- this.nombreAlumno = data[0].nombreUsuario;
|
|
|
- });
|
|
|
+ this._enviarInfo.currentColor.subscribe(color => {
|
|
|
+ this.color = color;
|
|
|
+ });
|
|
|
|
|
|
- this._gradosEducativos.getAll().subscribe((data: any) => {
|
|
|
- if (data) {
|
|
|
- for (let i = 0; i < data.length; i++) {
|
|
|
- if (data[i].nombreGrado == this.dataAlum[0].grado) {
|
|
|
- idNivel = data[i].idNivel;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- this.GradoCursar = data.filter((data: any) => data.idNivel == idNivel);
|
|
|
- });
|
|
|
- this._registroAdministrativo.getPlanPago().subscribe((data: any) => {
|
|
|
- this.planPago = data.planPago.filter((data: any) => data.idNivelPlanPago == idNivel);
|
|
|
- });
|
|
|
+ this.route.paramMap.subscribe(params => {
|
|
|
+ const id = params.get('id');
|
|
|
+ this.id = atob(id || '');
|
|
|
+ });
|
|
|
|
|
|
- this._registroAdministrativo.getPorcentajeBeca().subscribe((data: any) => {
|
|
|
- this.porcentaje = data.porcentajeBeca;
|
|
|
- });
|
|
|
+ this.form.get('idAlumno')?.setValue(this.id);
|
|
|
|
|
|
- this._registroAdministrativo.getMetodoPago().subscribe((data: any) => {
|
|
|
- this.MetodoPago = data.metodoPago;
|
|
|
- });
|
|
|
+ this._registro.getOne(this.id).subscribe((data: any) => {
|
|
|
+ this.dataAlum = data;
|
|
|
+ this.nombreAlumno = data[0].nombreUsuario;
|
|
|
+ });
|
|
|
|
|
|
- this._registroAdministrativo.getOneRegistroAdmin(this.id).subscribe((data: any) => {
|
|
|
+ this._gradosEducativos.getAll().subscribe((data: any) => {
|
|
|
+ if (data) {
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ if (data[i].nombreGrado == this.dataAlum[0].grado) {
|
|
|
+ idNivel = data[i].idNivel;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.GradoCursar = data.filter((data: any) => data.idNivel == idNivel);
|
|
|
+ });
|
|
|
+
|
|
|
+ this._registroAdministrativo.getPlanPago().subscribe((data: any) => {
|
|
|
+ this.planPago = data.planPago.filter((data: any) => data.idNivelPlanPago == idNivel);
|
|
|
+ });
|
|
|
+
|
|
|
+ this._registroAdministrativo.getPorcentajeBeca().subscribe((data: any) => {
|
|
|
+ this.porcentaje = data.porcentajeBeca;
|
|
|
+ });
|
|
|
+
|
|
|
+ this._registroAdministrativo.getMetodoPago().subscribe((data: any) => {
|
|
|
+ this.MetodoPago = data.metodoPago;
|
|
|
+ });
|
|
|
+
|
|
|
+ this._registroAdministrativo.getOneRegistroAdmin(this.id).subscribe((data: any) => {
|
|
|
this.datos = data.registro[0];
|
|
|
|
|
|
if (this.datos?.RegA_ConstanciaFiscal) {
|
|
|
this.rutaArchivo = this.datos.RegA_ConstanciaFiscal;
|
|
|
}
|
|
|
+
|
|
|
+ this.cargarFormulario();
|
|
|
});
|
|
|
- this.cargarFormulario();
|
|
|
+}
|
|
|
+autocompletarDomicilio() {
|
|
|
+ const domicilio = `${this.dataAlum[0].calle}, ${this.dataAlum[0].colonia}, ${this.dataAlum[0].cp}`;
|
|
|
+ this.form2.get('domicilioFactura')?.setValue(domicilio);
|
|
|
+}
|
|
|
+
|
|
|
+private limpiarErroresValidacion() {
|
|
|
+
|
|
|
+ Object.keys(this.form2.controls).forEach(key => {
|
|
|
+ const control = this.form2.get(key);
|
|
|
+ if (control) {
|
|
|
+ control.markAsUntouched();
|
|
|
+ control.markAsPristine();
|
|
|
}
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
async guardarFormulario() {
|
|
|
- if (this.form2.invalid) {
|
|
|
+
|
|
|
+ this.limpiarErroresValidacion();
|
|
|
+
|
|
|
+ const requiereFactura = this.form2.get('factura')?.value;
|
|
|
+
|
|
|
+ if (requiereFactura === 'si') {
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ Object.keys(this.form2.controls).forEach(key => {
|
|
|
+ const control = this.form2.get(key);
|
|
|
+ console.log(`${key}:`, {
|
|
|
+ value: control?.value,
|
|
|
+ valid: control?.valid,
|
|
|
+ errors: control?.errors,
|
|
|
+ disabled: control?.disabled
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ if (this.form.invalid || this.form2.invalid) {
|
|
|
+
|
|
|
+ this.form.markAllAsTouched();
|
|
|
this.form2.markAllAsTouched();
|
|
|
+
|
|
|
+ const errores: string[] = [];
|
|
|
+ Object.keys(this.form.controls).forEach(key => {
|
|
|
+ if (this.form.get(key)?.invalid) {
|
|
|
+ errores.push(`Formulario General - ${key}: ${JSON.stringify(this.form.get(key)?.errors)}`);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Object.keys(this.form2.controls).forEach(key => {
|
|
|
+ if (this.form2.get(key)?.invalid) {
|
|
|
+ errores.push(`Formulario Facturación - ${key}: ${JSON.stringify(this.form2.get(key)?.errors)}`);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Swal.fire('Error de validación', 'Por favor, complete todos los campos requeridos correctamente.', 'error');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
|
- // Creamos un objeto combinado de form1 y form2
|
|
|
const formularioCompleto: any = {
|
|
|
...this.form.getRawValue(),
|
|
|
...this.form2.getRawValue(),
|
|
|
idEscuela: 'COLEGIOABC'
|
|
|
};
|
|
|
|
|
|
- // Si el usuario seleccionó "No", seteamos manualmente los campos de factura como 'NA'
|
|
|
- if (requiereFactura === 'No') {
|
|
|
+
|
|
|
+ if (requiereFactura === 'no') {
|
|
|
formularioCompleto.domicilioFactura = 'NA';
|
|
|
formularioCompleto.correoFactura = 'NA';
|
|
|
formularioCompleto.razonSocial = 'NA';
|
|
|
@@ -1265,7 +1407,6 @@ async guardarFormulario() {
|
|
|
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) {
|
|
|
@@ -1273,24 +1414,21 @@ async guardarFormulario() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Adjuntar archivo solo si seleccionaron uno nuevo
|
|
|
if (this.selectedFile) {
|
|
|
formData.append('constanciaFiscal', this.selectedFile, this.selectedFile.name);
|
|
|
}
|
|
|
|
|
|
- // 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();
|
|
|
|
|
|
- // 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');
|
|
|
@@ -1298,11 +1436,10 @@ async guardarFormulario() {
|
|
|
},
|
|
|
(error) => {
|
|
|
Swal.fire('Error', 'No se pudo actualizar el registro', 'error');
|
|
|
- console.error('Error al actualizar:', error);
|
|
|
}
|
|
|
);
|
|
|
} else {
|
|
|
- // No existe => crear
|
|
|
+
|
|
|
this._registroAdministrativo.crearRegistroAdministrativo(formData).subscribe(
|
|
|
(res: any) => {
|
|
|
Swal.fire('Registro exitoso', res.mensaje, 'success');
|
|
|
@@ -1310,33 +1447,44 @@ async guardarFormulario() {
|
|
|
},
|
|
|
(error) => {
|
|
|
Swal.fire('Error', 'No se pudo crear el registro', 'error');
|
|
|
- console.error('Error al crear:', error);
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
} catch (error) {
|
|
|
- console.error('Error en guardarFormulario:', error);
|
|
|
Swal.fire('Error', 'Ocurrió un error al procesar el formulario', 'error');
|
|
|
+ } finally {
|
|
|
+
|
|
|
+ if (requiereFactura !== 'si') {
|
|
|
+ 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();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- Asistente() {
|
|
|
- const asistente = this.dialog.open(Asistente, {
|
|
|
- data: this.form2.getRawValue().domicilioFactura
|
|
|
- });
|
|
|
- asistente.afterClosed().subscribe((result) => {
|
|
|
- if (result) {
|
|
|
- let domicilio = `${result.calle}, ${result.exterior}, ${result.interior}, ${result.colonia}, ${result.localidad}, ${result.municipio}, ${result.estado}, ${result.pais}, ${result.CP}, ${result.referencia}`;
|
|
|
- this.form2.get('domicilioFactura')?.setValue(domicilio.trim());
|
|
|
- }
|
|
|
- });
|
|
|
+Asistente() {
|
|
|
+ const domicilioActual = this.form2.get('domicilioFactura')?.value || '';
|
|
|
+
|
|
|
+ const asistente = this.dialog.open(Asistente, {
|
|
|
+ data: domicilioActual
|
|
|
+ });
|
|
|
+
|
|
|
+ asistente.afterClosed().subscribe((result) => {
|
|
|
+ if (result) {
|
|
|
+ let domicilio = `${result.calle}, ${result.exterior}, ${result.interior}, ${result.colonia}, ${result.localidad}, ${result.municipio}, ${result.estado}, ${result.pais}, ${result.CP}, ${result.referencia}`;
|
|
|
+ this.form2.get('domicilioFactura')?.setValue(domicilio.trim());
|
|
|
}
|
|
|
+ });
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
@Component({
|
|
|
selector: 'App-Asistente',
|
|
|
@@ -1441,8 +1589,5 @@ export class Asistente {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-// 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
|
|
|
+//requiere una factura en un radio button se pone la opcion "si" cuando es asi se habilitan los cmapos para llenar, pero el prblema es que cuando se vargan las respuestas para editar neceisot poner "no" y despues "si" para que se cargue la infromacion del asistente de domicilio de factura
|
|
|
+//para que cargue la respuesta en caso de que cuente con una
|