Listado de Precios para Contrato Broker

This commit is contained in:
Juan Pablo Vial
2025-03-13 12:18:08 -03:00
parent 346001db8e
commit 68aebdb4fe
18 changed files with 826 additions and 14 deletions

View File

@ -32,6 +32,15 @@ class Contract extends Common\Ideal\Model
return $this->current;
}
protected array $promotions = [];
public function promotions(): array
{
if (count($this->promotions) === 0) {
$this->promotions = $this->runFactory('promotions');
}
return $this->promotions;
}
protected function jsonComplement(): array
{
return [

View File

@ -3,9 +3,11 @@ namespace Incoviba\Model\Venta;
use DateTimeInterface;
use Incoviba\Common;
use Incoviba\Model\Proyecto\Broker;
class Promotion extends Common\Ideal\Model
{
public Broker\Contract $contract;
public Precio $price;
public float $amount;
public DateTimeInterface $startDate;
@ -13,11 +15,18 @@ class Promotion extends Common\Ideal\Model
public DateTimeInterface $validUntil;
public int $state;
public function price(): float
{
return $this->price->valor * $this->amount;
}
protected function jsonComplement(): array
{
return [
'contract_rut' => $this->contract->id,
'price_id' => $this->price->id,
'amount' => $this->amount,
'price' => $this->price(),
'start_date' => $this->startDate->format('Y-m-d'),
'end_date' => $this->endDate->format('Y-m-d'),
'valid_until' => $this->validUntil->format('Y-m-d'),
@ -27,4 +36,4 @@ class Promotion extends Common\Ideal\Model
]
];
}
}
}

View File

@ -45,6 +45,18 @@ class Unidad extends Ideal\Model
return $precio;
}
protected bool $sold;
public function sold(): bool
{
if (!isset($this->sold)) {
$this->sold = false;
try {
$this->sold = $this->runFactory('sold') ?? false;
} catch (EmptyResult) {}
}
return $this->sold;
}
public function jsonSerialize(): mixed
{
$output = array_merge(parent::jsonSerialize(), [
@ -59,6 +71,7 @@ class Unidad extends Ideal\Model
$output['precios'] = $this->precios;
$output['current_precio'] = $this->currentPrecio;
}
$output['sold'] = $this->sold() ?? false;
return $output;
}
}