Separacion de Promocion de Contrato y Precio

"Simplificacion" de datos en listado de precios
This commit is contained in:
Juan Pablo Vial
2025-03-17 22:49:48 -03:00
parent 2e49e2c947
commit bae0f1f555
13 changed files with 479 additions and 278 deletions

View File

@ -7,33 +7,43 @@ use Incoviba\Model\Proyecto\Broker;
class Promotion extends Common\Ideal\Model
{
public Broker\Contract $contract;
public Precio $price;
public float $amount;
public DateTimeInterface $startDate;
public DateTimeInterface $endDate;
public DateTimeInterface $validUntil;
public int $state;
public function price(): float
protected array $contracts;
public function contracts(): array
{
return $this->price->valor * $this->amount;
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;
}
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'),
'state' => [
'id' => $this->state,
'description' => Promotion\State::name($this->state)
]
],
'contracts' => $this->contracts() ?? [],
'units' => $this->units() ?? []
];
}
}