FIX: Editar cuotas

This commit is contained in:
Juan Pablo Vial
2024-11-28 19:14:14 -03:00
parent 52de72b507
commit 8028b673fb
6 changed files with 130 additions and 38 deletions

View File

@ -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);

View File

@ -100,12 +100,13 @@ class Pagos
'pago_id' => $pago_id,
'input' => $body,
'pago' => null,
'depositado' => false
'depositado' => false,
'success' => false
];
try {
$pago = $pagoService->getById($pago_id);
$fecha = new DateTimeImmutable($body['fecha']);
$output['depositado'] = $pagoService->depositar($pago, $fecha);
$output['depositado'] = $output['success'] = $pagoService->depositar($pago, $fecha);
$output['pago'] = json_decode(json_encode($pagoService->getById($pago_id)), JSON_OBJECT_AS_ARRAY);
$output['pago']['valor_uf'] = $formatService->ufs($output['pago']['valor_uf']);
} catch (EmptyResult) {}
@ -129,12 +130,13 @@ class Pagos
'pago_id' => $pago_id,
'input' => $body,
'pago' => null,
'abonado' => false
'abonado' => false,
'success' => false,
];
try {
$pago = $pagoService->getById($pago_id);
$fecha = new DateTimeImmutable($body['fecha']);
$output['abonado'] = $pagoService->abonar($pago, $fecha);
$output['abonado'] = $output['success'] = $pagoService->abonar($pago, $fecha);
$output['pago'] = json_decode(json_encode($pagoService->getById($pago_id)), JSON_OBJECT_AS_ARRAY);
$output['pago']['valor_uf'] = $formatService->ufs($output['pago']['valor_uf']);
$output['input']['fecha'] = $fecha->format('d-m-Y');