Reservation Fixes

This commit is contained in:
Juan Pablo Vial
2025-09-09 16:24:48 -03:00
parent e5cf4e7067
commit e36281d924
6 changed files with 47 additions and 33 deletions

View File

@ -1,8 +1,10 @@
<?php
namespace Incoviba\Service\Venta;
use DateTimeImmutable;
use DateMalformedStringException;
use DateTimeImmutable;
use DateTimeInterface;
use Incoviba\Exception\ServiceAction\Read;
use PDOException;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Define;
@ -33,6 +35,12 @@ class Reservation extends Ideal\Service\API
return [];
}
}
/**
* @param int $project_id
* @return array
* @throws ServiceAction\Read
*/
public function getByProject(int $project_id): array
{
try {
@ -51,6 +59,21 @@ class Reservation extends Ideal\Service\API
}
}
/**
* @param int $buyer_rut
* @param DateTimeInterface $date
* @return Model\Venta\Reservation
* @throws Read
*/
public function getByBuyerAndDate(int $buyer_rut, DateTimeInterface $date): Model\Venta\Reservation
{
try {
return $this->process($this->reservationRepository->fetchByBuyerAndDate($buyer_rut, $date));
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
/**
* @param int $project_id
* @return array
@ -106,7 +129,7 @@ class Reservation extends Ideal\Service\API
try {
$broker = $this->brokerService->get($data['broker_rut']);
$reservation = $this->reservationRepository->edit($reservation, ['broker_rut' => $broker->rut]);
} catch (ServiceAction\Read $exception) {}
} catch (ServiceAction\Read) {}
}
} catch (Implement\Exception\EmptyResult) {
$buyerData = [];
@ -114,7 +137,7 @@ class Reservation extends Ideal\Service\API
if (!str_starts_with($key, 'buyer_')) {
continue;
}
$buyerData[substr($key, 6)] = $value;
$buyerData[substr($key, strlen('buyer_'))] = $value;
}
$this->personaService->add($buyerData);
if (array_key_exists('broker_rut', $data)) {
@ -186,11 +209,11 @@ class Reservation extends Ideal\Service\API
return $this->stateRepository->fetchByReservation($reservation_id);
})
);
$model->buyer = $this->personaService->getById($model->buyer->rut);
return $model;
}
protected function addUnits(Model\Venta\Reservation $reservation, array $units): void
{
//var_dump(__LINE__, $units);
foreach ($units as $unit_id => $value) {
try {
$unit = $this->unitService->getById($unit_id);
@ -203,7 +226,6 @@ class Reservation extends Ideal\Service\API
}
protected function addPromotions(Model\Venta\Reservation $reservation, array $promotions): void
{
var_dump(__LINE__, $promotions);
foreach ($promotions as $promotion_id) {
try {
$promotion = $this->promotionService->getById($promotion_id);