<?php 
$credito = $_GET['credito'];
$data_inicial = $_GET['data_inicial'];
$data_final = $_GET['data_final'];
?>
<div class="row">
		
	       
<section class="content">  
	        <div class="box box-success">
            <div class="box-body">
              <div class="table-responsive">
             	<div class="box-body">
             	    <div class="form-group">
                    <h1>Balancete</h1>
                </div><br>
<form method="post">
	<a class="btn btn-primary btn-flat" onclick="window.print();"><i class="fa fa-print"></i>&nbsp;Imprimir</a>
	<hr>		
	           <?php 
	             $sql = mysqli_query($link,"SELECT tipo_credito FROM tipo_credito WHERE id = '$credito'")or die (mysqli_error($link));
	             while($dadd = mysqli_fetch_assoc($sql)){
	                 $cr = $dadd['tipo_credito'];
	           ?>
	           <div class="form-group">
                    <label for="" class="col-sm-2 control-label" style="color:#009900"> Linha de Financiamento</label>
                        <div class="col-sm-10">
                          <input  type="text" class="form-control" value="<?php echo $cr; ?>" readonly>
                        </div>
                </div><br>
	           <?php
	             }
	           ?>
			  
			 <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Mutuario</th>
                  <th>Valor de Investimento</th>
                  <th>Valor a Reembolsar</th>
                  <th>Pagamentos Efetuados</th>
                  <th>Saldo</th>
                 </tr>
                </thead>
                <tbody>
<?php
$select2 = mysqli_query($link, "SELECT (select concat(fname, '',lname) as mt FROM borrowers as b WHERE b.id = l.`borrower`) as Mutuario, sum(`amount`) as debito,sum(`amount`+`tot_juros`) as apagar, sum((`amount`+`tot_juros`) - `amount_topay`) as valorpago, sum(`amount_topay`) as saldo FROM `loan_info` as l WHERE credito = '$credito' AND `pay_date` BETWEEN '$data_inicial' AND '$data_final' GROUP BY Mutuario") or die (mysqli_error($link));
while($dados2 = mysqli_fetch_array($select2)){
            $mutuario = $dados2['Mutuario'];
            $saldo = $dados2['saldo'];
            $debito = $dados2['debito'];
            $valor_pagar = $dados2['apagar'];
            $pago = $dados2['valorpago'];
            echo "<tr>";
            echo "<td>$mutuario</td>";
            echo "<td>$debito</td>";
            echo "<td>$valor_pagar</td>";
            echo "<td>$pago</td>";
            echo "<td>$saldo</td>";
            echo "</tr>";
        }
?>
    </tbody>
</table>  
</form>
</div>
</div>	
</div>
</div>	
</div>