Merge branch 'develop'

This commit is contained in:
2022-03-08 09:02:22 -03:00

View File

@ -52,13 +52,13 @@ class Resumen
{ {
return new DateTimeImmutable((clone $up_to)->sub(new DateInterval('P1Y'))->format('31-12-Y')); 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) protected function getAnticipos(Venta $venta, DateTimeInterface $up_to)
{ {
@ -68,7 +68,7 @@ class Resumen
$cuotas = $venta->pie()->cuotas('fecha', $up_to); $cuotas = $venta->pie()->cuotas('fecha', $up_to);
$ly = $this->startOfYear($up_to); $ly = $this->startOfYear($up_to);
$older = array_reduce($cuotas, function($sum, $item) use ($ly) { $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; return $sum;
} }
if ($item->pago()->fecha() >= $ly) { if ($item->pago()->fecha() >= $ly) {
@ -80,44 +80,44 @@ class Resumen
return $item->pago()->fecha() >= $ly; return $item->pago()->fecha() >= $ly;
}); });
foreach ($current as &$item) { 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) protected function getReajuste(Venta $venta, DateTimeInterface $up_to)
{ {
if ($venta->pie == 0 or $venta->pie()->reajuste == null) { 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) protected function getAbono(Venta $venta, DateTimeInterface $up_to)
{ {
if ($venta->escritura == 0) { 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) protected function getBono(Venta $venta, DateTimeInterface $up_to)
{ {
if ($venta->bono_pie == 0) { 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) protected function getCredito(Venta $venta, DateTimeInterface $up_to)
{ {
if ($venta->credito == 0) { 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) protected function getSubsidio(Venta $venta, DateTimeInterface $up_to)
{ {
if ($venta->subsidio == 0) { 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) protected function getPagos(Venta $venta, DateTimeInterface $up_to)
{ {
@ -136,20 +136,23 @@ class Resumen
protected function buildLibro(Venta $venta, DateTimeInterface $up_to) protected function buildLibro(Venta $venta, DateTimeInterface $up_to)
{ {
$pagos = $this->getPagos($venta, $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; $debe = 0;
$haber = 0; $haber = 0;
foreach ($pagos as $pago) { foreach ($pagos as $pago) {
if ($pago->valor > 0) { 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; $debe += $pago->valor;
} }
else { 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; $haber -= $pago->valor;
} }
} }
$output []= ['', '', $haber, $debe]; $output []= ['', '', 'Total', $haber, $debe];
return $output; return $output;
} }