Implemented repository mapper, and venta show
This commit is contained in:
@ -5,4 +5,14 @@ use Incoviba\Common\Ideal;
|
||||
|
||||
class BonoPie extends Ideal\Model
|
||||
{
|
||||
public float $valor;
|
||||
public Pago $pago;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'valor' => $this->valor,
|
||||
'pago' => $this->pago
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
21
app/src/Model/Venta/Comentario.php
Normal file
21
app/src/Model/Venta/Comentario.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Comentario extends Ideal\Model
|
||||
{
|
||||
public DateTimeInterface $fecha;
|
||||
public string $texto;
|
||||
public bool $activo;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'fecha' => $this->fecha->format('Y-m-d'),
|
||||
'texto' => $this->texto,
|
||||
'activo' => $this->activo
|
||||
]);
|
||||
}
|
||||
}
|
@ -4,4 +4,13 @@ namespace Incoviba\Model\Venta;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Credito extends Ideal\Model
|
||||
{}
|
||||
{
|
||||
public Pago $pago;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'pago' => $this->pago
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Escritura extends Ideal\Model
|
||||
{}
|
||||
{
|
||||
public Pago $pago;
|
||||
public DateTimeInterface $fecha;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'pago' => $this->pago,
|
||||
'fecha' => $this->fecha->format('Y-m-d')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -6,19 +6,62 @@ use JsonSerializable;
|
||||
class FormaPago implements JsonSerializable
|
||||
{
|
||||
public ?Pie $pie;
|
||||
public ?BonoPie $bonoPie;
|
||||
public ?Credito $credito;
|
||||
public ?Escritura $escritura;
|
||||
public ?BonoPie $bonoPie;
|
||||
public ?Subsidio $subsidio;
|
||||
public ?Credito $credito;
|
||||
public ?Pago $devolucion;
|
||||
|
||||
public function anticipo(string $moneda = Pago::UF): float
|
||||
{
|
||||
$sum = 0;
|
||||
if ($this->pie !== null) {
|
||||
$sum += $this->pie->pagado($moneda);
|
||||
if (isset($this->pie->reajuste) and $this->pie->reajuste !== null) {
|
||||
$sum += $this->pie->reajuste->valor($moneda);
|
||||
}
|
||||
}
|
||||
if ($this->escritura !== null) {
|
||||
$sum += $this->escritura->pago->valor($moneda);
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
public function total(string $moneda = Pago::UF): float
|
||||
{
|
||||
$sum = $this->anticipo($moneda);
|
||||
if (isset($this->bonoPie)) {
|
||||
$sum += $this->bonoPie->pago->valor($moneda);
|
||||
}
|
||||
if (isset($this->subsidio)) {
|
||||
$sum += $this->subsidio->ahorro->valor($moneda);
|
||||
$sum += $this->subsidio->subsidio->valor($moneda);
|
||||
}
|
||||
if (isset($this->credito)) {
|
||||
$sum += $this->credito->pago->valor($moneda);
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
public function ids(): array
|
||||
{
|
||||
return [
|
||||
'pie_id' => $this->pie?->id,
|
||||
'escritura_id' => $this->escritura?->id,
|
||||
'bono_pie_id' => $this->bonoPie?->id,
|
||||
'credito_id' => $this->credito?->id,
|
||||
'subsidio_id' => $this->subsidio?->id,
|
||||
'devolucion_id' => $this->devolucion?->id
|
||||
];
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'pie' => $this->pie ?? null,
|
||||
'bono_pie' => $this->bonoPie ?? null,
|
||||
'credito' => $this->credito ?? null,
|
||||
'escritura' => $this->escritura ?? null,
|
||||
'subsidio' => $this->subsidio ?? null
|
||||
'bono_pie' => $this->bonoPie ?? null,
|
||||
'subsidio' => $this->subsidio ?? null,
|
||||
'credito' => $this->credito ?? null,
|
||||
'devolucion' => $this->devolucion ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ use Incoviba\Model\Banco;
|
||||
|
||||
class Pago extends Model
|
||||
{
|
||||
const UF = 'uf';
|
||||
const PESOS = 'pesos';
|
||||
|
||||
public float $valor;
|
||||
public ?Banco $banco;
|
||||
public ?TipoPago $tipoPago;
|
||||
@ -16,6 +19,14 @@ class Pago extends Model
|
||||
public ?string $pagador;
|
||||
public ?Pago $asociado;
|
||||
|
||||
public array $estados;
|
||||
public EstadoPago $currentEstado;
|
||||
|
||||
public function valor(string $moneda = Pago::UF): float
|
||||
{
|
||||
return $this->valor / (($moneda === Pago::UF) ? ($this->uf > 0 ? $this->uf : 1) : 1);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
|
@ -13,6 +13,24 @@ class Pie extends Model
|
||||
public ?Pie $asociado;
|
||||
public ?Pago $reajuste;
|
||||
|
||||
public array $cuotasArray;
|
||||
public function cuotas(bool $pagadas = false): array
|
||||
{
|
||||
if (!$pagadas) {
|
||||
return $this->cuotasArray;
|
||||
}
|
||||
return array_filter($this->cuotasArray, function(Cuota $cuota) {
|
||||
return $cuota->pago->currentEstado->tipoEstadoPago->descripcion !== 'no pagado';
|
||||
});
|
||||
}
|
||||
|
||||
public function pagado(string $moneda = Pago::UF): float
|
||||
{
|
||||
return array_reduce($this->cuotas(true), function(float $sum, Cuota $cuota) use ($moneda) {
|
||||
return $sum + $cuota->pago->valor($moneda);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
|
@ -20,6 +20,14 @@ class Propiedad extends Ideal\Model
|
||||
return array_filter($this->unidades, function(Unidad $unidad) {return $unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'bodega';});
|
||||
}
|
||||
|
||||
protected float $vendible;
|
||||
public function vendible(): float
|
||||
{
|
||||
return array_reduce($this->departamentos(), function(float $sum, Unidad $unidad) {
|
||||
return $sum + $unidad->proyectoTipoUnidad->vendible();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
public function summary(): string
|
||||
{
|
||||
return implode(' - ', array_merge(
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
@ -15,6 +16,33 @@ class Unidad extends Ideal\Model
|
||||
public array $precios = [];
|
||||
public ?Precio $currentPrecio = null;
|
||||
|
||||
public function precio(DateTimeInterface $dateTime): Precio
|
||||
{
|
||||
if ($dateTime > $this->currentPrecio->current->fecha) {
|
||||
return $this->currentPrecio;
|
||||
}
|
||||
$precio = array_reduce(array_filter($this->precios, function(Precio $precio) use ($dateTime) {
|
||||
return $dateTime > $precio->current->fecha;
|
||||
}), function(?Precio $max, Precio $precio) {
|
||||
if ($max === null) {
|
||||
return $precio;
|
||||
}
|
||||
return $max->current->fecha > $precio->current->fecha ? $max : $precio;
|
||||
});
|
||||
if ($precio === null) {
|
||||
$precio = array_reduce(array_filter($this->precios, function(Precio $precio) use ($dateTime) {
|
||||
return $dateTime < $precio->current->fecha;
|
||||
}), function(?Precio $min, Precio $precio) {
|
||||
if ($min === null) {
|
||||
return $precio;
|
||||
}
|
||||
return $min->current->fecha < $precio->current->fecha ? $min : $precio;
|
||||
});
|
||||
}
|
||||
|
||||
return $precio;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
|
Reference in New Issue
Block a user