<?php
require_once("../app/config.php");
$title="Account statement";
require_once('include/user_header.php');
require_once('include/user_navbar.php');
require_once('include/user_sidebar.php');
?>
<div class="content-wrapper">
      <!-- Page header -->
      <div class="page-header">
        <div class="page-header-content header-elements-md-inline">
          <div class="page-title d-flex">
          <h4><i class="icon-certificate mr-2"></i> <span class="font-weight-semibold">Account statement</span></h4>
          </div>
        </div>
      </div>
      <!-- /page header -->
<div class="content">
  <div class="row">
    <div class="col-md-12">
      <div class="card">
        <div class="card-body">
          <ul class="nav nav-tabs justify-content-center nav-tabs-highlight nav-justified">
            <li class="nav-item"><a href="#basic-tab1" class="nav-link active" data-toggle="tab">Own bank</a></li>
            <li class="nav-item"><a href="#basic-tab2" class="nav-link" data-toggle="tab">Other bank</a></li>
          </ul>
          <div class="tab-content">
            <div class="tab-pane fade show active" id="basic-tab1">
            <div class="table-responsive">
              <table class="table datatable-show-all">
                  <a href="javascript:void;" onclick="window.print();" class="pull-right text-default"><i class="icon-printer2 mr-2"></i>PRINT</a>
                <thead>
                  <tr>
                      <th>#</th>                                                                       
                      <th>Reference</th>                                                                       
                      <th>Amount</th>                                                                       
                      <th>Sender</th>                                                                       
                      <th>Receiver</th>                                                                       
                      <th>Acct no</th>                                                                       
                      <th>Type</th>                                                                       
                      <th>Date</th>   
                      <th>Status</th>   
                  </tr>
                </thead>
                <tbody>  
                  <?php
                  $trans = mysqli_query($dbc, "SELECT * FROM transfers WHERE (sender_id = '".$row['id']."') OR (receiver_id = '".$row['id']."') ORDER BY transfers.date DESC");
                  while($row1 = mysqli_fetch_array($trans)){
                  $sender=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM users WHERE id='".$row1['sender_id']."'"));
                  $receiver=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM users WHERE id='".$row1['receiver_id']."'"));?>
                  <tr>
                  <td><?php echo $index++;?>.</td>
                  <td>#<?php echo $row1['ref_id'];?></td>
                  <td><?php echo number_format($row1['amount']).$scan2['currency'];?></td>
                  <td><?php echo $sender['name'];?></td>
                  <td><?php echo $receiver['name'];?></td>
                  <td>#<?php echo $receiver['acct_no'];?></td>
                  <td><?php if($row1['type']==1){echo'Bank Transfer';}else if($row1['type']==2){echo'Bank charges';}?></td>
                  <td><?php echo date("Y/m/d h:i:A", strtotime($row1['date'])); ?></td>
                  <td><?php if($row1['status']==0){echo '<span class="badge badge-danger">Pending</span>';}else if($row1['status']==1){echo '<span class="badge badge-success">Paid</span>';}else if($row1['status']==2){echo '<span class="badge badge-primary">Declined</span>';}?></td>
                  </tr>
                  <?php }?> 
                </tbody>
              </table>
                  </div>
              </div>
            <div class="tab-pane fade" id="basic-tab2">
            <div class="table-responsive">
              <table class="table datatable-show-all">
                <a href="javascript:void;" onclick="window.print();" class="pull-right text-default"><i class="icon-printer2 mr-2"></i>PRINT</a>
                <thead>
                  <tr>
                      <th>#</th>                                                                       
                      <th>Reference</th>                                                                       
                      <th>Amount</th>                                                                       
                      <th>Sender</th>                                                                     
                      <th>Details</th>                                                                       
                      <th>Type</th>                                                                       
                      <th>Date</th>   
                      <th>Status</th>   
                  </tr>
                </thead>
                <tbody>  
                  <?php
                  $trans = mysqli_query($dbc, "SELECT * FROM int_transfer WHERE  user_id = '".$row['id']."' ORDER BY int_transfer.date DESC");
                  $index=1;
                  while($row1 = mysqli_fetch_array($trans)){
                  $sender=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM users WHERE id='".$row1['user_id']."'"));
                  ?>
                  <tr>
                  <td><?php echo $index++;?>.</td>
                  <td>#<?php echo $row1['ref_id'];?></td>
                  <td><?php echo number_format($row1['amount']).$scan2['currency'];?></td>
                  <td><?php echo $sender['name'];?></td>
                  <td><?php echo $row1['details'];?></td>
                  <td><?php if($row1['type']==1){echo'Bank Transfer';}else if($row1['type']==2){echo'Bank charges';}?></td>
                  <td><?php echo date("Y/m/d h:i:A", strtotime($row1['date'])); ?></td>
                   <td><?php if($row1['status']==0){echo '<span class="badge badge-danger">Pending</span>';}else if($row1['status']==1){echo '<span class="badge badge-success">Paid</span>';}else if($row1['status']==2){echo '<span class="badge badge-primary">Declined</span>';}?></td>
                  </tr>
                  <?php }?> 
                </tbody>
              </table>
                  </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>