<?php
include 'conn.php';
//Select data from database

include 'funciones.php';
//error_reporting(E_ERROR  | E_PARSE);

session_start();
$_SESSION['database'] = $_GET['database'];

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

//$info=$_SESSION["newsession"];
/*session created*/
//echo $_SESSION["newsession"];

$getData = "SELECT ex.pr_id, dp.dep_descripcion, ex.p_existencia AS Exist_Total, ex.p_pventas   AS Exist_Ped, ex.p_apartado  AS
             Exist_Apart,  ex.p_existencia - (ex.p_pventas+ex.p_apartado) AS Exist_Disp, dp.dep_id  FROM  " . $_SESSION['database'] . ".prod_existencia ex
				     LEFT OUTER JOIN " . $_SESSION['database'] . ".depositos dp ON ex.p_existencia_dep_id=dp.dep_id
				     JOIN " . $_SESSION['database'] . ".productos p ON ex.pr_id = p.pr_id
             WHERE ex.pr_id = '" . $_SESSION['pr_id'] . "' or upper(p.pr_referencia) like upper('%" . $_SESSION['pr_id'] . "%')  ORDER BY ex.pr_id, ex.p_existencia_dep_id, p.pr_referencia ";

logs($getData);

//$getData = "select * from user";
$qur = $connection->query($getData);

$msg = 'false';

logs('paso al otro');

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

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

    logs('paso al otro3');

//echo '<br/>';
    //$msg='true';

//$msg = array("suc_id" => $r['suc_id'], "suc_descripcion" => $r['suc_descripcion']);

    $jsonTempData = array();
    $jsonTempData['pr_id'] = $r['pr_id'];

    $jsonTempData['dep_id'] = $r['dep_id'];
    $jsonTempData['dep_descripcion'] = $r['dep_descripcion'];

    $jsonTempData['Exist_Total'] = $r['Exist_Total'];
    $jsonTempData['Exist_Ped'] = $r['Exist_Ped'];

    $jsonTempData['Exist_Apart'] = $r['Exist_Apart'];
    $jsonTempData['Exist_Disp'] = $r['Exist_Disp'];

    $jsonData[] = $jsonTempData;

}

//header('content-type: application/json');
echo json_encode($jsonData);

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