Implement search pago
This commit is contained in:
@ -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