 <?php

if (isset($_SERVER['HTTP_ORIGIN'])) {
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400'); // cache for 1 day
}

//error_reporting(E_ERROR  | E_PARSE);
session_start();

//$_SESSION['database'] = $_POST['database'];
$_SESSION['coo'] = $_POST['coo'];

//echo "llega".  $_POST['json'];

$url1 = "http://localhost:8080/webservice.carlos/rest/todos/fiscalget3";

$data_string99 = '{"operacion":{"tipo":"2","nombre":"Juanita Sierra","ruc":"25","direccion":"Preparatoria","telefono":"2297596"},
"productos":[{"pr_id":"08989","descripcion":"soda pepsi","cantidad":"5.90","precio":"12345","desc":"0","iva":"7.00"},
{"pr_id":"111","descripcion":"soda coca cola","cantidad":"5.90","precio":"12345","desc":"0","iva":"7.00"}],
"cant_prod":2,"pagos":[{"detalle":"efectivo","monto":"500"}]}';

$data_string = $_SESSION['coo'];

$ch = curl_init($url1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
curl_close($ch);

echo $result;
?>