Rejected or canceled reservations, comments

This commit is contained in:
Juan Pablo Vial
2025-09-22 14:08:23 -03:00
parent fc65ee581a
commit 46d810555c
6 changed files with 62 additions and 16 deletions

View File

@ -117,6 +117,8 @@ class Reservation extends Common\Ideal\Model
return $base >= $price;
}
public string $comments;
protected function jsonComplement(): array
{
return [
@ -131,7 +133,10 @@ class Reservation extends Common\Ideal\Model
'base' => $this->base(),
'price' => $this->price(),
'valid' => $this->valid(),
'summary' => $this->summary()
'summary' => $this->summary(),
'states' => $this->states() ?? [],
'current_state' => $this->currentState()?->type?->name ?? null,
'comments' => $this->comments ?? '',
];
}
}

View File

@ -16,7 +16,10 @@ class State extends Common\Ideal\Model
return [
'reservation_id' => $this->reservation->id,
'date' => $this->date->format('Y-m-d'),
'type' => $this->type
'type' => [
'id' => $this->type->value,
'name' => $this->type->name,
]
];
}
}

View File

@ -18,6 +18,6 @@ enum Type: int
}
public static function getTypes(): array
{
return [self::ACTIVE->value, self::INACTIVE->value, self::REJECTED->value];
return [self::ACTIVE->value, self::INACTIVE->value, self::REJECTED->value, self::CANCELLED->value];
}
}

View File

@ -4,6 +4,7 @@ namespace Incoviba\Repository\Venta;
use DateTimeInterface;
use DateInterval;
use Incoviba\Common\Define;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\Model\InvalidState;
use PDO;
use Incoviba\Common;
@ -29,7 +30,7 @@ class Reservation extends Common\Ideal\Repository
public function create(?array $data = null): Model\Venta\Reservation
{
$map = (new Common\Implement\Repository\MapperParser())
$map = (new Common\Implement\Repository\MapperParser(['comments']))
->register('project_id', (new Common\Implement\Repository\Mapper())
->setProperty('project')
->setFunction(function($data) {
@ -114,13 +115,16 @@ class Reservation extends Common\Ideal\Repository
/**
* @param int $project_id
* @param int $state
* @param int|string $state
* @return array
* @throws Common\Implement\Exception\EmptyResult
* @throws EmptyResult
* @throws InvalidState
*/
public function fetchState(int $project_id, int $state): array
public function fetchState(int $project_id, int|string $state): array
{
if (is_string($state)) {
$state = Model\Venta\Reservation\State\Type::from($state)->value;
}
if (!in_array($state, Model\Venta\Reservation\State\Type::getTypes())) {
throw new InvalidState();
}