Resources

This commit is contained in:
2021-03-25 21:20:49 -03:00
parent cdf3ce9c21
commit 15e1eecc76
213 changed files with 19218 additions and 0 deletions

30
resources/js/app.js Normal file
View File

@ -0,0 +1,30 @@
require('./bootstrap');
var autocomplete = require('jquery-ui/ui/widgets/autocomplete');
$(document).ready(function() {
$('form:first').find('*').filter(':input:visible:first').focus();
$('.dropdown-submenu>a').on("click", function(e) {
$(this).next('ul').toggle();
e.stopPropagation();
e.preventDefault();
});
});
require('./jquery.filterTable');
require('./binaryIndexOf');
require('jquery.rut');
String.prototype.ucwords = function() {
str = this.toLowerCase();
return str.replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,
function(s) {
return s.toUpperCase();
});
};
require('./chart');
window.zxcvbn = require('zxcvbn');

View File

@ -0,0 +1,28 @@
function binaryIndexOf(searchElement) {
'use strict';
var minIndex = 0;
var maxIndex = this.length - 1;
var currentIndex;
var currentElement;
var resultIndex;
while (minIndex <= maxIndex) {
resultIndex = currentIndex = (minIndex + maxIndex) / 2 | 0;
currentElement = this[currentIndex];
if (currentElement < searchElement) {
minIndex = currentIndex + 1;
}
else if (currentElement > searchElement) {
maxIndex = currentIndex - 1;
}
else {
return currentIndex;
}
}
return ~maxIndex;
}
Array.prototype.binaryIndexOf = binaryIndexOf;

11
resources/js/bootstrap.js vendored Normal file
View File

@ -0,0 +1,11 @@
/**
* We'll load jQuery and the Bootstrap jQuery plugin which provides support
* for JavaScript based Bootstrap features such as modals and tabs. This
* code may be modified to fit the specific needs of your application.
*/
window.$ = window.jQuery = require('jquery');
require('bootstrap');
require('bootstrap-3-typeahead');

2
resources/js/chart.js Normal file
View File

@ -0,0 +1,2 @@
window.Chart = require('chart.js');
require('chartjs-plugin-barchart-background');

View File

@ -0,0 +1,68 @@
(function($) {
$.fn.filterTable = function(options)
{
var input = this;
var excludeFilter = function(row, col, headers, excludes) {
var exclude = false;
var cols = $(headers.get(row)).find('th');
if (excludes.indexOf($(cols.get(col)).html().toUpperCase()) > -1) {
exclude = true;
}
return exclude;
}
this.keyup(function(e) {
var settings = $.extend({
"table": "filteredTable",
"excludes": [],
"height": 1
}, options);
var id_table = settings.table;
var excludes = settings.excludes;
var height = settings.height;
for (i = 0; i < excludes.length; i ++) {
excludes[i] = excludes[i].toUpperCase();
}
var filter = input.val().toUpperCase();
var table = $('#' + id_table);
var rows = table.find('tbody tr');
var headers = table.find('thead tr');
if (filter == '') {
rows.css('display', '');
return;
}
for (i = 0; i < rows.length; i += height) {
var cols;
var found = false;
for (n = 0; n < height; n ++) {
cols = $(rows.get(i + n)).find('td');
$.each(cols, function(j, e) {
if (excludeFilter(n, j, headers, excludes)) {
return;
}
if ($(this).html().toUpperCase().indexOf(filter) > -1) {
found = true;
}
});
}
if (found) {
for (n = 0; n < height; n ++) {
$(rows.get(i + n)).css('display', '');
}
} else {
for (n = 0; n < height; n ++) {
$(rows.get(i + n)).css('display', 'none');
}
}
}
});
return this;
}
}(jQuery));

View File

@ -0,0 +1,233 @@
<?php
namespace App\Controller;
use App\Service\DBToModel;
use App\Definition\Controller;
use Incoviba\common\Action;
class Admin
{
use Controller;
protected static function setDefault()
{
self::$default = view('admin.base');
}
public static function models()
{
$data = config('databases');
$databases = array_keys($data);
return view('admin.models', compact('databases'));
}
public static function listModels()
{
$db = post('database');
$modeler = new DBToModel($db);
echo $modeler->list();
}
public static function listNamespaces()
{
$base = [
'Common',
'Inmobiliaria',
'Proyecto',
'Venta'
];
$nss = [
'Incoviba' => [
'old' => $base,
'new' => $base
]
];
echo json_encode(['namespaces' => self::collapseMultiArray($nss)]);
}
protected static function collapseMultiArray($array, $level = '')
{
$output = [];
foreach ($array as $key => $subarray) {
if (is_array($subarray)) {
$output = array_merge($output, self::collapseMultiArray($subarray, $level . '\\' . $key));
} else {
$output []= $level . '\\' . $subarray;
}
}
return $output;
}
public static function createModel()
{
$db = post('database');
$ns = post('namespace');
$table = post('table');
$modeler = new DBToModel($db);
echo $modeler->create($ns, $table);
}
public static function list_roles()
{
$roles = \Model::factory(\Incoviba\common\Role::class)->findMany();
echo view('admin.roles.list', compact('roles'));
}
public static function add_role()
{
echo view('admin.roles.add');
}
public static function do_add_role()
{
$role = \Model::factory(\Incoviba\common\Role::class)->where('description', post('description'))->findOne();
if ($role === false) {
$role = \Model::factory(\Incoviba\common\Role::class)->create(['description' => post('description')]);
$role->save();
}
header('Location: ' . nUrl('admin', 'add_role'));
}
public static function role()
{
$role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role'));
$actions = model(Action::class)->orderByAsc('description')->findMany();
$permissions = [];
foreach ($actions as $action) {
$permissions []= (object) ['description' => $action->description, 'status' => false, 'inherited' => false];
}
array_walk($permissions, function(&$el, $i, $role) {
if ($role->checkAccess($el->description)) {
$el->status = true;
if ($role->isInherited($el->description)) {
$el->inherited = true;
}
}
}, $role);
echo view('admin.roles.show', compact('role', 'permissions'));
}
public static function add_role_permissions()
{
$role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role'));
$locations = \Model::factory(\Incoviba\common\Location::class)->findMany();
$actions = model(\Incoviba\common\Action::class)->findMany();
echo view('admin.roles.add_permissions', compact('role', 'locations', 'actions'));
}
public static function do_add_role_permissions()
{
$role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role'));
$actions = model(\Incoviba\common\Action::class)->findMany();
foreach ($actions as $action) {
$p = \Model::factory(\Incoviba\common\Permission::class)->where('type', 2)->where('ext_id', $role->id)->where('action_id', $action->id)->findOne();
if (array_search($action->id, post('allowed'))) {
if (!$p) {
$data = [
'type' => 2,
'ext_id' => $role->id,
'action_id' => $action->id
];
$p = model(\Incoviba\common\Permission::class)->create($data);
}
$p->status = 1;
} else {
if ($p !== false) {
$p->status = 0;
}
}
if ($p !== false) {
$p->save();
}
}
header('Location: ' . nUrl('admin', 'role', ['role' => $role->id]));
}
public static function list_users()
{
$users = \Model::factory(\Incoviba\common\User::class)->orderByAsc('name')->findMany();
echo view('admin.users.list', compact('users'));
}
public static function add_user()
{
echo view('admin.users.add');
}
public static function do_add_user()
{
$user = \Model::factory(\Incoviba\common\User::class)->where('name', post('name'))->findOne();
if ($user === false) {
$user = \Model::factory(\Incoviba\common\User::class)->create();
$user->name = post('name');
$user->password(post('password'));
$user->save();
}
header('Location: ' . url('', ['p' => 'admin', 'a' => 'add_user']));
}
public static function user()
{
$user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user'));
echo view('admin.users.show', compact('user'));
}
public static function add_user_role()
{
if (get('user') !== false) {
$user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user'));
$roles = \Model::factory(\Incoviba\common\Role::class)->findMany();
return view('admin.users.add_role', compact('user', 'roles'));
} elseif (get('role') !== false) {
$role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role'));
$users = \Model::factory(\Incoviba\common\User::class)->findMany();
return view('admin.roles.add_users', compact('users', 'role'));
}
}
public static function do_add_user_role()
{
if (get('user') !== false) {
$user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user'));
foreach (post('role') as $r_id) {
$role = \Model::factory(\Incoviba\common\Role::class)->findOne($r_id);
$usrRl = \Model::factory(\Incoviba\common\UserRole::class)->where('user', $user->id)->where('role', $role->id)->findOne();
if ($usrRl === false) {
$usrRl = \Model::factory(\Incoviba\common\UserRole::class)->create(['user' => $user->id, 'role' => $role->id]);
$usrRl->save();
}
}
header('Location: ' . url('', ['p' => 'admin', 'a' => 'user', 'user' => $user->id]));
} elseif (get('role') !== false) {
$role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role'));
foreach (post('users') as $u_id) {
$user = \Model::factory(\Incoviba\common\User::class)->findOne($u_id);
$usrRl = \Model::factory(\Incoviba\common\UserRole::class)->where('user', $user->id)->where('role', $role->id)->findOne();
if ($usrRl === false) {
$usrRl = \Model::factory(\Incoviba\common\UserRole::class)->create(['user' => $user->id, 'role' => $role->id]);
$usrRl->save();
}
}
header('Location: ' . url('', ['p' => 'admin', 'a' => 'role', 'role' => $role->id]));
}
}
public static function remove_user_role()
{
$q = "DELETE FROM user_roles WHERE user = ? AND role = ?";
$st = \ORM::getDb()->prepare($q);
$st->execute([get('user'), get('role')]);
header('Location: ' . nUrl('admin'));
}
public static function delete_user()
{
$q = "DELETE FROM user_roles WHERE user = ?";
$st = \ORM::getDb()->prepare($q);
$st->execute([get('user')]);
$q = "DELETE FROM logins WHERE user = ?";
$st = \ORM::getDb()->prepare($q);
$st->execute([get('user')]);
$q = "DELETE FROM permissions WHERE type = 1 AND ext_id = ?";
$st = \ORM::getDb()->prepare($q);
$st->execute([get('user')]);
$user = \model(\Incoviba\common\User::class)->findOne(get('user'));
$user->delete();
header('Location: ' . nUrl('admin', 'list_users'));
}
public static function reset_user()
{
$user = model(\Incoviba\common\User::class)->findOne(get('user'));
$user->password('123456');
$user->save();
header('Location: ' . nUrl('admin', 'user', ['user' => $user->id]));
}
}
?>

View File

@ -0,0 +1,215 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Propietario;
use Incoviba\old\Common\Direccion;
use Incoviba\old\Inmobiliaria\Inmobiliaria;
class Ajax
{
use Controller;
protected static function setDefault()
{
self::$default = '';
}
public static function buscar()
{
$t = get('t');
if ($t == null) {
$t = get('tipo');
if ($t == null) {
return '';
}
}
$method = 'buscar' . str_replace(' ', '', ucwords(str_replace('_', ' ', $t)));
if (is_callable('self', $method)) {
return self::$method();
}
}
protected static function buscarBancos()
{
$bancos = \Model::factory(\Incoviba\old\Common\Banco::class)->whereNotEqual('nombre', '')->order_by_asc('nombre')->findMany();
foreach ($bancos as &$banco) {
$banco = $banco->as_array('nombre')['nombre'];
}
return json_encode($bancos);
}
protected static function buscarBanco()
{
$q = get('q');
if ($q == null) {
$q = get('query');
if ($q == null) {
return '';
}
}
$bancos = \Model::factory(\Incoviba\old\Common\Banco::class)->whereLike('nombre', '%' . $q . '%')->order_by_asc('nombre')->findMany();
foreach ($bancos as &$banco) {
$banco = $banco->as_array('nombre')['nombre'];
}
return json_encode($bancos);
}
public static function comunas()
{
$id = post('region');
$comunas = \Model::factory(\Incoviba\old\Common\Comuna::class)
->select('comuna.*')
->join('provincia', ['provincia.id', '=', 'comuna.provincia'])
->where('provincia.region', $id)
->order_by_asc('comuna.descripcion')
->findMany();
foreach ($comunas as &$comuna) {
$comuna = $comuna->as_array('id', 'descripcion');
}
return json_encode($comunas);
}
public static function propietario()
{
$id = post('rut');
$propietario = \Model::factory(\Incoviba\old\Venta\Propietario::class)->where('rut', $id)->findOne();
if ($propietario) {
$propietario = $propietario->as_array();
return json_encode($propietario);
}
return null;
}
public static function direccion()
{
$id = post('direccion');
$direccion = \Model::factory(\Incoviba\old\Common\Direccion::class)->findOne($id);
$comuna = $direccion->comuna();
$provincia = $comuna->provincia();
$region = $provincia->region();
$direccion = $direccion->as_array();
$direccion['comuna'] = $comuna->as_array();
$direccion['comuna']['provincia'] = $provincia->as_array();
$direccion['comuna']['provincia']['region'] = $region->as_array();
return json_encode($direccion);
}
public static function tipo_unidades()
{
$id = post('proyecto');
$proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id);
$tipos = $proyecto->tipoUnidades();
foreach ($tipos as &$tipo) {
$tipo = $tipo->as_array();
}
return json_encode($tipos);
}
public static function unidades()
{
$id_proyecto = post('proyecto');
$id_tipo = post('tipo');
$proyecto = model(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id_proyecto);
$unidades = $proyecto->unidadesDisponibles($id_tipo);
foreach ($unidades as &$unidad) {
$tipologia = $unidad->tipologia();
$unidad = $unidad->as_array();
$unidad['tipologia'] = $tipologia->as_array();
if ($tipologia->tipologia()) {
$unidad['tipologia']['tipologia'] = (array) $tipologia->tipologia();
continue;
}
$unidad['tipologia']['tipologia'] = ['descripcion' => $tipologia->abreviacion];
}
return json_encode($unidades);
}
public static function unidades_precios()
{
$proyecto = model(\Incoviba\old\Proyecto\Proyecto::class)->findOne(post('proyecto'));
$unidades = $proyecto->unidades();
usort($unidades, function($a, $b) {
$t = $a->tipo - $b->tipo;
if ($t == 0) {
return (int) $a->descripcion - (int) $b->descripcion;
}
return $t;
});
$output = [];
foreach ($unidades as $u) {
$info = [
'id' => $u->id,
'abreviacion' => $u->abreviacion,
'descripcion' => $u->descripcion,
'valor' => '--'
];
if ($u->precio()) {
$info['valor'] = format('ufs', $u->precio()->valor, null, true);
}
$output []= $info;
}
return json_encode($output);
}
public static function operadores()
{
$id_proyecto = post('proyecto');
$proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id_proyecto);
$operadores = $proyecto->operadores();
foreach ($operadores as &$operador) {
$operador = [
'id' => $operador->id,
'abreviacion' => $operador->abreviacion
];
}
return json_encode($operadores);
}
public static function promociones()
{
$id = post('proyecto');
$proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id);
$promociones = $proyecto->promociones();
foreach ($promociones as &$promocion) {
$promocion = $promocion->as_array();
}
return json_encode($promociones);
}
public static function nombres()
{
$nss = model(Propietario::class)->select('nombres')->orderByAsc('nombres')->findMany();
$nombres = [];
foreach ($nss as $n) {
$ns = explode(' ', $n->nombres);
foreach ($ns as $nombre) {
$nombres []= $nombre;
}
}
$nombres = array_values(array_unique($nombres));
return json_encode($nombres);
}
public static function apellidos()
{
$aps = model(Propietario::class)->select('apellido_paterno')->orderByAsc('apellido_paterno')->findMany();
$apellidos = [];
foreach ($aps as $ap) {
$apellidos []= $ap->apellido_paterno;
}
$aps = model(Propietario::class)->select('apellido_materno')->orderByAsc('apellido_materno')->findMany();
foreach ($aps as $ap) {
$apellidos []= $ap->apellido_paterno;
}
$apellidos = array_values(array_unique($apellidos));
sort($apellidos);
return json_encode($apellidos);
}
public static function calles()
{
$results = model(Direccion::class)->select('calle')->orderByAsc('calle')->findMany();
$calles = [];
foreach ($results as $result) {
$calles []= $result->calle;
}
$calles = array_values(array_unique($calles));
return json_encode($calles);
}
public static function inmobiliarias()
{
$q = post('rut');
$inmobiliaria = model(Inmobiliaria::class)->findOne($q);
return json_encode($inmobiliaria->as_array());
}
}
?>

View File

@ -0,0 +1,56 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use App\Contract\Auth as sAuth;
class Auth
{
use Controller;
public static function login()
{
return view('auth.login');
}
public static function do_login()
{
$name = post('name');
$password = post('password');
$bool = sAuth::login($name, $password);
if ($bool) {
header('Location: .');
} else {
header('Location: ' . url('', ['p' => 'auth', 'a' => 'login']));
}
}
public static function logout()
{
sAuth::logout();
header('Location: .');
}
public static function check_pass()
{
if (\password_verify(post('password'), sAuth::User()->password)) {
return 'OK';
}
return 'KO';
}
public static function change_pass()
{
return view('auth.change_pass');
}
public static function do_change_pass()
{
if (\password_verify(post('old'), sAuth::User()->password)) {
if (post('new') == post('new2')) {
$user = sAuth::User();
$user->password(post('new'));
$user->save();
header('Location: .');
die();
}
}
header('Location: ' . url('', ['p' => 'auth', 'a' => 'change_pass']));
}
}
?>

View File

@ -0,0 +1,57 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Venta;
use Incoviba\old\Venta\BonoPie;
use Incoviba\old\Venta\Pago;
class Bonos
{
use Controller;
public static function add()
{
$id_venta = get('venta');
$venta = model(Venta::class)->findOne($id_venta);
return view('ventas.bonos.add', compact('venta'));
}
public static function do_add()
{
$id_venta = get('venta');
$venta = model(Venta::class)->findOne($id_venta);
if ($venta->bono_pie != 0) {
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
return;
}
$uf = uf($venta->fecha());
$valor = post('valor');
$data = [
'fecha' => $venta->fecha,
'valor' => $valor * $uf->uf->value,
'tipo' => 8,
'uf' => $uf->uf->value
];
$pago = model(Pago::class)->create($data);
$pago->save();
$data = [
'valor' => $valor,
'pago' => $pago->id
];
$bono = model(BonoPie::class)->create($data);
$bono->save();
$venta->bono_pie = $bono->id;
$venta->save();
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
}
public static function edit()
{
$id_venta = get('venta');
$venta = model(Venta::class)->findOne($id_venta);
return view('ventas.bonos.edit', compact('venta'));
}
public static function do_edit()
{
d(post());
}
}

View File

@ -0,0 +1,340 @@
<?php
namespace App\Controller;
use Incoviba\old\Venta\Venta;
use Incoviba\old\Venta\Unidad;
use Incoviba\old\Venta\Propiedad;
class Buscar
{
protected static $tipos = ['cualquiera', 'departamento', 'estacionamiento', 'bodega', 'propietario', 'precio venta', 'proyecto', 'pago', 'unidad'];
public static function index()
{
$results = self::getResults();
$tipos = self::$tipos;
return view('buscar.buscar', compact('tipos', 'results'));
}
public static function ajax()
{
$results = self::getResults();
return json_encode(['results' => $results]);
}
protected static function getResults()
{
$q = get('q');
if ($q == null) {
$q = get('query');
}
$t = get('t');
if ($t == null) {
$t = get('tipo');
}
$t = urldecode($t);
if ($t == null) {
$t = 'cualquiera';
}
$results = null;
if ($q != null) {
$q = urldecode($q);
$results = self::buscar($q, $t);
}
return $results;
}
public static function buscar($query, $tipo)
{
$method = 'buscar' . str_replace(' ', '', ucwords($tipo));
if (is_callable(['self', $method])) {
$results = self::$method(self::prepareQuery($query));
$results = self::removeDuplicates($results);
$results = self::sort($results);
return $results;
}
return [];
}
protected static function prepareQuery($query)
{
$query = str_replace('&#34;', '"', $query);
$data = explode(' ', $query);
$regex = "~(?=\\S)[^'\"\\s]*(?:'[^']*'[^'\"\\s]*|\"[^\"]*\"[^'\"\\s]*)*~";
preg_match_all($regex, $query, $data);
$data = $data[0];
foreach ($data as &$l) {
$l = str_replace('"', '', str_replace("'", '', $l));
}
if (is_array($data) and count($data) == 1) {
$data = $data[0];
}
return $data;
}
protected static function removeDuplicates($results)
{
$output = [];
foreach ($results as $result) {
if (array_search($result, $output) === false) {
$output []= $result;
}
}
return $output;
}
protected static function sort($results)
{
usort($results, function($a, $b) {
$py = strcmp($a->proyecto()->descripcion, $b->proyecto()->descripcion);
if ($py == 0) {
if (!method_exists($a, 'unidad') and !method_exists($b, 'unidad')) {
return $a->descripcion - $b->descripcion;
}
if (!method_exists($a, 'unidad')) {
return $a->descripcion - $b->unidad()->descripcion;
}
if (!method_exists($b, 'unidad')) {
return $a->unidad()->descripcion - $b->descripcion;
}
$u = $a->unidad()->descripcion - $b->unidad()->descripcion;
if ($u == 0) {
return strcmp($a->propietario()->apellido_paterno, $b->propietario()->apellido_paterno);
}
return $u;
}
return $py;
});
return $results;
}
protected static function buscarCualquiera($query)
{
$results = [];
foreach (self::$tipos as $tipo) {
if ($tipo == 'cualquiera') {
continue;
}
$method = 'buscar' . str_replace(' ', '', ucwords($tipo));
if (is_callable(['self', $method])) {
$results = array_merge($results, self::$method($query));
}
}
return $results;
}
protected static function buscarDepartamento($query)
{
if (is_array($query)) {
$results = [];
foreach ($query as $segment) {
$results = array_merge($results, self::buscarDepartamento($segment));
}
} else {
$results = \Model::factory(Venta::class)
->select('venta.*')
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
->whereLike('unidad.descripcion', '%' . $query . '%')
->findMany();
}
return $results;
}
protected static function buscarEstacionamiento($query)
{
if (is_array($query)) {
$results = [];
foreach ($query as $segment) {
$results = array_merge($results, self::buscarEstacionamiento($segment));
}
} else {
$results = \Model::factory(Venta::class)
->select('venta.*')
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
->join('unidad', "`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('unidad.descripcion', $query)
->findMany();
}
return $results;
}
protected static function buscarBodega($query)
{
if (is_array($query)) {
$results = [];
foreach ($query as $segment) {
$results = array_merge($results, self::buscarBodega($segment));
}
} else {
$results = \Model::factory(Venta::class)
->select('venta.*')
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
->join('unidad', "`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('unidad.descripcion', $query)
->findMany();
}
return $results;
}
protected static function buscarPropietario($query)
{
if (is_array($query)) {
$results = [];
foreach ($query as $segment) {
$results = array_merge($results, self::buscarPropietario($segment));
}
} else {
$results = self::buscarPropietarioNombres($query);
$results = array_merge($results, self::buscarPropietarioApellido($query));
$results = array_merge($results, self::buscarPropietarioNombreCompleto($query));
}
return $results;
}
protected static function buscarPropietarioNombres($query)
{
$results = \Model::factory(Venta::class)
->select('venta.*')
->join('propietario', ['propietario.rut', '=', 'venta.propietario'])
->whereLike('propietario.nombres', '%' . $query . '%')
->findMany();
return $results;
}
protected static function buscarPropietarioApellido($query)
{
$results = \Model::factory(Venta::class)
->select('venta.*')
->join('propietario', ['propietario.rut', '=', 'venta.propietario'])
->whereAnyIs([
['propietario.apellido_paterno' => '%' . $query . '%'],
['propietario.apellido_materno' => '%' . $query . '%']
], 'LIKE')
->findMany();
return $results;
}
protected static function buscarPropietarioNombreCompleto($query)
{
$results = \Model::factory(Venta::class)
->select('venta.*')
->join('propietario', ['propietario.rut', '=', 'venta.propietario'])
->whereRaw("CONCAT_WS(' ', propietario.nombres, propietario.apellido_paterno, propietario.apellido_materno) LIKE '%" . $query . "%'")
->findMany();
return $results;
}
protected static function buscarPrecioVenta($query)
{
if (is_array($query)) {
$results = [];
foreach ($query as $segment) {
$results = array_merge($results, self::buscarPrecioVenta($segment));
}
} else {
$query = str_replace([',', '.'], ['.', ''], $query);
$results = \Model::factory(Venta::class)->where('valor_uf', $query)->findMany();
}
return $results;
}
protected static function buscarProyecto($query)
{
if (is_array($query)) {
$results = [];
foreach ($query as $segment) {
$results = array_merge($results, self::buscarProyecto($segment));
}
} else {
$results = model(Venta::class)
->select('venta.*')
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
->join('proyecto', ['proyecto.id', '=', 'unidad.proyecto'])
->whereLike('proyecto.descripcion', '%' . $query . '%')
->findMany();
}
return $results;
}
protected static function buscarPago($query)
{
if (is_array($query)) {
$results = [];
foreach ($query as $segment) {
$results = array_merge($results, self::buscarPrecioVenta($segment));
}
} else {
$query = str_replace(',', '.', str_replace('.', '', $query));
$query2 = (float) $query;
if ($query != $query2) {
return [];
}
if (!is_float($query2)) {
return [];
}
$query = $query2;
$results = self::buscarValorCuota($query);
$results = array_merge($results, self::buscarReajuste($query));
$results = array_merge($results, self::buscarEscritura($query));
$results = array_merge($results, self::buscarSubsidio($query));
$results = array_merge($results, self::buscarCredito($query));
}
return $results;
}
protected static function buscarValorCuota($query)
{
$results = \Model::factory(Venta::class)
->select('venta.*')
->join('cuota', ['cuota.pie', '=', 'venta.pie'])
->join('pago', ['pago.id', '=', 'cuota.pago'])
->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query)
->findMany();
return $results;
}
protected static function buscarReajuste($query)
{
$results = \Model::factory(Venta::class)
->select('venta.*')
->join('pie', ['pie.id', '=', 'venta.pie'])
->join('pago', ['pago.id', '=', 'pie.reajuste'])
->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query)
->findMany();
return $results;
}
protected static function buscarEscritura($query)
{
$results = \Model::factory(Venta::class)
->select('venta.*')
->join('escritura', ['escritura.id', '=', 'venta.escritura'])
->join('pago', ['pago.id', '=', 'escritura.pago'])
->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query)
->findMany();
return $results;
}
protected static function buscarSubsidio($query)
{
$results = \Model::factory(Venta::class)
->select('venta.*')
->join('subsidio', ['subsidio.id', '=', 'venta.subsidio'])
->join('pago', ['pago.id', '=', 'subsidio.pago'])
->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query)
->findMany();
return $results;
}
protected static function buscarCredito($query)
{
$results = \Model::factory(Venta::class)
->select('venta.*')
->join('credito', ['credito.id', '=', 'venta.credito'])
->join('pago', ['pago.id', '=', 'credito.pago'])
->whereRaw("`pago`.`valor` = " . $query . " OR `pago`.`valor` / `pago`.`uf` = " . $query)
->findMany();
return $results;
}
protected static function buscarUnidad($query)
{
if (is_array($query)) {
$results = [];
foreach ($query as $segment) {
$results = array_merge($results, self::buscarUnidad($segment));
}
} else {
$results = model(Unidad::class)->where('descripcion', $query)->findMany();
foreach ($results as $i => $u) {
if ($u->venta()) {
unset($results[$i]);
}
}
}
return $results;
}
}
?>

View File

