<?php
session_start();
if (!isset($_SESSION['nick'])){
 header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php" );
}
 include("emenux.php");
 require "funciones.php";
 //------INI-Coneccion Local
 require ("conecta.php");
 //-----INI-Coneccion Local
 //Recibe Fechas
 $fechai=editafechag($_POST['fechai']);
 $fechat=editafechag($_POST['fechat']);
 $sqlc="SELECT cod_tipo_d, numero,FECHA,  sum(neto) as neto, sum(iva) as iva, sum(total) as total, d1,estado
FROM m02005 where fecha >= '$fechai' and fecha <= '$fechat'
GROUP BY NUMERO,FECHA ;";
 $resc=mysql_query($sqlc,$con) or die(mysql_error());
 $cont=0;
 if (mysql_num_rows($resc)>0){
  while($fila=mysql_fetch_row($resc)){//while
   $cont++;
  }//while
 }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>

<TITLE>Detalle de Filtro Venta</TITLE>

<link rel="stylesheet" href="styles.css">
<SCRIPT language=JavaScript><!--
function popup(COD_TIPO_D,NUMERO,desc){ 
  var durl=new String();
  durl="detalven.php?COD_TIPO_D=" + COD_TIPO_D + "&NUMERO=" + NUMERO + "&desc=" + desc;
  open(durl,"detalle", "width=1000,height=500,left=0 resizable=YES ");
}
//--></SCRIPT>
<style type="text/css">
<!--
.Estilo1 {color: #FFFFFF}
-->
</style>
</HEAD>
<BODY>
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" align=center 
border=0>
  <TBODY>
  <TR>
    <TD vAlign=center align=middle height="100%">
      <TABLE height=400 cellSpacing=0 cellPadding=0 width=718 border=0>
        <TBODY>
        <TR>
          <TD width="718" height=22>
            <TABLE height=22 cellSpacing=0 cellPadding=0 width="100%" 
              border=0><TBODY>
              <TR>
                <TD vAlign=top align=left width=24><A 
                  href="index.php"><IMG 
                  height=22 src="images/xc_left.gif" width=24 
                  border=0></A></TD>
                <TD vAlign=top align=left width="100%"><IMG height=22 
                  src="images/xc_center.gif" width="100%" 
                border=0></TD>
              <TD vAlign=top align=right width=24><IMG height=22 
                  src="images/xc_right.gif" width=24 
              border=0></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=BottomTable vAlign=top 
          background=images/xc_stripes.gif height="100%">
            <TABLE class=IconsTable height=33 cellSpacing=0 cellPadding=0 
            width="100%" border=0>
              <TBODY>
              <TR>
                <TD height="32"><div align="right" class="larger">
                  <div align="right">Vemol</div>
                </div></TD>
                </TR></TBODY></TABLE>
            <TABLE cellSpacing=0 cellPadding=0 width="715" 
              border=0>
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD height=18 align=left vAlign=top class="LeftMenu">Resultado de Filtro de ventas: <span class="Emphasize"></span> <strong><?php echo $cont . "    fecha inicial: " . $_POST['fechai'] . "    fecha final: " . $_POST['fechat']  ?></strong></TD>
                <TD align=left vAlign=top class="LeftMenu">&nbsp;</TD>
                <TD width=20 height=18>&nbsp;</TD></TR>
              <TR>
                <TD width=23 height="100%">&nbsp;</TD>
                <TD height="100%" colspan="2" align=left vAlign=top class="contentcell"><form id="form1" name="form1" method="post" onSubmit="return validar(this)" action="resfilven.php">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="11%" class="m0l0oout Estilo1" scope="row"><div align="center" class="LeftMenu Estilo1">Tipo</div></td>
                        <td width="14%" class="m0l0oout" scope="row"><div align="center" class="Estilo1">
                            <div align="left" class="LeftMenu">Numero</div>
                        </div></td>
                        <td width="18%" class="m0l0oout Estilo1" scope="row"><div align="left" class="LeftMenu">Fecha</div></td>
                        <td width="20%" class="m0l0oout Estilo1" scope="row"><div align="left" class="LeftMenu">Neto</div></td>
                        <td width="21%" class="m0l0oout" scope="row"><div align="left" class="LeftMenu Estilo1">IVA</div></td>
                        <td width="16%" class="m0l0oout" scope="row"><div align="left" class="LeftMenu Estilo1">Total</div></td>
                        <td scope="row"><label>
                          <div align="center">&nbsp;                        </div>
                          </label></td>
                        </tr>
                      <tr>
                        <?php
					   //Definimos los colores a usar
					   $color0 = "#A4B4C1";
					   $color1 = "#D5E7FB";
					   $color2 = "#E8F2FC";
					   $color3 = "#E0FAC5";
					   $color = $color1;
					   $nneto=0;
					   $iiva=0;
					   $ttotal=0;
					   $resc=mysql_query($sqlc,$con);
					   if (mysql_num_rows($resc)>0){
					    while ($fila = mysql_fetch_row($resc)){
						$COD_TIPO_D=$fila[0];
						if ($COD_TIPO_D=='01'){
						 $tipol='Fact';
						}
						if ($COD_TIPO_D=='02'){
						 $tipol='Bole';
						}						
						$estado=$fila[7];
						$NUMERO=$fila[1];
						$FECHA=$fila[2];
						$FECHA=editafecha($FECHA);
						$NETO=$fila[3];						
						$IVA=$fila[4];						
						$TOTAL=$fila[5];
						$desc=$fila[6];
						if ($COD_TIPO_D=='03'){
						 $tipol='Guia';						 
						}
						if ($COD_TIPO_D=='04'){
						 $tipol='Guia interna';						 
						}												
						if ($estado=="02"){
						 $tipol=$tipol . " (a)";
						 $NETO=0;
						 $IVA=0;
						 $TOTAL=0;
						}
						$nneto=$nneto+$NETO;
						$iiva=$iiva+$IVA;
						$ttotal=$ttotal+$TOTAL;
						 // empezando una tabla html
						 echo "<tr style=\"background-color:$color\" onMouseOver=\"this.style.backgroundColor='$color3'\" onMouseOut=\"this.style.backgroundColor='$color'\">";
						 echo "<td><a href=\"javascript:popup('$COD_TIPO_D','$NUMERO','$desc')\"><acronym title=\"Ver detalle Codigo: ". $NUMERO . "\">$tipol</acronym></a></td>";
						 echo "<td><a href=\"javascript:popup('$COD_TIPO_D','$NUMERO','$desc')\"><acronym title=\"Ver detalle\">$NUMERO</acronym></a></td>";
						 echo "<td align='right'>$FECHA</td>";
						 echo "<td align='right'>" .number_format($NETO,0,".",",") ."</td>";
						 echo "<td align='right'>" .number_format($IVA,0,".",",") ."</td>";
						 echo "<td align='right'>" .number_format($TOTAL,0,".",",") ."</td>";
						 echo "</tr>";
						 if ($color == $color1){
						  $color = $color2;
						  }else{
						  $color = $color1;
						 }
						}//while
					   }//fin si 
					  ?>
                      </tr>
                      <tr>
                        <td scope="row">&nbsp;</td>
                        <td scope="row">&nbsp;</td>
                        <td scope="row">&nbsp;</td>
                        <td align="right" class="LeftMenu" scope="row"><strong><?php echo number_format($nneto,0,".",",") ?></strong></td>
                        <td align="right" class="LeftMenu" scope="row"><strong><?php echo number_format($iiva,0,".",",") ?></strong></td>
                        <td align="right" class="LeftMenu" scope="row"><strong><?php echo number_format($ttotal,0,".",",") ?></strong></td>
                      </tr>
                      </table>
                  </form>                  <p align="center"><span class="LeftMenu"><acronym><a href="M0202001.php">Volver a Buscar<br />
                  </a></acronym>
                      <label></label>
                  </span></p></TD>
                <TD width=20 height="100%">&nbsp;</TD></TR>
              <TR>
                <TD width=23 height=8>&nbsp;</TD>
                <TD height=8 colspan="2">&nbsp;</TD>
                <TD width=20 
      height=8>&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY>
<!-- /Footer -->
<script language="JavaScript" src="menu.js"></script>
<script language="JavaScript" src="menu_tpl.js"></script>
<script language="JavaScript">
	new menu (MENU_ITEMS, MENU_POS);
</script>
	  </TABLE>
</BODY>
<?php
	mysql_close($con);
?>
</HTML>