FIX: Cuotas se agregan sin UF, desface en la tabla

This commit is contained in:
Juan Pablo Vial
2024-11-29 14:22:05 -03:00
parent 02fc372610
commit 39da754d8b
2 changed files with 9 additions and 5 deletions

View File

@ -18,6 +18,7 @@ class Cuotas extends Ideal\Controller
Service\Venta\Pago $pagoService,
Service\UF $ufService,
Service\Valor $valorService,
Repository\Venta $ventaRepository,
Repository\Venta\Abono\Cuota $cuotaRepository): ResponseInterface
{
$input = $request->getParsedBody();
@ -27,12 +28,15 @@ class Cuotas extends Ideal\Controller
'success' => false,
];
try {
$venta = $ventaRepository->fetchById($input['venta_id']);
$input['valor'] = $valorService->clean($input['valor']);
if (isset($input['uf']) and !empty($input['uf'])) {
$uf = $ufService->get(new DateTimeImmutable($input['fecha']));
$input['valor'] = $uf * $valorService->clean($input['uf']);
$uf = $venta->uf;
$fecha = new DateTimeImmutable($input['fecha']);
if ($fecha <= new DateTimeImmutable()) {
$uf = $ufService->get($fecha);
}
$pagoData = array_intersect_key($input, array_flip(['fecha', 'valor']));
$input['uf'] = $uf;
$pagoData = array_intersect_key($input, array_flip(['fecha', 'valor', 'uf']));
$pago = $pagoService->add($pagoData);
$cuotaData = array_intersect_key($input, array_flip(['venta_id', 'numero']));
$cuotaData['pago_id'] = $pago->id;