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

@ -93,7 +93,7 @@ class Contract extends Common\Ideal\Repository
->select('a.*')
->from("{$this->getTable()} a")
->joined($this->statusJoin())
->where('a.broker_rut = :broker_rut AND bcs.state = :state');
->where('a.broker_rut = :broker_rut AND bcs.type = :state');
return $this->fetchMany($query, ['broker_rut' => $brokerRut, 'state' => Model\Proyecto\Broker\Contract\Type::ACTIVE]);
}
@ -108,8 +108,8 @@ class Contract extends Common\Ideal\Repository
->select('a.*')
->from("{$this->getTable()} a")
->joined($this->statusJoin())
->where('a.proyecto_id = :proyecto_id AND bcs.state = :state');
return $this->fetchMany($query, ['proyecto_id' => $projectId, 'state' => Model\Proyecto\Broker\Contract\State\Type::ACTIVE->value]);
->where('a.project_id = :project_id AND bcs.type = :state');
return $this->fetchMany($query, ['project_id' => $projectId, 'state' => Model\Proyecto\Broker\Contract\State\Type::ACTIVE->value]);
}
/**

View File

@ -212,7 +212,7 @@ class Promotion extends Common\Ideal\Repository
->joined('LEFT OUTER JOIN proyecto_tipo_unidad ptu1 ON ptu.id = unidad.pt')
->where('(pp.project_id = :project_id OR put.project_id = :project_id OR ptu.proyecto = :project_id OR ptu1.proyecto = :project_id) AND a.state = :state')
->group('a.id');
return $this->fetchMany($query, ['project_id' => $project_id, 'state' => Model\Venta\Promotion\State::ACTIVE]);
return $this->fetchMany($query, ['project_id' => $project_id, 'state' => Model\Venta\Promotion\State::ACTIVE->value]);
}
/**

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) {}

View File

@ -19,12 +19,16 @@ class State extends Common\Ideal\Repository
public function create(?array $data = null): Model\Venta\Reservation\State
{
$map = (new Common\Implement\Repository\MapperParser(['type']))
$map = (new Common\Implement\Repository\MapperParser())
->register('reservation_id', (new Common\Implement\Repository\Mapper())
->setProperty('reservation')
->setFunction(function($data) {
return $this->reservationRepository->fetchById($data['reservation_id']);
}))
->register('type', (new Common\Implement\Repository\Mapper())
->setFunction(function($data) {
return Model\Venta\Reservation\State\Type::from($data['type']);
}))
->register('date', new Common\Implement\Repository\Mapper\DateTime('date'));
return $this->parseData(new Model\Venta\Reservation\State(), $data, $map);
}
@ -32,7 +36,7 @@ class State extends Common\Ideal\Repository
{
$model->id = $this->saveNew(
['reservation_id', 'date', 'type'],
[$model->reservation->id, $model->date->format('Y-m-d'), $model->type]
[$model->reservation->id, $model->date->format('Y-m-d'), $model->type->value]
);
return $model;
}