<?php include "../index/conexion.inc" ?>
<?php include "../index/validacion.php" ?>
<?php
	// 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
	{
		$cV00 = $_POST['v1'];
		// 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);
		if (sqlsrv_num_rows($re1) != 0)
		{
			echo "
			<div class='x_panel'>
				<div class='x_title'>
					<h3>Stock por ubicación</h3>
					<button type='submit' class='btn btn-success'>
						<span class='glyphicon glyphicon-export' aria-hidden='true'></span> Exportar a excel
					</button>
					<div class='clearfix'></div>					
				</div>
				<div class='table-responsive'>
					<table id='example' class='table table-striped table-bordered' style='width:100%'>
						<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>";
						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>
				</div>
			</div>
			";
		}
		else
		{
			echo "
			<div class='alert alert-warning alert-dismissible fade in' role='alert'>
			<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span>
			</button>
				Registros <strong>NO</strong> localizados.
			</div>
			";
		}
		sqlsrv_free_stmt($re1);
	}
	sqlsrv_close($conexion);
?>
<script>
	$(document).ready(function() {
		$('#example').DataTable();
	} );
</script>