<?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
	{
		// PARAMETROS PARA EXPORTAR
		header("Pragma: public");
		header("Expires: 0");
		$filename = "PedidosAFacturar.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>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>";
					// 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);
					while($fila = sqlsrv_fetch_array($re1))
					{
						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>
		";
	}
	// Desconexion
	sqlsrv_close($conexion);
?>