<?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>PEDIDO: <?php echo $_GET['id']; ?> | SERIE: <?php echo $_GET['id2']; ?> | SUPEDIDO: <?php echo $_GET['id3']; ?> | CARRITO: <?php echo $_GET['id4']; ?></h2>
								<a href="reporte_13_xls.php?id=<?php echo $_GET['id']; ?>&id2=<?php echo $_GET['id2']; ?>&id3=<?php echo $_GET['id3']; ?>&id4=<?php echo $_GET['id4']; ?>&id5=<?php echo $_GET['id5']; ?>" target="_blank">
									<button class='btn btn-sm btn-success' type='button' data-placement='top' data-toggle='tooltip' data-original-title='Detalle'><i class='fa fa-file-pdf-o'></i> Exportar Excel</button>
								</a>
								<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>TALLA</th>
												<th>COLOR</th>
												<th>UNIDADES</th>
												<th>UNIDADES RECIBIDAS</th>
												<th>CARRITO</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['id3'];
													$cV02 = $_GET['id4'];
													// CONSULTA SQL
													$sql = "SELECT TR.IDDEVOLUCION, TR.DOCUMENTO, A.CODARTICULO, A.REFPROVEEDOR, A.DESCRIPCION, TR.TALLA, TR.COLOR, TR.CANTIDADDEVUELTA AS UNIDADES, \n"
														  ."										   (
				SELECT SUm(CANTIDADDEVUELTA)UD FROM JOIN_DEVOLUCIONES AS D WHERE D.DOCUMENTO = TR.DOCUMENTO AND D.ICG =TR.ICG AND D.MODULO = '30' AND D.CODIGOARTICULO = TR.CODIGOARTICULO AND D.TALLA = TR.TALLA AND D.COLOR = TR.COLOR )   AS UNIDADES_RECIBIDAS, TR.ICG \n"
														  ."FROM JOIN_DEVOLUCIONES AS TR LEFT JOIN ARTICULOS AS A ON TR.CODIGOARTICULO = A.CODARTICULO \n"
														  ."WHERE (TR.MODULO IN( 22,220))  AND (TR.DOCUMENTO = '".$cV01."') AND (TR.ICG = ".$cV02.")";
													$pa1 = array();
													$op1 = array("scrollable" => SQLSRV_CURSOR_KEYSET);
													// Lanzar la consulta
													$re1 = sqlsrv_query($conexion, $sql, $pa1, $op1);
													while($fila = sqlsrv_fetch_array($re1))
													{
														$cV03 = $fila['IDDEVOLUCION'];
														$cV04 = $fila['UNIDADES_RECIBIDAS'];
														echo "
															<tr>
																<td>".$fila['CODARTICULO']."</td>
																<td>".$fila['REFPROVEEDOR']."</td>
																<td>".$fila['DESCRIPCION']."</td>
																<td>".$fila['TALLA']."</td>
																<td>".$fila['COLOR']."</td>
																<td>".$fila['UNIDADES']."</td>
																<td>
																	<button class='btn btn-sm btn-dark' type='button' data-placement='top' onclick=popup01('$cV03','$cV04') data-toggle='tooltip'>".$fila['UNIDADES_RECIBIDAS']."</button>
																</td>
																<td>".$fila['ICG']."</td>
															</tr>
														";
													}
												}
											?>
										</tbody>
									</table>										
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- /page content -->
			</div>
		</div>
		<?php include '../index/fbody.php'; ?>
	</body>
</html>
<script>
	var mipopup;
	function popup01(d01, d02)
	{
		v01 = d01;
		v02 = d02;
		posicion_x=(screen.width/2)-(600/2);
		posicion_y=(screen.height/2)-(280/2)-50;
		mipopup = window.open("reporte_13_und.php?id="+v01+"&id2="+v02, "winund", "width=600, Height=280, menubar=0, toolbar=0,directories=0,scrollbars=no,resizable=no,left="+posicion_x+",top="+posicion_y+"");
		mipopup.focus()
	}
</script>