<?php include "../index/conexion.inc" ?>
<?php include "../index/validacion.php" ?>
<!doctype html>
<html lang="es">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<!-- Meta, title, CSS, favicons, etc. -->
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="icon" href="../images/me.ico" type="image/ico" />
	<title>Join Manager</title>
	<!-- Bootstrap -->
	<link href="../config/vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
	<!-- Font Awesome -->
	<link href="../config/vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
	<!-- NProgress -->
	<link href="../config/vendors/nprogress/nprogress.css" rel="stylesheet">
	<!-- iCheck -->
	<link href="../config/vendors/iCheck/skins/flat/green.css" rel="stylesheet">	
	<!-- Datatables -->
	<link href="../config/vendors/datatables.net-bs/css/dataTables.bootstrap.min.css" rel="stylesheet">
	<link href="../config/vendors/datatables.net-buttons-bs/css/buttons.bootstrap.min.css" rel="stylesheet">
	<link href="../config/vendors/datatables.net-fixedheader-bs/css/fixedHeader.bootstrap.min.css" rel="stylesheet">
	<link href="../config/vendors/datatables.net-responsive-bs/css/responsive.bootstrap.min.css" rel="stylesheet">
	<link href="../config/vendors/datatables.net-scroller-bs/css/scroller.bootstrap.min.css" rel="stylesheet">
	<!-- Custom Theme Style -->
	<link href="../config/build/css/custom.min.css" rel="stylesheet">
	</head>
	<div class="top_nav">
		<div class="container body">
			<div class="main_container">
				<!-- page content -->
				<div class="right_col" role="main">
					<div class="col-md-12 col-sm-12 col-xs-12">
						<div class="x_panel">
							<div class="x_title">
								<h2>Toma Fisica | Documento <?php echo $_GET['id'];?></h2>
								<?php 
									$cV01 = $_GET['id'];
									echo "
									<button type='botton' class='btn btn-success' onclick=popup02('$cV01');>
										<span class='glyphicon glyphicon-export' aria-hidden='true'></span> Exportar a excel
									</button>
									";
								?>
								<div class="clearfix"></div>
							</div>
							<div class="x_content">
							<table id="datatable" class="table table-striped table-bordered">
								<thead>
									<tr>
										<th>LINEA</th>
										<th>DOCUMENTO</th>
										<th>GONDOLA</th>
										<th>COD.ARTICULO</th>
										<th>PROVEEDOR</th>
										<th>TALLA</th>
										<th>COLOR</th>
										<th>COD.BARRAS</th>
										<th>BODEGA</th>
										<th>ALMACEN</th>
										<th>UNIDADES</th>
										<th>FECHA</th>
										<th>COD.VENDEDOR</th>
										<th>VENDEDOR</th>
										<th>CAJA MASTER</th>
										<th>UBICACION</th>
										<th>ZONA</th>
										<th>PASILLO</th>
										<th>LADO</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
										{
											$cV00 = $_GET['id'];
											// CONSULTA SQL
											$sql = "DECLARE @GONDOLA NVARCHAR(30) \n"
."SET @GONDOLA = ( SELECT GONDOLA FROM JOIN_INVENTARIO_FISICO WHERE DOCUMENTO  = ".$cV00." GROUP By GONDOLA)\n"
  ."SELECT A.IDLINEA, AR.CODARTICULO, AR.REFPROVEEDOR, ISNULL(AL1.TALLA, ISNULL(AL2.TALLA, AL3.TALLA)) AS TALLA,\n" 
	."											  ISNULL(AL1.COLOR, ISNULL(AL2.COLOR, AL3.COLOR)) AS COLOR, A.CODBARRAS, A.BODEGA, B.NOMBREALMACEN,\n"
		."										  A.UNIDADES,ISNULL( IF2.UNIDADES,0) UNIDADES2,\n"
			."									  ISNULL( IF3.UNIDADES,0) UNIDADES3,\n"
				."								  A.FECHAALTA, \n"
					."							  ISNULL(V.CODVENDEDOR, 0) AS CODVENDEDOR, V.NOMVENDEDOR AS VENDEDOR, A.CAJAMASTER, A.UBICACION, UB.IDZONA, UB.PASILLO, UB.LADO, \n"
						."						  P.CODPROVEEDOR, A.GONDOLA, A.DOCUMENTO, A.IDESTADO, 1 AS ORD \n"
							."					  FROM JOIN_INVENTARIO_FISICO AS A \n"
								."				  LEFT JOIN ALMACEN AS B ON (A.BODEGA = B.CODALMACEN COLLATE Latin1_General_CS_AI) \n"
									."			  LEFT JOIN ARTICULOSLIN AS AL1 ON (A.CODBARRAS = AL1.CODBARRAS COLLATE Latin1_General_CS_AI) \n"
										."		  LEFT JOIN ARTICULOSLIN AS AL2 ON (A.CODBARRAS = AL2.CODBARRAS2 COLLATE Latin1_General_CS_AI) \n"
											."	  LEFT JOIN ARTICULOSLIN AS AL3 ON (A.CODBARRAS = AL3.CODBARRAS3 COLLATE Latin1_General_CS_AI) \n"
												."  LEFT JOIN ARTICULOS AS AR ON (AR.CODARTICULO = AL1.CODARTICULO OR AR.CODARTICULO = AL2.CODARTICULO OR AR.CODARTICULO = AL3.CODARTICULO) \n"
												 ." LEFT JOIN JOIN_UBICACIONES AS UB ON (A.UBICACION = IDUBICACION) \n"
												  ."LEFT JOIN VENDEDORES AS V ON (A.USUARIO = V.CODVENDEDOR) \n"
												  ."LEFT JOIN REFERENCIASPROV AS P ON (AR.REFPROVEEDOR = P.REFPROVEEDOR) \n"
												 ." LEFT JOIN join_inventario_fisico_rev IF2 ON A.CODBARRAS = IF2.CODBARRAS AND A.GONDOLA = IF2.GONDOLA\n"
										."			AND A.CAJAMASTER = IF2.CAJAMASTER AND IF2.REV=1 \n"
										."			LEFT JOIN join_inventario_fisico_rev IF3 ON A.CODBARRAS = IF3.CODBARRAS AND A.GONDOLA = IF3.GONDOLA \n"
											."		AND A.CAJAMASTER = IF3.CAJAMASTER AND IF3.REV=2 \n"
											."		WHERE (A.DOCUMENTO = = ".$cV00.")   \n"
											 ."   UNION ALL\n"
 ."SELECT 0 IDLINEA, CODARTICULO, REFPROVEEDOR,TALLA,COLOR, CODBARRAS, BODEGA,NOMBREALMACEN,UNIDADES,\n"
 ."SUM(UNIDADES2)UNIDADES2, SUM(UNIDADES3)UNIDADES3, \n"
." GETDATE() FECHAALTA, CODVENDEDOR, VENDEDOR, CAJAMASTER, UBICACION,IDZONA, PASILLO,LADO, CODPROVEEDOR,\n"
." GONDOLA, DOCUMENTO, IDESTADO, ORD\n"
." FROM (SELECT A.IDLINEA, AR.CODARTICULO, AR.REFPROVEEDOR, ISNULL(AL1.TALLA, ISNULL(AL2.TALLA, AL3.TALLA)) AS TALLA, \n"
	."											  ISNULL(AL1.COLOR, ISNULL(AL2.COLOR, AL3.COLOR)) AS COLOR, A.CODBARRAS, A.BODEGA, B.NOMBREALMACEN, 0 UNIDADES, A.FECHAALTA, \n"
		."										  ISNULL(V.CODVENDEDOR, 0) AS CODVENDEDOR, V.NOMVENDEDOR AS VENDEDOR, A.CAJAMASTER, A.UBICACION, UB.IDZONA, UB.PASILLO, UB.LADO, \n"
			."									  P.CODPROVEEDOR, A.GONDOLA, A.DOCUMENTO, NULL IDESTADO, 1 AS ORD ,  A.UNIDADES UNIDADES2, 0 UNIDADES3 \n"
				."								   FROM JOIN_INVENTARIO_FISICO_REV AS A  \n"
					."							  LEFT JOIN ALMACEN AS B ON (A.BODEGA = B.CODALMACEN COLLATE Latin1_General_CS_AI) \n"
						."						  LEFT JOIN ARTICULOSLIN AS AL1 ON (A.CODBARRAS = AL1.CODBARRAS COLLATE Latin1_General_CS_AI) \n"
							."					  LEFT JOIN ARTICULOSLIN AS AL2 ON (A.CODBARRAS = AL2.CODBARRAS2 COLLATE Latin1_General_CS_AI) \n"
								."				  LEFT JOIN ARTICULOSLIN AS AL3 ON (A.CODBARRAS = AL3.CODBARRAS3 COLLATE Latin1_General_CS_AI) \n"
									."			  LEFT JOIN ARTICULOS AS AR ON (AR.CODARTICULO = AL1.CODARTICULO OR AR.CODARTICULO = AL2.CODARTICULO OR AR.CODARTICULO = AL3.CODARTICULO) \n"
										."		  LEFT JOIN JOIN_UBICACIONES AS UB ON (A.UBICACION = IDUBICACION)  \n"
											."	  LEFT JOIN VENDEDORES AS V ON (A.USUARIO = V.CODVENDEDOR)  \n"
							."					  LEFT JOIN REFERENCIASPROV AS P ON (AR.REFPROVEEDOR = P.REFPROVEEDOR) \n"
								."				  LEFT JOIN join_inventario_fisico IF2 ON A.CODBARRAS = IF2.CODBARRAS AND A.GONDOLA = IF2.GONDOLA\n"
									."				AND A.CAJAMASTER = IF2.CAJAMASTER AND A.REV=1 \n"
										."			WHERE (A.GONDOLA = @GONDOLA )  \n"
											."		AND IF2.UBICACION IS NULL \n"
									."				AND A.REV=1 \n"
										."		 	UNION ALL \n"
											."		SELECT A.IDLINEA, AR.CODARTICULO, AR.REFPROVEEDOR, ISNULL(AL1.TALLA, ISNULL(AL2.TALLA, AL3.TALLA)) AS TALLA, \n"
										."		  ISNULL(AL1.COLOR, ISNULL(AL2.COLOR, AL3.COLOR)) AS COLOR, A.CODBARRAS, A.BODEGA, B.NOMBREALMACEN, 0 UNIDADES, A.FECHAALTA, \n"
										."		  ISNULL(V.CODVENDEDOR, 0) AS CODVENDEDOR, V.NOMVENDEDOR AS VENDEDOR, A.CAJAMASTER, A.UBICACION, UB.IDZONA, UB.PASILLO, UB.LADO, \n" 
										."		  P.CODPROVEEDOR, A.GONDOLA, A.DOCUMENTO, NULL IDESTADO, 1 AS ORD , 0 UNIDADES2,  A.UNIDADES UNIDADES3 \n"
											."	  FROM JOIN_INVENTARIO_FISICO_REV AS A \n"
											."	  LEFT JOIN ALMACEN AS B ON (A.BODEGA = B.CODALMACEN COLLATE Latin1_General_CS_AI) \n"
							."					  LEFT JOIN ARTICULOSLIN AS AL1 ON (A.CODBARRAS = AL1.CODBARRAS COLLATE Latin1_General_CS_AI)  \n"
								."				  LEFT JOIN ARTICULOSLIN AS AL2 ON (A.CODBARRAS = AL2.CODBARRAS2 COLLATE Latin1_General_CS_AI) \n"
									."			  LEFT JOIN ARTICULOSLIN AS AL3 ON (A.CODBARRAS = AL3.CODBARRAS3 COLLATE Latin1_General_CS_AI) \n"
										."		  LEFT JOIN ARTICULOS AS AR ON (AR.CODARTICULO = AL1.CODARTICULO OR AR.CODARTICULO = AL2.CODARTICULO OR AR.CODARTICULO = AL3.CODARTICULO) \n"
											."	  LEFT JOIN JOIN_UBICACIONES AS UB ON (A.UBICACION = IDUBICACION)  \n"
					."							  LEFT JOIN VENDEDORES AS V ON (A.USUARIO = V.CODVENDEDOR) \n"
						."						  LEFT JOIN REFERENCIASPROV AS P ON (AR.REFPROVEEDOR = P.REFPROVEEDOR) \n"
							."					  LEFT JOIN join_inventario_fisico IF2 ON A.CODBARRAS = IF2.CODBARRAS AND A.GONDOLA = IF2.GONDOLA\n"
								."					AND A.CAJAMASTER = IF2.CAJAMASTER AND A.REV=2\n"
									."				WHERE (A.GONDOLA = @GONDOLA )  \n"
										."			AND IF2.UBICACION IS NULL\n"
											."		AND  A.REV=2 \n"
											."	  ) AS AA \n"
											."		GROUP BY CODARTICULO, REFPROVEEDOR,TALLA,COLOR, CODBARRAS, BODEGA,NOMBREALMACEN,UNIDADES,  CODVENDEDOR, VENDEDOR, CAJAMASTER, UBICACION,IDZONA, PASILLO,LADO, CODPROVEEDOR, \n"
												."	GONDOLA, DOCUMENTO, IDESTADO, ORD"; 
											$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['IDLINEA'];
												$cV02 = $fila['UNIDADES'];
												$cV03 = $_GET['id'];
												$cV04 = $fila['CODBARRAS'];
												$cV05 = $fila['UBICACION'];
												$cV06 = $fila['DOCUMENTO'];
												echo "
													<tr>
														<td>".$fila['IDLINEA']."</td>
														<td>".$fila['DOCUMENTO']."</td>
														<td>".$fila['GONDOLA']."</td>
														<td>".$fila['CODARTICULO']."</td>
														<td>".$fila['REFPROVEEDOR']."</td>
														<td>".$fila['TALLA']."</td>
														<td>".$fila['COLOR']."</td>";
														if ($fila['IDESTADO'] == 0)
														{
															echo "
															<td>
																<button class='btn btn-sm btn-dark' type='button' data-placement='top' onclick=popup98('$cV01','$cV04','$cV03')>".$fila['CODBARRAS']."</button>
															</td> ";
														}
														else
														{
															echo "<td>".$fila['CODBARRAS']."</td>";
														}
														echo "
														<td>".$fila['BODEGA']."</td>
														<td>".$fila['NOMBREALMACEN']."</td>";
														if ($fila['IDESTADO'] == 0)
														{
															echo "
															<td>
																<button class='btn btn-sm btn-dark' type='button' data-placement='top' onclick=popup99('$cV01','$cV02','$cV03')>".$fila['UNIDADES']."</button>
															</td>";
														}
														else
														{
															echo "<td>".$fila['UNIDADES']."</td>";
														}
														echo "
														<td>".$fila['FECHAALTA']->format('Y-m-d h:m:s')."</td>
														<td>".$fila['CODVENDEDOR']."</td>
														<td>".$fila['VENDEDOR']."</td>
														<td>".$fila['CAJAMASTER']."</td>";
														if ($fila['IDESTADO'] == 0)
														{
															echo "
															<td>
																<button class='btn btn-sm btn-dark' type='button' data-placement='top' onclick=popup97('$cV06','$cV05','$cV03')>".$fila['UBICACION']."</button>
															</td>";
														}
														else
														{
															echo "<td>".$fila['UBICACION']."</td>";
														}
														echo "
														<td>".$fila['IDZONA']."</td>
														<td>".$fila['PASILLO']."</td>
														<td>".$fila['LADO']."</td>
													</tr>
												";
											}
										}
									?>
								</tbody>
							</table>
							</div>
						</div>
					</div>
				</div>
				<!-- /page content -->
			</div>
		</div>
	</div>
    <!-- jQuery -->
    <script src="../config/vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="../config/vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="../config/vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="../config/vendors/nprogress/nprogress.js"></script>
    <!-- iCheck -->
    <script src="../config/vendors/iCheck/icheck.min.js"></script>
    <!-- Datatables -->
    <script src="../config/vendors/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="../config/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
    <script src="../config/vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
    <script src="../config/vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
    <script src="../config/vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
    <script src="../config/vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
    <script src="../config/vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
    <script src="../config/vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
    <script src="../config/vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
    <script src="../config/vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
    <script src="../config/vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
    <script src="../config/vendors/datatables.net-scroller/js/dataTables.scroller.min.js"></script>
    <script src="../config/vendors/jszip/dist/jszip.min.js"></script>
    <script src="../config/vendors/pdfmake/build/pdfmake.min.js"></script>
    <script src="../config/vendors/pdfmake/build/vfs_fonts.js"></script>
    <!-- Custom Theme Scripts -->
    <script src="../config/build/js/custom.min.js"></script>
	</body>
