Promociones
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Incoviba\Common;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository\Proyecto\Broker;
|
||||
@ -177,4 +179,29 @@ class Promotion extends Common\Ideal\Repository
|
||||
->where('pc.contract_id = :contract_id AND pu.unit_id = :unit_id');
|
||||
return $this->fetchOne($query, ['contract_id' => $contract_id, 'unit_id' => $unit_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $promotion_id
|
||||
* @return array
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchContractUnitsByPromotion(int $promotion_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('contracts.id, unidad.id')
|
||||
->from("{$this->getTable()} a")
|
||||
->joined('INNER JOIN promotion_contract_units pcu ON pcu.promotion_id = a.id')
|
||||
->joined('INNER JOIN unidad ON unidad.id = pcu.unit_id')
|
||||
->joined('INNER JOIN contracts ON contracts.id = pcu.contract_id')
|
||||
->where('a.id = :promotion_id');
|
||||
try {
|
||||
$result = $this->connection->execute($query, ['promotion_id' => $promotion_id])->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (empty($result)) {
|
||||
throw new Common\Implement\Exception\EmptyResult($query);
|
||||
}
|
||||
return $result;
|
||||
} catch (PDOException $exception) {
|
||||
throw new Common\Implement\Exception\EmptyResult($query, $exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user