<?php include "../index/conexion.inc" ?>
<?php include "../index/validacion.php" ?>
<?php
	// conexión
	$servername = $svr_servidor;
	$conectioninfo = array("Database"=>"JOININTEGRADOR", "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
	{
		echo "
		<div class='x_panel'>
			<div class='x_title'>
				<h3>LOG Join Pagos</h3>
				<div class='clearfix'></div>
			</div>
			<button type='submit' class='btn btn-success'>
				<span class='glyphicon glyphicon-export' aria-hidden='true'></span> Exportar a excel
			</button>
			<div class='col-md-6 col-sm-6 col-xs-12'>
				<input class='form-control' id='myInput' type='text' placeholder='Buscar...'>
			</div>
			<div class='table-responsive'>
				<table class='table table-striped jambo_table bulk_action'>
					<thead>
						<tr>
							<th>ITEMCODE</th>
							<th>ALMACEN</th>
							<th>CANTIDAD</th>
							<th>CENTRO</th>
							<th>DIRECCION</th>
							<th>DEPARTAMENTO</th>
							<th>COLOR</th>
							<th>TALLA</th>
						</tr>
					</thead>
					<tbody id='myTable'>";
						// CONSULTA SQL
						$sql = "SELECT * FROM JOININTEGRADOR.DBO.ws_log WHERE (IdWS = 34) ORDER BY IdLog ASC";
						$pa1 = array();
						$op1 = array("scrollable" => SQLSRV_CURSOR_KEYSET);
						// Lanzar la consulta
						$re1 = sqlsrv_query($conexion, $sql, $pa1, $op1);
						while($fila = sqlsrv_fetch_array($re1))
						{
							$json = $fila['Trama'];
							$objt = json_decode($json,"true");
							$cV01 = $objt["Encabezado"]["0"]["Detalle"]["0"]["ItemCode"];
							$cV02 = $objt["Encabezado"]["0"]["Detalle"]["0"]["Almacen"];
							$cV03 = $objt["Encabezado"]["0"]["Detalle"]["0"]["Cantidad"];
							$cV04 = $objt["Encabezado"]["0"]["Detalle"]["0"]["Centro"];
							$cV05 = $objt["Encabezado"]["0"]["Detalle"]["0"]["DIreccion"];
							$cV06 = $objt["Encabezado"]["0"]["Detalle"]["0"]["Departamento"];
							$cV07 = $objt["Encabezado"]["0"]["Detalle"]["0"]["Color"];
							$cV08 = $objt["Encabezado"]["0"]["Detalle"]["0"]["Talla"];
							$sq2 = "INSERT INTO provicional (ItemCode, Almacen, Cantidad, Centro, DIreccion, Departamento, Color, Talla) VALUES ( \n"
								  ."'$cV01', '$cV02', '$cV03', '$cV04', '$cV05', '$cV06', '$cV07', '$cV08')";
							$pa2 = array();
							$op2 = array("scrollable" => SQLSRV_CURSOR_KEYSET);
							$re2 = sqlsrv_query($conexion, $sq2, $pa2, $op2);
						} 
						echo "
					</tbody>
				</table>
			</div>
		</div>";
		sqlsrv_free_stmt($re1);
	}
	sqlsrv_close($conexion);
?>
<script>
	$(document).ready(function(){
	  $("#myInput").on("keyup", function() {
		var value = $(this).val().toLowerCase();
		$("#myTable tr").filter(function() {
		  $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
		});
	  });
	});
</script>