diff --git a/app/resources/views/ventas/escrituras/abono/cuotas.blade.php b/app/resources/views/ventas/escrituras/abono/cuotas.blade.php index bd45901..80fdc24 100644 --- a/app/resources/views/ventas/escrituras/abono/cuotas.blade.php +++ b/app/resources/views/ventas/escrituras/abono/cuotas.blade.php @@ -31,7 +31,7 @@ {{$format->pesos($cuota->pago->valor)}} {{$format->ufs($cuota->pago->valor())}} pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' ? ' positive' : '')}}" data-value="{{$cuota->pago->currentEstado->tipoEstadoPago->id}}"> {{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}} @if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['abonado', 'depositado'])) diff --git a/app/src/Controller/API/Ventas/Abonos/Cuotas.php b/app/src/Controller/API/Ventas/Abonos/Cuotas.php index 180898b..ca5379e 100644 --- a/app/src/Controller/API/Ventas/Abonos/Cuotas.php +++ b/app/src/Controller/API/Ventas/Abonos/Cuotas.php @@ -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;