<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = 'index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
$id_autoriza=33;
?>
<?
/*Sesiones*/
include("../conex.php");
include("../autoriza.php");
if ($editar==0)  
{
?>
		<script>
		alert ("No Autorizado");
		parent.location.href = 'index.php';
		</script>
	<? 
	exit();
}

$cod_bodega=$_GET["cp"];
$sql_lf = "SELECT * FROM familia WHERE id = $cod_bodega";
$resultado = mysql_query($sql_lf,$enlace);
$cont=0;
while (mysql_fetch_object ($resultado))
	{
	$nombre_familia=mysql_result($resultado, $cont, "descripcion");
	$codigo_familia=mysql_result($resultado, $cont, "id");
	$cont=$cont+1;
	}
?>
<!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>Lista de productos</title>
<style type="text/css">
<!--
.Estilo7 {
	font-size: small;
	color: #000099;
}
.Estilo11 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small; color: #000099; }
.Estilo13 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	color: #000099;
	text-decoration: underline;
}
.Estilo14 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #000099;
}
-->
</style>
<link href="../hojadeestilosjc.css" rel="stylesheet" type="text/css">
</head>

<body>
<table border="0" width="100%">
	<tr>
		<td><div align="center" class="titulos2">
			<?=$nombre_familia?>
		</div></td>
	</tr>
	<tr>
		<td><div id="botones" style="display:block" align="center" >
         <input name="Imprimir" type="button" class="botones" value="Imprimir" onClick="imprimir_formulario();">
		</div></td>
	</tr>
</table>
<form id="form1" name="form1" method="post" action="">

<br>
<table width="90%" border="1" align="center" cellspacing="0">
  <tr bgcolor="#00CCFF" class="detalle_tablas_II_negrita" style="font-size:12px">
    <th width="14%" scope="col">C&oacute;digo</th>
    <th width="54%" scope="col">Producto</th>
	<th width="8%" scope="col">Pedido </th>
    <th width="8%" scope="col">Precio </th>
	<th width="8%" scope="col">Quillota </th>

    <th width="8%" scope="col">Saldo </th>
	
    </tr>
<?
$cont=0;
$sql_lp = "SELECT p.codigo AS codigo_empresa, p.descripcion AS descr, p.precio AS precio, p.saldo AS saldo FROM productos AS p WHERE p.cod_familia = $codigo_familia ORDER BY p.descripcion";
$resultado = mysql_query($sql_lp,$enlace);
while (mysql_fetch_object ($resultado))
	{
	$codigo=mysql_result($resultado, $cont, "codigo_empresa");
	
	//***************
		$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=$codigo AND tipo_dcto<>3  AND tipo_dcto<>5 AND bodega=$id_bodega";

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

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

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

		  	$sqlfs = "SELECT entrada_salida_traspaso, cantidad FROM movimiento, salida  WHERE cod_producto=$codigo 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);	

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

			$cont1+=1;
			}
			$bode[$con]=$saldo;
		
       $con+=1;
	   }
	  
	//***************
?>
	<tr bgcolor="#CBFEC2">
		<td class="Estilo14"><div align="left">
      		<strong><?=$codigo;?></strong>
    	</div></td>
		<td class="Estilo14"><div align="left">
            <strong><?=mysql_result($resultado, $cont, "descr");?></strong>
        </div></td>
		<td class="Estilo14"><div align="left">
            &nbsp;
        </div></td>
		<td class="Estilo14"><div align="right">
      		<strong><?=number_format(mysql_result($resultado, $cont, "precio"), 0, ',', '.');?></strong>
    	</div></td>
		<td class="Estilo14"><div align="right">
      		<strong><?=$bode[1];?></strong>
    	</div></td>
      
        <td class="Estilo14"><div align="right">
      		<strong><?=mysql_result($resultado, $cont, "saldo");?></strong>
    	</div></td>
		
	</tr>
	<?
	$cont=$cont+1;
	}
	?>
	</table>
</form>
</body>
</html>
<script language="Javascript">
<!--
function imprimir_formulario(){
document.getElementById('botones').style.display = "none";
window.print();
document.getElementById('botones').style.display = "block";
};
function enviar(aux){
	document.form1.action = aux;
	document.form1.submit();
} 

</script>

