Contacto en inicio
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user