FIX: Editar cuotas
This commit is contained in:
@ -42,7 +42,12 @@ class Cuotas extends Ideal\Controller
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Abono\Cuota $cuotaRepository, int $cuota_id): ResponseInterface
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Pago $pagoService,
|
||||
Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
Service\UF $ufService,
|
||||
Service\Valor $valorService,
|
||||
Repository\Venta\Abono\Cuota $cuotaRepository, int $cuota_id): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
@ -52,7 +57,21 @@ class Cuotas extends Ideal\Controller
|
||||
];
|
||||
try {
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['cuota'] = $cuotaRepository->edit($cuota, $input);
|
||||
$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']);
|
||||
}
|
||||
$pagoData = array_intersect_key($input, array_flip(['fecha', 'valor']));
|
||||
$pago = $pagoService->edit($cuota->pago, $pagoData);
|
||||
if ($input['tipo_estado_id'] !== $pago->currentEstado->tipoEstadoPago->id) {
|
||||
$estadoData = array_intersect_key($input, array_flip(['fecha']));
|
||||
$estadoData['pago'] = $cuota->pago->id;
|
||||
$estadoData['estado'] = $input['tipo_estado_id'];
|
||||
$estado = $estadoPagoRepository->create($estadoData);
|
||||
$estadoPagoRepository->save($estado);
|
||||
}
|
||||
$output['cuota'] = $cuota;
|
||||
$output['success'] = true;
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
|
Reference in New Issue
Block a user