2023-09-12

This commit is contained in:
Juan Pablo Vial
2023-09-13 18:51:46 -03:00
parent fa15da1ee2
commit 0cd357b6cb
47 changed files with 1225 additions and 102 deletions

View File

@ -29,7 +29,7 @@ class Proyectos
{
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
try {
$unidades = $unidadRepository->fetchByProyecto($proyecto_id);
$unidades = $unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
$tipos = [];
foreach ($unidades as $unidad) {
if (!isset($tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion])) {

View File

@ -111,4 +111,25 @@ class Ventas
$proyectos = $proyectoRepository->fetchAllActive();
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
}
public function doAdd(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService): ResponseInterface
{
$data = $request->getParsedBody();
$output = [
'status' => false,
'errors' => []
];
try {
$ventaService->add($data);
$output['status'] = true;
} catch (\Exception $exception) {
$output['errors'] = $exception;
}
$response->getBody()->write(json_encode($output));
return $response->withHeader('Content-Type', 'application/json');
}
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, View $view, int $venta_id): ResponseInterface
{
$venta = $ventaService->getById($venta_id);
return $view->render($response, 'ventas.pies.cuotas', compact('venta'));
}
}

View File

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

View File

@ -0,0 +1,23 @@
<?php
namespace Incoviba\Controller\Ventas;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Alias\View;
use Incoviba\Service;
use Incoviba\Repository;
use Incoviba\Model;
class Pies
{
public function cuotas(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', compact('pie', 'venta', 'bancos'));
}
}