@ -0,0 +1,428 @@
<?php
namespace App\Controller;
use Carbon\Carbon;
use App\Definition\Controller;
use App\Service\Borrador;
use App\Service\Factory;
use Incoviba\old\Common\Direccion;
use Incoviba\old\Common\Region;
use Incoviba\old\Proyecto\Agente;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Venta\Propietario;
use Incoviba\old\Venta\Unidad;
use Incoviba\old\Venta\Cierre;
use Incoviba\old\Venta\EstadoCierre;
use Incoviba\nuevo\Venta\Precio;
use Incoviba\nuevo\Venta\Reserva;
use Incoviba\old\Venta\TipoEstadoCierre;
use Incoviba\old\Venta\TipoValorCierre;
use Incoviba\nuevo\Venta\UnidadReserva;
use Incoviba\old\Venta\Unidad as U;
class Cierres
{
use Controller;
public static function add()
{
$proyectos = model(Proyecto::class)
->select('proyecto.*')
->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado')
->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo')
->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa')
->whereGte('etapa.orden', 3)
->orderByAsc('proyecto.descripcion')
->groupBy('proyecto.id')
->findMany();
$regiones = model(Region::class)->order_by_asc('numeracion')->findMany();
return view('ventas.cierres.add', compact('proyectos', 'regiones'));
}
public static function agregar()
{
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$id_proyecto = post('proyecto');
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
$id_agente = post('agente');
$agente = model(Agente::class)->findOne($id_agente);
$direccion = model(Direccion::class)
->where('calle', post('calle'))
->where('numero', post('numero'))
->where('extra', post('extra'))
->where('comuna', post('comuna'))
->findOne();
if (!$direccion) {
$data = [
'calle' => post('calle'),
'numero' => post('numero'),
'extra' => post('extra'),
'comuna' => post('comuna')
];
$direccion = model(Direccion::class)->create($data);
$direccion->save();
}
list($rut, $dv) = explode('-', str_replace('.', '', post('rut')));
$propietario = model(Propietario::class)->findOne($rut);
if (!$propietario) {
$data = [
'rut' => $rut,
'dv' => $dv,
'nombres' => trim(post('nombres')),
'apellido_paterno' => post('paterno'),
'apellido_materno' => post('materno'),
'sexo' => post('sexo'),
'estado_civil' => post('estado_civil'),
'profesion' => post('profesion'),
'direccion' => $direccion->id,
'telefono' => post('codigo_telefono') . post('telefono'),
'email' => post('email') . '@' . post('email_domain'),
'representante' => 0,
'otro' => 0
];
$propietario = model(Propietario::class)->create($data);
$propietario->save();
}
$unis = json_decode(post('unidades'));
$id_principal = array_shift($unis);
$unidad = model(Unidad::class)->findOne(post('unidad' . $id_principal));
$u = model(U::class)->findOne($unidad->id);
if (!$u) {
$unidad->save();
}
$data = [
'unidad_id' => $unidad->id
];
$reserva = model(Reserva::class)->create($data);
$reserva->save();
foreach ($unis as $id_unidad) {
$unidad = model(Unidad::class)->findOne(post('unidad' . $id_unidad));
$data = [
'reserva_id' => $reserva->id,
'unidad_id' => $unidad->id
];
$ur = model(UnidadReserva::class)->create($data);
$ur->save();
}
$data = [
'proyecto_id' => $proyecto->id,
'agente_id' => $agente->id,
'propietario_rut' => $propietario->rut,
'reserva_id' => $reserva->id,
'fecha' => $f->format('Y-m-d'),
'valor' => correctNumber(post('valor')),
'pie' => correctNumber(post('pie')),
'credito' => correctNumber(post('credito')),
'estado' => 1
];
$cierre = model(Cierre::class)->create($data);
$cierre->save();
header('Location: ' . url('', ['p' => 'cierres', 'a' => 'list']));
}
public static function list()
{
$proyectos = Cierre::proyectos();
return view('ventas.cierres.list', compact('proyectos'));
}
public static function show()
{
$id = get('cierre');
$cierre = model(Cierre::class)->findOne($id);
return view('ventas.cierres.show', compact('cierre'));
}
public static function guardar()
{
$proyecto = \model(Proyecto::class)->findOne(post('proyecto'));
$fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$unidad = \model(Unidad::class)->findOne(post('departamento'));
$relacionado = (post('relacionado') === true) ? true : false;
$subrelacionado = (post('subrelacionado') === true) ? true : false;
$precio = (float) post('precio') ?: 0;
$input = [
'proyecto' => $proyecto,
'fecha' => $fecha,
'departamento' => $unidad,
'precio' => $precio,
'relacionado' => $relacionado,
'subrelacionado' => $subrelacionado,
'unidades' => [],
'pie' => (float) post('pie')
];
$ebs = 0;
if (post('unidades') != '') {
$unidades = json_decode(html_entity_decode(post('unidades')), true);
foreach ($unidades as $un) {
$u = \model(Unidad::class)->findOne($un);
$input['unidades'] []= $u;
if ($u->precio($fecha) !== false) {
$ebs += $u->precio($fecha)->valor;
}
}
}
$promo = 0;
if (post('promocion') != null) {
$promo = (float) post('promocion');
$input['promocion'] = $promo;
}
$bono = 0;
if (post('bono') != null) {
$bono = (float) post('bono');
$input['bono'] = $bono;
}
$operador = 0;
if (post('operador') != null) {
$operador = ($precio - $bono - $promo) * (float) post('operador') / 100;
$input['operador'] = $operador;
}
$cierre = Cierre::find($proyecto, $unidad, $precio)->findOne();
if ($cierre === false) {
$cierre = model(Cierre::class)->create();
$cierre->guardar((object) $input);
}
$output = ['status' => 'ok', 'cierre' => $cierre->asArray()];
return json_encode($output);
}
public static function aprobar()
{
$fecha = Carbon::today(config('app.timezone'));
$cierre = model(Cierre::class)->findOne(post('cierre'));
if ($cierre->estado()->tipo()->descripcion == "revisado" or $cierre->estado()->tipo()->descripcion == "rechazado") {
$cierre->aprobar($fecha);
return json_encode(['estado' => 'aprobado']);
}
return json_encode(['estado' => 'no vigente']);
}
public static function rechazar()
{
$fecha = Carbon::today(config('app.timezone'));
$cierre = model(Cierre::class)->findOne(post('cierre'));
if ($cierre->estado()->tipo()->vigente == 1) {
$cierre->rechazar($fecha);
return json_encode(['estado' => 'rechazado']);
}
return json_encode(['estado' => 'no vigente']);
}
public static function abandonar()
{
$id = get('cierre');
$cierre = model(Cierre::class)->findOne($id);
$tipo = model(TipoEstadoCierre::class)->where('descripcion', 'abandonado')->findOne();
$today = Carbon::today(config('app.timezone'));
$data = [
'cierre' => $cierre->id,
'tipo' => $tipo->id,
'fecha' => $today->format('Y-m-d')
];
$estado = model(EstadoCierre::class)->create($data);
$estado->save();
header('Location: ' . url('', ['p' => 'cierres', 'a' => 'list']));
}
public static function promesar()
{
$id = get('cierre');
$cierre = model(Cierre::class)->findOne($id);
$tipo = model(TipoEstadoCierre::class)->where('descripcion', 'promesado')->findOne();
$today = Carbon::today(config('app.timezone'));
$data = [
'cierre' => $cierre->id,
'tipo' => $tipo->id,
'fecha' => $today->format('Y-m-d')
];
$estado = model(EstadoCierre::class)->create($data);
$estado->save();
header('Location: ' . url('', ['p' => 'cierres', 'a' => 'show', 'cierre' => $cierre->id]));
}
public static function borrador()
{
$id = get('cierre');
$cierre = model(Cierre::class)->findOne($id);
$borrador = new Borrador($cierre);
d($borrador->show());
$borrador->create();
}
public static function evalue()
{
$proyectos = \model(Proyecto::class)->orderByAsc('descripcion')->findMany();
return view('ventas.cierres.evaluar', compact('proyectos'));
}
public static function evaluar()
{
$proyecto = \model(Proyecto::class)->findOne(post('proyecto'));
$fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$unidad = \model(Unidad::class)->findOne(post('departamento'));
$relacionado = (post('relacionado') === 'true') ? true : false;
$subrelacionado = (post('subrelacionado') === 'true') ? true : false;
$precio = (float) post('precio') ?: 0;
$neto = $precio;
$ebs = 0;
if (post('unidades') != '') {
$unidades = json_decode(html_entity_decode(post('unidades')), true);
foreach ($unidades as $un) {
$u = \model(Unidad::class)->findOne($un);
if ($u->precio($fecha) !== false) {
$ebs += $u->precio($fecha)->valor;
}
}
}
$promocion = 0;
if (post('promocion') != null) {
$promocion = (float) post('promocion');
}
$bono = 0;
if (post('bono') != null) {
$bono = (float) post('bono');
}
$operador = 0;
if (post('operador') != null) {
$operador = ($precio - $bono - $promocion) * (float) post('operador') / 100;
}
$rel = 0;
if ($relacionado) {
$rel = ($unidad->precio($fecha)->valor) * 6 / 100;
}
if ($subrelacionado) {
$rel = ($unidad->precio($fecha)->valor) * 3 / 100;
}
$neto = $precio - $bono - $promocion - $operador - $ebs;
$output = [
'unidad' => [
'tipo' => [
'nombre' => $unidad->tipologia()->nombre,
'tipologia' => $unidad->tipologia()->tipologia()->descripcion
],
'superficie' => format('m2', $unidad->m2()) . ' m&#0178;'
],
'oferta' => [
'bruto' => format('ufs', $precio, null, true),
'neto' => format('ufs', $neto, null, true),
'uf_m2' => format('ufs', $neto / $unidad->m2('vendible'), null, true) . '/m&#0178;',
'fecha' => format('shortDate', $unidad->precio($fecha)->inicio()->fecha())
],
'lista' => [
'precio' => format('ufs', $unidad->precio($fecha)->valor, null, true),
'uf_m2' => format('ufs', $unidad->precio($fecha)->valor / $unidad->m2('vendible'), null, true) . '/m&#0178;'
],
'precios' => [
'bruto' => format('ufs', $precio, null, true),
'neto' => format('ufs', $neto, null, true),
'departamento' => format('ufs', $unidad->precio($fecha)->valor, null, true),
'relacionado' => format('ufs', $unidad->precio($fecha)->valor - $rel, null, true),
'fecha' => format('shortDate', $unidad->precio($fecha)->inicio()->fecha())
],
'uf_m2' => [
'neto' => format('ufs', $neto / $unidad->m2('vendible'), null, true) . '/m&#0178;',
'departamento' => format('ufs', $unidad->precio($fecha)->valor / $unidad->m2('vendible'), null, true) . '/m&#0178;',
'relacionado' => format('ufs', ($unidad->precio($fecha)->valor - $rel) / $unidad->m2('vendible'), null, true) . '/&#0178;'
],
'evaluacion' => Cierre::evaluar($neto, $unidad, $fecha, $rel),
'estado' => ['id' => 0, 'descripcion' => 'no existe']
];
if ($rel > 0) {
$output ['relacionado'] = [
'precio' => format('ufs', $unidad->precio($fecha)->valor - $rel, null, true),
'uf_m2' => format('ufs', ($unidad->precio($fecha)->valor - $rel) / $unidad->m2('vendible'), null, true) . '/&#0178;'
];
}
$estado = Cierre::find($proyecto, $unidad, $precio)->findOne();
if ($estado) {
$output['estado'] = [
'id' => $estado->estado()->tipo()->id,
'cierre' => $estado->id,
'descripcion' => $estado->estado()->tipo()->descripcion,
'fecha' => format('shortDate', $estado->estado()->fecha)
];
}
return json_encode($output);
}
public static function edit()
{
$cierre = model(Cierre::class)->findOne(get('cierre'));
$proyectos = model(Proyecto::class)->findMany();
$regiones = model(Region::class)->findMany();
$valores = model(TipoValorCierre::class)->findMany();
return view('ventas.cierres.edit', compact('cierre', 'proyectos', 'regiones', 'valores'));
}
public static function do_edit()
{
$cierre = model(Cierre::class)->findOne(get('cierre'));
$data = [
'calle' => post('calle'),
'numero' => post('numero'),
'extra' => post('extra'),
'comuna' => post('comuna')
];
$direccion = (new Factory(Direccion::class))->where($data)->find();
if (!$direccion) {
$direccion = model(Direccion::class)->create($data);
$direccion->save();
}
if (post('rut') != '') {
$data = [
'rut' => explode('-', str_replace('.', '', post('rut')))[0],
];
$propietario = (new Factory(Propietario::class))->where($data)->find();
if (!$propietario) {
$data = array_merge($data, [
'nombres' => post('nombres'),
'apellido_paterno' => post('paterno'),
'apellido_materno' => post('materno'),
'dv' => (post('rut')) ? explode('-', str_replace('.', '', post('rut')))[1] : '',
'sexo' => post('sexo'),
'estado_civil' => post('estado_civil'),
'profesion' => post('profesion'),
'telefono' => post('codigo_telefono') . post('telefono'),
'email' => post('email') . '@' . post('email_domain'),
'direccion' => $direccion->id
]);
$propietario = model(Propietario::class)->create($data);
$propietario->save();
}
}
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$data = [
'proyecto' => post('proyecto'),
'precio' => post('precio'),
'fecha' => $f->format('Y-m-d'),
'relacionado' => (post('relacionado')) ? 1 : 0,
'propietario' => (isset($propietario) and $propietario) ? $propietario->rut : 0
];
foreach ($data as $field => $value) {
if ($value != $cierre->$field) {
$cierre->$field = $value;
}
}
$cierre->save();
$valores = model(TipoValorCierre::class)->findMany();
foreach ($valores as $valor) {
if (post($valor->descripcion) == '') {
continue;
}
if ($cierre->valor($valor->descripcion)) {
if ($cierre->valor($valor->descripcion)->valor != post($valor->descripcion)) {
$v = $cierre->valor($valor->descripcion);
$v->valor = post($valor->descripcion);
$v->save();
}
continue;
}
$data = [
'tipo' => $valor->descripcion,
'valor' => post($valor->descripcion)
];
$cierre->addValor($data);
}
header('Location: ' . nUrl('cierres', 'show', ['cierre' => $cierre->id]));
}
}
?>

View File

@ -0,0 +1,39 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
class Comentarios
{
use Controller;
public static function add()
{
$venta = \Model::factory(\Incoviba\old\Venta\Venta::class)->findOne(get('venta'));
echo view('ventas.comentarios.add', compact('venta'));
}
public static function agregar()
{
$venta = \Model::factory(\Incoviba\old\Venta\Venta::class)->findOne(get('venta'));
if ($venta === false) {
throw new Exception('Venta no existe.');
}
$data = [
'venta' => $venta->id,
'fecha' => \Carbon\Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'),
'texto' => post('comentario')
];
$comentario = \Model::factory(\Incoviba\old\Venta\Comentario::class)->create($data);
$comentario->save();
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
}
public static function delete()
{
$comentario = \Model::factory(\Incoviba\old\Venta\Comentario::class)->findOne(get('comentario'));
$venta = $comentario->venta();
$comentario->estado = 0;
$comentario->save();
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
}
}
?>

View File

@ -0,0 +1,102 @@
<?php
namespace App\Controller;
use Carbon\Carbon;
use App\Definition\Controller;
use Incoviba\old\Proyecto\Proyecto;
class Contabilidad {
use Controller;
/**
* Obtener Proyecto y fecha
* Listar Proyectos y fechas
* Listar pagos realizados en esa fecha para detalle de contabilidad
*/
public static function get_proyectos() {
$proyectos = model(Proyecto::class)->orderByAsc('descripcion')->findMany();
foreach ($proyectos as &$proyecto) {
$arr = $proyecto->asArray();
$arr['direccion'] = $proyecto->direccion()->asArray();
$arr['direccion']['comuna'] = $proyecto->direccion()->comuna()->asArray();
$arr['inmobiliaria'] = $proyecto->inmobiliaria()->asArray();
$proyecto = $arr;
}
return json_encode(compact('proyectos'));
}
public static function get_fechas() {
$id_proyecto = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
$cuotas = [];
foreach ($proyecto->ventas() as $venta) {
$cs = $venta->pie()->cuotas();
$cuotas = array_merge($cs, array_filter($cs, function($item) {
$tipo = $item->pago()->estado()->tipo();
return ($tipo == 'depositado' or $tipo == 'abonado');
}));
}
$fechas = array_map(function($item) {
return [
'timestamp' => $item->pago()->estado()->fecha()->timestamp,
'short' => $item->pago()->estado()->fecha()->format('Y-m-d'),
'long' => $item->pago()->estado()->fecha()->format('d / m / Y')
];
}, $cuotas);
usort($fechas, function($a, $b) {
return $b['timestamp'] - $a['timestamp'];
});
return json_encode(compact('fechas'));
}
public static function get_pagos_fechas() {
$id_proyecto = get('proyecto');
$fecha = Carbon::parse(get('fecha'));
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
$pagos = [];
foreach ($proyecto->ventas() as $venta) {
foreach ($venta->pie()->cuotas() as $cuota) {
if ($cuota->pago()->estado()->fecha() == $fecha) {
$pagos []= [
'Departamento' => $venta->propiedad()->unidad()->descripcion,
'Valor' => [
'UF' => $cuota->pago()->valor('ufs'),
'Pesos' => $cuota->pago()->valor()
],
'Numero' => $cuota->numero(),
'Total' => $venta->pie()->cuotas
];
break;
}
}
}
return json_encode(compact('pagos'));
}
public static function pagos_fecha() {
$fecha = Carbon::now();
return view('contabilidad.pagos', compact('fecha'));
}
public static function show_pagos() {
$id_proyecto = get('proyecto');
$fecha = Carbon::parse(get('fecha'));
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
$pagos = [];
!d($fecha);
foreach ($proyecto->ventas() as $venta) {
foreach ($venta->pie()->cuotas() as $cuota) {
!d($cuota, $cuota->pago()->estado()->fecha());
if ($cuota->pago()->estado()->fecha() == $fecha) {
$pagos []= (object) [
'Departamento' => $venta->propiedad()->unidad()->descripcion,
'Valor' => (object) [
'UF' => $cuota->pago()->valor('ufs'),
'Pesos' => $cuota->pago()->valor()
],
'Numero' => $cuota->numero(),
'Total' => $venta->pie()->cuotas
];
break;
}
}
}
return view('contabilidad.pago', compact('proyecto', 'fecha', 'pagos'));
}
}

View File

@ -0,0 +1,207 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Venta;
use Incoviba\old\Common\Banco;
use Incoviba\old\Venta\Credito;
use Carbon\Carbon;
use Incoviba\old\Venta\Pago;
use Incoviba\old\Venta\EstadoPago;
class Creditos
{
use Controller;
protected static function setDefault()
{
self::$default = view('construccion');
}
public static function agregar()
{
$id = get('venta');
if ($id == null) {
header('Location: .');
}
$venta = \Model::factory(Venta::class)->findOne($id);
return view('ventas.creditos.add', compact('venta'));
}
public static function agregado()
{
$id = get('venta');
if ($id == null) {
header('Location: .');
}
$venta = \Model::factory(Venta::class)->findOne($id);
$banco = \Model::factory(Banco::class)->where('nombre', post('banco'))->findOne();
$f = Carbon::createFromDate(post('y'), post('m'), post('d'), config('app.timezone'));
$uf = uf($f);
$pago = \Model::factory(Pago::class)->create();
$pago->banco = $banco->id;
$pago->fecha = $f->format('Y-m-d');
$pago->uf = $uf->uf->value;
$pago->valor = post('valor') * $pago->uf;
$pago->tipo = 2;
$credito = \Model::factory(Credito::class)->create();
$credito->banco = $pago->banco;
$credito->valor = $pago->valor;
$credito->fecha = $pago->fecha;
$credito->uf = $pago->uf;
$pago->new();
$credito->pago = $pago->id;
$credito->save();
$venta->credito = $credito->id;
$venta->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function pagar()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
return view('ventas.creditos.pagar', compact('venta'));
}
public static function pagando()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
$valor = str_replace(',', '.', str_replace('.', '', post('valor')));
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$pago = $venta->credito()->pago();
if ($pago->valor != $valor) {
$pago->valor = $valor;
}
$estado = \Model::factory(EstadoPago::class)->create();
$estado->pago = $pago->id;
$estado->fecha = $f->format('Y-m-d');
$estado->estado = 1;
$estado->save();
if ($pago->is_dirty('valor')) {
$pago->save();
}
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function abonar()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
return view('ventas.creditos.abonar', compact('venta'));
}
public static function abonando()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
$valor = str_replace(',', '.', str_replace('.', '', post('valor')));
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$pago = $venta->credito()->pago();
if ($pago->valor != $valor) {
$pago->valor = $valor;
}
$estado = \Model::factory(EstadoPago::class)->create();
$estado->pago = $pago->id;
$estado->fecha = $f->format('Y-m-d');
$estado->estado = 2;
$estado->save();
if ($pago->is_dirty('valor')) {
$pago->save();
}
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function show()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.creditos.show', compact('venta'));
}
public static function edit()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.creditos.edit', compact('venta'));
}
public static function editado()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$pago = $venta->credito()->pago();
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$uf = uf($f);
$banco = model(Banco::class)->where('nombre', post('banco'))->findOne();
$valor = correctNumber(post('valor')) * $uf->uf->value;
$fields = ['valor', 'uf', 'fecha', 'banco'];
$data = ['valor' => $valor, 'uf' => $uf->uf->value, 'fecha' => $f->format('Y-m-d'), 'banco' => $banco->id];
$change = false;
foreach ($fields as $field) {
if ($pago->$field != $data[$field]) {
$change = true;
$pago->$field = $data[$field];
if ($field == 'fecha') {
$eps = $pago->estados();
foreach ($eps as $ep) {
if ($ep->estado == 0) {
$ep->fecha = $data[$field];
$ep->save();
break;
}
}
}
}
}
if ($change) {
$pago->save();
}
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function remove()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$pago = $venta->credito()->pago();
$f = Carbon::today(config('app.timezone'));
$data = [
'pago' => $pago->id,
'estado' => -3,
'fecha' => $f->format('Y-m-d')
];
$estado = model(EstadoPago::class)->create($data);
$estado->save();
$venta->credito = 0;
$venta->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function pendientes()
{
$creditos = model(Credito::class)
->select('credito.*')
->join('venta', ['venta.credito', '=', 'credito.id'])
->join('pago', ['pago.id', '=', 'credito.pago'])
->rawJoin('JOIN (SELECT ep.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago ep ON ep.id = e0.id)', ['estado_pago.pago', '=', 'pago.id'], 'estado_pago')
->whereLt('estado_pago.estado', 2)
->where('venta.estado', 1)
->orderByAsc('estado_pago.fecha')
->findMany();
return view('ventas.creditos.pendientes', compact('creditos'));
}
}
?>

View File

@ -0,0 +1,230 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Cuota;
use Incoviba\old\Venta\EstadoPago;
use Carbon\Carbon;
use Incoviba\old\Venta\Pie;
use Incoviba\old\Venta\Pago;
use Incoviba\old\Common\Banco;
class Cuotas
{
use Controller;
protected static function setDefault()
{
self::$default = view('construccion');
}
public static function show()
{
$id = get('cuota');
$cuota = \Model::factory(Cuota::class)->findOne($id);
return view('ventas.pies.cuotas.show', compact('cuota'));
}
public static function edit()
{
$id = get('cuota');
$cuota = \Model::factory(Cuota::class)->findOne($id);
return view('ventas.pies.cuotas.edit', compact('cuota'));
}
public static function editar()
{
$id = get('cuota');
$cuota = \Model::factory(Cuota::class)->findOne($id);
$cuota->numero = post('numero');
$cuota->{'valor_$'} = post('valor');
$banco = \Model::factory(\Incoviba\old\Common\Banco::class)->where('nombre', post('banco'))->findOne();
if ($banco) {
$cuota->banco = $banco->id;
} else {
$cuota->banco = 0;
}
$f = \Carbon\Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$cuota->fecha = $f->format('Y-m-d');
$pago = $cuota->pago();
$pago->valor = post('valor');
$pago->banco = $banco->id;
$pago->identificador = post('identificador');
$pago->fecha = $f->format('Y-m-d');
$uf = uf($f);
if ($uf->total > 0) {
$pago->uf = $uf->uf->value;
} else {
$pago->uf = 0;
}
$pago->save();
$cuota->save();
header('Location: ' . url('', ['p' => 'pies', 'a' => 'resumen', 'pie' => $cuota->pie()->id]));
}
public static function edited()
{
$id = get('cuota');
$cuota = \Model::factory(Cuota::class)->findOne($id);
$pago = $cuota->pago();
foreach ($_POST as $key => $value) {
$pago->$key = $value;
}
$pago->save();
}
public static function pendientes()
{
$f = \Carbon\Carbon::today(config('app.timezone'));
$cuotas = \Model::factory(Cuota::class)
->select('cuota.*')
->join('pago', ['pago.id', '=', 'cuota.pago'])
->join('venta', ['venta.pie', '=', 'cuota.pie'])
->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('ep.estado', 0)
->where('venta.estado', 1)
->whereLte('pago.fecha', $f->format('Y-m-d'))
->order_by_asc('pago.fecha')
->findMany();
$sum = 0;
if (count($cuotas) > 0) {
$sum = array_reduce($cuotas, function($carry, $item) {
$carry += $item->pago()->valor;
return $carry;
});
}
setlocale(LC_TIME, 'es');
return view('ventas.pies.cuotas.pendientes', compact('cuotas', 'sum'));
}
public static function depositar()
{
$id = post('cuota');
$cuota = \Model::factory(Cuota::class)->findOne($id);
if ($cuota->pago()->estado()->estado == 1) {
return 'ok';
}
$estado = \Model::factory(EstadoPago::class)->create();
$estado->pago = $cuota->pago()->id;
$estado->estado = 1;
$f = Carbon::parse(post('fecha'), config('app.timezone'));
$estado->fecha = $f->format('Y-m-d');
$estado->save();
return 'ok';
}
public static function remove()
{
$id = get('cuota');
$cuota = \Model::factory(Cuota::class)->findOne($id);
$estado = \Model::factory(EstadoPago::class)->create();
$estado->pago = $cuota->pago()->id;
$estado->estado = -3;
$f = Carbon::today(config('app.timezone'));
$estado->fecha = $f->format('Y-m-d');
$estado->save();
header('Location: ' . url('', ['p' => 'pies', 'a' => 'resumen', 'pie' => $cuota->pie()->id]));
}
public static function para_abonar()
{
$cuotas = \Model::factory(Cuota::class)
->select('cuota.*')
->join('pago', ['pago.id', '=', 'cuota.pago'])
->join('venta', ['venta.pie', '=', 'cuota.pie'])
->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('ep.estado', 1)
->where('venta.estado', 1)
->order_by_asc('ep.fecha')
->findMany();
$ini = get('start');
if ($ini == null) {
$ini = 0;
}
$n = get('step');
if ($n == 0) {
$n = 30;
}
$total = count($cuotas);
$cuotas = array_slice($cuotas, $ini, $n);
$pages = ceil($total / $n);
$current = ($ini + $n) / $n;
return view('ventas.pies.cuotas.abonar', compact('cuotas', 'total', 'pages', 'current'));
}
public static function abonar()
{
$id = post('cuota');
$cuota = \Model::factory(Cuota::class)->findOne($id);
if ($cuota->pago()->estado()->estado == 2) {
return 'ok';
}
$estado = \Model::factory(EstadoPago::class)->create();
$estado->pago = $cuota->pago()->id;
$estado->estado = 2;
$f = Carbon::parse(post('fecha'), config('app.timezone'));
$estado->fecha = $f->format('Y-m-d');
$estado->save();
return 'ok';
}
public static function rebotar()
{
$id = post('cuota');
$cuota = \Model::factory(Cuota::class)->findOne($id);
if ($cuota->pago()->estado()->estado == -1) {
return 'ok';
}
$estado = \Model::factory(EstadoPago::class)->create();
$estado->pago = $cuota->pago()->id;
$estado->estado = -1;
$f = Carbon::parse(post('fecha'), config('app.timezone'));
$estado->fecha = $f->format('Y-m-d');
$estado->save();
return 'ok';
}
public static function add()
{
$id = get('pie');
$pie = \Model::factory(Pie::class)->findOne($id);
return view('ventas.pies.cuotas.add', compact('pie'));
}
public static function agregar()
{
$id = get('pie');
$pie = \Model::factory(Pie::class)->findOne($id);
$cant = $pie->cuotas - count($pie->cuotas());
for ($i = 0; $i < $cant; $i ++) {
if (trim(post('valor' . $i)) == '') {
continue;
}
$banco = \Model::factory(Banco::class)->where('nombre', post('banco' . $i))->findOne();
$f = Carbon::createFromDate(post('year' . $i), post('month' . $i), post('day' . $i), config('app.timezone'));
$uf = uf($f);
$valor = correctNumber(post('valor' . $i));
$pago = \Model::factory(Pago::class)->create();
$pago->banco = $banco->id;
$pago->fecha = $f->format('Y-m-d');
if ($uf and $uf->total > 0) {
$pago->uf = $uf->uf->value;
} else {
$pago->uf = 0;
}
$pago->tipo = 1;
$pago->valor = $valor;
$pago->identificador = post('identificador' . $i);
$cuota = \Model::factory(Cuota::class)->create();
$cuota->pie = $pie->id;
$cuota->fecha = $pago->fecha;
$cuota->{'valor_$'} = $pago->valor;
$cuota->estado = 0;
$cuota->banco = $pago->banco;
$cuota->uf = $pago->uf;
$cuota->numero = post('numero' . $i);
$pago->new();
$cuota->pago = $pago->id;
$cuota->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $pie->venta()->id]));
}
}
}
?>

View File

@ -0,0 +1,19 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Venta;
class Devoluciones
{
use Controller;
public static function liquidacion()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('print.devolucion', compact('venta'));
}
}
?>

View File

@ -0,0 +1,212 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Venta;
use Incoviba\old\Venta\Pago;
use Carbon\Carbon;
use Incoviba\old\Venta\Escritura;
use Incoviba\old\Common\Banco;
use Incoviba\old\Venta\Credito;
use Incoviba\old\Venta\Subsidio;
use Incoviba\old\Venta\EstadoPago;
use Incoviba\old\Venta\TipoEstadoVenta;
use Incoviba\old\Venta\EstadoVenta;
class Escrituras
{
use Controller;
protected static function setDefault()
{
self::$default = view('construccion');
}
public static function add()
{
$id = get('venta');
if ($id == null) {
header('Location: .');
}
$venta = \Model::factory(Venta::class)->findOne($id);
return view('ventas.escrituras.add', compact('venta'));
}
public static function agregar()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('escritura_year'), post('escritura_month'), post('escritura_day'), config('app.timezone'));
$venta->escriturado = $f->format('Y-m-d');
if (post('valor_reajuste')) {
$reajuste = \Model::factory(Pago::class)->create();
$reajuste->valor = correctNumber(post('valor_reajuste'));
$fp = Carbon::createFromDate(post('reajuste_year'), post('reajuste_month'), post('reajuste_day'), config('app.timezone'));
$reajuste->fecha = $fp->format('Y-m-d');
$reajuste->uf = (float) uf($fp)->uf->value;
$reajuste->newPagado();
$pie = $venta->pie();
$pie->reajuste = $reajuste->id;
$pie->save();
}
if (post('escritura_valor') or post('escritura_valor_uf')) {
$pago = \Model::factory(Pago::class)->create();
$fp = Carbon::createFromDate(post('pago_escritura_year'), post('pago_escritura_month'), post('pago_escritura_day'), config('app.timezone'));
$pago->fecha = $fp->format('Y-m-d');
$pago->uf = (float) uf($fp)->uf->value;
if (post('escritura_valor')) {
$pago->valor = correctNumber(post('escritura_valor'));
$pago->newPagado();
} else {
$pago->valor = correctNumber(post('escritura_valor_uf')) * $pago->uf;
$pago->new();
}
$escritura = \Model::factory(Escritura::class)->create();
$escritura->pago = $pago->id;
$escritura->valor = $pago->valor('uf');
$escritura->fecha = $pago->fecha;
$escritura->save();
$venta->escritura = $escritura->id;
}
if (post('subsidio_ahorrado') or post('subsidio_valor')) {
$total = post('subsidio_ahorrado') + post('subsidio_valor');
$subsidio = \Model::factory(Subsidio::class)->create();
$pago = \Model::factory(Pago::class)->create();
$pago->fecha = $f->format('Y-m-d');
$pago->uf = (float) uf($f)->uf->value;
$pago->valor = correctNumber(post('subsidio_ahorrado')) * $pago->uf;
$pago->new();
$subsidio->pago = $pago->id;
$pago = \Model::factory(Pago::class)->create();
$pago->fecha = $f->format('Y-m-d');
$pago->uf = (float) uf($f)->uf->value;
$pago->valor = correctNumber(post('subsidio_valor')) * $pago->uf;
$pago->new();
$subsidio->subsidio = $pago->id;
$subsidio->save();
$venta->subsidio = $subsidio->id;
}
if (post('credito_valor')) {
$pago = \Model::factory(Pago::class)->create();
$pago->fecha = $f->format('Y-m-d');
$pago->uf = (float) uf($f)->uf->value;
$valor = post('credito_valor');
if (strpos($valor, ',') !== false) {
$valor = correctNumber($valor);
}
$pago->valor = $valor * $pago->uf;
$banco = \Model::factory(Banco::class)->where('nombre', post('credito_banco'))->findOne();
$pago->banco = $banco->id;
$pago->new();
$credito = \Model::factory(Credito::class)->create();
$credito->pago = $pago->id;
$credito->save();
$venta->credito = $credito->id;
} elseif (post('credito_banco')) {
$pago = $venta->credito()->pago();
$banco = \Model::factory(Banco::class)->where('nombre', post('credito_banco'))->findOne();
$pago->banco = $banco->id;
$pago->save();
}
$tipo = \Model::factory(TipoEstadoVenta::class)->where('descripcion', 'escriturando')->findOne();
$data = [
'venta' => $venta->id,
'estado' => $tipo->id,
'fecha' => $venta->escriturado
];
$estado = \Model::factory(EstadoVenta::class)->create($data);
$estado->save();
$venta->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function edit()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
echo view('ventas.escrituras.edit', compact('venta'));
}
public static function editar()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$uf = uf($f);
$valor = correctNumber(post('valor'));
if ($valor == '') {
$valor_uf = correctNumber(post('valor_uf'));
$valor = $valor_uf * $uf->uf->value;
}
$pago = $venta->escritura()->pago();
if ($pago->valor != $valor) {
$pago->valor = $valor;
}
if ($pago->fecha != $f->format('Y-m-d')) {
$pago->fecha = $f->format('Y-m-d');
$pago->uf = $uf->uf->value;
}
$pago->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function informe()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
return view('ventas.escrituras.informe', compact('venta'));
}
public static function pagar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.escrituras.pagar', compact('venta'));
}
public static function pagado()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$data = [
'pago' => $venta->escritura()->pago()->id,
'fecha' => $f->format('Y-m-d'),
'estado' => 1
];
$estado = model(EstadoPago::class)->create($data);
$estado->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function abonar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.escrituras.abonar', compact('venta'));
}
public static function abonado()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$data = [
'pago' => $venta->escritura()->pago()->id,
'fecha' => $f->format('Y-m-d'),
'estado' => 2
];
$estado = model(EstadoPago::class)->create($data);
$estado->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
}
?>

View File

@ -0,0 +1,98 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Venta;
use Carbon\Carbon;
use Incoviba\old\Venta\Pie;
use Incoviba\old\Venta\Escritura;
use Incoviba\old\Venta\Pago;
class FormaPago
{
use Controller;
public static function edit()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.forma_pago.edit', compact('venta'));
}
public static function editar()
{
d(post());
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$valor = correctNumber(post('valor_pie'));
$cuotas = post('cuotas_pie');
if ($venta->pie != 0) {
$pie = $venta->pie();
$changed = false;
if ($pie->valor != $valor) {
$pie->valor = $valor;
$changed = true;
}
if ($pie->cuotas != $cuotas) {
$pie->cuotas = $cuotas;
$changed = true;
}
if ($changed) {
d($pie);
}
$valor = correctNumber(post('valor_reajuste'));
$f = Carbon::createFromDate(post('year_reajuste'), post('month_reajuste'), post('day_reajuste'), config('app.timezone'));
$uf = uf($f);
$reajuste = $pie->reajuste();
$changed = false;
if ($reajuste->valor != $valor) {
$reajuste->valor = $valor;
$changed = true;
}
if ($reajuste->fecha != $f->format('Y-m-d')) {
$reajuste->fecha = $f->format('Y-m-d');
$reajuste->uf = $uf->uf->value;
$changed = true;
}
if ($changed) {
d($reajuste);
}
} elseif ($valor != '') {
$f = Carbon::parse($venta->fecha, config('app.timezone'));
$uf = uf($f);
$data = [
'valor' => $valor,
'cuotas' => $cuotas,
'uf' => $uf->uf->value,
'fecha' => $f->format('Y-m-d')
];
$pie = model(Pie::class)->create($data);
d($pie);
}
$valor = correctNumber(post('valor_escritura'));
$f = Carbon::createFromDate(post('year_escritura'), post('month_escritura'), post('day_escritura'), config('app.timezone'));
if ($venta->escritura != 0) {
$escritura = $venta->escritura();
d($escritura);
} elseif ($valor != '') {
$data = [
'valor' => $valor,
'fecha' => $f->format('Y-m-d'),
'uf' => $uf->uf->value,
'tipo' => 7
];
$pago = model(Pago::class)->create($data);
$pago->newPagado();
$data['pago'] = $pago->id;
unset($data['tipo']);
$escritura = model(Escritura::class)->create($data);
$escritura->save();
$venta->escritura = $escritura->id;
$venta->save();
}
}
}
?>

View File

