2021-03-25 21:10:44 -03:00
|
|
|
<?php
|
|
|
|
function route() {
|
|
|
|
return App\Contract\Route::route();
|
|
|
|
}
|
|
|
|
function route_api() {
|
|
|
|
$p = get('page');
|
|
|
|
if (!$p) {
|
|
|
|
$p = get('p');
|
|
|
|
}
|
|
|
|
$a = get('action');
|
|
|
|
if (!$a) {
|
|
|
|
$a = get('a');
|
|
|
|
if (!$a) {
|
|
|
|
$a = 'index';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = "\\App\\Controller\\API\\" . ucfirst($p);
|
|
|
|
if (!class_exists($class)) {
|
|
|
|
throw new \Exception('Controller ' . $class . ' not found.');
|
|
|
|
}
|
|
|
|
if (!method_exists($class, $a)) {
|
|
|
|
throw new \Exception('Route ' . $a . ' not found in Controller ' . $class);
|
|
|
|
}
|
|
|
|
$params = get();
|
|
|
|
unset($params['p']);
|
|
|
|
unset($params['page']);
|
|
|
|
unset($params['a']);
|
|
|
|
unset($params['action']);
|
|
|
|
unset($params['API_KEY']);
|
|
|
|
return call_user_func_array([$class, $a], $params);
|
|
|
|
}
|
|
|
|
function uf($date, $async = false) {
|
|
|
|
if (is_string($date)) {
|
|
|
|
$date = Carbon\Carbon::parse($date, config('app.timezone'));
|
|
|
|
}
|
|
|
|
$next_m_9 = Carbon\Carbon::today(config('app.timezone'))->copy()->endOfMonth()->addDays(9);
|
|
|
|
if ($date->greaterThanOrEqualTo($next_m_9)) {
|
|
|
|
return (object) ['total' => 0];
|
|
|
|
}
|
|
|
|
$url = 'http://' . config('locations.money') . '/api/uf/value/' . $date->format('Y-m-d');
|
2023-02-10 15:14:14 +00:00
|
|
|
$client = new \GuzzleHttp\Client(['base_uri' => 'http://' . config('locations.money') . '/', 'headers' => ['Accept' => 'application/json']]);
|
|
|
|
$response = $client->get('api/uf/value/' . $date->format('Y-m-d'));
|
2021-03-25 21:10:44 -03:00
|
|
|
|
2023-02-10 15:14:14 +00:00
|
|
|
//$response = $client->getResponse();
|
2021-03-25 21:10:44 -03:00
|
|
|
if (!$response) {
|
|
|
|
return (object) ['total' => 0];
|
|
|
|
}
|
|
|
|
$status = $response->getStatusCode();
|
|
|
|
if ($status >= 200 and $status < 300) {
|
2023-02-10 15:14:14 +00:00
|
|
|
$data = json_decode($response->getBody()->getContents());
|
2021-03-25 21:10:44 -03:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
return (object) ['total' => 0];
|
|
|
|
}
|
|
|
|
function format($tipo, $valor, $format = null, $print = false) {
|
2022-04-11 11:01:35 -04:00
|
|
|
if ($valor === null) {
|
|
|
|
$valor = 0;
|
|
|
|
}
|
2021-03-25 21:10:44 -03:00
|
|
|
if (strtolower($tipo) == 'localdate') {
|
|
|
|
$d = \Carbon\Carbon::parse($valor);
|
|
|
|
$d->locale('es_ES');
|
|
|
|
if ($format == null) {
|
|
|
|
$format = 'DD [de] MMMM [de] YYYY';
|
|
|
|
}
|
|
|
|
return $d->isoFormat($format);
|
|
|
|
}
|
|
|
|
if (method_exists('\App\Helper\Format', $tipo)) {
|
|
|
|
if ($print) {
|
|
|
|
return \App\Helper\Format::$tipo($valor, $print);
|
|
|
|
} else {
|
|
|
|
return \App\Helper\Format::$tipo($valor);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch ($tipo) {
|
|
|
|
case 'localDate':
|
|
|
|
if (isset($format)) {
|
|
|
|
$intl = new IntlDateFormatter('es_ES', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'America/Santiago');
|
|
|
|
$intl->setPattern($format);
|
|
|
|
return ucwords($intl->format($valor));
|
|
|
|
}
|
|
|
|
case 'percent':
|
|
|
|
return \App\Helper\Format::number($valor, 2);
|
|
|
|
case 'rut':
|
|
|
|
return \App\Helper\Format::number($valor, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function model(string $class_name) {
|
|
|
|
return \Model::factory($class_name);
|
|
|
|
}
|
|
|
|
function correctNumber($number) {
|
|
|
|
if (strpos($number, ',') !== false) {
|
|
|
|
return str_replace(',', '.', str_replace('.', '', $number));
|
|
|
|
} elseif (substr_count($number, '.') > 1) {
|
|
|
|
return str_replace('.', '', $number);
|
|
|
|
}
|
|
|
|
return $number;
|
|
|
|
}
|
|
|
|
function parseRanges($range, $numeric = true, $negatives = true) {
|
|
|
|
$rns = preg_split('/[,;]+/', $range);
|
|
|
|
$data = [];
|
|
|
|
foreach ($rns as $p) {
|
|
|
|
if (!$negatives) {
|
|
|
|
if (strpos($p, '-') !== false) {
|
|
|
|
list($ini, $end) = explode('-', $p);
|
|
|
|
$data = array_merge($data, range($ini, $end));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($numeric) {
|
|
|
|
$data []= (float) $p;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$data []= $p;
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
function nUrl($p, $a = null, $data = null) {
|
|
|
|
$query = ['p' => $p];
|
|
|
|
if ($a != null) {
|
|
|
|
$query['a'] = $a;
|
|
|
|
if ($data != null) {
|
|
|
|
$query = array_merge($query, $data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return url('', $query);
|
|
|
|
}
|
|
|
|
function api($p, $a, $data = null) {
|
|
|
|
$url = baseUrl() . '/' . 'api';
|
|
|
|
$url .= '?' . 'p=' . $p . '&a=' . $a . '&API_KEY=1';
|
|
|
|
if ($data != null) {
|
|
|
|
$url .= '&' . implode('&', array_map(function($val, $k) {
|
|
|
|
return $k . '=' . $val;
|
|
|
|
}, $data));
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
function doLog($user, $action, $variables) {
|
|
|
|
App\Service\Register::log($user, $action, $variables);
|
|
|
|
}
|
|
|
|
?>
|