<?php include "../index/conexion.inc" ?>
<?php include "../index/validacion.php" ?>
<?php
	$cV01 = $_POST['v1'];	/* DESDE */
	$cV02 = $_POST['v2'];	/* HASTA */
?>
<?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
	{
		// CONSULTA SQL
		$sql = "SELECT * \n"
			  ."FROM JOIN_PICKING_ETQ \n"
			  ."WHERE (IDPICKING >= ".$cV01." AND IDPICKING <= ".$cV02.")";
		$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>A continuación te presentamos las NUEVAS etiqueta(s) picking</h3>
					<div class='clearfix'></div>					
				</div>
				<button type='sumit' class='btn btn-warning'
					<span class='glyphicon glyphicon-print' aria-hidden='true'></span> Imprimir etiquetas
				</button>
				<div class='table-responsive'>
					<table class='table table-striped jambo_table bulk_action'>
						<thead>
							<tr class='headings'>
								<th>
									<input type='checkbox' id='check-all' class='flat'>
								</th>
								<th>IDPICKING</th>
								<th>FECHA CREACIÓN</th>
							</tr>
						</thead>";
						while($fila = sqlsrv_fetch_array($re1))
						{
							$cV01 = $fila['IDPICKING'];
							echo "
								<tbody>
									<tr class='even pointer'>
										<td class='a-center'>
											<input type='checkbox' class='flat' name='lista[]' value='".$cV01."'>
										</td>															
										<td>".$fila['IDPICKING']."</td>
										<td>".$fila['FECHA']->format('Y-m-d h:m:s')."</td>
									</tr>
								</tbody>
							";
						}
					echo "
					</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>
	// Script para seleccion o Deseleccionar chekBox
	$("#check-all").on("click", function() {
	  $(".flat").prop("checked", this.checked);
	});
	// if all checkbox are selected, check the selectall checkbox and viceversa
	$(".flat").on("click", function() {
	  if ($(".flat").length == $(".flat:checked").length) {
		$("#check-all").prop("checked", true);
	  } else {
		$("#check-all").prop("checked", false);
	  }
	});
</script>