@ -0,0 +1,951 @@
<?php
namespace App\Controller;
use Carbon\Carbon;
use GuzzleHttp\Client;
use App\Definition\Controller;
use App\Alias\PHPExcel;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Proyecto\Agente;
use Incoviba\old\Proyecto\ProyectoAgente;
use Incoviba\old\Venta\Venta;
use Incoviba\old\Venta\Pie;
use Incoviba\old\Venta\Credito;
use Incoviba\old\Venta\Cuota;
class Informes
{
use Controller;
protected static function setDefault()
{
self::$default = view('informes.list');
}
public static function gantt_entregas()
{
if (get('proyecto')) {
$id_proyecto = get('proyecto');
$proyecto = model(Proyecto::class)->find_one($id_proyecto);
$ini = \Carbon\Carbon::parse($proyecto->estado()->fecha, config('app.timezone'));
#$informe = new Informador('Carta Gantt Proyecto - ' . $proyecto->descripcion);
$name = 'Carta Gantt Proyecto - ' . $proyecto->descripcion;
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = ['Departamento', 'Propietario', 'Entrega', 'Estado'];
$today = \Carbon\Carbon::today(config('app.timezone'));
$end = $today->copy()->addDays(30);
$dif = $end->diffInDays($ini);
for ($i = 0; $i <= $dif; $i ++) {
$f = $ini->copy()->addDays($i);
if ($f->isWeekend()) {
continue;
}
$columnas []= $f->format('Y-m-d');
}
$informe->addColumns($columnas);
$data = [];
foreach ($proyecto->entregas() as $venta) {
$info = [];
$info []= $venta->unidad()->descripcion;
$info []= $venta->propietario()->findOne()->nombreCompleto();
$fe = Carbon::parse($venta->entrega()->find_one()->fecha, config('app.timezone'));
$info []= $fe->format('Y-m-d');
$info []= '';
for ($i = 0; $i <= $dif; $i ++) {
$f = $ini->copy()->addDays($i);
if ($f->isWeekend()) {
continue;
}
if ($f >= $fe and $f <= $fe->copy()->addDays(14)) {
$info []= 'X';
} else {
$info []= '';
}
}
$data []= $info;
}
$informe->addDatas($data);
return $informe->informe();
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.gantt_entregas', compact('proyectos'));
}
}
public static function escrituras()
{
if (get('proyecto')) {
set_time_limit(60);
$id_proyecto = get('proyecto');
$proyecto = model(Proyecto::class)->find_one($id_proyecto);
#$informe = new Informador('Escrituras - ' . $proyecto->descripcion);
$name = 'Escrituras';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = [
'Departamento',
'Estacionamientos',
'Bodegas',
'Propietario',
(object) ['name' => 'Promesa', 'style' => 'number'],
['name' => 'Bono Pie', 'style' => 'amount'],
['name' => 'Pie Pagado', 'style' => 'amount'],
['name' => 'Reajuste', 'style' => 'amount'],
['name' => 'Abono Contado', 'style' => 'amount'],
['name' => 'Subsidio', 'style' => 'amount'],
'Estado Subsidio',
['name' => 'Credito', 'style' => 'amount'],
'Banco',
'Estado Credito',
['name' => 'Saldo', 'style' => 'amount'],
['name' => 'Escritura', 'style' => 'amount'],
['name' => 'Entrega', 'style' => 'date']
];
$informe->addColumns($columnas);
//$ventas = $proyecto->escrituras();
$ventas = $proyecto->ventas();
$data = [];
foreach ($ventas as $venta) {
$info = [];
$info['Departamento'] = $venta->unidad()->descripcion;
$ests = [];
foreach ($venta->propiedad()->estacionamientos() as $e) {
$ests []= $e->descripcion;
}
$bods = [];
foreach ($venta->propiedad()->bodegas() as $b) {
$bods []= $b->descripcion;
}
$info['Estacionamientos'] = implode(' - ', $ests);
$info['Bodegas'] = implode(' - ', $bods);
$info['Propietario'] = $venta->propietario()->nombreCompleto();
$info['Promesa'] = $venta->valor_uf;
$saldo = $venta->valor_uf;
$info['Bono Pie'] = '';
if ($venta->bono_pie != 0) {
$info['Bono Pie'] = $venta->bonoPie()->pago()->valor('ufs');
$saldo -= $venta->bonoPie()->pago()->valor('ufs');
}
$info['Pie'] = '';
$info['Reajuste'] = '';
if ($venta->pie != 0) {
$info['Pie'] = $venta->pie()->valorPagado();
$saldo -= $venta->pie()->valorPagado();
if ($venta->pie()->reajuste != 0) {
$info['Reajuste'] = $venta->pie()->reajuste()->valor('ufs');
$saldo -= $venta->pie()->reajuste()->valor('ufs');
}
}
$info['Abono Contado'] = '';
if ($venta->escritura != 0) {
$info['Abono Contado'] = $venta->escritura()->pago()->valor('ufs');
$saldo -= $venta->escritura()->pago()->valor('ufs');
}
$info['Subsidio'] = '';
$info['Estado Subsidio'] = '';
if ($venta->subsidio != 0) {
$info['Subsidio'] = $venta->subsidio()->total('ufs');
$info['Estado Subsidio'] = implode(' - ', [
$venta->subsidio()->subsidio()->estado()->tipo()->descripcion,
$venta->subsidio()->pago()->estado()->tipo()->descripcion
]);
$saldo -= $venta->subsidio()->total('ufs');
}
$info['Credito'] = '';
$info['Banco'] = '';
$info['Estado Credito'] = '';
if ($venta->credito != 0) {
$info['Credito'] = $venta->credito()->pago()->valor('ufs');
$saldo -= $venta->credito()->pago()->valor('ufs');
if ($venta->credito()->pago()->banco != 0) {
$info['Banco'] = $venta->credito()->pago()->banco()->nombre;
}
$info['Estado Credito'] = $venta->credito()->pago()->estado()->tipo()->descripcion;
}
$info['Saldo'] = -$saldo;
$info['Escritura'] = '';
if ($venta->escriturado != 0) {
$info['Escritura'] = $venta->escriturado;
}
$info['Entrega'] = '';
if ($venta->entregado != 0) {
$info['Entrega'] = $venta->entregado;
}
$data []= $info;
}
$informe->addData($data);
return $informe->informe();
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.escrituras', compact('proyectos'));
}
}
public static function consolidacion()
{
$id_proyecto = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
$ventas = $proyecto->ventas();
set_time_limit(count($ventas));
$f = Carbon::today(config('app.timezone'));
setlocale(LC_TIME, 'es');
$data = [
[$proyecto->descripcion],
[strftime('%d de %B de %Y', $f->timestamp)],
[''],
['']
];
$columns = [
['name' => 'Fecha', 'style' => 'date'],
'Glosa',
['name' => 'Debe', 'style' => 'number'],
['name' => 'Haber', 'style' => 'number'],
['name' => 'Saldo', 'style' => 'number'],
'Comentario'
];
$bold_rows = [];
foreach ($ventas as $venta) {
$data []= ['Departamento ' . $venta->unidad()->descripcion . ' (' . format('ufs', $venta->valor_uf) . ' UF)'];
$data []= $columns;
$bold_rows []= count($data) - 1;
$ufs = 0;
$debe = 0;
$haber = 0;
$sum = 0;
if ($venta->pie != 0) {
$cuotas = $venta->pie()->cuotas();
foreach ($cuotas as $cuota) {
$sum += $cuota->pago()->valor();
$ufs += $cuota->pago()->valor('ufs');
$haber += $cuota->pago()->valor();
$info = [
$cuota->pago()->estado()->fecha,
'Pie - Cuota ' . $cuota->numero() . ' - ' . $venta->pie()->cuotas . ' (' . format('ufs', $cuota->pago()->valor('ufs')) . ' UF)',
'',
$cuota->pago()->valor(),
$sum
];
if ($cuota->pago()->estado()->estado < 2) {
$info []= 'No ha sido abonada.';
}
$data []= $info;
}
if ($venta->pie()->reajuste != 0) {
$sum += $venta->pie()->reajuste()->valor();
$ufs += $venta->pie()->reajuste()->valor('ufs');
$haber += $venta->pie()->reajuste()->valor();
$info = [
$venta->pie()->reajuste()->estado()->fecha,
'Reajuste (' . format('ufs', $venta->pie()->reajuste()->valor('ufs')) . ' UF)',
'',
$venta->pie()->reajuste()->valor(),
$sum
];
if ($venta->pie()->reajuste()->estado()->estado < 2) {
$info []= 'No ha sido abonado.';
}
$data []= $info;
}
}
if ($venta->escritura != 0) {
$sum += $venta->escritura()->pago()->valor();
$ufs += $venta->escritura()->pago()->valor('ufs');
$haber += $venta->escritura()->pago()->valor();
$info = [
$venta->escritura()->pago()->estado()->fecha,
'Abono Escritura (' . format('ufs', $venta->escritura()->pago()->valor('ufs')) . ' UF)',
'',
$venta->escritura()->pago()->valor(),
$sum
];
if ($venta->escritura()->pago()->estado()->estado < 2) {
$info []= 'No ha sido abonado.';
}
$data []= $info;
}
if ($venta->credito != 0) {
$sum += $venta->credito()->pago()->valor();
$ufs += $venta->credito()->pago()->valor('ufs');
$haber += $venta->credito()->pago()->valor();
$info = [
$venta->credito()->pago()->estado()->fecha,
'Crédito (' . format('ufs', $venta->credito()->pago()->valor('ufs')) . ' UF)',
'',
$venta->credito()->pago()->valor(),
$sum
];
if ($venta->credito()->pago()->estado()->estado < 2) {
$info []= 'No ha sido pagado.';
}
$data []= $info;
}
if ($venta->bono_pie != 0) {
try {
$sum -= $venta->bonoPie()->pago()->valor();
$debe += $venta->bonoPie()->pago()->valor();
$info = [
$venta->bonoPie()->pago()->estado()->fecha,
'Bono Pie (' . format('ufs', $venta->bonoPie()->pago()->valor('ufs')) . ' UF)'.
$venta->bonoPie()->pago()->valor(),
'',
$sum
];
$data []= $info;
$sum += $venta->bonoPie()->pago()->valor();
$haber += $venta->bonoPie()->pago()->valor();
$info = [
$venta->bonoPie()->pago()->estado()->fecha,
'Bono Pie (' . format('ufs', $venta->bonoPie()->pago()->valor('ufs')) . ' UF)'.
'',
$venta->bonoPie()->pago()->valor(),
$sum
];
$data []= $info;
} catch (\Exception $e) {
}
}
$info = [
'',
'TOTAL (' . format('ufs', $ufs) . ' UF)',
$debe,
$haber,
$sum
];
$data []= $info;
$bold_rows []= count($data) - 1;
$data []= [''];
}
/**
* Departamento #
* Fecha |Glosa |Debe |Haber |Saldo
* <fecha> |Pie - Cuota 1 - n (# UF) |- |$# |<sum>
* <fecha> |Reajuste (# UF) |- |$# |<sum>
* <fecha> |Abono Escritura (# UF) |- |$# |<sum>
* <fecha> |Crédito (# UF) |- |$# |<sum>
* <fecha> |Bono Pie (# UF) |$# |- |<sum>
* <fecha> |Bono Pie (# UF) |- |$# |<sum>
* <fecha> |Devolución (# UF) |$# |- |<sum>
* - |TOTAL (# UF) |<sumDebe> |<sumHaber> |<sum>
*/
array_walk($data, function(&$e, $i) use ($columns) {
if (count($e) < count($columns)) {
$n = count($columns) - count($e);
for ($j = 0; $j < $n; $j ++) {
$e []= '';
}
}
});
#$informe = new Informador('Consolidación - ' . $proyecto->descripcion);
$name = 'Consolidación';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$informe->addColumns($columns);
$informe->addData($data);
return $informe->informe();
}
public static function creditos_pendientes()
{
function creditos() {
$creditos = model(Credito::class)
->select('credito.*')
->join('venta', ['venta.credito', '=', 'credito.id'])
->join('pago', ['pago.id', '=', 'credito.pago'])
->rawJoin('JOIN (SELECT ep.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago ep ON ep.id = e0.id)', ['estado_pago.pago', '=', 'pago.id'], 'estado_pago')
->whereLt('estado_pago.estado', 2)
->where('venta.estado', 1)
->orderByAsc('estado_pago.fecha')
->findMany();
foreach ($creditos as $credito) {
yield $credito;
}
}
$informe = new Informador('Créditos Pendientes');
$columnas = ['Proyecto', 'Departamento', 'Valor', 'Fecha Escritura', 'Estado'];
$informe->addColumns($columnas);
$row = 0;
foreach (creditos() as $credito) {
$informe->addData($row, $credito->venta()->proyecto()->descripcion, 'Proyecto');
$informe->addData($row, $credito->venta()->unidad()->descripcion, 'Departamento');
$informe->addData($row, $credito->pago()->valor('ufs'), 'Valor');
$informe->addData($row, (($credito->venta()->escriturado) ? $credito->venta()->escriturado : $credito->pago()->estado()->fecha), 'Fecha Escritura');
$informe->addData($row, ucwords($credito->pago()->estado()->tipo()->descripcion), 'Estado');
$row ++;
}
$date = [
'numberFormat' => ['short-date']
];
$ufs = [
'numberFormat' => ['thousands']
];
$formats = ['Valor' => $ufs, 'Fecha Escritura' => $date];
$informe->addFormats($formats);
return $informe->informe();
}
public static function ventas()
{
if (get('proyecto')) {
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$ventas = $proyecto->ventas();
/*usort($ventas, function($a, $b) {
return $a->fecha()->timestamp - $b->fecha()->timestamp;
});*/
$procasa = model(Agente::class)->findOne(1);
$pa = model(ProyectoAgente::class)->where('agente', $procasa->id)->where('proyecto', $proyecto->id)->findOne();
if ($pa) {
$comision = $pa->comision / 100;
} else {
$comision = 0.03;
}
#$informe = new Informador('Ventas - ' . $proyecto->descripcion);
$name = 'Informe de Ventas';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xlsx');
//$informe = new PHPExcel($name, $filename);
$columnas = [
'Propietario',
['name' => 'Departamento', 'style' => 'number'],
['name' => 'Estacionamientos', 'style' => 'number'],
['name' => 'Bodegas', 'style' => 'number'],
'Fecha Venta',
['name' => 'Mes', 'style' => 'mes'],
'Tipo',
['name' => 'm² Ponderados', 'style' => 'amount'],
['name' => 'Valor Promesa', 'style' => 'amount'],
['name' => 'Pie', 'style' => 'amount'],
['name' => 'Pie Pagado', 'style' => 'amount'],
['name' => '% Pie Pagado', 'style' => 'percent'],
['name' => 'Bono Pie', 'style' => 'amount'],
'Operador',
['name' => 'Valor Operador', 'style' => 'amount'],
['name' => 'Premios', 'style' => 'amount'],
['name' => 'Subsidio', 'style' => 'amount'],
['name' => 'Ahorro', 'style' => 'amount'],
['name' => 'Credito', 'style' => 'amount'],
'Banco',
['name' => 'Valor Ests & Bods', 'style' => 'amount'],
['name' => 'Valor Neto', 'style' => 'amount'],
['name' => 'UF/m²*', 'style' => 'amount'],
['name' => 'Comision', 'style' => 'amount'],
['name' => 'Venta s/Comision', 'style' => 'amount']
];
//$informe->addColumns($columnas);
$data = [];
foreach ($ventas as $venta) {
$info = [];
$info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto());
$info['Departamento'] = trim(array_reduce($venta->propiedad()->departamentos(), function($carry, $item) {
return implode(' - ', [$carry, $item->descripcion]);
}), ' -');
//$ests = [];
$es = $venta->propiedad()->estacionamientos();
/*if (count($es) > 0) {
foreach ($es as $e) {
$ests []= $e->descripcion;
}
}
$info['Estacionamientos'] = implode(', ', $ests);*/
$info['Estacionamientos'] = implode(', ', array_map(function($item) {
return $item->descripcion;
}, $es));
//$bods = [];
$bs = $venta->propiedad()->bodegas();
/*if (count($bs) > 0) {
foreach ($bs as $b) {
$bods []= $b->descripcion;
}
}
$info['Bodegas'] = implode(', ', $bods);*/
$info['Bodegas'] = implode(', ', array_map(function($item) {
return $item->descripcion;
}, $bs));
$info['Fecha Venta'] = $venta->fecha()->format('Y-m-d');
$info['Mes'] = $venta->fecha()->format('M-y');
$info['Tipo'] = $venta->unidad()->abreviacion;
$info['m² Ponderados'] = $venta->unidad()->m2('vendible');
$info['Valor Promesa'] = $venta->valor_uf;
$info['Pie'] = $venta->pie()->valor;
$info['Pie Pagado'] = 0;
$info['% Pie Pagado'] = 0;
if ($venta->pie()) {
$info['Pie Pagado'] = $venta->pie()->valorPagado('uf');
$info['% Pie Pagado'] = $venta->pie()->valorPagado('uf') / $venta->valor_uf;
}
$info['Bono Pie'] = ($venta->bono_pie == 0 or $venta->bonoPie() === false) ? '' : $venta->bonoPie()->pago()->valor('ufs');
$info['Operador'] = ($venta->agente and $venta->agente()->agente()->tipo == 19) ? $venta->agente()->agente()->descripcion : '';
$info['Valor Operador'] = $venta->valorComision();
//$promos = 0;
$ps = $venta->promociones();
/*if (count($ps) > 0) {
foreach ($ps as $promo) {
$promos += $promo->valor;
}
}
$info['Premios'] = $promos;*/
$info['Premios'] = array_reduce($ps, function($sum, $item) {
return $sum + $item->valor;
});
$info['Subsidio'] = 0;
$info['Ahorro'] = 0;
if ($venta->subsidio != 0) {
$info['Subsidio'] = $venta->subsidio()->subsidio()->valor('ufs');
$info['Ahorro'] = $venta->subsidio()->pago()->valor('ufs');
}
$info['Credito'] = 0;
$info['Banco'] = '';
if ($venta->credito != 0) {
$info['Credito'] = $venta->credito()->pago()->valor('ufs');
if ($venta->credito()->pago()->banco != 0) {
$info['Banco'] = $venta->credito()->pago()->banco()->nombre;
}
}
$info['Valor Ests & Bods'] = $venta->valorEstacionamientosYBodegas();
$info['Valor Neto'] = $venta->valorFinal();
$info['UF/m²*'] = $venta->uf_m2();
$info['Comision'] = $venta->valorFinal() * $comision;
$info['Venta s/Comision'] = $venta->valorFinal() - $info['Comision'];
$data []= $info;
}
/*$informe->addData($data);
$totals = [
'Propietario' => 'TOTAL',
'Departamento' => 'count',
'Estacionamientos' => 'count',
'Bodegas' => 'count',
'm² Ponderados' => 'sum',
'Valor Promesa' => 'sum',
'Bono Pie' => 'sum',
'Subsidio' => 'sum',
'Ahorro' => 'sum',
'Credito' => 'sum',
'Valor Operador' => 'sum',
'Premios' => 'sum',
'Valor Ests & Bods' => 'sum',
'Valor Neto' => 'sum',
'Comision' => 'sum'
];
$informe->addTotals($totals);
return $informe->informe();*/
$body = [
"Proyecto" => $proyecto->descripcion,
"Compañía" => $proyecto->inmobiliaria()->abreviacion,
"data" => $data
];
$client = new Client(['base_uri' => 'localhost:8011']);
$response = $client->post('/ventas', ['json' => $body]);
header("Content-Type: application/octet-stream; charset=utf-8");
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: max-age=0');
return $response->getBody();
//file_put_contents('php://output', $output);
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.ventas', compact('proyectos'));
}
}
public static function resumen_contabilidad()
{
if (get('proyecto')) {
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$fecha = get('fecha');
$mes = null;
if ($fecha != null) {
$mes = Carbon::parse($fecha)->addMonths(1)->subDays(1);
}
$ventas = $proyecto->ventas();
usort($ventas, function($a, $b) {
return $a->fecha()->timestamp - $b->fecha()->timestamp;
});
$name = 'Resumen Contabilidad';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - hasta ' . $fecha->format('Y-m-d') . '.xls');
$name .= ' - Hasta ' . $fecha->format('d-m-Y');
$informe = new PHPExcel($name, $filename);
$columnas = [
'Propietario',
['name' => 'Departamento', 'style' => 'general_number'],
['name' => 'Estacionamientos', 'style' => 'number'],
['name' => 'Bodegas', 'style' => 'number'],
'Fecha Venta',
['name' => 'Mes', 'style' => 'mes'],
'Tipo',
['name' => 'm² Ponderados', 'style' => 'amount'],
['name' => 'Valor Promesa', 'style' => 'amount'],
['name' => 'Pie [UF]', 'style' => 'amount'],
['name' => 'Pie [$]', 'style' => 'amount'],
['name' => 'Abono Escritura', 'style' => 'amount'],
['name' => 'Crédito', 'style' => 'amount'],
['name' => 'Cuotas', 'style' => 'number'],
['name' => 'Cuotas Pagadas', 'style' => 'number'],
['name' => 'Pie Pagado [UF]', 'style' => 'amount'],
['name' => 'Pie Pagado [$]', 'style' => 'amount']
];
$informe->addColumns($columnas);
$data = [];
foreach ($ventas as $venta) {
$info = [];
$info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto());
$info['Departamento'] = $venta->unidad()->descripcion;
$ests = [];
if ($venta->propiedad()->estacionamientos != '') {
$es = $venta->propiedad()->estacionamientos();
foreach ($es as $e) {
$ests []= $e->descripcion;
}
}
$info['Estacionamientos'] = implode(', ', $ests);
$bods = [];
if ($venta->propiedad()->bodegas != '') {
$bs = $venta->propiedad()->bodegas();
foreach ($bs as $b) {
$bods []= $b->descripcion;
}
}
$info['Bodegas'] = implode(', ', $bods);
$info['Fecha Venta'] = $venta->fecha()->format('d.m.Y');
$info['Mes'] = $venta->fecha()->format('M-y');
$info['Tipo'] = $venta->unidad()->abreviacion;
$info['m² Ponderados'] = $venta->unidad()->m2('vendible');
$info['Valor Promesa'] = $venta->valor_uf;
$info['Pie [UF]'] = 0;
$info['Pie [$]'] = 0;
$info['Abono Escritura'] = 0;
$info['Crédito'] = 0;
$info['Cuotas'] = 0;
$info['Cuotas Pagadas'] = 0;
$info['Pie Pagado [UF]'] = 0;
$info['Pie Pagado [$]'] = 0;
if ($venta->pie()) {
$info['Pie [UF]'] = $venta->pie()->valor;
$info['Pie [$]'] = $venta->pie()->valorPesos();
$info['Abono Escritura'] = ($venta->escritura != 0) ? $venta->escritura()->valor('ufs') : ($venta->valor_uf - $venta->pie()->valor - (($venta->credito != 0) ? $venta->credito()->pago()->valor('ufs') : 0));
$info['Crédito'] = ($venta->credito != 0) ? $venta->credito()->pago()->valor('ufs') : 0;
$info['Cuotas'] = $venta->pie()->cuotas;
$info['Cuotas Pagadas'] = count($venta->pie()->pagadas($mes));
$info['Pie Pagado [UF]'] = $venta->pie()->valorPagado('uf', $mes);
$info['Pie Pagado [$]'] = $venta->pie()->valorPagado('pesos', $mes);
}
$data []= $info;
}
$informe->addData($data);
$totals = [
'Departamento' => 'count',
'Estacionamientos' => 'count',
'Bodegas' => 'count',
'm² Ponderados' => 'sum',
'Valor Promesa' => 'sum',
'Pie' => 'sum',
'Pie Pagado' => 'sum'
];
$informe->addTotals($totals);
return $informe->informe();
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.resumen_contabilidad', compact('proyectos'));
}
}
public static function contabilidad()
{
if (get('proyecto')) {
$id = get('proyecto');
$fecha = get('fecha');
$mes = null;
if ($fecha != null) {
$mes = Carbon::parse($fecha);
}
$proyecto = model(Proyecto::class)->findOne($id);
$q = "SELECT pago.*, venta.id AS vid, venta.tipo AS ctipo, venta.pie AS pie
FROM (
SELECT pago.id, banco.nombre AS banco, pago.fecha, pago.valor, pago.uf, ep.estado, ep.fecha AS efecha
FROM pago JOIN banco ON banco.id = pago.banco JOIN ((
SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago ep ON ep.id = e0.id) ON ep.pago = pago.id
WHERE ep.estado > 0 ";
if ($mes != null) {
$q .= "AND (pago.fecha BETWEEN '" . $mes->format('Y-m-01') . "' AND '" . $mes->format('Y-m-t') . "'
OR ep.fecha BETWEEN '" . $mes->format('Y-m-01') . "' AND '" . $mes->format('Y-m-t') . "')";
}
$q .= ") pago JOIN (SELECT venta.*
FROM ((
SELECT venta.id, venta.pie, venta.propiedad, credito.pago, 'credito' AS tipo
FROM venta JOIN credito ON credito.id = venta.credito)
UNION ALL (
SELECT venta.id, venta.pie, venta.propiedad, escritura.pago, 'escritura' AS tipo
FROM venta JOIN escritura ON escritura.id = venta.escritura)
UNION ALL (
SELECT venta.id, venta.pie, venta.propiedad, cuota.pago, 'cuota' AS tipo
FROM venta JOIN cuota ON cuota.pie = venta.pie)) venta
JOIN propiedad ON propiedad.id = venta.propiedad
JOIN unidad ON unidad.id = propiedad.unidad_principal
WHERE unidad.proyecto = ?) venta
ON venta.pago = pago.id";
$st = \ORM::getDB()->prepare($q);
$st->execute([$id]);
if ($st->rowCount() > 0) {
$R = $st->fetchAll(\PDO::FETCH_OBJ);
//$informe = new Informador('Contabilidad - ' . (($mes != null) ? $mes->format('Y-m') . ' - ' : '') . $proyecto->descripcion);
$name = 'Contabilidad';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', 'Contabilidad - ' . (($mes != null) ? $mes->format('Y-m') . ' - ' : '') . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = ['Proyecto', 'Fecha', 'Banco', 'Departamento', 'RUT', 'Propietario', 'Glosa', 'Glosa2', (object) ['name' => 'Valor', 'style' => 'integer'], (object) ['name' => 'Valor UF', 'style' => 'currency']];
$informe->addColumns($columnas);
$data = [];
foreach ($R as $r) {
$info = [];
$info['Proyecto'] = $proyecto->descripcion;
$f1 = \Carbon\Carbon::parse($r->fecha, config('app.timezone'));
$f2 = \Carbon\Carbon::parse($r->efecha, config('app.timezone'));
$info['Fecha'] = ($f1->max($f2))->format('Y-m-d');
$info['Banco'] = $r->banco;
$venta = model(Venta::class)->findOne($r->vid);
$info['Departamento'] = $venta->unidad()->descripcion;
$info['RUT'] = $venta->propietario()->rut();
$info['Propietario'] = $venta->propietario()->nombreCompleto();
$info['Glosa'] = ucwords($r->ctipo);
$info['Glosa2'] = '';
if ($r->ctipo == 'cuota') {
$cuota = model(Cuota::class)->where('pago', $r->id)->findOne();
$info['Glosa'] = 'Pie - ' . format('ufs', $cuota->pie()->valor('ufs'), null, true);
$info['Glosa2'] = $cuota->numero() . ' - ' . $cuota->pie()->cuotas;
}
$info['Valor'] = $r->valor;
$info['Valor UF'] = '0';
if ($r->uf > 0) {
$info['Valor UF'] = $r->valor / $r->uf;
}
$data []= $info;
}
$informe->addData($data);
return $informe->informe();
}
} else {
setlocale(LC_TIME, 'es_ES');
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.contabilidad', compact('proyectos'));
}
}
public static function para_comision()
{
$proyectos = model(Proyecto::class)->orderByAsc('descripcion')->findMany();
return view('informes.para_comision', compact('proyectos'));
}
public static function comisiones()
{
$id = post('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$unidades = explode('-', str_replace([';', '.', ':', ' ', PHP_EOL, '|', '+', ','], '-', post('unidades')));
$ventas = model(Venta::class)
->select('venta.*')
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
->where('unidad.proyecto', $proyecto->id)
->where('venta.estado', 1)
->whereIn('unidad.descripcion', $unidades)
->orderByExpr('FIELD(unidad.descripcion, ' . implode(', ', $unidades) . ')')
->findMany();
$ids = [];
$totales = (object) ['precio' => 0, 'neto' => 0, 'comision' => 0];
foreach ($ventas as $venta) {
$ids []= $venta->id;
$totales->precio += $venta->valor_uf;
$totales->neto += $venta->valorCorredora();
$totales->comision += $venta->valorCorredora() * 1.5 / 100;
}
return view('informes.comisiones', compact('ventas', 'proyecto', 'totales', 'ids'));
}
public static function comisiones_xlsx()
{
$id_ventas = explode(',', get('ventas'));
$ventas = model(Venta::class)
->whereIn('id', $id_ventas)
->orderByExpr('FIELD(id, ' . implode(', ', $id_ventas) . ')')
->findMany();
$informe = new Informador('Comisiones - ' . $ventas[0]->proyecto()->descripcion);
$columnas = ['Departamento', 'Estacionamientos', 'Bodegas', 'Propietario', 'Precio', '% Com', 'Com UF'];
$informe->addColumns($columnas);
$data = [];
foreach ($ventas as $venta) {
$info = [];
$info['Departamento'] = $venta->unidad()->descripcion;
$info['Estacionamientos'] = implode(' - ', $venta->propiedad()->estacionamientos('array'));
$info['Bodegas'] = implode(' - ', $venta->propiedad()->bodegas('array'));
$info['Propietario'] = $venta->propietario()->nombreCompleto();
$info['Precio'] = "'" . format('ufs', $venta->valorCorredora());
$info['% Com'] = '1,5 %';
$info['Com UF'] = "'" . format('ufs', $venta->valorCorredora() * 1.5 / 100);
$data []= $info;
}
$informe->addDatas($data);
return $informe->informe();
}
public static function cuotas()
{
$id_venta = get('venta');
$venta = model(Venta::class)->findOne($id_venta);
$name = 'Cuotas - ' . $venta->unidad()->descripcion;
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $venta->proyecto()->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = [
['name' => 'Cuota', 'style' => 'number'],
['name' => 'Fecha Cuota', 'style' => 'date'],
'Banco',
'Identificador',
['name' => 'Valor $', 'style' => 'number'],
['name' => 'Valor UF', 'style' => 'currency'],
['name' => 'Fecha Pago', 'style' => 'date']
];
$informe->addColumns($columnas);
$data = [];
foreach ($venta->pie()->cuotas() as $cuota) {
$info = [];
$info['Cuota'] = $cuota->numero();
$info['Fecha Cuota'] = $cuota->pago()->fecha()->format('Y-m-d');
$info['Banco'] = $cuota->pago()->banco()->descripcion;
$info['Identificador'] = $cuota->pago()->identificador;
$info['Valor $'] = $cuota->pago()->valor();
$info['Valor UF'] = $cuota->pago()->valor('ufs');
$info['Fecha Pago'] = $cuota->pago()->estado()->fecha()->format('Y-m-d');
$data []= $info;
}
$informe->addData($data);
return $informe->informe();
}
public static function resciliaciones()
{
if (get('proyecto')) {
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$ventas = $proyecto->resciliaciones();
usort($ventas, function($a, $b) {
return $a->fecha()->timestamp - $b->fecha()->timestamp;
});
$name = 'Resciliaciones';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = [
'Propietario',
['name' => 'Departamento', 'style' => 'number'],
['name' => 'Estacionamientos', 'style' => 'number'],
['name' => 'Bodegas', 'style' => 'number'],
'Fecha Venta',
'Fecha Resciliación',
['name' => 'Mes', 'style' => 'mes'],
'Tipo',
['name' => 'm² Ponderados', 'style' => 'amount'],
['name' => 'Valor Promesa', 'style' => 'amount'],
];
$informe->addColumns($columnas);
$data = [];
foreach ($ventas as $venta) {
$info = [];
$info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto());
$info['Departamento'] = $venta->unidad()->descripcion;
$ests = [];
if ($venta->propiedad()->estacionamientos != '') {
$es = $venta->propiedad()->estacionamientos();
foreach ($es as $e) {
$ests []= $e->descripcion;
}
}
$info['Estacionamientos'] = implode(', ', $ests);
$bods = [];
if ($venta->propiedad()->bodegas != '') {
$bs = $venta->propiedad()->bodegas();
foreach ($bs as $b) {
$bods []= $b->descripcion;
}
}
$info['Bodegas'] = implode(', ', $bods);
$info['Fecha Venta'] = $venta->fecha()->format('d.m.Y');
$info['Fecha Resciliación'] = $venta->estado()->fecha()->format('d.m.Y');
$info['Mes'] = $venta->estado()->fecha()->format('M-y');
$info['Tipo'] = $venta->unidad()->abreviacion;
$info['m² Ponderados'] = $venta->unidad()->m2('vendible');
$info['Valor Promesa'] = $venta->valor_uf;
$data []= $info;
}
$informe->addData($data);
$totals = [
'Departamento' => 'count',
'Estacionamientos' => 'count',
'Bodegas' => 'count',
'm² Ponderados' => 'sum',
'Valor Promesa' => 'sum'
];
$informe->addTotals($totals);
return $informe->informe();
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.resciliaciones', compact('proyectos'));
}
}
}

View File

