Files
oficial/app/src/Controller/Ventas/Facturacion.php

46 lines
2.1 KiB
PHP
Raw Normal View History

2023-11-22 19:08:19 -03:00
<?php
namespace Incoviba\Controller\Ventas;
2024-04-28 23:01:55 -04:00
use DateInterval;
use DateTimeImmutable;
2023-11-22 19:08:19 -03:00
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Alias\View;
use Incoviba\Service;
class Facturacion
{
2024-04-15 20:13:15 -04:00
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
2024-04-19 23:19:35 -04:00
Service\Proyecto $proyectoService, Service\Proyecto\Terreno $terrenoService): ResponseInterface
2023-11-22 19:08:19 -03:00
{
$proyectos = $proyectoService->getEscriturando();
2024-04-19 23:19:35 -04:00
foreach ($proyectos as &$proyecto) {
$proyecto->terreno = $terrenoService->valor($proyecto->id) ?? $proyecto->terreno;
}
2023-11-22 19:08:19 -03:00
return $view->render($response, 'ventas.facturacion', compact('proyectos'));
}
2024-04-15 20:13:15 -04:00
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta $ventaService, Service\Proyecto\Terreno $terrenoService,
2024-04-28 23:01:55 -04:00
Service\IPC $ipcService, Service\UF $ufService,
2024-04-15 20:13:15 -04:00
int $venta_id): ResponseInterface
2023-11-22 19:08:19 -03:00
{
$venta = $ventaService->getById($venta_id);
2024-04-28 23:01:55 -04:00
$uf = $ufService->get($venta->currentEstado()->fecha);
2024-04-15 20:13:15 -04:00
$terreno = $terrenoService->valor($venta->proyecto()->id);
2024-04-28 23:01:55 -04:00
$lastNov = new DateTimeImmutable((new DateTimeImmutable())->sub(new DateInterval('P1Y'))->format('Y-11-1'));
$prevMonth = $venta->fecha->sub(new DateInterval('P1M'));
if ($prevMonth->format('m') === $venta->fecha->format('m')) {
$prevMonth = $prevMonth->sub(new DateInterval('P10D'));
}
$ipc = $ipcService->get($lastNov, $prevMonth);
if ($terreno !== null) {
$prevMonthTerreno = $terreno->fecha->sub(new DateInterval('P1M'));
if ($prevMonthTerreno->format('m') === $terreno->fecha->format('m')) {
$prevMonthTerreno = $prevMonthTerreno->sub(new DateInterval('P10D'));
}
$ipc = $ipcService->get($prevMonthTerreno, $prevMonth);
}
return $view->render($response, 'ventas.facturacion.show', compact('venta', 'terreno', 'uf', 'ipc'));
2023-11-22 19:08:19 -03:00
}
}