Base de Datos
This commit is contained in:
30
app/src/Model/Venta/Promotion.php
Normal file
30
app/src/Model/Venta/Promotion.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common;
|
||||
|
||||
class Promotion extends Common\Ideal\Model
|
||||
{
|
||||
public Precio $price;
|
||||
public float $amount;
|
||||
public DateTimeInterface $startDate;
|
||||
public DateTimeInterface $endDate;
|
||||
public DateTimeInterface $validUntil;
|
||||
public int $state;
|
||||
|
||||
protected function jsonComplement(): array
|
||||
{
|
||||
return [
|
||||
'price_id' => $this->price->id,
|
||||
'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)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
17
app/src/Model/Venta/Promotion/State.php
Normal file
17
app/src/Model/Venta/Promotion/State.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta\Promotion;
|
||||
|
||||
enum State: int
|
||||
{
|
||||
case ACTIVE = 1;
|
||||
case INACTIVE = 0;
|
||||
|
||||
public static function name(int $state): string
|
||||
{
|
||||
return match ($state) {
|
||||
self::ACTIVE => 'active',
|
||||
self::INACTIVE => 'inactive',
|
||||
default => throw new \InvalidArgumentException('Unexpected match value')
|
||||
};
|
||||
}
|
||||
}
|
83
app/src/Model/Venta/Reservation.php
Normal file
83
app/src/Model/Venta/Reservation.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Reservation extends Common\Ideal\Model
|
||||
{
|
||||
public Model\Persona $buyer;
|
||||
public DateTimeInterface $date;
|
||||
public array $units = [];
|
||||
public array $promotions = [];
|
||||
public ?Model\Proyecto\Broker $broker = null;
|
||||
protected array $states = [];
|
||||
|
||||
public function states(): array
|
||||
{
|
||||
if (!isset($this->states)) {
|
||||
$this->states = $this->runFactory('states');
|
||||
}
|
||||
return $this->states;
|
||||
}
|
||||
|
||||
protected Model\Venta\Reservation\State $currentState;
|
||||
|
||||
public function currentState(): Model\Venta\Reservation\State
|
||||
{
|
||||
if (!isset($this->currentState)) {
|
||||
$this->currentState = last($this->states());
|
||||
}
|
||||
return $this->currentState;
|
||||
}
|
||||
|
||||
public function addUnit(Model\Venta\Unidad $unit, float $value): self
|
||||
{
|
||||
if (($i = $this->findUnit($unit->id)) !== null) {
|
||||
$this->units[$i]['value'] = $value;
|
||||
return $this;
|
||||
}
|
||||
$this->units[] = [
|
||||
'unit' => $unit,
|
||||
'value' => $value,
|
||||
];
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeUnit(int $unit_id): self
|
||||
{
|
||||
if (($i = $this->findUnit($unit_id)) === null) {
|
||||
return $this;
|
||||
}
|
||||
unset($this->units[$i]);
|
||||
$this->units = array_values($this->units);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function findUnit(int $unit_id): ?int
|
||||
{
|
||||
foreach ($this->units as $idx => $unit) {
|
||||
if ($unit['unit']->id == $unit_id) {
|
||||
return $idx;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function hasUnit(int $unit_id): bool
|
||||
{
|
||||
return $this->findUnit($unit_id) !== null;
|
||||
}
|
||||
|
||||
protected function jsonComplement(): array
|
||||
{
|
||||
return [
|
||||
'buyer_rut' => $this->buyer->rut,
|
||||
'date' => $this->date->format('Y-m-d'),
|
||||
'units' => $this->units,
|
||||
'promotions' => $this->promotions,
|
||||
'broker_rut' => $this->broker?->rut,
|
||||
];
|
||||
}
|
||||
}
|
25
app/src/Model/Venta/Reservation/State.php
Normal file
25
app/src/Model/Venta/Reservation/State.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta\Reservation;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common;
|
||||
use Incoviba\Model;
|
||||
|
||||
class State extends Common\Ideal\Model
|
||||
{
|
||||
public Model\Venta\Reservation $reservation;
|
||||
public DateTimeInterface $date;
|
||||
public int $type;
|
||||
|
||||
protected function jsonComplement(): array
|
||||
{
|
||||
return [
|
||||
'reservation_id' => $this->reservation->id,
|
||||
'date' => $this->date->format('Y-m-d'),
|
||||
'type' => [
|
||||
'id' => $this->type,
|
||||
'description' => State\Type::name($this->type)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
19
app/src/Model/Venta/Reservation/State/Type.php
Normal file
19
app/src/Model/Venta/Reservation/State/Type.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta\Reservation\State;
|
||||
|
||||
enum Type: int
|
||||
{
|
||||
case ACTIVE = 1;
|
||||
case INACTIVE = 0;
|
||||
case REJECTED = -1;
|
||||
|
||||
public static function name(int $type): string
|
||||
{
|
||||
return match ($type) {
|
||||
self::ACTIVE => 'active',
|
||||
self::INACTIVE => 'inactive',
|
||||
self::REJECTED => 'rejected',
|
||||
default => throw new \InvalidArgumentException('Unexpected match value')
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user