 <?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['nombre'] = $_GET['nombre'];

include 'conn.php';

include 'funciones.php';

$montoesql = "SELECT id,toma_inv.pr_id,round(cantidad,0) as cantidad,fecha ,productos.pr_descripcion FROM " . $_SESSION['database'] . ".toma_inv  left outer join " . $_SESSION['database'] . ".productos on toma_inv.pr_id=productos.pr_id where nombre='" . $_SESSION['nombre'] . "'  order by id desc limit 20 ";

//echo   $montoesql;
//logs($montoesql);

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

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

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

    $jsonTempData = array();
    $jsonTempData['id'] = $r['id'];
    $jsonTempData['pr_id'] = $r['pr_id'];
    $jsonTempData['cantidad'] = $r['cantidad'];
    $jsonTempData['fecha'] = $r['fecha'];
    $jsonTempData['pr_descripcion'] = utf8_encode($r['pr_descripcion']);

    $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);
?>