config
This commit is contained in:
12
app_old/incoviba/modelos/src/common/Action.php
Normal file
12
app_old/incoviba/modelos/src/common/Action.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace Incoviba\common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $description
|
||||
*/
|
||||
class Action extends Model
|
||||
{
|
||||
}
|
63
app_old/incoviba/modelos/src/common/Auth.php
Normal file
63
app_old/incoviba/modelos/src/common/Auth.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace Incoviba\common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int $id
|
||||
* @property int $user_id foreign=users.id
|
||||
* @property DateTime $time
|
||||
* @property string $selector
|
||||
* @property string $token
|
||||
* @property int $status length=1 default=1
|
||||
*
|
||||
*/
|
||||
class Auth extends Model
|
||||
{
|
||||
public static $_table = 'logins';
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id')->findOne();
|
||||
}
|
||||
public function token($token = null)
|
||||
{
|
||||
if ($token == null) {
|
||||
return false;
|
||||
}
|
||||
$this->token = \password_hash($token, \PASSWORD_DEFAULT);
|
||||
}
|
||||
public function time($time = null)
|
||||
{
|
||||
if ($time == null) {
|
||||
return Carbon::parse($this->time, config('app.timezone'));
|
||||
}
|
||||
if (!\is_a($time, \DateTime::class)) {
|
||||
$time = Carbon::parse($time, config('app.timezone'));
|
||||
}
|
||||
$this->time = $time;
|
||||
}
|
||||
public function save()
|
||||
{
|
||||
if (!\is_string($this->time)) {
|
||||
$this->time = $this->time->format('Y-m-d H:i:s');
|
||||
}
|
||||
parent::save();
|
||||
}
|
||||
public function isIn()
|
||||
{
|
||||
if ($this->status == 0) {
|
||||
return false;
|
||||
}
|
||||
$now = Carbon::now(config('app.timezone'));
|
||||
$diff = $now->diffAsCarbonInterval($this->time, true);
|
||||
if ($diff->totalHours > config('app.login_hours')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
23
app_old/incoviba/modelos/src/common/Location.php
Normal file
23
app_old/incoviba/modelos/src/common/Location.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Incoviba\common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int $id
|
||||
* @property string $controller length=50
|
||||
* @property string $action length=100
|
||||
*
|
||||
*/
|
||||
class Location extends Model
|
||||
{
|
||||
public static $_table = 'locations';
|
||||
|
||||
public function permissions()
|
||||
{
|
||||
return $this->hasMany(Permission::class, 'location')->findMany();
|
||||
}
|
||||
}
|
||||
?>
|
49
app_old/incoviba/modelos/src/common/Permission.php
Normal file
49
app_old/incoviba/modelos/src/common/Permission.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Incoviba\common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int $id
|
||||
* @property int $type length=1
|
||||
* @property int $ext_id
|
||||
* @property Action $action_id
|
||||
* @property int $status
|
||||
* ---NULL---
|
||||
* @property int $location null foreign=locations.id
|
||||
* @property int $all length=1 default=0
|
||||
* @property int $access length=1 default=0
|
||||
*
|
||||
*/
|
||||
class Permission extends Model
|
||||
{
|
||||
public static $_table = 'permissions';
|
||||
|
||||
/*protected $locations = null;
|
||||
public function location()
|
||||
{
|
||||
if ($this->all == 0) {
|
||||
return $this->belongsTo(Location::class, 'location')->findOne();
|
||||
}
|
||||
if ($this->locations == null) {
|
||||
$this->locations = \Model::factory(Location::class)->findMany();
|
||||
}
|
||||
return $this->locations;
|
||||
}*/
|
||||
public function who()
|
||||
{
|
||||
switch ($this->type) {
|
||||
case 1:
|
||||
return $this->belongsTo(User::class, 'ext_id')->findOne();
|
||||
case 2:
|
||||
return $this->belongsTo(Role::class, 'ext_id')->findOne();
|
||||
}
|
||||
}
|
||||
public function action()
|
||||
{
|
||||
return $this->belongsTo(Action::class, 'action_id')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
64
app_old/incoviba/modelos/src/common/Registry.php
Normal file
64
app_old/incoviba/modelos/src/common/Registry.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace Incoviba\common;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property User $user
|
||||
* @property string $action
|
||||
* @property string $time
|
||||
*/
|
||||
class Registry extends Model
|
||||
{
|
||||
public static $_table = 'registries';
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user')->findOne();
|
||||
}
|
||||
protected $model;
|
||||
public function model()
|
||||
{
|
||||
if ($this->model == null) {
|
||||
list($model, $actions) = explode(']', $this->action);
|
||||
$model = str_replace(['Incoviba\\old\\', 'Incoviba\\nuevo\\', '\\'], ['', '', '->'], trim($model, '['));
|
||||
$this->model = $model;
|
||||
}
|
||||
return $this->model;
|
||||
}
|
||||
protected $actions;
|
||||
public function actions()
|
||||
{
|
||||
if ($this->actions == null) {
|
||||
list($model, $actions) = explode(']', $this->action);
|
||||
$actions = explode(', ', trim($actions));
|
||||
$resultados = [];
|
||||
foreach ($actions as $action) {
|
||||
if (strpos($action, ': ') !== false) {
|
||||
list($columna, $valor) = explode(': ', $action);
|
||||
} else {
|
||||
$columna = '';
|
||||
$valor = $action;
|
||||
}
|
||||
if (strpos($valor, ' -> ') !== false) {
|
||||
list($old, $new) = explode(' -> ', $valor);
|
||||
} else {
|
||||
$old = '';
|
||||
$new = $valor;
|
||||
}
|
||||
$resultados[$columna] = (object) ['old' => $old, 'new' => $new];
|
||||
}
|
||||
$this->actions = $resultados;
|
||||
}
|
||||
return $this->actions;
|
||||
}
|
||||
public function time(Carbon $time = null)
|
||||
{
|
||||
if ($time == null) {
|
||||
return Carbon::parse($this->time);
|
||||
}
|
||||
$this->time = $time->toDateTimeString();
|
||||
}
|
||||
}
|
16
app_old/incoviba/modelos/src/common/RegistryData.php
Normal file
16
app_old/incoviba/modelos/src/common/RegistryData.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property Registry $registry
|
||||
* @property string $column
|
||||
* @property mixed $old
|
||||
* @property mixed $new
|
||||
*/
|
||||
class RegistryData extends Model
|
||||
{
|
||||
public static $_table = 'registry_data';
|
||||
}
|
164
app_old/incoviba/modelos/src/common/Role.php
Normal file
164
app_old/incoviba/modelos/src/common/Role.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
namespace Incoviba\common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
use Incoviba\Common\Factory\Model as Factory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int $id
|
||||
* @property string $description length=50
|
||||
* @property int $level
|
||||
* @property Role $inherits
|
||||
*
|
||||
*/
|
||||
class Role extends Model
|
||||
{
|
||||
public static $_table = 'roles';
|
||||
|
||||
public function inherits()
|
||||
{
|
||||
if ($this->inherits != 0) {
|
||||
return $this->belongsTo(Role::class, 'inherits')->findOne();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected $permissions;
|
||||
public function permissions()
|
||||
{
|
||||
if ($this->permissions == null) {
|
||||
$permissions = $this->hasMany(Permission::class, 'ext_id')->where('permissions.type', 2)->findMany();
|
||||
if ($this->inherits()) {
|
||||
$permissions = array_merge($permissions, $this->inherits()->permissions());
|
||||
}
|
||||
usort($permissions, function($a, $b) {
|
||||
return strcmp($a->action()->description, $b->action()->description);
|
||||
});
|
||||
$this->permissions = $permissions;
|
||||
}
|
||||
return $this->permissions;
|
||||
}
|
||||
public function users()
|
||||
{
|
||||
return $this->hasManyThrough(User::class, UserRole::class, 'role', 'user')->findMany();
|
||||
}
|
||||
public function hasAccess($route)
|
||||
{
|
||||
$action = $route->getArgument('action');
|
||||
$action = (new Factory(Action::class))->where(['description' => $action])->find();
|
||||
if (!$action) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 2,
|
||||
'ext_id' => $this->id,
|
||||
'action_id' => $action->id,
|
||||
'status' => 1
|
||||
];
|
||||
$permission = (new Factory(Permission::class))->where($data)->find();
|
||||
if ($permission !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->inherits()) {
|
||||
return $this->inherits()->hasAccess($route);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function checkAccess($action_name)
|
||||
{
|
||||
$action = (new Factory(Action::class))->where(['description' => $action_name])->find();
|
||||
if (!$action) {
|
||||
throw new \Exception('Action ' . $action_name . ' not found.');
|
||||
}
|
||||
$permission = (new Factory(Permission::class))->where([
|
||||
'type' => 2,
|
||||
'ext_id' => $this->id,
|
||||
'action_id' => $action->id,
|
||||
'status' => 1
|
||||
])->find();
|
||||
if ($permission !== false) {
|
||||
return true;
|
||||
}
|
||||
if ($this->inherits()) {
|
||||
return $this->inherits()->checkAccess($action_name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function addPermission($action_name)
|
||||
{
|
||||
if ($this->checkAccess($action_name)) {
|
||||
return;
|
||||
}
|
||||
$action = (new Factory(Action::class))->where(['description' => $action_name])->find();
|
||||
if (!$action) {
|
||||
throw new \InvalidArgumentException($action_name . ' not found.');
|
||||
}
|
||||
$data = [
|
||||
'type' => 2,
|
||||
'ext_id' => $this->id,
|
||||
'action_id' => $action->id
|
||||
];
|
||||
$permission = (new Factory(Permission::class))->where($data)->find();
|
||||
if (!$permission) {
|
||||
$permission = (new Factory(Permission::class))->create($data);
|
||||
}
|
||||
$permission->status = 1;
|
||||
$permission->save();
|
||||
}
|
||||
public function removePermission($action_name)
|
||||
{
|
||||
if (!$this->checkAccess($action_name)) {
|
||||
return;
|
||||
}
|
||||
$action = (new Factory(Action::class))->where(['description' => $action_name])->find();
|
||||
if (!$action) {
|
||||
throw new \InvalidArgumentException($action_name . ' not found.');
|
||||
}
|
||||
$data = [
|
||||
'type' => 2,
|
||||
'ext_id' => $this->id,
|
||||
'action_id' => $action->id
|
||||
];
|
||||
$permission = (new Factory(Permission::class))->where($data)->find();
|
||||
if (!$permission) {
|
||||
return;
|
||||
}
|
||||
$permission->status = 0;
|
||||
$permission->save();
|
||||
}
|
||||
public function hasUser($user)
|
||||
{
|
||||
$user = \Model::factory(User::class)
|
||||
->select('users.*')
|
||||
->join('user_roles', ['user_roles.user', '=', 'users.id'])
|
||||
->join('roles', ['roles.id', '=', 'user_roles.role'])
|
||||
->where('roles.id', $this->id)
|
||||
->whereAnyIs([['users.name' => $user], ['users.id' => $user]])
|
||||
->findOne();
|
||||
if ($user !== false) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function isInherited($action_name)
|
||||
{
|
||||
if (!$this->checkAccess($action_name)) {
|
||||
return false;
|
||||
}
|
||||
$action = (new Factory(Action::class))->where(['description' => $action_name])->find();
|
||||
$permission = (new Factory(Permission::class))->where([
|
||||
'type' => 2,
|
||||
'ext_id' => $this->id,
|
||||
'action_id' => $action->id,
|
||||
'status' => 1
|
||||
])->find();
|
||||
if ($permission !== false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
104
app_old/incoviba/modelos/src/common/User.php
Normal file
104
app_old/incoviba/modelos/src/common/User.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
namespace Incoviba\common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
use Incoviba\Common\Factory\Model as Factory;
|
||||
|
||||
/**
|
||||
* User with Privileges
|
||||
* @property int $id
|
||||
* @property string $name length=50
|
||||
* @property string $password
|
||||
*/
|
||||
class User extends Model
|
||||
{
|
||||
public static $_table = 'users';
|
||||
|
||||
public function password($password = null)
|
||||
{
|
||||
if ($password == null) {
|
||||
return false;
|
||||
}
|
||||
$this->password = \password_hash($password, \PASSWORD_BCRYPT);
|
||||
}
|
||||
protected $permissions = null;
|
||||
public function permissions()
|
||||
{
|
||||
if ($this->permissions == null) {
|
||||
$permissions = $this->hasMany(Permission::class, 'ext_id')->where('permissions.type', 1)->findMany();
|
||||
if ($permissions == false) {
|
||||
$permissions = [];
|
||||
}
|
||||
foreach ($this->roles() as $role) {
|
||||
$rp = $role->permissions();
|
||||
if ($rp !== false) {
|
||||
$permissions = array_merge($permissions, $rp);
|
||||
}
|
||||
}
|
||||
if (count($permissions) == 0) {
|
||||
$permissions = false;
|
||||
}
|
||||
$this->permissions = $permissions;
|
||||
}
|
||||
return $this->permissions;
|
||||
}
|
||||
public function roles()
|
||||
{
|
||||
return $this->hasManyThrough(Role::class, UserRole::class, 'user', 'role')->findMany();
|
||||
}
|
||||
public function hasAccess($route)
|
||||
{
|
||||
foreach ($this->roles() as $role) {
|
||||
if ($role->hasAccess($route) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$action = $route->getArgument('action');
|
||||
$action = (new Factory(Action::class))->where(['description' => $action])->find();
|
||||
if (!$action) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 1,
|
||||
'ext_id' => $this->id,
|
||||
'action_id' => $action->id,
|
||||
'status' => 1
|
||||
];
|
||||
$permission = (new Factory(Permission::class))->where($data)->find();
|
||||
if ($permission !== false) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function checkAccess($action_name)
|
||||
{
|
||||
foreach ($this->roles() as $role) {
|
||||
if ($role->checkAccess($action_name) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$action = (new Factory(Action::class))->where(['description' => $action_name])->find();
|
||||
|
||||
$permission = (new Factory(Permission::class))->where([
|
||||
'type' => 1,
|
||||
'ext_id' => $this->id,
|
||||
'action_id' => $action->id,
|
||||
'status' => 1
|
||||
])->find();
|
||||
if ($permission !== false) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function hasRole($role)
|
||||
{
|
||||
foreach ($this->roles() as $r) {
|
||||
if ($r->description == $role or $r->id == $role) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
26
app_old/incoviba/modelos/src/common/UserRole.php
Normal file
26
app_old/incoviba/modelos/src/common/UserRole.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int $user foreign=users.id
|
||||
* @property int $role foreign=roles.id
|
||||
*
|
||||
*/
|
||||
class UserRole extends Model
|
||||
{
|
||||
public static $_table = 'user_roles';
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user')->findOne();
|
||||
}
|
||||
public function role()
|
||||
{
|
||||
return $this->belongsTo(Role::class, 'role')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
22
app_old/incoviba/modelos/src/nuevo/Common/Banco.php
Normal file
22
app_old/incoviba/modelos/src/nuevo/Common/Banco.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Common;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
*
|
||||
*/
|
||||
class Banco extends NewModel
|
||||
{
|
||||
protected static $_table = 'bancos';
|
||||
|
||||
//
|
||||
public function cuentas()
|
||||
{
|
||||
return $this->has_many(\Incoviba\nuevo\Inmobiliaria\Cuenta::class, 'banco_id')->findMany();
|
||||
}
|
||||
}
|
27
app_old/incoviba/modelos/src/nuevo/Common/Comuna.php
Normal file
27
app_old/incoviba/modelos/src/nuevo/Common/Comuna.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Common;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
* @property Provincia provincia_id
|
||||
*
|
||||
*/
|
||||
class Comuna extends NewModel
|
||||
{
|
||||
protected static $_table = 'comunas';
|
||||
|
||||
//
|
||||
public function provincia()
|
||||
{
|
||||
return $this->belongs_to(Provincia::class, 'provincia_id')->findOne();
|
||||
}
|
||||
public function direcciones()
|
||||
{
|
||||
return $this->has_many(Direccion::class, 'comuna_id')->findMany();
|
||||
}
|
||||
}
|
24
app_old/incoviba/modelos/src/nuevo/Common/Direccion.php
Normal file
24
app_old/incoviba/modelos/src/nuevo/Common/Direccion.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Common;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string calle
|
||||
* @property string numero
|
||||
* @property string extra
|
||||
* @property Comuna comuna_id
|
||||
*
|
||||
*/
|
||||
class Direccion extends NewModel
|
||||
{
|
||||
protected static $_table = 'direcciones';
|
||||
|
||||
public function comuna()
|
||||
{
|
||||
return $this->belongs_to(Comuna::class, 'comuna_id')->findOne();
|
||||
}
|
||||
}
|
33
app_old/incoviba/modelos/src/nuevo/Common/M2.php
Normal file
33
app_old/incoviba/modelos/src/nuevo/Common/M2.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Common;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property double util
|
||||
* @property double logia
|
||||
* @property double terraza
|
||||
* @property double cubierta
|
||||
* @property double terreno
|
||||
*
|
||||
*/
|
||||
class M2 extends NewModel
|
||||
{
|
||||
protected static $_table = 'm2s';
|
||||
|
||||
public function unidades()
|
||||
{
|
||||
return $this->has_many(\Incoviba\nuevo\Proyecto\UnidadProyecto::class, 'm2_id')->findMany();
|
||||
}
|
||||
public function vendibles()
|
||||
{
|
||||
return $this->util + $this->logia + $this->terraza / 2 + $this->cubierta / 3;
|
||||
}
|
||||
public function total()
|
||||
{
|
||||
return $this->util + $this->logia + $this->terraza + $this->cubierta;
|
||||
}
|
||||
}
|
27
app_old/incoviba/modelos/src/nuevo/Common/Provincia.php
Normal file
27
app_old/incoviba/modelos/src/nuevo/Common/Provincia.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Common;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
* @property Region region_id
|
||||
*
|
||||
*/
|
||||
class Provincia extends NewModel
|
||||
{
|
||||
protected static $_table = 'provincias';
|
||||
|
||||
//
|
||||
public function region()
|
||||
{
|
||||
return $this->belongs_to(Region::class, 'region_id')->findOne();
|
||||
}
|
||||
public function comunas()
|
||||
{
|
||||
return $this->has_many(Comuna::class, 'provincia_id')->findMany();
|
||||
}
|
||||
}
|
24
app_old/incoviba/modelos/src/nuevo/Common/Region.php
Normal file
24
app_old/incoviba/modelos/src/nuevo/Common/Region.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Common;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
* @property string nombre
|
||||
* @property string numeral
|
||||
* @property int orden
|
||||
*
|
||||
*/
|
||||
class Region extends NewModel
|
||||
{
|
||||
protected static $_table = 'regiones';
|
||||
|
||||
public function provincias()
|
||||
{
|
||||
return $this->has_many(Provincia::class, 'region_id')->findMany();
|
||||
}
|
||||
}
|
33
app_old/incoviba/modelos/src/nuevo/Common/UF.php
Normal file
33
app_old/incoviba/modelos/src/nuevo/Common/UF.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Common;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property Date fecha
|
||||
* @property double valor
|
||||
*
|
||||
*/
|
||||
class UF extends NewModel
|
||||
{
|
||||
protected static $_table = 'ufs';
|
||||
|
||||
protected static $_id_column = 'fecha';
|
||||
protected static $_timestamps = false;
|
||||
|
||||
//public $incrementing = false;
|
||||
|
||||
public function getValor()
|
||||
{
|
||||
$fecha = Carbon::parse($this->fecha, config('app.timezone'));
|
||||
$uf = uf($fecha);
|
||||
|
||||
if ($uf != null) {
|
||||
$this->valor = $uf->uf->value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
47
app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Agente.php
Normal file
47
app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Agente.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Common\Direccion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property int rut
|
||||
* @property char dv
|
||||
* @property string razon_social
|
||||
* @property string nombre
|
||||
* @property Representante representante_rut
|
||||
* @property int telefono
|
||||
* @property string correo
|
||||
* @property string giro
|
||||
* @property Direccion direccion_id
|
||||
* @property TipoAgente tipo_agente_id
|
||||
*
|
||||
*/
|
||||
class Agente extends NewModel
|
||||
{
|
||||
protected static $_table = 'agentes';
|
||||
//
|
||||
public function representante()
|
||||
{
|
||||
return $this->belongsTo(Representante::class, 'representante_rut', 'rut')->findOne();
|
||||
}
|
||||
public function direccion()
|
||||
{
|
||||
return $this->belongsTo(Direccion::class, 'direccion_id')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongsTo(TipoAgente::class, 'tipo_agente_id')->findOne();
|
||||
}
|
||||
public function contratos()
|
||||
{
|
||||
return $this->hasMany(Contrato::class, 'agente_id')->findMany();
|
||||
}
|
||||
public function comision($inmobiliaria_rut)
|
||||
{
|
||||
return $this->hasMany(Contrato::class, 'agente_id')->where('inmobiliaria_rut', $inmobiliaria_rut)->sum('valor');
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
*
|
||||
*/
|
||||
class CategoriaCuentaContable extends NewModel
|
||||
{
|
||||
protected static $_table = 'categoria_cuenta_contables';
|
||||
|
||||
public function cuentas()
|
||||
{
|
||||
return $this->hasMany(CuentaContable::class, 'categoria_id')->findMany();
|
||||
}
|
||||
}
|
36
app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Cobro.php
Normal file
36
app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Cobro.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\Common\Definition\hasEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Contrato contrato_id
|
||||
* @property TipoCobro tipo_cobro_id
|
||||
* @property Date fecha
|
||||
* @property string identificador
|
||||
* @property int valor
|
||||
* @property int iva
|
||||
* @property string glosa
|
||||
* @property double uf
|
||||
*
|
||||
*/
|
||||
class Cobro extends NewModel
|
||||
{
|
||||
use hasEstado;
|
||||
|
||||
protected static $_table = 'cobros';
|
||||
|
||||
//
|
||||
public function contrato()
|
||||
{
|
||||
return $this->belongsTo(Contrato::class, 'contrato_id')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongsTo(TipoCobro::class, 'tipo_cobro_id')->findOne();
|
||||
}
|
||||
}
|
37
app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Contrato.php
Normal file
37
app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Contrato.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Inmobiliaria inmobiliaria_rut
|
||||
* @property Agente agente_id
|
||||
* @property TipoContrato tipo_contrato_id
|
||||
* @property int valor
|
||||
*
|
||||
*/
|
||||
class Contrato extends NewModel
|
||||
{
|
||||
protected static $_table = 'contrato';
|
||||
|
||||
//
|
||||
public function inmobiliaria()
|
||||
{
|
||||
return $this->belongsTo(Inmobiliaria::class, 'inmobiliaria_rut', 'rut')->findOne();
|
||||
}
|
||||
public function agente()
|
||||
{
|
||||
return $this->belongsTo(Agente::class, 'agente_id')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongsTo(TipoContrato::class, 'tipo_contrato_id')->findOne();
|
||||
}
|
||||
public function cobros()
|
||||
{
|
||||
return $this->hasMany(Cobro::class, 'contrato_id')->findMany();
|
||||
}
|
||||
}
|
31
app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Cuenta.php
Normal file
31
app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Cuenta.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\nuevo\Common\Banco;
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property int cuenta
|
||||
* @property Banco banco_id
|
||||
* @property Inmobiliaria inmobiliaria_rut
|
||||
* @property string usuario
|
||||
* @property string password
|
||||
*
|
||||
*/
|
||||
class Cuenta extends NewModel
|
||||
{
|
||||
protected static $_table = 'cuentas';
|
||||
|
||||
//
|
||||
public function inmobiliaria()
|
||||
{
|
||||
return $this->belongsTo(Inmobiliaria::class, 'inmobiliaria_rut', 'rut')->findOne();
|
||||
}
|
||||
public function banco()
|
||||
{
|
||||
return $this->belongsTo(Banco::class, 'banco_id')->findOne();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Inmobiliaria inmobiliaria_rut
|
||||
* @property string descripcion
|
||||
* @property CategoriaCuentaContable categoria_id
|
||||
*
|
||||
*/
|
||||
class CuentaContable extends NewModel
|
||||
{
|
||||
protected static $_table = 'cuenta_contables';
|
||||
|
||||
public function inmobiliaria()
|
||||
{
|
||||
return $this->belongsTo(Inmobiliaria::class, 'inmobiliaria_rut', 'rut')->findOne();
|
||||
}
|
||||
public function categoria()
|
||||
{
|
||||
return $this->belongsTo(CategoriaCuentaContable::class, 'categoria_id')->findOne();
|
||||
}
|
||||
public function cargos()
|
||||
{
|
||||
return $this->hasMany(TransaccionContable::class, 'cuenta_de')->findMany();
|
||||
}
|
||||
public function abonos()
|
||||
{
|
||||
return $this->hasMany(TransaccionContable::class, 'cuenta_para')->findMany();
|
||||
}
|
||||
public function transacciones()
|
||||
{
|
||||
$transacciones = model(TransaccionContable::class)->whereAnyIs([['cuenta_de', $this->id], ['cuenta_para', $this->id]])->orderByAsc('fecha')->findMany();
|
||||
return $transacciones;
|
||||
}
|
||||
public function unidades()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property Cobro cobro_id
|
||||
* @property TipoEstadoCobro estado_id
|
||||
*
|
||||
*/
|
||||
class EstadoCobro extends NewEstado
|
||||
{
|
||||
protected static $_table = 'estado_cobros';
|
||||
|
||||
//
|
||||
public function cobro()
|
||||
{
|
||||
return $this->belongsTo(Cobro::class, 'cobro_id')->findOne();
|
||||
}
|
||||
public function estado()
|
||||
{
|
||||
return $this->belongsTo(TipoEstadoCobro::class, 'estado_id')->findOne();
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Common\Direccion;
|
||||
use Incoviba\nuevo\Proyecto\Proyecto;
|
||||
use Incoviba\Common\Definition\hasRUT;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
*
|
||||
* @property int rut
|
||||
* @property char dv
|
||||
* @property string nombre
|
||||
* @property string razon_social
|
||||
* @property Direccion direccion_id
|
||||
* @property Representante representante_rut
|
||||
* @property boolean estado
|
||||
*
|
||||
*/
|
||||
class Inmobiliaria extends NewModel
|
||||
{
|
||||
use hasRUT;
|
||||
|
||||
protected static $_table = 'inmobiliarias';
|
||||
|
||||
public function direccion()
|
||||
{
|
||||
return $this->belongs_to(Direccion::class, 'direccion_id')->findOne();
|
||||
}
|
||||
public function representante()
|
||||
{
|
||||
return $this->belongs_to(Representante::class, 'representante_rut', 'rut')->findOne();
|
||||
}
|
||||
public function estado()
|
||||
{
|
||||
return ($estado != 0);
|
||||
}
|
||||
|
||||
public function proyectos()
|
||||
{
|
||||
return $this->has_many(Proyecto::class, 'inmobiliaria_rut', 'rut')->findMany();
|
||||
}
|
||||
public function inversionistas()
|
||||
{
|
||||
return $this->has_many_through(Socio::class, Participacion::class, 'socio_id', 'inmobiliaria_rut', 'rut')->findMany();
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Inmobiliaria inmobiliaria_rut
|
||||
* @property Socio socio_rut
|
||||
* @property double participacion
|
||||
*
|
||||
*/
|
||||
class Participacion extends NewModel
|
||||
{
|
||||
protected static $_table = 'participaciones';
|
||||
|
||||
public function inmobiliaria()
|
||||
{
|
||||
return $this->belongsTo(Inmobiliaria::class, 'inmobiliaria_rut', 'rut')->findOne();
|
||||
}
|
||||
public function socio()
|
||||
{
|
||||
return $this->belongsTo(Socio::class, 'socio_rut', 'rut')->findOne();
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\nuevo\Common\Direccion;
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\Common\Definition\hasRUT;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int rut
|
||||
* @property char dv
|
||||
* @property string nombres
|
||||
* @property string apellidos
|
||||
* @property int telefono
|
||||
* @property Direccion direccion_id
|
||||
*
|
||||
*/
|
||||
class Representante extends NewModel
|
||||
{
|
||||
use hasRUT;
|
||||
|
||||
protected static $_table = 'representantes';
|
||||
|
||||
public function direccion()
|
||||
{
|
||||
return $this->belongsTo(Direccion::class, 'direccion_id')->findMany();
|
||||
}
|
||||
public function nombreCompleto()
|
||||
{
|
||||
return $this->nombres . ' ' . $this->apellidos;
|
||||
}
|
||||
|
||||
public function inmobiliarias()
|
||||
{
|
||||
return $this->hasMany(Inmobiliaria::class, 'representante_rut', 'rut')->findMany();
|
||||
}
|
||||
public function agentes()
|
||||
{
|
||||
return $this->hasMany(Agente::class, 'representante_rut', 'rut')->findMany();
|
||||
}
|
||||
public function apelativo()
|
||||
{
|
||||
if ($this->sexo == 'f') {
|
||||
return 'doña';
|
||||
}
|
||||
return 'don';
|
||||
}
|
||||
public function articulo()
|
||||
{
|
||||
if ($this->sexo == 'f') {
|
||||
return 'la';
|
||||
}
|
||||
return 'el';
|
||||
}
|
||||
}
|
23
app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Socio.php
Normal file
23
app_old/incoviba/modelos/src/nuevo/Inmobiliaria/Socio.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int rut
|
||||
* @property char dv
|
||||
* @property string nombre
|
||||
*
|
||||
*/
|
||||
class Socio extends NewModel
|
||||
{
|
||||
protected static $_table = 'socios';
|
||||
protected static $_id_column = 'rut';
|
||||
|
||||
public function participaciones()
|
||||
{
|
||||
return $this->hasMany(Participacion::class, 'socio_rut', 'rut')->findMany();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
*
|
||||
*/
|
||||
class TipoAgente extends NewModel
|
||||
{
|
||||
protected static $_table = 'tipo_agentes';
|
||||
|
||||
//
|
||||
public function agentes()
|
||||
{
|
||||
return $this->hasMany(Agente::class, 'tipo_agente_id')->findMany();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
*
|
||||
*/
|
||||
class TipoCobro extends NewModel
|
||||
{
|
||||
protected static $_table = 'tipo_cobros';
|
||||
|
||||
//
|
||||
public function cobros()
|
||||
{
|
||||
return $this->hasMany(Cobro::class, 'tipo_cobro_id')->findMany();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
*
|
||||
*/
|
||||
class TipoContrato extends NewModel
|
||||
{
|
||||
protected static $_table = 'tipo_contratos';
|
||||
|
||||
//
|
||||
public function contratos()
|
||||
{
|
||||
return $this->hasMany(Contrato::class)->findMany();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
*
|
||||
*/
|
||||
class TipoEstadoCobro extends NewModel
|
||||
{
|
||||
protected static $_table = 'tipo_estado_cobros';
|
||||
|
||||
//
|
||||
public function estados()
|
||||
{
|
||||
return $this->hasMany(EstadoCobro::class, 'estado_id')->findMany();
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Inmobiliaria;
|
||||
|
||||
use Incoviba\nuevo\Common\UF;
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Cuenta cuenta_de
|
||||
* @property Cuenta cuenta_para
|
||||
* @property int valor
|
||||
* @property Date fecha
|
||||
* @property string glosa
|
||||
*
|
||||
*/
|
||||
|
||||
class TransaccionContable extends NewModel
|
||||
{
|
||||
protected static $_table = 'transaccion_contables';
|
||||
|
||||
public function de()
|
||||
{
|
||||
return $this->belongsTo(CuentaContable::class, 'cuenta_de');
|
||||
}
|
||||
public function para()
|
||||
{
|
||||
return $this->belongsTo(CuentaContable::class, 'cuenta_para');
|
||||
}
|
||||
|
||||
public function valor($tipo = 'pesos')
|
||||
{
|
||||
if ($tipo == 'ufs') {
|
||||
$uf = model(UF::class)->where('fecha', $this->fecha)->findOne();
|
||||
if (!$uf) {
|
||||
$uf = model(UF::class)->create();
|
||||
$uf->fecha = $this->fecha;
|
||||
$uf->getValor();
|
||||
$uf->save();
|
||||
}
|
||||
return ($this->valor / $uf->valor) ?: 0;
|
||||
}
|
||||
return $this->valor;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\NewEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property Proyecto proyecto_id
|
||||
* @property TipoEstadoProyecto estado_id
|
||||
*
|
||||
*/
|
||||
class EstadoProyecto extends NewEstado
|
||||
{
|
||||
protected static $_table = 'estado_proyectos';
|
||||
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->belongsTo(Proyecto::class, 'proyecto_id')->findOne();
|
||||
}
|
||||
public function estado()
|
||||
{
|
||||
return $this->belongsTo(TipoEstadoProyecto::class, 'estado_id')->findOne();
|
||||
}
|
||||
}
|
22
app_old/incoviba/modelos/src/nuevo/Proyecto/Etapa.php
Normal file
22
app_old/incoviba/modelos/src/nuevo/Proyecto/Etapa.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
* @property int orden
|
||||
*
|
||||
*/
|
||||
class Etapa extends NewModel
|
||||
{
|
||||
protected static $_table = 'etapas';
|
||||
|
||||
public function tipos()
|
||||
{
|
||||
return $this->hasMany(TipoEstadoProyecto::class, 'etapa_id')->findMany();
|
||||
}
|
||||
}
|
27
app_old/incoviba/modelos/src/nuevo/Proyecto/Participe.php
Normal file
27
app_old/incoviba/modelos/src/nuevo/Proyecto/Participe.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Proyecto;
|
||||
|
||||
use Incoviba\Common\Definition\hasRUT;
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property string nombre
|
||||
*
|
||||
*/
|
||||
class Participe extends NewModel
|
||||
{
|
||||
use hasRUT;
|
||||
|
||||
protected static $_table = 'participes';
|
||||
|
||||
public function proyectos()
|
||||
{
|
||||
return $this->hasManyThrough(Proyecto::class, ProyectoParticipe::class, 'proyecto_id', 'participe_rut', 'rut')->findMany();
|
||||
}
|
||||
public function participaciones()
|
||||
{
|
||||
return $this->hasMany(ProyectoParticipe::class, 'participe_rut', 'rut')->findMany();
|
||||
}
|
||||
}
|
132
app_old/incoviba/modelos/src/nuevo/Proyecto/Proyecto.php
Normal file
132
app_old/incoviba/modelos/src/nuevo/Proyecto/Proyecto.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Inmobiliaria\Inmobiliaria;
|
||||
use Incoviba\nuevo\Common\Direccion;
|
||||
use Incoviba\Common\Definition\hasEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string nombre
|
||||
* @property string nombre_completo
|
||||
* @property Inmobiliaria inmobiliaria_rut
|
||||
* @property Direccion direccion_id
|
||||
* @property boolean portal
|
||||
* @property string descripcion
|
||||
*
|
||||
*/
|
||||
class Proyecto extends NewModel
|
||||
{
|
||||
use hasEstado;
|
||||
|
||||
protected static $_table = 'proyectos';
|
||||
|
||||
public function inmobiliaria()
|
||||
{
|
||||
return $this->belongsTo(Inmobiliaria::class, 'inmobiliaria_rut', 'rut')->findOne();
|
||||
}
|
||||
public function direccion()
|
||||
{
|
||||
return $this->belongsTo(Direccion::class, 'direccion_id')->findOne();
|
||||
}
|
||||
|
||||
public function participaciones()
|
||||
{
|
||||
return $this->hasMany(ProyectoParticipe::class, 'proyecto_id')->findMany();
|
||||
}
|
||||
public function participes()
|
||||
{
|
||||
return $this->hasManyThrough(Participe::class, ProyectoParticipe::class, 'proyecto_id', 'participe_rut', 'rut')->findMany();
|
||||
}
|
||||
public function unidades()
|
||||
{
|
||||
return $this->hasMany(UnidadProyecto::class, 'proyecto_id')->findMany();
|
||||
}
|
||||
public function cantidad($tipo = 'departamento')
|
||||
{
|
||||
$total = 0;
|
||||
$unidades = $this->unidades;
|
||||
foreach ($unidades as $unidad) {
|
||||
if ($unidad->tipo->descripcion == $tipo) {
|
||||
$total += $unidad->unidades->count();
|
||||
}
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
public function unidadesPrincipales()
|
||||
{
|
||||
if ($this->tipoUnidades()) {
|
||||
return $this->cantidad('departamento');
|
||||
} else {
|
||||
return $this->cantidad('casa');
|
||||
}
|
||||
}
|
||||
public function pisos()
|
||||
{
|
||||
$max_piso = 0;
|
||||
$unidades = $this->unidades;
|
||||
foreach ($unidades as $unidad) {
|
||||
$piso = $unidad->unidades->max('piso');
|
||||
if ($max_piso < $piso) {
|
||||
$max_piso = $piso;
|
||||
}
|
||||
}
|
||||
return $max_piso;
|
||||
}
|
||||
public function m2Construidos()
|
||||
{
|
||||
$total = 0;
|
||||
$unidades = $this->unidades;
|
||||
foreach ($unidades as $unidad) {
|
||||
$total += $unidad->m2->total() * $unidad->unidades->count();
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
public function tipoUnidades()
|
||||
{
|
||||
return (!$this->unidades->isEmpty() and $this->unidades[0]->tipo->descripcion == 'departamento');
|
||||
}
|
||||
public function ventas()
|
||||
{
|
||||
$ventas = [];
|
||||
foreach ($this->unidades as $up) {
|
||||
foreach ($up->unidades as $u) {
|
||||
if (isset($u->propiedad)) {
|
||||
$ventas->add($u->propiedad->venta);
|
||||
}
|
||||
}
|
||||
}
|
||||
$ventas = sort($ventas, function($a, $b) {
|
||||
return $a->propiedad->unidadPrincipal->numeracion - $b->propiedad->unidadPrincipal->numeracion;
|
||||
});
|
||||
return $ventas;
|
||||
}
|
||||
public function ventasActivas()
|
||||
{
|
||||
$ventas = $this->ventas();
|
||||
$output = [];
|
||||
foreach ($ventas as $venta) {
|
||||
$estado = $venta->ultimoEstado()->estado->descripcion;
|
||||
if ($estado == 'promesado' or $estado == 'escriturado' or $estado == 'entregado') {
|
||||
$output []= $venta;
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
public function pVendido()
|
||||
{
|
||||
return $this->ventasActivas()->count() / $this->unidadesPrincipales();
|
||||
}
|
||||
public function m2Vendidos()
|
||||
{
|
||||
$ventas = $this->ventasActivas();
|
||||
$sum = 0;
|
||||
foreach ($ventas as $venta) {
|
||||
$sum += $venta->propiedad->unidadPrincipal->unidadProyecto->m2->vendibles();
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Proyecto proyecto_id
|
||||
* @property Participe participe_rut
|
||||
* @property double participacion
|
||||
*
|
||||
*/
|
||||
class ProyectoParticipe extends NewModel
|
||||
{
|
||||
protected static $_table = 'proyecto_participes';
|
||||
|
||||
public function proyecto()
|
||||
{
|
||||
$this->belongsTo(Proyecto::class, 'proyecto_id')->findOne();
|
||||
}
|
||||
public function participe()
|
||||
{
|
||||
$this->belongsTo(Participe::class, 'participe_rut', 'rut')->findOne();
|
||||
}
|
||||
}
|
75
app_old/incoviba/modelos/src/nuevo/Proyecto/Tema.php
Normal file
75
app_old/incoviba/modelos/src/nuevo/Proyecto/Tema.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\old\Proyecto\Proyecto as P;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int $id
|
||||
* @property Proyecto $proyecto_id
|
||||
* @property string texto
|
||||
* @property DateTime inicio
|
||||
* @property DateTime cierre
|
||||
*
|
||||
*/
|
||||
class Tema extends NewModel
|
||||
{
|
||||
protected static $_table = 'temas';
|
||||
|
||||
public function proyecto()
|
||||
{
|
||||
$proyecto = $this->belongsTo(Proyecto::class)->findOne();
|
||||
if ($proyecto) {
|
||||
return $proyecto;
|
||||
}
|
||||
return $this->belongsTo(P::class)->findOne();
|
||||
}
|
||||
public function inicio()
|
||||
{
|
||||
return Carbon::parse($this->inicio, config('app.timezone'));
|
||||
}
|
||||
public function cierre()
|
||||
{
|
||||
return Carbon::parse($this->cierre, config('app.timezone'));
|
||||
}
|
||||
public function texto()
|
||||
{
|
||||
$text = $this->texto;
|
||||
$text = explode("\n", $text);
|
||||
foreach ($text as &$line) {
|
||||
$line = trim(rtrim($line, '.')) . '.';
|
||||
if ($line != ltrim($line, '-')) {
|
||||
$line = ' ' . $line;
|
||||
}
|
||||
}
|
||||
$text = implode('<br />', $text);
|
||||
|
||||
preg_match_all('/\[\[.*\]\]/', $text, $matches);
|
||||
$search = [];
|
||||
$replace = [];
|
||||
if (count($matches[0]) > 0) {
|
||||
foreach ($matches[0] as $match) {
|
||||
$search []= $match;
|
||||
list($model, $where, $value) = explode(':', str_replace(['[',']'], ['', ''], $match));
|
||||
$class = '\\Incoviba\\old\\' . $model;
|
||||
$obj = model($class)->where($where, $value)->findOne();
|
||||
|
||||
$str = $value;
|
||||
if ($obj->venta()) {
|
||||
$str = '<a href="';
|
||||
$str .= url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $obj->venta()->id]);
|
||||
$str .= '">' . $value . '</a>';
|
||||
}
|
||||
$replace []= $str;
|
||||
}
|
||||
}
|
||||
|
||||
$text = str_replace($search, $replace, $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
* @property int orden
|
||||
* @property Etapa etapa_id
|
||||
*
|
||||
*/
|
||||
class TipoEstadoProyecto extends NewModel
|
||||
{
|
||||
protected static $_table = 'tipo_estado_proyectos';
|
||||
|
||||
public function etapa()
|
||||
{
|
||||
return $this->belongsTo(Etapa::class, 'etapa_id')->findOne();
|
||||
}
|
||||
|
||||
public function estados()
|
||||
{
|
||||
return $this->hasMany(EstadoProyecto::class, 'estado_id')->findMany();
|
||||
}
|
||||
}
|
21
app_old/incoviba/modelos/src/nuevo/Proyecto/TipoUnidad.php
Normal file
21
app_old/incoviba/modelos/src/nuevo/Proyecto/TipoUnidad.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
*
|
||||
*/
|
||||
class TipoUnidad extends NewModel
|
||||
{
|
||||
protected static $_table = 'tipo_unidades';
|
||||
|
||||
public function unidades()
|
||||
{
|
||||
return $this->hasMany(UnidadProyecto::class, 'tipo_id')->findMany();
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Common\M2;
|
||||
use Incoviba\nuevo\Venta\Unidad;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Proyecto proyecto_id
|
||||
* @property TipoUnidad tipo_id
|
||||
* @property string nombre
|
||||
* @property string tipologia
|
||||
* @property M2 m2_id
|
||||
* @property string descripcion
|
||||
*
|
||||
*/
|
||||
class UnidadProyecto extends NewModel
|
||||
{
|
||||
protected static $_table = 'unidad_proyectos';
|
||||
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->belongsTo(Proyecto::class, 'proyecto_id')->findOne();
|
||||
}
|
||||
public function m2()
|
||||
{
|
||||
return $this->belongsTo(M2::class, 'm2_id')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongsTo(TipoUnidad::class, 'tipo_id')->findOne();
|
||||
}
|
||||
public function unidades()
|
||||
{
|
||||
return $this->hasMany(Unidad::class, 'unidad_proyecto_id')->findMany();
|
||||
}
|
||||
public function orientaciones()
|
||||
{
|
||||
$orientaciones = [];
|
||||
foreach ($this->unidades as $unidad) {
|
||||
if (array_search($unidad->orientacion, $orientaciones) === false) {
|
||||
$orientaciones []= $unidad->orientacion;
|
||||
}
|
||||
}
|
||||
return $orientaciones;
|
||||
}
|
||||
}
|
59
app_old/incoviba/modelos/src/nuevo/Venta/Cierre.php
Normal file
59
app_old/incoviba/modelos/src/nuevo/Venta/Cierre.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Inmobiliaria\Agente;
|
||||
use Carbon\Carbon;
|
||||
use Incoviba\nuevo\Proyecto\Proyecto;
|
||||
use Incoviba\Common\Definition\hasEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int $id
|
||||
* @property Proyecto $proyecto_id
|
||||
* @property Agente $agente_id
|
||||
* @property Propietario $propietario_rut
|
||||
* @property Reserva $reserva_id
|
||||
* @property date $fecha
|
||||
* @property double $valor
|
||||
* @property double $pie
|
||||
* @property double $credito
|
||||
*
|
||||
*/
|
||||
class Cierre extends NewModel
|
||||
{
|
||||
use hasEstado;
|
||||
|
||||
protected static $_table = 'cierres';
|
||||
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->belongsTo(Proyecto::class, 'proyecto_id')->findOne();
|
||||
}
|
||||
public function agente()
|
||||
{
|
||||
return $this->belongsTo(Agente::class, 'agente_id')->findOne();
|
||||
}
|
||||
public function propietario()
|
||||
{
|
||||
return $this->belongsTo(Propietario::class, 'propietario_rut')->findOne();
|
||||
}
|
||||
public function reserva()
|
||||
{
|
||||
return $this->belongsTo(Reserva::class, 'reserva_id')->findOne();
|
||||
}
|
||||
public function fecha()
|
||||
{
|
||||
return Carbon::parse($this->fecha, config('app.timezone'));
|
||||
}
|
||||
public function pie($type = 'ufs')
|
||||
{
|
||||
if ($type == 'ufs') {
|
||||
return $this->pie;
|
||||
}
|
||||
$uf = uf($this->fecha());
|
||||
return $this->pie * $uf->uf->value;
|
||||
}
|
||||
}
|
||||
?>
|
23
app_old/incoviba/modelos/src/nuevo/Venta/Comentario.php
Normal file
23
app_old/incoviba/modelos/src/nuevo/Venta/Comentario.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Venta venta_id
|
||||
* @property string texto
|
||||
* @property boolean estado
|
||||
*
|
||||
*/
|
||||
class Comentario extends NewModel
|
||||
{
|
||||
protected static $_table = 'comentarios';
|
||||
|
||||
public function venta()
|
||||
{
|
||||
return $this->belongsTo(Venta::class, 'venta_id')->findOne();
|
||||
}
|
||||
}
|
27
app_old/incoviba/modelos/src/nuevo/Venta/Cuota.php
Normal file
27
app_old/incoviba/modelos/src/nuevo/Venta/Cuota.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Pie pie_id
|
||||
* @property Pago pago_id
|
||||
* @property int numero
|
||||
*
|
||||
*/
|
||||
class Cuota extends NewModel
|
||||
{
|
||||
protected static $_table = 'cuotas';
|
||||
|
||||
public function pie()
|
||||
{
|
||||
return $this->belongsTo(Pie::class, 'pie_id')->findOne();
|
||||
}
|
||||
public function pago()
|
||||
{
|
||||
return $this->belongsTo(Pago::class, 'pago_id')->findOne();
|
||||
}
|
||||
}
|
47
app_old/incoviba/modelos/src/nuevo/Venta/Entrega.php
Normal file
47
app_old/incoviba/modelos/src/nuevo/Venta/Entrega.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\Common\Definition\hasEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Venta venta_id
|
||||
*
|
||||
*/
|
||||
class Entrega extends NewModel
|
||||
{
|
||||
use hasEstado;
|
||||
|
||||
protected static $_table = 'entregas';
|
||||
|
||||
public function venta()
|
||||
{
|
||||
return $this->belongs_to(Venta::class, 'venta_id')->findOne();
|
||||
}
|
||||
|
||||
public function fondos()
|
||||
{
|
||||
return $this->has_many_through(Pago::class, FondoEntrega::class, 'entrega_id', 'pago_id')->findMany();
|
||||
}
|
||||
public function mediciones()
|
||||
{
|
||||
return $this->has_many_through(Medicion::class, MedicionEntrega::class, 'entrega_id', 'medicion_id')->findMany();
|
||||
}
|
||||
public function observaciones()
|
||||
{
|
||||
return $this->has_many_through(Observacion::class, EntregaObservacion::class, 'entrega_id', 'observacion_id')->findMany();
|
||||
}
|
||||
public function observacionesPendientes()
|
||||
{
|
||||
return $this->has_many_through(Observacion::class, EntregaObservacion::class, 'entrega_id', 'observacion_id')
|
||||
->select('observaciones.*')
|
||||
->rawJoin('JOIN (SELECT e1.* FROM (SELECT MAX(id) AS id, observacion_id FROM estado_observaciones GROUP BY observacion_id) e0 JOIN estado_observaciones e1 ON e1.id = e0.id)', ['ep.observacion_id', '=', 'observaciones.id'], 'ep')
|
||||
->leftOuterJoin('tipo_estado_observaciones', ['tipo_estado_observaciones.id', '=', 'ep.tipo_estado_observacion_id'])
|
||||
->where('tipo_estado_observaciones.descripcion', 'ingresada')
|
||||
->findMany();
|
||||
}
|
||||
}
|
||||
?>
|
26
app_old/incoviba/modelos/src/nuevo/Venta/EstadoCierre.php
Normal file
26
app_old/incoviba/modelos/src/nuevo/Venta/EstadoCierre.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property Cierre $cierre_id
|
||||
* @property TipoEstadoCierre $estado_id
|
||||
*
|
||||
*/
|
||||
class EstadoCierre extends NewEstado
|
||||
{
|
||||
protected static $_table = 'estado_cierres';
|
||||
|
||||
public function cierre()
|
||||
{
|
||||
return $this->belongsTo(Cierre::class)->findOne();
|
||||
}
|
||||
public function estado()
|
||||
{
|
||||
return $this->belongsTo(TipoEstadoCierre::class)->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property Observacion observacion_id
|
||||
* @property TipoEstadoObservacion tipo_estado_observacion_id
|
||||
*
|
||||
*/
|
||||
class EstadoObservacion extends NewEstado
|
||||
{
|
||||
protected static $_table = 'estado_observaciones';
|
||||
|
||||
public function observacion()
|
||||
{
|
||||
return $this->belongs_to(Observacion::class, 'observacion_id')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongs_to(TipoEstadoObservacion::class, 'tipo_estado_observacion_id')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
25
app_old/incoviba/modelos/src/nuevo/Venta/EstadoPago.php
Normal file
25
app_old/incoviba/modelos/src/nuevo/Venta/EstadoPago.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property Pago pago_id
|
||||
* @property TipoEstadoPago estado_id
|
||||
*
|
||||
*/
|
||||
class EstadoPago extends NewEstado
|
||||
{
|
||||
protected static $_table = 'estado_pagos';
|
||||
|
||||
public function pago()
|
||||
{
|
||||
return $this->belongsTo(Pago::class, 'pago_id')->findOne();
|
||||
}
|
||||
public function estado()
|
||||
{
|
||||
return $this->belongsTo(TipoEstadoPago::class, 'estado_id')->findOne();
|
||||
}
|
||||
}
|
27
app_old/incoviba/modelos/src/nuevo/Venta/EstadoPostventa.php
Normal file
27
app_old/incoviba/modelos/src/nuevo/Venta/EstadoPostventa.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Incoviba\Common\Alias\NewEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property Postventa postventa_id
|
||||
* @property TipoEstadoPostventa tipo_estado_postventa_id
|
||||
*
|
||||
*/
|
||||
class EstadoPostventa extends NewEstado
|
||||
{
|
||||
protected static $_table = 'estado_postventas';
|
||||
|
||||
public function postventa()
|
||||
{
|
||||
return $this->belongs_to(Postventa::class, 'postventa_id')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongs_to(TipoEstadoPostventa::class, 'tipo_estado_postventa_id')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
25
app_old/incoviba/modelos/src/nuevo/Venta/EstadoVenta.php
Normal file
25
app_old/incoviba/modelos/src/nuevo/Venta/EstadoVenta.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property Venta venta_id
|
||||
* @property TipoEstadoVenta estado_id
|
||||
*
|
||||
*/
|
||||
class EstadoVenta extends NewEstado
|
||||
{
|
||||
protected static $_table = 'estado_ventas';
|
||||
|
||||
public function venta()
|
||||
{
|
||||
return $this->belongsTo(Venta::class, 'venta_id')->findOne();
|
||||
}
|
||||
public function estado()
|
||||
{
|
||||
return $this->belongsTo(TipoEstadoVenta::class, 'estado_id')->findOne();
|
||||
}
|
||||
}
|
31
app_old/incoviba/modelos/src/nuevo/Venta/FondoVenta.php
Normal file
31
app_old/incoviba/modelos/src/nuevo/Venta/FondoVenta.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Venta venta_id
|
||||
* @property TipoFondo tipo_id
|
||||
* @property Pago pago_id
|
||||
*
|
||||
*/
|
||||
class FondoVenta extends NewModel
|
||||
{
|
||||
protected static $_table = 'fondo_ventas';
|
||||
|
||||
public function venta()
|
||||
{
|
||||
return $this->belongs_to(Venta::class, 'venta_id')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongs_to(TipoFondo::class, 'tipo_id')->findOne();
|
||||
}
|
||||
public function pago()
|
||||
{
|
||||
return $this->belongs_to(Pago::class, 'pago_id')->findOne();
|
||||
}
|
||||
}
|
35
app_old/incoviba/modelos/src/nuevo/Venta/FormaPago.php
Normal file
35
app_old/incoviba/modelos/src/nuevo/Venta/FormaPago.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property Pie pie_id
|
||||
* @property Pago escritura_id
|
||||
* @property Pago credito_id
|
||||
* @property Pago subsidio_id
|
||||
*
|
||||
*/
|
||||
class FormaPago extends NewModel
|
||||
{
|
||||
protected static $_table = 'forma_pago';
|
||||
|
||||
public function pie()
|
||||
{
|
||||
return $this->belongsTo(Pie::class, 'pie_id')->findOne();
|
||||
}
|
||||
public function escritura()
|
||||
{
|
||||
return $this->belongsTo(Pago::class, 'escritura_id')->findOne();
|
||||
}
|
||||
public function credito()
|
||||
{
|
||||
return $this->belongsTo(Pago::class, 'credito_id')->findOne();
|
||||
}
|
||||
public function subsidio()
|
||||
{
|
||||
return $this->belongs_to(Subsidio::class, 'subsidio_id')->findOne();
|
||||
}
|
||||
}
|
24
app_old/incoviba/modelos/src/nuevo/Venta/Medicion.php
Normal file
24
app_old/incoviba/modelos/src/nuevo/Venta/Medicion.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property TipoMedicion tipo_medicion_id
|
||||
* @property double valor
|
||||
* @property Date fecha
|
||||
*
|
||||
*/
|
||||
class Medicion extends NewModel
|
||||
{
|
||||
protected static $_table = 'mediciones';
|
||||
|
||||
public function tipoMedicion()
|
||||
{
|
||||
return $this->belongs_to(TipoMedicion::class, 'tipo_medicion_id')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
20
app_old/incoviba/modelos/src/nuevo/Venta/Observacion.php
Normal file
20
app_old/incoviba/modelos/src/nuevo/Venta/Observacion.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel as Model;
|
||||
use Incoviba\Common\Definition\hasEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string text
|
||||
*
|
||||
*/
|
||||
class Observacion extends Model
|
||||
{
|
||||
use hasEstado;
|
||||
|
||||
protected static $_table = 'observaciones';
|
||||
}
|
||||
?>
|
35
app_old/incoviba/modelos/src/nuevo/Venta/Pago.php
Normal file
35
app_old/incoviba/modelos/src/nuevo/Venta/Pago.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Common\Banco;
|
||||
use Incoviba\Common\Definition\hasEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property TipoPago tipo_id
|
||||
* @property string identificador
|
||||
* @property int valor
|
||||
* @property Banco banco_id
|
||||
* @property Date fecha
|
||||
* @property double uf
|
||||
* @property string pagador
|
||||
*
|
||||
*/
|
||||
class Pago extends NewModel
|
||||
{
|
||||
use hasEstado;
|
||||
|
||||
protected static $_table = 'pagos';
|
||||
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongsTo(TipoPago::class, 'tipo_id')->findOne();
|
||||
}
|
||||
public function banco()
|
||||
{
|
||||
return $this->belongsTo(Banco::class, 'banco_id')->findOne();
|
||||
}
|
||||
}
|
39
app_old/incoviba/modelos/src/nuevo/Venta/Pie.php
Normal file
39
app_old/incoviba/modelos/src/nuevo/Venta/Pie.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property int cuotas
|
||||
* @property double valor
|
||||
* @property Pie asociado_id
|
||||
* @property double uf
|
||||
*
|
||||
*/
|
||||
class Pie extends NewModel
|
||||
{
|
||||
protected static $_table = 'pies';
|
||||
|
||||
public function asociado()
|
||||
{
|
||||
$pie = $this->belongsTo(Pie::class, 'asociado_id');
|
||||
if ($pie) {
|
||||
return $pie->findOne();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function Cuotas()
|
||||
{
|
||||
return $this->hasMany(Cuota::class, 'pie_id')->findMany();
|
||||
}
|
||||
public function CuotasPagadas()
|
||||
{
|
||||
return $this->hasMany(Cuota::class, 'pie_id')->filter(function($cuota) {
|
||||
$estado = $cuota->pago->ultimoEstado()->estado->descripcion;
|
||||
return ($estado == 'depositado' or $estado == 'abonado');
|
||||
});
|
||||
}
|
||||
}
|
38
app_old/incoviba/modelos/src/nuevo/Venta/Postventa.php
Normal file
38
app_old/incoviba/modelos/src/nuevo/Venta/Postventa.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Definition\hasEstado;
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Venta venta_id
|
||||
*
|
||||
*/
|
||||
class Postventa extends NewModel
|
||||
{
|
||||
use hasEstado;
|
||||
|
||||
protected static $_table = 'postventas';
|
||||
|
||||
public function venta()
|
||||
{
|
||||
return $this->belongs_to(Venta::class, 'venta_id')->findOne();
|
||||
}
|
||||
public function observaciones()
|
||||
{
|
||||
return $this->has_many_through(Observacion::class, PostventaObservacion::class, 'postventa_id', 'observacion_id')->findMany();
|
||||
}
|
||||
public function observacionesPendientes()
|
||||
{
|
||||
return $this->has_many_through(Observacion::class, PostventaObservacion::class, 'postventa_id', 'observacion_id')
|
||||
->select('observaciones.*')
|
||||
->rawJoin('JOIN (SELECT e1.* FROM (SELECT MAX(id) AS id, observacion_id FROM estado_observaciones GROUP BY observacion_id) e0 JOIN estado_observaciones e1 ON e1.id = e0.id)', ['ep.observacion_id', '=', 'observaciones.id'], 'ep')
|
||||
->leftOuterJoin('tipo_estado_observaciones', ['tipo_estado_observaciones.id', '=', 'ep.tipo_estado_observacion_id'])
|
||||
->where('tipo_estado_observaciones.descripcion', 'ingresada')
|
||||
->findMany();
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Postventa postventa_id
|
||||
* @property Observacion observacion_id
|
||||
*
|
||||
*/
|
||||
class PostventaObservacion extends NewModel
|
||||
{
|
||||
protected $_table = 'postventa_observaciones';
|
||||
|
||||
public function postventa()
|
||||
{
|
||||
return $this->belongs_to(Postventa::class, 'postventa_id')->findOne();
|
||||
}
|
||||
public function observacion()
|
||||
{
|
||||
return $this->belongs_to(Observacion::class, 'observacion_id')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
27
app_old/incoviba/modelos/src/nuevo/Venta/Premio.php
Normal file
27
app_old/incoviba/modelos/src/nuevo/Venta/Premio.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Venta venta_id
|
||||
* @property TipoPremio tipo_id
|
||||
* @property double valor
|
||||
*
|
||||
*/
|
||||
class Premio extends NewModel
|
||||
{
|
||||
protected static $_table = 'premios';
|
||||
|
||||
public function venta()
|
||||
{
|
||||
return $this->belongsTo(Venta::class, 'venta_id')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongsTo(TipoPremio::class, 'tipo_id')->findOne();
|
||||
}
|
||||
}
|
30
app_old/incoviba/modelos/src/nuevo/Venta/Propiedad.php
Normal file
30
app_old/incoviba/modelos/src/nuevo/Venta/Propiedad.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Unidad unidad_id
|
||||
* @property double valor
|
||||
*
|
||||
*/
|
||||
class Propiedad extends NewModel
|
||||
{
|
||||
protected static $_table = 'propiedades';
|
||||
|
||||
public function unidadPrincipal()
|
||||
{
|
||||
return $this->belongsTo(Unidad::class, 'unidad_id')->findOne();
|
||||
}
|
||||
public function unidades()
|
||||
{
|
||||
return $this->hasMany(UnidadPropiedad::class, 'propiedad_id')->findMany();
|
||||
}
|
||||
public function venta()
|
||||
{
|
||||
return $this->hasMany(Venta::class, 'propiedad_id')->findOne();
|
||||
}
|
||||
}
|
71
app_old/incoviba/modelos/src/nuevo/Venta/Propietario.php
Normal file
71
app_old/incoviba/modelos/src/nuevo/Venta/Propietario.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Common\Direccion;
|
||||
use Incoviba\Common\Definition\hasRUT;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property string nombres
|
||||
* @property string apellido_paterno
|
||||
* @property string apellido_materno
|
||||
* @property int direccion_id
|
||||
* @property int telefono
|
||||
* @property Propietario representante_rut
|
||||
* @property Propietario otro_rut
|
||||
*
|
||||
*/
|
||||
class Propietario extends NewModel
|
||||
{
|
||||
use hasRUT;
|
||||
|
||||
protected static $_table = 'propietarios';
|
||||
|
||||
public function direccion()
|
||||
{
|
||||
return $this->belongsTo(Direccion::class, 'direccion_id')->findOne();
|
||||
}
|
||||
public function representante()
|
||||
{
|
||||
$prop = $this->belongsTo(Propietario::class, 'representante_rut', 'rut');
|
||||
if ($prop) {
|
||||
return $prop->findOne();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function otro()
|
||||
{
|
||||
$prop = $this->belongsTo(Propietario::class, 'otro_rut', 'rut');
|
||||
if ($prop) {
|
||||
return $prop->findOne();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function nombreCompleto()
|
||||
{
|
||||
return implode(' ', [$this->nombres, $this->apellido_paterno, $this->apellido_materno]);
|
||||
}
|
||||
|
||||
public function represntado()
|
||||
{
|
||||
$prop = $this->has_many(Propietario::class, 'representante_rut', 'rut');
|
||||
if ($prop) {
|
||||
return $prop->findOne();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function ventas()
|
||||
{
|
||||
return $this->hasMany(Venta::class, 'propietario_rut', 'rut')->findMany();
|
||||
}
|
||||
public function articulo()
|
||||
{
|
||||
if ($this->sexo == 'f') {
|
||||
return 'la';
|
||||
}
|
||||
return 'el';
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Proyecto\Proyecto;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Proyecto proyecto_id
|
||||
* @property TipoMedicion tipo_medicion_id
|
||||
*
|
||||
*/
|
||||
class ProyectoTipoMedicion extends NewModel
|
||||
{
|
||||
protected static $_table = 'proyecto_tipo_mediciones';
|
||||
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->belongs_to(Proyecto::class, 'proyecto_id')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongs_to(TipoMedicion::class, 'tipo_medicion_id')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
30
app_old/incoviba/modelos/src/nuevo/Venta/Reserva.php
Normal file
30
app_old/incoviba/modelos/src/nuevo/Venta/Reserva.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int $id
|
||||
* @property Unidad $unidad_id
|
||||
*
|
||||
*/
|
||||
class Reserva extends NewModel
|
||||
{
|
||||
protected static $_table = 'reservas';
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Unidad
|
||||
*/
|
||||
public function unidad()
|
||||
{
|
||||
return $this->belongsTo(Unidad::class, 'unidad_id')->findOne();
|
||||
}
|
||||
public function unidades()
|
||||
{
|
||||
return $this->hasMany(UnidadReserva::class, 'reserva_id')->findMany();
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewTipo;
|
||||
|
||||
class TipoEstadoCierre extends NewTipo
|
||||
{
|
||||
protected static $_table = 'tipo_estado_cierres';
|
||||
}
|
||||
?>
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewTipo;
|
||||
|
||||
class TipoEstadoObservacion extends NewTipo
|
||||
{
|
||||
protected static $_table = 'tipo_estado_observaciones';
|
||||
}
|
||||
?>
|
14
app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoPago.php
Normal file
14
app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoPago.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewTipo;
|
||||
|
||||
class TipoEstadoPago extends NewTipo
|
||||
{
|
||||
protected static $_table = 'tipo_estado_pagos';
|
||||
|
||||
public function estados()
|
||||
{
|
||||
return $this->hasMany(EstadoPago::class, 'estado_id')->findMany();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewTipo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
*
|
||||
*/
|
||||
class TipoEstadoPostventa extends NewTipo
|
||||
{
|
||||
protected static $_table = 'tipo_estado_postventas';
|
||||
}
|
||||
?>
|
14
app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoVenta.php
Normal file
14
app_old/incoviba/modelos/src/nuevo/Venta/TipoEstadoVenta.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewTipo;
|
||||
|
||||
class TipoEstadoVenta extends NewTipo
|
||||
{
|
||||
protected static $_table = 'tipo_estado_ventas';
|
||||
|
||||
public function estados()
|
||||
{
|
||||
return $this->hasMany(EstadoVenta::class, 'estado_id')->findMany();
|
||||
}
|
||||
}
|
14
app_old/incoviba/modelos/src/nuevo/Venta/TipoFondo.php
Normal file
14
app_old/incoviba/modelos/src/nuevo/Venta/TipoFondo.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewTipo;
|
||||
|
||||
class TipoFondo extends NewTipo
|
||||
{
|
||||
protected static $_table = 'tipo_fondos';
|
||||
|
||||
public function fondos()
|
||||
{
|
||||
return $this->hasMany(FontoVenta::class, 'tipo_id')->findMany();
|
||||
}
|
||||
}
|
10
app_old/incoviba/modelos/src/nuevo/Venta/TipoMedicion.php
Normal file
10
app_old/incoviba/modelos/src/nuevo/Venta/TipoMedicion.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewTipo;
|
||||
|
||||
class TipoMedicion extends NewTipo
|
||||
{
|
||||
protected static $_table = 'tipo_mediciones';
|
||||
}
|
||||
?>
|
14
app_old/incoviba/modelos/src/nuevo/Venta/TipoPago.php
Normal file
14
app_old/incoviba/modelos/src/nuevo/Venta/TipoPago.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewTipo;
|
||||
|
||||
class TipoPago extends NewTipo
|
||||
{
|
||||
protected static $_table = 'tipo_pagos';
|
||||
|
||||
public function pagos()
|
||||
{
|
||||
return $this->hasMany(Pago::class, 'tipo_id')->findMany();
|
||||
}
|
||||
}
|
14
app_old/incoviba/modelos/src/nuevo/Venta/TipoPremio.php
Normal file
14
app_old/incoviba/modelos/src/nuevo/Venta/TipoPremio.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewTipo;
|
||||
|
||||
class TipoPremio extends NewTipo
|
||||
{
|
||||
protected static $_table = 'tipo_premios';
|
||||
|
||||
public function premios()
|
||||
{
|
||||
return $this->hasMany(Premio::class, 'tipo_id')->findMany();
|
||||
}
|
||||
}
|
47
app_old/incoviba/modelos/src/nuevo/Venta/Unidad.php
Normal file
47
app_old/incoviba/modelos/src/nuevo/Venta/Unidad.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\nuevo\Proyecto\UnidadProyecto;
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Inmobiliaria\CuentaContable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property UnidadProyecto unidad_proyecto_id
|
||||
* @property int piso
|
||||
* @property string linea
|
||||
* @property string numeracion
|
||||
* @property string orientacion
|
||||
*
|
||||
*/
|
||||
class Unidad extends NewModel
|
||||
{
|
||||
protected static $_table = 'unidades';
|
||||
|
||||
public function unidadProyecto()
|
||||
{
|
||||
return $this->belongsTo(UnidadProyecto::class, 'unidad_proyecto_id')->findOne();
|
||||
}
|
||||
public function uPropiedad()
|
||||
{
|
||||
$up = $this->hasMany(UnidadPropiedad::class, 'unidad_id');
|
||||
if ($up) {
|
||||
return $up->findOne();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function propiedad()
|
||||
{
|
||||
$prop = $this->hasMany(Propiedad::class, 'unidad_id');
|
||||
if ($prop) {
|
||||
return $prop->findOne();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function cuentas()
|
||||
{
|
||||
return $this->belongsTo(CuentaContable::class, 'cuenta_unidades', 'unidad_id', 'cuenta_id')->findMany();
|
||||
}
|
||||
}
|
27
app_old/incoviba/modelos/src/nuevo/Venta/UnidadPropiedad.php
Normal file
27
app_old/incoviba/modelos/src/nuevo/Venta/UnidadPropiedad.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Propiedad propiedad_id
|
||||
* @property Unidad unidad_id
|
||||
* @property double valor
|
||||
*
|
||||
*/
|
||||
class UnidadPropiedad extends NewModel
|
||||
{
|
||||
protected static $_table = 'unidad_propiedades';
|
||||
|
||||
public function propiedad()
|
||||
{
|
||||
return $this->belongsTo(Propiedad::class, 'propiedad_id')->findOne();
|
||||
}
|
||||
public function unidad()
|
||||
{
|
||||
return $this->belongsTo(Unidad::class, 'unidad_id')->findOne();
|
||||
}
|
||||
}
|
27
app_old/incoviba/modelos/src/nuevo/Venta/UnidadReserva.php
Normal file
27
app_old/incoviba/modelos/src/nuevo/Venta/UnidadReserva.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int $id
|
||||
* @property Reserva reserva_id
|
||||
* @property Unidad unidad_id
|
||||
*
|
||||
*/
|
||||
class UnidadReserva extends NewModel
|
||||
{
|
||||
protected static $_table = 'unidad_reservas';
|
||||
|
||||
public function reserva()
|
||||
{
|
||||
return $this->belongsTo(Reserva::class, 'reserva_id')->findOne();
|
||||
}
|
||||
public function unidad()
|
||||
{
|
||||
return $this->belongsTo(Unidad::class, 'unidad_id')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
104
app_old/incoviba/modelos/src/nuevo/Venta/Venta.php
Normal file
104
app_old/incoviba/modelos/src/nuevo/Venta/Venta.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
namespace Incoviba\nuevo\Venta;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Incoviba\Common\Alias\NewModel;
|
||||
use Incoviba\nuevo\Inmobiliaria\Agente;
|
||||
use Incoviba\Common\Definition\hasEstado;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int id
|
||||
* @property Propietario propietario_rut
|
||||
* @property Propiedad propiedad_id
|
||||
* @property FormaPago forma_pago_id
|
||||
* @property Date fecha_promesa
|
||||
* @property double valor_promesa
|
||||
* @property double uf
|
||||
* @property boolean relacionado
|
||||
* @property Agente agente_id
|
||||
* @property DateTime created_at
|
||||
* @property DateTime updated_at
|
||||
*
|
||||
*/
|
||||
class Venta extends NewModel
|
||||
{
|
||||
use hasEstado;
|
||||
|
||||
protected static $_table = 'ventas';
|
||||
|
||||
public function propietario()
|
||||
{
|
||||
return $this->belongs_to(Propietario::class, 'propietario_rut', 'rut')->findOne();
|
||||
}
|
||||
public function propiedad()
|
||||
{
|
||||
return $this->belongs_to(Propiedad::class, 'propiedad_id')->findOne();
|
||||
}
|
||||
public function formaPago()
|
||||
{
|
||||
return $this->belongs_to(FormaPago::class, 'forma_pago_id')->findOne();
|
||||
}
|
||||
public function agente()
|
||||
{
|
||||
$agente = $this->belongs_to(Agente::class, 'agente_id');
|
||||
if ($agente) {
|
||||
return $agente->findOne();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function valor()
|
||||
{
|
||||
return $this->valor_promesa * $this->uf;
|
||||
}
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->propiedad->unidadPrincipal->unidadProyecto->proyecto();
|
||||
}
|
||||
public function comision()
|
||||
{
|
||||
return $this->agente->comision($this->proyecto->inmobiliaria->rut);
|
||||
}
|
||||
public function ufM2()
|
||||
{
|
||||
if (!$this->agente) {
|
||||
return 0;
|
||||
}
|
||||
return ($this->valor_promesa - $this->premios->sum('valor') - $this->comision() - $this->propiedad->unidades->sum('valor')) / $this->propiedad->unidadPrincipal->unidadProyecto->m2->vendibles();
|
||||
}
|
||||
public function fechaPromesa()
|
||||
{
|
||||
return Carbon::parse($this->fecha_promesa, config('app.timezone'));
|
||||
}
|
||||
|
||||
public function premios()
|
||||
{
|
||||
$premios = $this->has_many(Premio::class, 'venta_id');
|
||||
if ($premios) {
|
||||
return $premios->findMany();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
public function comentarios()
|
||||
{
|
||||
$comentarios = $this->has_many(Comentario::class, 'venta_id');
|
||||
if ($comentarios) {
|
||||
return $comentarios->findMany();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
public function fondos()
|
||||
{
|
||||
return $this->has_many(FondoVenta::class, 'venta_id')->findMany();
|
||||
}
|
||||
public function postventas()
|
||||
{
|
||||
$postventas = $this->has_many(Postventa::class, 'venta_id');
|
||||
if ($postventas) {
|
||||
return $postventas->findMany();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
29
app_old/incoviba/modelos/src/old/Common/Banco.php
Normal file
29
app_old/incoviba/modelos/src/old/Common/Banco.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
*
|
||||
* @property int id
|
||||
* @property string nombre
|
||||
*
|
||||
*/
|
||||
class Banco extends Model
|
||||
{
|
||||
public function nombreCompleto()
|
||||
{
|
||||
$str = '';
|
||||
switch ($this->nombre) {
|
||||
case 'Estado':
|
||||
case 'Chile':
|
||||
case 'Edwards':
|
||||
$str .= 'Banco ';
|
||||
}
|
||||
$str .= $this->nombre;
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
?>
|
22
app_old/incoviba/modelos/src/old/Common/Comuna.php
Normal file
22
app_old/incoviba/modelos/src/old/Common/Comuna.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
*
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
* @property Provincia provincia
|
||||
*
|
||||
*/
|
||||
class Comuna extends Model
|
||||
{
|
||||
public function provincia()
|
||||
{
|
||||
return $this->belongs_to(Provincia::class, 'provincia')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
36
app_old/incoviba/modelos/src/old/Common/Direccion.php
Normal file
36
app_old/incoviba/modelos/src/old/Common/Direccion.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
*
|
||||
* @property int id
|
||||
* @property string calle
|
||||
* @property int numero
|
||||
* @property string extra
|
||||
* @property Comuna comuna
|
||||
*
|
||||
*/
|
||||
class Direccion extends Model
|
||||
{
|
||||
public function comuna()
|
||||
{
|
||||
return $this->belongs_to(Comuna::class, 'comuna')->findOne();
|
||||
}
|
||||
|
||||
public function completa($comuna = false)
|
||||
{
|
||||
$str = $this->calle . ' ' . $this->numero;
|
||||
if ($this->extra != '') {
|
||||
$str .= ', ' . $this->extra;
|
||||
}
|
||||
if ($comuna) {
|
||||
$str .= ', ' . $this->comuna()->descripcion;
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
?>
|
26
app_old/incoviba/modelos/src/old/Common/Provincia.php
Normal file
26
app_old/incoviba/modelos/src/old/Common/Provincia.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
*
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
* @property Region region
|
||||
*
|
||||
*/
|
||||
class Provincia extends Model
|
||||
{
|
||||
public function region()
|
||||
{
|
||||
return $this->belongsTo(Region::class, 'region')->findOne();
|
||||
}
|
||||
public function comunas()
|
||||
{
|
||||
return $this->hasMany(Comuna::class, 'provincia')->findMany();
|
||||
}
|
||||
}
|
||||
?>
|
44
app_old/incoviba/modelos/src/old/Common/Region.php
Normal file
44
app_old/incoviba/modelos/src/old/Common/Region.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Common;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
*
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
* @property char numeral
|
||||
* @property int numeracion
|
||||
*
|
||||
*/
|
||||
class Region extends Model
|
||||
{
|
||||
private $provincias = null;
|
||||
private $comunas = null;
|
||||
|
||||
public function provincias()
|
||||
{
|
||||
if ($this->provincias == null) {
|
||||
$this->provincias = $this->hasMany(Provincia::class, 'region')->findMany();
|
||||
}
|
||||
return $this->provincias;
|
||||
}
|
||||
public function comunas()
|
||||
{
|
||||
if ($this->comunas == null) {
|
||||
$provincias = $this->provincias();
|
||||
$comunas = [];
|
||||
foreach ($provincias as $prov) {
|
||||
$comunas = array_merge($comunas, $prov->comunas());
|
||||
}
|
||||
usort($comunas, function($a, $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$this->comunas = $comunas;
|
||||
}
|
||||
return $this->comunas;
|
||||
}
|
||||
}
|
||||
?>
|
23
app_old/incoviba/modelos/src/old/Inmobiliaria/Cuenta.php
Normal file
23
app_old/incoviba/modelos/src/old/Inmobiliaria/Cuenta.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
use Incoviba\old\Common\Banco;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property Inmobiliaria $inmobiliaria
|
||||
* @property Banco $banco
|
||||
* @property string $cuenta
|
||||
*/
|
||||
class Cuenta extends Model
|
||||
{
|
||||
public function inmobiliaria()
|
||||
{
|
||||
return $this->belongsTo(Inmobiliaria::class, 'inmobiliaria', 'rut')->findOne();
|
||||
}
|
||||
public function banco()
|
||||
{
|
||||
return $this->belongsTo(Banco::class, 'banco')->findOne();
|
||||
}
|
||||
}
|
135
app_old/incoviba/modelos/src/old/Inmobiliaria/Inmobiliaria.php
Normal file
135
app_old/incoviba/modelos/src/old/Inmobiliaria/Inmobiliaria.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
use Incoviba\old\Common\Banco;
|
||||
use Incoviba\old\Proyecto\Proyecto;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
*
|
||||
* @property int $rut
|
||||
* @property char $dv
|
||||
* @property string $razon
|
||||
* @property string $abreviacion
|
||||
* @property string $cuenta
|
||||
* @property Banco $banco
|
||||
* @property TipoSociedad $sociedad
|
||||
*
|
||||
*/
|
||||
class Inmobiliaria extends Model
|
||||
{
|
||||
public static $_id_column = 'rut';
|
||||
|
||||
public function banco()
|
||||
{
|
||||
return $this->cuenta()->banco();
|
||||
//return $this->belongsTo(Banco::class, 'banco')->findOne();
|
||||
}
|
||||
public function proyectos()
|
||||
{
|
||||
return $this->hasMany(Proyecto::class, 'inmobiliaria', 'rut')->orderByAsc('descripcion')->findMany();
|
||||
}
|
||||
public function nombre(bool $tipo = false)
|
||||
{
|
||||
return $this->abreviacion . (($tipo) ? ' ' . $this->sociedad()->abreviacion . '.' : '');
|
||||
}
|
||||
public function rut()
|
||||
{
|
||||
return format('rut', $this->rut) . '-' . $this->dv;
|
||||
}
|
||||
public function sociedad() {
|
||||
return $this->belongsTo(TipoSociedad::class, 'sociedad')->findOne();
|
||||
}
|
||||
public function razon(bool $tipo = false, bool $abreviado = false) {
|
||||
return $this->razon . (($tipo) ? ' ' . (($abreviado) ? $this->sociedad()->abreviacion . '.' : $this->sociedad()->descripcion) : '');
|
||||
}
|
||||
/**
|
||||
* $data = ['descripcion', 'calle', 'numero', 'extra', 'comuna']
|
||||
*/
|
||||
public function addProyecto(array $data)
|
||||
{
|
||||
//$proyecto = model(Proyecto::class)->where('inmobiliaria', $this->rut)->where('descripcion', $data['descripcion'])->findOne();
|
||||
$data = [
|
||||
'inmobiliaria' => $this->rut,
|
||||
'descripcion' => $data['descripcion']
|
||||
];
|
||||
$proyecto = (new Factory(Proyecto::class))->where($data)->find();
|
||||
if (!$proyecto) {
|
||||
//$proyecto = model(Proyecto::class)->create();
|
||||
$proyecto = (new Factory(Proyecto::class))->create($data);
|
||||
/*$proyecto->inmobiliaria = $this->rut;
|
||||
$proyecto->descripcion = $data['descripcion'];*/
|
||||
$proyecto->setDireccion($data);
|
||||
$proyecto->save();
|
||||
}
|
||||
}
|
||||
public function removeProyecto(array $data)
|
||||
{
|
||||
$proyecto = (new Factory(Proyecto::class))->where([
|
||||
'inmobiliaria' => $this->rut,
|
||||
'descripcion' => $data['descripcion']
|
||||
])->find();
|
||||
if ($proyecto) {
|
||||
$proyecto->delete();
|
||||
}
|
||||
}
|
||||
public function cuenta()
|
||||
{
|
||||
if (count($this->cuentas()) == 0) {
|
||||
return false;
|
||||
}
|
||||
return $this->cuentas()[0];
|
||||
}
|
||||
public function cuentas()
|
||||
{
|
||||
return $this->hasMany(Cuenta::class, 'inmobiliaria', 'rut')->findMany();
|
||||
}
|
||||
public function addCuenta(array $data)
|
||||
{
|
||||
if (!is_numeric($data['banco'])) {
|
||||
$banco = (new Factory(Banco::class))->where(['descripcion' => $data['banco']])->find();
|
||||
$data['banco'] = $banco->id;
|
||||
}
|
||||
$data = [
|
||||
'inmobiliaria' => $this->rut,
|
||||
'cuenta' => $data['cuenta'],
|
||||
'banco' => $data['banco']
|
||||
];
|
||||
$cuenta = (new Factory(Cuenta::class))->where($data)->find();
|
||||
if (!$cuenta) {
|
||||
$cuenta = (new Factory(Cuenta::class))->create($data);
|
||||
$cuenta->save();
|
||||
}
|
||||
}
|
||||
public function removeCuenta(array $data)
|
||||
{
|
||||
$cuenta = (new Factory(Cuenta::class))->where(['inmobiliaria' => $this->rut]);
|
||||
if (isset($data['cuenta'])) {
|
||||
$cuenta = $cuenta->where(['cuenta' => $data['cuenta']]);
|
||||
}
|
||||
if (isset($data['banco'])) {
|
||||
if (!is_numeric($data['banco'])) {
|
||||
$banco = (new Factory(Banco::class))->where(['descripcion' => $data['banco']])->find();
|
||||
$data['banco'] = $banco->id;
|
||||
}
|
||||
$cuenta = $cuenta->where(['banco' => $data['banco']]);
|
||||
}
|
||||
$cuenta = $cuenta->find();
|
||||
if ($cuenta) {
|
||||
$cuenta->delete();
|
||||
}
|
||||
}
|
||||
public function modify(array $data)
|
||||
{
|
||||
$fields = ['rut', 'dv', 'razon', 'abreviacion'];
|
||||
foreach ($data as $column => $value) {
|
||||
if (array_search($column, $fields) !== false) {
|
||||
$this->$column = $value;
|
||||
}
|
||||
}
|
||||
$this->cuenta()->modify($data);
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property int id
|
||||
* @property int padre
|
||||
* @property int hijo
|
||||
*
|
||||
*/
|
||||
class RelacionInmobiliarias extends Model
|
||||
{
|
||||
public function padre()
|
||||
{
|
||||
return $this->belongsTo(Inmobiliaria::class, 'padre', 'rut')->findOne();
|
||||
}
|
||||
public function hijo()
|
||||
{
|
||||
return $this->belongsTo(Inmobiliaria::class, 'hijo', 'rut')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Inmobiliaria;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $descripcion
|
||||
* @property string $abreviacion
|
||||
*/
|
||||
class TipoSociedad extends Model {
|
||||
}
|
41
app_old/incoviba/modelos/src/old/Proyecto/Agente.php
Normal file
41
app_old/incoviba/modelos/src/old/Proyecto/Agente.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
use Incoviba\old\Common\Direccion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
*
|
||||
* @property int id
|
||||
* @property TipoAgente tipo
|
||||
* @property int rut
|
||||
* @property string descripcion
|
||||
* @property string representante
|
||||
* @property int telefono
|
||||
* @property string correo
|
||||
* @property Direccion direccion
|
||||
* @property string giro
|
||||
* @property string abreviacion
|
||||
*
|
||||
*/
|
||||
class Agente extends Model
|
||||
{
|
||||
public function direccion()
|
||||
{
|
||||
return $this->belongs_to(Direccion::class, 'direccion')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongs_to(TipoAgente::class, 'tipo')->findOne();
|
||||
}
|
||||
public function tipos(int $tipo = 0)
|
||||
{
|
||||
if ($tipo == 0) {
|
||||
return $this->hasMany(AgenteTipo::class, 'agente')->findMany();
|
||||
}
|
||||
return $this->hasMany(AgenteTipo::class, 'agente')->where('tipo', $tipo)->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
20
app_old/incoviba/modelos/src/old/Proyecto/AgenteTipo.php
Normal file
20
app_old/incoviba/modelos/src/old/Proyecto/AgenteTipo.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
* @property Agente $agente
|
||||
* @property TipoAgente $tipo
|
||||
*/
|
||||
class AgenteTipo extends Model
|
||||
{
|
||||
public function agente()
|
||||
{
|
||||
return $this->belongsTo(Agente::class, 'agente')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongsTo(TipoAgente::class, 'tipo')->findOne();
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $proyecto
|
||||
* @property \DateTime $fecha
|
||||
* @property double $avance
|
||||
* @property double $estado_pago
|
||||
* @property int $pagado
|
||||
* @property double $uf
|
||||
* @property \DateTime $fecha_pagado
|
||||
*/
|
||||
class AvanceConstruccion extends Model
|
||||
{
|
||||
public static $_table = 'avance_construccion';
|
||||
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->belongsTo(Proyecto::class, 'proyecto')->findOne();
|
||||
}
|
||||
public function fecha(\DateTime $fecha = null)
|
||||
{
|
||||
if ($fecha == null) {
|
||||
return Carbon::parse($this->fecha, config('app.timezone'));
|
||||
}
|
||||
$this->fecha = $fecha->format('Y-m-d');
|
||||
}
|
||||
protected $pagare;
|
||||
public function pagare()
|
||||
{
|
||||
if ($this->pagare == null) {
|
||||
$this->pagare = $this->hasMany(Pagare::class, 'estado_pago', 'numero')
|
||||
->where('proyecto', $this->proyecto)
|
||||
->findOne();
|
||||
}
|
||||
return $this->pagare;
|
||||
}
|
||||
protected $pagares;
|
||||
public function pagares()
|
||||
{
|
||||
if ($this->pagares == null) {
|
||||
$this->pagares = $this->hasMany(Pagare::class, 'estado_pago', 'numero')
|
||||
->where('proyecto', $this->proyecto)
|
||||
->findMany();
|
||||
}
|
||||
return $this->pagares;
|
||||
}
|
||||
public function uf()
|
||||
{
|
||||
if ($this->uf == 0) {
|
||||
$uf = uf($this->fecha());
|
||||
if ($uf->total > 0) {
|
||||
$this->uf = $uf->uf->value;
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
return $this->uf;
|
||||
}
|
||||
public function pagado($tipo = 'ufs')
|
||||
{
|
||||
if ($tipo == 'ufs') {
|
||||
return $this->pagado / $this->uf();
|
||||
}
|
||||
return $this->pagado;
|
||||
}
|
||||
public function fechaPago(\DateTime $fecha = null)
|
||||
{
|
||||
if ($fecha == null) {
|
||||
return Carbon::parse($this->fecha_pagado, config('app.timezone'));
|
||||
}
|
||||
$this->fecha_pagado = $fecha->format('Y-m-d');
|
||||
}
|
||||
public function edit(array $data)
|
||||
{
|
||||
foreach ($data as $column => $value) {
|
||||
if (isset($this->$column) and $this->$column != $value) {
|
||||
$this->$column = $value;
|
||||
}
|
||||
}
|
||||
$this->save();
|
||||
}
|
||||
}
|
35
app_old/incoviba/modelos/src/old/Proyecto/Cobro.php
Normal file
35
app_old/incoviba/modelos/src/old/Proyecto/Cobro.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property int id
|
||||
* @property Proyecto proyecto
|
||||
* @property Agente agente
|
||||
* @property TipoCobro tipo
|
||||
* @property date fecha
|
||||
* @property float valor
|
||||
* @property float iva
|
||||
* @property float uf
|
||||
* @property string identificador
|
||||
* @property string glosa
|
||||
*
|
||||
*/
|
||||
class Cobro extends Model
|
||||
{
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->has_one(Proyecto::class);
|
||||
}
|
||||
public function agente()
|
||||
{
|
||||
return $this->has_one(Agente::class);
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->has_one(TipoCobro::class);
|
||||
}
|
||||
}
|
||||
?>
|
21
app_old/incoviba/modelos/src/old/Proyecto/Costo.php
Normal file
21
app_old/incoviba/modelos/src/old/Proyecto/Costo.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property int id
|
||||
* @property Proyecto proyecto
|
||||
* @property int tipo
|
||||
* @property float valor
|
||||
*
|
||||
*/
|
||||
class Costo extends Model
|
||||
{
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->has_one(Proyecto::class, 'proyecto')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
25
app_old/incoviba/modelos/src/old/Proyecto/EstadoCobro.php
Normal file
25
app_old/incoviba/modelos/src/old/Proyecto/EstadoCobro.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property int id
|
||||
* @property Cobro cobro
|
||||
* @property date fecha
|
||||
* @property TipoEstadoCobro estado
|
||||
*
|
||||
*/
|
||||
class EstadoCobro extends Model
|
||||
{
|
||||
public function cobro()
|
||||
{
|
||||
return $this->has_one(Cobro::class, 'cobro')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->has_one(TipoEstadoCobro::class, 'estado')->findOne();
|
||||
}
|
||||
}
|
||||
?>
|
30
app_old/incoviba/modelos/src/old/Proyecto/EstadoProyecto.php
Normal file
30
app_old/incoviba/modelos/src/old/Proyecto/EstadoProyecto.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property int id
|
||||
* @property Proyecto proyecto
|
||||
* @property TipoEstadoProyecto estado
|
||||
* @property date fecha
|
||||
*
|
||||
*/
|
||||
class EstadoProyecto extends Model
|
||||
{
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->belongs_to(Proyecto::class, 'proyecto')->findOne();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongs_to(TipoEstadoProyecto::class, 'estado')->findOne();
|
||||
}
|
||||
public function fecha()
|
||||
{
|
||||
return Carbon::parse($this->fecha, config('app.timezone'));
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property ProyectoAgente $agente
|
||||
* @property \DateTime $fecha
|
||||
* @property TipoEstadoProyectoAgente $tipo
|
||||
*/
|
||||
class EstadoProyectoAgente extends Model
|
||||
{
|
||||
public function agente()
|
||||
{
|
||||
return $this->belongsTo(ProyectoAgente::class, 'agente')->findOne();
|
||||
}
|
||||
public function fecha(\DateTime $fecha = null) {
|
||||
if ($fecha == null) {
|
||||
return Carbon::parse($this->fecha, config('app.timezone'));
|
||||
}
|
||||
$this->fecha = $fecha->format('Y-m-d');
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongsTo(TipoEstadoProyectoAgente::class, 'tipo')->findOne();
|
||||
}
|
||||
}
|
18
app_old/incoviba/modelos/src/old/Proyecto/EtapaProyecto.php
Normal file
18
app_old/incoviba/modelos/src/old/Proyecto/EtapaProyecto.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
*
|
||||
* @property int id
|
||||
* @property string descripcion
|
||||
* @property int orden
|
||||
*
|
||||
*/
|
||||
class EtapaProyecto extends Model
|
||||
{
|
||||
}
|
||||
?>
|
142
app_old/incoviba/modelos/src/old/Proyecto/Pagare.php
Normal file
142
app_old/incoviba/modelos/src/old/Proyecto/Pagare.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property Proyecto $proyecto
|
||||
* @property TipoMonedaPagare $moneda
|
||||
* @property double $capital
|
||||
* @property double $tasa
|
||||
* @property \DateTime $fecha
|
||||
* @property int $duracion
|
||||
* @property double $uf
|
||||
* @property int $abonado
|
||||
* @property int $estado_pago
|
||||
*/
|
||||
class Pagare extends Model
|
||||
{
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->belongsTo(Proyecto::class, 'proyecto')->findOne();
|
||||
}
|
||||
public function moneda()
|
||||
{
|
||||
return $this->belongsTo(TipoMonedaPagare::class, 'moneda')->findOne();
|
||||
}
|
||||
public function renovaciones()
|
||||
{
|
||||
return $this->hasMany(RenovacionPagare::class, 'pagare')->findMany();
|
||||
}
|
||||
public function fecha(\DateTime $fecha = null)
|
||||
{
|
||||
if ($fecha == null) {
|
||||
return Carbon::parse($this->fecha, config('app.timezone'));
|
||||
}
|
||||
$this->fecha = $fecha->format('Y-m-d');
|
||||
}
|
||||
public function fechaBanco(\DateTime $fecha = null)
|
||||
{
|
||||
if ($fecha == null) {
|
||||
return Carbon::parse($this->fecha_banco, config('app.timezone'));
|
||||
}
|
||||
$this->fecha_banco = $fecha->format('Y-m-d');
|
||||
}
|
||||
public function vencimiento()
|
||||
{
|
||||
return $this->fechaBanco()->addDays($this->duracion);
|
||||
}
|
||||
public function uf()
|
||||
{
|
||||
if ($this->uf == 0 and $this->fecha != '0000-00-00') {
|
||||
$uf = uf($this->fecha());
|
||||
if ($uf->total > 0) {
|
||||
$this->uf = $uf->uf->value;
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
return $this->uf;
|
||||
}
|
||||
protected $valores;
|
||||
public function valor($tipo = 'ufs')
|
||||
{
|
||||
if ($this->valores == null) {
|
||||
$valores = [];
|
||||
switch (strtolower($this->moneda()->descripcion)) {
|
||||
case 'uf':
|
||||
$valores = (object) ['uf' => $this->capital, 'pesos' => $this->capital * $this->uf()];
|
||||
break;
|
||||
case 'pesos':
|
||||
$valores = (object) ['uf' => $this->capital / $this->uf(), 'pesos' => $this->capital];
|
||||
break;
|
||||
}
|
||||
$this->valores = $valores;
|
||||
}
|
||||
switch (strtolower($tipo)) {
|
||||
case 'uf':
|
||||
case 'ufs':
|
||||
return $this->valores->uf;
|
||||
case 'peso':
|
||||
case 'pesos':
|
||||
case '$':
|
||||
return $this->valores->pesos;
|
||||
}
|
||||
}
|
||||
public function abonado($tipo = 'ufs')
|
||||
{
|
||||
if ($tipo == 'ufs') {
|
||||
if ($this->uf() > 0) {
|
||||
return $this->abonado / $this->uf();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return $this->abonado;
|
||||
}
|
||||
public function edit(array $data)
|
||||
{
|
||||
foreach ($data as $column => $value) {
|
||||
if (isset($this->$column) and $this->$column != $value) {
|
||||
$this->$column = $value;
|
||||
}
|
||||
}
|
||||
$this->save();
|
||||
}
|
||||
protected $intereses;
|
||||
public function intereses($tipo = 'ufs') {
|
||||
if ($this->intereses == null) {
|
||||
$this->intereses = (object) ['uf' => 0, 'pesos' => 0];
|
||||
if ($this->renovaciones()) {
|
||||
$arr = $this->renovaciones();
|
||||
$this->intereses->uf = array_reduce($arr, function($accum, $item) {
|
||||
return $accum + $item->intereses();
|
||||
});
|
||||
$this->intereses->pesos = array_reduce($arr, function($accum, $item) {
|
||||
return $accum + $item->intereses('pesos');
|
||||
});
|
||||
}
|
||||
}
|
||||
switch (strtolower($tipo)) {
|
||||
case 'uf':
|
||||
case 'ufs':
|
||||
return $this->intereses->uf;
|
||||
case 'peso':
|
||||
case 'pesos':
|
||||
case '$':
|
||||
return $this->intereses->pesos;
|
||||
}
|
||||
if ($fecha == null) {
|
||||
$fecha = $this->vencimiento();
|
||||
}
|
||||
$dif = $fecha->diffInDays($this->fecha());
|
||||
$duracion = ($dif > $this->duracion) ? $this->duracion : $dif;
|
||||
return $this->valor() * ($this->tasa / 365 * $duracion) / 100;
|
||||
}
|
||||
public function estado_pago() {
|
||||
if ($this->estado_pago == 0) {
|
||||
return false;
|
||||
}
|
||||
return $this->belongsTo(AvanceConstruccion::class, 'estado_pago', 'numero')->findOne();
|
||||
}
|
||||
}
|
21
app_old/incoviba/modelos/src/old/Proyecto/Proyectista.php
Normal file
21
app_old/incoviba/modelos/src/old/Proyecto/Proyectista.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property int id
|
||||
* @property int rut
|
||||
* @property string nombre
|
||||
* @property int tipo
|
||||
* @property string representante
|
||||
* @property int telefono
|
||||
* @property string correo
|
||||
* @property int direccion
|
||||
*
|
||||
*/
|
||||
class Proyectista extends Model
|
||||
{
|
||||
}
|
||||
?>
|
17
app_old/incoviba/modelos/src/old/Proyecto/Proyectistas.php
Normal file
17
app_old/incoviba/modelos/src/old/Proyecto/Proyectistas.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property int id
|
||||
* @property int proyecto
|
||||
* @property int proyectista
|
||||
* @property date fecha
|
||||
*
|
||||
*/
|
||||
class Proyectistas extends Model
|
||||
{
|
||||
}
|
||||
?>
|
873
app_old/incoviba/modelos/src/old/Proyecto/Proyecto.php
Normal file
873
app_old/incoviba/modelos/src/old/Proyecto/Proyecto.php
Normal file
@ -0,0 +1,873 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
use Incoviba\old\Common\Direccion;
|
||||
use Incoviba\old\Inmobiliaria\Inmobiliaria;
|
||||
use Incoviba\old\Venta\Cierre;
|
||||
use Incoviba\old\Venta\Cuota;
|
||||
use Incoviba\old\Venta\Promocion;
|
||||
use Incoviba\old\Venta\TipoUnidad;
|
||||
use Incoviba\old\Venta\Unidad;
|
||||
use Incoviba\old\Venta\Venta;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
*
|
||||
* @property int $id
|
||||
* @property Inmobiliaria $inmobiliaria
|
||||
* @property string $descripcion
|
||||
* @property Direccion $direccion
|
||||
* @property float $superficie_terreno
|
||||
* @property float $valor_terreno
|
||||
* @property float $corredor
|
||||
* @property float $superficie_sobre_nivel
|
||||
* @property float $superficie_bajo_nivel
|
||||
* @property int $pisos
|
||||
* @property int $subterraneos
|
||||
*
|
||||
*/
|
||||
class Proyecto extends Model
|
||||
{
|
||||
protected $unidades;
|
||||
protected $valores;
|
||||
protected $tipo_unidades;
|
||||
protected $ventas;
|
||||
protected $escrituras;
|
||||
protected $entregas;
|
||||
protected $estado;
|
||||
protected $agentes;
|
||||
protected $operadores;
|
||||
protected $promociones;
|
||||
protected $cuotas;
|
||||
protected $superficies;
|
||||
|
||||
public function inmobiliaria()
|
||||
{
|
||||
return $this->belongs_to(Inmobiliaria::class, 'inmobiliaria', 'rut')->findOne();
|
||||
}
|
||||
public function direccion()
|
||||
{
|
||||
return $this->belongs_to(Direccion::class, 'direccion')->findOne();
|
||||
}
|
||||
public function unidades($tipo = null)
|
||||
{
|
||||
if ($tipo == null) {
|
||||
if (!isset($this->unidades) or !isset($this->unidades->total)) {
|
||||
$unidades = [];
|
||||
if (isset($this->unidades)) {
|
||||
$unidades = (array) $this->unidades;
|
||||
}
|
||||
$unidades['total'] = $this->has_many(Unidad::class, 'proyecto')->findMany();
|
||||
$this->unidades = (object) $unidades;
|
||||
}
|
||||
return $this->unidades->total;
|
||||
}
|
||||
switch ($tipo) {
|
||||
case 1:
|
||||
case 'departamento':
|
||||
case 'departamentos':
|
||||
$tipo = 'departamento';
|
||||
$id_tipo = 1;
|
||||
break;
|
||||
case 2:
|
||||
case 'estacionamiento':
|
||||
case 'estacionamientos':
|
||||
$tipo = 'estacionamiento';
|
||||
$id_tipo = 2;
|
||||
break;
|
||||
case 3:
|
||||
case 'bodega':
|
||||
case 'bodegas':
|
||||
$tipo = 'bodega';
|
||||
$id_tipo = 3;
|
||||
break;
|
||||
default:
|
||||
return $this->unidades();
|
||||
}
|
||||
if (!isset($this->unidades) or !isset($this->unidades->{$tipo})) {
|
||||
$unidades = [];
|
||||
if (isset($this->unidades)) {
|
||||
$unidades = (array) $this->unidades;
|
||||
}
|
||||
$unidades[$tipo] = $this->has_many(Unidad::class, 'proyecto')->where('tipo', $id_tipo)->findMany();
|
||||
$this->unidades = (object) $unidades;
|
||||
}
|
||||
return $this->unidades->{$tipo};
|
||||
}
|
||||
public function unidadesDisponibles($tipo = null)
|
||||
{
|
||||
switch ($tipo) {
|
||||
case 1:
|
||||
case 'departamento':
|
||||
case 'departamentos':
|
||||
$tipo = 'departamento';
|
||||
$id_tipo = 1;
|
||||
break;
|
||||
case 2:
|
||||
case 'estacionamiento':
|
||||
case 'estacionamientos':
|
||||
$tipo = 'estacionamiento';
|
||||
$id_tipo = 2;
|
||||
break;
|
||||
case 3:
|
||||
case 'bodega':
|
||||
case 'bodegas':
|
||||
$tipo = 'bodega';
|
||||
$id_tipo = 3;
|
||||
break;
|
||||
default:
|
||||
$tipo = 'total';
|
||||
$id_tipo = null;
|
||||
}
|
||||
if (!isset($this->unidades) or !isset($this->unidades->disponibles) or !isset($this->unidades->disponibles->{$tipo})) {
|
||||
$unidades = ['disponibles' => []];
|
||||
if (isset($this->unidades)) {
|
||||
$unidades = (array) $this->unidades;
|
||||
$unidades['disponibles'] = [];
|
||||
if (isset($this->unidades->disponibles)) {
|
||||
$unidades['disponibles'] = (array) $this->unidades->disponibles;
|
||||
}
|
||||
}
|
||||
/*$q_s = "SELECT u.*
|
||||
FROM
|
||||
(SELECT * FROM unidad WHERE proyecto = ? ORDER BY tipo) AS u
|
||||
LEFT JOIN
|
||||
(SELECT unidad.*
|
||||
FROM venta
|
||||
JOIN propiedad ON propiedad.id = venta.propiedad
|
||||
JOIN unidad ON unidad.id = propiedad.unidad_principal
|
||||
WHERE venta.estado = 1) AS v ON v.id = u.id
|
||||
LEFT JOIN
|
||||
(SELECT unidad.*
|
||||
FROM venta
|
||||
JOIN propiedad ON propiedad.id = venta.propiedad
|
||||
JOIN unidad ON propiedad.estacionamientos LIKE unidad.id
|
||||
OR propiedad.estacionamientos LIKE CONCAT(unidad.id, ';%')
|
||||
OR propiedad.estacionamientos LIKE CONCAT('%;', unidad.id)
|
||||
OR propiedad.estacionamientos LIKE CONCAT('%;', unidad.id, ';%')
|
||||
WHERE venta.estado = 1) AS e ON e.id = u.id
|
||||
LEFT JOIN
|
||||
(SELECT unidad.*
|
||||
FROM venta
|
||||
JOIN propiedad ON propiedad.id = venta.propiedad
|
||||
JOIN unidad ON propiedad.bodegas LIKE unidad.id
|
||||
OR propiedad.bodegas LIKE CONCAT(unidad.id, ';%')
|
||||
OR propiedad.bodegas LIKE CONCAT('%;', unidad.id)
|
||||
OR propiedad.bodegas LIKE CONCAT('%;', unidad.id, ';%')
|
||||
WHERE venta.estado = 1) AS b ON b.id = u.id
|
||||
WHERE v.id IS NULL AND e.id IS NULL AND b.id IS NULL";*/
|
||||
$q_s = "SELECT u.*
|
||||
FROM
|
||||
(SELECT * FROM unidad WHERE proyecto = ? ORDER BY tipo) AS u
|
||||
LEFT JOIN (SELECT unidad.*
|
||||
FROM unidad
|
||||
JOIN propiedad_unidad pu ON pu.unidad = unidad.id
|
||||
JOIN venta ON venta.propiedad = pu.propiedad
|
||||
JOIN (SELECT e1.* FROM estado_venta e1
|
||||
JOIN (SELECT venta, MAX(id) AS id FROM estado_venta GROUP BY venta) e0 ON e0.id = e1.id) ev ON ev.venta = venta.id
|
||||
WHERE ev.estado = 1) AS v ON v.id = u.id
|
||||
WHERE v.id IS NULL";
|
||||
$q_p = " ORDER BY u.tipo, LPAD(u.descripcion, 4, '0')";
|
||||
switch (strtolower($id_tipo)) {
|
||||
case null:
|
||||
default:
|
||||
$q = $q_s . $q_p;
|
||||
break;
|
||||
case 1:
|
||||
case 'departamento':
|
||||
case 'departamentos':
|
||||
$q = $q_s . ' AND u.tipo = 1' . $q_p;
|
||||
break;
|
||||
case 2:
|
||||
case 'estacionamiento':
|
||||
case 'estacionamientos':
|
||||
$q = $q_s . ' AND u.tipo = 2' . $q_p;
|
||||
break;
|
||||
case 3:
|
||||
case 'bodega':
|
||||
case 'bodegas':
|
||||
$q = $q_s . ' AND u.tipo = 3' . $q_p;
|
||||
break;
|
||||
}
|
||||
$disponibles = model(Unidad::class)->rawQuery($q, [$this->id])->findMany();
|
||||
$unidades['disponibles'][$tipo] = $disponibles;
|
||||
$unidades['disponibles'] = (object) $unidades['disponibles'];
|
||||
$this->unidades = (object) $unidades;
|
||||
}
|
||||
return $this->unidades->disponibles->{$tipo};
|
||||
}
|
||||
public function proyectoTipoUnidades()
|
||||
{
|
||||
return $this->hasMany(ProyectoTipoUnidad::class, 'proyecto')->orderByAsc('tipo')->findMany();
|
||||
}
|
||||
public function tipoUnidades()
|
||||
{
|
||||
if (!isset($this->tipos_unidades)) {
|
||||
$tipos = \Model::factory(TipoUnidad::class)
|
||||
->select('tipo_unidad.*')
|
||||
->join('unidad', ['unidad.tipo', '=', 'tipo_unidad.id'])
|
||||
->join('proyecto', ['proyecto.id', '=', 'unidad.proyecto'])
|
||||
->where('proyecto.id', $this->id)
|
||||
->order_by_asc('tipo_unidad.id')
|
||||
->group_by('tipo_unidad.id')
|
||||
->findMany();
|
||||
$this->tipos_unidades = $tipos;
|
||||
}
|
||||
return $this->tipos_unidades;
|
||||
}
|
||||
public function ventas($order = 'departamento')
|
||||
{
|
||||
if (!isset($this->ventas)) {
|
||||
$ventas = model(Venta::class)
|
||||
->select('venta.*')
|
||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
||||
->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')
|
||||
->join('tipo_estado_venta', ['tipo_estado_venta.id', '=', 'estado_venta.estado'])
|
||||
->where('unidad.proyecto', $this->id)
|
||||
->where('unidad.tipo', 1)
|
||||
->where('tipo_estado_venta.activa', 1);
|
||||
switch (strtolower($order)) {
|
||||
case 'fecha':
|
||||
$ventas = $ventas->orderByAsc('venta.fecha');
|
||||
case 'departamento':
|
||||
default:
|
||||
$ventas = $ventas->orderByExpr('LPAD(`unidad`.`descripcion`, 4, "0")');
|
||||
break;
|
||||
}
|
||||
$ventas = $ventas->find_many();
|
||||
$this->ventas = $ventas;
|
||||
}
|
||||
return $this->ventas;
|
||||
}
|
||||
protected $resciliaciones;
|
||||
public function resciliaciones()
|
||||
{
|
||||
if ($this->resciliaciones == null) {
|
||||
$resciliaciones = model(Venta::class)
|
||||
->select('venta.*')
|
||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
||||
->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')
|
||||
->join('tipo_estado_venta', ['tipo_estado_venta.id', '=', 'estado_venta.estado'])
|
||||
->where('unidad.proyecto', $this->id)
|
||||
->where('unidad.tipo', 1)
|
||||
->where('tipo_estado_venta.activa', 0)
|
||||
->orderByExpr('LPAD(`unidad`.`descripcion`, 4, "0")')
|
||||
->find_many()
|
||||
;
|
||||
$this->resciliaciones = $resciliaciones;
|
||||
}
|
||||
return $this->resciliaciones;
|
||||
}
|
||||
public function escrituras()
|
||||
{
|
||||
if (!isset($escrituras)) {
|
||||
$ventas = model(Venta::class)
|
||||
->select('venta.*')
|
||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
||||
->where('unidad.proyecto', $this->id)
|
||||
->where('venta.estado', 1)
|
||||
->where('unidad.tipo', 1)
|
||||
->whereNotEqual('venta.escriturado', '0')
|
||||
->orderByExpr('LPAD(unidad.descripcion, 4, "0")')
|
||||
->find_many()
|
||||
;
|
||||
$this->escrituras = $ventas;
|
||||
}
|
||||
return $this->escrituras;
|
||||
}
|
||||
public function entregas()
|
||||
{
|
||||
if (!isset($this->entregas)) {
|
||||
$entregas = [];
|
||||
$escrituras = $this->escrituras();
|
||||
foreach ($escrituras as $escritura) {
|
||||
if ($escritura->entrega == '0') {
|
||||
continue;
|
||||
}
|
||||
$entregas []= $escritura;
|
||||
}
|
||||
usort($entregas, function($a, $b) {
|
||||
$fa = \Carbon\Carbon::parse($a->entrega()->find_one()->fecha);
|
||||
$fb = \Carbon\Carbon::parse($b->entrega()->find_one()->fecha);
|
||||
$dif = $fb->diffInDays($fa, false);
|
||||
if ($dif == 0) {
|
||||
return $a->unidad()->descripcion - $b->unidad()->descripcion;
|
||||
}
|
||||
return $dif;
|
||||
});
|
||||
$this->entregas = $entregas;
|
||||
}
|
||||
return $this->entregas;
|
||||
}
|
||||
public function estados()
|
||||
{
|
||||
return $this->has_many(EstadoProyecto::class, 'proyecto')->orderByAsc('fecha')->findMany();
|
||||
}
|
||||
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);
|
||||
}
|
||||
return $this->estado;
|
||||
}
|
||||
public function avances()
|
||||
{
|
||||
return $this->hasMany(AvanceConstruccion::class, 'proyecto')->orderByAsc('fecha')->findMany();
|
||||
}
|
||||
protected $avance;
|
||||
public function avance()
|
||||
{
|
||||
if ($this->avance == null and $this->avances()) {
|
||||
$avance = array_reduce($this->avances(), function($carry, $item) {
|
||||
return ($carry += $item->avance);
|
||||
});
|
||||
$this->avance = $avance;
|
||||
}
|
||||
return $this->avance;
|
||||
}
|
||||
protected $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);
|
||||
}
|
||||
return $this->inicio;
|
||||
}
|
||||
public function valores()
|
||||
{
|
||||
if (!isset($this->valores)) {
|
||||
$ventas = $this->ventas();
|
||||
|
||||
/**
|
||||
* vendidos
|
||||
* departamentos
|
||||
* cantidad
|
||||
* ingreso
|
||||
* neto
|
||||
* bruto // suma estacionamientos, bodegas, comision y premios
|
||||
* pagado
|
||||
* abonado
|
||||
* precio
|
||||
* minimo
|
||||
* promedio
|
||||
* maximo
|
||||
* mts
|
||||
* minimo
|
||||
* promedio // total dividido cantidad
|
||||
* maximo
|
||||
* total
|
||||
* uf_m2
|
||||
* minimo // minimo de precio dividido mts
|
||||
* promedio // ingreso neto dividido mts total
|
||||
* maximo // maximo de precio dividido mts
|
||||
* estacionamientos // valor estacionamientos
|
||||
* bodegas // valor bodegas
|
||||
* comision // valor comisiones
|
||||
* premios // valor total cada premio
|
||||
* estimados // idem vendidos, pero valores estimados proporcional a mts
|
||||
* totales // vendidos + estimados
|
||||
*/
|
||||
|
||||
$premios = model(Promocion::class)->findMany();
|
||||
$valores = (object) [
|
||||
'vendidos' => new BaseValores(),
|
||||
'estimados' => new BaseValores(),
|
||||
'totales' => new BaseValores()
|
||||
];
|
||||
foreach ($valores as &$name) {
|
||||
$name->basePremios($premios);
|
||||
}
|
||||
if ($ventas) {
|
||||
$valores->vendidos->ingreso->neto = 0;
|
||||
$valores->vendidos->ingreso->neto = array_reduce($ventas, function($sum, $item) {
|
||||
return $sum + $item->valorFinal();
|
||||
});
|
||||
foreach ($ventas as $venta) {
|
||||
//$valores->vendidos->ingreso->neto += $venta->valorFinal();
|
||||
$valores->vendidos->ingreso->bruto += $venta->valor_uf;
|
||||
$valores->vendidos->ingreso->pagado += $venta->valorPagado();
|
||||
$valores->vendidos->ingreso->abonado += $venta->valorAbonado();
|
||||
|
||||
$valores->vendidos->departamentos->cantidad ++;
|
||||
if ($venta->unidad()->precio($venta->fecha())) {
|
||||
$valores->vendidos->departamentos->addPrecio($venta->unidad()->precio($venta->fecha())->valor);
|
||||
}
|
||||
$valores->vendidos->departamentos->addMts('totales', $venta->unidad()->m2('total'));
|
||||
$valores->vendidos->departamentos->addMts('vendibles', $venta->unidad()->m2());
|
||||
|
||||
//$valores->vendidos->otros->cantidad += ($venta->estacionamientos() or $venta->bodegas()) :
|
||||
$valores->vendidos->otros->valor += $venta->valorEstacionamientosYBodegas();
|
||||
if ($venta->bono_pie) {
|
||||
$valores->vendidos->bono->cantidad ++;
|
||||
$valores->vendidos->bono->valor += $venta->bonoPie()->pago()->valor('ufs');
|
||||
}
|
||||
$valores->vendidos->comision += $venta->valorComision();
|
||||
$ps = $venta->promociones();
|
||||
if (count($ps) > 0) {
|
||||
foreach ($ps as $promo) {
|
||||
if ($promo->descripcion != '') {
|
||||
$valores->vendidos->premios->{$promo->descripcion} += $promo->valor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$valores->vendidos->departamentos->setPromedios();
|
||||
}
|
||||
|
||||
$valores->estimados->departamentos->cantidad = count($this->unidades(1)) - count($this->ventas());
|
||||
$valores->estimados->departamentos->mts->vendibles->total = 0;
|
||||
$valores->estimados->departamentos->mts->vendibles->promedio = 0;
|
||||
$valores->estimados->departamentos->precio->promedio = 0;
|
||||
$valores->estimados->departamentos->uf_m2->promedio = 0;
|
||||
if ($valores->estimados->departamentos->cantidad > 0) {
|
||||
$valores->estimados->departamentos->mts->vendibles->total = array_reduce($this->unidadesDisponibles(1), function($sum, $item) {
|
||||
return $sum + $item->m2();
|
||||
});
|
||||
$valores->estimados->departamentos->mts->vendibles->promedio = $valores->estimados->departamentos->mts->vendibles->total / $valores->estimados->departamentos->cantidad;
|
||||
$valores->estimados->ingreso->neto = array_reduce($this->unidadesDisponibles(1), function($sum, $item) {
|
||||
if (!$item->precio()) {
|
||||
return $sum;
|
||||
}
|
||||
return $sum + $item->precio()->valor;
|
||||
});
|
||||
if ($valores->estimados->ingreso->neto == null) {
|
||||
$valores->estimados->ingreso->neto = 0;
|
||||
}
|
||||
$valores->estimados->departamentos->precio->promedio = $valores->estimados->ingreso->neto / $valores->estimados->departamentos->cantidad;
|
||||
$valores->estimados->departamentos->uf_m2->promedio = $valores->estimados->ingreso->neto / $valores->estimados->departamentos->mts->vendibles->total;
|
||||
}
|
||||
|
||||
$valores->estimados->otros->cantidad = count($this->unidadesDisponibles(2)) + count($this->unidadesDisponibles(3));
|
||||
$valores->estimados->otros->valor = count($this->unidadesDisponibles(2)) * 330 + count($this->unidadesDisponibles(3)) * 50;
|
||||
foreach ($premios as $premio) {
|
||||
$valores->estimados->premios->{$premio->descripcion} = 0;
|
||||
if ($valores->vendidos->ingreso->neto > 0) {
|
||||
$valores->estimados->premios->{$premio->descripcion} = $valores->vendidos->premios() * $valores->estimados->ingreso->neto / $valores->vendidos->ingreso->neto;
|
||||
}
|
||||
}
|
||||
$valores->estimados->bono->valor = 0;
|
||||
$valores->estimados->comision = 0;
|
||||
if ($valores->vendidos->ingreso->neto > 0) {
|
||||
$valores->estimados->bono->valor = $valores->vendidos->bono->valor * $valores->estimados->ingreso->neto / $valores->vendidos->ingreso->neto;
|
||||
$valores->estimados->comision = $valores->vendidos->comision * $valores->estimados->ingreso->neto / $valores->vendidos->ingreso->neto;
|
||||
}
|
||||
$valores->estimados->ingreso->bruto = $valores->estimados->ingreso->neto
|
||||
+ $valores->estimados->otros->valor
|
||||
+ $valores->estimados->bono->valor
|
||||
+ $valores->estimados->premios()
|
||||
+ $valores->estimados->comision;
|
||||
|
||||
$this->valores = $valores;
|
||||
}
|
||||
|
||||
return $this->valores;
|
||||
}
|
||||
public function agentes()
|
||||
{
|
||||
if (!isset($this->agentes)) {
|
||||
$this->agentes = \Model::factory(Agente::class)
|
||||
->select('agente.*')
|
||||
->join('proyecto_agente', ['proyecto_agente.agente', '=', 'agente.id'])
|
||||
->where('proyecto_agente.proyecto', $this->id)
|
||||
->orderByAsc('agente.abreviacion')
|
||||
->findMany();
|
||||
}
|
||||
return $this->agentes;
|
||||
}
|
||||
public function operadores()
|
||||
{
|
||||
if (!isset($this->operadores)) {
|
||||
$this->operadores = \Model::factory(Agente::class)
|
||||
->select('agente.*')
|
||||
->select('agente_tipo.id', 'agente_tipo')
|
||||
->join('agente_tipo', ['agente_tipo.agente', '=', 'agente.id'])
|
||||
->join('proyecto_agente', ['proyecto_agente.agente', '=', 'agente_tipo.id'])
|
||||
->where('agente_tipo.tipo', 19)
|
||||
->where('proyecto_agente.proyecto', $this->id)
|
||||
->orderByAsc('agente.abreviacion')
|
||||
->groupBy('agente_tipo.id')
|
||||
->findMany();
|
||||
}
|
||||
return $this->operadores;
|
||||
}
|
||||
public function operadoresVigentes()
|
||||
{
|
||||
return $this->hasMany(ProyectoAgente::class, 'proyecto')
|
||||
->select('proyecto_agente.*')
|
||||
->join('agente_tipo', ['agente_tipo.id', '=', 'proyecto_agente.agente'])
|
||||
->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')
|
||||
->where('agente_tipo.tipo', 19)
|
||||
->where('ep.tipo', 1)
|
||||
->findMany();
|
||||
}
|
||||
public function promociones()
|
||||
{
|
||||
if (!isset($this->promociones)) {
|
||||
$this->promociones = \Model::factory(Promocion::class)
|
||||
->select('promocion.*')
|
||||
->join('promocion_venta', ['promocion_venta.promocion', '=', 'promocion.id'])
|
||||
->join('venta', ['venta.id', '=', 'promocion_venta.venta'])
|
||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
||||
->where('unidad.proyecto', $this->id)
|
||||
->groupBy('promocion.id')
|
||||
->orderByAsc('promocion.titulo')
|
||||
->findMany();
|
||||
}
|
||||
return $this->promociones;
|
||||
}
|
||||
public function pisos()
|
||||
{
|
||||
if ($this->pisos == 0) {
|
||||
$pisos = $this->has_many(Unidad::class, 'proyecto')->where('tipo', 1)->max('piso');
|
||||
if (!$pisos) {
|
||||
return 0;
|
||||
}
|
||||
$this->pisos = $pisos;
|
||||
$this->save();
|
||||
}
|
||||
return $this->pisos;
|
||||
}
|
||||
public function cuotasHoy()
|
||||
{
|
||||
if (!isset($this->cuotas) or !isset($this->cuotas->hoy)) {
|
||||
$cuotas = [];
|
||||
if (isset($this->cuotas)) {
|
||||
$cuotas = (array) $this->cuotas;
|
||||
}
|
||||
$f = Carbon::today(config('app.timezone'));
|
||||
$cuotas['hoy'] = model(Venta::class)
|
||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
||||
->join('cuota', ['cuota.pie', '=', 'venta.pie'])
|
||||
->join('pago', ['pago.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')
|
||||
->where('unidad.proyecto', $this->id)
|
||||
->where('venta.estado', 1)
|
||||
->where('pago.fecha', $f->format('Y-m-d'))
|
||||
->whereLt('ep.estado', 1)
|
||||
->whereGte('ep.estado', 0)
|
||||
->count('cuota.id');
|
||||
$this->cuotas = (object) $cuotas;
|
||||
}
|
||||
return $this->cuotas->hoy;
|
||||
}
|
||||
public function cuotasPendientes()
|
||||
{
|
||||
if (!isset($this->cuotas) or !isset($this->cuotas->pendientes)) {
|
||||
$cuotas = [];
|
||||
if (isset($this->cuotas)) {
|
||||
$cuotas = (array) $this->cuotas;
|
||||
}
|
||||
$f = Carbon::today(config('app.timezone'));
|
||||
$cuotas['pendientes'] = model(Cuota::class)
|
||||
->join('venta', ['cuota.pie', '=', 'venta.pie'])
|
||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
||||
->join('pago', ['pago.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')
|
||||
->where('unidad.proyecto', $this->id)
|
||||
->where('venta.estado', 1)
|
||||
->whereLt('pago.fecha', $f->format('Y-m-d'))
|
||||
->whereLt('ep.estado', 1)
|
||||
->whereGte('ep.estado', 0)
|
||||
->count('cuota.id');
|
||||
$this->cuotas = (object) $cuotas;
|
||||
}
|
||||
return $this->cuotas->pendientes;
|
||||
}
|
||||
public function cuotasMes()
|
||||
{
|
||||
if (!isset($this->cuotas) or !isset($this->cuotas->mes)) {
|
||||
$cuotas = [];
|
||||
if (isset($this->cuotas)) {
|
||||
$cuotas = (array) $this->cuotas;
|
||||
}
|
||||
$f = Carbon::today(config('app.timezone'));
|
||||
$cuotas['mes'] = model(Cuota::class)
|
||||
->join('venta', ['cuota.pie', '=', 'venta.pie'])
|
||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
||||
->join('pago', ['pago.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')
|
||||
->where('unidad.proyecto', $this->id)
|
||||
->where('venta.estado', 1)
|
||||
->whereGt('pago.fecha', $f->format('Y-m-d'))
|
||||
->whereLte('pago.fecha', $f->copy()->addMonth(1)->format('Y-m-d'))
|
||||
->where('ep.estado', 0)
|
||||
->findMany();
|
||||
$this->cuotas = (object) $cuotas;
|
||||
}
|
||||
return $this->cuotas->mes;
|
||||
}
|
||||
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')
|
||||
{
|
||||
if (!isset($this->superficies) or !isset($this->superficies->{$tipo})) {
|
||||
$superficies = [];
|
||||
if (isset($this->superficies)) {
|
||||
$superficies = (array) $this->superficies;
|
||||
}
|
||||
switch (strtolower($tipo)) {
|
||||
case 'total':
|
||||
$superficies['total'] = $this->superficie('snt') + $this->superficie('bnt');
|
||||
break;
|
||||
case 'terreno':
|
||||
$superficies['terreno'] = $this->superficie_terreno;
|
||||
break;
|
||||
case 'sobre_nivel':
|
||||
case 'snt':
|
||||
$superficies['snt'] = $superficies['sobre_nivel'] = $this->superficie_sobre_nivel;
|
||||
break;
|
||||
case 'bajo_nivel':
|
||||
case 'bnt':
|
||||
$superficies['bnt'] = $superficies['bajo_nivel'] = $this->superficie_bajo_nivel;
|
||||
break;
|
||||
case 'vendible':
|
||||
$superficies['vendible'] = 0;
|
||||
if ($this->unidades()) {
|
||||
$metros = $this->hasMany(Unidad::class, 'proyecto')->selectExpr('SUM(m2 + logia + terraza /2)', 'metros')->where('tipo', 1)->groupBy('proyecto')->findOne();
|
||||
$superficies['vendible'] = $metros->metros;
|
||||
}
|
||||
break;
|
||||
case 'vendida':
|
||||
$superficies['vendida'] = 0;
|
||||
if ($this->ventas()) {
|
||||
$metros = model(Venta::class)
|
||||
->selectExpr('SUM(unidad.m2 + unidad.logia + unidad.terraza / 2)', 'metros')
|
||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
||||
->where('unidad.proyecto', $this->id)
|
||||
->where('venta.estado', 1)
|
||||
->where('unidad.tipo', 1)
|
||||
->groupBy('unidad.proyecto')
|
||||
->findOne();
|
||||
if ($metros) {
|
||||
$superficies['vendida'] = $metros->metros;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'por vender':
|
||||
$superficies['por vender'] = $this->superficie('vendible') - $this->superficie('vendida');
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
$this->superficies = (object) $superficies;
|
||||
}
|
||||
return $this->superficies->{$tipo};
|
||||
}
|
||||
public function setDireccion(array $data)
|
||||
{
|
||||
if (!is_numeric($data['comuna'])) {
|
||||
$comuna = model(Comuna::class)->where('descripcion', $data['comuna'])->findOne();
|
||||
$data['comuna'] = $comuna->id;
|
||||
}
|
||||
$direccion = model(Direccion::class)
|
||||
->where('calle', $data['calle'])
|
||||
->where('numero', $data['numero'])
|
||||
->where('extra', $data['extra'])
|
||||
->where('comuna', $data['comuna'])
|
||||
->findOne();
|
||||
$this->direccion = $direccion->id;
|
||||
}
|
||||
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()
|
||||
{
|
||||
if ($this->tipologias == null) {
|
||||
$pts = $this->proyectoTipoUnidades();
|
||||
$tipologias = [];
|
||||
foreach ($pts as $pt) {
|
||||
if ($pt->tipologia()) {
|
||||
if (!isset($tipologias[$pt->tipologia()->tipologia->descripcion])) {
|
||||
$tipologias[$pt->tipologia()->tipologia->descripcion] = (object) ['tipologia' => $pt->tipologia()->tipologia, 'tipos' => []];
|
||||
}
|
||||
$tipologias[$pt->tipologia()->tipologia->descripcion]->tipos []= $pt;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$this->tipologias = $tipologias;
|
||||
}
|
||||
return $this->tipologias;
|
||||
}
|
||||
public function pagares()
|
||||
{
|
||||
return $this->hasMany(Pagare::class, 'proyecto')->findMany();
|
||||
}
|
||||
protected $cierres;
|
||||
public function cierres(int $vigentes = 0)
|
||||
{
|
||||
if (!isset($this->cierres[$vigentes]) or $this->cierres[$vigentes] == null) {
|
||||
$orm = model(Cierre::class)
|
||||
->select('cierre.*')
|
||||
->rawJoin(
|
||||
'join (select e1.* from estado_cierre e1 join (select cierre, max(id) as id from estado_cierre group by cierre) e0 on e0.id = e1.id)',
|
||||
['ec.cierre', '=', 'cierre.id'],
|
||||
'ec')
|
||||
->join('tipo_estado_cierre', ['tipo_estado_cierre.id', '=', 'ec.tipo'])
|
||||
->join('proyecto', ['proyecto.id', '=', 'cierre.proyecto'])
|
||||
->join('unidad_cierre', ['unidad_cierre.cierre', '=', 'cierre.id'])
|
||||
->join('unidad', ['unidad.id', '=', 'unidad_cierre.unidad'])
|
||||
->where('proyecto.id', $this->id)
|
||||
->where('unidad_cierre.principal', 1)
|
||||
->orderByAsc('proyecto.descripcion')
|
||||
->orderByDesc('tipo_estado_cierre.vigente')
|
||||
->orderByDesc('cierre.fecha')
|
||||
->orderByExpr('LPAD(unidad.descripcion, 4, "0")')
|
||||
->groupBy('cierre.id');
|
||||
switch ($vigentes) {
|
||||
case Cierre::VIGENTES:
|
||||
$orm = $orm->where('tipo_estado_cierre.vigente', 1);
|
||||
break;
|
||||
case Cierre::NO_VIGENTES:
|
||||
$orm = $orm->where('tipo_estado_cierre.vigente', 0);
|
||||
break;
|
||||
case Cierre::VIGENTES + 1:
|
||||
$orm = $orm
|
||||
->where('tipo_estado_cierre.vigente', 1)
|
||||
->whereNotLike('tipo_estado_cierre.descripcion', 'promesado')
|
||||
;
|
||||
break;
|
||||
case Cierre::VIGENTES + 2:
|
||||
$orm = $orm
|
||||
->where('tipo_estado_cierre.vigente', 1)
|
||||
->whereLike('tipo_estado_cierre.descripcion', 'promesado')
|
||||
;
|
||||
break;
|
||||
}
|
||||
$this->cierres[$vigentes] = $orm->findMany();
|
||||
}
|
||||
return $this->cierres[$vigentes];
|
||||
}
|
||||
public function tipos() {
|
||||
return $this->hasMany(ProyectoTipoUnidad::class, 'proyecto')->findMany();
|
||||
}
|
||||
}
|
||||
|
||||
class Departamentos {
|
||||
public $cantidad;
|
||||
public $precio;
|
||||
public $mts;
|
||||
public $uf_m2;
|
||||
public function __construct() {
|
||||
$this->cantidad = 0;
|
||||
$base = [
|
||||
'minimo' => 1000000,
|
||||
'promedio' => 0,
|
||||
'maximo' => -1
|
||||
];
|
||||
$this->precio = (object) $base;
|
||||
$this->mts = (object) [
|
||||
'totales' => (object) array_merge($base, ['total' => 0]),
|
||||
'vendibles' => (object) array_merge($base, ['total' => 0])
|
||||
];
|
||||
$this->uf_m2 = (object) $base;
|
||||
}
|
||||
protected function setMin(&$var, $val) {
|
||||
if ($var > $val) {
|
||||
$var = $val;
|
||||
}
|
||||
}
|
||||
protected function setMax(&$var, $val) {
|
||||
if ($var < $val) {
|
||||
$var = $val;
|
||||
}
|
||||
}
|
||||
public function addPrecio($val) {
|
||||
$this->precio->promedio += $val;
|
||||
$this->setMin($this->precio->minimo, $val);
|
||||
$this->setMax($this->precio->maximo, $val);
|
||||
$this->uf_m2->promedio += $val;
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function addMts($name, $val) {
|
||||
$this->mts->$name->total += $val;
|
||||
$this->mts->$name->promedio += $val;
|
||||
$this->setMin($this->mts->{$name}->minimo, $val);
|
||||
$this->setMax($this->mts->{$name}->maximo, $val);
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function addUfM2($val) {
|
||||
$this->setMin($this->uf_m2->minimo, $val);
|
||||
$this->setMax($this->uf_m2->maximo, $val);
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function setPromedios() {
|
||||
$this->precio->promedio /= $this->cantidad;
|
||||
$this->mts->totales->promedio /= $this->cantidad;
|
||||
$this->mts->vendibles->promedio /= $this->cantidad;
|
||||
$this->uf_m2->promedio /= $this->mts->vendibles->total;
|
||||
|
||||
return $this;
|
||||
}
|
||||
};
|
||||
class BaseValores {
|
||||
public $ingreso;
|
||||
public $departamentos;
|
||||
public $otros;
|
||||
public $bono;
|
||||
public $comision;
|
||||
public $premios;
|
||||
|
||||
public function __construct() {
|
||||
$this->ingreso = (object) [
|
||||
'neto' => 0,
|
||||
'bruto' => 0,
|
||||
'pagado' => 0,
|
||||
'abonado' => 0
|
||||
];
|
||||
$this->departamentos = new Departamentos();
|
||||
$this->otros = (object) [
|
||||
'cantidad' => 0,
|
||||
'valor' => 0
|
||||
];
|
||||
$this->bono = (object) [
|
||||
'cantidad' => 0,
|
||||
'valor' => 0
|
||||
];
|
||||
$this->comision = 0;
|
||||
$this->premios = [];
|
||||
}
|
||||
public function basePremios(array $premios) {
|
||||
foreach ($premios as $premio) {
|
||||
$this->premios[$premio->descripcion] = 0;
|
||||
}
|
||||
$this->premios = (object) $this->premios;
|
||||
|
||||
return $this;
|
||||
}
|
||||
protected $total_premios;
|
||||
public function premios() {
|
||||
if ($this->total_premios == null) {
|
||||
$this->total_premios = array_reduce((array) $this->premios, function($sum, $item) {
|
||||
return $sum + $item;
|
||||
});
|
||||
}
|
||||
return $this->total_premios;
|
||||
}
|
||||
};
|
54
app_old/incoviba/modelos/src/old/Proyecto/ProyectoAgente.php
Normal file
54
app_old/incoviba/modelos/src/old/Proyecto/ProyectoAgente.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
use Incoviba\old\Venta\UnidadBloqueada;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
*
|
||||
* @property int id
|
||||
* @property Proyecto proyecto
|
||||
* @property AgenteTipo agente
|
||||
* @property date fecha
|
||||
* @property float comision
|
||||
*
|
||||
*/
|
||||
class ProyectoAgente extends Model
|
||||
{
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->belongsTo(Proyecto::class, 'proyecto')->findOne();
|
||||
}
|
||||
public function agente()
|
||||
{
|
||||
return $this->belongsTo(AgenteTipo::class, 'agente')->findOne();
|
||||
}
|
||||
public function estado()
|
||||
{
|
||||
return $this->hasMany(EstadoProyectoAgente::class, 'agente')
|
||||
->orderByDesc('id')->findOne();
|
||||
}
|
||||
public function estados()
|
||||
{
|
||||
return $this->hasMany(EstadoProyectoAgente::class, 'agente')->findMany();
|
||||
}
|
||||
public function unidadesBloqueadas()
|
||||
{
|
||||
return $this->hasMany(UnidadBloqueada::class, 'agente')->findMany();
|
||||
}
|
||||
public function new()
|
||||
{
|
||||
parent::save();
|
||||
$tipo = model(TipoEstadoProyectoAgente::class)->where('descripcion', 'vigente')->findOne();
|
||||
$data = [
|
||||
'agente' => $this->id,
|
||||
'fecha' => $this->fecha,
|
||||
'tipo' => $tipo->id
|
||||
];
|
||||
$estado = model(EstadoProyectoAgente::class)->create($data);
|
||||
$estado->save();
|
||||
}
|
||||
}
|
||||
?>
|
165
app_old/incoviba/modelos/src/old/Proyecto/ProyectoTipoUnidad.php
Normal file
165
app_old/incoviba/modelos/src/old/Proyecto/ProyectoTipoUnidad.php
Normal file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Proyecto;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
use Incoviba\old\Venta\TipoUnidad;
|
||||
use Incoviba\old\Venta\Unidad;
|
||||
use Incoviba\old\Venta\Venta;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property int id
|
||||
* @property int proyecto
|
||||
* @property string nombre
|
||||
* @property int tipo
|
||||
* @property string abreviacion
|
||||
* @property float m2
|
||||
* @property float logia
|
||||
* @property float terraza
|
||||
* @property string descripcion
|
||||
*
|
||||
*/
|
||||
class ProyectoTipoUnidad extends Model
|
||||
{
|
||||
protected $lineas;
|
||||
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->belongsTo(Proyecto::class, 'proyecto')->findOne();
|
||||
}
|
||||
public function unidades()
|
||||
{
|
||||
return $this->hasMany(Unidad::class, 'pt')->orderByExpr('LPAD(subtipo, 3, "0")')->orderByExpr('LPAD(descripcion, 4, "0")')->findMany();
|
||||
}
|
||||
public function tipo()
|
||||
{
|
||||
return $this->belongsTo(TipoUnidad::class, 'tipo')->findOne();
|
||||
}
|
||||
public function m2($tipo = 'vendible')
|
||||
{
|
||||
return $this->m2 + $this->logia + $this->terraza / (($tipo == 'vendible') ? 2 : 1);
|
||||
}
|
||||
public function lineas()
|
||||
{
|
||||
if ($this->lineas == null) {
|
||||
$lineas = [];
|
||||
foreach ($this->unidades() as $unidad) {
|
||||
if (array_search($unidad->subtipo, $lineas) === false) {
|
||||
$lineas []= $unidad->subtipo;
|
||||
}
|
||||
}
|
||||
sort($lineas);
|
||||
$this->lineas = implode(', ', $lineas);
|
||||
}
|
||||
return $this->lineas;
|
||||
}
|
||||
public function precio($fecha = null)
|
||||
{
|
||||
$sum = 0;
|
||||
$cnt = 0;
|
||||
foreach ($this->unidades() as $unidad) {
|
||||
if ($unidad->precio($fecha)) {
|
||||
$sum += $unidad->precio($fecha)->valor;
|
||||
$cnt ++;
|
||||
}
|
||||
}
|
||||
if ($cnt == 0) {
|
||||
return 0;
|
||||
}
|
||||
return $sum / $cnt;
|
||||
}
|
||||
protected $precios;
|
||||
public function precioSubtipo($subtipo, $fecha = null)
|
||||
{
|
||||
if (!isset($this->precios[$subtipo])) {
|
||||
$sum = 0;
|
||||
$cnt = 0;
|
||||
foreach ($this->unidades() as $unidad) {
|
||||
if ($unidad->subtipo == $subtipo and $unidad->precio($fecha)) {
|
||||
$sum += $unidad->precio($fecha)->valor;
|
||||
$cnt ++;
|
||||
}
|
||||
}
|
||||
if ($this->precios == null) {
|
||||
$this->precios = [];
|
||||
}
|
||||
$prom = 0;
|
||||
if ($cnt > 0) {
|
||||
$prom = $sum / $cnt;
|
||||
}
|
||||
$this->precios[$subtipo] = $prom;
|
||||
}
|
||||
return $this->precios[$subtipo];
|
||||
}
|
||||
public function setPrecios($fecha, $valor)
|
||||
{
|
||||
foreach ($this->unidades() as $unidad) {
|
||||
$unidad->setPrecio($fecha, $valor);
|
||||
}
|
||||
}
|
||||
public function setPreciosSubtipo($subtipo, $fecha, $valor)
|
||||
{
|
||||
foreach ($this->unidades() as $unidad) {
|
||||
if ($unidad->subtipo == $subtipo) {
|
||||
$unidad->setPrecio($fecha, $valor);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected $tipologia;
|
||||
public function tipologia()
|
||||
{
|
||||
if ($this->tipologia == null) {
|
||||
$tipologias = $this->hasMany(TipoTipologia::class, 'tipo')->findMany();
|
||||
if (!$tipologias) {
|
||||
$this->tipologia = false;
|
||||
return false;
|
||||
}
|
||||
usort($tipologias, function($a, $b) {
|
||||
return $a->elemento()->orden - $b->elemento()->orden;
|
||||
});
|
||||
$tipologia = ['tipologia' => $tipologias[0]->tipologia(), 'detalles' => $tipologias];
|
||||
$resumen = [];
|
||||
$detalle = [];
|
||||
foreach ($tipologias as $t) {
|
||||
if (strpos($t->elemento()->descripcion, 'cocina ') !== false) {
|
||||
$resumen []= $t->elemento()->abreviacion;
|
||||
$detalle []= $t->elemento()->descripcion;
|
||||
continue;
|
||||
}
|
||||
$resumen []= $t->cantidad . '' . $t->elemento()->abreviacion;
|
||||
$detalle []= $t->cantidad . ' ' . $t->elemento()->descripcion . (($t->cantidad > 1) ? 's' : '');
|
||||
}
|
||||
$tipologia['descripcion'] = implode('/', $resumen);
|
||||
$tipologia['detalle'] = implode(', ', $detalle) . '.';
|
||||
|
||||
$this->tipologia = (object) $tipologia;
|
||||
}
|
||||
return $this->tipologia;
|
||||
}
|
||||
protected $ventas;
|
||||
public function ventas($order = 'departamento')
|
||||
{
|
||||
if ($this->ventas == null) {
|
||||
$ventas = model(Venta::class)
|
||||
->select('venta.*')
|
||||
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
|
||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
||||
->join('proyecto_tipo_unidad', ['proyecto_tipo_unidad.id', '=', 'unidad.pt'])
|
||||
->rawJoin('JOIN (SELECT e1.* FROM estado_venta e1 JOIN (SELECT venta, MAX(id) AS id FROM estado_venta GROUP BY venta) e0 ON e0.id = e1.id)', ['ev.venta', '=', 'venta.id'], 'ev')
|
||||
->join('tipo_estado_venta', ['tipo_estado_venta.id', '=', 'ev.estado'])
|
||||
->where('tipo_estado_venta.activa', 1)
|
||||
->where('proyecto_tipo_unidad.id', $this->id);
|
||||
switch (strtolower($order)) {
|
||||
case 'fecha':
|
||||
$ventas = $ventas->orderByAsc('venta.fecha');
|
||||
case 'departamento':
|
||||
default:
|
||||
$ventas = $ventas->orderByExpr('LPAD(unidad.descripcion, 4, "0")');
|
||||
break;
|
||||
}
|
||||
$ventas = $ventas->findMany();
|
||||
$this->ventas = $ventas;
|
||||
}
|
||||
return $this->ventas;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user