Promociones

This commit is contained in:
Juan Pablo Vial
2025-03-25 19:22:38 -03:00
parent d3b0026ca4
commit b191a01313
12 changed files with 286 additions and 8 deletions

View File

@ -17,6 +17,15 @@ class Promotion extends Common\Ideal\Model
public Type $type;
public State $state = State::ACTIVE;
protected array $projects;
public function projects(): array
{
if (empty($this->projects)) {
$this->projects = $this->runFactory('projects');
}
return $this->projects;
}
protected array $contracts;
public function contracts(): array
{
@ -35,6 +44,15 @@ class Promotion extends Common\Ideal\Model
return $this->units;
}
protected array $contractUnits;
public function contractUnits(): array
{
if (empty($this->contractUnits)) {
$this->contractUnits = $this->runFactory('contractUnits');
}
return $this->contractUnits;
}
public function value(float $price): float
{
if ($this->type === Type::FIXED) {
@ -53,6 +71,7 @@ class Promotion extends Common\Ideal\Model
'valid_until' => $this->validUntil?->format('Y-m-d'),
'type' => $this->type,
'state' => $this->state,
'projects' => $this->projects() ?? [],
'contracts' => $this->contracts() ?? [],
'units' => $this->units() ?? []
];