Optimizaciones y funciones
This commit is contained in:
@ -29,8 +29,7 @@ use Incoviba\old\Venta\Venta;
|
||||
* @property int $subterraneos
|
||||
*
|
||||
*/
|
||||
class Proyecto extends Model
|
||||
{
|
||||
class Proyecto extends Model {
|
||||
protected $unidades;
|
||||
protected $valores;
|
||||
protected $tipo_unidades;
|
||||
@ -44,16 +43,23 @@ class Proyecto extends Model
|
||||
protected $cuotas;
|
||||
protected $superficies;
|
||||
|
||||
public function inmobiliaria()
|
||||
{
|
||||
return $this->belongs_to(Inmobiliaria::class, 'inmobiliaria', 'rut')->findOne();
|
||||
protected $inmobiliaria_obj;
|
||||
public function inmobiliaria() {
|
||||
if ($this->inmobiliaria_obj === null) {
|
||||
$this->inmobiliaria_obj = $this->setRelationship(Inmobiliaria::class, 'rut', 'inmobiliaria')->one();
|
||||
}
|
||||
return $this->inmobiliaria_obj;
|
||||
//return $this->belongs_to(Inmobiliaria::class, 'inmobiliaria', 'rut')->findOne();
|
||||
}
|
||||
public function direccion()
|
||||
{
|
||||
return $this->belongs_to(Direccion::class, 'direccion')->findOne();
|
||||
protected $direccion_obj;
|
||||
public function direccion() {
|
||||
if ($this->direccion_obj === null) {
|
||||
$this->direccion_obj = $this->setRelationship(Direccion::class, 'id', 'direccion')->one();
|
||||
}
|
||||
return $this->direccion_obj;
|
||||
//return $this->belongs_to(Direccion::class, 'direccion')->findOne();
|
||||
}
|
||||
public function unidades($tipo = null)
|
||||
{
|
||||
public function unidades($tipo = null) {
|
||||
if ($tipo == null) {
|
||||
if (!isset($this->unidades) or !isset($this->unidades->total)) {
|
||||
$unidades = [];
|
||||
@ -97,8 +103,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->unidades->{$tipo};
|
||||
}
|
||||
public function unidadesDisponibles($tipo = null)
|
||||
{
|
||||
public function unidadesDisponibles($tipo = null) {
|
||||
switch ($tipo) {
|
||||
case 1:
|
||||
case 'departamento':
|
||||
@ -188,12 +193,15 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->unidades->disponibles->{$tipo};
|
||||
}
|
||||
public function proyectoTipoUnidades()
|
||||
{
|
||||
return $this->hasMany(ProyectoTipoUnidad::class, 'proyecto')->orderByAsc('tipo')->findMany();
|
||||
protected $ptus;
|
||||
public function proyectoTipoUnidades() {
|
||||
if ($this->ptus === null) {
|
||||
$this->ptus = $this->setRelationship(ProyectoTipoUnidad::class, 'proyecto', 'id')->sort(['tipo', 'asc'])->many();
|
||||
}
|
||||
return $this->ptus;
|
||||
//return $this->hasMany(ProyectoTipoUnidad::class, 'proyecto')->orderByAsc('tipo')->findMany();
|
||||
}
|
||||
public function tipoUnidades()
|
||||
{
|
||||
public function tipoUnidades() {
|
||||
if (!isset($this->tipos_unidades)) {
|
||||
$tipos = \Model::factory(TipoUnidad::class)
|
||||
->select('tipo_unidad.*')
|
||||
@ -207,8 +215,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->tipos_unidades;
|
||||
}
|
||||
public function ventas($order = 'departamento')
|
||||
{
|
||||
public function ventas($order = 'departamento') {
|
||||
if (!isset($this->ventas)) {
|
||||
$ventas = model(Venta::class)
|
||||
->select('venta.*')
|
||||
@ -236,9 +243,8 @@ class Proyecto extends Model
|
||||
return $this->ventas;
|
||||
}
|
||||
protected $resciliaciones;
|
||||
public function resciliaciones()
|
||||
{
|
||||
if ($this->resciliaciones == null) {
|
||||
public function resciliaciones() {
|
||||
if ($this->resciliaciones === null) {
|
||||
$resciliaciones = model(Venta::class)
|
||||
->select('venta.*')
|
||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
||||
@ -258,8 +264,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->resciliaciones;
|
||||
}
|
||||
public function escrituras()
|
||||
{
|
||||
public function escrituras() {
|
||||
if (!isset($escrituras)) {
|
||||
$ventas = model(Venta::class)
|
||||
->select('venta.*')
|
||||
@ -279,8 +284,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->escrituras;
|
||||
}
|
||||
public function entregas()
|
||||
{
|
||||
public function entregas() {
|
||||
if (!isset($this->entregas)) {
|
||||
$entregas = [];
|
||||
$escrituras = $this->escrituras();
|
||||
@ -306,12 +310,15 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->entregas;
|
||||
}
|
||||
public function estados()
|
||||
{
|
||||
return $this->has_many(EstadoProyecto::class, 'proyecto')->orderByAsc('fecha')->findMany();
|
||||
protected $estados;
|
||||
public function estados() {
|
||||
if ($this->estados === null) {
|
||||
$this->estados = $this->setRelationship(EstadoProyecto::class, 'proyecto', 'id')->sort(['fecha', 'asc'])->many();
|
||||
}
|
||||
return $this->estados;
|
||||
//return $this->has_many(EstadoProyecto::class, 'proyecto')->orderByAsc('fecha')->findMany();
|
||||
}
|
||||
public function estado()
|
||||
{
|
||||
public function estado() {
|
||||
if (!isset($this->estado)) {
|
||||
$id = $this->has_many(EstadoProyecto::class, 'proyecto')->max('id');
|
||||
$this->estado = $this->has_many(EstadoProyecto::class, 'proyecto')->findOne($id);
|
||||
@ -319,13 +326,16 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->estado;
|
||||
}
|
||||
public function avances()
|
||||
{
|
||||
return $this->hasMany(AvanceConstruccion::class, 'proyecto')->orderByAsc('fecha')->findMany();
|
||||
protected $avances;
|
||||
public function avances() {
|
||||
if ($this->avances === null) {
|
||||
$this->avances = $this->setRelationship(AvanceConstruccion::class, 'proyecto', 'id')->sort(['fecha', 'asc'])->many();
|
||||
}
|
||||
return $this->avances;
|
||||
//return $this->hasMany(AvanceConstruccion::class, 'proyecto')->orderByAsc('fecha')->findMany();
|
||||
}
|
||||
protected $avance;
|
||||
public function avance()
|
||||
{
|
||||
public function avance() {
|
||||
if ($this->avance == null and $this->avances()) {
|
||||
$avance = array_reduce($this->avances(), function($carry, $item) {
|
||||
return ($carry += $item->avance);
|
||||
@ -335,8 +345,7 @@ class Proyecto extends Model
|
||||
return $this->avance;
|
||||
}
|
||||
protected $inicio;
|
||||
public function inicio()
|
||||
{
|
||||
public function inicio() {
|
||||
if (!isset($this->inicio) or $this->inicio == null) {
|
||||
$id = $this->has_many(EstadoProyecto::class, 'proyecto')->min('id');
|
||||
$this->inicio = $this->has_many(EstadoProyecto::class, 'proyecto')->findOne($id);
|
||||
@ -344,8 +353,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->inicio;
|
||||
}
|
||||
public function valores()
|
||||
{
|
||||
public function valores() {
|
||||
if (!isset($this->valores)) {
|
||||
$ventas = $this->ventas();
|
||||
|
||||
@ -473,8 +481,7 @@ class Proyecto extends Model
|
||||
|
||||
return $this->valores;
|
||||
}
|
||||
public function agentes()
|
||||
{
|
||||
public function agentes() {
|
||||
if (!isset($this->agentes)) {
|
||||
$this->agentes = \Model::factory(Agente::class)
|
||||
->select('agente.*')
|
||||
@ -485,8 +492,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->agentes;
|
||||
}
|
||||
public function operadores()
|
||||
{
|
||||
public function operadores() {
|
||||
if (!isset($this->operadores)) {
|
||||
$this->operadores = \Model::factory(Agente::class)
|
||||
->select('agente.*')
|
||||
@ -501,8 +507,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->operadores;
|
||||
}
|
||||
public function operadoresVigentes()
|
||||
{
|
||||
public function operadoresVigentes() {
|
||||
return $this->hasMany(ProyectoAgente::class, 'proyecto')
|
||||
->select('proyecto_agente.*')
|
||||
->join('agente_tipo', ['agente_tipo.id', '=', 'proyecto_agente.agente'])
|
||||
@ -511,8 +516,7 @@ class Proyecto extends Model
|
||||
->where('ep.tipo', 1)
|
||||
->findMany();
|
||||
}
|
||||
public function promociones()
|
||||
{
|
||||
public function promociones() {
|
||||
if (!isset($this->promociones)) {
|
||||
$this->promociones = \Model::factory(Promocion::class)
|
||||
->select('promocion.*')
|
||||
@ -527,8 +531,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->promociones;
|
||||
}
|
||||
public function pisos()
|
||||
{
|
||||
public function pisos() {
|
||||
if ($this->pisos == 0) {
|
||||
$pisos = $this->has_many(Unidad::class, 'proyecto')->where('tipo', 1)->max('piso');
|
||||
if (!$pisos) {
|
||||
@ -539,8 +542,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->pisos;
|
||||
}
|
||||
public function cuotasHoy()
|
||||
{
|
||||
public function cuotasHoy() {
|
||||
if (!isset($this->cuotas) or !isset($this->cuotas->hoy)) {
|
||||
$cuotas = [];
|
||||
if (isset($this->cuotas)) {
|
||||
@ -563,8 +565,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->cuotas->hoy;
|
||||
}
|
||||
public function cuotasPendientes()
|
||||
{
|
||||
public function cuotasPendientes() {
|
||||
if (!isset($this->cuotas) or !isset($this->cuotas->pendientes)) {
|
||||
$cuotas = [];
|
||||
if (isset($this->cuotas)) {
|
||||
@ -587,8 +588,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->cuotas->pendientes;
|
||||
}
|
||||
public function cuotasMes()
|
||||
{
|
||||
public function cuotasMes() {
|
||||
if (!isset($this->cuotas) or !isset($this->cuotas->mes)) {
|
||||
$cuotas = [];
|
||||
if (isset($this->cuotas)) {
|
||||
@ -611,16 +611,14 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->cuotas->mes;
|
||||
}
|
||||
public function tiposMediciones()
|
||||
{
|
||||
public function tiposMediciones() {
|
||||
$tipos = $this->has_many_through(\Incoviba\nuevo\Venta\TipoMedicion::class, \Incoviba\nuevo\Venta\ProyectoTipoMedicion::class, 'proyecto_id', 'tipo_medicion_id');
|
||||
if ($tipos) {
|
||||
return $tipos->orderByAsc('descripcion')->findMany();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function superficie($tipo = 'total')
|
||||
{
|
||||
public function superficie($tipo = 'total') {
|
||||
if (!isset($this->superficies) or !isset($this->superficies->{$tipo})) {
|
||||
$superficies = [];
|
||||
if (isset($this->superficies)) {
|
||||
@ -675,8 +673,7 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->superficies->{$tipo};
|
||||
}
|
||||
public function setDireccion(array $data)
|
||||
{
|
||||
public function setDireccion(array $data) {
|
||||
if (!is_numeric($data['comuna'])) {
|
||||
$comuna = model(Comuna::class)->where('descripcion', $data['comuna'])->findOne();
|
||||
$data['comuna'] = $comuna->id;
|
||||
@ -689,16 +686,14 @@ class Proyecto extends Model
|
||||
->findOne();
|
||||
$this->direccion = $direccion->id;
|
||||
}
|
||||
public function addAgente(array $data)
|
||||
{
|
||||
public function addAgente(array $data) {
|
||||
$data = ['agente' => $data['agente'], 'tipo' => $data['tipo']];
|
||||
$agente = (new Factory(AgenteTipo::class))->create($data);
|
||||
$agente->save();
|
||||
$this->agentes []= $agente;
|
||||
}
|
||||
protected $tipologias;
|
||||
public function tipologias()
|
||||
{
|
||||
public function tipologias() {
|
||||
if ($this->tipologias == null) {
|
||||
$pts = $this->proyectoTipoUnidades();
|
||||
$tipologias = [];
|
||||
@ -715,13 +710,16 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->tipologias;
|
||||
}
|
||||
public function pagares()
|
||||
{
|
||||
return $this->hasMany(Pagare::class, 'proyecto')->findMany();
|
||||
protected $pagares;
|
||||
public function pagares() {
|
||||
if ($this->pagares === null) {
|
||||
$this->pagares = $this->setRelationship(Pagare::class, 'proyecto', 'id')->many();
|
||||
}
|
||||
return $this->pagares;
|
||||
//return $this->hasMany(Pagare::class, 'proyecto')->findMany();
|
||||
}
|
||||
protected $cierres;
|
||||
public function cierres(int $vigentes = 0)
|
||||
{
|
||||
public function cierres(int $vigentes = 0) {
|
||||
if (!isset($this->cierres[$vigentes]) or $this->cierres[$vigentes] == null) {
|
||||
$orm = model(Cierre::class)
|
||||
->select('cierre.*')
|
||||
@ -761,8 +759,13 @@ class Proyecto extends Model
|
||||
}
|
||||
return $this->cierres[$vigentes];
|
||||
}
|
||||
protected $tipos;
|
||||
public function tipos() {
|
||||
return $this->hasMany(ProyectoTipoUnidad::class, 'proyecto')->findMany();
|
||||
if ($this->tipos === null) {
|
||||
$this->tipos = $this->setRelationship(ProyectoTipoUnidad::class, 'proyecto', 'id')->many();
|
||||
}
|
||||
return $this->tipos;
|
||||
//return $this->hasMany(ProyectoTipoUnidad::class, 'proyecto')->findMany();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user