FIX: Propiedad con unidad_principal
This commit is contained in:
@ -22,6 +22,13 @@ class Propiedad extends Ideal\Repository
|
|||||||
public function create(?array $data = null): Model\Venta\Propiedad
|
public function create(?array $data = null): Model\Venta\Propiedad
|
||||||
{
|
{
|
||||||
$map = (new Implement\Repository\MapperParser())
|
$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'));
|
->register('estado', new Implement\Repository\Mapper\Boolean('estado'));
|
||||||
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
|
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
|
public function save(Define\Model $model): Model\Venta\Propiedad
|
||||||
{
|
{
|
||||||
$model->id = $this->saveNew(
|
$model->id = $this->saveNew(
|
||||||
[
|
['unidad_principal', 'estacionamientos', 'bodegas', 'estado'],
|
||||||
'unidad_principal',
|
|
||||||
'estacionamientos', 'bodegas', 'estado'],
|
|
||||||
[
|
[
|
||||||
$model->principal()?->id,
|
$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->estacionamientos())),
|
||||||
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->bodegas())),
|
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->bodegas())),
|
||||||
1]
|
1
|
||||||
|
]
|
||||||
);
|
);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
@ -68,9 +74,10 @@ class Propiedad extends Ideal\Repository
|
|||||||
public function fetchVigenteByUnidad(int $unidad_id): Model\Venta\Propiedad
|
public function fetchVigenteByUnidad(int $unidad_id): Model\Venta\Propiedad
|
||||||
{
|
{
|
||||||
$query = $this->connection->getQueryBuilder()
|
$query = $this->connection->getQueryBuilder()
|
||||||
->select()
|
->select('a.*')
|
||||||
->from($this->getTable())
|
->from("{$this->getTable()} a")
|
||||||
->where('`unidad_principal` = ? AND `estado` = 1');
|
->joined('propiedad_unidad pu ON pu.propiedad = a.id')
|
||||||
|
->where('`pu`.unidad = ? AND `estado` = 1');
|
||||||
return $this->fetchOne($query, [$unidad_id]);
|
return $this->fetchOne($query, [$unidad_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,10 +64,10 @@ class Propiedad extends Service
|
|||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
$propiedad = $this->propiedadRepository->fetchVigenteByUnidad($unidades[0]->id);
|
$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) {
|
} catch (EmptyResult) {
|
||||||
$propiedad = $this->propiedadRepository->create([
|
$propiedad = $this->propiedadRepository->create([
|
||||||
# 'unidad_principal' => $unidades[0]->id,
|
'unidad_principal' => $unidades[0]->id,
|
||||||
'estado' => 1
|
'estado' => 1
|
||||||
]);
|
]);
|
||||||
$propiedad = $this->propiedadRepository->save($propiedad);
|
$propiedad = $this->propiedadRepository->save($propiedad);
|
||||||
|
Reference in New Issue
Block a user