<?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['id5']; ?></h2>
								<a href="reporte_12_pdf.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-danger' type='button' data-placement='top' data-toggle='tooltip' data-original-title='Detalle'><i class='fa fa-file-pdf-o'></i> Exportar PDF</button>
								</a>
								<a href="reporte_12_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>FECHA</th>
												<th>CODIGO DE BARRAS</th>
												<th>ARTICULO</th>
												<th>DESCRIPCION</th>
												<th>TALLA</th>
												<th>COLOR</th>
												<th>UNIDADES</th>
												<th>UBICAICON</th>
												<th>CAJA MASTER</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['id'];
													$cV02 = $_GET['id2'];
													$cV03 = $_GET['id3'];
													$cV04 = $_GET['id4'];
													$cV05 = $_GET['id5'];
													// CONSULTA SQL
													$sql = "DECLARE @SERIE NVARCHAR(10) = '".$cV01."' \n"
														  ."DECLARE @NUMERO INT = ".$cV02." \n"
														  ."DECLARE @SUPEDIDO NVARCHAR(30) = '".$cV03."' \n"
														  ."DECLARE @BODEGA NVARCHAR(5) = '".$cV04."' \n"
														  ."DECLARE @CARRITO NVARCHAR(10) = '".$cV05."' \n"
														  ."SELECT C.NUMSERIE, C.NUMPEDIDO, C.SUPEDIDO, D.FECHA, D.CODIGOARTICULO, A.DESCRIPCION, D.TALLA, D.COLOR, D.CANTIDADDEVUELTA, D.UBICACION, D.CAJAMASTER, D.ICG AS CARRITO, \n"
														  ."@BODEGA CODALMACEN, N.CODBARRAS, A.REFPROVEEDOR, D.IDDEVOLUCION  \n"
														  ."FROM JOIN_DEVOLUCIONES AS D   \n"
														  ."LEFT JOIN PEDVENTACAB AS C  ON  (C.TIPODOC = CASE WHEN   D.MODULO = 220 THEN 22 ELSE D.MODULO END)  AND (C.SUPEDIDO = D.DOCUMENTO COLLATE Modern_Spanish_CI_AS)   \n"
														  ."LEFT JOIN ARTICULOS AS A ON (D.CODIGOARTICULO = A.CODARTICULO)   \n"
														  ."LEFT JOIN ARTICULOSLIN AS N ON (D.CODIGOARTICULO = N.CODARTICULO) AND (D.TALLA = N.TALLA COLLATE Modern_Spanish_CI_AS) AND (D.COLOR = N.COLOR COLLATE Modern_Spanish_CI_AS )  \n"
														  ."WHERE (MODULO in  (22,220)) AND (CONVERT(VARCHAR, C.SUPEDIDO) = CONVERT(VARCHAR, @SUPEDIDO)) AND (D.ICG = @CARRITO)  \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'];
														$cV02 = $fila['CANTIDADDEVUELTA'];
														echo "
															<tr>
																<td>".$fila['FECHA']->format('Y-m-d h:m:s')."</td>
																<td>".$fila['CODBARRAS']."</td>
																<td>".$fila['CODIGOARTICULO']."</td>
																<td>".$fila['DESCRIPCION']."</td>
																<td>".$fila['TALLA']."</td>
																<td>".$fila['COLOR']."</td>
																<td>
																	<button class='btn btn-sm btn-dark' type='button' data-placement='top' onclick=popup99('$cV01','$cV02') data-toggle='tooltip' data-original-title='Cambio de unidades'>".$fila['CANTIDADDEVUELTA']."</button>
																</td>
																<td>".$fila['UBICACION']."</td>
																<td>".$fila['CAJAMASTER']."</td>
																<td>".$fila['CARRITO']."</td>
															</tr>
														";
													}
												}
											?>
										</tbody>
									</table>										
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- /page content -->
			</div>
		</div>
		<?php include '../index/fbody.php'; ?>
	</body>
</html>
<script>
	var mipopup;
	function popup99(d01, d02)
	{
		v01 = d01;
		v02 = d02;
		posicion_x=(screen.width/2)-(600/2);
		posicion_y=(screen.height/2)-(400/2)-50;
		mipopup = window.open("reporte_12_und.php?id="+v01+"&id2="+v02, "unidades", "width=600, Height=400, menubar=0, toolbar=0,directories=0,scrollbars=no,resizable=no,left="+posicion_x+",top="+posicion_y+"");
		mipopup.focus()
	}
</script>
