<?php
if(!defined('SPECIALCONSTANT')) die('Acceso Denegado');

$app->get('/api/deudaempresas/:dni/:empresas', function( $dni, $empresas ) use($app){

   $respuesta = [];
   $aempresas = explode('-',$empresas);

   if(in_array('timbos',$aempresas )){
      $endpoint = 'http://181.119.121.158/timbossigecre2/public/api/servicioexterno/consultacliente/35260/qmwnenrbtvycuxizopalskdjfhg9632?dni='.$dni;
      $curl = curl_init();
      curl_setopt_array($curl, array(
          CURLOPT_RETURNTRANSFER => 1,
          CURLOPT_POST => 1,
          CURLOPT_URL => $endpoint,
          CURLOPT_USERAGENT => 'api si.ge.cre.'
      ));
      $salida = curl_exec($curl);
      curl_close($curl);
      $valor = json_decode( $salida ) ;
      $respuesta['timbos'] = $valor ;
   }

   if(in_array('mateu',$aempresas )){
      $endpoint = 'http://181.119.121.158/mateusigecre2/public/api/servicioexterno/consultacliente/35260/qmwnenrbtvycuxizopalskdjfhg9632?dni='.$dni;
      $curl = curl_init();
      curl_setopt_array($curl, array(
          CURLOPT_RETURNTRANSFER => 1,
          CURLOPT_POST => 1,
          CURLOPT_URL => $endpoint,
          CURLOPT_USERAGENT => 'api si.ge.cre.'
      ));
      $salida = curl_exec($curl);
      curl_close($curl);
      $valor = json_decode( $salida ) ;
      $respuesta['mateu'] = $valor ;
   }

   if(in_array('creditodo',$aempresas )){
      $endpoint = 'http://181.119.121.23/creditodosigecre2/public/api/servicioexterno/consultacliente/35260/qmwnenrbtvycuxizopalskdjfhg9632?dni='.$dni;
      $curl = curl_init();
      curl_setopt_array($curl, array(
          CURLOPT_RETURNTRANSFER => 1,
          CURLOPT_POST => 1,
          CURLOPT_URL => $endpoint,
          CURLOPT_USERAGENT => 'api si.ge.cre.'
      ));
      $salida = curl_exec($curl);
      curl_close($curl);
      $valor = json_decode( $salida ) ;
      $respuesta['creditodo'] = $valor ;
   }


   $app->response->headers->set('Content-type', 'application/json');
   $app->response->headers->set('Access-Control-Allow-Origin', '*');
   $app->response->headers->set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization');
   $app->response->headers->set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
   $app->response->status(200);

   $app->response->body(json_encode( $respuesta ));





});
