This commit is contained in:
2021-03-25 23:33:37 -03:00
parent cd1ee7d446
commit 8fe357cc95
16 changed files with 216 additions and 58 deletions

View File

@ -1,16 +1,12 @@
<?php
namespace App\Controller\API;
use App\Definition\Controller;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Incoviba\old\Proyecto\Proyecto;
use Incoviba\old\Venta\Unidad;
class Unidades {
use Controller;
public static function unidades_no_reservadas() {
$id_proyecto = get('proyecto');
$id_tipo = get('tipo');
public function no_reservadas(Request $request, Response $response, $id_proyecto, $id_tipo) {
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
if (!$proyecto) {
throw new \InvalidArgumentException('Proyecto identificado por ' . $id_proyecto . ' no existe.');
@ -39,6 +35,7 @@ class Unidades {
);
});
$output = array_values($unidades);
return json_encode($output);
$response->getBody()->write(\json_encode($output));
return $response->withHeader('Content-Type', 'application/json');
}
}

View File

@ -250,7 +250,7 @@ class Cierres
public static function evalue()
{
$proyectos = \model(Proyecto::class)->orderByAsc('descripcion')->findMany();
return view('ventas.cierres.evaluar', compact('proyectos'));
return view('ventas.cierres.evaluar', ['proyectos' => $proyectos, 'locations' => config('locations')]);
}
public static function evaluar()
{

View File

@ -17,7 +17,12 @@
"phpoffice/phpword": "^0.14.0",
"slam/php-excel": "^4.4",
"fabpot/goutte": "^3.2",
"incoviba/modelos": "dev-master"
"incoviba/modelos": "dev-master",
"slim/slim": "4.x-dev",
"php-di/slim-bridge": "dev-master",
"rubellum/slim-blade-view": "dev-master",
"nyholm/psr7": "1.4.x-dev",
"nyholm/psr7-server": "dev-master"
},
"require-dev" : {
"phpunit/phpunit" : "^6.3",
@ -44,11 +49,17 @@
"repositories": [
{
"type": "path",
"url": "aldarien/**"
"url": "./aldarien/**",
"options": {
"symlink": false
}
},
{
"type": "path",
"url": "incoviba/modelos"
"url": "./incoviba/modelos",
"options": {
"symlink": false
}
}
]
}

View File

@ -181,13 +181,15 @@ class Unidad extends Model
public function isVendida() {
if ($this->is_vendidad == null) {
$this->is_vendida = false;
$p = $this->propiedad();
if ($p) {
$v = $p->venta();
if ($v) {
$this->is_vendida = true;
try {
$p = $this->propiedad();
if ($p) {
$v = $p->venta();
if ($v) {
$this->is_vendida = true;
}
}
}
} catch(\Exception $e) {}
}
return $this->is_vendida;
}

View File

@ -1,35 +1,8 @@
<?php
include_once realpath(dirname(__DIR__, 2) . '/bootstrap/autoload.php');
$get = $_GET;
$post = $_POST;
function get_keys() {
$filename = realpath('./keys');
$keys = [];
if ($filename !== false) {
$keys = json_decode(trim(file_get_contents($filename)));
}
return $keys;
}
function validate_key($keys, $key) {
if (array_search($key, $keys) !== false) {
return true;
}
return false;
}
$keys = get_keys();
$key = $get['API_KEY'];
if (!validate_key($keys, $key)) {
throw new Exception('Error en la identificacion.');
}
$p = $get['page'] ?? $get['p'];
$a = $get['action'] ?? $get['a'];
if ($p == 'precios' and $a == 'importar') {
echo json_encode($post);
} else {
echo route_api();
}
$__environment = 'api';
include_once implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 2),
'setup',
'app.php'
]);
$app->run();

8
resources/routes/api.php Normal file
View File

@ -0,0 +1,8 @@
<?php
$files = new DirectoryIterator(__DIR__ . '/api');
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
include_once $file->getRealPath();
}

View File

@ -0,0 +1,6 @@
<?php
use App\Controller\API\Unidades;
$app->group('/unidades', function($app) {
$app->get('/no_reservadas/{id_proyecto}/{id_tipo}', [Unidades::class, 'no_reservadas']);
});

View File

