Reservation fixes
This commit is contained in:
@ -234,7 +234,7 @@ class Reservation extends Common\Ideal\Repository
|
||||
}
|
||||
try {
|
||||
$queryCheck = $this->connection->getQueryBuilder()
|
||||
->select('id')
|
||||
->select('reference_id')
|
||||
->from('reservation_details')
|
||||
->where('reservation_id = :id AND type = :type');
|
||||
$statementCheck = $this->connection->execute($queryCheck, [
|
||||
@ -242,9 +242,12 @@ class Reservation extends Common\Ideal\Repository
|
||||
'type' => Model\Venta\Reservation\Detail\Type::Broker->value
|
||||
]);
|
||||
$result = $statementCheck->fetch(PDO::FETCH_ASSOC);
|
||||
$new_id = $reservation->broker->id;
|
||||
$reservation->broker = $this->brokerRepository->fetchById($result['id']);
|
||||
$this->editBroker($reservation, ['broker_id' => $new_id]);
|
||||
if ($result === false) {
|
||||
throw new PDOException();
|
||||
}
|
||||
$new_id = $reservation->broker->rut;
|
||||
$reservation->broker = $this->brokerRepository->fetchById($result['reference_id']);
|
||||
$this->editBroker($reservation, ['broker_rut' => $new_id]);
|
||||
} catch (PDOException) {
|
||||
$queryInsert = $this->connection->getQueryBuilder()
|
||||
->insert()
|
||||
@ -254,7 +257,7 @@ class Reservation extends Common\Ideal\Repository
|
||||
$this->connection->execute($queryInsert, [
|
||||
'reservation_id' => $reservation->id,
|
||||
'type' => Model\Venta\Reservation\Detail\Type::Broker->value,
|
||||
'reference_id' => $reservation->broker->id
|
||||
'reference_id' => $reservation->broker->rut
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -386,20 +389,20 @@ class Reservation extends Common\Ideal\Repository
|
||||
}
|
||||
protected function editBroker(Model\Venta\Reservation &$reservation, array $new_data): void
|
||||
{
|
||||
if (!array_key_exists('broker_id', $new_data) or $new_data['broker_id'] === $reservation->broker->id) {
|
||||
if (!array_key_exists('broker_rut', $new_data) or $new_data['broker_rut'] === $reservation->broker->rut) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->update('reservation_details')
|
||||
->set('reference_id = :broker_id')
|
||||
->set('reference_id = :broker_rut')
|
||||
->where('reservation_id = :id AND type = :type');
|
||||
$this->connection->execute($query, [
|
||||
'id' => $reservation->id,
|
||||
'type' => Model\Venta\Reservation\Detail\Type::Broker->value,
|
||||
'broker_id' => $new_data['broker_id']
|
||||
'broker_rut' => $new_data['broker_rut']
|
||||
]);
|
||||
$reservation->broker = $this->brokerRepository->fetchById($new_data['broker_id']);
|
||||
$reservation->broker = $this->brokerRepository->fetchById($new_data['broker_rut']);
|
||||
} catch (PDOException) {}
|
||||
}
|
||||
protected function editPromotions(Model\Venta\Reservation &$reservation, array $new_data): void
|
||||
|
Reference in New Issue
Block a user