FIX: Fecha terreno #10
@ -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);
|
||||
|
@ -53,4 +53,13 @@ class Nubox extends Ideal\Repository
|
||||
{
|
||||
return 'inmobiliaria_rut';
|
||||
}
|
||||
protected function getIndex(Define\Model $model): mixed
|
||||
{
|
||||
return $model->inmobiliaria->rut;
|
||||
}
|
||||
protected function setIndex(Define\Model &$model, mixed $value): Ideal\Repository
|
||||
{
|
||||
$model->inmobiliaria = $this->inmobiliariaRepository->fetchById($value);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -52,4 +52,9 @@ class Prorrateo extends Ideal\Repository
|
||||
{
|
||||
return array_intersect_key($data, array_flip(['prorrateo']));
|
||||
}
|
||||
|
||||
protected function getIndex(Define\Model $model): mixed
|
||||
{
|
||||
return $model->unidad->id;
|
||||
}
|
||||
}
|
||||
|
@ -31,12 +31,13 @@ class Terreno extends Ideal\Service
|
||||
try {
|
||||
$proyecto = $this->proyectoRepository->fetchById($proyecto_id);
|
||||
$today = new DateTimeImmutable();
|
||||
$lastDecember = (new DateTimeImmutable($today->format('Y-01-31')))->sub(new DateInterval('P1M'));
|
||||
if ($proyecto->terreno->fecha >= $lastDecember) {
|
||||
$lastNovember = (new DateTimeImmutable($today->format('Y-01-30')))->sub(new DateInterval('P2M'));
|
||||
if ($proyecto->terreno->fecha >= $lastNovember) {
|
||||
return $proyecto->terreno;
|
||||
}
|
||||
try {
|
||||
return $this->getValorContable($proyecto, $lastDecember->add(new DateInterval('P1D')));
|
||||
// Valor 1o Enero
|
||||
return $this->getValorContable($proyecto, $lastNovember->add(new DateInterval('P1M'))->add(new DateInterval('P1D')));
|
||||
} catch (Implement\Exception\EmptyResponse) {}
|
||||
if ($proyecto->terreno->fecha === null) {
|
||||
return null;
|
||||
@ -83,7 +84,7 @@ class Terreno extends Ideal\Service
|
||||
$novLast = new DateTimeImmutable($lastDecember->format('Y-11-1'));
|
||||
$ipc = $this->ipcService->get($novPrevTerreno, $novLast);
|
||||
$terreno = $proyecto->terreno;
|
||||
$terreno->fecha = $lastDecember;
|
||||
$terreno->fecha = $novLast;
|
||||
$terreno->valor *= (1 + $ipc);
|
||||
return $terreno;
|
||||
}
|
||||
|
Reference in New Issue
Block a user