FIX: venta sin departamentos

This commit is contained in:
Juan Pablo Vial
2024-06-11 18:16:34 -04:00
parent b7e9a17586
commit 15e9a54c7e
2 changed files with 4 additions and 1 deletions

View File

@ -48,6 +48,9 @@ class Propiedad extends Ideal\Model
protected float $vendible;
public function vendible(): float
{
if (count($this->departamentos()) === 0) {
return $this->principal()->proyectoTipoUnidad->vendible();
}
return array_reduce($this->departamentos(), function(float $sum, Unidad $unidad) {
return $sum + $unidad->proyectoTipoUnidad->vendible();
}, 0);

View File

@ -372,7 +372,7 @@ class Venta extends Ideal\Repository
->joined('JOIN tipo_unidad tu ON tu.id = ptu.tipo')
->joined('JOIN (SELECT ev1.* FROM estado_venta ev1 JOIN (SELECT MAX(id) AS id, venta FROM estado_venta GROUP BY venta) ev0 ON ev0.id = ev1.id) ev ON ev.venta = venta.id')
->joined('JOIN tipo_estado_venta tev ON ev.estado = tev.id')
->where('venta.id = ? AND tu.descripcion = "departamento"')
->where('venta.id = ?')
->group('venta.id');
return $this->connection->execute($query, [$venta_id])->fetch(PDO::FETCH_ASSOC);
}