<?php 
 include_once '../php/config.php';
 include_once '../header.php';
?>
<style>
th, td{
	font-size:19px;
}
</style>
   
    <!DOCTYPE html>
    <html>
      <head>
        
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <meta name="viewport" content="width=device-width">
<meta name="mobile-web-app-capable" content="yes">

<div class="container" style="background:white; padding:18px"><br>

<span class="text-rojo" style="font-size:35px"><i class="bi bi-map"></i> Balance por cobrador</span>
<br><br>
Usuario: <?php echo $_COOKIE["usuario"];?>
<hr>




	
	
	

 <br>
 
 

	<div class="table-responsive">
	<table class="table table-hover">
	<th>COBRADOR</th><th>BALANCE</th>
		<?php 
		$balance = 0;
		
			include_once '../php/config.php';
			
			$usuario = $_COOKIE["usuario"];
			$sql1 = mysql_query("select *  from login where nivel='Cobrador'") or die(mysql_error());
			while($row1 = mysql_fetch_array($sql1)){
				echo "<tr>";
				$cobrador = $row1["nombre_completo"];
				
				echo "<td>".$cobrador."</td>";
				echo "<td>".decimal(clientes($cobrador))."</td>";
				
				
				
				echo "</tr>";
				
			}
		
		
		
			function clientes($cobrador){
			
				global $balance0;
				$sql2 = mysql_query("select nombre from clientes where cobrador='$cobrador'") or die(mysql_error());
				while($row1 = mysql_fetch_array($sql2)){
						 
						$cliente = $row1["nombre"];
			  
						  $sql = mysql_query("select  sum(balance) as total from ventas where cliente='$cliente'") or die(mysql_error());
						  $total =mysql_fetch_row($sql);
						  $t+= $total[0];
						 
			  
				}
					  $balance0+=$t;
					  return $t; 
					 
					 
			  }
		
		?>
		
	<tfoot>
	
	</tfoot>	
	</table>

    <?php echo "<b>TOTAL: ".decimal($balance0)."</b>"?>

 </div>


</div>