@@ -686,7 +686,7 @@
$('
').addClass('content').append(tipo.charAt(0).toUpperCase() + tipo.slice(1) + ' ').append(
unidad.draw(this.unidades[tipo])
).append(
- $('
').addClass('ui icon button').attr('type', 'button').attr('data-number', number).append(
+ $('
').addClass('ui basic red icon button').attr('type', 'button').attr('data-number', number).append(
$('
').addClass('remove icon')
).click(event => {
const number = $(event.currentTarget).attr('data-number')
@@ -766,7 +766,7 @@
}
function showErrors(errors) {
- console.debug(errors)
+ console.error(errors)
}
$(document).ready(() => {
@@ -789,20 +789,21 @@
$('#add_form').submit(event => {
event.preventDefault()
- const data = new FormData(event.currentTarget)
- const uri = $(event.currentTarget).attr('action')
- fetch(uri, {method: 'post', body: data}).then(response => {
- if (response.ok) {
- return response.json()
+ const body = new FormData(event.currentTarget)
+ const uri = '{{$urls->api}}/ventas/add'
+ return fetchAPI(uri, {method: 'post', body}).then(response => {
+ if (!response) {
+ return false
}
- }).then(data => {
- if (data.status) {
- window.location = '{{$urls->base}}'
- return true
- }
- showErrors(data.errors)
+ return response.json().then(data => {
+ if (data.status) {
+ window.location = '{{$urls->base}}/venta/' + data.venta_id
+ return true
+ }
+ showErrors(data.errors)
+ return false
+ })
})
- return false
})
})
diff --git a/app/setup/setups/logs.php b/app/setup/setups/logs.php
index 046300a..cb17296 100644
--- a/app/setup/setups/logs.php
+++ b/app/setup/setups/logs.php
@@ -8,12 +8,18 @@ return [
(new Monolog\Handler\RotatingFileHandler('/logs/debug.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
Monolog\Level::Debug,
- Monolog\Level::Notice
+ Monolog\Level::Debug
+ ),
+ new Monolog\Handler\FilterHandler(
+ (new Monolog\Handler\RotatingFileHandler('/logs/info.log', 10))
+ ->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
+ Monolog\Level::Info,
+ Monolog\Level::Warning,
),
new Monolog\Handler\FilterHandler(
(new Monolog\Handler\RotatingFileHandler('/logs/error.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
- Monolog\Level::Warning,
+ Monolog\Level::Error,
Monolog\Level::Error
),
new Monolog\Handler\FilterHandler(
diff --git a/app/src/Controller/API/Search.php b/app/src/Controller/API/Search.php
new file mode 100644
index 0000000..7770215
--- /dev/null
+++ b/app/src/Controller/API/Search.php
@@ -0,0 +1,20 @@
+getParsedBody();
+ $results = $service->query($data['query'], $data['tipo']);
+ $output = compact('results');
+ return $this->withJson($response, $output);
+ }
+}
diff --git a/app/src/Controller/API/Ventas.php b/app/src/Controller/API/Ventas.php
index 684ec99..507f405 100644
--- a/app/src/Controller/API/Ventas.php
+++ b/app/src/Controller/API/Ventas.php
@@ -1,17 +1,19 @@
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);
}
diff --git a/app/src/Controller/Search.php b/app/src/Controller/Search.php
index 94a6a6f..082d713 100644
--- a/app/src/Controller/Search.php
+++ b/app/src/Controller/Search.php
@@ -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');
- }
}
diff --git a/app/src/Middleware/NotFound.php b/app/src/Middleware/NotFound.php
index 8971be4..abccf49 100644
--- a/app/src/Middleware/NotFound.php
+++ b/app/src/Middleware/NotFound.php
@@ -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;
diff --git a/app/src/Model/Venta.php b/app/src/Model/Venta.php
index 50e9bde..4eca125 100644
--- a/app/src/Model/Venta.php
+++ b/app/src/Model/Venta.php
@@ -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
{
diff --git a/app/src/Repository/Venta.php b/app/src/Repository/Venta.php
index 0476532..34c4fd2 100644
--- a/app/src/Repository/Venta.php
+++ b/app/src/Repository/Venta.php
@@ -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
diff --git a/app/src/Service/Search.php b/app/src/Service/Search.php
index 0132c28..9d58d4b 100644
--- a/app/src/Service/Search.php
+++ b/app/src/Service/Search.php
@@ -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;
}
}
diff --git a/app/src/Service/Venta.php b/app/src/Service/Venta.php
index be79d78..9697d0d 100644
--- a/app/src/Service/Venta.php
+++ b/app/src/Service/Venta.php
@@ -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
{
diff --git a/app/src/Service/Venta/Propiedad.php b/app/src/Service/Venta/Propiedad.php
index 7de58ba..58788c3 100644
--- a/app/src/Service/Venta/Propiedad.php
+++ b/app/src/Service/Venta/Propiedad.php
@@ -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]);
diff --git a/php-errors.ini b/php-errors.ini
index aed1ffb..511b6ac 100644
--- a/php-errors.ini
+++ b/php-errors.ini
@@ -1,3 +1,3 @@
display_errors=no
log_errors=yes
-error_log=/logs/errors.log
+#error_log=/logs/errors.log