Integracion Toku a flujo

This commit is contained in:
Juan Pablo Vial
2025-05-10 12:39:31 -04:00
parent fb7177fd65
commit 4ca1616dfc
5 changed files with 67 additions and 15 deletions

View File

@ -6,6 +6,7 @@ use Psr\Http\Message\ServerRequestInterface;
use DateTimeImmutable;
use Incoviba\Common\Alias\View;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Create;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
@ -84,13 +85,15 @@ class Cuotas
return $view->render($response, 'ventas.pies.cuotas.add', compact('pie', 'venta', 'bancos'));
}
public function doAdd(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService,
Repository\Venta $ventaRepository, Service\Valor $valorService, int $pie_id): ResponseInterface
Repository\Venta $ventaRepository, Service\Valor $valorService,
Service\Queue $queueService, int $pie_id): ResponseInterface
{
$body = $request->getParsedBody();
$pie = $pieService->getById($pie_id);
$venta = $ventaRepository->fetchByPie($pie_id);
$start = count($pie->cuotas(vigentes: true));
$total = $pie->cuotas;
$cuotas = [];
for ($i = $start; $i < $total; $i ++) {
if ($body["banco{$i}"] === '') {
continue;
@ -103,7 +106,17 @@ class Cuotas
'valor' => $valorService->clean(str_replace('.', '', $body["valor{$i}"])),
'numero' => $i + 1,
];
$pieService->addCuota($data);
try {
$cuotas []= $pieService->addCuota($data)->id;
} catch (Create) {}
}
if (count($cuotas) > 0) {
$data = [
'type' => 'request',
'action' => "/api/external/toku/cuotas/{$venta->id}",
'body' => compact('cuotas')
];
$queueService->enqueue($data);
}
return $response->withHeader('Location', "/venta/{$venta->id}");
}