diff --git a/app/src/Repository/Venta/Reservation.php b/app/src/Repository/Venta/Reservation.php index 45f005f..e181eba 100644 --- a/app/src/Repository/Venta/Reservation.php +++ b/app/src/Repository/Venta/Reservation.php @@ -176,14 +176,28 @@ class Reservation extends Common\Ideal\Repository */ public function fetchRejected(int $project_id): array { + $reservations = []; + $exceptions = []; try { - return [ + $reservations = [ + ...$reservations, ...$this->fetchState($project_id, Model\Venta\Reservation\State\Type::REJECTED->value), + ]; + } catch (InvalidState $exception) { + $exceptions[] = new Common\Implement\Exception\EmptyResult('No rejected reservations', $exception); + } + try { + $reservations = [ + ...$reservations, ...$this->fetchState($project_id, Model\Venta\Reservation\State\Type::CANCELLED->value) ]; } catch (InvalidState $exception) { - throw new Common\Implement\Exception\EmptyResult('Select rejected reservations', $exception); + $exceptions[] = new Common\Implement\Exception\EmptyResult('No cancelled reservations', $exception); } + if (count($reservations) === 0) { + throw new Common\Implement\Exception\EmptyResult('No rejected nor cancelled reservations', last($exceptions)); + } + return $reservations; } protected function saveUnits(Model\Venta\Reservation $reservation): void diff --git a/app/src/Service/Venta/Reservation.php b/app/src/Service/Venta/Reservation.php index a12f442..6326cca 100644 --- a/app/src/Service/Venta/Reservation.php +++ b/app/src/Service/Venta/Reservation.php @@ -222,6 +222,12 @@ class Reservation extends Ideal\Service\API throw new ServiceAction\Update(__CLASS__, $exception); } } + + /** + * @param Model\Venta\Reservation $reservation + * @return void + * @throws ServiceAction\Update + */ public function reject(Model\Venta\Reservation $reservation): void { try {