<?php 
$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="box-body">
             	    <div class="form-group">
                    <h1>Resumo Financeiro</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>		
			 <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Linha de Financiamento</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 tipo_credito FROM tipo_credito as t WHERE t.id = l.`credito`) as creditos, 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 `pay_date` BETWEEN '$data_inicial' AND '$data_final' GROUP BY creditos") or die (mysqli_error($link));
while($dados2 = mysqli_fetch_array($select2)){
            $credito = $dados2['creditos'];
            $saldo = $dados2['saldo'];
            $debito = $dados2['debito'];
            $valor_pagar = $dados2['apagar'];
            $pago = $dados2['valorpago'];
            echo "<tr>";
            echo "<td>$credito</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>