FIX: Pie cuotas valores uf
This commit is contained in:
@ -26,7 +26,10 @@
|
|||||||
<th>Fecha Estado ISO</th>
|
<th>Fecha Estado ISO</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>@php $now = new DateTimeImmutable(); @endphp
|
<tbody>@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)
|
@foreach ($venta->formaPago()->pie->cuotas() as $cuota)
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{$cuota->numero}}</td>
|
<td>{{$cuota->numero}}</td>
|
||||||
@ -85,16 +88,12 @@
|
|||||||
}, 0))}}
|
}, 0))}}
|
||||||
</th>
|
</th>
|
||||||
<th class="right aligned">
|
<th class="right aligned">
|
||||||
@php
|
|
||||||
$now = new DateTimeImmutable();
|
|
||||||
@endphp
|
|
||||||
{{$format->ufs($total = array_reduce($venta->formaPago()->pie->cuotas(),
|
{{$format->ufs($total = array_reduce($venta->formaPago()->pie->cuotas(),
|
||||||
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) use ($now, $venta) {
|
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) use ($now, $uf_venta) {
|
||||||
if ($cuota->pago->fecha > $now) {
|
return $sum + (($cuota->pago->fecha > $now or $cuota->pago->uf === null) ?
|
||||||
return $sum + $cuota->pago->valor / $venta->uf;
|
$cuota->pago->valor / $uf_venta :
|
||||||
}
|
$cuota->pago->valor());
|
||||||
return $sum + $cuota->pago->valor();
|
}, 0.0))}}
|
||||||
}, 0))}}
|
|
||||||
</th>
|
</th>
|
||||||
<th colspan="3"></th>
|
<th colspan="3"></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -24,7 +24,8 @@ class Pago extends Model
|
|||||||
|
|
||||||
public function valor(string $moneda = Pago::UF): float
|
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
|
public function jsonSerialize(): mixed
|
||||||
|
@ -25,7 +25,7 @@ class Pie extends Model
|
|||||||
}
|
}
|
||||||
if ($pagadas) {
|
if ($pagadas) {
|
||||||
return array_filter($this->cuotasArray, function(Cuota $cuota) {
|
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) {
|
return array_filter($this->cuotasArray, function(Cuota $cuota) {
|
||||||
|
@ -136,14 +136,23 @@ class Pago
|
|||||||
{
|
{
|
||||||
$pago->estados = $this->estadoPagoRepository->fetchByPago($pago->id);
|
$pago->estados = $this->estadoPagoRepository->fetchByPago($pago->id);
|
||||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($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)
|
if (($pago->uf === null or $pago->uf === 0.0)
|
||||||
and $pago->currentEstado->tipoEstadoPago->descripcion === 'abonado'
|
and $pago->currentEstado->tipoEstadoPago->descripcion === 'abonado'
|
||||||
and $pago->currentEstado->fecha <= new DateTimeImmutable()) {
|
and $pago->currentEstado->fecha <= new DateTimeImmutable()) {
|
||||||
$pago->uf = $this->moneyService->getUF($pago->currentEstado->fecha);
|
$uf = $this->moneyService->getUF($pago->currentEstado->fecha);
|
||||||
if ($pago->uf !== 0.0) {
|
if ($uf !== 0.0) {
|
||||||
$this->pagoRepository->edit($pago, ['uf' => $pago->uf]);
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user