Base de Datos
This commit is contained in:
23
app/src/Model/Proyecto/Broker.php
Normal file
23
app/src/Model/Proyecto/Broker.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto;
|
||||
|
||||
use Incoviba\Common;
|
||||
|
||||
class Broker extends Common\Ideal\Model
|
||||
{
|
||||
public int $rut;
|
||||
public string $digit;
|
||||
public string $name;
|
||||
|
||||
public ?Broker\Data $data = null;
|
||||
|
||||
protected function jsonComplement(): array
|
||||
{
|
||||
return [
|
||||
'rut' => $this->rut,
|
||||
'digit' => $this->digit,
|
||||
'name' => $this->name,
|
||||
'data' => $this->data
|
||||
];
|
||||
}
|
||||
}
|
41
app/src/Model/Proyecto/Broker/Contract.php
Normal file
41
app/src/Model/Proyecto/Broker/Contract.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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
|
||||
{
|
||||
if (!isset($this->states)) {
|
||||
$this->states = $this->runFactory('states');
|
||||
}
|
||||
return $this->states;
|
||||
}
|
||||
|
||||
protected Contract\State $current;
|
||||
public function currentState(): Contract\State
|
||||
{
|
||||
if (!isset($this->current)) {
|
||||
$this->current = last($this->states());
|
||||
}
|
||||
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(),
|
||||
];
|
||||
}
|
||||
}
|
25
app/src/Model/Proyecto/Broker/Contract/State.php
Normal file
25
app/src/Model/Proyecto/Broker/Contract/State.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto\Broker\Contract;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common;
|
||||
use Incoviba\Model;
|
||||
|
||||
class State extends Common\Ideal\Model
|
||||
{
|
||||
public Model\Proyecto\Broker\Contract $contract;
|
||||
public DateTimeInterface $date;
|
||||
public int $type;
|
||||
|
||||
protected function jsonComplement(): array
|
||||
{
|
||||
return [
|
||||
'contract_id' => $this->contract->id,
|
||||
'date' => $this->date->format('Y-m-d'),
|
||||
'type' => [
|
||||
'id' => $this->type,
|
||||
'description' => State\Type::name($this->type)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
17
app/src/Model/Proyecto/Broker/Contract/State/Type.php
Normal file
17
app/src/Model/Proyecto/Broker/Contract/State/Type.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto\Broker\Contract\State;
|
||||
|
||||
enum Type: int
|
||||
{
|
||||
case ACTIVE = 1;
|
||||
case INACTIVE = 0;
|
||||
|
||||
public static function name(int $type): string
|
||||
{
|
||||
return match ($type) {
|
||||
self::ACTIVE => 'active',
|
||||
self::INACTIVE => 'inactive',
|
||||
default => throw new \InvalidArgumentException('Unexpected match value')
|
||||
};
|
||||
}
|
||||
}
|
21
app/src/Model/Proyecto/Broker/Data.php
Normal file
21
app/src/Model/Proyecto/Broker/Data.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Proyecto\Broker;
|
||||
|
||||
use Incoviba\Common;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Data extends Common\Ideal\Model
|
||||
{
|
||||
public Model\Proyecto\Broker $broker;
|
||||
public ?Model\Persona $representative = null;
|
||||
public ?string $legalName = null;
|
||||
|
||||
protected function jsonComplement(): array
|
||||
{
|
||||
return [
|
||||
'broker_rut' => $this->broker->rut,
|
||||
'representative_rut' => $this->representative?->rut,
|
||||
'legal_name' => $this->legalName
|
||||
];
|
||||
}
|
||||
}
|
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