From 5fefdd94b0ef4827cc5955f6a869143a851eadad Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 7 Mar 2022 21:20:27 -0300 Subject: [PATCH] Fixes to format and defaults --- app/Service/Informe/Contabilidad/Resumen.php | 31 ++++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/app/Service/Informe/Contabilidad/Resumen.php b/app/Service/Informe/Contabilidad/Resumen.php index cad97df..bddba58 100644 --- a/app/Service/Informe/Contabilidad/Resumen.php +++ b/app/Service/Informe/Contabilidad/Resumen.php @@ -33,7 +33,7 @@ class Resumen } protected function startOfYear(DateTimeInterface $up_to) { - return new DateTimeImmutable(DateTimeImmutable::createFromInterface($up_to)->format('1-1-Y')); + return new DateTimeImmutable((clone $up_to)->sub('P1Y')->format('31-12-Y')); } protected function defaultValueDate(DateTimeInterface $up_to) { @@ -45,6 +45,9 @@ class Resumen } protected function getAnticipos(Venta $venta, DateTimeInterface $up_to) { + if ($venta->pie == 0) { + return [$this->defaultValueDate($up_to)]; + } $cuotas = $venta->pie()->cuotas('fecha', $up_to); $ly = $this->startOfYear($up_to); $older = array_reduce($cuotas, function($sum, $item) use ($ly) { @@ -56,42 +59,45 @@ class Resumen } return $sum + $item->pago()->valor; }); - $current = array_map([$this, 'extractValueDate'], array_filter($cuotas, function($item) use ($ly) { + $current = array_filter($cuotas, function($item) use ($ly) { return $item->pago()->fecha() >= $ly; - })); + }); + foreach ($current as &$item) { + $item = $this->extractValueDate($item->pago()); + } return array_merge([(object) ['fecha' => $ly, 'valor' => $older]], $current); } protected function getReajuste(Venta $venta, DateTimeInterface $up_to) { - if ($venta->pie()->reajuste == null) { + if ($venta->pie == 0 or $venta->pie()->reajuste == null) { return $this->defaultValueDate($up_to); } return $this->extractValueDate($venta->pie()->reajuste()); } protected function getAbono(Venta $venta, DateTimeInterface $up_to) { - if ($venta->escritura == null) { + if ($venta->escritura == 0) { return $this->defaultValueDate($up_to); } return $this->extractValueDate($venta->escritura()->pago()); } protected function getBono(Venta $venta, DateTimeInterface $up_to) { - if ($venta->bono_pie == null) { + if ($venta->bono_pie == 0) { return $this->defaultValueDate($up_to); } return $this->extractValueDate($venta->bonoPie()->pago()); } protected function getCredito(Venta $venta, DateTimeInterface $up_to) { - if ($venta->credito == null) { - return $this->defaultValueDate($up_to); + if ($venta->credito == 0) { + return [$this->defaultValueDate($up_to), $this->defaultValueDate($up_to)]; } return $this->extractValueDate($venta->credito()->pago()); } protected function getSubsidio(Venta $venta, DateTimeInterface $up_to) { - if ($venta->subsidio == null) { + if ($venta->subsidio == 0) { return $this->defaultValueDate($up_to); } return [$this->extractValueDate($venta->subsidio()->pago()), $this->extractValueDate($venta->subsidio()->subsidio())]; @@ -122,15 +128,15 @@ class Resumen $haber = 0; foreach ($pagos as $pago) { if ($pago->valor > 0) { - $output []= implode($this->separator, [$pago->fecha->format('d/m/Y'), $this->formatValue($pago->valor), '']); + $output []= implode($this->separator, [$pago->fecha->format('d/m/Y'), '', $this->formatValue($pago->valor)]); $debe += $pago->valor; } else { - $output []= implode($this->separator, [$pago->fecha->format('d/m/Y'), '', $this->formatValue(-$pago->valor)]); + $output []= implode($this->separator, [$pago->fecha->format('d/m/Y'), $this->formatValue(-$pago->valor), '']); $haber -= $pago->valor; } } - $output []= implode($this->separator, ['', $debe, $haber]); + $output []= implode($this->separator, ['', $haber, $debe]); return $output; } @@ -138,7 +144,6 @@ class Resumen { $ventas = $this->getVentas($id_proyecto); - $output = []; foreach ($ventas as $venta) { $output = array_merge($output, $this->buildLibro($venta, $up_to), []);