Cleanup
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
@ -128,6 +129,12 @@ class Venta extends Ideal\Repository
|
||||
}
|
||||
return $this->parseData(new Model\Venta(), $data, $map);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @return Model\Venta
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function save(Define\Model $model): Model\Venta
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
@ -142,6 +149,13 @@ class Venta extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Model\Venta
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta
|
||||
{
|
||||
return $this->update($model, ['propietario', 'propiedad', 'pie', 'bono_pie', 'credito', 'escritura', 'subsidio', 'escriturado',
|
||||
@ -149,6 +163,11 @@ class Venta extends Ideal\Repository
|
||||
'relacionado', 'promocion', 'resciliacion', 'devolucion'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -163,6 +182,12 @@ class Venta extends Ideal\Repository
|
||||
->group('a.id');
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdsByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -177,6 +202,12 @@ class Venta extends Ideal\Repository
|
||||
->group('a.id');
|
||||
return $this->fetchIds($query, [$proyecto_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchActivaByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -191,6 +222,13 @@ class Venta extends Ideal\Repository
|
||||
->group('a.id');
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $proyecto_nombre
|
||||
* @param int $unidad_descripcion
|
||||
* @return Model\Venta
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -205,6 +243,12 @@ class Venta extends Ideal\Repository
|
||||
->where('`proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`');
|
||||
return $this->fetchOne($query, [$proyecto_nombre, $unidad_descripcion]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pie_id
|
||||
* @return Model\Venta
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPie(int $pie_id): Model\Venta
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -213,6 +257,12 @@ class Venta extends Ideal\Repository
|
||||
->where('pie = ?');
|
||||
return $this->fetchOne($query, [$pie_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pie_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdByPie(int $pie_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -221,6 +271,13 @@ class Venta extends Ideal\Repository
|
||||
->where('pie = ?');
|
||||
return $this->fetchId($query, [$pie_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unidad
|
||||
* @param string $tipo
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByUnidad(string $unidad, string $tipo): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -233,6 +290,12 @@ class Venta extends Ideal\Repository
|
||||
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
|
||||
return $this->fetchMany($query, [$unidad, $tipo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $unidad_id
|
||||
* @return Model\Venta
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByUnidadId(int $unidad_id): Model\Venta
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -242,6 +305,13 @@ class Venta extends Ideal\Repository
|
||||
->where('pu.unidad = ?');
|
||||
return $this->fetchOne($query, [$unidad_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unidad
|
||||
* @param string $tipo
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdsByUnidad(string $unidad, string $tipo): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -254,6 +324,12 @@ class Venta extends Ideal\Repository
|
||||
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
|
||||
return $this->fetchIds($query, [$unidad, $tipo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $precio
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPrecio(string $precio): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -262,6 +338,12 @@ class Venta extends Ideal\Repository
|
||||
->where('valor_uf = ?');
|
||||
return $this->fetchMany($query, [$precio]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $precio
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdsByPrecio(string $precio): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -270,6 +352,13 @@ class Venta extends Ideal\Repository
|
||||
->where('valor_uf = ?');
|
||||
return $this->fetchIds($query, [$precio]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propietario_rut
|
||||
* @param int $propiedad_id
|
||||
* @return Model\Venta
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPropietarioAndPropiedad(int $propietario_rut, int $propiedad_id): Model\Venta
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -278,6 +367,12 @@ class Venta extends Ideal\Repository
|
||||
->where('propietario = ? AND propiedad = ?');
|
||||
return $this->fetchOne($query, [$propietario_rut, $propiedad_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $propietario
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPropietario(string $propietario): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -289,6 +384,12 @@ class Venta extends Ideal\Repository
|
||||
OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario");
|
||||
return $this->fetchMany($query, [':propietario' => "%{$propietario}%"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $propietario
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdsByPropietario(string $propietario): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -302,6 +403,12 @@ class Venta extends Ideal\Repository
|
||||
OR CONCAT_WS('-', rut, dv) = :rut");
|
||||
return $this->fetchIds($query, [':propietario' => "%{$propietario}%", ':rut' => $propietario]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $propietario
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPropietarioNombreCompleto(string $propietario): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -311,6 +418,12 @@ class Venta extends Ideal\Repository
|
||||
->where("CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?");
|
||||
return $this->fetchMany($query, [$propietario]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchEscriturasByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -325,6 +438,12 @@ class Venta extends Ideal\Repository
|
||||
->group('a.id');
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $escritura_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdByEscritura(int $escritura_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -333,6 +452,12 @@ class Venta extends Ideal\Repository
|
||||
->where('escritura = ?');
|
||||
return $this->fetchId($query, [$escritura_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subsidio_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdBySubsidio(int $subsidio_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -341,6 +466,12 @@ class Venta extends Ideal\Repository
|
||||
->where('subsidio = ?');
|
||||
return $this->fetchId($query, [$subsidio_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $credito_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdByCredito(int $credito_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -349,6 +480,12 @@ class Venta extends Ideal\Repository
|
||||
->where('credito = ?');
|
||||
return $this->fetchId($query, [$credito_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $bono_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdByBono(int $bono_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -357,6 +494,11 @@ class Venta extends Ideal\Repository
|
||||
->where('bono_pie = ?');
|
||||
return $this->fetchId($query, [$bono_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return array
|
||||
*/
|
||||
public function fetchByIdForSearch(int $venta_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -382,6 +524,11 @@ class Venta extends Ideal\Repository
|
||||
->limit(1);
|
||||
return $this->connection->execute($query, [$venta_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return array
|
||||
*/
|
||||
public function fetchByIdForList(int $venta_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -404,20 +551,33 @@ class Venta extends Ideal\Repository
|
||||
return $this->connection->execute($query, [$venta_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array|null $data
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
protected function fetchIds(string $query, ?array $data = null): array
|
||||
{
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($results === false) {
|
||||
throw new Implement\Exception\EmptyResult($query);
|
||||
try {
|
||||
return $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Implement\Exception\EmptyResult($query, $exception);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array|null $data
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
protected function fetchId(string $query, ?array $data = null): array
|
||||
{
|
||||
$results = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
|
||||
if ($results === false) {
|
||||
throw new Implement\Exception\EmptyResult($query);
|
||||
try {
|
||||
return $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Implement\Exception\EmptyResult($query, $exception);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user