@ -0,0 +1,901 @@
<?php
namespace App\Controller;
use Carbon\Carbon;
use App\Definition\Controller;
use App\Alias\PHPExcel;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Proyecto\Agente;
use Incoviba\old\Proyecto\ProyectoAgente;
use Incoviba\old\Venta\Venta;
use Incoviba\old\Venta\Pie;
use Incoviba\old\Venta\Credito;
use Incoviba\old\Venta\Cuota;
class Informes
{
use Controller;
protected static function setDefault()
{
self::$default = view('informes.list');
}
public static function gantt_entregas()
{
if (get('proyecto')) {
$id_proyecto = get('proyecto');
$proyecto = model(Proyecto::class)->find_one($id_proyecto);
$ini = \Carbon\Carbon::parse($proyecto->estado()->fecha, config('app.timezone'));
#$informe = new Informador('Carta Gantt Proyecto - ' . $proyecto->descripcion);
$name = 'Carta Gantt Proyecto - ' . $proyecto->descripcion;
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = ['Departamento', 'Propietario', 'Entrega', 'Estado'];
$today = \Carbon\Carbon::today(config('app.timezone'));
$end = $today->copy()->addDays(30);
$dif = $end->diffInDays($ini);
for ($i = 0; $i <= $dif; $i ++) {
$f = $ini->copy()->addDays($i);
if ($f->isWeekend()) {
continue;
}
$columnas []= $f->format('Y-m-d');
}
$informe->addColumns($columnas);
$data = [];
foreach ($proyecto->entregas() as $venta) {
$info = [];
$info []= $venta->unidad()->descripcion;
$info []= $venta->propietario()->findOne()->nombreCompleto();
$fe = Carbon::parse($venta->entrega()->find_one()->fecha, config('app.timezone'));
$info []= $fe->format('Y-m-d');
$info []= '';
for ($i = 0; $i <= $dif; $i ++) {
$f = $ini->copy()->addDays($i);
if ($f->isWeekend()) {
continue;
}
if ($f >= $fe and $f <= $fe->copy()->addDays(14)) {
$info []= 'X';
} else {
$info []= '';
}
}
$data []= $info;
}
$informe->addDatas($data);
return $informe->informe();
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.gantt_entregas', compact('proyectos'));
}
}
public static function escrituras()
{
if (get('proyecto')) {
set_time_limit(60);
$id_proyecto = get('proyecto');
$proyecto = model(Proyecto::class)->find_one($id_proyecto);
#$informe = new Informador('Escrituras - ' . $proyecto->descripcion);
$name = 'Escrituras';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = [
'Departamento',
'Estacionamientos',
'Bodegas',
'Propietario',
(object) ['name' => 'Promesa', 'style' => 'number'],
['name' => 'Bono Pie', 'style' => 'amount'],
['name' => 'Pie Pagado', 'style' => 'amount'],
['name' => 'Reajuste', 'style' => 'amount'],
['name' => 'Abono Contado', 'style' => 'amount'],
['name' => 'Subsidio', 'style' => 'amount'],
'Estado Subsidio',
['name' => 'Credito', 'style' => 'amount'],
'Banco',
'Estado Credito',
['name' => 'Saldo', 'style' => 'amount'],
['name' => 'Escritura', 'style' => 'amount'],
['name' => 'Entrega', 'style' => 'date']
];
$informe->addColumns($columnas);
//$ventas = $proyecto->escrituras();
$ventas = $proyecto->ventas();
$data = [];
foreach ($ventas as $venta) {
$info = [];
$info['Departamento'] = $venta->unidad()->descripcion;
$ests = [];
foreach ($venta->propiedad()->estacionamientos() as $e) {
$ests []= $e->descripcion;
}
$bods = [];
foreach ($venta->propiedad()->bodegas() as $b) {
$bods []= $b->descripcion;
}
$info['Estacionamientos'] = implode(' - ', $ests);
$info['Bodegas'] = implode(' - ', $bods);
$info['Propietario'] = $venta->propietario()->nombreCompleto();
$info['Promesa'] = $venta->valor_uf;
$saldo = $venta->valor_uf;
$info['Bono Pie'] = '';
if ($venta->bono_pie != 0) {
$info['Bono Pie'] = $venta->bonoPie()->pago()->valor('ufs');
$saldo -= $venta->bonoPie()->pago()->valor('ufs');
}
$info['Pie'] = '';
$info['Reajuste'] = '';
if ($venta->pie != 0) {
$info['Pie'] = $venta->pie()->valorPagado();
$saldo -= $venta->pie()->valorPagado();
if ($venta->pie()->reajuste != 0) {
$info['Reajuste'] = $venta->pie()->reajuste()->valor('ufs');
$saldo -= $venta->pie()->reajuste()->valor('ufs');
}
}
$info['Abono Contado'] = '';
if ($venta->escritura != 0) {
$info['Abono Contado'] = $venta->escritura()->pago()->valor('ufs');
$saldo -= $venta->escritura()->pago()->valor('ufs');
}
$info['Subsidio'] = '';
$info['Estado Subsidio'] = '';
if ($venta->subsidio != 0) {
$info['Subsidio'] = $venta->subsidio()->total('ufs');
$info['Estado Subsidio'] = implode(' - ', [
$venta->subsidio()->subsidio()->estado()->tipo()->descripcion,
$venta->subsidio()->pago()->estado()->tipo()->descripcion
]);
$saldo -= $venta->subsidio()->total('ufs');
}
$info['Credito'] = '';
$info['Banco'] = '';
$info['Estado Credito'] = '';
if ($venta->credito != 0) {
$info['Credito'] = $venta->credito()->pago()->valor('ufs');
$saldo -= $venta->credito()->pago()->valor('ufs');
if ($venta->credito()->pago()->banco != 0) {
$info['Banco'] = $venta->credito()->pago()->banco()->nombre;
}
$info['Estado Credito'] = $venta->credito()->pago()->estado()->tipo()->descripcion;
}
$info['Saldo'] = -$saldo;
$info['Escritura'] = '';
if ($venta->escriturado != 0) {
$info['Escritura'] = $venta->escriturado;
}
$info['Entrega'] = '';
if ($venta->entregado != 0) {
$info['Entrega'] = $venta->entregado;
}
$data []= $info;
}
$informe->addData($data);
return $informe->informe();
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.escrituras', compact('proyectos'));
}
}
public static function consolidacion()
{
$id_proyecto = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
$ventas = $proyecto->ventas();
set_time_limit(count($ventas));
$f = Carbon::today(config('app.timezone'));
setlocale(LC_TIME, 'es');
$data = [
[$proyecto->descripcion],
[strftime('%d de %B de %Y', $f->timestamp)],
[''],
['']
];
$columns = [
['name' => 'Fecha', 'style' => 'date'],
'Glosa',
['name' => 'Debe', 'style' => 'number'],
['name' => 'Haber', 'style' => 'number'],
['name' => 'Saldo', 'style' => 'number'],
'Comentario'
];
$bold_rows = [];
foreach ($ventas as $venta) {
$data []= ['Departamento ' . $venta->unidad()->descripcion . ' (' . format('ufs', $venta->valor_uf) . ' UF)'];
$data []= $columns;
$bold_rows []= count($data) - 1;
$ufs = 0;
$debe = 0;
$haber = 0;
$sum = 0;
if ($venta->pie != 0) {
$cuotas = $venta->pie()->cuotas();
foreach ($cuotas as $cuota) {
$sum += $cuota->pago()->valor();
$ufs += $cuota->pago()->valor('ufs');
$haber += $cuota->pago()->valor();
$info = [
$cuota->pago()->estado()->fecha,
'Pie - Cuota ' . $cuota->numero() . ' - ' . $venta->pie()->cuotas . ' (' . format('ufs', $cuota->pago()->valor('ufs')) . ' UF)',
'',
$cuota->pago()->valor(),
$sum
];
if ($cuota->pago()->estado()->estado < 2) {
$info []= 'No ha sido abonada.';
}
$data []= $info;
}
if ($venta->pie()->reajuste != 0) {
$sum += $venta->pie()->reajuste()->valor();
$ufs += $venta->pie()->reajuste()->valor('ufs');
$haber += $venta->pie()->reajuste()->valor();
$info = [
$venta->pie()->reajuste()->estado()->fecha,
'Reajuste (' . format('ufs', $venta->pie()->reajuste()->valor('ufs')) . ' UF)',
'',
$venta->pie()->reajuste()->valor(),
$sum
];
if ($venta->pie()->reajuste()->estado()->estado < 2) {
$info []= 'No ha sido abonado.';
}
$data []= $info;
}
}
if ($venta->escritura != 0) {
$sum += $venta->escritura()->pago()->valor();
$ufs += $venta->escritura()->pago()->valor('ufs');
$haber += $venta->escritura()->pago()->valor();
$info = [
$venta->escritura()->pago()->estado()->fecha,
'Abono Escritura (' . format('ufs', $venta->escritura()->pago()->valor('ufs')) . ' UF)',
'',
$venta->escritura()->pago()->valor(),
$sum
];
if ($venta->escritura()->pago()->estado()->estado < 2) {
$info []= 'No ha sido abonado.';
}
$data []= $info;
}
if ($venta->credito != 0) {
$sum += $venta->credito()->pago()->valor();
$ufs += $venta->credito()->pago()->valor('ufs');
$haber += $venta->credito()->pago()->valor();
$info = [
$venta->credito()->pago()->estado()->fecha,
'Crédito (' . format('ufs', $venta->credito()->pago()->valor('ufs')) . ' UF)',
'',
$venta->credito()->pago()->valor(),
$sum
];
if ($venta->credito()->pago()->estado()->estado < 2) {
$info []= 'No ha sido pagado.';
}
$data []= $info;
}
if ($venta->bono_pie != 0) {
try {
$sum -= $venta->bonoPie()->pago()->valor();
$debe += $venta->bonoPie()->pago()->valor();
$info = [
$venta->bonoPie()->pago()->estado()->fecha,
'Bono Pie (' . format('ufs', $venta->bonoPie()->pago()->valor('ufs')) . ' UF)'.
$venta->bonoPie()->pago()->valor(),
'',
$sum
];
$data []= $info;
$sum += $venta->bonoPie()->pago()->valor();
$haber += $venta->bonoPie()->pago()->valor();
$info = [
$venta->bonoPie()->pago()->estado()->fecha,
'Bono Pie (' . format('ufs', $venta->bonoPie()->pago()->valor('ufs')) . ' UF)'.
'',
$venta->bonoPie()->pago()->valor(),
$sum
];
$data []= $info;
} catch (\Exception $e) {
}
}
$info = [
'',
'TOTAL (' . format('ufs', $ufs) . ' UF)',
$debe,
$haber,
$sum
];
$data []= $info;
$bold_rows []= count($data) - 1;
$data []= [''];
}
/**
* Departamento #
* Fecha |Glosa |Debe |Haber |Saldo
* <fecha> |Pie - Cuota 1 - n (# UF) |- |$# |<sum>
* <fecha> |Reajuste (# UF) |- |$# |<sum>
* <fecha> |Abono Escritura (# UF) |- |$# |<sum>
* <fecha> |Crédito (# UF) |- |$# |<sum>
* <fecha> |Bono Pie (# UF) |$# |- |<sum>
* <fecha> |Bono Pie (# UF) |- |$# |<sum>
* <fecha> |Devolución (# UF) |$# |- |<sum>
* - |TOTAL (# UF) |<sumDebe> |<sumHaber> |<sum>
*/
array_walk($data, function(&$e, $i) use ($columns) {
if (count($e) < count($columns)) {
$n = count($columns) - count($e);
for ($j = 0; $j < $n; $j ++) {
$e []= '';
}
}
});
#$informe = new Informador('Consolidación - ' . $proyecto->descripcion);
$name = 'Consolidación';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$informe->addColumns($columns);
$informe->addData($data);
return $informe->informe();
}
public static function creditos_pendientes()
{
function creditos() {
$creditos = model(Credito::class)
->select('credito.*')
->join('venta', ['venta.credito', '=', 'credito.id'])
->join('pago', ['pago.id', '=', 'credito.pago'])
->rawJoin('JOIN (SELECT ep.* FROM (SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago ep ON ep.id = e0.id)', ['estado_pago.pago', '=', 'pago.id'], 'estado_pago')
->whereLt('estado_pago.estado', 2)
->where('venta.estado', 1)
->orderByAsc('estado_pago.fecha')
->findMany();
foreach ($creditos as $credito) {
yield $credito;
}
}
$informe = new Informador('Créditos Pendientes');
$columnas = ['Proyecto', 'Departamento', 'Valor', 'Fecha Escritura', 'Estado'];
$informe->addColumns($columnas);
$row = 0;
foreach (creditos() as $credito) {
$informe->addData($row, $credito->venta()->proyecto()->descripcion, 'Proyecto');
$informe->addData($row, $credito->venta()->unidad()->descripcion, 'Departamento');
$informe->addData($row, $credito->pago()->valor('ufs'), 'Valor');
$informe->addData($row, (($credito->venta()->escriturado) ? $credito->venta()->escriturado : $credito->pago()->estado()->fecha), 'Fecha Escritura');
$informe->addData($row, ucwords($credito->pago()->estado()->tipo()->descripcion), 'Estado');
$row ++;
}
$date = [
'numberFormat' => ['short-date']
];
$ufs = [
'numberFormat' => ['thousands']
];
$formats = ['Valor' => $ufs, 'Fecha Escritura' => $date];
$informe->addFormats($formats);
return $informe->informe();
}
public static function ventas()
{
if (get('proyecto')) {
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$ventas = $proyecto->ventas();
usort($ventas, function($a, $b) {
return $a->fecha()->timestamp - $b->fecha()->timestamp;
});
$procasa = model(Agente::class)->findOne(1);
$pa = model(ProyectoAgente::class)->where('agente', $procasa->id)->where('proyecto', $proyecto->id)->findOne();
if ($pa) {
$comision = $pa->comision / 100;
} else {
$comision = 0.03;
}
#$informe = new Informador('Ventas - ' . $proyecto->descripcion);
$name = 'Ventas';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = [
'Propietario',
['name' => 'Departamento', 'style' => 'number'],
['name' => 'Estacionamientos', 'style' => 'number'],
['name' => 'Bodegas', 'style' => 'number'],
'Fecha Venta',
['name' => 'Mes', 'style' => 'mes'],
'Tipo',
['name' => 'm² Ponderados', 'style' => 'amount'],
['name' => 'Valor Promesa', 'style' => 'amount'],
['name' => 'Bono Pie', 'style' => 'amount'],
'Operador',
['name' => 'Valor Operador', 'style' => 'amount'],
['name' => 'Premios', 'style' => 'amount'],
['name' => 'Subsidio', 'style' => 'amount'],
['name' => 'Ahorro', 'style' => 'amount'],
['name' => 'Credito', 'style' => 'amount'],
'Banco',
['name' => 'Valor Ests & Bods', 'style' => 'amount'],
['name' => 'Valor Neto', 'style' => 'amount'],
['name' => 'UF/m²*', 'style' => 'amount'],
['name' => 'Comision', 'style' => 'amount'],
['name' => 'Venta s/Comision', 'style' => 'amount']
];
$informe->addColumns($columnas);
$data = [];
foreach ($ventas as $venta) {
$info = [];
$info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto());
$info['Departamento'] = $venta->unidad()->descripcion;
$ests = [];
if ($venta->propiedad()->estacionamientos != '') {
$es = $venta->propiedad()->estacionamientos();
foreach ($es as $e) {
$ests []= $e->descripcion;
}
}
$info['Estacionamientos'] = implode(', ', $ests);
$bods = [];
if ($venta->propiedad()->bodegas != '') {
$bs = $venta->propiedad()->bodegas();
foreach ($bs as $b) {
$bods []= $b->descripcion;
}
}
$info['Bodegas'] = implode(', ', $bods);
$info['Fecha Venta'] = $venta->fecha()->format('d.m.Y');
$info['Mes'] = $venta->fecha()->format('M-y');
$info['Tipo'] = $venta->unidad()->abreviacion;
$info['m² Ponderados'] = $venta->unidad()->m2('vendible');
$info['Valor Promesa'] = $venta->valor_uf;
$info['Bono Pie'] = ($venta->bono_pie == 0 or $venta->bonoPie() === false) ? '' : $venta->bonoPie()->pago()->valor('ufs');
$info['Operador'] = ($venta->agente and $venta->agente()->agente()->tipo == 19) ? $venta->agente()->agente()->descripcion : '';
$info['Valor Operador'] = $venta->valorComision();
$promos = 0;
$ps = $venta->promociones();
if (count($ps) > 0) {
foreach ($ps as $promo) {
$promos += $promo->valor;
}
}
$info['Premios'] = $promos;
$info['Subsidio'] = 0;
$info['Ahorro'] = 0;
if ($venta->subsidio != 0) {
$info['Subsidio'] = $venta->subsidio()->subsidio()->valor('ufs');
$info['Ahorro'] = $venta->subsidio()->pago()->valor('ufs');
}
$info['Credito'] = 0;
$info['Banco'] = '';
if ($venta->credito != 0) {
$info['Credito'] = $venta->credito()->pago()->valor('ufs');
if ($venta->credito()->pago()->banco != 0) {
$info['Banco'] = $venta->credito()->pago()->banco()->nombre;
}
}
$info['Valor Ests & Bods'] = $venta->valorEstacionamientosYBodegas();
$info['Valor Neto'] = $venta->valorFinal();
$info['UF/m²*'] = $venta->uf_m2();
$info['Comision'] = $venta->valorFinal() * $comision;
$info['Venta s/Comision'] = $venta->valorFinal() - $info['Comision'];
$data []= $info;
}
$informe->addData($data);
$totals = [
'Propietario' => 'TOTAL',
'Departamento' => 'count',
'Estacionamientos' => 'count',
'Bodegas' => 'count',
'm² Ponderados' => 'sum',
'Valor Promesa' => 'sum',
'Bono Pie' => 'sum',
'Subsidio' => 'sum',
'Ahorro' => 'sum',
'Credito' => 'sum',
'Valor Operador' => 'sum',
'Premios' => 'sum',
'Valor Ests & Bods' => 'sum',
'Valor Neto' => 'sum',
'Comision' => 'sum'
];
$informe->addTotals($totals);
return $informe->informe();
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.ventas', compact('proyectos'));
}
}
public static function resumen_contabilidad()
{
if (get('proyecto')) {
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$ventas = $proyecto->ventas();
usort($ventas, function($a, $b) {
return $a->fecha()->timestamp - $b->fecha()->timestamp;
});
$name = 'Ventas';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = [
'Propietario',
['name' => 'Departamento', 'style' => 'general_number'],
['name' => 'Estacionamientos', 'style' => 'number'],
['name' => 'Bodegas', 'style' => 'number'],
'Fecha Venta',
['name' => 'Mes', 'style' => 'mes'],
'Tipo',
['name' => 'm² Ponderados', 'style' => 'amount'],
['name' => 'Valor Promesa', 'style' => 'amount'],
['name' => 'Pie [UF]', 'style' => 'amount'],
['name' => 'Pie [$]', 'style' => 'amount'],
['name' => 'Abono Escritura', 'style' => 'amount'],
['name' => 'Crédito', 'style' => 'amount'],
['name' => 'Cuotas', 'style' => 'number'],
['name' => 'Cuotas Pagadas', 'style' => 'number'],
['name' => 'Pie Pagado [UF]', 'style' => 'amount'],
['name' => 'Pie Pagado [$]', 'style' => 'amount']
];
$informe->addColumns($columnas);
$data = [];
foreach ($ventas as $venta) {
$info = [];
$info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto());
$info['Departamento'] = $venta->unidad()->descripcion;
$ests = [];
if ($venta->propiedad()->estacionamientos != '') {
$es = $venta->propiedad()->estacionamientos();
foreach ($es as $e) {
$ests []= $e->descripcion;
}
}
$info['Estacionamientos'] = implode(', ', $ests);
$bods = [];
if ($venta->propiedad()->bodegas != '') {
$bs = $venta->propiedad()->bodegas();
foreach ($bs as $b) {
$bods []= $b->descripcion;
}
}
$info['Bodegas'] = implode(', ', $bods);
$info['Fecha Venta'] = $venta->fecha()->format('d.m.Y');
$info['Mes'] = $venta->fecha()->format('M-y');
$info['Tipo'] = $venta->unidad()->abreviacion;
$info['m² Ponderados'] = $venta->unidad()->m2('vendible');
$info['Valor Promesa'] = $venta->valor_uf;
$info['Pie [UF]'] = 0;
$info['Pie [$]'] = 0;
if ($venta->pie()) {
$info['Pie [UF]'] = $venta->pie()->valor;
$info['Pie [$]'] = $venta->pie()->valorPesos();
}
$info['Abono Escritura'] = ($venta->escritura != 0) ? $venta->escritura()->valor('ufs') : ($venta->valor_uf - $venta->pie()->valor - (($venta->credito != 0) ? $venta->credito()->pago()->valor('ufs') : 0));
$info['Crédito'] = ($venta->credito != 0) ? $venta->credito()->pago()->valor('ufs') : 0;
$info['Cuotas'] = $venta->pie()->cuotas;
$info['Cuotas Pagadas'] = count($venta->pie()->pagadas());
$info['Pie Pagado [UF]'] = $venta->pie()->valorPagado('uf');
$info['Pie Pagado [$]'] = $venta->pie()->valorPagado('pesos');
$data []= $info;
}
$informe->addData($data);
$totals = [
'Departamento' => 'count',
'Estacionamientos' => 'count',
'Bodegas' => 'count',
'm² Ponderados' => 'sum',
'Valor Promesa' => 'sum',
'Pie' => 'sum',
'Pie Pagado' => 'sum'
];
$informe->addTotals($totals);
return $informe->informe();
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.resumen_contabilidad', compact('proyectos'));
}
}
public static function contabilidad()
{
if (get('proyecto')) {
$id = get('proyecto');
$fecha = get('fecha');
$mes = null;
if ($fecha != null) {
$mes = Carbon::parse($fecha);
}
$proyecto = model(Proyecto::class)->findOne($id);
$q = "SELECT pago.*, venta.id AS vid, venta.tipo AS ctipo, venta.pie AS pie
FROM (
SELECT pago.id, banco.nombre AS banco, pago.fecha, pago.valor, pago.uf, ep.estado, ep.fecha AS efecha
FROM pago JOIN banco ON banco.id = pago.banco JOIN ((
SELECT pago, MAX(id) AS id FROM estado_pago GROUP BY pago) e0 JOIN estado_pago ep ON ep.id = e0.id) ON ep.pago = pago.id
WHERE ep.estado > 0 ";
if ($mes != null) {
$q .= "AND (pago.fecha BETWEEN '" . $mes->format('Y-m-01') . "' AND '" . $mes->format('Y-m-t') . "'
OR ep.fecha BETWEEN '" . $mes->format('Y-m-01') . "' AND '" . $mes->format('Y-m-t') . "')";
}
$q .= ") pago JOIN (SELECT venta.*
FROM ((
SELECT venta.id, venta.pie, venta.propiedad, credito.pago, 'credito' AS tipo
FROM venta JOIN credito ON credito.id = venta.credito)
UNION ALL (
SELECT venta.id, venta.pie, venta.propiedad, escritura.pago, 'escritura' AS tipo
FROM venta JOIN escritura ON escritura.id = venta.escritura)
UNION ALL (
SELECT venta.id, venta.pie, venta.propiedad, cuota.pago, 'cuota' AS tipo
FROM venta JOIN cuota ON cuota.pie = venta.pie)) venta
JOIN propiedad ON propiedad.id = venta.propiedad
JOIN unidad ON unidad.id = propiedad.unidad_principal
WHERE unidad.proyecto = ?) venta
ON venta.pago = pago.id";
$st = \ORM::getDB()->prepare($q);
$st->execute([$id]);
if ($st->rowCount() > 0) {
$R = $st->fetchAll(\PDO::FETCH_OBJ);
#$informe = new Informador('Contabilidad - ' . (($mes != null) ? $mes->format('Y-m') . ' - ' : '') . $proyecto->descripcion);
$name = 'Contabilidad';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', 'Contabilidad - ' . (($mes != null) ? $mes->format('Y-m') . ' - ' : '') . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = ['Proyecto', 'Fecha', 'Banco', 'Departamento', 'RUT', 'Propietario', 'Glosa', 'Glosa2', (object) ['name' => 'Valor', 'style' => 'integer'], (object) ['name' => 'Valor UF', 'style' => 'currency']];
$informe->addColumns($columnas);
$data = [];
foreach ($R as $r) {
$info = [];
$info['Proyecto'] = $proyecto->descripcion;
$f1 = \Carbon\Carbon::parse($r->fecha, config('app.timezone'));
$f2 = \Carbon\Carbon::parse($r->efecha, config('app.timezone'));
$info['Fecha'] = ($f1->max($f2))->format('Y-m-d');
$info['Banco'] = $r->banco;
$venta = model(Venta::class)->findOne($r->vid);
$info['Departamento'] = $venta->unidad()->descripcion;
$info['RUT'] = $venta->propietario()->rut();
$info['Propietario'] = $venta->propietario()->nombreCompleto();
$info['Glosa'] = ucwords($r->ctipo);
$info['Glosa2'] = '';
if ($r->ctipo == 'cuota') {
$cuota = model(Cuota::class)->where('pago', $r->id)->findOne();
$info['Glosa'] = 'Pie - ' . format('ufs', $cuota->pie()->valor('ufs'), null, true);
$info['Glosa2'] = $cuota->numero() . ' - ' . $cuota->pie()->cuotas;
}
$info['Valor'] = $r->valor;
$info['Valor UF'] = '0';
if ($r->uf > 0) {
$info['Valor UF'] = $r->valor / $r->uf;
}
$data []= $info;
}
$informe->addData($data);
return $informe->informe();
}
} else {
setlocale(LC_TIME, 'es');
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.contabilidad', compact('proyectos'));
}
}
public static function para_comision()
{
$proyectos = model(Proyecto::class)->orderByAsc('descripcion')->findMany();
return view('informes.para_comision', compact('proyectos'));
}
public static function comisiones()
{
$id = post('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$unidades = explode('-', str_replace([';', '.', ':', ' ', PHP_EOL, '|', '+', ','], '-', post('unidades')));
$ventas = model(Venta::class)
->select('venta.*')
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
->where('unidad.proyecto', $proyecto->id)
->where('venta.estado', 1)
->whereIn('unidad.descripcion', $unidades)
->orderByExpr('FIELD(unidad.descripcion, ' . implode(', ', $unidades) . ')')
->findMany();
$ids = [];
$totales = (object) ['precio' => 0, 'neto' => 0, 'comision' => 0];
foreach ($ventas as $venta) {
$ids []= $venta->id;
$totales->precio += $venta->valor_uf;
$totales->neto += $venta->valorCorredora();
$totales->comision += $venta->valorCorredora() * 1.5 / 100;
}
return view('informes.comisiones', compact('ventas', 'proyecto', 'totales', 'ids'));
}
public static function comisiones_xlsx()
{
$id_ventas = explode(',', get('ventas'));
$ventas = model(Venta::class)
->whereIn('id', $id_ventas)
->orderByExpr('FIELD(id, ' . implode(', ', $id_ventas) . ')')
->findMany();
$informe = new Informador('Comisiones - ' . $ventas[0]->proyecto()->descripcion);
$columnas = ['Departamento', 'Estacionamientos', 'Bodegas', 'Propietario', 'Precio', '% Com', 'Com UF'];
$informe->addColumns($columnas);
$data = [];
foreach ($ventas as $venta) {
$info = [];
$info['Departamento'] = $venta->unidad()->descripcion;
$info['Estacionamientos'] = implode(' - ', $venta->propiedad()->estacionamientos('array'));
$info['Bodegas'] = implode(' - ', $venta->propiedad()->bodegas('array'));
$info['Propietario'] = $venta->propietario()->nombreCompleto();
$info['Precio'] = "'" . format('ufs', $venta->valorCorredora());
$info['% Com'] = '1,5 %';
$info['Com UF'] = "'" . format('ufs', $venta->valorCorredora() * 1.5 / 100);
$data []= $info;
}
$informe->addDatas($data);
return $informe->informe();
}
public static function cuotas()
{
$id_venta = get('venta');
$venta = model(Venta::class)->findOne($id_venta);
$name = 'Cuotas - ' . $venta->unidad()->descripcion;
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $venta->proyecto()->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = [
['name' => 'Cuota', 'style' => 'number'],
['name' => 'Fecha Cuota', 'style' => 'date'],
'Banco',
'Identificador',
['name' => 'Valor $', 'style' => 'number'],
['name' => 'Valor UF', 'style' => 'currency'],
['name' => 'Fecha Pago', 'style' => 'date']
];
$informe->addColumns($columnas);
$data = [];
foreach ($venta->pie()->cuotas() as $cuota) {
$info = [];
$info['Cuota'] = $cuota->numero();
$info['Fecha Cuota'] = $cuota->pago()->fecha()->format('Y-m-d');
$info['Banco'] = $cuota->pago()->banco()->descripcion;
$info['Identificador'] = $cuota->pago()->identificador;
$info['Valor $'] = $cuota->pago()->valor();
$info['Valor UF'] = $cuota->pago()->valor('ufs');
$info['Fecha Pago'] = $cuota->pago()->estado()->fecha()->format('Y-m-d');
$data []= $info;
}
$informe->addData($data);
return $informe->informe();
}
public static function resciliaciones()
{
if (get('proyecto')) {
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$ventas = $proyecto->resciliaciones();
usort($ventas, function($a, $b) {
return $a->fecha()->timestamp - $b->fecha()->timestamp;
});
$name = 'Resciliaciones';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = [
'Propietario',
['name' => 'Departamento', 'style' => 'number'],
['name' => 'Estacionamientos', 'style' => 'number'],
['name' => 'Bodegas', 'style' => 'number'],
'Fecha Venta',
'Fecha Resciliación',
['name' => 'Mes', 'style' => 'mes'],
'Tipo',
['name' => 'm² Ponderados', 'style' => 'amount'],
['name' => 'Valor Promesa', 'style' => 'amount'],
];
$informe->addColumns($columnas);
$data = [];
foreach ($ventas as $venta) {
$info = [];
$info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto());
$info['Departamento'] = $venta->unidad()->descripcion;
$ests = [];
if ($venta->propiedad()->estacionamientos != '') {
$es = $venta->propiedad()->estacionamientos();
foreach ($es as $e) {
$ests []= $e->descripcion;
}
}
$info['Estacionamientos'] = implode(', ', $ests);
$bods = [];
if ($venta->propiedad()->bodegas != '') {
$bs = $venta->propiedad()->bodegas();
foreach ($bs as $b) {
$bods []= $b->descripcion;
}
}
$info['Bodegas'] = implode(', ', $bods);
$info['Fecha Venta'] = $venta->fecha()->format('d.m.Y');
$info['Fecha Resciliación'] = $venta->estado()->fecha()->format('d.m.Y');
$info['Mes'] = $venta->estado()->fecha()->format('M-y');
$info['Tipo'] = $venta->unidad()->abreviacion;
$info['m² Ponderados'] = $venta->unidad()->m2('vendible');
$info['Valor Promesa'] = $venta->valor_uf;
$data []= $info;
}
$informe->addData($data);
$totals = [
'Departamento' => 'count',
'Estacionamientos' => 'count',
'Bodegas' => 'count',
'm² Ponderados' => 'sum',
'Valor Promesa' => 'sum'
];
$informe->addTotals($totals);
return $informe->informe();
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.resciliaciones', compact('proyectos'));
}
}
}

View File

@ -0,0 +1,74 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Inmobiliaria\Inmobiliaria;
use Incoviba\old\Inmobiliaria\TipoSociedad;
use Incoviba\old\Common\Banco;
class Inmobiliarias
{
use Controller;
public static function list()
{
$inmobiliarias = model(Inmobiliaria::class)->orderByAsc('abreviacion')->findMany();
return view('inmobiliarias.list', compact('inmobiliarias'));
}
public static function show()
{
$rut = get('rut');
$inmobiliaria = model(Inmobiliaria::class)->findOne($rut);
return view('inmobiliarias.show', compact('inmobiliaria'));
}
public static function add()
{
$sociedades = model(TipoSociedad::class)->findMany();
return view('inmobiliarias.add', compact('sociedades'));
}
public static function agregar()
{
list($rut, $dv) = explode('-', str_replace('.', '', post('rut')));
$inmobiliaria = model(Inmobiliaria::class)->findOne($rut);
if ($inmobiliaria) {
header('Location: ' . url('', ['p' => 'inmobiliarias', 'a' => 'show', 'rut' => $inmobiliaria->rut]));
die();
}
$inmobiliaria = model(Inmobiliaria::class)->create();
$inmobiliaria->rut = $rut;
$inmobiliaria->dv = $dv;
$inmobiliaria->razon = post('razon');
$inmobiliaria->abreviacion = post('abrev');
$inmobiliaria->sociedad = post('sociedad');
$inmobiliaria->save();
header('Location: ' . url('', ['p' => 'inmobiliarias', 'a' => 'show', 'rut' => $inmobiliaria->rut]));
}
public static function edit()
{
$sociedades = model(TipoSociedad::class)->findMany();
$rut = get('rut');
$inmobiliaria = model(Inmobiliaria::class)->findOne($rut);
$bancos = model(Banco::class)->findMany();
usort($bancos, function($a, $b) {
return strcmp($a->nombre, $b->nombre);
});
return view('inmobiliarias.edit', compact('inmobiliaria', 'bancos', 'sociedades'));
}
public static function do_edit()
{
$rut = get('rut');
$inmobiliaria = model(Inmobiliaria::class)->findOne($rut);
foreach (post() as $field => $value) {
if ($value != '' and $inmobiliaria->{$field} != $value) {
$inmobiliaria->{$field} = $value;
}
}
$inmobiliaria->save();
header('Location: ' . nUrl('inmobiliarias', 'show', ['rut' => $inmobiliaria->rut]));
}
}
?>

View File

@ -0,0 +1,47 @@
<?php
namespace App\Controller;
use Carbon\Carbon;
use App\Definition\Controller;
use Incoviba\old\Proyecto\Agente;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Proyecto\ProyectoAgente;
class Operadores
{
use Controller;
public static function agregar()
{
$proyecto = model(Proyecto::class)->findOne(get('proyecto'));
$operadores = model(Agente::class)
->select('agente.*')
->join('agente_tipo', ['agente_tipo.agente', '=', 'agente.id'])
->join('tipo_agente', ['tipo_agente.id', '=', 'agente_tipo.tipo'])
->where('tipo_agente.descripcion', 'operador')
->orderByAsc('agente.abreviacion')
->findMany();
$vigentes = array_map(function($item) {
return $item->agente()->agente();
}, $proyecto->operadoresVigentes());
echo view('proyectos.operadores.add', compact('proyecto', 'operadores', 'vigentes'));
}
public static function add()
{
$proyecto = model(Proyecto::class)->findOne(get('proyecto'));
$fecha = Carbon::today(config('app.timezone'));
foreach (post('operadores') as $op) {
$operador = model(Agente::class)->findOne($op);
$at = $operador->tipos(19);
$data = [
'proyecto' => $proyecto->id,
'agente' => $at->id,
'fecha' => $fecha->format('Y-m-d'),
'comision' => 2
];
$pa = model(ProyectoAgente::class)->create($data);
$pa->new();
}
header('Location: ' . nUrl('proyectos', 'show', ['proyecto' => $proyecto->id]));
}
}

View File

