This commit is contained in:
Juan Pablo Vial
2025-08-22 09:28:53 -04:00
parent 78222eb9f1
commit 454ba41d9c
26 changed files with 1036 additions and 135 deletions

View File

@ -45,15 +45,17 @@ class Reservation extends Common\Ideal\Repository
}
public function save(Common\Define\Model $model): Model\Venta\Reservation
{
$model->id = $this->saveNew([
'project_id',
'buyer_rut',
'date'
], [
$model->project->id,
$model->buyer->rut,
$model->date->format('Y-m-d')
]);
if (!isset($model->id)) {
$model->id = $this->saveNew([
'project_id',
'buyer_rut',
'date'
], [
$model->project->id,
$model->buyer->rut,
$model->date->format('Y-m-d')
]);
}
$this->saveUnits($model);
$this->savePromotions($model);
$this->saveBroker($model);
@ -440,10 +442,10 @@ class Reservation extends Common\Ideal\Repository
$query = $this->connection->getQueryBuilder()
->select()
->from('reservation_details')
->where('reservation_id = :id AND type = ?');
->where('reservation_id = :id AND type = :type');
$statement = $this->connection->execute($query, [
'id' => $reservation->id,
Model\Venta\Reservation\Detail\Type::Unit->value
'type' =>Model\Venta\Reservation\Detail\Type::Unit->value
]);
while ($result = $statement->fetch(PDO::FETCH_ASSOC)) {
@ -479,6 +481,13 @@ class Reservation extends Common\Ideal\Repository
}
return $reservation;
}
/**
* @param Model\Venta\Reservation $reservation
* @param array $new_data
* @return Model\Venta\Reservation
* @throws Common\Implement\Exception\EmptyResult
*/
protected function fetchBroker(Model\Venta\Reservation &$reservation, array $new_data): Model\Venta\Reservation
{
if (!array_key_exists('broker_id', $new_data)) {
@ -492,6 +501,9 @@ class Reservation extends Common\Ideal\Repository
'type' => Model\Venta\Reservation\Detail\Type::Broker->value
]);
$result = $statement->fetch(PDO::FETCH_ASSOC);
if ($result === false) {
throw new Common\Implement\Exception\EmptyResult($query);
}
$reservation->broker = $this->brokerRepository->fetchById($result['reference_id']);
} catch (PDOException) {}