Agregar, editar y eliminar promociones
This commit is contained in:
@ -4,14 +4,18 @@ namespace Incoviba\Model\Venta;
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common;
|
||||
use Incoviba\Model\Proyecto\Broker;
|
||||
use Incoviba\Model\Venta\Promotion\State;
|
||||
use Incoviba\Model\Venta\Promotion\Type;
|
||||
|
||||
class Promotion extends Common\Ideal\Model
|
||||
{
|
||||
public string $description;
|
||||
public float $amount;
|
||||
public DateTimeInterface $startDate;
|
||||
public DateTimeInterface $endDate;
|
||||
public DateTimeInterface $validUntil;
|
||||
public int $state;
|
||||
public ?DateTimeInterface $endDate;
|
||||
public ?DateTimeInterface $validUntil;
|
||||
public Type $type;
|
||||
public State $state = State::ACTIVE;
|
||||
|
||||
protected array $contracts;
|
||||
public function contracts(): array
|
||||
@ -31,17 +35,24 @@ class Promotion extends Common\Ideal\Model
|
||||
return $this->units;
|
||||
}
|
||||
|
||||
public function value(float $price): float
|
||||
{
|
||||
if ($this->type === Type::FIXED) {
|
||||
return $price + $this->amount;
|
||||
}
|
||||
return $price / (1 - $this->amount);
|
||||
}
|
||||
|
||||
protected function jsonComplement(): array
|
||||
{
|
||||
return [
|
||||
'description' => $this->description,
|
||||
'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)
|
||||
],
|
||||
'end_date' => $this->endDate?->format('Y-m-d'),
|
||||
'valid_until' => $this->validUntil?->format('Y-m-d'),
|
||||
'type' => $this->type,
|
||||
'state' => $this->state,
|
||||
'contracts' => $this->contracts() ?? [],
|
||||
'units' => $this->units() ?? []
|
||||
];
|
||||
|
Reference in New Issue
Block a user