@ -0,0 +1,71 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Entrega;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Venta\Unidad;
use Stringy\Stringy;
class Other
{
use Controller;
protected static function setDefault()
{
self::$default = view('other.list');
}
public static function entregar_multiple()
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$file = $_FILES['entregas'];
$data = explode(PHP_EOL, trim(file_get_contents($file['tmp_name'])));
foreach ($data as $line) {
$info = explode(';', $line);
if ($info[0] == 'Departamento' or $info[1] == 'Fecha') {
continue;
}
$entrega = \Model::factory(Entrega::class)->create();
$unidad = \Model::factory(Unidad::class)->where('descripcion', $info[0])->where('proyecto', post('proyecto'))->find_one();
if (!$unidad->venta()->find_one()) {
echo 'x';
continue;
}
$venta = $unidad->venta()->find_one();
$entrega->fecha = \Carbon\Carbon::parse($info[1])->format('Y-m-d');
if ($venta->entrega == '0') {
$entrega->save();
$venta->entrega = $entrega->id;
$venta->save();
echo '.';
} else {
echo 'x';
}
}
} else {
$proyectos = \Model::factory(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('other.entregar_multiple', compact('proyectos'));
}
}
public static function capacidades()
{
$capacidades = [];
$controllers = glob(config('locations.app') . '/Controller/*.php');
foreach ($controllers as $controller) {
if (basename($controller) == 'Admin.php' or basename($controller) == 'Other.php') {
continue;
}
$class = Stringy::create($controller)->replace(config('locations.app'), '/App')->replace('.php', '')->replace('/', '\\')->__toString();
$ref = new \ReflectionClass($class);
$static = $ref->getMethods(\ReflectionMethod::IS_STATIC && \ReflectionMethod::IS_PUBLIC);
foreach ($static as $method) {
if ($method->name == 'setDefault' or $method->name == 'index') {
continue;
}
$capacidades []= $method;
}
}
return view('other.capacidades', compact('capacidades'));
}
}
?>

View File

@ -0,0 +1,271 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Proyecto\Pagare;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Proyecto\RenovacionPagare;
use Incoviba\old\Proyecto\TipoMonedaPagare;
class Pagares
{
use Controller;
public static function show()
{
$pagare = model(Pagare::class)->findOne(get('pagare'));
return view('proyectos.pagares.show', compact('pagare'));
}
public static function add()
{
$proyecto = model(Proyecto::class)->findOne(get('proyecto'));
return view('proyectos.pagares.add', compact('proyecto'));
}
public static function do_add()
{
$proyecto = model(Proyecto::class)->findOne(get('proyecto'));
$data = post();
$data['id'] = $data['numero'];
unset($data['numero']);
$data['proyecto'] = $proyecto->id;
$moneda = model(TipoMonedaPagare::class)->where('descripcion', $data['moneda'])->findOne();
$data['moneda'] = $moneda->id;
$fecha = ['year', 'month', 'day'];
$fecha_arr = array_filter($data, function($item) use ($fecha) {
return (array_search($item, $fecha) !== false);
}, \ARRAY_FILTER_USE_KEY);
uksort($fecha_arr, function($a, $b) use ($fecha) {
return array_search($a, $fecha) - array_search($b, $fecha);
});
foreach ($fecha as $f) {
unset($data[$f]);
}
array_walk($fecha_arr, function(&$item) {
if (strlen($item) < 4) {
$item = str_pad($item, 2, '0', \STR_PAD_LEFT);
}
});
$data['fecha'] = implode('-', $fecha_arr);
foreach ($fecha as &$key) {
$key .= '_banco';
}
$fecha_arr = array_filter($data, function($item) use ($fecha) {
return (array_search($item, $fecha) !== false);
}, \ARRAY_FILTER_USE_KEY);
uksort($fecha_arr, function($a, $b) use ($fecha) {
return array_search($a, $fecha) - array_search($b, $fecha);
});
foreach ($fecha as $f) {
unset($data[$f]);
}
array_walk($fecha_arr, function(&$item) {
if (strlen($item) < 4) {
$item = str_pad($item, 2, '0', \STR_PAD_LEFT);
}
});
$data['fecha_banco'] = implode('-', $fecha_arr);
$data['abonado'] = (int) $data['abonado'];
if ($data['abonado'] == 0) {
$data['fecha'] = '0000-00-00';
}
$pagare = model(Pagare::class)->create($data);
$pagare->save();
header('Location: ' . nUrl('pagares', 'show', ['pagare' => $pagare->id]));
}
public static function edit()
{
$pagare = model(Pagare::class)->findOne(get('pagare'));
return view('proyectos.pagares.edit', compact('pagare'));
}
public static function do_edit()
{
$pagare = model(Pagare::class)->findOne(get('pagare'));
$data = post();
if ($pagare->id != $data['numero']) {
foreach ($pagare->renovaciones() as $renovacion) {
$renovacion->pagare = $data['numero'];
$renovacion->save();
}
$pagare->id = $data['numero'];
$changed = true;
}
unset($data['numero']);
$moneda = model(TipoMonedaPagare::class)->where('descripcion', $data['moneda'])->findOne();
$data['moneda'] = $moneda->id;
$fecha = ['year', 'month', 'day'];
$fecha_arr = array_filter($data, function($item) use ($fecha) {
return (array_search($item, $fecha) !== false);
}, \ARRAY_FILTER_USE_KEY);
uksort($fecha_arr, function($a, $b) use ($fecha) {
return array_search($a, $fecha) - array_search($b, $fecha);
});
foreach ($fecha as $f) {
unset($data[$f]);
}
array_walk($fecha_arr, function(&$item) {
if (strlen($item) < 4) {
$item = str_pad($item, 2, '0', \STR_PAD_LEFT);
}
});
$data['fecha'] = implode('-', $fecha_arr);
foreach ($fecha as &$key) {
$key .= '_banco';
}
$fecha_arr = array_filter($data, function($item) use ($fecha) {
return (array_search($item, $fecha) !== false);
}, \ARRAY_FILTER_USE_KEY);
uksort($fecha_arr, function($a, $b) use ($fecha) {
return array_search($a, $fecha) - array_search($b, $fecha);
});
foreach ($fecha as $f) {
unset($data[$f]);
}
array_walk($fecha_arr, function(&$item) {
if (strlen($item) < 4) {
$item = str_pad($item, 2, '0', \STR_PAD_LEFT);
}
});
$data['fecha_banco'] = implode('-', $fecha_arr);
$data['abonado'] = (int) $data['abonado'];
if ($data['abonado'] == 0) {
$data['fecha'] = '0000-00-00';
}
$changed = false;
foreach ($data as $k => $v) {
if ($pagare->$k != $v) {
$pagare->$k = $v;
$changed = true;
if (strpos($k, 'fecha') !== false) {
$pagare->uf = 0;
}
}
}
if ($changed) {
$pagare->save();
}
header('Location: ' . nUrl('pagares', 'show', ['pagare' => $pagare->id]));
}
public static function edit_renovacion()
{
$renovacion = model(RenovacionPagare::class)->findOne(get('renovacion'));
return view('proyectos.pagares.edit_renovacion', compact('renovacion'));
}
public static function do_edit_renovacion()
{
$renovacion = model(RenovacionPagare::class)->findOne(get('renovacion'));
$data = post();
$fecha = ['year', 'month', 'day'];
$fecha_arr = array_filter($data, function($item) use ($fecha) {
return (array_search($item, $fecha) !== false);
}, \ARRAY_FILTER_USE_KEY);
uksort($fecha_arr, function($a, $b) use ($fecha) {
return array_search($a, $fecha) - array_search($b, $fecha);
});
foreach ($fecha as $f) {
unset($data[$f]);
}
array_walk($fecha_arr, function(&$item) {
if (strlen($item) < 4) {
$item = str_pad($item, 2, '0', \STR_PAD_LEFT);
}
});
$data['fecha'] = implode('-', $fecha_arr);
foreach ($fecha as &$key) {
$key .= '_banco';
}
$fecha_arr = array_filter($data, function($item) use ($fecha) {
return (array_search($item, $fecha) !== false);
}, \ARRAY_FILTER_USE_KEY);
uksort($fecha_arr, function($a, $b) use ($fecha) {
return array_search($a, $fecha) - array_search($b, $fecha);
});
foreach ($fecha as $f) {
unset($data[$f]);
}
array_walk($fecha_arr, function(&$item) {
if (strlen($item) < 4) {
$item = str_pad($item, 2, '0', \STR_PAD_LEFT);
}
});
$data['fecha_banco'] = implode('-', $fecha_arr);
$changed = false;
foreach ($data as $k => $v) {
if ($renovacion->$k != $v) {
$renovacion->$k = $v;
$changed = true;
if (strpos($k, 'fecha') !== false) {
$renovacion->uf = 0;
}
}
}
if ($changed) {
$renovacion->save();
}
header('Location: ' . nUrl('pagares', 'show', ['pagare' => $renovacion->pagare]));
}
public static function add_renovacion()
{
$pagare = model(Pagare::class)->findOne(get('pagare'));
return view('proyectos.pagares.add_renovacion', compact('pagare'));
}
public static function do_add_renovacion()
{
$pagare = model(Pagare::class)->findOne(get('pagare'));
$data = post();
$data['pagare'] = $pagare->id;
$fecha = ['year', 'month', 'day'];
$fecha_arr = array_filter($data, function($item) use ($fecha) {
return (array_search($item, $fecha) !== false);
}, \ARRAY_FILTER_USE_KEY);
uksort($fecha_arr, function($a, $b) use ($fecha) {
return array_search($a, $fecha) - array_search($b, $fecha);
});
foreach ($fecha as $f) {
unset($data[$f]);
}
array_walk($fecha_arr, function(&$item) {
if (strlen($item) < 4) {
$item = str_pad($item, 2, '0', \STR_PAD_LEFT);
}
});
$data['fecha'] = implode('-', $fecha_arr);
foreach ($fecha as &$key) {
$key .= '_banco';
}
$fecha_arr = array_filter($data, function($item) use ($fecha) {
return (array_search($item, $fecha) !== false);
}, \ARRAY_FILTER_USE_KEY);
uksort($fecha_arr, function($a, $b) use ($fecha) {
return array_search($a, $fecha) - array_search($b, $fecha);
});
foreach ($fecha as $f) {
unset($data[$f]);
}
array_walk($fecha_arr, function(&$item) {
if (strlen($item) < 4) {
$item = str_pad($item, 2, '0', \STR_PAD_LEFT);
}
});
$data['fecha_banco'] = implode('-', $fecha_arr);
$renovacion = model(RenovacionPagare::class)->create($data);
$renovacion->save();
header('Location: ' . nUrl('pagares', 'show', ['pagare' => $renovacion->pagare]));
}
}

View File

@ -0,0 +1,358 @@
<?php
namespace App\Controller;
use Carbon\Carbon;
use App\Definition\Controller;
use Incoviba\old\Venta\Pago;
use Incoviba\old\Venta\TipoPago;
use Incoviba\old\Venta\TipoEstadoPago;
use Incoviba\old\Common\Banco;
use Incoviba\old\Venta\Venta;
use Incoviba\old\Venta\EstadoPago;
class Pagos
{
use Controller;
public static function edit()
{
$id = get('pago');
$asociado = get('asociado');
$id_asociado = get($asociado);
$pago = model(Pago::class)->findOne($id);
$tipos = model(TipoPago::class)->orderByAsc('descripcion')->findMany();
$estados = model(TipoEstadoPago::class)->orderByAsc('descripcion')->findMany();
return view('ventas.pagos.edit', compact('pago', 'asociado', 'id_asociado', 'tipos', 'estados'));
}
public static function editar()
{
$id = get('pago');
$pago = model(Pago::class)->findOne($id);
$fp = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$tipo = model(TipoPago::class)->findOne(post('tipo'));
$valor = correctNumber(post('valor'));
$banco = model(Banco::class)->where('nombre', post('banco'))->findOne();
$fe = Carbon::createFromDate(post('yearestado'), post('monthestado'), post('dayestado'), config('app.timezone'));
$estado = model(TipoEstadoPago::class)->findOne(post('estado'));
$uf = uf($fe);
$est = $pago->estado();
if ($est->fecha != $fe->format('Y-m-d')) {
$est->fecha = $fe->format('Y-m-d');
$pago->uf = $uf->uf->value;
}
if ($est->estado != $estado->id) {
$est->estado = $estado->id;
}
if ($pago->fecha != $fp->format('Y-m-d')) {
$pago->fecha = $fp->format('Y-m-d');
}
if ($pago->tipo != $tipo->id) {
$pago->tipo = $tipo->id;
}
if ($pago->valor != $valor) {
$pago->valor = $valor;
}
if ($pago->identificador != post('identificador')) {
$pago->identificador = post('identificador');
}
if ($pago->pagador != post('pagador')) {
$pago->pagador = post('pagador');
}
if ($pago->banco != $banco->id) {
$pago->banco = $banco->id;
}
$est->save();
$pago->save();
header('Location: ' . url('', ['p' => get('asociado') . 's', 'a' => 'show', get('asociado') => get(get('asociado'))]));
}
public static function pendientes()
{
$ventas = model(Venta::class)
->select('venta.*')
->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', ['te.id', '=', 'ev.estado'], 'te')
->join('propiedad', ['propiedad.id', '=', 'venta.propiedad'])
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
->join('proyecto', ['proyecto.id', '=', 'unidad.proyecto'])
->where('te.activa', 1)
->orderByAsc('proyecto.descripcion')
->orderByExpr('LPAD(unidad.descripcion, 4, "0")')
->findMany();
$n = 30;
$mod = floor(count($ventas) / $n);
$i_rest = count($ventas) - count($ventas) % $mod + 1;
$rest = count($ventas) - $i_rest;
$lots = (object) ['size' => $mod, 'N' => $n, 'rest' => (object) [
'size' => $rest,
'start' => $i_rest
]
];
return view('ventas.pagos.pendientes', compact('ventas', 'lots'));
}
public static function para_pendientes()
{
$timezone = config('app.timezone');
$today = Carbon::today($timezone);
$days = [];
$fechas = [];
for ($i = $today->copy()->subDays(15); $i <= $today->copy()->addDays(15); $i = $i->copy()->addDay()) {
$days []= $i->format('Y-m-d');
$fechas []= $i->format('d-m-Y');
}
$pagos_pendientes = model(Pago::class)
->select('estado_pago.fecha')
->selectExpr('COUNT(pago.id)', 'cantidad')
->join('cuota', ['cuota.pago', '=', 'pago.id'])
->join('venta', ['venta.pie', '=', 'cuota.pie'])
->filter('filterEstado')
->where('estado_pago.estado', 0)
->where('venta.estado', 1)
->whereGte('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d'))
->whereLte('estado_pago.fecha', $today->copy()->addDays(15)->format('Y-m-d'))
->orderByAsc('estado_pago.fecha')
->groupBy('estado_pago.fecha')
->findMany();
$valores = array_fill(0, count($days), 0);
$anteriores = model(Pago::class)
->join('cuota', ['cuota.pago', '=', 'pago.id'])
->join('venta', ['venta.pie', '=', 'cuota.pie'])
->filter('filterEstado')
->where('estado_pago.estado', 0)
->where('venta.estado', 1)
->whereLt('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d'))
->count();
foreach ($pagos_pendientes as $pago) {
$valores[array_search($pago->fecha()->format('Y-m-d'), $days)] = $pago->cantidad;
}
$acum = [];
$sum = 0;
foreach ($valores as $valor) {
$sum += $valor;
$acum []= $sum;
}
$t = array_search($today->format('Y-m-d'), $days);
$color = array_merge(
array_fill(0, $t, 'red'),
['blue'],
array_fill(0, count($days) - $t, 'green')
);
$pagos = ['data' => $acum, 'historico' => $anteriores, 'backgroundColor' => $color];
$abonos_pendientes = model(Pago::class)
->select('estado_pago.fecha')
->selectExpr('COUNT(pago.id)', 'cantidad')
->filter('filterEstado')
->where('estado_pago.estado', 1)
->whereGte('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d'))
->whereLt('estado_pago.fecha', $today->copy()->format('Y-m-d'))
->orderByAsc('estado_pago.fecha')
->groupBy('estado_pago.fecha')
->findMany();
$anteriores = model(Pago::class)
->join('cuota', ['cuota.pago', '=', 'pago.id'])
->join('venta', ['venta.pie', '=', 'cuota.pie'])
->filter('filterEstado')
->where('estado_pago.estado', 1)
->where('venta.estado', 1)
->whereLt('estado_pago.fecha', $today->copy()->subDays(15)->format('Y-m-d'))
->count();
$valores = array_fill(0, count($days), 0);
foreach ($abonos_pendientes as $pago) {
$valores[array_search($pago->fecha()->format('Y-m-d'), $days)] = $pago->cantidad;
}
$acum = [];
$sum = 0;
foreach ($valores as $valor) {
$sum += $valor;
$acum []= $sum;
}
$color = array_fill(0, count($pagos), 'rgb(200, 0, 0)');
$abonos = ['data' => $acum, 'historico' => $anteriores, 'backgroundColor' => $color];
$output = ['count' => count($days), 'fechas' => $fechas, 'pagos' => $pagos, 'abonos' => $abonos];
echo json_encode($output);
}
public static function para_abonar()
{
$ids = json_decode(post('ids'));
//$id = get('id');
function checkPago(&$pagos, $tipo, $pago) {
if (!$pago) {
return;
}
if (!$pago->estado()) {
$pagos []= [
'tipo' => $tipo,
'pago' => $pago->asArray(),
'estado' => -1
];
return;
}
if ($pago->estado()->tipo()->descripcion == 'depositado') {
$pagos []= [
'tipo' => $tipo,
'pago' => $pago->asArray(),
'fecha' => format('shortDate', $pago->estado()->fecha),
'valor' => format('pesos', $pago->valor, true),
'estado' => 1
];
}
}
$output = [];
foreach ($ids as $id) {
$venta = model(Venta::class)->findOne($id);
if ($venta->estado()->tipo()->activa == 0) {
$output []= ['status' => -1, 'venta' => $venta->id];
continue;
}
$pagos = [];
if ($venta->pie()) {
foreach ($venta->pie()->cuotas() as $cuota) {
checkPago($pagos, 'Pie', $cuota->pago());
}
if ($venta->pie()->reajuste()) {
checkPago($pagos, 'Reajuste', $venta->pie()->reajuste());
}
}
if ($venta->credito()) {
checkPago($pagos, 'Credito', $venta->credito()->pago());
}
if ($venta->escritura()) {
checkPago($pagos, 'Abono Escritura', $venta->escritura()->pago());
}
if ($venta->subsidio()) {
checkPago($pagos, 'Subsidio', $venta->subsidio()->subsidio());
checkPago($pagos, 'Ahorro', $venta->subsidio()->pago());
}
if (count($pagos) <= 0) {
$output []= ['status' => -1, 'venta' => $venta->id];
continue;
}
$output []= [
'status' => 1,
'proyecto' => $venta->proyecto()->descripcion,
'venta' => $venta->id,
'propietario' => $venta->propietario()->nombreCompleto(),
'departamento' => $venta->unidad()->descripcion,
'pagos' => $pagos
];
}
return json_encode($output);
}
public static function rebotes()
{
$ids = json_decode(post('ids'));
$response = [];
foreach ($ids as $id) {
//$id = get('id');
$venta = model(Venta::class)->findOne($id);
$rebotes = $venta->pagos(-1);
if (count($rebotes) < 1) {
$response []= ['status' => -1, 'venta' => $venta->id];
continue;
}
usort($rebotes, function($a, $b) {
return $b->estado()->fecha()->diffInDays($a->estado()->fecha(), false);
});
$output = [];
$textos = [];
foreach ($rebotes as $rebote) {
$fuente = $rebote->fuente()[0];
$text = '<td>' . ucwords(str_replace('_', ' ', $fuente->tipo)) . '</td>';
$info = ['tipo' => ucwords(str_replace('_', ' ', $fuente->tipo))];
switch ($fuente->tipo) {
case('cuota'):
$text .= '<td>' . $fuente->obj->pie()->venta()->proyecto()->descripcion
. '</td><td><a href="' . nUrl('ventas', 'show', ['venta' => $fuente->obj->pie()->venta()->id])
. '">' . $fuente->obj->pie()->venta()->unidad()->descripcion . '</a></td><td>'
. $fuente->obj->pie()->venta()->propietario()->nombreCompleto()
. '</td><td>' . format('shortDate', $rebote->estado()->fecha) . '</td>';
$info['proyecto'] = $fuente->obj->pie()->venta()->proyecto()->descripcion;
$info['venta'] = $fuente->obj->pie()->venta()->id;
$info['departamento'] = $fuente->obj->pie()->venta()->unidad()->descripcion;
$info['propietario'] = $fuente->obj->pie()->venta()->propietario()->nombreCompleto();
$info['fecha'] = format('shortDate', $rebote->estado()->fecha);
break;
}
$text .= '<td>' . format('pesos', $rebote->valor('pesos'), true) . '</td>';
$info['valor'] = format('pesos', $rebote->valor('pesos'), true);
$output []= array_merge(['id' => $rebote->id], $info);
$textos []= ['id' => $rebote->id, 'text' => $text];
}
$response []= ['status' => 1, 'venta' => $venta->id, 'textos' => $textos, 'rebotes' => $output];
}
return json_encode($response);
}
public static function show()
{
$id = get('pago');
$asociado = get('asociado');
$id_asociado = get($asociado);
$pago = model(Pago::class)->findOne($id);
return view('ventas.pagos.show', compact('pago', 'asociado', 'id_asociado'));
}
public static function pagar()
{
$id = get('pago');
$pago = model(Pago::class)->findOne($id);
$asociado = get('asociado');
$id_asociado = get($asociado);
return view('ventas.pagos.pagar', compact('pago', 'asociado', 'id_asociado'));
}
public static function pagando()
{
$id = get('pago');
$pago = model(Pago::class)->findOne($id);
$asociado = get('asociado');
$id_asociado = get($asociado);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$data = [
'fecha' => $f->format('Y-m-d'),
'pago' => $pago->id,
'estado' => 1
];
$estado = model(EstadoPago::class)->create($data);
$estado->save();
header('Location: ' . url('', ['p' => $asociado . 's', 'a' => 'show', $asociado => $id_asociado]));
}
public static function abonar()
{
$id = get('pago');
$pago = model(Pago::class)->findOne($id);
$asociado = get('asociado');
$id_asociado = get($asociado);
return view('ventas.pagos.abonar', compact('pago', 'asociado', 'id_asociado'));
}
public static function abonando()
{
$id = get('pago');
$pago = model(Pago::class)->findOne($id);
$asociado = get('asociado');
$id_asociado = get($asociado);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$data = [
'fecha' => $f->format('Y-m-d'),
'pago' => $pago->id,
'estado' => 2
];
$estado = model(EstadoPago::class)->create($data);
$estado->save();
header('Location: ' . url('', ['p' => $asociado . 's', 'a' => 'show', $asociado => $id_asociado]));
}
}
?>

View File

@ -0,0 +1,104 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Pie;
use Incoviba\old\Venta\Venta;
use Incoviba\old\Venta\Pago;
use Carbon\Carbon;
class Pies
{
use Controller;
protected static function setDefault()
{
self::$default = self::list();
}
public static function list()
{
$proyecto = get('proyecto');
if ($proyecto == null) {
return self::listProyectos();
}
$proyecto = \Model::factory(Proyecto::class)->findOne($proyecto);
$ventas = $proyecto->ventas();
self::sort($ventas);
return view('ventas.list', compact('proyecto', 'ventas'));
}
public static function listProyectos()
{
$proyectos = \Model::factory(Proyecto::class)
->select('proyecto.*')
->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado')
->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo')
->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa')
->whereGte('etapa.orden', 4)
->groupBy('proyecto.id')
->findMany();
echo view('ventas.proyectos', compact('proyectos'));
}
public static function resumen()
{
$id = get('pie');
$pie = \Model::factory(\Incoviba\old\Venta\Pie::class)->findOne($id);
$venta = $pie->venta();
return view('ventas.pies.resumen', compact('venta'));
}
public static function reajustar()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
return view('ventas.pies.reajustar', compact('venta'));
}
public static function reajuste()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$pago = \Model::factory(Pago::class)->create();
$pago->fecha = $f->format('Y-m-d');
$pago->uf = (float) uf($f)->uf->value;
$pago->valor = str_replace('.', '', post('valor'));
$pago->new();
$pie = $venta->pie();
$pie->reajuste = $pago->id;
$pie->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function edit()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
return view('ventas.pies.edit', compact('venta'));
}
public static function editar()
{
$id = get('venta');
$venta = \Model::factory(Venta::class)->findOne($id);
$pie = $venta->pie();
$valor = correctNumber(post('valor'));
if ($pie->valor != $valor) {
$pie->valor = $valor;
}
if ($pie->cuotas != post('cuotas')) {
$pie->cuotas = post('cuotas');
}
$pie->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function asociar()
{
$id = get('pie');
$pie = \Model::factory(Pie::class)->findOne($id);
$pie->asociado = post('asociado');
$pie->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $pie->venta()->id]));
}
}
?>

View File

@ -0,0 +1,69 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Venta;
use Carbon\Carbon;
use Incoviba\nuevo\Venta\Observacion;
use Incoviba\nuevo\Venta\EstadoObservacion;
use Incoviba\nuevo\Venta\Postventa;
use Incoviba\nuevo\Venta\PostventaObservacion;
use Incoviba\nuevo\Venta\EstadoPostventa;
class Postventas
{
use Controller;
public static function add()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.postventas.add', compact('venta'));
}
public static function agregar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$observaciones = json_decode(post('observaciones'));
$postventa = model(Postventa::class)->create();
$postventa->venta_id = $venta->id;
$postventa->save();
$estado = model(EstadoPostventa::class)->create();
$estado->postventa_id = $postventa->id;
$estado->tipo_estado_postventa_id = 1;
$estado->fecha = $f->format('Y-m-d');
$estado->save();
foreach ($observaciones as $o) {
$observacion = model(Observacion::class)->create();
$observacion->texto = post('observacion' . $o);
$observacion->save();
$estado = model(EstadoObservacion::class)->create();
$estado->observacion_id = $observacion->id;
$estado->tipo_estado_observacion_id = 1;
$estado->fecha = $f->format('Y-m-d');
$estado->save();
$po = model(PostventaObservacion::class)->create();
$po->postventa_id = $postventa->id;
$po->observacion_id = $observacion->id;
$po->save();
}
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function show()
{
$id = get('postventa');
$postventa = model(Postventa::class)->findOne($id);
$venta = model(Venta::class)->findOne($postventa->venta_id);
return view('ventas.postventas.show', compact('postventa', 'venta'));
}
}
?>

View File

@ -0,0 +1,166 @@
<?php
namespace App\Controller;
use Carbon\Carbon;
use Stringy\Stringy;
use App\Definition\Controller;
use App\Service\Factory;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Proyecto\ProyectoTipoUnidad;
use Incoviba\old\Venta\Precio;
use Incoviba\old\Venta\EstadoPrecio;
use Incoviba\old\Venta\Unidad;
use Incoviba\old\Venta\TipoUnidad;
use Incoviba\old\Venta\TipoEstadoPrecio;
class Precios
{
use Controller;
public static function listProyectos()
{
$proyectos = \model(Proyecto::class)->orderByAsc('descripcion')->findMany();
return view('ventas.precios.proyectos', compact('proyectos'));
}
public static function list()
{
$proyecto = \model(Proyecto::class)->findOne(get('proyecto'));
return view('ventas.precios.list', compact('proyecto'));
}
public static function import()
{
$proyectos = \model(Proyecto::class)->orderByAsc('descripcion')->findMany();
return view('ventas.precios.import', compact('proyectos'));
}
public static function importar()
{
$proyecto = \model(Proyecto::class)->findOne(post('proyecto'));
$fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$file = explode(PHP_EOL, trim(file_get_contents($_FILES['archivo']['tmp_name'])));
$columnas = explode(';', array_shift($file));
$tr = model(TipoEstadoPrecio::class)->where('descripcion', 'reemplazado')->findOne()->id;
$tv = model(TipoEstadoPrecio::class)->where('descripcion', 'vigente')->findOne()->id;
foreach ($file as $line) {
if (trim($line) == '') {
continue;
}
$info = explode(';', $line);
$tipo = \model(TipoUnidad::class)->where('descripcion', $info[0])->findOne();
$unidad = \model(Unidad::class)->where('tipo', $tipo->id)->where('descripcion', $info[1])->where('proyecto', $proyecto->id)->findOne();
self::reemplazar($unidad->id, $info[2], $fecha, $tr, $tv);
}
header('Location: ' . nUrl('precios', 'list', ['proyecto' => $proyecto->id]));
}
public static function add()
{
$proyecto = \model(Proyecto::class)->findOne(get('proyecto'));
return view('ventas.precios.add', compact('proyecto'));
}
public static function agregar()
{
$proyecto = get('proyecto');
$fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$precios = [];
foreach (post() as $name => $valor) {
if ($valor == '' or strpos($name, 'precio') === false) {
continue;
}
list($tipo, $id) = explode(':', $name);
$tipo = trim(str_replace('precio', '', $tipo), '_');
$id = explode('-', $id);
switch (count($id)) {
case 1:
$precios []= ['tipo' => 'pt', 'id' => $id[0], 'valor' => $valor];
break;
case 2:
$exists = false;
foreach ($precios as $precio) {
if ($precio['tipo'] == 'pt' and $precio['id'] == $id[0]) {
$exists = true;
break;
}
}
if (!$exists) {
$precios []= ['tipo' => 'subtipo', 'id' => $id[1], 'pt' => $id[0], 'valor' => $valor];
}
break;
case 3:
$exists = false;
foreach ($precios as $precio) {
if ($precio['tipo'] == 'pt' and $precio['id'] == $id[0]) {
$exists = true;
break;
}
if ($precio['tipo'] == 'subtipo' and 'id' == $id[1] and 'pt' == $id[0]) {
$exists = true;
break;
}
}
if (!$exists) {
$precios []= ['tipo' => 'unidad', 'id' => $id[2], 'valor' => $valor];
}
break;
}
}
foreach ($precios as $precio) {
$precio = (object) $precio;
switch ($precio->tipo) {
case 'pt':
$pt = model(ProyectoTipoUnidad::class)->findOne($precio->id);
$pt->setPrecios($fecha, $precio->valor);
break;
case 'subtipo':
$pt = model(ProyectoTipoUnidad::class)->findOne($precio->pt);
$pt->setPreciosSubtipo($precios->id, $fecha, $precio->valor);
break;
case 'unidad':
$unidad = model(Unidad::class)->findOne($precio->id);
$unidad->setPrecio($fecha, $precio->valor);
break;
}
}
header('Location: ' . nUrl('precios', 'list', ['proyecto' => $proyecto]));
}
protected static function reemplazar(int $unidad_id, float $valor, \DateTime $fecha, int $tr = 0, int $tv = 0)
{
if ($tr == 0) {
$tr = model(TipoEstadoPrecio::class)->where('descripcion', 'reemplazado')->findOne()->id;
}
if ($tv == 0) {
$tv = model(TipoEstadoPrecio::class)->where('descripcion', 'vigente')->findOne()->id;
}
$olds = \model(Precio::class)->where('unidad', $unidad_id)->findMany();
if ($olds !== false) {
foreach ($olds as $old) {
if (!$old->vigente()) {
continue;
}
$data = [
'precio' => $old->id,
'fecha' => $fecha->format('Y-m-d'),
'estado' => $tr
];
$estado = \model(EstadoPrecio::class)->create($data);
$estado->save();
}
}
$data = [
'unidad' => $unidad_id,
'valor' => $valor
];
$precio = (new Factory(Precio::class))->where($data)->find();
if (!$precio) {
$precio = \model(Precio::class)->create($data);
$precio->save();
}
$data = [
'precio' => $precio->id,
'fecha' => $fecha->format('Y-m-d'),
'estado' => $tv
];
$estado = \model(EstadoPrecio::class)->create($data);
$estado->save();
}
}

View File

@ -0,0 +1,129 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Propietario;
use Incoviba\old\Common\Region;
use Incoviba\old\Common\Direccion;
use Incoviba\old\Venta\Venta;
class Propietarios
{
use Controller;
public static function edit()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$propietario = $venta->propietario();
$regiones = model(Region::class)->orderByAsc('numeracion')->findMany();
return view('ventas.propietarios.edit', compact('venta', 'propietario', 'regiones'));
}
public static function editar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$info = post();
list($info['rut'], $info['dv']) = explode('-', str_replace('.', '', $info['rut']));
$propietario = model(Propietario::class)->findOne($info['rut']);
if (!$propietario) {
$propietario = model(Propietario::class)->create();
}
if ($propietario->direccion != 0) {
$direccion = $propietario->direccion();
} else {
$direccion = model(Direccion::class)
->where('calle', post('calle'))
->where('numero', post('numero'))
->where('extra', post('extra'))
->where('comuna', post('comuna'))
->findOne();
if (!$direccion) {
$data = [
'calle' => post('calle'),
'numero' => post('numero'),
'extra' => post('extra'),
'comuna' => post('comuna')
];
$direccion = model(Direccion::class)->create($data);
}
}
if (isset($info['empresa'])) {
$info['apellido_paterno'] = '';
$info['apellido_materno'] = '';
}
if ($propietario->representante != 0) {
list($info['rep_rut'], $info['rep_dv']) = explode('-', str_replace('.', '', $info['rep_rut']));
$representante = $propietario->representante();
} elseif (isset($info['rep_rut'])) {
list($info['rep_rut'], $info['rep_dv']) = explode('-', str_replace('.', '', $info['rep_rut']));
$representante= model(Propietario::class)->findOne($info['rep_rut']);
if (!$representante) {
$representante= model(Propietario::class)->create();
}
}
$fields = ['rut', 'dv', 'nombres', 'apellido_paterno', 'apellido_materno'];
$change = false;
foreach ($fields as $key) {
if ($propietario->$key != $info[$key]) {
$propietario->$key = $info[$key];
$change = true;
}
}
if ($direccion->isNew()) {
$direccion->save();
}
if ($propietario->direccion != $direccion->id) {
$propietario->direccion = $direccion->id;
$change = true;
}
if ($change) {
d($propietario);
$propietario->save();
}
if (isset($info['rep_rut'])) {
$change = false;
if ($representante->rut != $info['rep_rut']) {
$representante->rut = $info['rep_rut'];
$representante->dv = $info['rep_dv'];
$change = true;
}
if ($representante->nombres != $info['rep_nombres']) {
$representante->nombres = $info['rep_nombres'];
$change = true;
}
if ($representante->apellido_paterno != $info['rep_apaterno']) {
$representante->apellido_paterno = $info['rep_apaterno'];
$change = true;
}
if ($representante->apellido_materno != $info['rep_amaterno']) {
$representante->apellido_materno = $info['rep_amaterno'];
$change = true;
}
if ($representante->direccion != $direccion->id) {
$representante->direccion = $direccion->id;
$change = true;
}
if ($change) {
$representante->save();
}
if ($propietario->representante != $representante->rut) {
$propietario->representante = $representante->rut;
$propietario->save();
}
}
if ($venta->propietario != $propietario->rut) {
$venta->propietario = $propietario->rut;
$venta->save();
}
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
}
?>

