Conecciones de Promociones
This commit is contained in:
@ -94,7 +94,7 @@ class Proyecto extends Ideal\Repository
|
||||
->where("a.descripcion LIKE ?");
|
||||
return $this->fetchOne($query, ["%{$name}%"]);
|
||||
}
|
||||
public function fetchAllActive(): array
|
||||
public function fetchAllActive(null|string|array $orderBy = null): array
|
||||
{
|
||||
$etapaProyecto = $this->etapaRepository->fetchByDescripcion('Proyecto');
|
||||
$etapaTerminado = $this->etapaRepository->fetchByDescripcion('Terminado');
|
||||
@ -103,8 +103,12 @@ class Proyecto extends Ideal\Repository
|
||||
->from("{$this->getTable()} a")
|
||||
->joined($this->joinTerreno())
|
||||
->joined($this->joinEstado())
|
||||
->where("et.orden BETWEEN {$etapaProyecto->orden} AND ({$etapaTerminado->orden} - 1)")
|
||||
->order('a.descripcion');
|
||||
->where("et.orden BETWEEN {$etapaProyecto->orden} AND ({$etapaTerminado->orden} - 1)");
|
||||
if ($orderBy === null) {
|
||||
$query = $query->order('a.descripcion');
|
||||
} else {
|
||||
$query = $query->order($orderBy);
|
||||
}
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
public function fetchAllEscriturando(): array
|
||||
@ -175,8 +179,14 @@ class Proyecto extends Ideal\Repository
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('INNER JOIN promotion_projects pp ON pp.project_id = a.id')
|
||||
->where('pp.promotion_id = :promotion_id');
|
||||
->joined('LEFT OUTER JOIN proyecto_tipo_unidad ptu ON ptu.proyecto = a.id')
|
||||
->joined('LEFT OUTER JOIN unidad ON unidad.pt = ptu.id')
|
||||
->joined('LEFT OUTER JOIN promotion_units pu ON pu.unit_id = unidad.id')
|
||||
->joined('LEFT OUTER JOIN broker_contracts bc ON bc.project_id = a.id')
|
||||
->joined('LEFT OUTER JOIN promotion_contracts pc ON pc.contract_id = bc.id')
|
||||
->where('pu.promotion_id = :promotion_id OR pc.promotion_id = :promotion_id')
|
||||
->group('a.id');
|
||||
trigger_error($query . ' ' . json_encode(['promotion_id' => $promotion_id]));
|
||||
return $this->fetchMany($query, ['promotion_id' => $promotion_id]);
|
||||
}
|
||||
/*public function fetchSuperficieVendido(int $proyecto_id): float
|
||||
|
@ -43,4 +43,21 @@ class ProyectoTipoUnidad extends Ideal\Repository
|
||||
{
|
||||
return $this->update($model, ['proyecto', 'tipo', 'nombre', 'abreviacion', 'util', 'logia', 'terraza', 'descripcion'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $promotion_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPromotion(int $promotion_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('INNER JOIN unidad ON unidad.`pt` = a.`id`')
|
||||
->joined('INNER JOIN `promotion_units` pu ON pu.`unit_id` = unidad.`id`')
|
||||
->where('pu.`promotion_id` = :promotion_id')
|
||||
->group('a.id');
|
||||
return $this->fetchMany($query, ['promotion_id' => $promotion_id]);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -32,6 +34,11 @@ class TipoUnidad extends Ideal\Repository
|
||||
return $this->update($model, ['descripcion', 'orden'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -43,6 +50,31 @@ class TipoUnidad extends Ideal\Repository
|
||||
->order('a.orden');
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $promotion_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPromotion(int $promotion_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.id, ptu.proyecto AS project_id')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('INNER JOIN proyecto_tipo_unidad ptu ON ptu.`tipo` = a.`id`')
|
||||
->joined('INNER JOIN unidad ON unidad.`pt` = ptu.`id`')
|
||||
->joined('INNER JOIN `promotion_units` pu ON pu.`unit_id` = unidad.`id`')
|
||||
->where('pu.`promotion_id` = :promotion_id')
|
||||
->group('a.id');
|
||||
try {
|
||||
$result = $this->connection->execute($query, ['promotion_id' => $promotion_id])->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (empty($result)) {
|
||||
throw new Implement\Exception\EmptyResult($query);
|
||||
}
|
||||
return $result;
|
||||
} catch (PDOException $exception) {
|
||||
throw new Implement\Exception\EmptyResult($query, $exception);
|
||||
}
|
||||
return $this->fetchMany($query, ['promotion_id' => $promotion_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -204,4 +204,45 @@ class Promotion extends Common\Ideal\Repository
|
||||
throw new Common\Implement\Exception\EmptyResult($query, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model\Venta\Promotion $promotion
|
||||
* @param int $project_id
|
||||
* @return void
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function insertProjectForPromotion(Model\Venta\Promotion $promotion, int $project_id): void
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->insert()
|
||||
->into('promotion_projects')
|
||||
->columns(['promotion_id', 'project_id'])
|
||||
->values([':promotion_id', ':project_id']);
|
||||
$this->connection->execute($query, ['promotion_id' => $promotion->id, 'project_id' => $project_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model\Venta\Promotion $promotion
|
||||
* @param int $contract_id
|
||||
* @return void
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function insertContractForPromotion(Model\Venta\Promotion $promotion, int $contract_id): void
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->insert()
|
||||
->into('promotion_contracts')
|
||||
->columns(['promotion_id', 'contract_id'])
|
||||
->values([':promotion_id', ':contract_id']);
|
||||
$this->connection->execute($query, ['promotion_id' => $promotion->id, 'contract_id' => $contract_id]);
|
||||
}
|
||||
public function insertUnitForPromotion(Model\Venta\Promotion $promotion, int $unit_id): void
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->insert()
|
||||
->into('promotion_units')
|
||||
->columns(['promotion_id', 'unit_id'])
|
||||
->values([':promotion_id', ':unit_id']);
|
||||
$this->connection->execute($query, ['promotion_id' => $promotion->id, 'unit_id' => $unit_id]);
|
||||
}
|
||||
}
|
||||
|
@ -200,6 +200,22 @@ class Unidad extends Ideal\Repository
|
||||
return $this->fetchMany($query, ['promotion_id' => $promotion_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @param int $tipo_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByProyectoAndTipo(int $proyecto_id, int $tipo_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.*')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('INNER JOIN proyecto_tipo_unidad ptu ON a.pt = ptu.id')
|
||||
->where('ptu.`proyecto` = :proyecto_id AND ptu.`tipo` = :tipo_id');
|
||||
return $this->fetchMany($query, ['proyecto_id' => $proyecto_id, 'tipo_id' => $tipo_id]);
|
||||
}
|
||||
|
||||
protected function joinProrrateo(): string
|
||||
{
|
||||
return "LEFT OUTER JOIN unidad_prorrateo up ON up.unidad_id = a.id";
|
||||
|
Reference in New Issue
Block a user