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

@ -31,7 +31,7 @@
<td class="valor right aligned" data-value="{{$cuota->pago->valor}}">{{$format->pesos($cuota->pago->valor)}}</td>
<td class="valor_uf right aligned" data-value="{{$cuota->pago->valor()}}">{{$format->ufs($cuota->pago->valor())}}</td>
<td class="estado{{$cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado' ? ' warning' :
($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' ? ' positive' : '')}}" rowspan="2"
($cuota->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']))

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;