diff --git a/app/Service/Informe/Contabilidad/Resumen.php b/app/Service/Informe/Contabilidad/Resumen.php index 66f9e10..e13a7f8 100644 --- a/app/Service/Informe/Contabilidad/Resumen.php +++ b/app/Service/Informe/Contabilidad/Resumen.php @@ -52,13 +52,13 @@ class Resumen { return new DateTimeImmutable((clone $up_to)->sub(new DateInterval('P1Y'))->format('31-12-Y')); } - protected function defaultValueDate(DateTimeInterface $up_to) + protected function defaultValueDate(DateTimeInterface $up_to, $glosa = '') { - return (object) ['fecha' => $this->startOfYear($up_to), 'valor' => 0]; + return (object) ['fecha' => $this->startOfYear($up_to), 'valor' => 0, 'glosa' => $glosa, 'estado' => '']; } - protected function extractValueDate(Pago $pago) + protected function extractValueDate(Pago $pago, $glosa = '') { - return (object) ['fecha' => $pago->fecha(), 'valor' => $pago->valor]; + return (object) ['fecha' => $pago->fecha(), 'valor' => $pago->valor, 'glosa' => $glosa, 'estado' => $pago->estado()->tipo()->descripcion]; } protected function getAnticipos(Venta $venta, DateTimeInterface $up_to) { @@ -68,7 +68,7 @@ class Resumen $cuotas = $venta->pie()->cuotas('fecha', $up_to); $ly = $this->startOfYear($up_to); $older = array_reduce($cuotas, function($sum, $item) use ($ly) { - if ($item->pago()->estado()->tipo()->active != 1) { + if ($item->pago()->estado()->tipo()->active != 1 || strtolower($item->pago()->estado()->tipo()->descripcion) != 'no pagado') { return $sum; } if ($item->pago()->fecha() >= $ly) { @@ -80,44 +80,44 @@ class Resumen return $item->pago()->fecha() >= $ly; }); foreach ($current as &$item) { - $item = $this->extractValueDate($item->pago()); + $item = $this->extractValueDate($item->pago(), "Cuota {$item->numero}"); } - return array_merge([(object) ['fecha' => $ly, 'valor' => $older]], $current); + return array_merge([(object) ['fecha' => $ly, 'valor' => $older, 'glosa' => 'Anticipo acumulado', 'estado' => 'Pagado']], $current); } protected function getReajuste(Venta $venta, DateTimeInterface $up_to) { if ($venta->pie == 0 or $venta->pie()->reajuste == null) { - return $this->defaultValueDate($up_to); + return $this->defaultValueDate($up_to, 'Reajuste'); } - return $this->extractValueDate($venta->pie()->reajuste()); + return $this->extractValueDate($venta->pie()->reajuste(), 'Reajuste'); } protected function getAbono(Venta $venta, DateTimeInterface $up_to) { if ($venta->escritura == 0) { - return $this->defaultValueDate($up_to); + return $this->defaultValueDate($up_to, 'Abono'); } - return $this->extractValueDate($venta->escritura()->pago()); + return $this->extractValueDate($venta->escritura()->pago(), 'Abono'); } protected function getBono(Venta $venta, DateTimeInterface $up_to) { if ($venta->bono_pie == 0) { - return $this->defaultValueDate($up_to); + return $this->defaultValueDate($up_to, 'Bono Pie'); } - return $this->extractValueDate($venta->bonoPie()->pago()); + return $this->extractValueDate($venta->bonoPie()->pago(), 'Bono Pie'); } protected function getCredito(Venta $venta, DateTimeInterface $up_to) { if ($venta->credito == 0) { - return [$this->defaultValueDate($up_to), $this->defaultValueDate($up_to)]; + return $this->defaultValueDate($up_to, 'Credito'); } - return $this->extractValueDate($venta->credito()->pago()); + return $this->extractValueDate($venta->credito()->pago(), 'Credito'); } protected function getSubsidio(Venta $venta, DateTimeInterface $up_to) { if ($venta->subsidio == 0) { - return [$this->defaultValueDate($up_to), $this->defaultValueDate($up_to)]; + return [$this->defaultValueDate($up_to, 'Ahorro'), $this->defaultValueDate($up_to, 'Subsidio')]; } - return [$this->extractValueDate($venta->subsidio()->pago()), $this->extractValueDate($venta->subsidio()->subsidio())]; + return [$this->extractValueDate($venta->subsidio()->pago(), 'Ahorro'), $this->extractValueDate($venta->subsidio()->subsidio(), 'Subsidio')]; } protected function getPagos(Venta $venta, DateTimeInterface $up_to) { @@ -136,20 +136,23 @@ class Resumen protected function buildLibro(Venta $venta, DateTimeInterface $up_to) { $pagos = $this->getPagos($venta, $up_to); - $output = ['', "Cuenta: Anticipos Dpto {$venta->unidad()->descripcion}"]; + $output = [ + ['', "Cuenta: Anticipos Dpto {$venta->unidad()->descripcion}"], + ['', 'Fecha', 'Glosa', 'Haber', 'Debe', 'Estado'] + ]; $debe = 0; $haber = 0; foreach ($pagos as $pago) { if ($pago->valor > 0) { - $output []= ['', $pago->fecha->format('d/m/Y'), '', $pago->valor]; + $output []= ['', $pago->fecha->format('d/m/Y'), $pago->glosa, '', $pago->valor, $pago->estado]; $debe += $pago->valor; } else { - $output []= ['', $pago->fecha->format('d/m/Y'), -$pago->valor, '']; + $output []= ['', $pago->fecha->format('d/m/Y'), $pago->glosa, -$pago->valor, '', $pago->estado]; $haber -= $pago->valor; } } - $output []= ['', '', $haber, $debe]; + $output []= ['', '', 'Total', $haber, $debe]; return $output; }