View File

@ -0,0 +1,77 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Proyecto\ProyectoTipoUnidad;
use Incoviba\old\Venta\Unidad;
use Incoviba\old\Venta\TipoUnidad;
class ProyectoTipoUnidades
{
use Controller;
protected static function setDefault()
{
self::$default = self::list();
}
public static function list()
{
d(get());
}
public static function edit()
{
$id = get('tipo_unidad');
$tipo = model(ProyectoTipoUnidad::class)->findOne($id);
$tipos = model(TipoUnidad::class)->findMany();
return view('proyectos.tipo_unidades.edit', compact('tipo', 'tipos'));
}
public static function editar()
{
$id = get('tipo_unidad');
$tipo = model(ProyectoTipoUnidad::class)->findOne($id);
$changed = false;
foreach (post() as $field => $value) {
if ($tipo->{$field} != $value) {
$tipo->{$field} = $value;
$changed = true;
}
}
if ($changed) {
$tipo->save();
}
header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $tipo->proyecto()->id]));
}
public static function add_unidad()
{
$id = get('tipo_unidad');
$tipo = model(ProyectoTipoUnidad::class)->findOne($id);
if ($tipo->tipo()->descripcion == 'departamento') {
return view('proyectos.unidades.add', compact('tipo'));
}
return view('proyectos.unidades.add2', compact('tipo'));
}
public static function assign()
{
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$tipos = model(ProyectoTipoUnidad::class)->where('proyecto', $proyecto->id)->findMany();
$libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany();
return view('proyectos.unidades.assign', compact('proyecto', 'tipos', 'libres'));
}
public static function asignar()
{
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany();
foreach ($libres as $unidad) {
$unidad->pt = post('tipo' . $unidad->id);
$unidad->save();
}
header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $proyecto->id]));
}
}

View File

@ -0,0 +1,327 @@
<?php
namespace App\Controller;
use Carbon\Carbon;
use App\Definition\Controller;
use Incoviba\old\Common\Direccion;
use Incoviba\old\Common\Region;
use Incoviba\nuevo\Common\Direccion as D;
use Incoviba\old\Inmobiliaria\Inmobiliaria;
use Incoviba\old\Proyecto\AvanceConstruccion;
use Incoviba\old\Proyecto\EstadoProyecto;
use Incoviba\old\Proyecto\Pagare;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Proyecto\ProyectoTipoUnidad;
use Incoviba\old\Proyecto\TipoEstadoProyecto;
use Incoviba\old\Proyecto\TipoMonedaPagare;
use Incoviba\old\Venta\TipoUnidad;
use Incoviba\old\Venta\Unidad;
class Proyectos
{
use Controller;
protected static function setDefault()
{
self::$default = self::list();
}
public static function list()
{
$id_inmobiliaria = get('inmobiliaria');
if ($id_inmobiliaria != null) {
$proyectos = model(Proyecto::class)->where('inmobiliaria', $id_inmobiliaria);
} else {
$proyectos = model(Proyecto::class);
}
$proyectos = $proyectos->order_by_asc('descripcion')->findMany();
return view('proyectos.list', compact('proyectos'));
}
public static function show()
{
$id_proyecto = get('proyecto');
if ($id_proyecto == null) {
header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'list']));
}
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
$estados = model(TipoEstadoProyecto::class)->findMany();
foreach ($estados as &$estado) {
$estado = $estado->asArray()['orden'] + 1;
}
$colors = [];
$ventas_pt = (object) ['fields' => [], 'data' => [], 'totales' => [], 'vendidas' => []];
$ventas = $proyecto->ventas('fecha');
$months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
if (count($ventas) > 0) {
$inicio = $ventas[0]->fecha()->format('Y');
$fin = $ventas[count($ventas) - 1]->fecha()->format('Y');
$end = $ventas[count($ventas) - 1]->fecha()->format('M');
for ($y = $inicio; $y <= $fin; $y ++) {
foreach ($months as $month) {
$ventas_pt->fields []= $y . ' ' . $month;
if ($y == $fin and $month == $end) {
break;
}
}
}
}
foreach ($proyecto->tipologias() as $tipo) {
if (!isset($ventas_pt->data[$tipo->tipologia->descripcion])) {
$ventas_pt->data[$tipo->tipologia->descripcion] = [];
$ventas_pt->data[$tipo->tipologia->descripcion] = array_fill(0, count($ventas_pt->fields), 0);
$ventas_pt->totales[$tipo->tipologia->descripcion] = 0;
$ventas_pt->vendidas[$tipo->tipologia->descripcion] = 0;
}
foreach ($tipo->tipos as $pt) {
foreach ($pt->ventas('fecha') as $venta) {
$ventas_pt->data[$tipo->tipologia->descripcion][array_search($venta->fecha()->format('Y M'), $ventas_pt->fields)] ++;
$ventas_pt->vendidas[$tipo->tipologia->descripcion] ++;
}
$ventas_pt->totales[$tipo->tipologia->descripcion] += count($pt->unidades());
}
}
foreach ($ventas_pt->data as $tipo => $data) {
$acum = 0;
foreach ($data as $i => $cantidad) {
$acum += $cantidad;
$ventas_pt->data[$tipo][$i] = round($acum / $ventas_pt->totales[$tipo] * 100, 2);
}
}
$meses = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'];
array_walk($ventas_pt->fields, function(&$item) use ($meses, $months) {
$item = str_replace($months, $meses, $item);
});
for ($i = 0; $i < 10; $i ++) {
$colors[$i] = 'rgb(' . mt_rand(0, 255) . ', ' . mt_rand(0, 255) . ', ' . mt_rand(0, 255) . ')';
}
return view('proyectos.show', compact('proyecto', 'estados', 'colors', 'ventas_pt'));
}
public static function historial()
{
$proyecto = model(Proyecto::class)->findOne(get('proyecto'));
return view('proyectos.historia', compact('proyecto'));
}
public static function advance()
{
$id_proyecto = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
$estados = model(TipoEstadoProyecto::class)->whereGt('orden', $proyecto->estado()->tipo()->orden)->orderByAsc('orden')->findMany();
return view('proyectos.advance', compact('proyecto', 'estados'));
}
public static function avanzar()
{
$id_proyecto = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
$id_tipo = post('estado');
$tipo = model(TipoEstadoProyecto::class)->findOne($id_tipo);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$tipos = model(TipoEstadoProyecto::class)
->whereGt('orden', $proyecto->estado()->tipo()->orden)
->whereLte('orden', $tipo->orden)
->orderByAsc('orden')
->findMany();
foreach ($tipos as $t) {
$estado = model(EstadoProyecto::class)->create();
$estado->proyecto = $proyecto->id;
$estado->estado = $t->id;
$estado->fecha = $f->format('Y-m-d');
$estado->save();
}
header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'show', 'proyecto' => $proyecto->id]));
}
public static function avance()
{
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$av = post('avance') / 100;
$ep = (double) post('estado_pago');
$avance = model(AvanceConstruccion::class)
->where('proyecto', $proyecto->id)
->where('fecha', $f->format('Y-m-d'))
->findOne();
if (!$avance) {
$data = [
'proyecto' => $proyecto->id,
'fecha' => $f->format('Y-m-d'),
'numero' => post('numero'),
'avance' => $av,
'estado_pago' => $ep
];
$avance = model(AvanceConstruccion::class)->create($data);
}
$avance->save();
header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'historial', 'proyecto' => $proyecto->id]));
}
public static function add()
{
$rut = get('inmobiliaria');
$inmobiliarias = model(Inmobiliaria::class)->orderByAsc('abreviacion')->findMany();
$regiones = model(Region::class)->orderByAsc('numeracion')->findMany();
return view('proyectos.add', compact('inmobiliarias', 'rut', 'regiones'));
}
public static function agregar()
{
$proyecto = model(Proyecto::class)->where('descripcion', post('descripcion'))->where('inmobiliaria', post('inmobiliaria'))->find_one();
if ($proyecto) {
header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'show', 'proyecto' => $proyecto->id]));
die();
}
$proyecto = model(Proyecto::class)->create();
$proyecto->descripcion = post('descripcion');
$proyecto->inmobiliaria = post('inmobiliaria');
$direccion = model(Direccion::class)
->where('calle', post('calle'))
->where('numero', post('numero'))
->where('extra', post('extra'))
->where('comuna', post('comuna'))
->findOne();
if (!$direccion) {
$direccion = model(Direccion::class)->create();
$direccion->calle = post('calle');
$direccion->numero = post('numero');
$direccion->extra = post('extra');
$direccion->comuna = post('comuna');
$direccion->save();
}
$proyecto->direccion = $direccion->id;
$proyecto->save();
$fecha = Carbon::parse(post('year'), post('month'), post('day'), config('app.timezone'));
$estado = model(EstadoProyecto::class)->create();
$estado->proyecto = $proyecto->id;
$estado->estado = 1;
$estado->fecha = $fecha->format('Y-m-d');
$estado->save();
header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'show', 'proyecto' => $proyecto->id]));
}
public static function disponibles()
{
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
return view('proyectos.disponibles', compact('proyecto'));
}
public static function list_unidades()
{
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany();
return view('proyectos.unidades.list', compact('proyecto', 'libres'));
}
public static function add_tipo_unidad()
{
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$tipos = model(TipoUnidad::class)->findMany();
return view('proyectos.tipo_unidades.add', compact('proyecto', 'tipos'));
}
public static function agregar_tipo_unidad()
{
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
$data = post();
$data['proyecto'] = $proyecto->id;
$tipo = model(ProyectoTipoUnidad::class)->where('proyecto', $data['proyecto'])
->where('tipo', $data['tipo'])->where('nombre', $data['nombre'])->findOne();
if ($tipo === false) {
$tipo = model(ProyectoTipoUnidad::class)->create($data);
$tipo->save();
}
header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $proyecto->id]));
}
public static function construccion()
{
$id = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id);
return view('proyectos.construccion', compact('proyecto'));
}
public static function editar_avance()
{
$avance = model(AvanceConstruccion::class)->findOne(get('avance'));
return view('proyectos.avances.edit', compact('avance'));
}
public static function edit_avance()
{
$avance = model(AvanceConstruccion::class)->findOne(get('avance'));
$cols = [
'day',
'month',
'year',
'avance',
'estado_pago',
'pagado',
'day_pago',
'month_pago',
'year_pago'
];
$data = array_filter(post(), function($key) use ($cols) {
return (array_search($key, $cols) !== false);
}, \ARRAY_FILTER_USE_KEY);
$data['fecha'] = implode('-', [$data['year'], $data['month'], $data['day']]);
unset($data['year']);
unset($data['month']);
unset($data['day']);
$data['fecha_pagado'] = implode('-', [$data['year_pago'], $data['month_pago'], $data['day_pago']]);
unset($data['year_pago']);
unset($data['month_pago']);
unset($data['day_pago']);
$data['avance'] /= 100;
$avance->edit($data);
header('Location: ' . nUrl('proyectos', 'construccion', ['proyecto' => $avance->proyecto]));
}
public static function reservas()
{
$proyecto = model(Proyecto::class)->findOne(get('proyecto'));
$pisos = [];
$totales = [];
foreach ($proyecto->unidades('departamento') as $unidad) {
if (!isset($pisos[$unidad->piso - 1])) {
$piso = (object) ['descripcion' => $unidad->piso, 'unidades' => []];
$pisos[$unidad->piso - 1] = $piso;
}
if (!isset($totales[$unidad->linea()])) {
$totales[$unidad->linea()] = (object) ['ventas' => 0, 'reservas' => 0];
}
$pisos[$unidad->piso - 1]->unidades[$unidad->linea()] = $unidad;
if ($unidad->isVendida()) {
$totales[$unidad->linea()]->ventas ++;
}
if ($unidad->isReservada()) {
$totales[$unidad->linea()]->reservas ++;
}
}
ksort($pisos);
$max_unidades = 0;
foreach ($pisos as $piso) {
if (count($piso->unidades) > $max_unidades) {
$max_unidades = count($piso->unidades);
}
}
return view('proyectos.reservas.base', compact('proyecto', 'pisos', 'max_unidades', 'totales'));
}
public function unidades()
{
if (get('proyecto')) {
$proyecto = model(Proyecto::class)->findOne(get('proyecto'));
$libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany();
return view('proyectos.unidades.list', compact('proyecto', 'libres'));
}
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->findMany();
return view('proyectos.unidades.proyectos', compact('proyectos'));
}
}
?>

View File

@ -0,0 +1,90 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Venta\Venta;
use Incoviba\old\Venta\EstadoPago;
use Carbon\Carbon;
class Reajustes
{
use Controller;
public static function edit()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.pies.reajustes.edit', compact('venta'));
}
public static function editar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$uf = uf($f);
$valor = correctNumber(post('valor'));
if ($valor == '') {
$valor_uf = correctNumber(post('valor_uf'));
$valor = $valor_uf * $uf->uf->value;
}
$pago = $venta->pie()->reajuste();
if ($pago->valor != $valor) {
$pago->valor = $valor;
}
if ($pago->fecha != $f->format('Y-m-d')) {
$pago->fecha = $f->format('Y-m-d');
$pago->uf = $uf->uf->value;
}
$pago->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function pagar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.pies.reajustes.pagar', compact('venta'));
}
public static function pagado()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$data = [
'pago' => $venta->pie()->reajuste()->id,
'fecha' => $f->format('Y-m-d'),
'estado' => 1
];
$estado = model(EstadoPago::class)->create($data);
$estado->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function abonar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.pies.reajustes.abonar', compact('venta'));
}
public static function abonado()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$data = [
'pago' => $venta->pie()->reajuste()->id,
'fecha' => $f->format('Y-m-d'),
'estado' => 2
];
$estado = model(EstadoPago::class)->create($data);
$estado->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
}
?>

View File

@ -0,0 +1,39 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use App\Helper\Color;
use App\Helper\Line;
use Incoviba\common\Registry as RModel;
class Registros
{
use Controller;
public static function list()
{
$registros = model(RModel::class)->orderByDesc('time')->findMany();
$ini = new Color(0, 100, 0);
$end = new Color(255, 255, 255);
$colores = self::colores($end, $ini, 100);
return view('admin.registros.list', compact('registros', 'colores'));
}
public static function show()
{
$registro = model(RModel::class)->findOne(get('registro'));
$ini = new Color(0, 100, 0);
$end = new Color(255, 255, 255);
$colores = self::colores($end, $ini, 100);
return view('admin.registros.show', compact('registro', 'colores'));
}
protected static function colores($ini, $end, $max)
{
$current = $ini->toVector();
$colores = [];
$line = new Line($ini->toVector(), $end->toVector());
for ($i = 0; $i < $max; $i ++) {
$colores[$i] = new Color($current);
$current = $line->move($current, $line->length() / $max);
}
return $colores;
}
}

View File

@ -0,0 +1,184 @@
<?php
namespace App\Controller;
use Carbon\Carbon;
use App\Definition\Controller;
use Incoviba\old\Venta\Venta;
use Incoviba\old\Venta\Subsidio;
use Incoviba\old\Venta\Pago;
use Incoviba\old\Venta\EstadoPago;
use Incoviba\old\Venta\TipoEstadoPago;
class Subsidios
{
use Controller;
public static function add()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
echo view('ventas.subsidios.add', compact('venta'));
}
public static function do_add()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$uf = uf($f);
$pago1 = model(Pago::class)->create();
$valor = post('ahorro_uf') * $uf->uf->value;
if (post('ahorro') != null) {
$valor = post('ahorro');
}
$pago1->valor = $valor;
$pago1->fecha = $f->format('Y-m-d');
$pago1->uf = $uf->uf->value;
$pago2 = model(Pago::class)->create();
$valor = post('subsidio_uf') * $uf->uf->value;
if (post('subsidio') != null) {
$valor = post('subsidio');
}
$pago2->valor = $valor;
$pago2->fecha = $f->format('Y-m-d');
$pago2->uf = $uf->uf->value;
$pago1->new();
$pago2->new();
$subsidio = model(Subsidio::class)->create();
$subsidio->pago = $pago1->id;
$subsidio->subsidio = $pago2->id;
$subsidio->save();
$venta->subsidio = $subsidio->id();
$venta->save();
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
}
public static function edit()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
echo view('ventas.subsidios.edit', compact('venta'));
}
public static function do_edit()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$uf = uf($f);
$pago1 = $venta->subsidio()->pago();
$valor = post('ahorro_uf') * $uf->uf->value;
if (post('ahorro') != null) {
$valor = post('ahorro');
}
$pago1->valor = $valor;
$pago1->fecha = $f->format('Y-m-d');
$pago1->uf = $uf->uf->value;
$pago2 = $venta->subsidio()->subsidio();
$valor = post('subsidio_uf') * $uf->uf->value;
if (post('subsidio') != null) {
$valor = post('subsidio');
}
$pago2->valor = $valor;
$pago2->fecha = $f->format('Y-m-d');
$pago2->uf = $uf->uf->value;
$pago1->save();
$pago2->save();
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
}
public static function pagar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$tipo = get('tipo');
switch($tipo) {
case 'subsidio':
$pago = $venta->subsidio()->subsidio();
break;
case 'pago':
$pago = $venta->subsidio()->pago();
break;
default:
$pago = null;
}
echo view('ventas.subsidios.pagar', compact('venta', 'pago'));
}
public static function do_pagar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$tipo = post('tipo');
switch($tipo) {
case 'subsidio':
$pago = $venta->subsidio()->subsidio();
break;
case 'pago':
$pago = $venta->subsidio()->pago();
break;
default:
$pago = null;
}
$pago->valor = post('valor');
$tipo = model(TipoEstadoPago::class)->where('descripcion', 'depositado')->findOne();
$data = [
'pago' => $pago->id,
'fecha' => $f->format('Y-m-d'),
'estado' => $tipo->id
];
$estado = model(EstadoPago::class)->create($data);
$pago->save();
$estado->save();
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
}
public static function abonar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$tipo = get('tipo');
switch($tipo) {
case 'subsidio':
$pago = $venta->subsidio()->subsidio();
break;
case 'pago':
$pago = $venta->subsidio()->pago();
break;
default:
$pago = null;
}
echo view('ventas.subsidios.abonar', compact('venta', 'pago'));
}
public static function do_abonar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$tipo = post('tipo');
switch($tipo) {
case 'subsidio':
$pago = $venta->subsidio()->subsidio();
break;
case 'pago':
$pago = $venta->subsidio()->pago();
break;
default:
$pago = null;
}
$pago->valor = post('valor');
$tipo = model(TipoEstadoPago::class)->where('descripcion', 'abonado')->findOne();
$data = [
'pago' => $pago->id,
'fecha' => $f->format('Y-m-d'),
'estado' => $tipo->id
];
$estado = model(EstadoPago::class)->create($data);
$pago->save();
$estado->save();
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
}
}

View File

@ -0,0 +1,111 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Proyecto\Proyecto;
use Carbon\Carbon;
use Incoviba\nuevo\Proyecto\Tema;
class Temas
{
use Controller;
public static function add()
{
$proyectos = model(Proyecto::class)->orderByAsc('descripcion')->findMany();
return view('temas.add', compact('proyectos'));
}
public static function agregar()
{
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$data = [
"proyecto_id" => post('proyecto'),
"inicio" => $f->format('Y-m-d'),
"texto" => post('texto')
];
$tema = model(Tema::class)->create($data);
$tema->save();
header('Location: ' . url('', ['p' => 'temas', 'a' => 'list']));
}
public static function list()
{
$temas = model(Tema::class)->findMany();
$t = Carbon::today(config('app.timezone'));
foreach ($temas as $i => $tema) {
if ($tema->cierre()->year != -1 and $t->diff($tema->cierre())->days > 10) {
unset($temas[$i]);
}
}
$temas = array_values($temas);
usort($temas, function($a, $b) {
$p = strcmp($a->proyecto()->descripcion, $b->proyecto()->descripcion);
if ($p == 0) {
$f = $b->inicio()->diff($a->inicio())->format('%r%a');
if ($f == 0) {
return $a->id - $b->id;
}
return $f;
}
return $p;
});
return view('temas.list', compact('temas'));
}
public static function edit()
{
$id = get('tema');
$tema = model(Tema::class)->findOne($id);
$proyectos = model(Proyecto::class)->orderByAsc('descripcion')->findMany();
return view('temas.edit', compact('tema', 'proyectos'));
}
public static function editar()
{
$id = get('tema');
$tema = model(Tema::class)->findOne($id);
$proyecto = post('proyecto');
$changed = false;
if ($tema->proyecto_id != $proyecto) {
$tema->proyecto_id = $proyecto;
$changed = true;
}
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
if ($tema->inicio() != $f) {
$tema->inicio = $f->format('Y-m-d');
$changed = true;
}
$texto = post('texto');
if ($tema->texto != $texto) {
$tema->texto = $texto;
$changed = true;
}
if ($changed) {
$tema->save();
}
header('Location: ' . url('', ['p' => 'temas', 'a' => 'list']));
}
public static function cerrar()
{
$id = get('tema');
$tema = model(Tema::class)->findOne($id);
$f = Carbon::today(config('app.timezone'));
$tema->cierre = $f->format('Y-m-d');
$tema->save();
header('Location: ' . url('', ['p' => 'temas', 'a' => 'list']));
}
public static function abrir()
{
$id = get('tema');
$tema = model(Tema::class)->findOne($id)->as_array();
unset($tema['id'], $tema['cierre'], $tema['created_at'], $tema['updated_at']);
$tema = model(Tema::class)->create($tema);
$tema->save();
header('Location: ' . url('', ['p' => 'temas', 'a' => 'list']));
}
}
?>

View File

@ -0,0 +1,126 @@
<?php
namespace App\Controller;
use App\Definition\Controller;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Venta\TipoUnidad;
use Incoviba\old\Proyecto\ProyectoTipoUnidad;
use Incoviba\old\Venta\Unidad;
class Unidades
{
use Controller;
public static function agregar()
{
$id = get('tipo');
$tipo = model(ProyectoTipoUnidad::class)->findOne($id);
$len = strlen(post('total'));
$unis = json_decode(post('unidades'));
$data = [];
foreach ($unis as $n_unidad) {
if ($tipo->tipo()->descripcion == 'departamento') {
$ini = post('piso_ini' . $n_unidad);
$end = post('piso_end' . $n_unidad);
$subtipo = post('linea' . $n_unidad);
$orientacion = post('orientacion' . $n_unidad);
for ($piso = $ini; $piso <= $end; $piso ++) {
$descripcion = $piso . str_pad(post('linea' . $n_unidad), $len, '0', \STR_PAD_LEFT);
$data []= [
'proyecto' => $tipo->proyecto()->id,
'tipo' => $tipo->tipo()->id,
'subtipo' => $subtipo,
'piso' => $piso,
'descripcion' => $descripcion,
'abreviacion' => $tipo->abreviacion,
'm2' => $tipo->m2,
'terraza' => $tipo->terraza,
'logia' => $tipo->logia,
'orientacion' => $orientacion,
'pt' => $tipo->id
];
}
} else {
$descripcion = post('descripcion' . $n_unidad);
$piso = post('piso' . $n_unidad);
$data []= [
'proyecto' => $tipo->proyecto()->id,
'tipo' => $tipo->tipo()->id,
'piso' => $piso,
'descripcion' => $descripcion,
'abreviacion' => $tipo->abreviacion,
'm2' => $tipo->m2,
'terraza' => $tipo->terraza,
'logia' => $tipo->logia,
'pt' => $tipo->id
];
}
}
foreach ($data as $uni) {
$unidad = model(Unidad::class)
->where('descripcion', $uni['descripcion'])
->where('proyecto', $uni['proyecto'])
->where('tipo', $uni['tipo'])
->findOne();
if ($unidad) {
continue;
}
$unidad = model(Unidad::class)->create($uni);
$unidad->save();
}
header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'list_unidades', 'proyecto' => $tipo->proyecto()->id]));
}
public static function edit()
{
$id = get('unidad');
$unidad = model(Unidad::class)->findOne($id);
$tipos = model(ProyectoTipoUnidad::class)->where('proyecto', $unidad->proyecto()->id)->findMany();
$abreviaciones = ['N', 'NE', 'E', 'SE', 'S', 'SO', 'O', 'NO'];
$descripciones = ['Norte', 'Noreste', 'Este', 'Sureste', 'Sur', 'Suroeste', 'Oeste', 'Noroeste'];
$orientaciones = [];
foreach ($abreviaciones as $i => $ab) {
$orientaciones []= (object) ['abreviacion' => $ab, 'descripcion' => $descripciones[$i]];
}
return view('proyectos.unidades.edit', compact('unidad', 'tipos', 'orientaciones'));
}
public static function editar()
{
$id = get('unidad');
$unidad = model(Unidad::class)->findOne($id);
$change = false;
$fields = ['descripcion', 'tipo', 'piso', 'linea', 'orientacion'];
foreach ($fields as $field) {
$f = $field;
if ($f == 'tipo') {
$f = 'pt';
}
if ($f == 'linea') {
$f = 'subtipo';
}
if ($unidad->{$f} != post($field)) {
$unidad->{$f} = post($field);
$change = true;
}
}
if ($change) {
$unidad->save();
}
header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $unidad->proyecto()->id]));
}
public static function remove()
{
$id = get('unidad');
$unidad = model(Unidad::class)->findOne($id);
$unidad->delete();
$id = get('proyecto');
header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $id]));
}
}
?>

View File

@ -0,0 +1,83 @@
<?php
namespace App\Controller;
use Carbon\Carbon;
use App\Definition\Controller;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Proyecto\ProyectoAgente;
use Incoviba\old\Venta\Unidad;
use Incoviba\old\Venta\UnidadBloqueada;
class UnidadesBloqueadas
{
use Controller;
public static function list()
{
$proyectos = model(Proyecto::class)->findMany();
echo view('ventas.operadores.unidades.list', compact('proyectos'));
}
public static function add()
{
$proyectos = model(Proyecto::class)->findMany();
echo view('ventas.operadores.unidades.add', compact('proyectos'));
}
public static function bloquear()
{
$operador = model(ProyectoAgente::class)->findOne(get('operador'));
echo view('ventas.operadores.unidades.bloquear', compact('operador'));
}
public static function do_bloquear()
{
$operador = model(ProyectoAgente::class)->findOne(get('operador'));
$fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$unidades = self::getUnidades([], 'departamentos', 1);
$unidades = self::getUnidades($unidades, 'estacionamientos', 2);
$unidades = self::getUnidades($unidades, 'bodegas', 3);
if (post('unidad') != null) {
foreach (post('unidad') as $u) {
$unidad = model(Unidad::class)->findOne($u);
if (array_search($unidad, $unidades) === false) {
$unidades []= $unidad;
}
}
}
foreach ($unidades as $unidad) {
$data = [
'agente' => $operador->id,
'unidad' => $unidad->id
];
$ub = model(UnidadBloqueada::class)->create($data);
$ub->new($fecha);
}
header('Location: ' . nUrl('unidades_bloqueadas', 'list'));
}
protected static function getUnidades(array $unidades, string $name, int $tipo): array
{
if (trim(post($name)) == '') {
return $unidades;
}
$unis = [];
$separators = [PHP_EOL, ';', ',', '-'];
foreach ($separators as $separator) {
if (strpos(post($name), $separator) !== false) {
$unis = explode($separator, post($name));
break;
}
}
if (count($unis) == 0) {
return $unidades;
}
array_walk($unis, function(&$item) {
$item = trim($item);
$item = model(Unidad::class)->where('descripcion', $item)->where('tipo', 1)->findOne();
});
foreach ($unis as $uni) {
if (array_search($uni, $unidades) === false) {
$unidades []= $uni;
}
}
return $unidades;
}
}

View File

