Merge branch 'develop'
This commit is contained in:
@ -11,6 +11,8 @@ use Incoviba\old\Venta\Promocion;
|
|||||||
use Incoviba\old\Venta\TipoUnidad;
|
use Incoviba\old\Venta\TipoUnidad;
|
||||||
use Incoviba\old\Venta\Unidad;
|
use Incoviba\old\Venta\Unidad;
|
||||||
use Incoviba\old\Venta\Venta;
|
use Incoviba\old\Venta\Venta;
|
||||||
|
use Incoviba\nuevo\Venta\TipoMedicion;
|
||||||
|
use Incoviba\nuevo\Venta\ProyectoTipoMedicion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -66,7 +68,7 @@ class Proyecto extends Model {
|
|||||||
if (isset($this->unidades)) {
|
if (isset($this->unidades)) {
|
||||||
$unidades = (array) $this->unidades;
|
$unidades = (array) $this->unidades;
|
||||||
}
|
}
|
||||||
$unidades['total'] = $this->has_many(Unidad::class, 'proyecto')->findMany();
|
$unidades['total'] = $this->setRelationship(Unidad::class, 'id', 'proyecto')->many();
|
||||||
$this->unidades = (object) $unidades;
|
$this->unidades = (object) $unidades;
|
||||||
}
|
}
|
||||||
return $this->unidades->total;
|
return $this->unidades->total;
|
||||||
@ -98,7 +100,7 @@ class Proyecto extends Model {
|
|||||||
if (isset($this->unidades)) {
|
if (isset($this->unidades)) {
|
||||||
$unidades = (array) $this->unidades;
|
$unidades = (array) $this->unidades;
|
||||||
}
|
}
|
||||||
$unidades[$tipo] = $this->has_many(Unidad::class, 'proyecto')->where('tipo', $id_tipo)->findMany();
|
$unidades[$tipo] = $this->setRelationship(Unidad::class, 'id', 'proyecto')->build()->where([['tipo', $id_tipo]])->many();
|
||||||
$this->unidades = (object) $unidades;
|
$this->unidades = (object) $unidades;
|
||||||
}
|
}
|
||||||
return $this->unidades->{$tipo};
|
return $this->unidades->{$tipo};
|
||||||
@ -187,6 +189,9 @@ class Proyecto extends Model {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$disponibles = model(Unidad::class)->rawQuery($q, [$this->id])->findMany();
|
$disponibles = model(Unidad::class)->rawQuery($q, [$this->id])->findMany();
|
||||||
|
foreach ($disponibles as &$u) {
|
||||||
|
$u->setContainer($this->container);
|
||||||
|
}
|
||||||
$unidades['disponibles'][$tipo] = $disponibles;
|
$unidades['disponibles'][$tipo] = $disponibles;
|
||||||
$unidades['disponibles'] = (object) $unidades['disponibles'];
|
$unidades['disponibles'] = (object) $unidades['disponibles'];
|
||||||
$this->unidades = (object) $unidades;
|
$this->unidades = (object) $unidades;
|
||||||
@ -196,91 +201,96 @@ class Proyecto extends Model {
|
|||||||
protected $ptus;
|
protected $ptus;
|
||||||
public function proyectoTipoUnidades() {
|
public function proyectoTipoUnidades() {
|
||||||
if ($this->ptus === null) {
|
if ($this->ptus === null) {
|
||||||
$this->ptus = $this->setRelationship(ProyectoTipoUnidad::class, 'proyecto', 'id')->sort(['tipo', 'asc'])->many();
|
$this->ptus = $this->setRelationship(ProyectoTipoUnidad::class, 'proyecto', 'id')->build()->sort(['tipo', 'asc'])->many();
|
||||||
}
|
}
|
||||||
return $this->ptus;
|
return $this->ptus;
|
||||||
//return $this->hasMany(ProyectoTipoUnidad::class, 'proyecto')->orderByAsc('tipo')->findMany();
|
//return $this->hasMany(ProyectoTipoUnidad::class, 'proyecto')->orderByAsc('tipo')->findMany();
|
||||||
}
|
}
|
||||||
public function tipoUnidades() {
|
public function tipoUnidades() {
|
||||||
if (!isset($this->tipos_unidades)) {
|
if (!isset($this->tipos_unidades)) {
|
||||||
$tipos = \Model::factory(TipoUnidad::class)
|
$tipos = $this->container->get('model')->find(TipoUnidad::class)
|
||||||
->select('tipo_unidad.*')
|
->select('tipo_unidad.*')
|
||||||
->join('unidad', ['unidad.tipo', '=', 'tipo_unidad.id'])
|
->join([
|
||||||
->join('proyecto', ['proyecto.id', '=', 'unidad.proyecto'])
|
['unidad', 'unidad.tipo', 'tipo_unidad.id'],
|
||||||
->where('proyecto.id', $this->id)
|
['proyecto', 'proyecto.id', 'unidad.proyecto']
|
||||||
->order_by_asc('tipo_unidad.id')
|
])
|
||||||
->group_by('tipo_unidad.id')
|
->where([
|
||||||
->findMany();
|
['proyecto.id', $this->id]
|
||||||
|
])
|
||||||
|
->order('tipo_unidad.id')
|
||||||
|
->group('tipo_unidad.id')
|
||||||
|
->many();
|
||||||
$this->tipos_unidades = $tipos;
|
$this->tipos_unidades = $tipos;
|
||||||
}
|
}
|
||||||
return $this->tipos_unidades;
|
return $this->tipos_unidades;
|
||||||
}
|
}
|
||||||
public function ventas($order = 'departamento') {
|
public function ventas($order = 'departamento') {
|
||||||
if (!isset($this->ventas)) {
|
if (!isset($this->ventas)) {
|
||||||
$ventas = model(Venta::class)
|
$ventas = $this->container->get('model')->find(Venta::class)
|
||||||
->select('venta.*')
|
->select('venta.*')
|
||||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
->join([
|
||||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
['propiedad', 'propiedad.id', 'venta.propiedad'],
|
||||||
->rawJoin('JOIN (SELECT `e1`.* FROM (SELECT `venta`, MAX(`id`) AS `id` FROM `estado_venta` GROUP BY `venta`) AS `e0` JOIN `estado_venta` AS `e1` ON `e1`.`id` = `e0`.`id`)', ['estado_venta.venta', '=', 'venta.id'], 'estado_venta')
|
['unidad', 'unidad.id', 'propiedad.unidad_principal'],
|
||||||
->join('tipo_estado_venta', ['tipo_estado_venta.id', '=', 'estado_venta.estado'])
|
['JOIN (SELECT `e1`.* FROM (SELECT `venta`, MAX(`id`) AS `id` FROM `estado_venta` GROUP BY `venta`) AS `e0` JOIN `estado_venta` AS `e1` ON `e1`.`id` = `e0`.`id`)', 'estado_venta.venta', 'venta.id', 'alias' => 'estado_venta', 'type' => 'raw'],
|
||||||
->where('unidad.proyecto', $this->id)
|
['tipo_estado_venta', 'tipo_estado_venta.id', 'estado_venta.estado']
|
||||||
->where('unidad.tipo', 1)
|
])
|
||||||
->where('tipo_estado_venta.activa', 1);
|
->where([
|
||||||
|
['unidad.proyecto', $this->id],
|
||||||
|
['unidad.tipo', 1],
|
||||||
|
['tipo_estado_venta.activa', 1]
|
||||||
|
]);
|
||||||
switch (strtolower($order)) {
|
switch (strtolower($order)) {
|
||||||
case 'fecha':
|
case 'fecha':
|
||||||
$ventas = $ventas->orderByAsc('venta.fecha');
|
$ventas = $ventas->order('venta.fecha');
|
||||||
case 'departamento':
|
case 'departamento':
|
||||||
default:
|
default:
|
||||||
$ventas = $ventas->orderByExpr('LPAD(`unidad`.`descripcion`, 4, "0")');
|
$ventas = $ventas->order(['LPAD(`unidad`.`descripcion`, 4, "0")' => 'expr']);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$ventas = $ventas->find_many();
|
$ventas = $ventas->many();
|
||||||
$this->ventas = $ventas;
|
$this->ventas = $ventas;
|
||||||
foreach ($this->ventas as &$venta) {
|
|
||||||
$venta->setContainer($this->container);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $this->ventas;
|
return $this->ventas;
|
||||||
}
|
}
|
||||||
protected $resciliaciones;
|
protected $resciliaciones;
|
||||||
public function resciliaciones() {
|
public function resciliaciones() {
|
||||||
if ($this->resciliaciones === null) {
|
if ($this->resciliaciones === null) {
|
||||||
$resciliaciones = model(Venta::class)
|
$resciliaciones = $this->container->get('model')->find(Venta::class)
|
||||||
->select('venta.*')
|
->select('venta.*')
|
||||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
->join([
|
||||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
['propiedad', 'propiedad.id', 'venta.propiedad'],
|
||||||
->rawJoin('JOIN (SELECT `e1`.* FROM (SELECT `venta`, MAX(`id`) AS `id` FROM `estado_venta` GROUP BY `venta`) AS `e0` JOIN `estado_venta` AS `e1` ON `e1`.`id` = `e0`.`id`)', ['estado_venta.venta', '=', 'venta.id'], 'estado_venta')
|
['unidad', 'unidad.id', 'propiedad.unidad_principal'],
|
||||||
->join('tipo_estado_venta', ['tipo_estado_venta.id', '=', 'estado_venta.estado'])
|
['JOIN (SELECT `e1`.* FROM (SELECT `venta`, MAX(`id`) AS `id` FROM `estado_venta` GROUP BY `venta`) AS `e0` JOIN `estado_venta` AS `e1` ON `e1`.`id` = `e0`.`id`)', 'estado_venta.venta', 'venta.id', 'alias' => 'estado_venta', 'type' => 'raw'],
|
||||||
->where('unidad.proyecto', $this->id)
|
['tipo_estado_venta', 'tipo_estado_venta.id', 'estado_venta.estado']
|
||||||
->where('unidad.tipo', 1)
|
])
|
||||||
->where('tipo_estado_venta.activa', 0)
|
->where([
|
||||||
->orderByExpr('LPAD(`unidad`.`descripcion`, 4, "0")')
|
['unidad.proyecto', $this->id],
|
||||||
->find_many()
|
['unidad.tipo', 1],
|
||||||
;
|
['tipo_estado_venta.activa', 0]
|
||||||
|
])
|
||||||
|
->order(['LPAD(`unidad`.`descripcion`, 4, "0")' => 'expr'])
|
||||||
|
->many();
|
||||||
$this->resciliaciones = $resciliaciones;
|
$this->resciliaciones = $resciliaciones;
|
||||||
foreach ($this->resciliaciones as &$venta) {
|
|
||||||
$venta->setContainer($this->container);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $this->resciliaciones;
|
return $this->resciliaciones;
|
||||||
}
|
}
|
||||||
public function escrituras() {
|
public function escrituras() {
|
||||||
if (!isset($escrituras)) {
|
if (!isset($escrituras)) {
|
||||||
$ventas = model(Venta::class)
|
$ventas = $this->container->get('model')->find(Venta::class)
|
||||||
->select('venta.*')
|
->select('venta.*')
|
||||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
->join([
|
||||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
['propiedad', 'propiedad.id', 'venta.propiedad'],
|
||||||
->where('unidad.proyecto', $this->id)
|
['unidad', 'unidad.id', 'propiedad.unidad_principal']
|
||||||
->where('venta.estado', 1)
|
])
|
||||||
->where('unidad.tipo', 1)
|
->where([
|
||||||
->whereNotEqual('venta.escriturado', '0')
|
['unidad.proyecto', $this->id],
|
||||||
->orderByExpr('LPAD(unidad.descripcion, 4, "0")')
|
['venta.estado', 1],
|
||||||
->find_many()
|
['unidad.tipo', 1],
|
||||||
;
|
['venta.escriturado', '0', '!=']
|
||||||
|
])
|
||||||
|
->order(['LPAD(unidad.descripcion, 4, "0")' => 'expr'])
|
||||||
|
->many();
|
||||||
$this->escrituras = $ventas;
|
$this->escrituras = $ventas;
|
||||||
foreach ($this->escrituras as &$venta) {
|
|
||||||
$venta->setContainer($this->container);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $this->escrituras;
|
return $this->escrituras;
|
||||||
}
|
}
|
||||||
@ -320,9 +330,10 @@ class Proyecto extends Model {
|
|||||||
}
|
}
|
||||||
public function estado() {
|
public function estado() {
|
||||||
if (!isset($this->estado)) {
|
if (!isset($this->estado)) {
|
||||||
$id = $this->has_many(EstadoProyecto::class, 'proyecto')->max('id');
|
$this->estado = $this->setRelationship(EstadoProyecto::class, 'proyecto', 'id')->build()
|
||||||
$this->estado = $this->has_many(EstadoProyecto::class, 'proyecto')->findOne($id);
|
->order(['id' => 'desc'])
|
||||||
$this->estado->setContainer($this->container);
|
->group('id')
|
||||||
|
->one();
|
||||||
}
|
}
|
||||||
return $this->estado;
|
return $this->estado;
|
||||||
}
|
}
|
||||||
@ -347,9 +358,10 @@ class Proyecto extends Model {
|
|||||||
protected $inicio;
|
protected $inicio;
|
||||||
public function inicio() {
|
public function inicio() {
|
||||||
if (!isset($this->inicio) or $this->inicio == null) {
|
if (!isset($this->inicio) or $this->inicio == null) {
|
||||||
$id = $this->has_many(EstadoProyecto::class, 'proyecto')->min('id');
|
$this->inicio = $this->setRelationship(EstadoProyecto::class, 'proyecto', 'id')->build()
|
||||||
$this->inicio = $this->has_many(EstadoProyecto::class, 'proyecto')->findOne($id);
|
->order('id')
|
||||||
$this->inicio->setContainer($this->container);
|
->group('id')
|
||||||
|
->one();
|
||||||
}
|
}
|
||||||
return $this->inicio;
|
return $this->inicio;
|
||||||
}
|
}
|
||||||
@ -387,7 +399,7 @@ class Proyecto extends Model {
|
|||||||
* totales // vendidos + estimados
|
* totales // vendidos + estimados
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$premios = model(Promocion::class)->findMany();
|
$premios = $this->container->get('model')->find(Promocion::class)->many();
|
||||||
$valores = (object) [
|
$valores = (object) [
|
||||||
'vendidos' => new BaseValores(),
|
'vendidos' => new BaseValores(),
|
||||||
'estimados' => new BaseValores(),
|
'estimados' => new BaseValores(),
|
||||||
@ -483,58 +495,79 @@ class Proyecto extends Model {
|
|||||||
}
|
}
|
||||||
public function agentes() {
|
public function agentes() {
|
||||||
if (!isset($this->agentes)) {
|
if (!isset($this->agentes)) {
|
||||||
$this->agentes = \Model::factory(Agente::class)
|
$this->agentes = $this->container->get('model')->find(Agente::class)
|
||||||
->select('agente.*')
|
->select('agente.*')
|
||||||
->join('proyecto_agente', ['proyecto_agente.agente', '=', 'agente.id'])
|
->join([
|
||||||
->where('proyecto_agente.proyecto', $this->id)
|
['proyecto_agente', 'proyecto_agente.agente', 'agente.id']
|
||||||
->orderByAsc('agente.abreviacion')
|
])
|
||||||
->findMany();
|
->where([
|
||||||
|
['proyecto_agente.proyecto', $this->id]
|
||||||
|
])
|
||||||
|
->order('agente.abreviacion')
|
||||||
|
->many();
|
||||||
}
|
}
|
||||||
return $this->agentes;
|
return $this->agentes;
|
||||||
}
|
}
|
||||||
public function operadores() {
|
public function operadores() {
|
||||||
if (!isset($this->operadores)) {
|
if (!isset($this->operadores)) {
|
||||||
$this->operadores = \Model::factory(Agente::class)
|
$this->operadores = $this->container->get('model')->find(Agente::class)
|
||||||
->select('agente.*')
|
->select([
|
||||||
->select('agente_tipo.id', 'agente_tipo')
|
['agente.*'],
|
||||||
->join('agente_tipo', ['agente_tipo.agente', '=', 'agente.id'])
|
['agente_tipo.id', 'alias' => 'agente_tipo']
|
||||||
->join('proyecto_agente', ['proyecto_agente.agente', '=', 'agente_tipo.id'])
|
])
|
||||||
->where('agente_tipo.tipo', 19)
|
->join([
|
||||||
->where('proyecto_agente.proyecto', $this->id)
|
['agente_tipo', 'agente_tipo.agente', 'agente.id'],
|
||||||
->orderByAsc('agente.abreviacion')
|
['proyecto_agente', 'proyecto_agente.agente', 'agente_tipo.id']
|
||||||
->groupBy('agente_tipo.id')
|
])
|
||||||
->findMany();
|
->where([
|
||||||
|
['agente_tipo.tipo', 19],
|
||||||
|
['proyecto_agente.proyecto', $this->id]
|
||||||
|
])
|
||||||
|
->order('agente.abreviacion')
|
||||||
|
->group('agente_tipo.id')
|
||||||
|
->many();
|
||||||
}
|
}
|
||||||
return $this->operadores;
|
return $this->operadores;
|
||||||
}
|
}
|
||||||
public function operadoresVigentes() {
|
public function operadoresVigentes() {
|
||||||
return $this->hasMany(ProyectoAgente::class, 'proyecto')
|
return $this->setRelationship(ProyectoAgente::class, 'id', 'proyecto')->build()
|
||||||
->select('proyecto_agente.*')
|
->select('proyecto_agente.*')
|
||||||
->join('agente_tipo', ['agente_tipo.id', '=', 'proyecto_agente.agente'])
|
->join([
|
||||||
->rawJoin('JOIN (SELECT e1.* FROM estado_proyecto_agente e1 JOIN (SELECT agente, MAX(id) AS id FROM estado_proyecto_agente GROUP BY agente) e0 ON e0.id = e1.id)', ['ep.agente', '=', 'proyecto_agente.id'], 'ep')
|
['agente_tipo', 'agente_tipo.id', 'proyecto_agente.agente'],
|
||||||
->where('agente_tipo.tipo', 19)
|
['JOIN (SELECT e1.* FROM estado_proyecto_agente e1 JOIN (SELECT agente, MAX(id) AS id FROM estado_proyecto_agente GROUP BY agente) e0 ON e0.id = e1.id)', 'ep.agente', 'proyecto_agente.id', 'alias' => 'ep', 'type' => 'raw']
|
||||||
->where('ep.tipo', 1)
|
])
|
||||||
->findMany();
|
->where([
|
||||||
|
['agente_tipo,tipo', 19],
|
||||||
|
['eo.tipo', 1]
|
||||||
|
])
|
||||||
|
->many();
|
||||||
}
|
}
|
||||||
public function promociones() {
|
public function promociones() {
|
||||||
if (!isset($this->promociones)) {
|
if (!isset($this->promociones)) {
|
||||||
$this->promociones = \Model::factory(Promocion::class)
|
$this->promociones = $this->container->get('model')->find(Promocion::class)
|
||||||
->select('promocion.*')
|
->select('promocion.*')
|
||||||
->join('promocion_venta', ['promocion_venta.promocion', '=', 'promocion.id'])
|
->join([
|
||||||
->join('venta', ['venta.id', '=', 'promocion_venta.venta'])
|
['promocion_venta', 'promocion_venta.promocion', 'promocion.id'],
|
||||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
['venta', 'venta.id', 'promocion_venta.venta'],
|
||||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
['propiedad', 'propiedad.id', 'venta.propiedad'],
|
||||||
->where('unidad.proyecto', $this->id)
|
['unidad', 'unidad.id', 'propiedad.unidad_principal']
|
||||||
->groupBy('promocion.id')
|
])
|
||||||
->orderByAsc('promocion.titulo')
|
->where([['unidad.proyecto', $this->id]])
|
||||||
->findMany();
|
->group('promocion.id')
|
||||||
|
->order('promocion.titulo')
|
||||||
|
->many();
|
||||||
}
|
}
|
||||||
return $this->promociones;
|
return $this->promociones;
|
||||||
}
|
}
|
||||||
public function pisos() {
|
public function pisos() {
|
||||||
if ($this->pisos == 0) {
|
if ($this->pisos == 0) {
|
||||||
$pisos = $this->has_many(Unidad::class, 'proyecto')->where('tipo', 1)->max('piso');
|
$pisos = $this->setRelationship(Unidad::class, 'proyecto', 'id')->build()
|
||||||
|
->select('MAX(piso) AS pisos')
|
||||||
|
->where([['tipo', 1]])
|
||||||
|
->group('id')
|
||||||
|
->one()->pisos;
|
||||||
if (!$pisos) {
|
if (!$pisos) {
|
||||||
|
$this->pisos = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$this->pisos = $pisos;
|
$this->pisos = $pisos;
|
||||||
@ -549,18 +582,23 @@ class Proyecto extends Model {
|
|||||||
$cuotas = (array) $this->cuotas;
|
$cuotas = (array) $this->cuotas;
|
||||||
}
|
}
|
||||||
$f = Carbon::today($this->container->get('settings')->app->timezone);
|
$f = Carbon::today($this->container->get('settings')->app->timezone);
|
||||||
$cuotas['hoy'] = model(Venta::class)
|
$cuotas['hoy'] = $this->container->get('model')->find(Venta::class)
|
||||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
->select('COUNT(cuota.id) AS cantidad')
|
||||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
->join([
|
||||||
->join('cuota', ['cuota.pie', '=', 'venta.pie'])
|
['propiedad', 'propiedad.id', 'venta.propiedad'],
|
||||||
->join('pago', ['pago.id', '=', 'cuota.pago'])
|
['unidad', 'unidad.id', 'propiedad.unidad_principal'],
|
||||||
->raw_join('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'], 'ep')
|
['cuota', 'cuota.pie', 'venta.pie'],
|
||||||
->where('unidad.proyecto', $this->id)
|
['pago', 'pago.id', 'cuota.pago'],
|
||||||
->where('venta.estado', 1)
|
['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']
|
||||||
->where('pago.fecha', $f->format('Y-m-d'))
|
])
|
||||||
->whereLt('ep.estado', 1)
|
->where([
|
||||||
->whereGte('ep.estado', 0)
|
['unidad.proyecto', $this->id],
|
||||||
->count('cuota.id');
|
['venta.estado', 1],
|
||||||
|
['pago.fecha', $f->format('Y-m-d')],
|
||||||
|
['ep.estado', 1, '<'],
|
||||||
|
['ep.estado', 0, '>=']
|
||||||
|
])
|
||||||
|
->one()->cantidad;
|
||||||
$this->cuotas = (object) $cuotas;
|
$this->cuotas = (object) $cuotas;
|
||||||
}
|
}
|
||||||
return $this->cuotas->hoy;
|
return $this->cuotas->hoy;
|
||||||
@ -572,18 +610,23 @@ class Proyecto extends Model {
|
|||||||
$cuotas = (array) $this->cuotas;
|
$cuotas = (array) $this->cuotas;
|
||||||
}
|
}
|
||||||
$f = Carbon::today($this->container->get('settings')->app->timezone);
|
$f = Carbon::today($this->container->get('settings')->app->timezone);
|
||||||
$cuotas['pendientes'] = model(Cuota::class)
|
$cuotas['pendientes'] = $this->container->get('model')->find(Cuota::class)
|
||||||
->join('venta', ['cuota.pie', '=', 'venta.pie'])
|
->select('COUNT(cuota.id) AS cantidad')
|
||||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
->join([
|
||||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
['venta', 'cuota.pie', 'venta.pie'],
|
||||||
->join('pago', ['pago.id', '=', 'cuota.pago'])
|
['propiedad', 'propiedad.id', 'venta.propiedad'],
|
||||||
->raw_join('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'], 'ep')
|
['unidad', 'unidad.id', 'propiedad.unidad_principal'],
|
||||||
->where('unidad.proyecto', $this->id)
|
['pago', 'pago.id', 'cuota.pago'],
|
||||||
->where('venta.estado', 1)
|
['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']
|
||||||
->whereLt('pago.fecha', $f->format('Y-m-d'))
|
])
|
||||||
->whereLt('ep.estado', 1)
|
->where([
|
||||||
->whereGte('ep.estado', 0)
|
['unidad.proyecto', $this->id],
|
||||||
->count('cuota.id');
|
['venta.estado', 1],
|
||||||
|
['pago.fecha', $f->format('Y-m-d'), '<'],
|
||||||
|
['ep.estado', 1, '<'],
|
||||||
|
['ep.estado', 0, '>=']
|
||||||
|
])
|
||||||
|
->one()->cantidad;
|
||||||
$this->cuotas = (object) $cuotas;
|
$this->cuotas = (object) $cuotas;
|
||||||
}
|
}
|
||||||
return $this->cuotas->pendientes;
|
return $this->cuotas->pendientes;
|
||||||
@ -595,26 +638,35 @@ class Proyecto extends Model {
|
|||||||
$cuotas = (array) $this->cuotas;
|
$cuotas = (array) $this->cuotas;
|
||||||
}
|
}
|
||||||
$f = Carbon::today($this->container->get('settings')->app->timezone);
|
$f = Carbon::today($this->container->get('settings')->app->timezone);
|
||||||
$cuotas['mes'] = model(Cuota::class)
|
$cuotas['mes'] = $this->container->get('model')->find(Cuota::class)
|
||||||
->join('venta', ['cuota.pie', '=', 'venta.pie'])
|
->join([
|
||||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
['venta', 'cuota.pie', 'venta.pie'],
|
||||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
['propiedad', 'propiedad.id', 'venta.propiedad']
|
||||||
->join('pago', ['pago.id', '=', 'cuota.pago'])
|
['unidad', 'unidad.id', 'cuota.pago'],
|
||||||
->raw_join('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'], 'ep')
|
['pago', 'pago.id', 'cuota.pago'],
|
||||||
->where('unidad.proyecto', $this->id)
|
['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']
|
||||||
->where('venta.estado', 1)
|
])
|
||||||
->whereGt('pago.fecha', $f->format('Y-m-d'))
|
->where([
|
||||||
->whereLte('pago.fecha', $f->copy()->addMonth(1)->format('Y-m-d'))
|
['unidad.proyecto', $this->id],
|
||||||
->where('ep.estado', 0)
|
['venta.estado', 1],
|
||||||
->findMany();
|
['pago.fecha', $f->format('Y-m-d'), '>'],
|
||||||
|
['pago.fecha', $f->copy()->addMonth(1)->format('Y-m-d'), '<='],
|
||||||
|
['ep.estado', 0]
|
||||||
|
])
|
||||||
|
->many();
|
||||||
$this->cuotas = (object) $cuotas;
|
$this->cuotas = (object) $cuotas;
|
||||||
}
|
}
|
||||||
return $this->cuotas->mes;
|
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');
|
$tipos = (new Relationship)
|
||||||
|
->setFactory($this->container->get('model'))
|
||||||
|
->setStart(TipoMedicion::class)
|
||||||
|
->with(TipoMedicion::class, 'id', ProyectoTipoMedicion::class, 'tipo_medicion_id')
|
||||||
|
->with(ProyectoTipoMedicion::class, 'proyecto_id', get_called_class(), 'id')
|
||||||
|
->setCondition(get_called_class(), 'id', $this->id)->build();
|
||||||
if ($tipos) {
|
if ($tipos) {
|
||||||
return $tipos->orderByAsc('descripcion')->findMany();
|
return $tipos->order('descripcion')->many();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -642,22 +694,33 @@ class Proyecto extends Model {
|
|||||||
case 'vendible':
|
case 'vendible':
|
||||||
$superficies['vendible'] = 0;
|
$superficies['vendible'] = 0;
|
||||||
if ($this->unidades()) {
|
if ($this->unidades()) {
|
||||||
$metros = $this->hasMany(Unidad::class, 'proyecto')->selectExpr('SUM(m2 + logia + terraza /2)', 'metros')->where('tipo', 1)->groupBy('proyecto')->findOne();
|
$metros = $this->setRelationship(Unidad:class, 'proyecto', 'id')
|
||||||
|
->build()
|
||||||
|
->select([['SUM(m2 + logia + terraza /2)', 'metros']])
|
||||||
|
->where([
|
||||||
|
['tipo', 1]
|
||||||
|
])
|
||||||
|
group('proyecto')
|
||||||
|
->one();
|
||||||
$superficies['vendible'] = $metros->metros;
|
$superficies['vendible'] = $metros->metros;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'vendida':
|
case 'vendida':
|
||||||
$superficies['vendida'] = 0;
|
$superficies['vendida'] = 0;
|
||||||
if ($this->ventas()) {
|
if ($this->ventas()) {
|
||||||
$metros = model(Venta::class)
|
$metros = $this->container->get('model')->find(Venta::class)
|
||||||
->selectExpr('SUM(unidad.m2 + unidad.logia + unidad.terraza / 2)', 'metros')
|
->select([['SUM(unidad.m2 + unidad.logia + unidad.terraza / 2)', 'metros']])
|
||||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
->join([
|
||||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
['propiedad', 'propiedad.id', 'venta.propiedad'],
|
||||||
->where('unidad.proyecto', $this->id)
|
['unidad', 'unidad.id', 'propiedad.unidad_principal']
|
||||||
->where('venta.estado', 1)
|
])
|
||||||
->where('unidad.tipo', 1)
|
->where([
|
||||||
->groupBy('unidad.proyecto')
|
['unidad.proyecto', $this->id],
|
||||||
->findOne();
|
['venta.estado', 1],
|
||||||
|
['unidad.tipo', 1]
|
||||||
|
])
|
||||||
|
->group('unidad.proyecto')
|
||||||
|
->one();
|
||||||
if ($metros) {
|
if ($metros) {
|
||||||
$superficies['vendida'] = $metros->metros;
|
$superficies['vendida'] = $metros->metros;
|
||||||
}
|
}
|
||||||
@ -675,21 +738,24 @@ class Proyecto extends Model {
|
|||||||
}
|
}
|
||||||
public function setDireccion(array $data) {
|
public function setDireccion(array $data) {
|
||||||
if (!is_numeric($data['comuna'])) {
|
if (!is_numeric($data['comuna'])) {
|
||||||
$comuna = model(Comuna::class)->where('descripcion', $data['comuna'])->findOne();
|
$comuna = $this->container->get('model')->find(Comuna::class)
|
||||||
|
->where([['descripcion', $data['comuna']]])
|
||||||
|
->one();
|
||||||
$data['comuna'] = $comuna->id;
|
$data['comuna'] = $comuna->id;
|
||||||
}
|
}
|
||||||
$direccion = model(Direccion::class)
|
$direccion = $this->container->get('model')->find(Direccion::class)
|
||||||
->where('calle', $data['calle'])
|
->where([
|
||||||
->where('numero', $data['numero'])
|
['calle', $data['calle']],
|
||||||
->where('extra', $data['extra'])
|
['numero', $data['numero']],
|
||||||
->where('comuna', $data['comuna'])
|
['extra', $data['extra']],
|
||||||
->findOne();
|
['comuna', $data['comuna']]
|
||||||
|
])
|
||||||
|
->one();
|
||||||
$this->direccion = $direccion->id;
|
$this->direccion = $direccion->id;
|
||||||
}
|
}
|
||||||
public function addAgente(array $data) {
|
public function addAgente(array $data) {
|
||||||
$data = ['agente' => $data['agente'], 'tipo' => $data['tipo']];
|
$data = ['agente' => $data['agente'], 'tipo' => $data['tipo']];
|
||||||
$agente = (new Factory(AgenteTipo::class))->create($data);
|
$agente = $this->container->get('model')->create(AgenteTipo::class, $data);
|
||||||
$agente->save();
|
|
||||||
$this->agentes []= $agente;
|
$this->agentes []= $agente;
|
||||||
}
|
}
|
||||||
protected $tipologias;
|
protected $tipologias;
|
||||||
@ -700,7 +766,10 @@ class Proyecto extends Model {
|
|||||||
foreach ($pts as $pt) {
|
foreach ($pts as $pt) {
|
||||||
if ($pt->tipologia()) {
|
if ($pt->tipologia()) {
|
||||||
if (!isset($tipologias[$pt->tipologia()->tipologia->descripcion])) {
|
if (!isset($tipologias[$pt->tipologia()->tipologia->descripcion])) {
|
||||||
$tipologias[$pt->tipologia()->tipologia->descripcion] = (object) ['tipologia' => $pt->tipologia()->tipologia, 'tipos' => []];
|
$tipologias[$pt->tipologia()->tipologia->descripcion] = (object) [
|
||||||
|
'tipologia' => $pt->tipologia()->tipologia,
|
||||||
|
'tipos' => []
|
||||||
|
];
|
||||||
}
|
}
|
||||||
$tipologias[$pt->tipologia()->tipologia->descripcion]->tipos []= $pt;
|
$tipologias[$pt->tipologia()->tipologia->descripcion]->tipos []= $pt;
|
||||||
continue;
|
continue;
|
||||||
|
@ -19,16 +19,18 @@ class Propiedad extends Model
|
|||||||
private $estacionamientos_arr = null;
|
private $estacionamientos_arr = null;
|
||||||
private $bodegas_arr = null;
|
private $bodegas_arr = null;
|
||||||
|
|
||||||
|
protected $unidad;
|
||||||
public function unidad()
|
public function unidad()
|
||||||
{
|
{
|
||||||
$unidad = $this->belongs_to(Unidad::class, 'unidad_principal')->findOne();
|
if ($this->unidad === null) {
|
||||||
$unidad->setContainer($this->container);
|
$this->unidad = $this->setRelationship(Unidad::class, 'id', 'unidad_principal')->one();
|
||||||
return $unidad;
|
}
|
||||||
|
return $this->unidad;
|
||||||
}
|
}
|
||||||
protected $unidades;
|
protected $unidades;
|
||||||
public function unidades() {
|
public function unidades() {
|
||||||
if ($this->unidades == null) {
|
if ($this->unidades == null) {
|
||||||
$this->unidades = $this->hasMany(PropiedadUnidad::class, 'propiedad')->findMany();
|
$this->unidades = $this->setRelationship(PropiedadUnidad::class, 'propiedad', 'id')->many();
|
||||||
}
|
}
|
||||||
return $this->unidades;
|
return $this->unidades;
|
||||||
}
|
}
|
||||||
@ -57,7 +59,7 @@ class Propiedad extends Model
|
|||||||
$ests = explode(';', $this->estacionamientos);
|
$ests = explode(';', $this->estacionamientos);
|
||||||
$estacionamientos = [];
|
$estacionamientos = [];
|
||||||
foreach ($ests as $e) {
|
foreach ($ests as $e) {
|
||||||
$estacionamiento = \Model::factory(Unidad::class)->findOne($e);
|
$estacionamiento = $this->container->get('model')->find(Unidad::class)->one($e);
|
||||||
if ($estacionamiento) {
|
if ($estacionamiento) {
|
||||||
$estacionamientos []= $estacionamiento;
|
$estacionamientos []= $estacionamiento;
|
||||||
}
|
}
|
||||||
@ -91,7 +93,7 @@ class Propiedad extends Model
|
|||||||
$bods = explode(';', $this->bodegas);
|
$bods = explode(';', $this->bodegas);
|
||||||
$bodegas = [];
|
$bodegas = [];
|
||||||
foreach ($bods as $b) {
|
foreach ($bods as $b) {
|
||||||
$bodega = \Model::factory(Unidad::class)->findOne($b);
|
$bodega = $this->container->get('model')->find(Unidad::class)->one($b);
|
||||||
if ($bodega) {
|
if ($bodega) {
|
||||||
$bodegas []= $bodega;
|
$bodegas []= $bodega;
|
||||||
}
|
}
|
||||||
@ -111,9 +113,13 @@ class Propiedad extends Model
|
|||||||
}
|
}
|
||||||
return $this->bodegas_arr;
|
return $this->bodegas_arr;
|
||||||
}
|
}
|
||||||
|
protected $venta;
|
||||||
public function venta()
|
public function venta()
|
||||||
{
|
{
|
||||||
return $this->has_one(Venta::class, 'propiedad')->findOne();
|
if ($this->venta === null) {
|
||||||
|
$this->venta = $this->setRelationship(Venta::class, 'propiedad', 'id')->one();
|
||||||
|
}
|
||||||
|
return $this->venta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -7,14 +7,14 @@ class PropiedadUnidad extends Model {
|
|||||||
protected $propiedad_model;
|
protected $propiedad_model;
|
||||||
public function propiedad() {
|
public function propiedad() {
|
||||||
if ($this->propiedad_model == null) {
|
if ($this->propiedad_model == null) {
|
||||||
$this->propiedad_model = $this->belongsTo(Propiedad::class, 'propiedad')->findOne();
|
$this->propiedad_model = $this->setRelationship(Propiedad::class, 'id', 'propiedad')->one();
|
||||||
}
|
}
|
||||||
return $this->propiedad_model;
|
return $this->propiedad_model;
|
||||||
}
|
}
|
||||||
protected $unidad_model;
|
protected $unidad_model;
|
||||||
public function unidad() {
|
public function unidad() {
|
||||||
if ($this->unidad_model == null) {
|
if ($this->unidad_model == null) {
|
||||||
$this->unidad_model = $this->belongsTo(Unidad::class, 'unidad')->findOne();
|
$this->unidad_model = $this->setRelationship(Unidad::class, 'id', 'unidad')->one();
|
||||||
}
|
}
|
||||||
return $this->unidad_model;
|
return $this->unidad_model;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user