<?php 
include_once("../php/config.php");
        $sql = mysql_query("select * from clientes where nombre like '%".$_GET['buscar']."%' and  cobrador='".$_COOKIE['usuario']."' and ruta='".$_GET['ruta']."' order by  nombre asc
		") or die(mysql_error());


?>


			
             

					
            <?php while($r=mysql_fetch_array($sql)){?>
			<?php
			$c++;
			$monto+=$r["monto"];
      $id = $r["id_cliente"];
			?>
		<b><a class="#"   onClick='ver(<?php echo $r["id_cliente"]?>)'> <?php echo $r["id_cliente"]?></a> </b>
       - <a class="#"   onClick='ver(<?php echo $r["id_cliente"]?>)'><i class="bi bi-stickies"></i> <?php echo $r["nombre"]?></a> <span style='color:red; font-size:25px; font-weight:bolder'> <?php  $ba = balance($r["nombre"]);  if($ba>0){ echo $ba;

	   }?> </span> <br>
              
				<?php echo ($r["telefono"])?> |
				<?php echo ($r["direccion"])?><br>

				 

		
		
			

            
                                                        <?php }
												
		echo "<br><b class='h3'>".$c." clientes</b>";											
		echo "<br><b class='h3'> TOTAL: ".decimal($balance0)."</b>";													
	
$balance0=0;
function balance($cliente){
	global $balance0;
	        $sql = mysql_query("select sum(balance) as balance from ventas where cliente = '$cliente' and  balance>0") or die(mysql_error());
			$balance0+=mysql_result($sql, 0, "balance");
			return decimal(mysql_result($sql, 0, "balance"));
}





	?>
						
					
					