2023-07-24 20:55:26 -04:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Repository\Venta;
|
|
|
|
|
|
|
|
use Incoviba\Common\Ideal;
|
|
|
|
use Incoviba\Common\Define;
|
|
|
|
use Incoviba\Model;
|
|
|
|
use Incoviba\Repository;
|
|
|
|
|
|
|
|
class Unidad extends Ideal\Repository
|
|
|
|
{
|
|
|
|
public function __construct(Define\Connection $connection, protected Repository\Proyecto\ProyectoTipoUnidad $proyectoTipoUnidadRepository)
|
|
|
|
{
|
|
|
|
parent::__construct($connection);
|
|
|
|
$this->setTable('unidad');
|
|
|
|
}
|
|
|
|
|
|
|
|
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']);
|
|
|
|
}
|
|
|
|
]
|
|
|
|
];
|
|
|
|
return $this->parseData(new Model\Venta\Unidad(), $data, $map);
|
|
|
|
}
|
|
|
|
public function save(Define\Model $model): Define\Model
|
|
|
|
{
|
|
|
|
$model->id = $this->saveNew(
|
|
|
|
['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'],
|
|
|
|
[$model->subtipo, $model->piso, $model->descripcion, $model->orientacion, $model->proyectoTipoUnidad->id]
|
|
|
|
);
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
public function edit(Define\Model $model, array $new_data): Define\Model
|
|
|
|
{
|
|
|
|
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
|
|
|
|
}
|
2023-07-25 17:03:57 -04:00
|
|
|
|
2023-07-28 16:22:20 -04:00
|
|
|
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`";
|
|
|
|
return $this->fetchMany($query, [$propiedad_id]);
|
|
|
|
}
|
2023-07-25 17:03:57 -04:00
|
|
|
public function fetchByCierre(int $cierre_id): array
|
|
|
|
{
|
|
|
|
$query = "SELECT a.*
|
|
|
|
FROM `{$this->getTable()}` a
|
|
|
|
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` = ?
|
2023-07-28 16:22:20 -04:00
|
|
|
GROUP BY a.`id`
|
2023-07-25 17:03:57 -04:00
|
|
|
ORDER BY tu.`orden`, LPAD(a.`descripcion`, 4, '0')";
|
|
|
|
return $this->fetchMany($query, [$cierre_id]);
|
|
|
|
}
|
2023-07-24 20:55:26 -04:00
|
|
|
}
|