2025-10-22 19:28:40 -06:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2025-10-29 17:16:27 -06:00
|
|
|
import { AlumnoService } from 'src/modules/AT/alumno/student.service';
|
|
|
|
|
import { AlumnoInscritoService } from 'src/modules/AT/alumno_inscrito/alumno_inscrito.service';
|
2025-11-03 19:26:45 -06:00
|
|
|
import { PeriodoService } from 'src/modules/AT/periodo/periodo.service';
|
2025-10-23 08:35:55 -06:00
|
|
|
import { PagoKioscoService } from 'src/modules/Monedero/pago-kiosco/pago-kiosco.service';
|
|
|
|
|
import { PersonaService } from 'src/modules/Monedero/persona/persona.service';
|
|
|
|
|
import { TransaccionService } from 'src/modules/Monedero/transaccion/transaccion.service';
|
2025-11-03 19:26:45 -06:00
|
|
|
import { abonoKioscoDto } from './dto/create-operation.dto';
|
2025-10-20 14:13:16 -06:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class OperationsService {
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly transaccionService: TransaccionService,
|
|
|
|
|
private readonly pagoKioscoService: PagoKioscoService,
|
|
|
|
|
private readonly personaService: PersonaService,
|
2025-10-29 17:16:27 -06:00
|
|
|
private readonly alumnoInscritoServie: AlumnoInscritoService,
|
|
|
|
|
private readonly alumnoService: AlumnoService,
|
2025-11-03 19:26:45 -06:00
|
|
|
private readonly periodoService: PeriodoService,
|
2025-10-20 14:13:16 -06:00
|
|
|
) {}
|
|
|
|
|
|
2025-11-03 19:26:45 -06:00
|
|
|
async depositKiosco(abono: abonoKioscoDto, idPersona: number) {
|
|
|
|
|
const { cantidad, idKiosco, transaccion, plataforma } = abono;
|
2025-10-20 14:13:16 -06:00
|
|
|
const today = new Date().toString();
|
|
|
|
|
|
2025-10-21 13:42:37 -06:00
|
|
|
const transaction = {
|
|
|
|
|
nombreTransaccion: transaccion,
|
2025-10-20 14:13:16 -06:00
|
|
|
idPersona,
|
|
|
|
|
fecha: today,
|
|
|
|
|
tipoTransaccion: 2,
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-21 13:42:37 -06:00
|
|
|
const responseTransaccion = this.transaccionService.create(transaction);
|
2025-10-22 16:53:41 -06:00
|
|
|
|
2025-10-20 14:13:16 -06:00
|
|
|
const pagoKiosco = {
|
|
|
|
|
idTransaccion: (await responseTransaccion).idTransaccion,
|
2025-10-20 15:46:44 -06:00
|
|
|
monto: cantidad,
|
2025-10-20 14:13:16 -06:00
|
|
|
fecha: today,
|
|
|
|
|
idKiosco,
|
|
|
|
|
pagoPatronatoCreado: false,
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-22 19:28:40 -06:00
|
|
|
this.pagoKioscoService.create(pagoKiosco);
|
2025-10-22 16:53:41 -06:00
|
|
|
|
2025-10-29 08:16:36 -06:00
|
|
|
let newSaldo: number;
|
|
|
|
|
if (transaccion === 'Inscripcion') {
|
|
|
|
|
newSaldo = await this.personaService.saldo(idPersona);
|
2025-10-29 17:16:27 -06:00
|
|
|
const persona = await this.personaService.findById(idPersona);
|
|
|
|
|
|
|
|
|
|
const alumno = await this.alumnoService.findOneById(
|
|
|
|
|
Number(persona.numeroIdentificar),
|
|
|
|
|
);
|
2025-11-03 19:26:45 -06:00
|
|
|
|
|
|
|
|
const periodo = await this.periodoService.getLatestPeriodo();
|
|
|
|
|
|
|
|
|
|
await this.alumnoInscritoServie.create({
|
|
|
|
|
id_cuenta: alumno.id_cuenta,
|
|
|
|
|
id_periodo: periodo.id_periodo,
|
|
|
|
|
id_plataforma: plataforma,
|
|
|
|
|
});
|
2025-10-29 08:16:36 -06:00
|
|
|
} else {
|
|
|
|
|
newSaldo = await this.personaService.updateSaldo(idPersona, cantidad);
|
|
|
|
|
}
|
2025-10-22 15:00:05 -06:00
|
|
|
|
2025-10-20 14:13:16 -06:00
|
|
|
return newSaldo;
|
|
|
|
|
}
|
|
|
|
|
}
|