<?php

require_once("../../include/dbcommon.php"); // DataBase PHPRunner

if (!isset($_POST['ID'])) { //  Control of the call and verification of the existence of the parameter
  echo("Please provide a Valor.");
  die();
}
$id = $_POST['ID'];

// Datos de cabecera de factura 
$sql = 
"SELECT
idfactura, cliente_idcliente, Nif, NombreRazonSocial,
Domicilio, RestoDomicilio, FechaFactura, TotalFactura, Email
FROM factura
WHERE idfactura = $id   
";
$rs = DB::Query($sql);
$invoice = $rs->fetchAssoc();

// Datos de líneas de Factura
$sql = 
"SELECT Nombre, Precio, Cantidad, Valor
FROM linea_factura
WHERE  factura_idfactura = $id
";
$lines = array();
$rs = DB::Query($sql);
 
while( $line = $rs->fetchAssoc() )
{
$lines[]= $line;
}

$data = array();
$data['invoice'] = $invoice;
$data['lines'] = $lines;


$json = json_encode($data,JSON_NUMERIC_CHECK);

header_remove('X-Powered-By'); // Opcional: elimina el header de PHP
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-Type: application/json; charset=utf-8');

echo $json;
