From f1363fa4c165396cf51cb4c678992e1746904575 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Wed, 11 Mar 2020 16:20:33 -0300 Subject: [PATCH] Relaciones --- src/old/Proyecto/Proyecto.php | 12 ++++++--- src/old/Venta/Cuota.php | 46 ++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/old/Proyecto/Proyecto.php b/src/old/Proyecto/Proyecto.php index 619e047..4c601fc 100644 --- a/src/old/Proyecto/Proyecto.php +++ b/src/old/Proyecto/Proyecto.php @@ -583,7 +583,7 @@ class Proyecto extends Model { } $f = Carbon::today($this->container->get('settings')->app->timezone); $cuotas['hoy'] = $this->container->get('model')->find(Venta::class) - ->select('COUNT(cuota.id) AS cantidad') + ->select([['COUNT(cuota.id)', 'cantidad', 'expr']]) ->join([ ['propiedad', 'propiedad.id', 'venta.propiedad'], ['unidad', 'unidad.id', 'propiedad.unidad_principal'], @@ -611,7 +611,7 @@ class Proyecto extends Model { } $f = Carbon::today($this->container->get('settings')->app->timezone); $cuotas['pendientes'] = $this->container->get('model')->find(Cuota::class) - ->select('COUNT(cuota.id) AS cantidad') + ->select([['COUNT(cuota.id)', 'cantidad', 'expr']]) ->join([ ['venta', 'cuota.pie', 'venta.pie'], ['propiedad', 'propiedad.id', 'venta.propiedad'], @@ -642,7 +642,7 @@ class Proyecto extends Model { ->join([ ['venta', 'cuota.pie', 'venta.pie'], ['propiedad', 'propiedad.id', 'venta.propiedad'], - ['unidad', 'unidad.id', 'cuota.pago'], + ['unidad', 'unidad.id', 'propiedad.unidad_principal'], ['pago', 'pago.id', 'cuota.pago'], ['JOIN (SELECT e1.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago e1 ON e1.id = e0.id)', 'ep.pago', 'pago.id', 'alias' => 'ep', 'type' => 'raw'] ]) @@ -824,7 +824,11 @@ class Proyecto extends Model { ; break; } - $this->cierres[$vigentes] = $orm->findMany(); + $cierres = $orm->findMany(); + foreach ($cierres as &$cierre) { + $cierre->setContainer($this->container); + } + $this->cierres[$vigentes] = $cierres; } return $this->cierres[$vigentes]; } diff --git a/src/old/Venta/Cuota.php b/src/old/Venta/Cuota.php index e52aeb1..b3a15eb 100644 --- a/src/old/Venta/Cuota.php +++ b/src/old/Venta/Cuota.php @@ -21,25 +21,33 @@ use Incoviba\Common\Alias\OldModel as Model; */ class Cuota extends Model { - public function pago() - { - return $this->belongs_to(Pago::class, 'pago')->findOne(); - } - public function pie() - { - return $this->belongs_to(Pie::class, 'pie')->findOne(); - } - public function uf() - { - if ($this->uf == 0) { - $uf = $this->pago()->uf(); - if ($uf == 1) { - $uf = $this->pie()->uf(); - } - $this->uf = $uf; - } - return $this->uf; - } + protected $pago_obj; + public function pago() + { + if ($this->pago_obj === null) { + $this->pago_obj = $this->setRelationship(Pago::class, 'id', 'pago')->one(); + } + return $this->pago_obj; + } + protected $pie_obj; + public function pie() + { + if ($this->pie_obj === null) { + $this->pie_obj = $this->setRelationship(Pie::class, 'id', 'pie')->one(); + } + return $this->pie_obj; + } + public function uf() + { + if ($this->uf == 0) { + $uf = $this->pago()->uf(); + if ($uf == 1) { + $uf = $this->pie()->uf(); + } + $this->uf = $uf; + } + return $this->uf; + } public function valor($tipo = 'pesos') { $valor = $this->pago()->valor;