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, Service\Venta $ventaService, Service\Proyecto\Terreno $terrenoService, Service\IPC $ipcService, Service\UF $ufService, int $venta_id): ResponseInterface { $venta = $ventaService->getById($venta_id); $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->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')); } }