FIX: Cuotas se agregan sin UF, desface en la tabla
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user