Search update and optimization
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDO;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -155,6 +155,19 @@ WHERE ptu.`proyecto` = ? AND tev.`activa`
|
||||
GROUP BY a.`id`";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchIdsByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT a.`id`
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
WHERE ptu.`proyecto` = ? AND tev.`activa`
|
||||
GROUP BY a.`id`";
|
||||
return $this->connection->execute($query, [$proyecto_id])->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
public function fetchActivaByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
@ -197,11 +210,27 @@ FROM `{$this->getTable()}` a
|
||||
WHERE `unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?";
|
||||
return $this->fetchMany($query, [$unidad, $tipo]);
|
||||
}
|
||||
public function fetchIdsByUnidad(string $unidad, string $tipo): array
|
||||
{
|
||||
$query = "SELECT a.id
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad`
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
|
||||
WHERE `unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?";
|
||||
return $this->connection->execute($query, [$unidad, $tipo])->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
public function fetchByPrecio(string $precio): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `valor_uf` = ?";
|
||||
return $this->fetchMany($query, [$precio]);
|
||||
}
|
||||
public function fetchIdsByPrecio(string $precio): array
|
||||
{
|
||||
$query = "SELECT `id` FROM `{$this->getTable()}` WHERE `valor_uf` = ?";
|
||||
return $this->connection->execute($query, [$precio])->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
public function fetchByPropietario(string $propietario): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
@ -212,6 +241,16 @@ WHERE CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario
|
||||
OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario";
|
||||
return $this->fetchMany($query, [':propietario' => "%{$propietario}%"]);
|
||||
}
|
||||
public function fetchIdsByPropietario(string $propietario): array
|
||||
{
|
||||
$query = "SELECT a.id
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propietario` ON `propietario`.`rut` = a.`propietario`
|
||||
WHERE CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario OR `propietario`.`nombres` LIKE :propietario
|
||||
OR `propietario`.`apellido_paterno` LIKE :propietario OR `propietario`.`apellido_materno` LIKE :propietario
|
||||
OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario";
|
||||
return $this->connection->execute($query, [':propietario' => "%{$propietario}%"])->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
public function fetchByPropietarioNombreCompleto(string $propietario): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use PDO;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -117,6 +118,20 @@ class Unidad extends Ideal\Repository
|
||||
->where("a.`descripcion` LIKE ? AND tu.`descripcion` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)");
|
||||
return $this->fetchMany($query, [$descripcion, $tipo]);
|
||||
}
|
||||
public function fetchDisponiblesIdsByDescripcionAndTipo(string $descripcion, string $tipo): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.id')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined("JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
|
||||
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
|
||||
LEFT OUTER JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id`
|
||||
LEFT OUTER JOIN `venta` ON `venta`.`propiedad` = pu.`propiedad`
|
||||
LEFT OUTER JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) as 'id', `venta` FROM `estado_venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id`
|
||||
LEFT OUTER JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`")
|
||||
->where("a.`descripcion` LIKE ? AND tu.`descripcion` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)");
|
||||
return $this->connection->execute($query, [$descripcion, $tipo])->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
protected function joinProrrateo(): string
|
||||
{
|
||||
|
Reference in New Issue
Block a user