<?php include "../index/conexion.inc" ?>
<!doctype html>
<html lang="es">
	<head>
		<?php include '../index/head.php'; ?>
	</head>
	<body>
		<div class="container body">
			<div class="main_container">
				<!-- page content -->
				<div class="right_col" role="main">
					<div class="">
						<div class="clearfix"></div>
						<div class="x_panel">
							<div class="x_title">
								<h2>DOCUMENTO: <?php echo $_GET['id']; ?></h2>
								<div class="clearfix"></div>
							</div>
							<div class="x_content">
								<div class="row">
									<table id="datatable" class="table table-striped table-bordered">
										<thead>
											<tr>
												<th>ARTICULO</th>
												<th>REFERENCIA</th>
												<th>DESCRIPCION</th>
												<th>CODIGO DE BARRAS</th>
												<th>TALLA</th>
												<th>COLOR</th>
												<th>UNIDADES</th>
												<th>CAJA MASTER</th>
												<th>UBICACION</th>
												<th></th>
											</tr>
										</thead>
										<tbody>
											<?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
												{
													$cV01 = $_GET['id'];
													// CONSULTA SQL
													$sql = "SELECT D.*, L.CODBARRAS, A.REFPROVEEDOR, A.DESCRIPCION \n"
														  ."FROM JOIN_DEVOLUCIONES AS D \n"
														  ."INNER JOIN ARTICULOSLIN AS L ON (D.CODIGOARTICULO = L.CODARTICULO) AND (D.TALLA = L.TALLA COLLATE Modern_Spanish_CI_AS) AND (D.COLOR = L.COLOR COLLATE Modern_Spanish_CI_AS) \n"
														  ."INNER JOIN ARTICULOS AS A ON (L.CODARTICULO = A.CODARTICULO) \n"
														  ."WHERE (MODULO = 2) AND (DOCUMENTO = ".$cV01.") \n"
														  ."ORDER BY D.FECHA DESC";
													$pa1 = array();
													$op1 = array("scrollable" => SQLSRV_CURSOR_KEYSET);
													// Lanzar la consulta
													$re1 = sqlsrv_query($conexion, $sql, $pa1, $op1);
													while($fila = sqlsrv_fetch_array($re1))
													{
														$cV01 = $fila['IDDEVOLUCION'];
														echo "
															<tr>
																<td>".$fila['CODIGOARTICULO']."</td>
																<td>".$fila['REFPROVEEDOR']."</td>
																<td>".$fila['DESCRIPCION']."</td>
																<td>".$fila['CODBARRAS']."</td>
																<td>".$fila['TALLA']."</td>
																<td>".$fila['COLOR']."</td>
																<td>".$fila['CANTIDADDEVUELTA']."</td>
																<td>".$fila['CAJAMASTER']."</td>
																<td>".$fila['UBICACION']."</td>
																<td>
																	<button class='btn btn-sm btn-dark' onclick=popupDEL('$cV01') type='button' data-placement='top' data-toggle='tooltip' data-original-title='Elimina la fila seleccionada'><i class='fa fa-trash'></i></button>
																</td>
															</tr>
														";
													}
												}
											?>
										</tbody>
									</table>										
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- /page content -->
			</div>
		</div>
		<?php include '../index/fbody.php'; ?>
	</body>
</html>
<script>
	var mipopup;
	function popupDEL(d01)
	{
		if(!confirm('Eliminar la fila seleccionada?'))
			return;
		v01 = d01;
		posicion_x=(screen.width/2)-(1100/2);
		posicion_y=(screen.height/2)-(650/2)-50;
		mipopup = window.open("reporte_14_del.php?id="+v01, "WinPedDeL", "width=1100, Height=650, menubar=0, toolbar=0,directories=0,scrollbars=no,resizable=no,left="+posicion_x+",top="+posicion_y+"");
		mipopup.focus()
	}
</script>