Merge pull request 'feature/porcentajes-pie-y-bono' (#22) from feature/porcentajes-pie-y-bono into develop

Reviewed-on: #22
This commit is contained in:
2025-04-03 16:51:15 +00:00
8 changed files with 21 additions and 12 deletions

View File

@ -58,6 +58,7 @@
if (!this.venta.current_estado.tipo_estado_venta.activa) {
unidad.html(unidad.html() + ' (I)')
}
unidad.html(unidad.html() + ' <i class="angle right icon"></i>')
propietario = $('<a></a>')
.attr('href','{{$urls->base}}/search/"' + encodeURIComponent(this.venta.propietario.nombre_completo) + '"/propietario')
.html(this.venta.propietario.nombre_completo)

View File

@ -167,7 +167,8 @@
}, 0.0))}}
</th>
<th class="right aligned">
{{$format->number(($total > 0) ? $pagado / $total * 100 : 0, 2)}}%
{{ $format->percent(($total > 0) ? $pagado / $total : 0, 2, true) }} Pie<br />
{{ $format->percent($pagado / $venta->valor, 2, true) }} Promesa
</th>
<th colspan="3"></th>
</tr>

View File

@ -1,6 +1,6 @@
<tr>
<td><strong>Anticipo</strong></td>
<td></td>
<td>{{ $format->percent($anticipo['uf'] / $venta->valor, 2, true) }}</td>
<td class="right aligned"><strong>{{$format->ufs($anticipo['uf'])}}</strong></td>
<td class="right aligned"><strong>{{$format->pesos($anticipo['pesos'])}}</strong></td>
<td colspan="2"></td>

View File

@ -14,7 +14,7 @@
@endif
</td>
@if ($bonoPie !== null)
<td></td>
<td>{{ $format->percent($bonoPie->pago->valor() / $venta->valor, 2, true) }}</td>
<td class="right aligned">{{$format->ufs($bonoPie->pago->valor())}}</td>
<td class="right aligned">{{$format->pesos($bonoPie->pago->valor)}}</td>
<td colspan="2"></td>

View File

@ -14,7 +14,7 @@
@endif
</td>
@if ($credito !== null)
<td></td>
<td>{{ $format->percent($credito->pago->valor() / $venta->valor, 2, true) }}</td>
<td class="right aligned">
{{$format->ufs($credito->pago->valor())}}
</td>

View File

@ -8,7 +8,7 @@
</a>
</sub>
</td>
<td></td>
<td>{{ $format->percent($pie->valor / $venta->valor, 2, true) }}</td>
<td class="right aligned">{{$format->ufs($pie->valor)}}</td>
<td class="right aligned">{{$format->pesos($pie->valor * $pie->uf)}}</td>
<td class="right aligned">Cuotas</td>
@ -25,7 +25,7 @@
</tr>
<tr>
<td>Pagado</td>
<td></td>
<td>{{$format->percent($pie->pagado() / $venta->valor, 2, true)}}</td>
<td class="right aligned">{{$format->ufs($pie->pagado())}}</td>
<td class="right aligned">{{$format->pesos($pie->pagado('pesos'))}}</td>
<td colspan="2"></td>

View File

@ -24,8 +24,15 @@ class Pago extends Model
public function valor(string $moneda = Pago::UF): float
{
$uf = $this->uf ?? ($this->uf > 0.0 ? $this->uf : 1);
return $this->valor / (($moneda === Pago::UF) ? $uf : 1);
$multiplier = 1;
if ($moneda === Pago::UF) {
if ($this->uf === null or $this->uf === 0.0) {
return 0;
}
$uf = $this->uf;
$multiplier = 1 / $uf;
}
return $this->valor * $multiplier;
}
public function estado(?string $tipoEstado = null): ?EstadoPago

View File

@ -6,12 +6,12 @@ use IntlDateFormatter;
class Format
{
public function localDate(string $valor, string $format, bool $print = false): string
public function localDate(string $valor, ?string $format = null, bool $print = false): string
{
$date = new DateTimeImmutable($valor);
$formatter = new IntlDateFormatter('es_ES');
if ($format == null) {
$format = 'DD [de] MMMM [de] YYYY';
$format = "dd 'de' MMMM 'de' YYYY";
}
$formatter->setPattern($format);
return $formatter->format($date);
@ -21,9 +21,9 @@ class Format
{
return number_format($number, $decimal_places, ',', '.');
}
public function percent(float|string $number, int $decimal_places = 2): string
public function percent(float|string $number, int $decimal_places = 2, bool $multiply = false): string
{
return "{$this->number($number, $decimal_places)}%";
return "{$this->number(($multiply) ? $number * 100 : $number, $decimal_places)}%";
}
public function pesos(string $valor, int $decimal_places = 0): string
{