Cleanup logs, fixed add Venta, fixed search
This commit is contained in:
20
app/src/Controller/API/Search.php
Normal file
20
app/src/Controller/API/Search.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Search
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function query(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Search $service): ResponseInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$results = $service->query($data['query'], $data['tipo']);
|
||||
$output = compact('results');
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -1,17 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use PDOException;
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Ideal\Controller;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\withRedis;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class Ventas
|
||||
class Ventas extends Controller
|
||||
{
|
||||
use withJson, withRedis;
|
||||
|
||||
@ -55,6 +57,9 @@ class Ventas
|
||||
Service\Venta $service, int $venta_id): ResponseInterface
|
||||
{
|
||||
$redisKey = "venta:{$venta_id}";
|
||||
$output = [
|
||||
'venta' => null
|
||||
];
|
||||
try {
|
||||
$venta = $this->fetchRedis($redisService, $redisKey);
|
||||
$output = compact('venta');
|
||||
@ -64,12 +69,7 @@ class Ventas
|
||||
$output = compact('venta');
|
||||
$this->saveRedis($redisService, $redisKey, $venta);
|
||||
} catch (EmptyResult $exception) {
|
||||
$output = [
|
||||
'error' => [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
|
||||
]
|
||||
];
|
||||
$this->logger->notice($exception);
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
@ -178,14 +178,20 @@ class Ventas
|
||||
$data = $request->getParsedBody();
|
||||
$output = [
|
||||
'status' => false,
|
||||
'venta_id' => null,
|
||||
'errors' => []
|
||||
];
|
||||
try {
|
||||
$venta = $ventaService->add($data);
|
||||
$this->saveRedis($redisService, "venta:{$venta->id}", $venta);
|
||||
$output['venta_id'] = $venta->id;
|
||||
$output['status'] = true;
|
||||
} catch (\Exception $exception) {
|
||||
$output['errors'] = $exception;
|
||||
} catch (EmptyResult | PDOException $exception) {
|
||||
$output['errors'] = [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => $exception->getMessage(),
|
||||
'stack' => $exception->getTraceAsString()
|
||||
];
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
@ -13,11 +13,4 @@ class Search
|
||||
$post = $request->getParsedBody() ?? '';
|
||||
return $view->render($response, 'search', compact('post', 'query', 'tipo'));
|
||||
}
|
||||
public function query(ServerRequestInterface $request, ResponseInterface $response, Service\Search $service): ResponseInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$results = $service->query($data['query'], $data['tipo']);
|
||||
$response->getBody()->write(json_encode(compact('results')));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class NotFound
|
||||
try {
|
||||
return $handler->handle($request);
|
||||
} catch (HttpNotFoundException $exception) {
|
||||
$this->logger->warning($exception);
|
||||
$this->logger->notice($exception);
|
||||
$response = $this->responseFactory->createResponse(404);
|
||||
if (str_contains($request->getUri()->getPath(), '/api')) {
|
||||
return $response;
|
||||
|
@ -19,8 +19,8 @@ class Venta extends Ideal\Model
|
||||
public float $uf;
|
||||
protected ?Pago $resciliacion;
|
||||
|
||||
public array $estados;
|
||||
public Venta\EstadoVenta $currentEstado;
|
||||
public ?array $estados;
|
||||
public ?Venta\EstadoVenta $currentEstado;
|
||||
|
||||
public function propietario(): Venta\Propietario
|
||||
{
|
||||
@ -63,7 +63,7 @@ class Venta extends Ideal\Model
|
||||
if (!isset($this->estados)) {
|
||||
$this->estados = $this->runFactory('estados');
|
||||
}
|
||||
return $this->estados;
|
||||
return $this->estados ?? [];
|
||||
}
|
||||
public function currentEstado(): ?Venta\EstadoVenta
|
||||
{
|
||||
|
@ -115,13 +115,15 @@ class Venta extends Ideal\Repository
|
||||
->register('fecha_ingreso', new Implement\Repository\Mapper\DateTime('fecha_ingreso', 'fechaIngreso'))
|
||||
//->register('avalchile')
|
||||
//->register('agente')
|
||||
->register('resciliacion', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->pagoService, 'getById'])
|
||||
->setArgs(['pago_id' => $data['resciliacion']])))
|
||||
->register('relacionado', new Implement\Repository\Mapper\Boolean('relacionado'));
|
||||
//->register('promocion')
|
||||
//->register('devolucion');
|
||||
if (array_key_exists('resciliacion', $data)) {
|
||||
$map = $map->register('resciliacion', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->pagoService, 'getById'])
|
||||
->setArgs(['pago_id' => $data['resciliacion']])));
|
||||
}
|
||||
return $this->parseData(new Model\Venta(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\Venta
|
||||
@ -147,7 +149,17 @@ class Venta extends Ideal\Repository
|
||||
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('JOIN propiedad_unidad pu ON pu.propiedad = a.propiedad')
|
||||
->joined('JOIN unidad ON unidad.id = pu.unidad AND pu.principal = 1')
|
||||
->joined('JOIN proyecto_tipo_unidad ptu ON ptu.id = unidad.pt')
|
||||
->joined('JOIN (SELECT ev1.* FROM estado_venta ev1 JOIN (SELECT MAX(id) AS id, venta FROM estado_venta GROUP BY venta) ev0 ON ev0.id = ev1.id) ev ON ev.venta = a.id')
|
||||
->joined('JOIN tipo_estado_venta tev ON tev.id = ev.estado')
|
||||
->where('ptu.proyecto = ? AND tev.activa')
|
||||
->group('a.id');
|
||||
/*$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
||||
@ -155,12 +167,22 @@ FROM `{$this->getTable()}` a
|
||||
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`";
|
||||
GROUP BY a.`id`";*/
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchIdsByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT a.`id`
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.id')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('JOIN propiedad_unidad pu ON pu.propiedad = a.propiedad')
|
||||
->joined('JOIN unidad ON unidad.id = pu.unidad AND unidad.pt')
|
||||
->joined('proyecto_tipo_unidad ptu ON ptu.id = unidad.pt')
|
||||
->joined('JOIN (SELECT ev1.* FROM estado_venta ev1 JOIN (SELECT MAX(id) AS id, venta FROM estado_venta GROUP BY venta) ev0 ON ev0.id = ev1.id) ev ON ev.venta = a.id')
|
||||
->joined('JOIN tipo_estado_venta tev ON tev.id = ev.estado')
|
||||
->where('ptu.proyecto = ? AND tev.activa')
|
||||
->group('a.id');
|
||||
/*$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
|
||||
@ -168,12 +190,22 @@ FROM `{$this->getTable()}` a
|
||||
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`";
|
||||
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.*
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
|
||||
->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1')
|
||||
->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
|
||||
->joined("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`")
|
||||
->joined('JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`')
|
||||
->where('WHERE ptu.`proyecto` = ? AND tev.`activa`')
|
||||
->group('a.id');
|
||||
/*$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
||||
@ -181,12 +213,22 @@ FROM `{$this->getTable()}` a
|
||||
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`";
|
||||
GROUP BY a.`id`";*/
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select("a.*")
|
||||
->from("`{$this->getTable()}` a")
|
||||
->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
|
||||
->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1')
|
||||
->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
|
||||
->joined('JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto`')
|
||||
->joined("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`")
|
||||
->joined('JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`')
|
||||
->where('WHERE `proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`');
|
||||
/*$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
||||
@ -194,82 +236,147 @@ FROM `{$this->getTable()}` a
|
||||
JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto`
|
||||
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 `proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`";
|
||||
WHERE `proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`";*/
|
||||
return $this->fetchOne($query, [$proyecto_nombre, $unidad_descripcion]);
|
||||
}
|
||||
public function fetchByPie(int $pie_id): Model\Venta
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pie` = ?";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->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` = ?";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->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.*
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
|
||||
->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad`')
|
||||
->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
|
||||
->joined('JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`')
|
||||
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
|
||||
/*$query = "SELECT a.*
|
||||
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` = ?";
|
||||
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
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.id')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
|
||||
->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad`')
|
||||
->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
|
||||
->joined('JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`')
|
||||
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
|
||||
/*$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` = ?";
|
||||
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` = ?";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->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` = ?";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('id')
|
||||
->from($this->getTable())
|
||||
->where('valor_uf = ?');
|
||||
return $this->connection->execute($query, [$precio])->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
public function fetchByPropietarioAndPropiedad(int $propietario_rut, int $propiedad_id): Model\Venta
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('propietario = ? AND propiedad = ?');
|
||||
return $this->fetchOne($query, [$propietario_rut, $propiedad_id]);
|
||||
}
|
||||
public function fetchByPropietario(string $propietario): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('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");
|
||||
/*$query = "SELECT a.*
|
||||
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";
|
||||
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
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.id')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('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");
|
||||
/*$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";
|
||||
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.*
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('JOIN `propietario` ON `propietario`.`rut` = a.`propietario`')
|
||||
->where("CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?");
|
||||
/*$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propietario` ON `propietario`.`rut` = a.`propietario`
|
||||
WHERE CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?";
|
||||
WHERE CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?";*/
|
||||
return $this->fetchMany($query, [$propietario]);
|
||||
}
|
||||
public function fetchEscriturasByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT DISTINCT a.*
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('DISTINCT a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
|
||||
->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad`')
|
||||
->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`id`')
|
||||
->joined("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`")
|
||||
->joined('JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`')
|
||||
->where("ptu.`proyecto` = ? AND tev.`descripcion` IN ('firmado por inmobiliaria', 'escriturando')")
|
||||
->group('a.id');
|
||||
/*$query = "SELECT DISTINCT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad`
|
||||
@ -277,7 +384,7 @@ FROM `{$this->getTable()}` a
|
||||
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.`descripcion` IN ('firmado por inmobiliaria', 'escriturando')
|
||||
GROUP BY a.`id`";
|
||||
GROUP BY a.`id`";*/
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchIdByEscritura(int $escritura_id): array
|
||||
|
@ -65,7 +65,11 @@ class Search
|
||||
foreach ($queries as $q) {
|
||||
$this->add($results, $this->findVentas($q, $tipo));
|
||||
if (in_array($tipo, $tiposUnidades)) {
|
||||
$this->add($results, $this->findUnidadesDisponibles($q, $tipo), false);
|
||||
$disponibles = $this->findUnidadesDisponibles($q, $tipo);
|
||||
if (count($disponibles) === 0) {
|
||||
continue;
|
||||
}
|
||||
$this->add($results, $disponibles, false);
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
@ -281,11 +285,10 @@ class Search
|
||||
protected function add(array &$results, array $found, bool $is_venta = true): void
|
||||
{
|
||||
foreach ($found as $item) {
|
||||
if (!isset($item['tipo'])) {
|
||||
$item['tipo'] = ($is_venta) ? 'venta' : 'unidad';
|
||||
}
|
||||
if (!$this->inResults($item, $results)) {
|
||||
$item['tipo'] = 'venta';
|
||||
if (!$is_venta) {
|
||||
$item['tipo'] = 'unidad';
|
||||
}
|
||||
$results []= $item;
|
||||
}
|
||||
}
|
||||
|
@ -100,17 +100,22 @@ class Venta
|
||||
$venta_data[$field] = $forma_pago->{$name}->id;
|
||||
}
|
||||
}
|
||||
$venta = $this->ventaRepository->create($venta_data);
|
||||
$venta = $this->ventaRepository->save($venta);
|
||||
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('vigente');
|
||||
$estado = $this->estadoVentaRepository->create([
|
||||
'venta' => $venta->id,
|
||||
'estado' => $tipoEstado->id,
|
||||
'fecha' => $venta->fecha->format('Y-m-d')
|
||||
]);
|
||||
$this->estadoVentaRepository->save($estado);
|
||||
try {
|
||||
return $this->ventaRepository->fetchByPropietarioAndPropiedad($propietario->rut, $propiedad->id);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$venta = $this->ventaRepository->create($venta_data);
|
||||
$venta = $this->ventaRepository->save($venta);
|
||||
|
||||
return $venta;
|
||||
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('vigente');
|
||||
$estado = $this->estadoVentaRepository->create([
|
||||
'venta' => $venta->id,
|
||||
'estado' => $tipoEstado->id,
|
||||
'fecha' => $venta->fecha->format('Y-m-d')
|
||||
]);
|
||||
$this->estadoVentaRepository->save($estado);
|
||||
|
||||
return $venta;
|
||||
}
|
||||
}
|
||||
protected function addPropietario(array $data): Model\Venta\Propietario
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ class Propiedad
|
||||
if (count($diff) === 0) {
|
||||
return;
|
||||
}
|
||||
$query = "DELECT FROM `propiedad_unidad` WHERE `propiedad` = ? AND `unidad` = ?";
|
||||
$query = "DELETE FROM `propiedad_unidad` WHERE `propiedad` = ? AND `unidad` = ?";
|
||||
$statement = $this->connection->prepare($query);
|
||||
foreach ($diff as $id) {
|
||||
$statement->execute([$propiedad->id, $id]);
|
||||
|
Reference in New Issue
Block a user