<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Estadisticas de Ventas</title>
<?
include("../conex.php");
 
$vende =$_GET["cp"];

?>



<style type="text/css">
<!--
.Estilo1 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;}
.Estilo2 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color:#FF0000}
-->
</style>
</head>
<body LINK="#000000" VLINK="#000000" ALINK="#000000">  <br>
<div align="center" class="titulos2">Ubicación Bodega </div>
<div align="center">

    <table width="85%" border="0">
      <tr bgcolor="#CCCCCC">
	  	
        
       
        
        <th width="29%" scope="col"><div align="center">Bodega</div></th>
       <th width="9%" scope="col"><div align="center">Saldo</div></th>
   
     
     
     
	<?		
	//**********  ver anterior *************
	$con=0;
	$sql_bod = "SELECT * FROM bodega ORDER BY descripcion ";
  	$res_bod = mysql_query($sql_bod,$enlace);	
	while (mysql_fetch_object ($res_bod))
 			{	
	$id_bodega= mysql_result($res_bod, $con, "Id");
    $bodega= mysql_result($res_bod, $con, "descripcion");
		$saldo=0;
		  
$sqlfs = "SELECT entrada_salida_traspaso, cantidad FROM movimiento  WHERE cod_producto=$vende AND tipo_dcto<>3  AND tipo_dcto<>5 AND bodega=$id_bodega";

  	$resfs = mysql_query($sqlfs,$enlace);	

	$cont=0;
	while (mysql_fetch_object ($resfs))
 			{				
				$entrada_salida= mysql_result($resfs, $cont, "entrada_salida_traspaso");
				$cantidad= mysql_result($resfs, $cont, "cantidad");
			
				if ($entrada_salida == "E") 
				{
					$saldo+=$cantidad;
				}
				else
				{
				    $saldo-=$cantidad;
				}
			$cont+=1;
			}
						

	//**************  saldo NV no facturadas ***********************

		  	$sqlfs = "SELECT entrada_salida_traspaso, cantidad FROM movimiento, salida  WHERE cod_producto=$vende AND (movimiento.tipo_dcto=3 OR movimiento.tipo_dcto=5) AND id_soe=salida.id AND documento_control is Null  AND movimiento.bodega=$id_bodega ";
		

		  	$resfs = mysql_query($sqlfs,$enlace);	

			$cont=0;
			while (mysql_fetch_object ($resfs))
 				{
				
				$entrada_salida= mysql_result($resfs, $cont, "entrada_salida_traspaso");
				$cantidad= mysql_result($resfs, $cont, "cantidad");
			
				if ($entrada_salida == "E") {
					$saldo+=$cantidad;
				}
				else
				{
				$saldo-=$cantidad;
				}

			$cont+=1;
			}
						
			?>

			
	
				 
	  <tr>
		        <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong>
		        
	          </strong></span><?=$bodega?></div></td>
             
				
                
                <td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong>
				  <?=$saldo?>
				</strong></span></div></td>
                
				
      </tr>		
    	
  <?
       $con+=1;
	   }
	  
	?>   

    
       
    
    
    
    
    	
    </table>
<form name="form1" method="post" action="">

	  <input type="button" name="imprimir" id="imprimir" value="Imprimir" onClick="fun_imprimir();">
	  <input name="txt_nv" id="txt_nv" type="text" style="visibility:hidden" size="1">
    </form>
  </div>
</body>
</html>

<script language="javascript" type="text/javascript">
function cerrar()
{
window.top.open('','_parent','');
window.top.close();
}
function fun_imprimir()
	{
	document.getElementById('imprimir').style.display = "none";
	window.print();
	document.getElementById('imprimir').style.display = "block";
	};

</script>