<?php
 session_start();
 require "funciones.php";
 include "emenux.php";
 //------INI-Coneccion Local
 require ("conecta.php");
 //------INI-Coneccion Local
 //Recibe descripcion
 $TIPOD=$_GET['COD_TIPO_D'];
 $NUMEROV=$_GET['NUMERO'];
 $desc=$_GET['desc'];
 $llaverv=$TIPOD . $NUMEROV;
 $sqlb="select * from m02007 where llave like '$llaverv%';";
 $resb=mysql_query($sqlb,$con);
 // contador de resultados en "0";
 $cant=0;
 if (mysql_num_rows($resb)>0){
   while ($filab = mysql_fetch_row($resb)){
    $cant++;
   }//while
  }//fin si
?>
<!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>Resultado de busqueda</TITLE>

<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
.Estilo1 {
	color: #FFFFFF;
	font-weight: bold;
}
-->
</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=804 border=0>
        <TBODY>
        <TR>
          <TD width="718" height=22>
            <TABLE width="872" height=22 
              border=0 cellPadding=0 cellSpacing=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="690"><img height="22" 
                  src="images/xc_center.gif" width="111%" 
                border="0" /></TD>
              <TD vAlign=top align=right width=98>&nbsp;</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 width="873" 
              border=0 cellPadding=0 cellSpacing=0 bordercolor="#595959">
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD height=18 align=left vAlign=top>&nbsp;</TD>
                <TD width=20 height=18>&nbsp;</TD></TR>
              <TR>
                <TD width=23 height="100%">&nbsp;</TD>
                <TD height="100%" align=left vAlign=top><form id="form1" name="form1" method="post" action="">
                  <table width="103%" border="1" cellpadding="0" cellspacing="0">
                      <tr>
                        <td colspan="11" scope="col"><div align="center">
                          <p><strong><span class="MainMenuHead">Resultado de Busqueda:<?php echo $cant ?></strong></p>
                          </div></td>
                        </tr>

                      <tr>
					    <td width="6%" class="m0l0oout Estilo1" scope="row"><div align="center">Tipo</div></td>
                        <td width="6%" class="m0l0oout Estilo1" scope="row"><div align="center">Numero</div></td>
                        <td width="7%" class="m0l0oout" scope="row"><div align="center" class="Estilo1">
                          <div align="left">Cantidad</div>
                        </div></td>
                        <td width="10%" class="m0l0oout Estilo1" scope="row"><div align="left">Cod_Interno</div></td>
                        <td width="39%" class="m0l0oout Estilo1" scope="row"><div align="left">Glosa</div></td>
                        <td width="7%" class="m0l0oout Estilo1" scope="row"><div align="center">Precio Venta </div></td>
                        <td width="6%" class="m0l0oout Estilo1" scope="row">Precio c/desc. </td>
                        <td width="5%" class="m0l0oout Estilo1" scope="row"><div align="center">Precio Neto </div></td>
                        <td width="3%" class="m0l0oout Estilo1" scope="row">Costo</td>
                        <td width="5%" class="m0l0oout Estilo1" scope="row">Util.($)</td>
                        <td width="6%" class="m0l0oout Estilo1" scope="row">Util.(%)</td>
                      </tr>
					  <?php
					   //Definimos los colores a usar
					   $color0 = "#A4B4C1";
					   $color1 = "#D5E7FB";
					   $color2 = "#E8F2FC";
					   $color3 = "#E0FAC5";
					   $color = $color1;
					   $resb=mysql_query($sqlb,$con);
					   if (mysql_num_rows($resb)>0){
					    $sumaneto=0;
						$sumacosto=0;
						$sumatot=0;
					    while ($filab = mysql_fetch_row($resb)){
						$LLAVE=$filab[0];
						$tipo=substr($LLAVE,0,2);
						$numdoc=substr($LLAVE,5,7);
						if ($tipo=="01"){$tipogl="Fact.";}
						if ($tipo=="02"){$tipogl="Bole.";}
						if ($tipo=="03"){$tipogl="Guía.";}
						$CANTIDAD=$filab[1];
						$COD_INTERNO=$filab[2];
						$costo=0;
						$sqlcos="select costo_contable from m07005 where cod_interno='$COD_INTERNO';";
						$rescos=mysql_query($sqlcos,$con);// or die(mysql_error());						
						while ($filacos=mysql_fetch_array($rescos)){
						 $costo=$filacos[0]*$CANTIDAD;
						 }//wend
						$GLOSA=$filab[3];
						$PRECIO_V=$filab[4];	
						$preciocd=round($PRECIO_V - ($PRECIO_V*$desc/100));//precio con descuento incl.
						$preciont=round($CANTIDAD *$preciocd / 1.19);
						$sumaneto += $preciont;
						$sumacosto+=$costo;
						$difpeso=$preciont - $costo; 
						$difpor=$difpeso*100/$costo;
						$difpore=number_format($difpor,2,".",",") . "%";
						 // empezando una tabla html
						 echo "<tr style=\"background-color:$color\" onMouseOver=\"this.style.backgroundColor='$color3'\" onMouseOut=\"this.style.backgroundColor='$color'\">";
						 echo "<td> $tipogl </td>";
						 echo "<td> $numdoc </td>";
						 echo "<td align='right'>$CANTIDAD</td>";
						 echo "<td>$COD_INTERNO</td>";
						 echo "<td>$GLOSA</td>";
						 echo "<td align='right'>$PRECIO_V</td>";
						 echo "<td align='right'>$preciocd</td>";
						 echo "<td align='right'>$preciont</td>";
						 echo "<td align='right'>$costo</td>";
						 echo "<td align='right'>$difpeso</td>";
						 echo "<td align='right'>$difpore</td>";
						 echo "</tr>";
						 if ($color == $color1){
						  $color = $color2;
						  }else{
						  $color = $color1;
						 }
						}//while
						$dift=$sumaneto - $sumacosto;
						 echo "<tr style=\"background-color:$color\" onMouseOver=\"this.style.backgroundColor='$color3'\" onMouseOut=\"this.style.backgroundColor='$color'\">";
						 echo "<td><b> Totales </b> </td>";
						 echo "<td>  </td>";
						 echo "<td align='right'></td>";
						 echo "<td></td>";
						 echo "<td></td>";
						 echo "<td align='right'></td>";
						 echo "<td align='right'></td>";
						 echo "<td align='right'><b>$sumaneto</b></td>";
						 echo "<td align='right'><b>$sumacosto</b></td>";
						 echo "<td align='right'><b>$dift</b></td>";
						 echo "<td align='right'></td>";
						 echo "</tr>";

					   }//fin si 
					  ?>
                      <tr>
                        <td colspan="11" scope="row"><label>
                          <div align="center" class="LeftMenu"><acronym><a href="javascript:window.close();">Volver a Buscar<br />
</a></acronym>
                            <label></label>
</div>
                          </label></td>
                        </tr>
                      <tr>
                        <th colspan="11" scope="row"><label></label></th>
                        </tr>
                    </table>
                </form>
                  <p>&nbsp;</p>                  <p><a href="buscar"></a> </p></TD>
                <TD width=20 height="100%">&nbsp;</TD></TR>
              <TR>
                <TD width=23 height=8>&nbsp;</TD>
                <TD height=8>&nbsp;</TD>
        <TD width=20 
      height=8>&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY>
	  <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
 //------FIN-Coneccion Local
 mysql_close($con)
 //------FIN-Coneccion Local
 ?>
</HTML>