<?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-info h3"><i class="fa fa-coins"></i> Cobros por Cobradores</span>
<br><br>
Usuario: <?php echo $_COOKIE["usuario"];?>
<hr>


<form action="" method="POST">
<div class="row">
	<div class="col-md-1 mt-2">Desde</div>
	<div class="col-md-3"><input type="Date" id="fecha1" name="fecha1" class="form-control mt-2" value="<?php echo $hoy;?>"></div>
	
	<div class="col-md-1 mt-2">Hasta</div>
	<div class="col-md-3"><input type="Date" id="fecha2" name="fecha2" class="form-control mt-2" value="<?php echo $hoy;?>"></div>
	<div class="col-md-4"><button class="btn btn-orange mt-2" name="btn_cosulta"><i class="bi cash-coin"></i> Consultar</button>
	<a class="btn btn-light mt-2" href="mainAdmin.php"><i class="fa fa-undo"></i> Atras</a> </div>
 </div>
 <br>
 
 
 <div class="row">
  <div class="col-md-12">
	<div class="table-responsive">
	<table class="table table-hover">
	<th>COBRADOR</th><th>MONTO</th><th>COMISION</th><th>BALANCE</th>
		<?php 
		$balance = 0;
		if(isSet($_POST["btn_cosulta"])){
			include_once '../php/config.php';
			$fecha1 = $_POST["fecha1"];
			$fecha2 = $_POST["fecha2"];
			$usuario = $_COOKIE["usuario"];
			$sql1 = mysql_query("select nombre_completo, comision from login where nivel='Cobrador' order by nombre_completo asc") or die(mysql_error());
			while($row1 = mysql_fetch_array($sql1)){
				echo "<tr>";
				$nombre = $row1["nombre_completo"];
				$tasa_comision = $row1["comision"];
				echo "<td>$nombre</td>";
				echo "<td>".decimal(get_cobro($nombre, $fecha1, $fecha2))."</td>";
				
				echo "<td>".decimal(get_comision($nombre, $fecha1, $fecha2, $tasa_comision))." (".$tasa_comision."%)</td>";
				echo "<td>".decimal($balance)."</td>";
				$balance = 0;
				echo "</tr>";
				
			}
		}
		
		
		function get_cobro($usuario, $fecha1, $fecha2){
			
			global $balance;
			$sql2 = mysql_query("select sum(monto) as total from pagos_credito where usuario='$usuario' and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());
			$total =mysql_fetch_row($sql2);
			$balance +=$total[0];
			return $total[0];
		}
		
	
		
			function get_comision($usuario, $fecha1, $fecha2, $tasa_comision){
			
			global $balance;
			
			$sql2 = mysql_query("select  sum(monto) as total from pagos_credito where usuario='$usuario' and fecha between '$fecha1' and '$fecha2'") or die(mysql_error());
			$total =mysql_fetch_row($sql2);
			$t = $total[0] * $tasa_comision /100;
			$balance = $balance - $t;
			return $t; 
		}
		
		
		?>
		
	<tfoot>
	
	</tfoot>	
	</table>
	</div>
  </div>
 </div>
</form>

</div>