2025-02-18 16:02:10 -03:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Model\Proyecto\Broker;
|
|
|
|
|
|
|
|
use Incoviba\Common;
|
|
|
|
use Incoviba\Model;
|
|
|
|
|
|
|
|
class Contract extends Common\Ideal\Model
|
|
|
|
{
|
|
|
|
public Model\Proyecto $project;
|
|
|
|
public Model\Proyecto\Broker $broker;
|
|
|
|
public float $commission;
|
|
|
|
protected array $states = [];
|
|
|
|
|
|
|
|
public function states(): array
|
|
|
|
{
|
2025-03-03 21:41:43 -03:00
|
|
|
if (!isset($this->states) or count($this->states) === 0) {
|
2025-02-18 16:02:10 -03:00
|
|
|
$this->states = $this->runFactory('states');
|
|
|
|
}
|
|
|
|
return $this->states;
|
|
|
|
}
|
|
|
|
|
2025-03-03 21:41:43 -03:00
|
|
|
protected ?Contract\State $current;
|
|
|
|
public function currentState(): ?Contract\State
|
2025-02-18 16:02:10 -03:00
|
|
|
{
|
|
|
|
if (!isset($this->current)) {
|
2025-03-03 21:41:43 -03:00
|
|
|
try {
|
|
|
|
$this->current = last($this->states());
|
|
|
|
} catch (\TypeError $error) {
|
|
|
|
$this->current = null;
|
|
|
|
}
|
2025-02-18 16:02:10 -03:00
|
|
|
}
|
|
|
|
return $this->current;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function jsonComplement(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'project_id' => $this->project->id,
|
|
|
|
'broker_rut' => $this->broker->rut,
|
|
|
|
'commission' => $this->commission,
|
|
|
|
'states' => $this->states(),
|
|
|
|
'current' => $this->currentState(),
|
|
|
|
];
|
|
|
|
}
|
2025-03-03 21:41:43 -03:00
|
|
|
}
|