@ -0,0 +1,623 @@
<?php
namespace App\Controller;
use Carbon\Carbon;
use App\Definition\Controller;
use Incoviba\old\Common\Banco;
use Incoviba\old\Common\Direccion;
use Incoviba\old\Common\Region;
use Incoviba\old\Proyecto\Agente;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Venta\BonoPie;
use Incoviba\old\Venta\Credito;
use Incoviba\old\Venta\EstadoVenta;
use Incoviba\old\Venta\Pago;
use Incoviba\old\Venta\Pie;
use Incoviba\old\Venta\Promocion;
use Incoviba\old\Venta\PromocionVenta;
use Incoviba\old\Venta\Propiedad;
use Incoviba\old\Venta\PropiedadUnidad;
use Incoviba\old\Venta\Propietario;
use Incoviba\old\Venta\TipoEstadoVenta;
use Incoviba\old\Venta\Unidad;
use Incoviba\old\Venta\Venta;
class Ventas
{
use Controller;
protected static function setDefault()
{
self::$default = self::list();
}
public static function list()
{
$proyecto = get('proyecto');
if ($proyecto == null) {
return self::listProyectos();
}
$proyecto = model(Proyecto::class)->findOne($proyecto);
$ventas = $proyecto->ventas();
self::sort($ventas);
return view('ventas.list', compact('proyecto', 'ventas'));
}
protected static function sort(&$ventas)
{
$sort = get('sort');
if ($sort == null) {
$sort = 'departamento';
}
$direction = get('sort_dir');
if ($direction == null) {
$direction = 1;
}
switch ($sort) {
case 'departamento':
usort($ventas, function($a, $b) use ($direction) {
return ($a->propiedad()->unidad()->descripcion - $b->propiedad()->unidad()->descripcion) * $direction;
});
break;
case 'propietario':
usort($ventas, function($a, $b) use ($direction) {
$pa = trim($a->propietario()->nombreCompleto(true), ', ');
$pb = trim($b->propietario()->nombreCompleto(true), ', ');
return $direction * strcasecmp($pa, $pb);
});
break;
case 'valor_uf':
usort($ventas, function($a, $b) use ($direction) {
return $direction * ($a->valor_uf - $b->valor_uf);
});
break;
case 'uf_m2':
usort($ventas, function($a, $b) use ($direction) {
return $direction * ($a->uf_m2() - $b->uf_m2());
});
break;
case 'fecha_venta':
usort($ventas, function($a, $b) use ($direction) {
return ($a->fecha()->timestamp - $b->fecha()->timestamp) * $direction;
});
break;
}
if ($direction == 'desc') {
$ventas = array_reverse($ventas);
}
}
public static function listProyectos()
{
$proyectos = model(Proyecto::class)
->select('proyecto.*')
->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado')
->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo')
->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa')
->whereGte('etapa.orden', 4)
->orderByAsc('proyecto.descripcion')
->groupBy('proyecto.id')
->findMany();
echo view('ventas.proyectos', compact('proyectos'));
}
public static function show()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.show', compact('venta'));
}
public static function new()
{
$proyectos = model(Proyecto::class)
->select('proyecto.*')
->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado')
->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo')
->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa')
->whereGte('etapa.orden', 3)
->orderByAsc('proyecto.descripcion')
->groupBy('proyecto.id')
->findMany();
$regiones = model(Region::class)->order_by_asc('numeracion')->findMany();
return view('ventas.add', compact('proyectos', 'regiones'));
}
public static function agregar()
{
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$t = Carbon::today(config('app.timezone'));
$uf = uf($f);
$calle = trim(post('calle'));
$numero = post('numero');
$extra = trim(post('extra'));
$comuna = post('comuna');
$direccion = model(Direccion::class)
->where('calle', $calle)
->where('numero', $numero)
->where('extra', $extra)
->where('comuna', $comuna)
->findOne();
if (!$direccion) {
$direccion = model(Direccion::class)->create();
$direccion->calle = $calle;
$direccion->numero = $numero;
$direccion->extra = $extra;
$direccion->comuna = $comuna;
$direccion->save();
}
list($rut, $dv) = explode('-', str_replace('.', '', post('rut')));
$propietario = model(Propietario::class)->where('rut', $rut)->findOne();
if (!$propietario) {
$propietario = model(Propietario::class)->create();
$propietario->rut = $rut;
$propietario->dv = $dv;
$propietario->nombres = trim(post('nombres'));
$propietario->apellido_paterno = trim(post('paterno'));
$propietario->apellido_materno = trim(post('materno'));
$propietario->direccion = $direccion->id;
if (post('otro') != null) {
$propietario->otro = 1;
}
$propietario->save();
}
$unis = json_decode(post('unidades'));
$id_principal = array_shift($unis);
$principal = model(Unidad::class)->findOne(post('unidad' . $id_principal));
$propiedad = model(Propiedad::class)
->select('propiedad.*')
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
->where('propiedad.unidad_principal', $principal->id)
->where('unidad.proyecto', post('proyecto'))
->orderByDesc('propiedad.id')
->findOne();
// Revisar si existe la propiedad y si está vigente.
if (!$propiedad or ($propiedad->venta() and $propiedad->venta()->estado() and $propiedad->venta()->estado()->tipo()->descripcion != 'vigente')) {
if (!$propiedad) {
$propiedad = model(Propiedad::class)->create();
}
$propiedad->unidad_principal = $principal->id;
$propiedad->save();
$data = [
'propiedad' => $propiedad->id,
'unidad' => $principal->id,
'principal' => 1
];
$pu = model(PropiedadUnidad::class)->create($data);
$pu->save();
foreach ($unis as $id_unidad) {
$data = [
'propiedad' => $propiedad->id,
'unidad' => post('unidad' . $id_unidad),
'principal' => 0
];
$pu = model(PropiedadUnidad::class)->create($data);
$pu->save();
}
/*$ests = [];
$bods = [];
foreach ($unis as $id_unidad) {
$unidad = model(Unidad::class)->findOne(post('unidad' . $id_unidad));
if ($unidad->tipo == 2) {
$ests []= $unidad->id;
}
if ($unidad->tipo == 3) {
$bods []= $unidad->id;
}
}
$propiedad->estacionamientos = implode(';', $ests);
$propiedad->bodegas = implode(';', $bods);
$propiedad->save();*/
} elseif ($propiedad->venta() and $propiedad->venta()->estado()->tipo()->descripcion == 'vigente') {
// Existe la propiedad en este proyecto y está vigente. Error, no se debiese vender si está vigente.
throw new \Exception('Existe la propiedad en este proyecto y está vigente. Error, no se debiese vender si está vigente.');
}
$venta = model(Venta::class)->create();
$venta->propietario = $propietario->rut;
$venta->propiedad = $propiedad->id;
if (post('pie')) {
$pie = model(Pie::class)->create();
$pie->valor = post('pie');
$pie->fecha = $f->format('Y-m-d');
$pie->cuotas = post('cuotas');
$pie->uf = $uf->uf->value;
$pie->save();
$venta->pie = $pie->id;
}
if (post('bono_pie')) {
$bono = model(BonoPie::class)->create();
$bono->valor = post('bono_pie');
$pago = model(Pago::class)->create();
$pago->fecha = $f->format('Y-m-d');
$pago->uf = $uf->uf->value;
$pago->valor = $bono->valor * $uf->uf->value;
$pago->tipo = 8;
$pago->new();
$bono->pago = $pago->id;
$bono->save();
$venta->bono_pie = $bono->id;
}
if (post('credito')) {
$pago = model(Pago::class)->create();
$pago->fecha = $f->format('Y-m-d');
$pago->uf = $uf->uf->value;
$pago->valor = post('credito') * $uf->uf->value;
$pago->tipo = 2;
$pago->new();
$credito = model(Credito::class)->create();
$credito->pago = $pago->id;
$credito->save();
$venta->credito = $credito->id;
}
$venta->fecha = $f->format('Y-m-d');
$venta->valor_uf = post('valor');
$venta->fecha_ingreso = $t->format('Y-m-d');
if (post('operador') != 0) {
$venta->agente = post('operador');
}
$venta->uf = $uf->uf->value;
$venta->new();
if (post('promociones') != 0) {
$promos = json_decode(post('promociones'));
foreach ($promos as $id_promo) {
$promocion = model(Promocion::class)->findOne(post('promocion' . $id_promo));
$promo = model(PromocionVenta::class)->create();
$promo->promocion = $promocion->id;
$promo->venta = $venta->id;
$promo->valor = post('promo' . $id_promo);
$promo->save();
}
}
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function edit()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->findMany();
$regiones = model(Region::class)->order_by_asc('numeracion')->findMany();
return view('ventas.edit', compact('venta', 'proyectos', 'regiones'));
}
public static function editar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$uf = uf($f);
$valor = correctNumber(post('valor'));
$change = false;
if ($venta->fecha != $f->format('Y-m-d')) {
$venta->fecha = $f->format('Y-m-d');
$venta->uf = $uf->uf->value;
$change = true;
}
if ($venta->valor_uf != $valor) {
$venta->valor_uf = $valor;
$change = true;
}
if ($change) {
$venta->save();
}
$direccion = $venta->propietario()->direccion();
$calle = post('calle');
$numero = post('numero');
$extra = post('extra');
$comuna = post('comuna');
$change = false;
if ($direccion->calle != $calle) {
$direccion->calle = $calle;
$change = true;
}
if ($direccion->numero != $numero) {
$direccion->numero = $numero;
$change = true;
}
if ($direccion->extra != $extra) {
$direccion->extra = $extra;
$change = true;
}
if ($direccion->comuna != $comuna) {
$direccion->comuna = $comuna;
$change = true;
}
if ($change) {
$direccion->save();
}
$propietario = $venta->propietario();
list($rut, $dv) = explode('-', str_replace('.', '', post('rut')));
$nombres = post('nombres');
$paterno = post('paterno');
$materno = post('materno');
$change = false;
if ($propietario->rut != $rut) {
$propietario->rut = $rut;
$propietario->dv = $dv;
$venta->propietario = $rut;
$venta->save();
$change = true;
}
if ($propietario->nombres != $nombres) {
$propietario->nombres = $nombres;
$change = true;
}
if ($propietario->apellido_paterno != $paterno) {
$propietario->apellido_paterno = $paterno;
$change = true;
}
if ($propietario->apellido_materno != $materno) {
$propietario->apellido_materno = $materno;
$change = true;
}
if ($change) {
$propietario->save();
}
$unidades = json_decode(post('unidades'));
if (count($unidades) > 0) {
$propiedad = $venta->propiedad();
$ests = explode(';', $propiedad->estacionamientos);
$bods = explode(';', $propiedad->bodegas);
$change = false;
foreach ($unidades as $n) {
$id = post('unidad' . $n);
$unidad = model(Unidad::class)->findOne($id);
if ($unidad->tipo == 1 and $propiedad->unidad_principal != $unidad->id) {
$propiedad->unidad_principal = $unidad->id;
$change = true;
}
if ($unidad->tipo == 2 and array_search($unidad->id, $ests) === false) {
$ests []= $unidad->id;
}
if ($unidad->tipo == 3 and array_search($unidad->id, $bods) === false) {
$bods []= $unidad->id;
}
}
$ests = implode(';', $ests);
$bods = implode(';', $bods);
if ($propiedad->estacionamientos != $ests) {
$propiedad->estacionamientos = $ests;
$change = true;
}
if ($propiedad->bodegas != $bods) {
$propiedad->bodegas = $bods;
$change = true;
}
if ($change) {
$propiedad->save();
}
}
if (post('pie')) {
$pie = $venta->pie();
$valor = correctNumber(post('pie'));
$cuotas = post('cuotas');
$change = false;
if ($pie->valor != $valor) {
$pie->valor = $valor;
$change = true;
}
if ($pie->cuotas != $cuotas) {
$pie->cuotas = $cuotas;
$change = true;
}
if ($change) {
$pie->save();
}
}
$credito = $venta->credito();
$valor = post('credito');
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function desistir()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.desist', compact('venta'));
}
public static function desistiendo()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$valor = correctNumber(post('pago'));
$uf = uf($f);
$venta->estado = 0;
$tipo = model(TipoEstadoVenta::class)->where('descripcion', 'desistida')->findOne();
$data = [
'venta' => $venta->id,
'estado' => $tipo->id,
'fecha' => $f->format('Y-m-d')
];
$estado = model(EstadoVenta::class)->create($data);
$propiedad = $venta->propiedad();
$propiedad->estado = 0;
$pago = model(Pago::class)->create();
$pago->fecha = $f->format('Y-m-d');
$pago->valor = (double) $valor;
$pago->uf = $uf->uf->value;
$pago->tipo = 1;
$pago->new();
$propiedad->save();
$estado->save();
$venta->resciliacion = $pago->id;
$venta->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function ceder()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.ceder', compact('venta'));
}
public static function cediendo()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$nueva_venta = model(Venta::class)->create();
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
list($rut, $dv) = explode('-', str_replace('.', '', post('rut')));
$propietario = model(Propietario::class)->where('rut', $rut)->findOne();
if (!$propietario) {
$propietario = model(Propietario::class)->create();
$propietario->rut = $rut;
$propietario->dv = $dv;
$propietario->nombres = trim(post('nombres'));
$propietario->apellido_paterno = trim(post('paterno'));
$propietario->apellido_materno = trim(post('materno'));
$propietario->direccion = $direccion->id;
if (post('otro') != null) {
$propietario->otro = 1;
}
$propietario->save();
}
$nueva_venta->fecha_ingreso = $f->format();
$nueva_venta->estado = 1;
$cols = [
'propiedad',
'pie',
'bono_pie',
'credito',
'escritura',
'subsidio',
'fecha',
'valor_uf',
'agente',
'uf'
];
foreach ($cols as $col) {
$nueva_venta->{$col} = $venta->{$col};
}
$nueva_venta->new();
$venta->estado = -1;
$tipo = model(TipoEstadoVenta::class)->where('descripcion', 'cedida')->findOne();
$data = [
'venta' => $venta->id,
'estado' => $tipo->id,
'fecha' => $f->format('Y-m-d')
];
$estado = model(EstadoVenta::class)->create($data);
$estado->save();
$venta->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function entregar()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
return view('ventas.entregar', compact('venta'));
}
public static function consolidacion()
{
if (get('proyecto')) {
$id_proyecto = get('proyecto');
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
$ventas = $proyecto->ventas();
set_time_limit(count($ventas));
$f = Carbon::today(config('app.timezone'));
setlocale(LC_TIME, 'es');
return view('ventas.consolidacion.show', compact('ventas', 'f'));
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('ventas.consolidacion.proyectos', compact('proyectos'));
}
}
public static function devolucion()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$uf = uf(Carbon::now(config('app.config')))->uf->value;
$valor = round($venta->saldo() * $uf);
return view('ventas.devolucion', compact('venta', 'valor', 'uf'));
}
public static function devolver()
{
$id = get('venta');
$venta = model(Venta::class)->findOne($id);
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$uf = uf($f);
$valor = correctNumber(post('valor'));
$data = [
'fecha' => $f->format('Y-m-d'),
'valor' => $valor,
'tipo' => 1,
'uf' => $uf->uf->value,
'identificador' => post('identificador'),
'banco' => 0
];
$banco = model(Banco::class)->where('nombre', post('banco'))->findOne();
if ($banco) {
$data['banco'] = $banco->id;
}
$pago = model(Pago::class)->create($data);
$pago->newPagado();
$venta->devolucion = $pago->id;
$venta->save();
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
}
public static function resciliaciones()
{
$resciliaciones = model(Venta::class)->where('estado', 0)->findMany();
return view('ventas.resciliaciones', compact('resciliaciones'));
}
public static function firmar()
{
$venta = \model(Venta::class)->findOne(get('venta'));
return view('ventas.firmar', compact('venta'));
}
public static function firmando()
{
$venta = \model(Venta::class)->findOne(get('venta'));
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$venta->firmar($f);
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
}
public static function archivar()
{
$venta = \model(Venta::class)->findOne(get('venta'));
return view('ventas.archivar', compact('venta'));
}
public static function archivando()
{
$venta = \model(Venta::class)->findOne(get('venta'));
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
$venta->archivar($f);
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
}
}
?>

View File

@ -0,0 +1,9 @@
@icon-font-path: '~bootstrap/dist/fonts';
@palette1: #333;
@palette2: #f78820;
@page_heading: #14153c;
@grey: #a9a9a9;
@dark-grey: #808080;
@light-grey: #d3d3d3;

9
resources/less/app.less Normal file
View File

@ -0,0 +1,9 @@
@import "_variables";
@import "bootstrap";
//@import "node_modules/font-awesome/less/font-awesome";
@import "custom";
@import (less) "node_modules/jquery-ui-bootstrap/jquery.ui.theme.css";

2
resources/less/bootstrap.less vendored Normal file
View File

@ -0,0 +1,2 @@
@import "node_modules/bootstrap/less/bootstrap";
//@import "node_modules/bootstrap-datepicker/less/datepicker3";

View File

@ -0,0 +1,50 @@
@import "submenu";
@import "print";
.logo_cabezal {
padding: 1%;
img {
height: @line-height-base * @font-size-base * 5;
}
}
.dropdown-submenu {
position: relative;
.dropdown-menu {
top: 0;
left: 100%;
margin-top: -1px;
}
}
.error {
background-color: darken(@brand-danger, .9);
}
.page-heading {
padding: 3px 10px;
margin: auto 0;
background-color: @page_heading;
color: white;
a {
color: inherit;
}
}
.section-heading {
background-color: @dark-grey !important;
color: white !important;
a {
color: inherit !important;
}
}
.subsection-heading {
background-color: @light-grey !important;
}
.agregar, .remover, .click {
cursor: pointer;
}

101
resources/less/print.less Normal file
View File

@ -0,0 +1,101 @@
@media print {
header, footer, .benchmark {
display: none;
}
}
#print {
width: 100%;
div.title {
font-size: 15pt;
font-weight: bold;
border-bottom: 3px solid black;
text-align: center;
}
table.data-box {
width: 100%;
border-collapse: collapse;
td {
border: thin solid black;
padding-left: 2px;
}
}
table.details {
width: 100%;
border-collapse: collapse;
thead {
color: white;
background-color: black;
font-weight: bold;
}
tbody {
tr {
border: thin solid black;
&:nth-child(odd) {
background-color: lightgray;
}
&.total {
font-weight: bold;
td {
border-top-style: double;
border-top-width: 3px;
}
}
}
}
td, th {
border: thin solid black;
padding-left: 2px;
}
}
label {
font-variant: small-caps;
font-size: 10pt;
}
div.data {
float: left;
}
div.data-value {
float: right;
}
div.total {
float: left;
font-weight: bold;
}
div.total-value {
float: right;
font-weight: bold;
}
br.clear {
clear: both;
}
table.signature {
width: 75%;
tr {
&.double {
height: 12pt * 2;
}
&.triple {
height: 12pt * 3;
}
&.quadruple {
height: 12pt * 4;
}
td {
padding-left: 2px;
border: thin solid black;
&:nth-child(2) {
width: 70%;
}
}
}
}
}

View File

@ -0,0 +1,42 @@
.dropdown-submenu {
position: relative;
.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px;
border-radius: 0 6px 6px 6px;
}
&:hover>.dropdown-menu {
display: block;
a:after {
border-left-color: #fff;
}
}
a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #ccc;
margin-top: 5px;
margin-right: -10px;
}
.pull-left {
float: none;
.dropdown-menu {
left: -100%;
margin-left: 10px;
-webkit-border-radius: 6px 0 6px 6px;
-moz-border-radius: 6px 0 6px 6px;
border-radius: 6px 0 6px 6px;
}
}
}

View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>
@if (isset($titulo))
{{$titulo}} -
@endif
Incoviba S. A.</title>
<link rel="stylesheet" type="text/css" href="css/app.css" />
<link rel="icon" type="image/png" href="images/Isotipo 32.png" />
<script type="text/javascript" src="js/app.js"></script>
@stack('styles')
</head>
<body>
<header>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="logo_cabezal">
<a href="."><img src="images/logo_cabezal.png" /></a>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
@include('admin.menu')
</div>
</div>
</div>
</header>
<div class="container">
<div class="row">
<div class="col-md-12">
@yield('content')
</div>
</div>
</div>
@include('layout.footer')
@stack('scripts')
</body>
</html>

View File

@ -0,0 +1,40 @@
<nav class="navbar navbar-default">
<ul class="nav navbar-nav">
<li><a href=".">Inicio</a></li>
<li><a href="{{url('', ['p' => 'admin'])}}">Administraci&oacute;n</a>
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
Modelos <span class="caret"></span>
</a>
@include('admin.menu.models')
</li>
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
Roles <span class="caret"></span>
</a>
@include('admin.menu.roles')
</li>
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
Usuarios <span class="caret"></span>
</a>
@include('admin.menu.users')
</li>
<li><a href="{{url('admin/registros')}}">Registros</a></li>
<?php
/*
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
Registros <span class="caret"></span>
</a>
@include('admin.menu.registros')
</li>
*/ ?>
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
{{\App\Contract\Auth::User()->name}} <span class="caret"></span>
</a>
@include('layout.menu.login')
</li>
</ul>
</nav>

View File

@ -0,0 +1,3 @@
<ul class="dropdown-menu">
<li><a href="{{url('', ['p' => 'admin', 'a' => 'listModels'])}}">Listar Modelos</a></li>
</ul>

View File

@ -0,0 +1,3 @@
<ul class="dropdown-menu">
<li><a href="{{nUrl('registros', 'list')}}">Listar Registros</a></li>
</ul>

View File

@ -0,0 +1,4 @@
<ul class="dropdown-menu">
<li><a href="{{nUrl('admin', 'list_roles')}}">Listar Roles</a></li>
<li><a href="{{nUrl('admin', 'add_role')}}">Agregar Rol</a></li>
</ul>

View File

@ -0,0 +1,4 @@
<ul class="dropdown-menu">
<li><a href="{{url('', ['p' => 'admin', 'a' => 'list_users'])}}">Listar Usuarios</a></li>
<li><a href="{{url('', ['p' => 'admin', 'a' => 'add_user'])}}">Agregar Usuario</a></li>
</ul>

View File

@ -0,0 +1,31 @@
@extends('layout.base')
@section('content')
<div class="panel panel-default">
<div class="panel-heading">DB to Models</div>
<div class="panel-body">
<form action="{{url('', ['p' => 'admin', 'a' => 'models'])}}" method="post" class="form-horizontal" id="databases">
<div class="row form-group">
<div class="col-md-3">DB</div>
<div class="col-md-4">
<select name="database" class="form-control">
@foreach ($databases as $database)
<option value="{{$database}}">{{$database}}</option>
@endforeach
</select>
</div>
</div>
<div class="row form-group">
<div class="col-md-offset-3 col-md-2"><input type="submit" value="Listar" class="form-control" /></div>
</div>
</form>
<div class="row">
<div class="col-md-12" id="results"></div>
</div>
</div>
</div>
@endsection
@push('scripts')
<script type="text/javascript" src="js/admin.js"></script>
@endpush

View File

@ -0,0 +1,31 @@
<div class="row">
<div class="col-md-1">
@if ($start > 0)
<a href="{{url('admin/registros')}}">
<span class="glyphicon glyphicon-fast-backward"></span>
</a>
@endif
</div>
<div class="col-md-1">
@if ($start > 0)
<a href="{{url('admin/registros/') . ($start - $step + 1) . '/' . (($end > 0) ? $end - $step : $step * 2)}}">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
@endif
</div>
<div class="col-md-offset-3 col-md-2 text-center">{{$start + 1}} - {{$end}}</div>
<div class="col-md-offset-3 col-md-1 text-right">
@if ($end < $total)
<a href="{{url('admin/registros/') . (($end > 0) ? $end + 1 : $step) . '/' . (($end > 0) ? $end + $step : $step * 2)}}">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
@endif
</div>
<div class="col-md-1 text-right">
@if ($end < $total)
<a href="{{url('admin/registros/') . (round($total / $step, 0) * $step + 1) . '/' . (round($total / $step, 0) *$step + $step)}}">
<span class="glyphicon glyphicon-fast-forward"></span>
</a>
@endif
</div>
</div>

View File

@ -0,0 +1,41 @@
@extends('admin.base')
@section('content')
<div class="panel panel-default">
<div class="panel-heading">Registros</div>
<div class="panel-body">
@include('admin.registros.controles_avance')
<table class="table table-striped">
<thead>
<tr>
<th>Usuario</th>
<th>Roles</th>
<th>Fecha - Hora</th>
<th>Modelo</th>
<th>Cambios</th>
</tr>
</thead>
<tbody>
@foreach ($registros as $registro)
<tr>
<td>{{$registro->user()->name}}</td>
<td>
@foreach ($registro->user()->roles() as $rol)
<span class="label label-default" style="padding: 3px; background-color: {{$colores[$rol->level]->toRGB()}};
@if ($colores[$rol->level]->isDark())
color: #fff;
@endif
">{{ucwords($rol->description)}}</span>
@endforeach
</td>
<td><a href="{{url('admin/registro/' . $registro->id)}}">{{$registro->time()->format('d-m-Y - H:i:s')}} hrs.</a></td>
<td>{{$registro->model()}}</td>
<td>{{count($registro->actions())}}</td>
</tr>
@endforeach
</tbody>
</table>
@include('admin.registros.controles_avance')
</div>
</div>
@endsection

View File

