Implement search pago
This commit is contained in:
@ -202,6 +202,11 @@ WHERE `proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activ
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pie` = ?";
|
||||
return $this->fetchOne($query, [$pie_id]);
|
||||
}
|
||||
public function fetchIdByPie(int $pie_id): array
|
||||
{
|
||||
$query = "SELECT `id` FROM `{$this->getTable()}` WHERE `pie` = ?";
|
||||
return $this->connection->execute($query, [$pie_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
public function fetchByUnidad(string $unidad, string $tipo): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
@ -275,4 +280,36 @@ WHERE ptu.`proyecto` = ? AND tev.`descripcion` IN ('firmado por inmobiliaria', '
|
||||
GROUP BY a.`id`";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchIdByEscritura(int $escritura_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('id')
|
||||
->from($this->getTable())
|
||||
->where('escritura = ?');
|
||||
return $this->connection->execute($query, [$escritura_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
public function fetchIdBySubsidio(int $subsidio_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('id')
|
||||
->from($this->getTable())
|
||||
->where('subsidio = ?');
|
||||
return $this->connection->execute($query, [$subsidio_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
public function fetchIdByCredito(int $credito_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('id')
|
||||
->from($this->getTable())
|
||||
->where('credito = ?');
|
||||
return $this->connection->execute($query, [$credito_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
public function fetchIdByBono(int $bono_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('id')
|
||||
->from($this->getTable())
|
||||
->where('bono_pie = ?');
|
||||
return $this->connection->execute($query, [$bono_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
}
|
||||
|
@ -35,4 +35,21 @@ class BonoPie extends Ideal\Repository
|
||||
{
|
||||
return $this->update($model, ['valor', 'pago'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByValue(float $value): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('valor = ?');
|
||||
return $this->fetchMany($query, [$value]);
|
||||
}
|
||||
public function fetchByPago(int $pago_id): Model\Venta\BonoPie
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('pago = ?');
|
||||
return $this->fetchOne($query, [$pago_id]);
|
||||
}
|
||||
}
|
||||
|
@ -36,4 +36,21 @@ class Credito extends Ideal\Repository
|
||||
{
|
||||
return $this->update($model, ['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByValue(int $value): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('valor = ?');
|
||||
return $this->fetchMany($query, [$value]);
|
||||
}
|
||||
public function fetchByPago(int $pago_id): Model\Venta\Credito
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('pago = ?');
|
||||
return $this->fetchOne($query, [$pago_id]);
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +182,8 @@ ORDER BY p1.`fecha`, v1.`descripcion`";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('pie = ?');
|
||||
->where('pie = ?')
|
||||
->group('id');
|
||||
return $this->fetchMany($query, [$pie_id]);
|
||||
}
|
||||
public function fetchVigenteByPie(int $pie_id): array
|
||||
@ -192,7 +193,16 @@ FROM `{$this->getTable()}` a
|
||||
JOIN `pago` ON `pago`.`id` = a.`pago`
|
||||
JOIN (SELECT e1.* FROM `estado_pago` e1 JOIN (SELECT MAX(`id`) AS 'id', `pago` FROM `estado_pago` GROUP BY `pago`) e0 ON e0.`id` = e1.`id`) ep ON ep.`pago` = `pago`.`id`
|
||||
JOIN `tipo_estado_pago` tep ON tep.`id` = ep.`estado`
|
||||
WHERE a.`pie` = ? AND tep.`active` = 1";
|
||||
WHERE a.`pie` = ? AND tep.`active` = 1
|
||||
GROUP BY a.`id`";
|
||||
return $this->fetchMany($query, [$pie_id]);
|
||||
}
|
||||
public function fetchByPago(int $pago_id): Model\Venta\Cuota
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('pago = ?');
|
||||
return $this->fetchOne($query, [$pago_id]);
|
||||
}
|
||||
}
|
||||
|
@ -38,4 +38,21 @@ class Escritura extends Ideal\Repository
|
||||
{
|
||||
return $this->update($model, ['valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByValue(int $value): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('valor = ?');
|
||||
return $this->fetchMany($query, [$value]);
|
||||
}
|
||||
public function fetchByPago(int $pago_id): Model\Venta\Escritura
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('pago = ?');
|
||||
return $this->fetchOne($query, [$pago_id]);
|
||||
}
|
||||
}
|
||||
|
@ -100,4 +100,12 @@ FROM (
|
||||
WHERE venta_id = ?";
|
||||
return $this->fetchMany($query, [$venta_id]);
|
||||
}
|
||||
public function fetchByValue(int $value): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('valor = ? OR ROUND(valor/uf, 3) = ?');
|
||||
return $this->fetchMany($query, [$value, $value]);
|
||||
}
|
||||
}
|
||||
|
@ -56,4 +56,20 @@ class Pie extends Ideal\Repository
|
||||
->where('asociado = ?');
|
||||
return $this->fetchMany($query, [$pie_id]);
|
||||
}
|
||||
public function fetchByValue(float $value): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('valor = ?');
|
||||
return $this->fetchMany($query, [$value]);
|
||||
}
|
||||
public function fetchByReajuste(int $reajuste_id): Model\Venta\Pie
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('reajuste = ?');
|
||||
return $this->fetchOne($query, [$reajuste_id]);
|
||||
}
|
||||
}
|
||||
|
@ -40,4 +40,13 @@ class Subsidio extends Ideal\Repository
|
||||
{
|
||||
return $this->update($model, ['pago', 'subsidio'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByPago(int $pago_id): Model\Venta\Subsidio
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('subsidio = ? OR pago = ?');
|
||||
return $this->fetchOne($query, [$pago_id, $pago_id]);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,15 @@ class Search
|
||||
protected Venta $ventaService,
|
||||
protected Repository\Venta $ventaRepository,
|
||||
protected Repository\Venta\Unidad $unidadRepository,
|
||||
protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository) {}
|
||||
protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository,
|
||||
protected Repository\Venta\Pie $pieRepository,
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\Cuota $cuotaRepository,
|
||||
protected Repository\Venta\Credito $creditoRepository,
|
||||
protected Repository\Venta\Escritura $escrituraRepository,
|
||||
protected Repository\Venta\Subsidio $subsidioRepository,
|
||||
protected Repository\Venta\BonoPie $bonoPieRepository
|
||||
) {}
|
||||
|
||||
public function query(string $query, string $tipo): array
|
||||
{
|
||||
@ -65,27 +73,24 @@ class Search
|
||||
protected function findVentas(string $query, string $tipo): array
|
||||
{
|
||||
$tiposUnidades = $this->getTiposUnidades();
|
||||
if ($tipo === 'unidad') {
|
||||
$results = [];
|
||||
foreach ($tiposUnidades as $t) {
|
||||
$this->add($results, $this->findVentas($query, $t));
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
if (in_array($tipo, $tiposUnidades)) {
|
||||
return $this->findUnidad($query, $tipo);
|
||||
}
|
||||
if ($tipo === 'propietario') {
|
||||
return $this->findPropietario($query);
|
||||
}
|
||||
if ($tipo === 'precio_venta') {
|
||||
return $this->findPrecio($query);
|
||||
}
|
||||
if ($tipo === 'proyecto') {
|
||||
return $this->findProyecto($query);
|
||||
}
|
||||
if ($tipo === 'pago') {
|
||||
return $this->findPago($query);
|
||||
switch ($tipo) {
|
||||
case 'unidad':
|
||||
$results = [];
|
||||
foreach ($tiposUnidades as $t) {
|
||||
$this->add($results, $this->findVentas($query, $t));
|
||||
}
|
||||
return $results;
|
||||
case 'propietario':
|
||||
return $this->findPropietario($query);
|
||||
case 'precio_venta':
|
||||
return $this->findPrecio($query);
|
||||
case 'proyecto':
|
||||
return $this->findProyecto($query);
|
||||
case 'pago':
|
||||
return $this->findPago($query);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
@ -133,7 +138,134 @@ class Search
|
||||
}
|
||||
protected function findPago(string $query): array
|
||||
{
|
||||
return [];
|
||||
$methods = [
|
||||
'findPie',
|
||||
'findEscritura',
|
||||
'findSubsidio',
|
||||
'findCredito',
|
||||
'findPromociones',
|
||||
];
|
||||
$valor = str_replace(['$', '.', ','], ['', '', '.'], $query);
|
||||
$pagos = [];
|
||||
try {
|
||||
$pagos = $this->pagoRepository->fetchByValue($valor);
|
||||
} catch (EmptyResult) {}
|
||||
$results = [];
|
||||
foreach ($methods as $method) {
|
||||
$this->add($results, $this->{$method}($valor, $pagos));
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
protected function findPie(string $query, array $pagos): array
|
||||
{
|
||||
$results = [];
|
||||
try {
|
||||
$pies = $this->pieRepository->fetchByValue($query);
|
||||
foreach ($pies as $pie) {
|
||||
try {
|
||||
$this->add($results, [$this->ventaRepository->fetchIdByPie($pie->id)]);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
} catch (EmptyResult) {}
|
||||
$this->add($results, $this->findReajuste($query, $pagos));
|
||||
$this->add($results, $this->findCuota($query, $pagos));
|
||||
return $results;
|
||||
}
|
||||
protected function findReajuste(string $query, array $pagos): array
|
||||
{
|
||||
$results = [];
|
||||
foreach ($pagos as $pago) {
|
||||
try {
|
||||
$pie = $this->pieRepository->fetchByReajuste($pago->id);
|
||||
$this->add($results, [$this->ventaRepository->fetchIdByPie($pie->id)]);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
protected function findCuota(string $query, array $pagos): array
|
||||
{
|
||||
$results = [];
|
||||
foreach ($pagos as $pago) {
|
||||
try {
|
||||
$cuota = $this->cuotaRepository->fetchByPago($pago->id);
|
||||
$this->add($results, [$this->ventaRepository->fetchIdByPie($cuota->pie->id)]);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
protected function findEscritura(string $query, array $pagos): array
|
||||
{
|
||||
$results = [];
|
||||
try {
|
||||
$escrituras = $this->escrituraRepository->fetchByValue($query);
|
||||
foreach ($escrituras as $escritura) {
|
||||
try {
|
||||
$this->add($results, [$this->ventaRepository->fetchIdByEscritura($escritura->id)]);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
} catch (EmptyResult) {}
|
||||
foreach ($pagos as $pago) {
|
||||
try {
|
||||
$escritura = $this->escrituraRepository->fetchByPago($pago->id);
|
||||
$this->add($results, [$this->ventaRepository->fetchIdByEscritura($escritura->id)]);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
protected function findSubsidio(string $query, array $pagos): array
|
||||
{
|
||||
$results = [];
|
||||
foreach ($pagos as $pago) {
|
||||
try {
|
||||
$subsidio = $this->subsidioRepository->fetchByPago($pago->id);
|
||||
$this->add($results, [$this->ventaRepository->fetchIdBySubsidio($subsidio->id)]);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
protected function findCredito(string $query, array $pagos): array
|
||||
{
|
||||
$results = [];
|
||||
try {
|
||||
$creditos = $this->creditoRepository->fetchByValue($query);
|
||||
foreach ($creditos as $credito) {
|
||||
try {
|
||||
$this->add($results, [$this->ventaRepository->fetchIdByCredito($credito->id)]);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
} catch (EmptyResult) {}
|
||||
foreach ($pagos as $pago) {
|
||||
try {
|
||||
$credito = $this->creditoRepository->fetchByPago($pago->id);
|
||||
$this->add($results, [$this->ventaRepository->fetchIdByCredito($credito->id)]);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
protected function findPromociones(string $query, array $pagos): array
|
||||
{
|
||||
$results = [];
|
||||
$this->add($results, $this->findBonoPie($query, $pagos));
|
||||
return $results;
|
||||
}
|
||||
protected function findBonoPie(string $query, array $pagos): array
|
||||
{
|
||||
$results = [];
|
||||
try {
|
||||
$bonos = $this->bonoPieRepository->fetchByValue($query);
|
||||
foreach ($bonos as $bono) {
|
||||
try {
|
||||
$this->add($results, [$this->ventaRepository->fetchIdByBono($bono->id)]);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
} catch (EmptyResult) {}
|
||||
foreach ($pagos as $pago) {
|
||||
try {
|
||||
$bono = $this->bonoPieRepository->fetchByPago($pago->id);
|
||||
$this->add($results, [$this->ventaRepository->fetchIdByBono($bono->id)]);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected array $tipos;
|
||||
|
@ -76,6 +76,9 @@ class Cuota
|
||||
public function getByPie(int $pie_id): array
|
||||
{
|
||||
return $this->cuotaRepository->fetchByPie($pie_id);
|
||||
/*return array_filter($this->cuotaRepository->fetchByPie($pie_id), function(Model\Venta\Cuota $cuota) {
|
||||
return !in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado']);
|
||||
});*/
|
||||
}
|
||||
public function getVigenteByPie(int $pie_id): array
|
||||
{
|
||||
|
Reference in New Issue
Block a user