<?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 adae01.numero,adae01.FECHA as fecha, adae01.rut,adae01.nombre,m01002.glosa,adae01.neto,adae01.iva,adae01.total,adae01.estado,adae01.d1,adae01.d2,adae01.d3 
FROM adae01 left join m01002 on adae01.cpago = m01002.codconpa where adae01.FECHA >= '$fechai' and adae01.FECHA <= '$fechat'
ORDER BY adae01.numero;";

 $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(NUMERO,tabla,d1,d2,d3){ 
  var durl=new String();
  durl="detalcom.php?NUMERO=" + NUMERO  + "&tabla=" + tabla + "&d1=" + d1+ "&d2=" + d2 + "&d3=" + d3;
  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=828 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="813" 
              border=0>
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD height=18 align=left vAlign=top class="LeftMenu"><p>Resultado de Filtro de Pedidos de Proveedor: <span class="Emphasize"></span> <strong><?php echo $cont . "    fecha inicial: " . $_POST['fechai'] . "    fecha final: " . $_POST['fechat']  ?></strong></p></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="1" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="7%" class="m0l0oout Estilo1" scope="row"><div align="center" class="LeftMenu Estilo1">Número</div></td>
                        <td width="9%" class="m0l0oout" scope="row"><div align="center" class="Estilo1">
                            <div align="left" class="LeftMenu">Fecha</div>
                        </div></td>
                        <td width="12%" class="m0l0oout Estilo1" scope="row"><div align="left" class="LeftMenu">Rut</div></td>
                        <td width="26%" class="m0l0oout Estilo1" scope="row"><div align="left" class="LeftMenu">Nombre</div></td>
                        <td width="9%" class="m0l0oout" scope="row"><div align="left" class="LeftMenu Estilo1">Cond.Pago</div></td>
                        <td width="9%" class="m0l0oout" scope="row"><div align="left" class="LeftMenu Estilo1">Neto</div></td>
                        <td width="8%" class="m0l0oout" scope="row"><div align="left" class="LeftMenu Estilo1">Iva</div></td>
						<td width="8%" class="m0l0oout" scope="row"><div align="left" class="LeftMenu Estilo1">Total</div></td>
						<td width="11%" class="m0l0oout" scope="row"><div align="left" class="LeftMenu Estilo1">Estado</div></td>
                        <td width="1%" 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)){
						
						$NUMERO=$fila[0];
						$FECHA=$fila[1];
						$RUT=editarut($fila[2]);
						$NOMBRE=ucfirst(strtolower($fila[3]));
						$FECHA=editafecha($FECHA);
						$CPAGO=strtolower($fila[4]);
						$NETO=$fila[5];						
						$IVA=$fila[6];						
						$TOTAL=$fila[7];
						$ESTADO=$fila[8];
						$D1=$fila[9];
						$D2=$fila[10];
						$D3=$fila[11];
						if ($ESTADO==0){
						 $ESTADOGL="Pendiente";
						 }else{
						   $ESTADOGL="Actualizado";
						 } 
						 // 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('$NUMERO','adai01','$D1','$D2','$D3')\"><acronym title=\"Ver detalle Pedido: ". $NUMERO . "\">$NUMERO</acronym></a></td>";
						 echo "<td><a href=\"javascript:popup('$NUMERO','adai01','$D1','$D2','$D3')\"><acronym title=\"Ver detalle\">$FECHA</acronym></a></td>";
						 echo "<td align='right'>$RUT</td>";
						 echo "<td align='Left'>$NOMBRE</td>";
						 echo "<td align='Left'>$CPAGO</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 "<td align='center'>$ESTADOGL</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 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="M0102002.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>