<div class="row">
    
		    <section class="content">  
	        <div class="box box-success">
            <div class="box-body">
              <div class="table-responsive">
             <div class="box-body">
<form method="post">
	 <button type="submit" class="btn btn-flat btn-danger" name="delete"><i class="fa fa-times"></i>&nbsp;Delete</button>
	<a href="newdespesa.php?id=<?php echo $_SESSION['tid']; ?>&&mid=<?php echo base64_encode("408"); ?>"><button type="button" class="btn btn-flat btn-info"><i class="fa fa-dollar"></i>&nbsp;Nova Despesa</button></a>
	
	<hr>
			<table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th><input type="checkbox" id="select_all"/></th>
                  <th>ID</th>
                  <th>Descrição</th>
				  <th>Valor</th>
				  <th>Data</th>
				  <th>Editar</th>
                 </tr>
                </thead>
                <tbody>
<?php
$tid = $_SESSION['tid'];
$select = mysqli_query($link, "SELECT id,customer,loan,amount_to_pay,referencia,conta,pay_date FROM payments WHERE tid = '$tid'order by pay_date DESC") or die (mysqli_error($link));
if(mysqli_num_rows($select)==0)
{
echo "<div class='alert alert-info'>Sem dados!.....Veja mais tarde!!</div>";
}
else{
while($row = mysqli_fetch_array($select))
{
$id = $row['id'];
$customer = $row['customer'];
$getin = mysqli_query($link, "SELECT fname, lname, account FROM borrowers WHERE id = '$customer'") or die (mysqli_error($link));
$have = mysqli_fetch_array($getin);
$nameit = $have['fname'].'&nbsp;'.$have['lname'];
//$accte = $have['account'];
$loan = $row['loan'];
$amount_to_pay = $row['amount_to_pay'];
$referencia = $row['referencia'];
$conta = $row['conta'];
$pay_date = $row['pay_date'];
$select1 = mysqli_query($link, "SELECT * FROM systemset") or die (mysqli_error($link));
while($row1 = mysqli_fetch_array($select1))
{
$balance = $loan - $amount_to_pay;
$currency = $row1['currency']; 
?>    
                <tr>
                <td><input id="optionsCheckbox" class="checkbox" name="selector[]" type="checkbox" value="<?php echo $id; ?>"></td>
                <td><?php echo $id; ?></td>
				<td><?php echo $nameit; ?></td>
				<td><?php echo "".number_format($loan,2,".",","); ?></td>
				
			<td><?php echo "".number_format($amount_to_pay,2,".",","); ?></td>
                <td><?php echo "".number_format($balance,2,".",","); ?></td>
				
				<td><?php echo $referencia; ?></td>
				<td><?php echo $conta; ?></td>
				<td><?php echo $pay_date; ?></td>
				
				<!--<td style="display:none;"><?php echo $name; ?></td>-->
				
			    <td><a href="view_pmt.php?id=<?php echo $id;?>"><button type="button" class="btn btn-success edit"<span class="glyphicon glyphicon-edit"></span> Editar</button>
			    </td>
			    
			    <!--<td><a href="#bs-example-modal-sm ?id=<?php echo $id;?>"><button type="button" class="btn btn-success edit"<span class="glyphicon glyphicon-edit"></span> Ver</button>-->
			    <!--</td>-->
			    
			    <!--<td><a class="bs-example-modal-sm" data-userid="<?php echo $id; ?>" data-toggle="bs-example-modal-sm" data-target="#bs-example-modal-sm"></a>-->
			    <!--<button type="button" class="btn btn-success edit"-->
			    <!--<span class="glyphicon glyphicon-edit"></span> Ver</button>-->
			    <!--</td>-->
	
		
			

<?php } } } ?>
             </tbody>
                </table>  
		
<?php
						if(isset($_POST['delete'])){
						$idm = $_GET['id'];
							$id=$_POST['selector'];
							$N = count($id);
						if($id == ''){
						echo "<script>alert('Sem linhas Selecionadas!!!'); </script>";	
						echo "<script>window.location='listpayment.php?id=".$_SESSION['tid']."&&mid=".base64_encode("408")."'; </script>";
							}
							else{
							for($i=0; $i < $N; $i++)
							{
								$result = mysqli_query($link,"DELETE FROM payments WHERE id ='$id[$i]'");
								echo "<script>alert('Pagamento deletado com sucesso!!!'); </script>";
								echo "<script>window.location='listpayment.php?id=".$_SESSION['tid']."&&mid=".base64_encode("408")."'; </script>";
							}
							}
							}
?>			
				
</form>
                </div>

				</div>	
				</div>
				
			
</div>	
			
			<div class="box box-info">
            <div class="box-body">
            <div class="alert alert-info" align="center" class="style2" style="color: #FFFFFF">Quantidade de Recebimentos:&nbsp;
			<?php 
			$call3 = mysqli_query($link, "SELECT * FROM payments ");
			$num3 = mysqli_num_rows($call3);
			?>
			<?php echo $num3; ?> 
			
			</div>
			
			 <div id="chartdiv1"></div>								
			</div>
			</div>		
       
</div>

<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Detalhes Do Financiamento</h4>
    </div>
    <div class="modal-body">
        <div class="col-md-4">
            <span style="width:350px;">Nome</span>
            <label for="recipient-name" class="control-label">Recipient:</label>
        </div>
    </div>
    
    <div class="form-group" class="col-md-4">
        
        
     </div>
    
    <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar
        </button>
      </div>
    </div>
  </div>
</div>


<!--<script>
jQuery(document).ready(function($) {
    $(".clickable-row").click(function() {
        window.location = $(this).data("href");
    });
});

</script>-->




<style>
    .clickable-row {
    cursor: pointer;
}
</style>