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

$tipo_res=$_GET['tipo_res']; 
$can=mysqli_query($api,"SELECT MAX(id)as id  FROM resolutions ") or die(mysqli_error($con)); 
$dato=mysqli_fetch_array($can);
$id=$dato['id']+1;

if($tipo_res=='electronica')
{
   $curl = curl_init();
    curl_setopt_array($curl, array(
    CURLOPT_URL => "{$configuration->base_url}ubl2.1/config/resolution",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_POSTFIELDS =>'{
    "type_document_id": 1,
    "prefix": "SETP",
    "resolution": "18760000001",
    "resolution_date": "2019-01-19",
    "technical_key": "fc8eac422eba16e22ffd8c6f94b3f40a6e38162c",
    "from": 990000000,
    "to": 995000000,
    "generated_to_date": 0,
    "date_from": "2019-01-19",
    "date_to": "2030-01-19"
    }
',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'accept: application/json',
    'Authorization: Bearer '.$token
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

}
else
{
    $curl = curl_init();
    curl_setopt_array($curl, array(
    CURLOPT_URL => "{$configuration->base_url}ubl2.1/config/resolution",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_POSTFIELDS =>'{
    "type_document_id": 15,
    "prefix": "EPOS",
    "resolution": "18760000001",
    "resolution_date": "2019-01-19",
    "from": 1,
    "to": 1000000,
    "generated_to_date": 0,
    "date_from": "2019-01-19",
    "date_to": "2030-01-19"
    }
  ',
    CURLOPT_HTTPHEADER => array(
      'Content-Type: application/json',
      'accept: application/json',
        'Authorization: Bearer '.$token
    ),
    ));

    $response = curl_exec($curl);

    curl_close($curl);
    echo $response;
}

echo '<meta http-equiv="refresh" content="2;url=../A_api.php">'; 
?>