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 (
|
||||
|
Reference in New Issue
Block a user