|
|
@@ -1134,68 +1134,74 @@ cargarFormulario() {
|
|
|
this._registroAdministrativo.getOneRegistroAdmin(this.id).subscribe({
|
|
|
next: (data: any) => {
|
|
|
this.isLoading = false;
|
|
|
- this.datos = data.registro[0];
|
|
|
|
|
|
- if (this.datos != undefined) {
|
|
|
- this.form.get('gradoCursar')?.setValue(this.datos.RegA_GradoCursar);
|
|
|
+ // Protege el acceso a data.registro
|
|
|
+ this.datos = data.registro && data.registro.length > 0 ? data.registro[0] : null;
|
|
|
|
|
|
+if (!this.datos) {
|
|
|
+ this.isLoading = false;
|
|
|
+ Swal.fire('Aviso', 'No se encontraron datos para este registro', 'info');
|
|
|
+ return;
|
|
|
+}
|
|
|
+ if (this.datos) {
|
|
|
+ // Cargar campos principales
|
|
|
+ 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 || '');
|
|
|
+
|
|
|
+ // Método de pago
|
|
|
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.form2.get('metedoPago')?.setValue(match ? match.idMetodoPago : '');
|
|
|
}
|
|
|
|
|
|
- this.form.get('mesInscripcion')?.setValue(this.datos.RegA_MesInscripcion);
|
|
|
- this.form.get('planPago')?.setValue(this.datos.RegA_PlanPagos);
|
|
|
-
|
|
|
+ // Beca
|
|
|
const beca = (this.datos.RegA_BecaCurso || '').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);
|
|
|
+ this.form.get('becaCurso')?.setValue(
|
|
|
+ beca === 'si' || beca === 'no' ? beca.charAt(0).toUpperCase() + beca.slice(1) : ''
|
|
|
+ );
|
|
|
+ this.form.get('becaPorcentaje')?.setValue(this.datos.RegA_BecaPorcentaje || '');
|
|
|
|
|
|
- const requiereFactura = this.datos.RegA_RequiereFactura?.toLowerCase() || 'no';
|
|
|
+ // Facturación
|
|
|
+ const requiereFactura = (this.datos.RegA_RequiereFactura || 'no').toLowerCase();
|
|
|
this.form2.get('factura')?.setValue(requiereFactura);
|
|
|
|
|
|
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,
|
|
|
+ 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 === 'si') {
|
|
|
- this.form2.get('metedoPago')?.setValue(this.facturaDataOriginal.metodoPago || '', { emitEvent: false });
|
|
|
- this.form2.get('RFCFactura')?.setValue(this.facturaDataOriginal.RFC || '', { emitEvent: false });
|
|
|
- this.form2.get('razonSocial')?.setValue(this.facturaDataOriginal.razonSocial || '', { emitEvent: false });
|
|
|
- this.form2.get('correoFactura')?.setValue(this.facturaDataOriginal.correo || '', { emitEvent: false });
|
|
|
- this.form2.get('cuentaPago')?.setValue(this.facturaDataOriginal.cuenta || '', { emitEvent: false });
|
|
|
-
|
|
|
- if (this.datos.RegA_DireccionFactura && this.datos.RegA_DireccionFactura.trim() !== '') {
|
|
|
- this.form2.get('domicilioFactura')?.setValue(this.datos.RegA_DireccionFactura, { emitEvent: false });
|
|
|
+ this.form2.get('metedoPago')?.setValue(this.facturaDataOriginal.metodoPago, { emitEvent: false });
|
|
|
+ this.form2.get('RFCFactura')?.setValue(this.facturaDataOriginal.RFC, { emitEvent: false });
|
|
|
+ this.form2.get('razonSocial')?.setValue(this.facturaDataOriginal.razonSocial, { emitEvent: false });
|
|
|
+ this.form2.get('correoFactura')?.setValue(this.facturaDataOriginal.correo, { emitEvent: false });
|
|
|
+ this.form2.get('cuentaPago')?.setValue(this.facturaDataOriginal.cuenta, { emitEvent: false });
|
|
|
+
|
|
|
+ if (this.facturaDataOriginal.domicilio.trim() !== '') {
|
|
|
+ this.form2.get('domicilioFactura')?.setValue(this.facturaDataOriginal.domicilio, { emitEvent: false });
|
|
|
} 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, { emitEvent: false });
|
|
|
+ if (this.facturaDataOriginal.archivo.trim() !== '') {
|
|
|
+ this.rutaArchivo = this.facturaDataOriginal.archivo;
|
|
|
+ this.rutaArchivoOriginal = this.facturaDataOriginal.archivo;
|
|
|
+ this.form2.get('constanciaFiscal')?.setValue(this.facturaDataOriginal.archivo, { emitEvent: false });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this.factura({ value: requiereFactura });
|
|
|
this.cdr.detectChanges();
|
|
|
+ } else {
|
|
|
+ console.warn('No se encontraron datos para este registro');
|
|
|
+ Swal.fire('Aviso', 'No se encontraron datos para este registro', 'info');
|
|
|
}
|
|
|
},
|
|
|
error: (err) => {
|
|
|
@@ -1204,11 +1210,9 @@ cargarFormulario() {
|
|
|
Swal.fire('Error', 'No se pudo cargar el formulario', 'error');
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+
|
|
|
factura(event: any) {
|
|
|
const requiereFactura = event.value;
|
|
|
|