<?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  numero,FECHA, rut, nombre,cpago,estado, neto, iva, total FROM adae01 where (fecha >= '$fechai' and fecha <= '$fechat') 
order by cpago ;";
 $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=mysql_num_rows($resc);
  //}//while
 }
 $enc="<tr>
                        <td width='19%' class='m0l0oout Estilo1' scope='row'><div align='center' class='LeftMenu Estilo1'>Documento</div></td>
                        <td width='19%' class='m0l0oout' scope='row'><div align='center' class='Estilo1'>
                            <div align='left' class='LeftMenu'>Banco</div>
                        </div></td>
                        <td width='17%' class='m0l0oout Estilo1' scope='row'><div align='left' class='LeftMenu'>Numero</div></td>
                        <td width='19%' class='m0l0oout Estilo1' scope='row'><div align='center' class='BoldText'>Fec.Vcto.
                          </div>
                          <div align='left' class='LeftMenu'></div></td>
                        <td width='25%' class='m0l0oout' scope='row'><div align='right' class='LeftMenu Estilo1'>Valor</div>                          <div align='left' class='LeftMenu Estilo1'></div></td>
                        <td width='1%' scope='row'><label>
                          <div align='center'>&nbsp;                        </div>
                          </label></td>
                        </tr>";
?>
<!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=620 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="633" 
              border=0>
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD height=18 align=left vAlign=top class="LeftMenu">Consulta de pedidos &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fecha inicial: <?php echo $_POST['fechai'] ?> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fecha final: <?php echo $_POST['fechat'] ?></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">
                      
						<?PHP 
						$veces=0;
						 while ($fila=mysql_fetch_row($resc)){ 						  
						  $COD_TIPO_D=$fila[0];                        
						  if ($cp != $fila[8]){
						   $veces++;
						   if ($veces>1){
						    echo "<tr>";
                            echo "<td align='center'></td>";
                            echo "<td align='center'></td>";
                            echo "<td align='center'></td>";
                            echo "<td align='right' ><b>total<b></td>";
                            echo "<td align='right'><b>". number_format($sumatipo,0,".",",") . "<b></td>";
                            echo "</tr>";
							$sumatipo=0;
						   }//fin veces>0 
						   echo $enc;
						   $cpa=$fila[8];
						   $sqlcp="select glosa from m01002 where codconpa='$cpa';";
						   $rescp=mysql_query($sqlcp,$con) or die(mysql_error());
						   while ($filacp=mysql_fetch_row($rescp)){
						    $glcp=$filacp[0];
						   }//wend cp
						   echo "<tr>";
                           echo "<td align='center'><b>$glcp<b></td>";
                           echo "<td align='center'></td>";
                           echo "<td align='center'></td>";
                           echo "<td align='right' ></td>";
                           echo "<td align='right'></td>";
                           echo "</tr>";
						  
						  }				  
						  
						  if ($COD_TIPO_D=='01'){
						   $tipol='Fact';
						   }
						  if ($COD_TIPO_D=='02'){
						   $tipol='Bole';
						   }
						   
						  $tot=$fila[5];
						  $sumatot=$sumatot + $tot;
						  $sumatipo=$sumatipo+$tot;
						  $tote=number_format($tot,0,".",",");
						  $cp=$fila[8];	
						  $bco=$fila[9];
						  $num=$tipol . " " . substr($fila[1],5,5);	
						  $cheque=$fila[10];				  
						  $fechav=$fila[11];
						  echo "<tr>";
                          echo "<td align='center'>$num</td>";
                          echo "<td align='center'>$bco</td>";
                          echo "<td align='center'>$cheque</td>";
                          echo "<td align='right' >$fechav</td>";
                          echo "<td align='right'>$tote</td>";
                          echo "</tr>";
						  }//wend
						  echo "<tr>";
                          echo "<td align='center'></td>";
                          echo "<td align='center'></td>";
                          echo "<td align='center'></td>";
                          echo "<td align='right' ><b>total<b></td>";
                          echo "<td align='right'><b>". number_format($sumatipo,0,".",",") . "<b></td>";
                          echo "</tr>";
						  $sumatipo=0;
						?>
                      </table>
                  </form>                  <p align="center"><span class="LeftMenu"><acronym><a href="M0202002.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>