FIX: Propiedad con unidad_principal

This commit is contained in:
Juan Pablo Vial
2025-04-25 19:25:16 -04:00
parent 31f49dddb6
commit 2a1930c5f7
2 changed files with 16 additions and 9 deletions

View File

@ -22,6 +22,13 @@ class Propiedad extends Ideal\Repository
public function create(?array $data = null): Model\Venta\Propiedad
{
$map = (new Implement\Repository\MapperParser())
->register('unidad_principal', (new Implement\Repository\Mapper())
->setProperty('unidades')
->setDefault([])
->setFunction(function($data) {
return [$this->unidadService->getById($data['unidad_principal'])];
})
)
->register('estado', new Implement\Repository\Mapper\Boolean('estado'));
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
}
@ -37,14 +44,13 @@ class Propiedad extends Ideal\Repository
public function save(Define\Model $model): Model\Venta\Propiedad
{
$model->id = $this->saveNew(
[
'unidad_principal',
'estacionamientos', 'bodegas', 'estado'],
['unidad_principal', 'estacionamientos', 'bodegas', 'estado'],
[
$model->principal()?->id,
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->estacionamientos())),
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->bodegas())),
1]
1
]
);
return $model;
}
@ -68,9 +74,10 @@ class Propiedad extends Ideal\Repository
public function fetchVigenteByUnidad(int $unidad_id): Model\Venta\Propiedad
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('`unidad_principal` = ? AND `estado` = 1');
->select('a.*')
->from("{$this->getTable()} a")
->joined('propiedad_unidad pu ON pu.propiedad = a.id')
->where('`pu`.unidad = ? AND `estado` = 1');
return $this->fetchOne($query, [$unidad_id]);
}

View File

@ -64,10 +64,10 @@ class Propiedad extends Service
});
try {
$propiedad = $this->propiedadRepository->fetchVigenteByUnidad($unidades[0]->id);
#$propiedad = $this->propiedadRepository->edit($propiedad, ['unidad_principal' => $unidades[0]->id]);
$propiedad = $this->propiedadRepository->edit($propiedad, ['unidad_principal' => $unidades[0]->id]);
} catch (EmptyResult) {
$propiedad = $this->propiedadRepository->create([
# 'unidad_principal' => $unidades[0]->id,
'unidad_principal' => $unidades[0]->id,
'estado' => 1
]);
$propiedad = $this->propiedadRepository->save($propiedad);