Correcciones
This commit is contained in:
@ -27,10 +27,10 @@ class Contract extends Common\Ideal\Repository
|
||||
return $this->brokerRepository->fetchById($data['broker_rut']);
|
||||
})
|
||||
)
|
||||
->register('proyecto_id', (new Common\Implement\Repository\Mapper())
|
||||
->setProperty('proyecto')
|
||||
->register('project_id', (new Common\Implement\Repository\Mapper())
|
||||
->setProperty('project')
|
||||
->setFunction(function($data) {
|
||||
return $this->proyectoRepository->fetchById($data['proyecto_id']);
|
||||
return $this->proyectoRepository->fetchById($data['project_id']);
|
||||
})
|
||||
);
|
||||
return $this->parseData(new Model\Proyecto\Broker\Contract(), $data, $map);
|
||||
@ -38,8 +38,8 @@ class Contract extends Common\Ideal\Repository
|
||||
public function save(Common\Define\Model $model): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['broker_rut', 'proyecto_id', 'commission'],
|
||||
[$model->broker->rut, $model->proyecto->id, $model->commission]);
|
||||
['broker_rut', 'project_id', 'commission'],
|
||||
[$model->broker->rut, $model->project->id, $model->commission]);
|
||||
return $model;
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ class Contract extends Common\Ideal\Repository
|
||||
*/
|
||||
public function edit(Common\Define\Model $model, array $new_data): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
return $this->update($model, ['broker_rut', 'proyecto_id', 'commission'], $new_data);
|
||||
return $this->update($model, ['broker_rut', 'project_id', 'commission'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,17 +69,17 @@ class Contract extends Common\Ideal\Repository
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @param int $projectId
|
||||
* @return array
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByProject(int $proyecto_id): array
|
||||
public function fetchByProject(int $projectId): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('proyecto_id = :proyecto_id');
|
||||
return $this->fetchMany($query, ['proyecto_id' => $proyecto_id]);
|
||||
->where('project_id = :project_id');
|
||||
return $this->fetchMany($query, ['project_id' => $projectId]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,38 +98,38 @@ class Contract extends Common\Ideal\Repository
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @param int $projectId
|
||||
* @return array
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchActiveByProject(int $proyecto_id): array
|
||||
public function fetchActiveByProject(int $projectId): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->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' => $proyecto_id, 'state' => Model\Proyecto\Broker\Contract\Type::ACTIVE]);
|
||||
return $this->fetchMany($query, ['proyecto_id' => $projectId, 'state' => Model\Proyecto\Broker\Contract\State\Type::ACTIVE->value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @param int $projectId
|
||||
* @param int $brokerRut
|
||||
* @return Model\Proyecto\Broker\Contract
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchActiveByProjectAndBroker(int $proyecto_id, int $brokerRut): Model\Proyecto\Broker\Contract
|
||||
public function fetchActiveByProjectAndBroker(int $projectId, int $brokerRut): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->statusJoin())
|
||||
->where('a.proyecto_id = :proyecto_id AND a.broker_rut = :broker_rut AND bcs.state = :state');
|
||||
return $this->fetchOne($query, ['proyecto_id' => $proyecto_id, 'broker_rut' => $brokerRut, 'state' => Model\Proyecto\Broker\Contract\Type::ACTIVE]);
|
||||
->where('a.project_id = :project_id AND a.broker_rut = :broker_rut AND bcs.type = :state');
|
||||
return $this->fetchOne($query, ['project_id' => $projectId, 'broker_rut' => $brokerRut, 'state' => Model\Proyecto\Broker\Contract\State\Type::ACTIVE->value]);
|
||||
}
|
||||
|
||||
protected function statusJoin(): string
|
||||
{
|
||||
return 'INNER JOIN (SELECT bcs1.* FROM broker_contract_states bcs1 INNER JOIN (SELECT MAX(id) AS id, contract_id FROM broker_contract_states GROUP BY contract_id) bcs0 ON bcs0.id = bcs1.id) bcs ON bcs.contract = a.id';
|
||||
return 'INNER JOIN (SELECT bcs1.* FROM broker_contract_states bcs1 INNER JOIN (SELECT MAX(id) AS id, contract_id FROM broker_contract_states GROUP BY contract_id) bcs0 ON bcs0.id = bcs1.id) bcs ON bcs.contract_id = a.id';
|
||||
}
|
||||
}
|
||||
|
@ -14,23 +14,27 @@ class State extends Common\Ideal\Repository
|
||||
|
||||
public function getTable(): string
|
||||
{
|
||||
return 'brokers_contract_states';
|
||||
return 'broker_contract_states';
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Proyecto\Broker\Contract\State
|
||||
{
|
||||
$map = (new Common\Implement\Repository\MapperParser(['type']))
|
||||
$map = (new Common\Implement\Repository\MapperParser())
|
||||
->register('contract_id', (new Common\Implement\Repository\Mapper())
|
||||
->setProperty('contract')
|
||||
->setFunction(function($data) {
|
||||
return $this->contractRepository->fetchById($data['contract_id']);
|
||||
}))
|
||||
->register('type', (new Common\Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return Model\Proyecto\Broker\Contract\State\Type::from($data['type']);
|
||||
}))
|
||||
->register('date', new Common\Implement\Repository\Mapper\DateTime('date'));
|
||||
return $this->parseData(new Model\Proyecto\Broker\Contract\State(), $data, $map);
|
||||
}
|
||||
public function save(Common\Define\Model $model): Model\Proyecto\Broker\Contract\State
|
||||
{
|
||||
$model->id = $this->saveNew(['contract_id', 'date', 'type'], [$model->contract->id, $model->date->format('Y-m-d'), $model->type]);
|
||||
$model->id = $this->saveNew(['contract_id', 'date', 'type'], [$model->contract->id, $model->date->format('Y-m-d'), $model->type->value]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Common\Define\Model $model, array $new_data): Model\Proyecto\Broker\Contract\State
|
||||
@ -38,6 +42,11 @@ class State extends Common\Ideal\Repository
|
||||
return $this->update($model, ['contract_id', 'date', 'type'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $contract_id
|
||||
* @return array
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByContract(int $contract_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -46,6 +55,12 @@ class State extends Common\Ideal\Repository
|
||||
->where('contract_id = :contract_id');
|
||||
return $this->fetchMany($query, ['contract_id' => $contract_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $contract_id
|
||||
* @return Model\Proyecto\Broker\Contract\State
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchActiveByContract(int $contract_id): Model\Proyecto\Broker\Contract\State
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
Reference in New Issue
Block a user