This commit is contained in:
Juan Pablo Vial
2023-09-28 21:05:16 -03:00
parent 2e2d0f07b4
commit 3141f1e7c4
16 changed files with 556 additions and 19 deletions

View File

@ -52,10 +52,10 @@ class Propietario extends Ideal\Repository
}))
->register('otro', (new Implement\Repository\Mapper())
->setFunction(function($data) {
if ($data['otro'] === null or $data['otro'] === 0) {
if ($data['otro'] === null) {
return null;
}
return $this->fetchById($data['otro']);
return $data['otro'] !== 0;
})
->setDefault(null));
return $this->parseData(new Model\Venta\Propietario(), $data, $map);

View File

@ -15,7 +15,7 @@ class Unidad extends Ideal\Repository
$this->setTable('unidad');
}
public function create(?array $data = null): Define\Model
public function create(?array $data = null): Model\Venta\Unidad
{
$map = (new Implement\Repository\MapperParser(['subtipo', 'piso', 'descripcion', 'orientacion']))
->register('pt', (new Implement\Repository\Mapper())
@ -25,7 +25,7 @@ class Unidad extends Ideal\Repository
}));
return $this->parseData(new Model\Venta\Unidad(), $data, $map);
}
public function save(Define\Model $model): Define\Model
public function save(Define\Model $model): Model\Venta\Unidad
{
$model->id = $this->saveNew(
['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'],
@ -33,7 +33,7 @@ class Unidad extends Ideal\Repository
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
public function edit(Define\Model $model, array $new_data): Model\Venta\Unidad
{
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
}
@ -83,4 +83,17 @@ WHERE ptu.`proyecto` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`ac
ORDER BY tu.`orden`";
return $this->fetchMany($query, [$proyecto_id]);
}
public function fetchDisponiblesByDescripcionAndTipo(string $descripcion, string $tipo): 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 a.`descripcion` LIKE ? AND tu.`descripcion` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)";
return $this->fetchMany($query, [$descripcion, $tipo]);
}
}