<?php include "conexion.inc" ?>
<?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 = "EXECUTE JOIN_INFORMES_PEDPORFAC";
		$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>Pedidos a facturar</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>SERIE</th>
								<th>PEDIDO</th>
								<th>FECHA PEDIDO</th>
								<th>CODIDGO CLIENTE</th>
								<th>NOMBRE CLIENTE</th>
								<th>FACTURAR</th>
								<th>ID.PICKING</th>
								<th>METODO PAGO (1)</th>
								<th>METODO PAGO (2)</th>
							</tr>
						</thead>
						<tbody>";
						while($fila = sqlsrv_fetch_array($re1))
						{
							$cV01 = $fila['NUMSERIE'];
							$cV02 = $fila['NUMPEDIDO'];
							echo "
								<tr>
									<td>".$fila['NUMSERIE']."</td>
									<td>".$fila['NUMPEDIDO']."</td>
									<td>".$fila['FECHAPEDIDO']."</td>
									<td>".$fila['CODCLIENTE']."</td>
									<td>".$fila['NOMBRECLIENTE']."</td>
									<td>".$fila['FACTURAR']."</td>
									<td>".$fila['IDPICKING']."</td>
									<td>".$fila['FORMA_PAGO']."</td>
									<td>".$fila['FORMA_PAGO2']."</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>