Implemented repository mapper, and venta show
This commit is contained in:
@ -3,12 +3,13 @@ namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Unidad extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidadRepository)
|
||||
public function __construct(Define\Connection $connection, protected Service\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidadService)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('unidad');
|
||||
@ -16,18 +17,12 @@ class Unidad extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'subtipo' => [],
|
||||
'piso' => [],
|
||||
'descripcion' => [],
|
||||
'orientacion' => [],
|
||||
'pt' => [
|
||||
'property' => 'proyectoTipoUnidad',
|
||||
'function' => function($data) {
|
||||
return $this->proyectoTipoUnidadRepository->fetchById($data['pt']);
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser(['subtipo', 'piso', 'descripcion', 'orientacion']))
|
||||
->register('pt', (new Implement\Repository\Mapper())
|
||||
->setProperty('proyectoTipoUnidad')
|
||||
->setFunction(function($data) {
|
||||
return $this->proyectoTipoUnidadService->getById($data['pt']);
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Unidad(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
@ -64,4 +59,28 @@ GROUP BY a.`id`
|
||||
ORDER BY 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`";
|
||||
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`
|
||||
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`";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user