From bc2333bc95110bc07f8955ea9153e9a51dfd9580 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Mon, 8 Jan 2024 13:16:12 -0300 Subject: [PATCH] FIX: Pie cuotas valores uf --- .../views/ventas/pies/cuotas.blade.php | 19 +++++++++---------- app/src/Model/Venta/Pago.php | 3 ++- app/src/Model/Venta/Pie.php | 2 +- app/src/Service/Venta/Pago.php | 17 +++++++++++++---- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/resources/views/ventas/pies/cuotas.blade.php b/app/resources/views/ventas/pies/cuotas.blade.php index c7794c3..a8268c3 100644 --- a/app/resources/views/ventas/pies/cuotas.blade.php +++ b/app/resources/views/ventas/pies/cuotas.blade.php @@ -26,7 +26,10 @@ Fecha Estado ISO - @php $now = new DateTimeImmutable(); @endphp + @php + $now = new DateTimeImmutable(); + $uf_venta = $venta->uf === 0.0 ? $UF->get($venta->currentEstado()->fecha) : $venta->uf; + @endphp @foreach ($venta->formaPago()->pie->cuotas() as $cuota) {{$cuota->numero}} @@ -85,16 +88,12 @@ }, 0))}} - @php - $now = new DateTimeImmutable(); - @endphp {{$format->ufs($total = array_reduce($venta->formaPago()->pie->cuotas(), - function(float $sum, Incoviba\Model\Venta\Cuota $cuota) use ($now, $venta) { - if ($cuota->pago->fecha > $now) { - return $sum + $cuota->pago->valor / $venta->uf; - } - return $sum + $cuota->pago->valor(); - }, 0))}} + function(float $sum, Incoviba\Model\Venta\Cuota $cuota) use ($now, $uf_venta) { + return $sum + (($cuota->pago->fecha > $now or $cuota->pago->uf === null) ? + $cuota->pago->valor / $uf_venta : + $cuota->pago->valor()); + }, 0.0))}} diff --git a/app/src/Model/Venta/Pago.php b/app/src/Model/Venta/Pago.php index 8beda1e..c983b22 100644 --- a/app/src/Model/Venta/Pago.php +++ b/app/src/Model/Venta/Pago.php @@ -24,7 +24,8 @@ class Pago extends Model public function valor(string $moneda = Pago::UF): float { - return $this->valor / (($moneda === Pago::UF) ? ($this->uf > 0 ? $this->uf : 1) : 1); + $uf = $this->uf ?? ($this->uf > 0.0 ? $this->uf : 1); + return $this->valor / (($moneda === Pago::UF) ? $uf : 1); } public function jsonSerialize(): mixed diff --git a/app/src/Model/Venta/Pie.php b/app/src/Model/Venta/Pie.php index 6eb4f5d..ec3f11d 100644 --- a/app/src/Model/Venta/Pie.php +++ b/app/src/Model/Venta/Pie.php @@ -25,7 +25,7 @@ class Pie extends Model } if ($pagadas) { return array_filter($this->cuotasArray, function(Cuota $cuota) { - return $cuota->pago->currentEstado->tipoEstadoPago->descripcion !== 'no pagado'; + return in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'abonado']); }); } return array_filter($this->cuotasArray, function(Cuota $cuota) { diff --git a/app/src/Service/Venta/Pago.php b/app/src/Service/Venta/Pago.php index 9509a91..b55cd26 100644 --- a/app/src/Service/Venta/Pago.php +++ b/app/src/Service/Venta/Pago.php @@ -136,14 +136,23 @@ class Pago { $pago->estados = $this->estadoPagoRepository->fetchByPago($pago->id); $pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago->id); + $pago->uf = $this->getUF($pago); + return $pago; + } + protected function getUF(Model\Venta\Pago $pago): ?float + { if (($pago->uf === null or $pago->uf === 0.0) and $pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' and $pago->currentEstado->fecha <= new DateTimeImmutable()) { - $pago->uf = $this->moneyService->getUF($pago->currentEstado->fecha); - if ($pago->uf !== 0.0) { - $this->pagoRepository->edit($pago, ['uf' => $pago->uf]); + $uf = $this->moneyService->getUF($pago->currentEstado->fecha); + if ($uf !== 0.0) { + $this->pagoRepository->edit($pago, ['uf' => $uf]); + return $uf; } + } elseif ($pago->uf === 0.0) { + $this->pagoRepository->edit($pago, ['uf' => null]); + return null; } - return $pago; + return $pago->uf; } }