<?
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");
$txtfecha=$_POST["txtfecha"];
$txtfecha1=$_POST["txtfecha1"];

$dia = substr ($txtfecha, 0, 2);
$dia1 = substr ($txtfecha1, 0, 2);
$mes = substr ($txtfecha, 3, 2);
$mes1 = substr ($txtfecha1, 3, 2);
$mes2=$mes;

$aņo = substr ($txtfecha, 6, 4);
$aņo1 = substr ($txtfecha1, 6, 4);

$ini = $aņo.'/'.$mes.'/'.$dia;
$fin = $aņo1.'/'.$mes1.'/'.$dia1;

 
$vende =$_POST["lstvendedor"];

?>



<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">ESTADISTICA DE VENTAS VENDEDORES DESDE EL 
<?=$txtfecha?> HASTA EL <?=$txtfecha1?></div>
<div align="center">

    <table width="80%" border="0">
      <tr bgcolor="#CCCCCC">
	  	
        <th scope="col"><div align="center">Familia/Vendedor</div></th>
       <?
	   $sql_bf = "SELECT * FROM vendedor";
	   $res_bf = mysql_query($sql_bf,$enlace);
	   $cont_bf=0;
		while(mysql_fetch_object($res_bf))
			{
			?>
			<th scope="col"><div align="center">&nbsp;<?=mysql_result($res_bf, $cont_bf, "nombres")?></div></th>
			<?		
		$cont_bf+=1;
		}
		$total_neto=0;
			
	$sqlfs = "SELECT  fecha_emision, sum(neto), vendedor FROM salida 
	WHERE (fecha_emision>='$ini' and fecha_emision<='$fin') and (salida.tipo_dcto='1' or salida.tipo_dcto='2' or salida.tipo_dcto='6' or salida.tipo_dcto='7')  GROUP BY salida.vendedor ORDER BY salida.vendedor";

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

			$cont=0;
			while (mysql_fetch_object ($resfs))
 				{
									
				$rut = mysql_result($resfs, $cont, "vendedor");
				
				if ($rut!=''){
				$sqlc = "SELECT * FROM vendedor WHERE id='$rut'";
		  		$resc = mysql_query($sqlc,$enlace);
				
				$nombre = mysql_result($resc, 0, "nombres");
				}
				
				else 
				{
				}
			
				$neto= mysql_result($resfs, $cont, "sum(neto)");
				$total_neto+=$neto;
				
				$neto=number_format($neto,0,',','.');
			?>	
				 
			<tr>

				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong>
				  <?=$nombre?>
				</strong></span></div></td>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px" align="right"><div align="right"><span class="Estilo1"><strong>
				  <?=$neto?>
				</strong></span></div></td>
				
	        </tr>	
			<?
			$cont+=1;
			}
			$total_neto=number_format($total_neto,0,',','.');
			
			?>
			<tr>

				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="left"><span class="Estilo1"><strong>
	            
				</strong></span><strong>Total Neto: </strong></div></td>
				<td style="border-color:#CCCCCC; border:solid; border-width:2px; border-right-width:1px"><div align="right"><span class="Estilo1"><strong>
	            
				</strong></span><span class="Estilo1"><strong>
				<?=$total_neto?>
				</strong></span></div></td>
				
	        </tr>
    </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>