2023-09-12
This commit is contained in:
@ -8,6 +8,7 @@ use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Cuotas
|
||||
{
|
||||
@ -72,4 +73,34 @@ class Cuotas
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService, Repository\Venta $ventaRepository, Repository\Banco $bancoRepository, View $view, int $pie_id): ResponseInterface
|
||||
{
|
||||
$pie = $pieService->getById($pie_id);
|
||||
$venta = $ventaRepository->fetchByPie($pie_id);
|
||||
$bancos = $bancoRepository->fetchAll();
|
||||
usort($bancos, function(Model\Banco $a, Model\Banco $b) {
|
||||
return strcmp($a->nombre, $b->nombre);
|
||||
});
|
||||
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, int $pie_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$pie = $pieService->getById($pie_id);
|
||||
$venta = $ventaRepository->fetchByPie($pie_id);
|
||||
$total = $pie->cuotas - count($pie->cuotas());
|
||||
$start = count($pie->cuotas());
|
||||
for ($i = $start; $i < $total; $i ++) {
|
||||
$data = [
|
||||
'pie' => $pie->id,
|
||||
'fecha' => $body["fecha{$i}"],
|
||||
'banco' => $body["banco{$i}"],
|
||||
'identificador' => $body["identificador{$i}"],
|
||||
'valor' => str_replace(['.', ','], ['', ''], $body["valor{$i}"]),
|
||||
'numero' => $i + 1,
|
||||
];
|
||||
$pieService->addCuota($data);
|
||||
}
|
||||
return $response->withHeader('Location', "/venta/{$venta->id}");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user