Facturacion
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -36,6 +37,10 @@ class Proyecto extends Ideal\Repository
|
||||
$terreno = new Model\Proyecto\Terreno();
|
||||
$terreno->superficie = $data['superficie_terreno'];
|
||||
$terreno->valor = $data['valor_terreno'];
|
||||
$terreno->date = null;
|
||||
if (isset($data['fecha_terreno']) and $data['fecha_terreno'] !== '') {
|
||||
$terreno->date = new DateTimeImmutable($data['fecha_terreno']);
|
||||
}
|
||||
return $terreno;
|
||||
}))
|
||||
->register('superficie_sobre_nivel', (new Implement\Repository\Mapper())
|
||||
@ -67,36 +72,55 @@ class Proyecto extends Ideal\Repository
|
||||
}
|
||||
public function fetchByName(string $name): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `name` = ?";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select($this->columns())
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinTerreno())
|
||||
->where("name = ?");
|
||||
return $this->fetchOne($query, [$name]);
|
||||
}
|
||||
public function fetchAllActive(): array
|
||||
{
|
||||
$etapaProyecto = $this->etapaRepository->fetchByDescripcion('Proyecto');
|
||||
$etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado');
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
{$this->joinEstado()}
|
||||
WHERE et.`orden` BETWEEN {$etapaProyecto->orden} AND ({$etapaTerminado->orden} - 1)
|
||||
ORDER BY a.`descripcion`";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select($this->columns())
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinTerreno())
|
||||
->joined($this->joinEstado())
|
||||
->where("et.orden BETWEEN {$etapaProyecto->orden} AND ({$etapaTerminado->orden} - 1)")
|
||||
->order('a.descripcion');
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
public function fetchAllEscriturando(): array
|
||||
{
|
||||
$etapaRecepcion = $this->etapaRepository->fetchByDescripcion('Recepción');
|
||||
$etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado');
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
{$this->joinEstado()}
|
||||
WHERE et.`orden` BETWEEN {$etapaRecepcion->orden} AND ({$etapaTerminado->orden} - 1)
|
||||
ORDER BY a.`descripcion`";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select($this->columns())
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinTerreno())
|
||||
->joined($this->joinEstado())
|
||||
->where("et.orden BETWEEN {$etapaRecepcion->orden} AND ({$etapaTerminado->orden} - 1)")
|
||||
->order('a.descripcion');
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
public function fetchSuperficieVendido(int $proyecto_id): float
|
||||
/*public function fetchSuperficieVendido(int $proyecto_id): float
|
||||
{
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
protected function columns(): string
|
||||
{
|
||||
return "a.id, a.inmobiliaria, a.descripcion, a.direccion, a.superficie_terreno,
|
||||
COALESCE(pt.valor, a.valor_terreno) AS valor_terreno, COALESCE(pt.fecha, '') AS fecha_terreno, a.corredor,
|
||||
a.superficie_sobre_nivel, a.superficie_bajo_nivel, a.pisos, a.subterraneos";
|
||||
}
|
||||
protected function joinTerreno(): string
|
||||
{
|
||||
return "LEFT OUTER JOIN (SELECT pt1.* FROM proyecto_terreno pt1 JOIN (
|
||||
SELECT MAX(id) AS id, proyecto_id FROM proyecto_terreno) pt0 ON pt0.id = pt1.id) pt ON pt.proyecto_id = a.id";
|
||||
}
|
||||
protected function joinEstado(): string
|
||||
{
|
||||
return "JOIN (
|
||||
|
@ -17,7 +17,7 @@ class Unidad extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Model\Venta\Unidad
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['subtipo', 'piso', 'descripcion', 'orientacion']))
|
||||
$map = (new Implement\Repository\MapperParser(['subtipo', 'piso', 'descripcion', 'orientacion', 'prorrateo']))
|
||||
->register('pt', (new Implement\Repository\Mapper())
|
||||
->setProperty('proyectoTipoUnidad')
|
||||
->setFunction(function($data) {
|
||||
@ -38,62 +38,88 @@ class Unidad extends Ideal\Repository
|
||||
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByVenta(int $venta_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*, up.prorrateo')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinProrrateo())
|
||||
->joined('JOIN propiedad_unidad pu ON pu.unidad = a.id
|
||||
JOIN venta ON venta.propiedad = pu.propiedad')
|
||||
->where('venta.id = ?');
|
||||
return $this->fetchMany($query, [$venta_id]);
|
||||
}
|
||||
public function fetchByPropiedad(int $propiedad_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id`
|
||||
WHERE pu.`propiedad` = ?
|
||||
GROUP BY a.`id`";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*, up.prorrateo')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinProrrateo())
|
||||
->joined('JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id`')
|
||||
->where('pu.propiedad = ?')
|
||||
->group('a.id');
|
||||
return $this->fetchMany($query, [$propiedad_id]);
|
||||
}
|
||||
public function fetchByCierre(int $cierre_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `unidad_cierre` uc ON uc.`unidad` = a.`id`
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*, up.prorrateo')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinProrrateo())
|
||||
->joined("JOIN `unidad_cierre` uc ON uc.`unidad` = a.`id`
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
|
||||
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
|
||||
WHERE uc.`cierre` = ?
|
||||
GROUP BY a.`id`
|
||||
ORDER BY tu.`orden`, LPAD(a.`descripcion`, 4, '0')";
|
||||
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`")
|
||||
->where('uc.cierre = ?')
|
||||
->group('a.id')
|
||||
->order("tu.orden, LPAD(a.descripcion, 4, '0')");
|
||||
return $this->fetchMany($query, [$cierre_id]);
|
||||
}
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
|
||||
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
|
||||
WHERE ptu.`proyecto` = ?
|
||||
ORDER BY tu.`orden`";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*, up.prorrateo')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinProrrateo())
|
||||
->joined("JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
|
||||
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`")
|
||||
->where('ptu.proyecto = ?')
|
||||
->order('tu.orden');
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchDisponiblesByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT DISTINCT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('DISTINCT a.*, up.prorrateo')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinProrrateo())
|
||||
->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 ptu.`proyecto` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)
|
||||
ORDER BY tu.`orden`";
|
||||
LEFT OUTER JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`")
|
||||
->where("ptu.`proyecto` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)")
|
||||
->order('tu.orden');
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchDisponiblesByDescripcionAndTipo(string $descripcion, string $tipo): array
|
||||
{
|
||||
$query = "SELECT DISTINCT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('DISTINCT a.*, up.prorrateo')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinProrrateo())
|
||||
->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)";
|
||||
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->fetchMany($query, [$descripcion, $tipo]);
|
||||
}
|
||||
|
||||
protected function joinProrrateo(): string
|
||||
{
|
||||
return "LEFT OUTER JOIN unidad_prorrateo up ON up.unidad_id = a.id";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user