<?php include "../index/conexion.inc" ?>
<?php include "../index/validacion.php" ?>
<?php
	$cV00 = $_POST['bodega'];
	// conexión
	$servername = $svr_servidor;
	$conectioninfo = array("Database"=>$svr_base, "UID"=>$svr_usuario, "PWD"=>$svr_contrasena, "CharacterSet"=>"UTF-8");
	$conexion = sqlsrv_connect($servername, $conectioninfo);
	if ($conexion == false)
	{
		$mensaje = "Existe un error al intentar conectarse con el servidor...";
	}
	else
	{
		// PARAMETROS PARA EXPORTAR
		header("Pragma: public");
		header("Expires: 0");
		$filename = "StockPorUbicacion.xls";
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=$filename");
		header("Pragma: no-cache");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		echo "
			<table>
				<thead>
					<tr>
						<th>COD.ARTICULO</th>
						<th>TALLA</th>
						<th>COLOR</th>
						<th>REF.PROVEEDOR</th>
						<th>DESCRIPCION</th>
						<th>CAJA MASTER</th>
						<th>STOCK</th>
						<th>IDUBICACION</th>
						<th>COD.UBICACION</th>
						<th>BODEGA</th>
						<th>ALMACEN</th>
					</tr>
				</thead>
				<tbody>";
					// CONSULTA SQL
					$sql = "EXECUTE dbo.JOIN_INV_RE_STOCK '".$cV00."'";
					$pa1 = array();
					$op1 = array("scrollable" => SQLSRV_CURSOR_KEYSET);
					// Lanzar la consulta
					$re1 = sqlsrv_query($conexion, $sql, $pa1, $op1);
					while($fila = sqlsrv_fetch_array($re1))
					{
						echo "
							<tr>
								<td>".$fila['CODARTICULO']."</td>
								<td>".$fila['TALLA']."</td>
								<td>".$fila['COLOR']."</td>
								<td>".$fila['REFPROVEEDOR']."</td>
								<td>".$fila['DESCRIPCION']."</td>
								<td>".$fila['CAJAMASTER']."</td>
								<td>".$fila['STOCK']."</td>
								<td>".$fila['IDUBICACION']."</td>
								<td>".$fila['CODUBICACION']."</td>
								<td>".$fila['BODEGA']."</td>
								<td>".$fila['NOMBREALMACEN']."</td>
							</tr>
						";
					}
				echo "
				</tbody>
			</table>
		";
	}
	// Desconexion
	sqlsrv_close($conexion);
?>