Escriturar
This commit is contained in:
@ -4,6 +4,7 @@ namespace Incoviba\Model;
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Controller\Ventas;
|
||||
use Incoviba\Model\Venta\Pago;
|
||||
|
||||
class Venta extends Ideal\Model
|
||||
{
|
||||
@ -84,9 +85,10 @@ class Venta extends Ideal\Model
|
||||
}
|
||||
return $this->valor_util;
|
||||
}
|
||||
public function saldo(): float
|
||||
public function saldo(string $moneda = Pago::UF): float
|
||||
{
|
||||
return $this->valor - $this->formaPago->total();
|
||||
$valor = $this->valor * (($moneda === Pago::UF) ? 1 : $this->uf);
|
||||
return $valor - $this->formaPago()->total($moneda);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
|
@ -17,6 +17,9 @@ class Pie extends Model
|
||||
public array $cuotasArray;
|
||||
public function cuotas(bool $pagadas = false): array
|
||||
{
|
||||
if ($this->asociado !== null) {
|
||||
return $this->asociado->cuotas($pagadas);
|
||||
}
|
||||
if (!$pagadas) {
|
||||
return $this->cuotasArray;
|
||||
}
|
||||
@ -27,9 +30,30 @@ class Pie extends Model
|
||||
|
||||
public function pagado(string $moneda = Pago::UF): float
|
||||
{
|
||||
$proporcion = 1;
|
||||
if (count($this->asociados()) > 0) {
|
||||
$proporcion = $this->valor / ((($this->asociado) ? $this->asociado->valor : $this->valor) + array_reduce($this->asociados(), function(float $sum, Pie $pie) {
|
||||
return $sum + $pie->valor;
|
||||
}, 0));
|
||||
}
|
||||
if ($this->asociado !== null) {
|
||||
return $this->asociado->pagado($moneda) * $proporcion;
|
||||
}
|
||||
|
||||
return array_reduce($this->cuotas(true), function(float $sum, Cuota $cuota) use ($moneda) {
|
||||
return $sum + $cuota->pago->valor($moneda);
|
||||
}, 0);
|
||||
}, 0) * $proporcion;
|
||||
}
|
||||
public ?array $asociados;
|
||||
public function asociados(): array
|
||||
{
|
||||
if ($this->asociado !== null) {
|
||||
return $this->asociado->asociados();
|
||||
}
|
||||
if (!isset($this->asociados) or $this->asociados === []) {
|
||||
$this->asociados = $this->runFactory('asociados');
|
||||
}
|
||||
return $this->asociados ?? [];
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
|
Reference in New Issue
Block a user