<?php 
session_start(); 
require_once('../conexion.php');
require_once('../include/sesiones.php');
require_once('../php_api/api.php');


$ser_tipo_documento=$_GET['ser_tipo_documento'];
$iden_soft_ele=$ele['iden_soft_ele'];
$iden_soft_pos=$ele['iden_soft_pos'];

if($ser_tipo_documento=='electronica')
{
    $json = array(
    "IDSoftware" => $iden_soft_ele
    );
    $consulta='si';
}
else if($ser_tipo_documento=='doc_soporte')
{
    $json = array(
    "IDSoftware" => $iden_soft_ele
    );
    $consulta='si';
}
else if($ser_tipo_documento=='pos_electronico')
{
    $json = array(
    "IDSoftware" => $iden_soft_pos
    );
    $consulta='si';
}
else
{
    $consulta='no';
}

if($consulta=='si')
{
    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "{$configuration->base_url}ubl2.1/numbering-range",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_POSTFIELDS =>json_encode($json),

      CURLOPT_HTTPHEADER => array(
        'Content-Type: application/json',
        'accept: application/json',
        'Authorization: Bearer '.$token
      ),
    ));

    $response = curl_exec($curl);
    curl_close($curl);

    $resultado = json_decode($response);

    $ResolutionNumber=$resultado->ResponseDian->Envelope->Body->GetNumberingRangeResponse->GetNumberingRangeResult->ResponseList->NumberRangeResponse;
    $json_ResolutionNumber = json_encode($ResolutionNumber);
    ?>
    <div style="display: none;"><?php $contador= count($ResolutionNumber); ?></div>
    <?php
    if($contador>1){
        
    $array = json_decode($json_ResolutionNumber, true);

    foreach ($array as $value) {
    ?> 
    <div class="widget stacked">
        <div class="widget-content">
            <div class="">                      
                Número resolución:
                <strong><?php echo $value['ResolutionNumber']; ?></strong>
            </div> <!-- /control-group -->
            <div class="">                      
                Fecha de la resolución:
                <strong><?php echo $value['ResolutionDate']; ?></strong>
            </div> <!-- /control-group -->
             <div class="">                      
                Fecha de vencimiento:
                <strong><?php echo $value['ValidDateTo']; ?></strong>
            </div> <!-- /control-group -->
            <div class="">                      
                Prefijo: 
                <strong><?php echo $value['Prefix']; ?></strong>
            </div> <!-- /control-group -->
            <div class="">                      
                Inicia rango de facturación: 
                <strong><?php echo $value['FromNumber']; ?></strong>
            </div> <!-- /control-group -->
            <div class="">                      
                Termina rango de facturación: 
                <strong><?php echo $value['ToNumber']; ?></strong>
            </div> <!-- /control-group --> 
            <div class="">                      
                Clave Tecnica: 
                <span style="color: red;"><strong><?php if (!is_null($value['TechnicalKey'])) echo $value['TechnicalKey']; ?></strong></span>
            </div> <!-- /control-group --> 
            </br>
        </div>
    </div>
    <?php } }
    if($contador==1)
    {

        $ResolutionNumber=$resultado->ResponseDian->Envelope->Body->GetNumberingRangeResponse->GetNumberingRangeResult->ResponseList->NumberRangeResponse->ResolutionNumber;
        $ResolutionDate=$resultado->ResponseDian->Envelope->Body->GetNumberingRangeResponse->GetNumberingRangeResult->ResponseList->NumberRangeResponse->ResolutionDate;
        $ValidDateTo=$resultado->ResponseDian->Envelope->Body->GetNumberingRangeResponse->GetNumberingRangeResult->ResponseList->NumberRangeResponse->ValidDateTo;
        $Prefix=$resultado->ResponseDian->Envelope->Body->GetNumberingRangeResponse->GetNumberingRangeResult->ResponseList->NumberRangeResponse->Prefix;
        $FromNumber=$resultado->ResponseDian->Envelope->Body->GetNumberingRangeResponse->GetNumberingRangeResult->ResponseList->NumberRangeResponse->FromNumber;
        $ToNumber=$resultado->ResponseDian->Envelope->Body->GetNumberingRangeResponse->GetNumberingRangeResult->ResponseList->NumberRangeResponse->ToNumber;
        $TechnicalKey=$resultado->ResponseDian->Envelope->Body->GetNumberingRangeResponse->GetNumberingRangeResult->ResponseList->NumberRangeResponse->TechnicalKey;
     ?>
     <div class="widget stacked">
        <div class="widget-content">
            <div class="">                      
                Número resolución:
                <strong><?php echo $ResolutionNumber; ?></strong>
            </div> <!-- /control-group -->
            <div class="">                      
                Fecha de la resolución:
                <strong><?php echo $ResolutionDate; ?></strong>
            </div> <!-- /control-group -->
             <div class="">                      
                Fecha de vencimiento:
                <strong><?php echo $ValidDateTo; ?></strong>
            </div> <!-- /control-group -->
            <div class="">                      
                Prefijo: 
                <strong><?php echo $Prefix; ?></strong>
            </div> <!-- /control-group -->
            <div class="">                      
                Inicia rango de facturación: 
                <strong><?php echo $FromNumber; ?></strong>
            </div> <!-- /control-group -->
            <div class="">                      
                Termina rango de facturación: 
                <strong><?php echo $ToNumber; ?></strong>
            </div> <!-- /control-group --> 
            <div class="">                      
                Clave Tecnica: 
                <span style="color: red;"><strong><?php if (!is_null($TechnicalKey)) echo $TechnicalKey; ?></strong></span>
            </div> <!-- /control-group --> 
            </br>
        </div>
    </div>

    <?php }
    if($contador<=0)

    {
        echo '<div class="alert alert-success alert-dismissable">
                <strong>No tiene Resoluciones Asociadas en el portal de Dian.</strong> 
            </div>';
    }
}
else
{
     echo '<div class="alert alert-success alert-dismissable">
                <strong>Para el tipo de documento seleccionado no necesitas Resoluciones asociadas en el portal de Dian.</strong> 
            </div>';
}

?>