</html>
<script>
	var mipopup;
	function popup02(d01)
	{
		v01 = d01;
		posicion_x=(screen.width/2)-(1000/2);
		posicion_y=(screen.height/2)-(600/2)-50;
		mipopup = window.open("reporte_06_xls.php?id="+v01, "neo", "width=1000, Height=600, menubar=0, toolbar=0,directories=0,scrollbars=no,resizable=no,left="+posicion_x+",top="+posicion_y+"");
		mipopup.focus()
	}
</script>
<script>
	var mipopup;
	function popup98(d01, d02, d03)
	{
		v01 = d01;
		v02 = d02;
		v03 = d03;
		posicion_x=(screen.width/2)-(400/2);
		posicion_y=(screen.height/2)-(200/2)-50;
		mipopup = window.open("reporte_06_bar.php?id="+v01+"&id2="+v02+"&id3="+v03, "neo98", "width=400, Height=200, menubar=0, toolbar=0,directories=0,scrollbars=no,resizable=no,left="+posicion_x+",top="+posicion_y+"");
		mipopup.focus()
	}
</script>
<script>
	var mipopup;
	function popup99(d01, d02, d03)
	{
		v01 = d01;
		v02 = d02;
		v03 = d03;
		posicion_x=(screen.width/2)-(400/2);
		posicion_y=(screen.height/2)-(200/2)-50;
		mipopup = window.open("reporte_06_und.php?id="+v01+"&id2="+v02+"&id3="+v03, "neo99", "width=400, Height=200, menubar=0, toolbar=0,directories=0,scrollbars=no,resizable=no,left="+posicion_x+",top="+posicion_y+"");
		mipopup.focus()
	}
</script>
<script>
	var mipopup;
	function popup97(d01, d02, d03)
	{
		v01 = d01;
		v02 = d02;
		v03 = d03;
		posicion_x=(screen.width/2)-(400/2);
		posicion_y=(screen.height/2)-(200/2)-50;
		mipopup = window.open("reporte_06_ubi.php?id="+v01+"&id2="+v02+"&id3="+v03, "neo97", "width=400, Height=200, menubar=0, toolbar=0,directories=0,scrollbars=no,resizable=no,left="+posicion_x+",top="+posicion_y+"");
		mipopup.focus()
	}
</script>