Facturacion

This commit is contained in:
Juan Pablo Vial
2024-04-19 23:19:35 -04:00
parent 9388dc17fc
commit d2511901ec
7 changed files with 126 additions and 43 deletions

View File

@ -9,9 +9,12 @@ use Incoviba\Service;
class Facturacion
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Proyecto $proyectoService): ResponseInterface
Service\Proyecto $proyectoService, Service\Proyecto\Terreno $terrenoService): ResponseInterface
{
$proyectos = $proyectoService->getEscriturando();
foreach ($proyectos as &$proyecto) {
$proyecto->terreno = $terrenoService->valor($proyecto->id) ?? $proyecto->terreno;
}
return $view->render($response, 'ventas.facturacion', compact('proyectos'));
}
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,

View File

@ -171,7 +171,7 @@ class Venta extends Ideal\Repository
->joined('JOIN proyecto_tipo_unidad ptu ON ptu.id = unidad.pt')
->joined('JOIN (SELECT ev1.* FROM estado_venta ev1 JOIN (SELECT MAX(id) AS id, venta FROM estado_venta GROUP BY venta) ev0 ON ev0.id = ev1.id) ev ON ev.venta = a.id')
->joined('JOIN tipo_estado_venta tev ON tev.id = ev.estado')
->where('ptu.proyecto = ? AND tev.activa')
->where('ptu.proyecto = ? AND tev.activa = 1')
->group('a.id');
return $this->fetchIds($query, [$proyecto_id]);
}
@ -185,7 +185,7 @@ class Venta extends Ideal\Repository
->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
->joined("JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`")
->joined('JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`')
->where('ptu.`proyecto` = ? AND tev.`activa`')
->where('ptu.`proyecto` = ? AND tev.`activa` = 1')
->group('a.id');
return $this->fetchMany($query, [$proyecto_id]);
}

View File

@ -31,8 +31,11 @@ class Terreno extends Ideal\Service
try {
return $this->getValorContable($proyecto, $lastDecember);
} catch (Implement\Exception\EmptyResponse) {}
if ($proyecto->terreno->fecha === null) {
return null;
}
if ($proyecto->terreno->fecha->getTimestamp() > 0) {
return $this->getValorReajustado($proyecto, $lastDecember);
return $this->getValorReajustado($proyecto);
}
$terreno = $proyecto->terreno;
} catch (Implement\Exception\EmptyResult) {}

View File

@ -46,6 +46,10 @@ class Venta extends Service
$ventas = $this->ventaRepository->fetchActivaByProyecto($proyecto_id);
return array_map([$this, 'process'], $ventas);
}
public function getIdsByProyecto(int $proyecto_id): array
{
return $this->ventaRepository->fetchIdsByProyecto($proyecto_id);
}
public function getByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta
{
$venta = $this->ventaRepository->fetchByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);