@ -69,8 +69,7 @@
@push('scripts')
<script type="text/javascript">
function findUnidades(proyecto) {
$.getJSON('{!!api('unidades', 'unidades_no_reservadas')!!}&proyecto=' + proyecto + '&tipo=1', function(data) {
//$.post('{!!nUrl('ajax', 'unidades', ['ajax' => true])!!}', {proyecto: proyecto, tipo: 1}, function(data) {
$.getJSON('{!!$locations['api']!!}/unidades/no_reservadas/' + proyecto + '/1', function(data) {
var unidades = $('#departamento')
unidades.html('')
$.each(data, function(i, el) {
@ -79,13 +78,12 @@
}
unidades.append($('<option></option>').attr('value', el.id).html(el.descripcion));
})
})//, 'json')
})
}
var unis = []
function agregarUnidad(tipo) {
var proyecto = $('#proyecto').val()
$.getJSON('{!!api('unidades', 'unidades_no_reservadas')!!}&proyecto=' + proyecto + '&tipo=' + tipo, function(data) {
//$.post('{!!nUrl('ajax', 'unidades', ['ajax' => true])!!}', {proyecto: proyecto, tipo: tipo}, function(data) {
$.getJSON('{!!$locations['api']!!}/unidades/no_reservadas/' + proyecto + '/' + tipo, function(data) {
var unidades = $('#unidades')
var n = unis[unis.length - 1] + 1;
if (unis.length == 0) {
@ -128,7 +126,7 @@
i = $(this).attr('data-id');
removeUnidad(i);
});
})//, 'json')
})
}
function removeUnidad(n) {
var unidades = $('#unidades');

11
setup/api/config.php Normal file
View File

@ -0,0 +1,11 @@
<?php
use Psr\Container\ContainerInterface as Container;
return [
'locations' => DI\decorate(function($prev, Container $c) {
$arr = (array) $prev;
$arr['cache'] = $prev->base . '/cache';
$arr['views'] = $prev->resources . '/views';
return (object) $arr;
})
];

15
setup/api/setups.php Normal file
View File

@ -0,0 +1,15 @@
<?php
use Psr\Container\ContainerInterface as Container;
return [
Slim\Views\Blade::class => function(Container $c) {
return new Slim\Views\Blade(
$c->get('locations')->views,
$c->get('locations')->cache,
null,
[
'locations' => $c->get('locations')
]
);
}
];

52
setup/app.php Normal file
View File

@ -0,0 +1,52 @@
<?php
use DI\ContainerBuilder as Builder;
use DI\Bridge\Slim\Bridge;
include_once 'composer.php';
$folders = [
'env',
'common',
$__environment
];
$files = [
'config',
'setups'
];
$builder = new Builder();
foreach ($files as $file) {
foreach ($folders as $folder) {
$filename = implode(DIRECTORY_SEPARATOR, [
__DIR__,
$folder,
$file . '.php'
]);
if (!file_exists($filename)) {
continue;
}
$builder->addDefinitions($filename);
}
}
$container = $builder->build();
$app = Bridge::create($container);
$app->setBasePath('/api');
$app->addRoutingMiddleware();
foreach ($folders as $folder) {
$filename = implode(DIRECTORY_SEPARATOR, [
__DIR__,
$folder,
'middleware.php'
]);
if (!file_exists($filename)) {
continue;
}
include_once $filename;
}
$app->addErrorMiddleware(true, true, true);
include_once 'database.php';
include_once 'router.php';

40
setup/common/config.php Normal file
View File

@ -0,0 +1,40 @@
<?php
return [
'timezone' => 'America/Santiago',
'locale' => 'es',
'database' => 'mysql',
'login_hours' => 5*24,
'cierres' => [
'caducidad' => 30
],
'databases' => function() {
$arr = [
'mysql' => [
'host' => 'db',
//'port' => 3306,
'database' => 'incoviba',
'username' => 'incoviba',
'password' => '5GQYFvRjVw2A4KcD'
],
'mysql_copy' => [
'host' => 'localhost',
'database' => 'incoviba3',
'username' => 'incoviba',
'password' => '5GQYFvRjVw2A4KcD'
]
];
return $arr;
},
'locations' => function() {
$arr = ['base' => dirname(__DIR__, 2)];
$arr['public'] = $arr['base'] . '/public';
$arr['resources'] = $arr['base'] . '/resources';
$arr['routes'] = $arr['resources'] . '/routes';
$arr['src'] = $arr['base'] . '/src';
$arr['app'] = $arr['base'] . '/app';
$arr['controllers'] = $arr['app'] . '/Controller';
$arr['money'] = 'http://provm.cl/optimus/money';
$arr['api'] = 'http://localhost:8080/api';
return (object) $arr;
}
];

6
setup/composer.php Normal file
View File

@ -0,0 +1,6 @@
<?php
include_once implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__),
'vendor',
'autoload.php'
]);

29
setup/database.php Normal file
View File

@ -0,0 +1,29 @@
<?php
$databases = $app->getContainer()->get('databases');
load($databases['mysql']);
foreach ($databases as $name => $data) {
load($data, $name);
}
function load($data, $name = '') {
if (!isset($data['port'])) {
$port = 3306;
} else {
$port = $data['port'];
}
$dsn = 'mysql:host=' . $data['host'] . ';port=' . $port . ';dbname=' . $data['database'] . ';charset=utf8';
if ($name != '') {
ORM::configure($dsn, null, $name);
ORM::configure('username', $data['username'], $name);
ORM::configure('password', $data['password'], $name);
} else {
ORM::configure($dsn, null);
ORM::configure('username', $data['username']);
ORM::configure('password', $data['password']);
}
}
Model::$short_table_names = true;

5
setup/env/config.php vendored Normal file
View File

@ -0,0 +1,5 @@
<?php
return [
'debug' => false,
'benchmark' => false
];

5
setup/router.php Normal file
View File

@ -0,0 +1,5 @@
<?php
include_once implode(DIRECTORY_SEPARATOR, [
$app->getContainer()->get('locations')->routes,
$__environment . '.php'
]);