2025-02-18 16:02:10 -03:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Model\Venta;
|
|
|
|
|
|
|
|
use DateTimeInterface;
|
|
|
|
use Incoviba\Common;
|
2025-03-13 12:18:08 -03:00
|
|
|
use Incoviba\Model\Proyecto\Broker;
|
2025-02-18 16:02:10 -03:00
|
|
|
|
|
|
|
class Promotion extends Common\Ideal\Model
|
|
|
|
{
|
|
|
|
public float $amount;
|
|
|
|
public DateTimeInterface $startDate;
|
|
|
|
public DateTimeInterface $endDate;
|
|
|
|
public DateTimeInterface $validUntil;
|
|
|
|
public int $state;
|
|
|
|
|
2025-03-17 22:49:48 -03:00
|
|
|
protected array $contracts;
|
|
|
|
public function contracts(): array
|
2025-03-13 12:18:08 -03:00
|
|
|
{
|
2025-03-17 22:49:48 -03:00
|
|
|
if (empty($this->contracts)) {
|
|
|
|
$this->contracts = $this->runFactory('contracts');
|
|
|
|
}
|
|
|
|
return $this->contracts;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected array $units;
|
|
|
|
public function units(): array
|
|
|
|
{
|
|
|
|
if (empty($this->units)) {
|
|
|
|
$this->units = $this->runFactory('units');
|
|
|
|
}
|
|
|
|
return $this->units;
|
2025-03-13 12:18:08 -03:00
|
|
|
}
|
|
|
|
|
2025-02-18 16:02:10 -03:00
|
|
|
protected function jsonComplement(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'amount' => $this->amount,
|
|
|
|
'start_date' => $this->startDate->format('Y-m-d'),
|
|
|
|
'end_date' => $this->endDate->format('Y-m-d'),
|
|
|
|
'valid_until' => $this->validUntil->format('Y-m-d'),
|
|
|
|
'state' => [
|
|
|
|
'id' => $this->state,
|
|
|
|
'description' => Promotion\State::name($this->state)
|
2025-03-17 22:49:48 -03:00
|
|
|
],
|
|
|
|
'contracts' => $this->contracts() ?? [],
|
|
|
|
'units' => $this->units() ?? []
|
2025-02-18 16:02:10 -03:00
|
|
|
];
|
|
|
|
}
|
2025-03-13 12:18:08 -03:00
|
|
|
}
|