Contacto en inicio

This commit is contained in:
2020-05-12 19:12:54 -04:00
parent 9084ea5edb
commit 1ed3788e87
12 changed files with 239 additions and 40 deletions

View File

@ -2,6 +2,7 @@
namespace ProVM\KI\Common\Service;
use GuzzleHttp\Client;
use Carbon\Carbon;
class Indicadores {
//protected $cliente;
@ -14,7 +15,7 @@ class Indicadores {
$url = implode('/', [
$this->base_uri,
$indicador,
$fecha->format('d-m-Y')
$fecha->format('Y')
]);
if ( ini_get('allow_url_fopen') ) {
$json = file_get_contents($url);
@ -25,10 +26,32 @@ class Indicadores {
curl_close($curl);
}
$data = json_decode($json);
$valor = 0;
$output = (object) [
'valor' => 0,
'fecha' => $fecha->format('d-m-Y')
];
if (isset($data->serie[0])) {
$valor = $data->serie[0]->valor;
$n = 0;
foreach ($data->serie as $i => $d) {
if (Carbon::parse($d->fecha)->format('d-m-Y') == $fecha->format('d-m-Y')) {
$n = $i;
break;
}
}
$output->fecha = Carbon::parse($data->serie[$n]->fecha)->format('d-m-Y');
$output->valor = $data->serie[$n]->valor;
switch ($data->unidad_medida) {
case 'Pesos':
$output->valor = '$ ' . number_format($output->valor, 2, ',', '.');
break;
case 'Porcentaje':
$output->valor = number_format($output->valor, 2, ',', '.') . '%';
break;
case 'Dólar':
$output->valor = 'US$ ' . number_format($output->valor, 2, ',', '.');
break;
}
}
return $valor;
return $output;
}
}