FIX: Fecha terreno

This commit is contained in:
Juan Pablo Vial
2025-01-16 19:30:11 -03:00
parent 44ea8acd39
commit 3262ef9a62
4 changed files with 24 additions and 11 deletions

View File

@ -35,18 +35,16 @@ class Facturacion extends Ideal\Controller
$uf = $ufService->get($venta->currentEstado()->fecha);
$terreno = $terrenoService->valor($venta->proyecto()->id);
$lastNov = new DateTimeImmutable((new DateTimeImmutable())->sub(new DateInterval('P1Y'))->format('Y-11-1'));
$prevMonth = $venta->currentEstado()->fecha->sub(new DateInterval('P2M'));
$prevMonth = $venta->currentEstado()->fecha->sub(new DateInterval('P1M'));
if ($prevMonth->format('m') === $venta->currentEstado()->fecha->format('m')) {
// If sub P1M stays in same month
$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'));
}
if ($prevMonthTerreno->format('Y-m') !== $lastNov->format('Y-m')) {
$ipc = $ipcService->get($prevMonthTerreno, $prevMonth);
$monthTerreno = $terreno->fecha;
if ($monthTerreno->format('Y-m') !== $lastNov->format('Y-m')) {
$ipc = $ipcService->get($monthTerreno, $prevMonth);
}
}
$facturas = $facturasService->getByVenta($venta->id);