@ -0,0 +1,62 @@
@extends('admin.base')
@section('content')
<div class="panel panel-default">
<div class="panel-heading">Ver Registro</div>
<div class="panel-body">
<div class="row">
<div class="col-md-2"><strong>Usuario</strong></div>
<div class="col-md-5">{{$registro->user()->name}}</div>
</div>
<div class="row">
<div class="col-md-2"><strong>Roles</strong></div>
<div class="col-md-8">
@foreach ($registro->user()->roles() as $rol)
<span style="padding: 3px; background-color: {{$colores[$rol->level]->toRGB()}};
@if ($colores[$rol->level]->isDark())
color: #fff;
@endif
">{{ucwords($rol->description)}}</span>
@endforeach
</div>
</div>
<div class="row">
<div class="col-md-2"><strong>Fecha - Hora</strong></div>
<div class="col-md-8">{{$registro->time()->format('d-m-Y - H:i:s')}}</div>
</div>
<div class="row">
<div class="col-md-2"><strong>Modelo</strong></div>
<div class="col-md-8">{{$registro->model()}}</div>
</div>
<div class="row">
<div class="col-md-2"><strong>Cambios</strong></div>
<div class="col-md-10">
<table class="table table-striped">
<thead>
<tr>
<th rowspan="2">Columna</th>
<th class="text-center" colspan="2">Valor</th>
</tr>
<tr>
<th>Antiguo</th>
<th>Nuevo</th>
</tr>
</thead>
<tbody>
@foreach ($registro->actions() as $column => $action)
<tr>
<td>{{$column}}</td>
<td>{{$action->old}}</td>
<td>{{$action->new}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<div class="row">
<a href="{{nUrl('registros', 'list')}}"><span class="glyphicon glyphicon-chevron-left"></span> Volver</a>
</div>
</div>
</div>
@endsection

View File

@ -0,0 +1,17 @@
@extends('admin.base')
@section('content')
<div class="row page-heading">
<div class="col-md-12 h3">Agregar Rol</div>
</div>
<br />
<form action="{{url('', ['p' => 'admin', 'a' => 'do_add_role'])}}" method="post" class="form-horizontal">
<div class="form-group">
<div class="col-md-2">Descripci&oacute;n</div>
<div class="col-md-3"><input type="text" name="description" class="form-control" /></div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-2"><button type="submit" class="form-control">Create</button></div>
</div>
</form>
@endsection

View File

@ -0,0 +1,40 @@
@extends('admin.base')
@section('content')
<div class="row page-heading">
<div class="col-md-12 h3">Agregar Permisos - {{$role->description}}</div>
</div>
<br />
<form class="form-horizontal" method="post" action="{{nUrl('admin', 'do_add_role_permissions', ['role' => $role->id])}}">
<div class="form-group">
<div class="col-md-2">Permitidos</div>
<div class="col-md-3"><select name="allowed[]" class="form-control" multiple="multiple">
@foreach ($actions as $action)
<option value="{{$action->id}}"
@if ($role->checkAccess($action->description))
selected="selected"
@endif
>{{$action->description}}</option>
@endforeach
</select></div>
</div>
<?php
/*
<div class="form-group">
<div class="col-md-2">Denegados</div>
<div class="col-md-3"><select name="denied[]" class="form-control" multiple="multiple">
@foreach ($actions as $action)
<option value="{{$action->id}}"
@if (!$role->checkAccess($action->description))
selected="selected"
@endif
>{{$action->description}}</option>
@endforeach
</select></div>
</div>
*/ ?>
<div class="form-group">
<div class="col-md-offset-2 col-md-2"><button class="form-control" type="submit">Agregar</button></div>
</div>
</form>
@endsection

View File

@ -0,0 +1,24 @@
@extends('admin.base')
@section('content')
<div class="row page-heading">
<div class="col-md-12 h3">Agregar Usuario - {{$role->description}}</div>
</div>
<br />
<form class="form-horizontal" method="post" action="{{url('', ['p' => 'admin', 'a' => 'do_add_user_role', 'role' => $role->id])}}">
<div class="form-group">
<div class="col-md-2">Ususarios</div>
<div class="col-md-3"><select name="users[]" class="form-control" multiple="multiple">
@foreach ($users as $user)
@if ($role->hasUser($user->id))
@continue
@endif
<option value="{{$user->id}}">{{$user->name}}</option>
@endforeach
</select></div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-2"><button type="submit" class="form-control">Agregar</button></div>
</div>
</form>
@endsection

View File

@ -0,0 +1,32 @@
@extends('admin.base')
@section('content')
<div class="page-heading row">
<div class="col-md-6 h3">Roles</div>
<div class="col-md-6 text-right h3"><a href="{{url('', ['p' => 'admin', 'a' => 'add_role'])}}"><span class="glyphicon glyphicon-plus"></span></a></div>
</div>
<table class="table">
<thead>
<tr>
<th>Descripci&oacute;n</th>
<th>Nivel</th>
<th>Usuarios</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($roles as $role)
<tr>
<td><a href="{{nUrl('admin', 'role', ['role' => $role->id])}}">{{$role->description}}</a></td>
<td>{{$role->level}}</td>
<td>
@foreach ($role->users() as $user)
{{$user->name}}
@endforeach
</td>
<td><a href="{{url('', ['p' => 'admin', 'a' => 'delete_role'])}}"><span class="glyphicon glyphicon-minus"></span></a></td>
</tr>
@endforeach
</tbody>
</table>
@endsection

View File

@ -0,0 +1,63 @@
@extends('admin.base')
@section('content')
<div class="row page-heading">
<div class="col-md-12 h3">{{$role->description}}</div>
</div>
<div class="section-heading row">
<div class="col-md-6 h4">Usuarios</div>
<div class="col-md-6 h4 text-right"><a href="{{url('', ['p' => 'admin', 'a' => 'add_user_role', 'role' => $role->id])}}"><span class="glyphicon glyphicon-plus"></span></a></div>
</div>
<table class="table">
@foreach ($role->users() as $user)
<tr>
<td><a href="{{nUrl('admin', 'user', ['user' => $user->id])}}">{{$user->name}}</a></td>
<td><a href="{{url('', ['p' => 'admin', 'a' => 'remove_user_role', 'user' => $user->id, 'role' => $role->id])}}"><span class="glyphicon glyphicon-minus"></span></a></td>
</tr>
@endforeach
</table>
<div class="row section-heading">
<div class="col-md-6 h4">Permisos</div>
<div class="col-md-6 h4 text-right"><a href="{{nUrl('admin', 'add_role_permissions', ['role' => $role->id])}}"><span class="glyphicon glyphicon-plus"></span></a></div>
</div>
@if ($role->permissions())
<table class="table table-striped">
<thead>
<tr>
<th>Acci&oacute;n</th>
<th>Estado</th>
<th>Heredado</th>
</tr>
</thead>
<tbody>
@foreach ($permissions as $permission)
<tr>
<td>{{$permission->description}}</td>
<td style="color:
@if ($permission->status)
#00ff00
@else
#ff0000
@endif
;">
@if ($permission->status) Permitido @else Denegado @endif
</td>
<td style="color:
@if ($permission->inherited)
#00ff00
@else
#ff0000
@endif
;">
@if ($permission->inherited)
Si
@else
No
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
@endif
@endsection

View File

@ -0,0 +1,21 @@
@extends('admin.base')
@section('content')
<div class="row page-heading">
<div class="col-md-12 h3">Agregar Ususario</div>
</div>
<br />
<form action="{{url('', ['p' => 'admin', 'a' => 'do_add_user'])}}" method="post" class="form-horizontal">
<div class="form-group">
<div class="col-md-2">Usuario</div>
<div class="col-md-3"><input type="text" name="name" class="form-control" /></div>
</div>
<div class="form-group">
<div class="col-md-2">Password</div>
<div class="col-md-3"><input type="password" name="password" class="form-control" /></div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-2"><button type="submit" class="form-control">Create</button></div>
</div>
</form>
@endsection

View File

@ -0,0 +1,24 @@
@extends('admin.base')
@section('content')
<div class="row page-heading">
<div class="col-md-12 h3">Agregar Rol - {{$user->name}}</div>
</div>
<br />
<form class="form-horizontal" method="post" action="{{url('', ['p' => 'admin', 'a' => 'do_add_user_role', 'user' => $user->id])}}">
<div class="form-group">
<div class="col-md-2">Rol</div>
<div class="col-md-3"><select name="role[]" class="form-control" multiple="multiple">
@foreach ($roles as $role)
@if ($user->hasRole($role->id))
@continue
@endif
<option value="{{$role->id}}">{{$role->description}}</option>
@endforeach
</select></div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-2"><button type="submit" class="form-control">Agregar</button></div>
</div>
</form>
@endsection

View File

@ -0,0 +1,29 @@
@extends('admin.base')
@section('content')
<div class="page-heading row">
<div class="col-md-6 h3">Usuarios</div>
<div class="col-md-6 text-right h3"><a href="{{url('', ['p' => 'admin', 'a' => 'add_user'])}}"><span class="glyphicon glyphicon-plus"></span></a></div>
</div>
<table class="table">
<thead>
<tr>
<th>Nombre</th>
<th>Roles</th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
<tr>
<td><a href="{{url('', ['p' => 'admin', 'a' => 'user', 'user' => $user->id])}}">{{$user->name}}</a></td>
<td>
@foreach ($user->roles() as $role)
{{$role->description}}
@endforeach
</td>
<td><a href="{{url('', ['p' => 'admin', 'a' => 'delete_user', 'user' => $user->id])}}"><span class="glyphicon glyphicon-minus"></span></a></td>
</tr>
@endforeach
</tbody>
</table>
@endsection

View File

@ -0,0 +1,62 @@
@extends('admin.base')
@section('content')
<div class="row page-heading">
<div class="col-md-12 h3">{{$user->name}}</div>
</div>
<a href="{{nUrl('admin', 'reset_user', ['user' => $user->id])}}">
Resetear Clave
</a>
<div class="section-heading row">
<div class="col-md-6 h4">Roles</div>
<div class="col-md-6 h4 text-right"><a href="{{url('', ['p' => 'admin', 'a' => 'add_user_role', 'user' => $user->id])}}"><span class="glyphicon glyphicon-plus"></span></a></div>
</div>
<table class="table">
@foreach ($user->roles() as $role)
<tr>
<td><a href="{{nUrl('admin', 'role', ['role' => $role->id])}}">{{$role->description}}</a></td>
<td><a href="{{url('', ['p' => 'admin', 'a' => 'remove_user_role', 'user' => $user->id, 'role' => $role->id])}}"><span class="glyphicon glyphicon-minus"></span></a></td>
</tr>
@endforeach
</table>
<div class="row section-heading">
<div class="col-md-6 h4">Permisos</div>
<div class="col-md-6 h4 text-right"><a href="{{nUrl('admin', 'add_user_permissions', ['user' => $user->id])}}"><span class="glyphicon glyphicon-plus"></span></a></div>
</div>
@if ($user->permissions())
<table class="table">
<thead>
<tr>
<th>P&aacute;ginas</th>
<th>Rol</th>
<th>Acceso</th>
</tr>
</thead>
<tbody>
@foreach ($user->permissions() as $permission)
<tr>
<td>
{{$permission->action()->description}}
</td>
<td>
@if ($permission->type == 2)
{{$permission->who()->description}}
@endif
</td>
<td>
@if ($permission->all == 0)
@if ($permission->access == 1)
Permitido
@else
Denegado
@endif
@else
Permitido
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
@endif
@endsection

View File

@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>
@if (isset($titulo))
{{$titulo}} -
@endif
Incoviba S. A.</title>
<link rel="stylesheet" type="text/css" href="css/app.css" />
<link rel="icon" type="image/png" href="images/Isotipo 32.png" />
<script type="text/javascript" src="js/app.js"></script>
@stack('styles')
</head>
<body>
<header>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="logo_cabezal">
<a href="."><img src="images/logo_cabezal.png" /></a>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<nav class="navbar navbar-default">
<ul class="nav navbar-nav">
<li><a href=".">Inicio</a></li>
@if (\App\Contract\Auth::isIn())
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
{{\App\Contract\Auth::User()->name}} <span class="caret"></span>
</a>
@include('layout.menu.login')
</li>
@else
<li><a href="{{url('', ['p' => 'auth', 'a' => 'login'])}}">Ingresar</a></li>
@endif
</ul>
</nav>
</div>
</div>
</div>
</header>
<div class="container">
<div class="row">
<div class="col-md-12">
@yield('content')
</div>
</div>
</div>
@include('layout.footer')
@stack('scripts')
</body>
</html>

View File

@ -0,0 +1,78 @@
@extends('auth.base')
@section('content')
<div class="row page-heading">
<div class="col-md-12 h3">Cambio de Cl&aacute;ve</div>
</div>
<br />
<form class="form-horizontal" method="post" action="{{url('', ['p' => 'auth', 'a' => 'do_change_pass'])}}">
<div class="form-group">
<div class="col-md-2">Cl&aacute;ve anterior</div>
<div class="col-md-3"><input type="password" name="old" class="form-control" /></div>
<div class="col-md-3" id="msg1"></div>
</div>
<div class="form-group">
<div class="col-md-2">Cl&aacute;ve nueva</div>
<div class="col-md-3"><input type="password" name="new" class="form-control" /></div>
<div class="col-md-3" id="msg2"></div>
</div>
<div class="form-group">
<div class="col-md-2">Repetir cl&aacute;ve</div>
<div class="col-md-3"><input type="password" name="new2" class="form-control" /></div>
<div class="col-md-3" id="msg3"></div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-2"><button type="submit" class="form-control">Cambiar</button></div>
</div>
</form>
@endsection
@push('scripts')
<script type="text/javascript">
$(document).ready(function() {
var status = [0, 0, 0, 0];
$("input[name='old']").blur(function(e) {
$.post('{!!nUrl('auth', 'check_pass', ['ajax' => 'true'])!!}', {"password": $(this).val()}, function(data) {
if (data == 'KO') {
$('#msg1').html('<span class="label label-danger"><span class="glyphicon glyphicon-warning-sign"></span> Cl&aacute;ve anterior inv&aacute;lida.</span>');
status[1] = 0;
} else {
$('#msg1').html('<span class="label label-success"><span class="glyphicon glyphicon-ok "></span></span>');
status[1] = 1;
}
});
})
$("input[name='new']").blur(function(e) {
var result = zxcvbn($(this).val(), user_inputs=[$("input[name='old']").val(), '{{\App\Contract\Auth::User()->name}}']);
if (result.score < 3) {
$('#msg2').html('<span class="label label-danger"><span class="glyphicon glyphicon-warning-sign"></span> Nivel ' + result.score + '</span>');
status[2] = 0;
} else {
if (result.score == 3) {
$('#msg2').html('<span class="label label-warning"><span class="glyphicon glyphicon-ok"></span> Nivel ' + result.score + '</span>');
} else {
$('#msg2').html('<span class="label label-success"><span class="glyphicon glyphicon-ok"></span> Nivel ' + result.score + '</span>');
}
status[2] = 1;
}
});
$("input[name='new2']").blur(function(e) {
var n = $("input[name='new']").val();
if ($(this).val() != n) {
$('#msg3').html('<span class="label label-danger"><span class="glyphicon glyphicon-warning-sign"></span> Las cl&aacute;ves no coinciden.</span>');
status[3] = 0;
} else {
$('#msg3').html('<span class="label label-success"><span class="glyphicon glyphicon-ok"></span></span>');
status[3] = 1;
}
});
$("form").submit(function(e) {
status[0] = status[1] & status[2] & status[3];
if (!status[0]) {
e.preventDefault();
}
return status[0];
});
});
</script>
@endpush

View File

@ -0,0 +1,17 @@
@extends('auth.base')
@section('content')
<form class="form-horizontal" action="{{url('', ['p' => 'auth', 'a' => 'do_login'])}}" method="post">
<div class="form-group">
<div class="col-md-2">Usuario</div>
<div class="col-md-3"><input type="text" name="name" class="form-control" /></div>
</div>
<div class="form-group">
<div class="col-md-2">Cl&aacute;ve</div>
<div class="col-md-3"><input type="password" name="password" class="form-control" /></div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-2"><input type="submit" value="Ingresar" class="form-control" /></div>
</div>
</form>
@endsection

View File

@ -0,0 +1,7 @@
<br />
<div class="benchmark container">
<div class="row alert alert-info">
<div class="col-md-2">Tiempo demorado</div>
<div class="col-md-5">{{$benchmark->time}} s</div>
</div>
</div>

View File

@ -0,0 +1,77 @@
@extends('layout.base')
@section('content')
<div class="panel panel-default">
<div class="panel-heading">Buscar</div>
<div class="panel-body">
<form action="{{url('', ['p' => 'buscar'])}}" method="get" class="form form-horizontal">
<input type="hidden" name="p" value="buscar" />
<div class="form-group">
<div class="col-md-6"><input type="text" name="q" class="form-control"
@if (get('q'))
value="{!!urldecode(get('q'))!!}"
@elseif (get('query'))
value="{!!urldecode(get('query'))!!}"
@endif
/></div>
<div class="col-md-2"><input type="submit" value="Buscar" class="form-control" /></div>
<div class="col-md-4">
<div class="col-md-12 text-center">
<input type="radio" name="tipo" value="{{urlencode($tipos[0])}}"
@if (get('tipo') == null or get('tipo') == $tipos[0])
checked="checked"
@endif
/>
{{ucwords($tipos[0])}}
</div>
@foreach ($tipos as $i => $tipo)
@if ($tipo == 'cualquiera')
@continue
@endif
<div class="col-md-6">
<input type="radio" name="tipo" value="{{urlencode($tipo)}}"
@if (get('tipo') != null)
@if ($tipo == get('tipo'))
checked="checked"
@endif
@else
@if ($tipo == 'cualquiera')
checked="checked"
@endif
@endif
/>
{{ucwords($tipo)}}
</div>
@endforeach
</div>
</div>
</form>
</div>
</div>
@if ($results != null)
<div class="panel panel-default">
<div class="panel-heading">Resultados</div>
<div class="panel-body">
<table class="table table-striped">
<thead>
<tr>
<th>Proyecto</th>
<th>Departamento</th>
<th>Propietario</th>
<th>Tipo</th>
<th>m&#0178;</th>
<th>Valor [UF]</th>
<th>Fecha Venta</th>
<th>Fecha Entrega</th>
</tr>
</thead>
<tbody>
@foreach ($results as $resultado)
@include('buscar.resultado')
@endforeach
</tbody>
</table>
</div>
</div>
@endif
@endsection

View File

@ -0,0 +1,46 @@
<tr>
<td>
<a href="{{url('', ['p' => 'buscar', 'q' => urlencode('"' . $resultado->proyecto()->descripcion . '"'), 't' => 'proyecto'])}}">
{{$resultado->proyecto()->descripcion}} <span class="small glyphicon glyphicon-search"></span>
</a>
</td>
@if (method_exists($resultado, 'unidad'))
<td>
<a href="{{url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $resultado->id])}}">
{{$resultado->unidad()->descripcion}}
@if ($resultado->estado == 0)
(r)
@elseif ($resultado->estado == -1)
(c)
@endif
<span class="small glyphicon glyphicon-chevron-right"></span>
</a>
</td>
<td>
<a href="{{url('', ['p' => 'buscar', 'q' => urlencode('"' . $resultado->propietario()->nombreCompleto() . '"'), 't' => 'propietario'])}}">
{{$resultado->propietario()->nombreCompleto()}} <span class="small glyphicon glyphicon-search"></span>
</a>
</td>
<td>{{ucwords($resultado->unidad()->tipo()->descripcion)}}</td>
<td>{{\App\Helper\Format::m2($resultado->unidad()->m2())}}</td>
<td>{{\App\Helper\Format::ufs($resultado->valor_uf)}}</td>
<td>{{\App\Helper\Format::shortDate($resultado->fecha)}}</td>
<td>
@if ($resultado->entrega != 0)
{{\App\Helper\Format::shortDate($resultado->entrega()->fecha)}}
@endif
</td>
@else
<td>
{{$resultado->descripcion}} <span class="glyphicon glyphicon-ban-circle"></span>
</td><td>
<td>{{ucwords($resultado->tipo()->descripcion)}}</td>
<td>{{\App\Helper\Format::m2($resultado->m2())}}</td>
@if ($resultado->valor)
<td>{{format('ufs', $resultado->valor)}}</td>
@else
<td></td>
@endif
<td></td>
@endif
</tr>

View File

@ -0,0 +1,17 @@
<div class="ui divided list" style="max-width: 300px;">
@foreach ($dias as $dia => $proyectos)
<div class="item">
<div class="date"><strong>{{format('localDate', $dia, 'ddd DD [de] MMMM [de] YYYY', true)}}</strong></div>
<div class="ui feed">
@foreach ($proyectos as $proyecto => $cantidad)
<div class="event">
<div class="content">
<div class="summary">{{$proyecto}}</div>
</div>
<div class="meta">{{$cantidad}}</div>
</div>
@endforeach
</div>
</div>
@endforeach
</div>

View File

@ -0,0 +1,31 @@
<h3 class="ui header">Cierres Vigentes</h3>
<div class="ui divided list" style="max-width: 300px;">
@foreach ($cierres as $proyecto => $cierre)
<div class="item">
<div class="date"><strong>{{$proyecto}}</strong> [{{$cierre->total}}]</div>
<div class="ui feed">
<div class="event">
<div class="content">
<div class="summary">Promesados</div>
</div>
<div class="meta">{{count($cierre->vigentes)}}</div>
</div>
<div class="event">
<div class="content">
<div class="summary">Pendientes</div>
@if (count($cierre->pendientes) > 0)
<div class="date">Desde {{$cierre->pendientes[0]->periodo()}} d&iacute;as atr&aacute;s</div>
@endif
</div>
<div class="meta">{{count($cierre->pendientes)}}</div>
</div>
<div class="event">
<div class="content">
<div class="summary">Rechazados</div>
</div>
<div class="meta">{{count($cierre->rechazados)}}</div>
</div>
</div>
</div>
@endforeach
</div>

View File

@ -0,0 +1,5 @@
@extends('layout.base')
@section('content')
Secci&oacute;n en construcci&oacute;n.
@endsection

View File

@ -0,0 +1,20 @@
@extends('layout.base')
@section('content')
<div class="page-heading">
<h2>Pagos del Mes - {{$proyecto->descripcion}} - {{$proyecto->inmobiliaria()->abreviacion}}</h2>
</div>
<h3>{{$fecha->format('d / m / Y')}}</h3>
{{!d($pagos)}}
<table class="table">
@foreach ($pagos as $pago)
<tr>
<td>{{$pago->Departamento}}</td>
<td>{{$pago->Numero}}</td>
<td>{{$pago->Total}}</td>
<td>{{format('ufs', $pago->Valor->UF)}}</td>
<td>{{format('pesos', $pago->Valor->Pesos)}}</td>
</tr>
@endforeach
</table>
@endsection

View File

@ -0,0 +1,74 @@
@extends('layout.base')
@section('content')
<div class="page-heading">
<h2>Pagos del Mes</h2>
</div>
<table class="table table-striped">
<thead>
<tr>
<th colspan="2">Proyectos</th>
</tr>
<tr>
<th>Nombre</th>
<th>Inmobiliaria</th>
</tr>
</thead>
<tbody id="proyectos">
</tbody>
</table>
@endsection
@push('scripts')
<script type="text/javascript">
let proyectos = {
id: "#proyectos",
proyectos: [],
get: function() {
let url = '{{nUrl('contabilidad')}}&a=get_proyectos&ajax=1'
return $.getJSON(url, (data) => {
this.proyectos = data.proyectos
})
},
build: function() {
let tbod = $(this.id)
$.each(this.proyectos, (i, el) => {
let inm = $('<td></td>').html(el.inmobiliaria.abreviacion)
let line2 = $('<tr></tr>')
let line = $('<tr></tr>').attr('data-proyecto', el.id).append(
$('<td></td>').html(el.descripcion)
).append(
inm
).click(function(e) {
line2.html('')
let url = '{{nUrl('contabilidad')}}&a=get_fechas&proyecto=' + el.id
$.getJSON(url, (data) => {
let tb = $('<table></table>')
$.each(data.fechas, (k, fe) => {
let url = '{{nUrl('contabilidad')}}&a=show_pagos&proyecto=' + el.id + '&fecha=' + fe.short
let tr = $('<tr></tr>').append(
$('<td></td>').append(
$('<a></a>').attr('href', url).html(fe.long)
)
)
tb.append(tr)
})
line2.append($('<td></td>')).append(tb)
})
})
tbod.append(line).append(line2)
})
},
setup: function() {
this.get().then(() => {
this.build()
})
}
}
$(document).ready(() => {
proyectos.setup()
})
</script>
@endpush

View File

@ -0,0 +1,38 @@
<?php $t = \Carbon\Carbon::today(config('app.timezone')) ?>
<div class="col-md-1"><select name="day{{(isset($id)) ? $id : ''}}" class="form-control">
@for ($i = 0; $i < 31; $i ++)
<option value="{{$i + 1}}"
@if (isset($f))
@if ($f->day == $i + 1)
selected="selected"
@endif
@elseif ($t->day == $i + 1)
selected="selected"
@endif
>{{str_pad($i + 1, 2, '0', STR_PAD_LEFT)}}</option>
@endfor
</select></div>
<div class="col-md-1"><select name="month{{(isset($id)) ? $id : ''}}" class="form-control">
@for ($i = 0; $i < 12; $i ++)
<option value="{{$i + 1}}"
@if (isset($f))
@if ($f->month == $i + 1)
selected="selected"
@endif
@elseif ($t->month == $i + 1)
selected="selected"
@endif
>{{str_pad($i + 1, 2, '0', STR_PAD_LEFT)}}</option>
@endfor
</select></div>
<div class="col-md-2"><select name="year{{(isset($id)) ? $id : ''}}" class="form-control">
@for ($i = $t->year; $i > $t->year - 5; $i --)
<option value="{{$i}}"
@if (isset($f))
@if ($f->year == $i)
selected="selected"
@endif
@endif
>{{$i}}</option>
@endfor
</select></div>

View File

@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>
@if (isset($titulo))
{{$titulo}} -
@endif
Incoviba S. A.</title>
<link rel="stylesheet" type="text/css" href="css/app.css" />
<link rel="icon" type="image/png" href="images/Isotipo 32.png" />
<script type="text/javascript" src="js/app.js"></script>
@stack('styles')
</head>
<body>
<header>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="logo_cabezal">
<a href="."><img src="images/logo_cabezal.png" /></a>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<nav class="navbar navbar-default">
<ul class="nav navbar-nav">
<li><a href=".">Inicio</a></li>
@if (\App\Contract\Auth::isIn())
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
{{Auth::User()}} <span class="caret"></span>
</a>
@include('layout.menu.login')
</li>
@else
<li><a href="{{url('', ['p' => 'auth', 'a' => 'login'])}}">Ingresar</a></li>
@endif
</ul>
</nav>
</div>
</div>
</div>
</header>
<div class="container">
<div class="row">
<div class="col-md-12">
Hola invitad@, favor ingresar.
</div>
</div>
</div>
@include('layout.footer')
@stack('scripts')
</body>
</html>

View File

@ -0,0 +1,28 @@
@extends('layout.base')
@section('content')
@if ($hoy > 0)
<div clasS="row">
<div class="col-md-12">Hay {{$hoy}} deposito{{($hoy > 1) ? 's' : ''}} para hoy.</div>
</div>
@endif
@if ($pendientes > 0)
<div class="row">
<div class="col-md-12"><a href="{{url('', ['p' => 'cuotas', 'a' => 'pendientes'])}}">Existe{{($pendientes > 1) ? 'n' : ''}} {{$pendientes}} cuota{{($pendientes > 1) ? 's' : ''}} pendiente{{($pendientes > 1) ? 's' : ''}}. <span class="glyphicon glyphicon-arrow-right"></span></a></div>
</div>
@endif
<table class="ui table">
<tr>
@if (count($dias) > 0)
<td>
@include('calendario')
</td>
@endif
@if (count($cierres) > 0)
<td>
@include('cierres')
</td>
@endif
</tr>
</table>
@endsection

View File

@ -0,0 +1,49 @@
@extends('layout.base')
@section('content')
<div class="page-heading">
<h2>Comisiones - {{$proyecto->descripcion}}</h2>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Departamento</th>
<th>Propietario</th>
<th class="text-center">Estacionamientos</th>
<th class="text-center">Bodegas</th>
<th colspan="2" class="text-center">Precio</th>
<th colspan="2" class="text-center">Comisi&oacute;n</th>
<th>Operador</th>
</tr>
<tr>
<th colspan="4"></th>
<th class="text-right">Promesa</th>
<th class="text-right">Neto</th>
<th class="text-center">%</th>
<th class="text-right">UF</th>
</tr>
</thead>
<tbody>
@foreach ($ventas as $venta)
<tr>
<td><a href="{{nUrl('ventas', 'show', ['venta' => $venta->id])}}">{{$venta->unidad()->descripcion}}</a></td>
<td>{{$venta->propietario()->nombreCompleto()}}</td>
<td class="text-center">{{implode(' - ', $venta->propiedad()->estacionamientos('array'))}}</td>
<td class="text-center">{{implode(' - ', $venta->propiedad()->bodegas('array'))}}</td>
<td class="text-right">{{format('ufs', $venta->valor_uf, null, true)}}</td>
<td class="text-right">{{format('ufs', $venta->valorCorredora(), null, true)}}</td>
<td class="text-center">1,5 %</td>
<td class="text-right">{{format('ufs', $venta->valorCorredora() * 1.5 / 100, null, true)}}</td>
<td>{{($venta->agente != 0 and $venta->agente()->agente != 1) ? $venta->agente()->agente()->descripcion : ''}}</td>
</tr>
@endforeach
<tr>
<td colspan="4"><b>Total</b></td>
<td class="text-right"><b>{{format('ufs', $totales->precio, null, true)}}</b></td>
<td class="text-right"><b>{{format('ufs', $totales->neto, null, true)}}</b></td>
<td class="text-center"><b>1,5 %</b></td>
<td class="text-right"><b>{{format('ufs', $totales->comision, null, true)}}</b></td>
</tbody>
</table>
<!-- <a href="{{nUrl('informes', 'comisiones_xlsx', ['ventas' => implode(',', $ids)])}}">Excel</a> -->
@endsection

View File

@ -0,0 +1,68 @@
@extends('layout.base')
@section('content')
<h2>Contabilidad</h2>
<form action="#" class="form-horizontal">
<div class="form-group">
<div class="col-md-1">Mes</div>
<div class="col-md-3"><select name="mes" class="form-control">
<option value="">Todo</option>
<?php $f = Carbon\Carbon::today(); ?>
@for ($y = date('Y'); $y >= date('Y') - 5; $y --)
@for ($m = 12; $m > 0; $m --)
@if ($y == date('Y') and $m >= date('m'))
@continue
@endif
<option value="{{$y}}-{{$m}}" @if ($m == $f->month-1 and $y == $f->year) selected="selected" @endif>{{ucwords(strftime('%B - %Y', mktime(0, 0, 0, $m, 1, $y)))}}</option>
@endfor
@endfor
</select></div>
</div>
</form>
<div id="proyectos">
@include('informes.proyectos', ['a' => 'contabilidad'])
</div>
@endsection
@push('scripts')
<script type="text/javascript">
function changeUrl(url, field, change) {
if (url.indexOf(field) > -1) {
var nurl = [];
var info = url.split('&');
$.each(info, function(k, v) {
if (v.indexOf(field) == -1) {
nurl.push(v);
} else {
if (change != '') {
nurl.push(field + '=' + change);
}
}
});
nurl = nurl.join('&');
return nurl;
} else {
if (change != '') {
nurl = url + '&' + field + '=' + change;
return nurl;
}
}
return url;
}
function updateUrls(select, link_id) {
var f = $("select[name='" + select + "']").val();
var links = $('#' + link_id + ' a');
links.each(function(k, v) {
url = $(v).attr('href');
nurl = changeUrl(url, 'fecha', f);
$(v).attr('href', nurl);
});
}
$(document).ready(function() {
$("select[name='mes']").change(function(e) {
updateUrls('mes', 'proyectos');
});
updateUrls('mes', 'proyectos');
});
</script>
@endpush

View File

@ -0,0 +1,6 @@
@extends('layout.base')
@section('content')
<h2>Escrituras</h2>
@include('informes.proyectos', ['a' => 'escrituras'])
@endsection

View File

@ -0,0 +1,6 @@
@extends('layout.base')
@section('content')
<h2>Gantt de Entregas</h2>
@include('informes.proyectos', ['a' => 'gantt_entregas'])
@endsection

View File

@ -0,0 +1,25 @@
@extends('layout.base')
@section('content')
<div class="page-heading">
<h2>Comisiones</h2>
</div>
<br />
<form class="form-horizontal" method="post" action="{{nUrl('informes', 'comisiones')}}">
<div class="form-group">
<div class="col-md-2">Proyecto</div>
<div class="col-md-3"><select class="form-control" name="proyecto">
@foreach ($proyectos as $proyecto)
<option value="{{$proyecto->id}}">{{$proyecto->descripcion}}</option>
@endforeach
</select></div>
</div>
<div class="form-group">
<div class="col-md-2">Unidades</div>
<div class="col-md-5"><textarea name="unidades" class="form-control" rows="5"></textarea></div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-2"><button type="submit" class="form-control">Buscar</button>
</div>
</form>
@endsection

View File

@ -0,0 +1,12 @@
<div class="panel panel-default">
<div class="panel-heading">Proyectos</div>
<ul class="list-group">
@foreach ($proyectos as $proyecto)
<li class="list-group-item">
<a href="{{url('', ['p' => 'informes', 'a' => $a, 'proyecto' => $proyecto->id])}}">
{{$proyecto->descripcion}} - {{$proyecto->inmobiliaria()->abreviacion}}
</a>
</li>
@endforeach
</ul>
</div>

View File

@ -0,0 +1,6 @@
@extends('layout.base')
@section('content')
<h2>Resciliaciones</h2>
@include('informes.proyectos', ['a' => 'resciliaciones'])
@endsection

View File

@ -0,0 +1,71 @@
@extends('layout.base')
@section('content')
<h2>Resumen para Contabilidad</h2>
<form action="#" class="form-horizontal">
<div class="form-group">
<div class="col-md-1">Hasta Mes</div>
<div class="col-md-3"><select name="mes" class="form-control">
<option value="">Todo</option>
<?php $f = Carbon\Carbon::today(); ?>
@for ($y = date('Y'); $y >= date('Y') - 5; $y --)
@for ($m = 12; $m > 0; $m --)
@if ($y == date('Y') and $m >= date('m'))
@continue
@endif
<option value="{{$y}}-{{$m}}" @if ($m == $f->month-1 and $y == $f->year) selected="selected" @endif>
{{ucwords(strftime('%B - %Y', mktime(0, 0, 0, $m, 1, $y)))}}
</option>
@endfor
@endfor
</select></div>
</div>
</form>
<div id="proyectos">
@include('informes.proyectos', ['a' => 'resumen_contabilidad'])
</div>
@endsection
@push('scripts')
<script type="text/javascript">
function changeUrl(url, field, change) {
if (url.indexOf(field) > -1) {
var nurl = [];
var info = url.split('&');
$.each(info, function(k, v) {
if (v.indexOf(field) == -1) {
nurl.push(v);
} else {
if (change != '') {
nurl.push(field + '=' + change);
}
}
});
nurl = nurl.join('&');
return nurl;
} else {
if (change != '') {
nurl = url + '&' + field + '=' + change;
return nurl;
}
}
return url;
}
function updateUrls(select, link_id) {
var f = $("select[name='" + select + "']").val();
var links = $('#' + link_id + ' a');
links.each(function(k, v) {
url = $(v).attr('href');
nurl = changeUrl(url, 'fecha', f);
$(v).attr('href', nurl);
});
}
$(document).ready(function() {
$("select[name='mes']").change(function(e) {
updateUrls('mes', 'proyectos');
});
updateUrls('mes', 'proyectos');
});
</script>
@endpush

View File

@ -0,0 +1,6 @@
@extends('layout.base')
@section('content')
<h2>Ventas</h2>
@include('informes.proyectos', ['a' => 'ventas'])
@endsection

View File

@ -0,0 +1,50 @@
@extends('layout.base')
@section('content')
<div class="row page-heading">
<h3>Agregar Inmobiliaria</h3>
</div>
<br />
<form method="post" class="form-horizontal" action="{{url('', ['p' => 'inmobiliarias', 'a' => 'agregar'])}}">
<div class="form-group">
<div class="col-md-2">RUT</div>
<div class="col-md-3"><input type="text" name="rut" class="form-control" /></div>
</div>
<div class="form-group">
<div class="col-md-2">Raz&oacute;n Social</div>
<div class="col-md-5"><input type="text" name="razon" class="form-control" /></div>
<div class="col-md-2">
<select name="sociedad" class="form-control">
@foreach ($sociedades as $sociedad)
<option value="{{$sociedad->id}}">{{$sociedad->abreviacion}}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group">
<div class="col-md-2">Abreviaci&oacute;n</div>
<div class="col-md-4"><input type="text" name="abrev" class="form-control" /></div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-2"><input type="submit" value="Agregar" class="form-control" /></div>
</div>
</form>
@endsection
@push('scripts')
<script type="text/javascript">
$(document).ready(function() {
$("input[name='rut']").rut({"formatOn": 'keyup', "validateOn": 'blur'}).on('rutInvalido', function(e) {
$(this).parent().next().remove();
$(this).parent().after($('<div></div>').attr('class', 'col-md-2 alert-danger').html('Rut inv&aacute;lido'));
}).on('rutValido', function(e, rut, dv) {
$(this).parent().next().remove();
$.post('{!!url('', ['p' => 'ajax', 'a' => 'inmobiliarias', 'ajax' => true])!!}', {'rut': rut}, function(data) {
$("input[name='razon']").val(data.razon);
$("input[name='abrev']").val(data.abreviacion);
}, 'json');
});
});
</script>
@endpush

View File

@ -0,0 +1,54 @@
@extends('layout.base')
@section('content')
<div class="page-heading">
<h3>Editar <a href="{{nUrl('inmobiliarias', 'show', ['rut' => $inmobiliaria->rut])}}">{{$inmobiliaria->abreviacion}}</a></h3>
</div>
<br />
<form class="form-horizontal" method="post" action="{{nUrl('inmobiliarias', 'do_edit', ['rut' => $inmobiliaria->rut])}}">
<div class="form-group">
<div class="col-md-2">RUT</div>
<div class="col-md-3"><input type="text" name="rut" class="form-control" value="{{$inmobiliaria->rut}}" /></div>
<div class="col-md-1"><input type="text" name="dv" class="form-control" value="{{$inmobiliaria->dv}}" /></div>
</div>
<div class="form-group">
<div class="col-md-2">Abreviaci&oacute;n</div>
<div class="col-md-3"><input type="text" name="abreviacion" class="form-control" value="{{$inmobiliaria->abreviacion}}" /></div>
</div>
<div class="form-group">
<div class="col-md-2">Raz&oacute;n Social</div>
<div class="col-md-4"><input type="text" name="razon" value="{{$inmobiliaria->razon}}" class="form-control" /></div>
<div class="col-md-2">
<select name="sociedad" class="form-control">
@foreach ($sociedades as $sociedad)
<option value="{{$sociedad->id}}"
@if ($sociedad->id == $inmobiliaria->sociedad)
selected="selected"
@endif
>{{$sociedad->abreviacion}}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group">
<div class="col-md-2">Banco</div>
<div class="col-md-3"><select name="banco" class="form-control">
<option value="0">---</option>
@foreach ($bancos as $banco)
<option value="{{$banco->id}}"
@if ($banco->id == $inmobiliaria->id)
selected="selected"
@endif
>{{$banco->nombre}}</option>
@endforeach
</select></div>
</div>
<div class="form-group">
<div class="col-md-2">Cuenta</div>
<div class="col-md-3"><input type="text" name="cuenta" class="form-control" value="{{$inmobiliaria->cuenta}}" /></div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-2"><button type="submit" class="form-control">Edit</button></div>
</div>
</form>
@endsection

View File

@ -0,0 +1,31 @@
@extends('layout.base')
@section('content')
<div class="row page-heading">
<div class="col-md-10 h3">Inmobiliarias</div>
<div class="col-md-2 text-right h4">
<a href="{{url('', ['p' => 'inmobiliarias', 'a' => 'add'])}}">
<span class="glyphicon glyphicon-plus"></span>
</a>
</div>
</div>
<div class="ui segment">
<div class="ui cards">
@foreach ($inmobiliarias as $inmobiliaria)
<div class="card">
<div class="content">
<div class="header">
<a href="{{nUrl('inmobiliarias', 'show', ['rut' => $inmobiliaria->rut])}}">{{$inmobiliaria->nombre()}}</a>
</div>
<div class="meta">
{{$inmobiliaria->rut()}}
</div>
<div class="description">
{{$inmobiliaria->razon(true)}}
</div>
</div>
</div>
@endforeach
</div>
</div>
@endsection

View File

@ -0,0 +1,47 @@
@extends('layout.base')
@section('content')
<div class="row page-heading">
<div class="col-md-10">
<h3>Inmobiliaria {{$inmobiliaria->nombre()}}</h3>
</div>
<div class="col-md-2 text-right h3">
<a href="{{url('', ['p' => 'inmobiliarias', 'a' => 'edit', 'rut' => $inmobiliaria->rut])}}">
<span class="glyphicon glyphicon-edit"></span>
</a>
</div>
</div>
<br />
<div class="row">
<div class="col-md-2">RUT</div>
<div class="col-md-4">{{format('rut', $inmobiliaria->rut)}}-{{$inmobiliaria->dv}}</div>
</div>
<div class="row">
<div class="col-md-2">Raz&oacute;n Social</div>
<div class="col-md-10">{{$inmobiliaria->razon(true)}}</div>
</div>
@if ($inmobiliaria->banco != 0)
<div class="row">
<div class="col-md-2">Cuenta</div>
<div class="col-md-2">{{$inmobiliaria->banco()->nombre}}</div>
<div class="col-md-3">{{$inmobiliaria->cuenta}}</div>
</div>
@endif
<br />
<div class="row">
<div class="col-md-2">Proyectos</div>
<div class="col-md-10 text-right"><a href="{{url('', ['p' => 'proyectos', 'a' => 'add', 'inmobiliaria' => $inmobiliaria->rut])}}"><span class="glyphicon glyphicon-plus"></span></a></div>
</div>
<div class="row">
<div class="col-md-offset-2 col-md-10">
<table class="table table-striped">
@foreach ($inmobiliaria->proyectos() as $proyecto)
<tr>
<td><a href="{{url('', ['p' => 'proyectos', 'a' => 'show', 'proyecto' => $proyecto->id])}}">{{$proyecto->descripcion}}</a></td>
<td>{{$proyecto->estado()->tipo()->etapa()->descripcion}}</td>
</tr>
@endforeach
</table>
</div>
</div>
@endsection

View File

@ -0,0 +1,47 @@
@extends('install.base')
@section('content')
<h3>Create Admin</h3>
<form class="form-horizontal" method="post" action="create_admin.php">
<div class="form-group">
<div class="col-md-2">Username</div>
<div class="col-md-3"><input type="text" name="name" class="form-control" /></div>
</div>
<div class="form-group">
<div class="col-md-2">Password</div>
<div class="col-md-3"><input type="password" name="password" class="form-control" /></div>
<div class="col-md-3" id="msg2"></div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-2"><button type="submit" class="form-control">Create</button></div>
</div>
</form>
@endsection
@push('scripts')
<script type="text/javascript">
$(document).ready(function() {
status = 0;
$("input[name='password']").blur(function(e) {
var result = zxcvbn($(this).val(), user_inputs=[$("input[name='name']").val()]);
if (result.score < 3) {
$('#msg2').html('<span class="label label-danger"><span class="glyphicon glyphicon-warning-sign"></span> Nivel ' + result.score + '</span>');
status = 0;
} else {
if (result.score == 3) {
$('#msg2').html('<span class="label label-warning"><span class="glyphicon glyphicon-ok"></span> Nivel ' + result.score + '</span>');
} else {
$('#msg2').html('<span class="label label-success"><span class="glyphicon glyphicon-ok"></span> Nivel ' + result.score + '</span>');
}
status = 1;
}
});
$("form").submit(function(e) {
if (!status) {
e.preventDefault();
}
return status;
});
};
</script>
@endpush

View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>
@if (isset($titulo))
{{$titulo}} -
@endif
Incoviba S. A.</title>
<link rel="stylesheet" type="text/css" href="../css/app.css" />
<link rel="icon" type="image/png" href="../images/Isotipo 32.png" />
<script type="text/javascript" src="../js/app.js"></script>
@stack('styles')
</head>
<body>
<header>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="logo_cabezal">
<a href="."><img src="../images/logo_cabezal.png" /></a>
</div>
</div>
</div>
</div>
</header>
<div class="container">
<div class="row">
<div class="col-md-12">
@yield('content')
</div>
</div>
</div>
@include('layout.footer')
@stack('scripts')
</body>
</html>

View File

@ -0,0 +1,5 @@
@extends('install.base')
@section('content')
Installation ended. Go to <a href="../">Inicio</a>. Remember to remove install folder.
@endsection

View File

@ -0,0 +1,6 @@
@extends('install.base')
@section('content')
Start Installation
<a href="next_step.php">Create Tables</a>
@endsection

View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>
@if (isset($titulo))
{{$titulo}} -
@endif
Incoviba S. A.</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.7.8/semantic.min.css" />
<link rel="stylesheet" type="text/css" href="css/app.css" />
<link rel="stylesheet" type="text/css" href="css/custom.css" />
<link rel="icon" type="image/png" href="images/Isotipo 32.png" />
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.7.8/semantic.min.js"></script>
@stack('styles')
</head>
<body>
@include('layout.header')
<div class="container">
<div class="row">
<div class="col-md-12">
@yield('content')
</div>
</div>
</div>
@include('layout.footer')
@stack('scripts')
</body>
</html>

View File

View File

@ -0,0 +1,16 @@
<header>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="logo_cabezal">
<a href="."><img src="images/logo_cabezal.png" /></a>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
@include('layout.menu')
</div>
</div>
</div>
</header>

View File

@ -0,0 +1 @@
<span class="glyphicon glyphicon-piggy-bank small" title="Abonar"></span>

View File

@ -0,0 +1,5 @@
<span class="glyphicon glyphicon-plus
@if (isset($small) and $small)
small
@endif
" title="Agregar"></span>

View File

@ -0,0 +1,5 @@
<span class="glyphicon glyphicon-edit
@if (isset($small) and $small)
small
@endif
" title="Editar"></span>

Some files were not shown because too many files have changed in this diff Show More