Fetch reservation with unit
This commit is contained in:
@ -71,9 +71,9 @@ class Reservations
|
||||
$output['errors'] []= $this->parseError($exception);
|
||||
}*/
|
||||
|
||||
if (count($input['reservations']) === count($output['reservations'])) {
|
||||
/*if (count($input['reservations']) === count($output['reservations'])) {
|
||||
$output['success'] = true;
|
||||
}
|
||||
}*/
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
@ -92,18 +92,57 @@ class Reservation extends Common\Ideal\Repository
|
||||
|
||||
/**
|
||||
* @param int $buyer_rut
|
||||
* @param int $unit_id
|
||||
* @param DateTimeInterface $date
|
||||
* @return Model\Venta\Reservation
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
public function fetchByBuyerAndDate(int $buyer_rut, DateTimeInterface $date): Model\Venta\Reservation
|
||||
public function fetchByBuyerAndUnitAndDate(int $buyer_rut, int $unit_id, DateTimeInterface $date): Model\Venta\Reservation
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from('reservations a')
|
||||
->joined('INNER JOIN reservation_details rd ON a.id = rd.reservation_id')
|
||||
->where('a.buyer_rut = :buyer_rut AND rd.unit_id = :unit_id AND a.date >= :date');
|
||||
return $this->fetchOne($query, ['buyer_rut' => $buyer_rut, 'unit_id' => $unit_id, 'date' => $date->sub(new DateInterval('P10D'))->format('Y-m-d')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $buyer_rut
|
||||
* @param int $project_id
|
||||
* @param DateTimeInterface $date
|
||||
* @return array
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
public function fetchByBuyerAndProjectAndDate(int $buyer_rut, int $project_id, DateTimeInterface $date): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from('reservations')
|
||||
->where('buyer_rut = :buyer_rut AND project_id = :project_id AND date >= :date');
|
||||
return $this->fetchMany($query, ['buyer_rut' => $buyer_rut, 'project_id' => $project_id, 'date' => $date->sub(new DateInterval('P10D'))->format('Y-m-d')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $buyer_rut
|
||||
* @param DateTimeInterface $date
|
||||
* @return array
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
public function fetchByBuyerAndDate(int $buyer_rut, DateTimeInterface $date): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from('reservations')
|
||||
->where('buyer_rut = :buyer_rut AND date >= :date');
|
||||
return $this->fetchOne($query, ['buyer_rut' => $buyer_rut, 'date' => $date->sub(new DateInterval('P10D'))->format('Y-m-d')]);
|
||||
return $this->fetchMany($query, ['buyer_rut' => $buyer_rut, 'date' => $date->sub(new DateInterval('P10D'))->format('Y-m-d')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $project_id
|
||||
* @return array
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
public function fetchByProject(int $project_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -145,6 +184,7 @@ class Reservation extends Common\Ideal\Repository
|
||||
return $this->fetchMany($query, ['project_id' => $project_id,
|
||||
'state' => $state]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $project_id
|
||||
* @return array
|
||||
|
@ -123,7 +123,7 @@ class Reservation extends Ideal\Service\API
|
||||
$date = new DateTimeImmutable($data['date']);
|
||||
} catch (DateMalformedStringException) {}
|
||||
try {
|
||||
$reservation = $this->reservationRepository->fetchByBuyerAndDate($data['buyer_rut'], $date);
|
||||
$reservation = $this->reservationRepository->fetchByBuyerAndUnitAndDate($data['buyer_rut'], (int) $data['units'][0], $date);
|
||||
|
||||
if (array_key_exists('broker_rut', $data) and $data['broker_rut'] !== '') {
|
||||
try {
|
||||
|
Reference in New Issue
Block a user