 <?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
}

$_SESSION['database'] = $_GET['database'];

$_SESSION['nodoc'] = $_GET['nodoc'];

include 'conn.php';

include 'funciones.php';

$montoesql = "select nodoc,fecha,nombre,round(sum(cantidad),0) as unidades , count(pr_id) as lineas from " . $_SESSION['database'] . ".toma_inv group by nombre order     by id desc LIMIT 50";

//logs($montoesql);

$qur = $connection->query($montoesql);

$jsonData = array();
$jsonTempData = array();

while ($r = mysqli_fetch_assoc($qur)) {

    $jsonTempData = array();
    $jsonTempData['nodoc'] = $r['nodoc'];
    $jsonTempData['fecha'] = $r['fecha'];

    $jsonTempData['nombre'] = utf8_encode($r['nombre']);
    $jsonTempData['unidades'] = $r['unidades'];
    $jsonTempData['lineas'] = $r['lineas'];

    $jsonData[] = $jsonTempData;
}

print_r(json_encode($jsonData));

//echo $_SESSION['codigo']."@".$_SESSION['costo']."@".$_SESSION['precio1']."@".$_SESSION['precio6']."@".$_SESSION['itbm']."@".$_SESSION['familia'];

$qur=null;
@mysqli_close($connection);
?>