<?php require ("header.php") ?>

	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
	  
    
	
  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.6/jspdf.plugin.autotable.min.js"></script> 
  
				
                                    
           
  
 
 
 <br><br>
 
 
 <div class="container-fluid py-4">
 
  <div class="row">
        <div class="col-12">
          <div class="card my-4">
            <div class="card-header p-0 position-relative mt-n4 mx-3 z-index-2">
              <div class="bg-gradient-primary shadow-primary border-radius-lg pt-4 pb-3">
                <h4 class="text-white text-capitalize ps-3">Account Statement</h4>
               &nbsp; &nbsp;&nbsp;<input type="button" onclick="generate()" class="btn btn-success"  value="Export To PDF" />
              </div>
            </div>
            
            
            
            <div class="card-body px-0 pb-2">
              <div class="table-responsive p-0">
                
                
                
                <table class="table align-items-center mb-0" id="dataexample">
                    
              


                    
                  <thead>
                                <tr>
                                   <td colspan="7" style="text-align:center;"><h6> BANK ADDRESS: &nbsp;&nbsp; <?php echo $addre ?>   </h6></td>  
                               </tr>
                     
                     
                     
                     
                      <tr>
                           <td colspan="7" style="text-align:center;"><h6>ACCOUNT NAME:&nbsp;&nbsp; <?php echo $firstname ?> <?php echo $lastname ?> &nbsp;&nbsp;&nbsp;&nbsp; ACCOUNT NUMBER: &nbsp;&nbsp; <?php echo $acc_no ?>  </h6></td> 
                         </tr>
                         
                         
                       
                       
                   <?php
// Query transactions using PDO
$stmt = $pdo->prepare("SELECT * FROM transactions WHERE log_id = :log_id ORDER BY id DESC LIMIT 1000");
$stmt->execute(['log_id' => $id]);
$ordersres = $stmt->fetchAll(PDO::FETCH_ASSOC);

if (empty($ordersres)) {
    echo "<strong>No History</strong>";
} else {
    ?>
    <thead>
        <tr>    
            <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Amount</th>
            <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Type</th>
            <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Description</th>
            <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Transaction Id</th>
            <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Date/Time</th>
            <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Status</th>
            <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Action</th>
        </tr>
    </thead>
    <tbody>
    <?php
    foreach ($ordersres as $row) {
        $amount = $row['cur'] . " " . number_format($row['trans_amount'], 2);
        $tranType = ($row['tran_type'] == 1 || $row['tran_type2'] == 1) ? "DEBIT" : "CREDIT";
        $tranColor = ($row['tran_type'] == 1 || $row['tran_type2'] == 1) ? "red" : "green";

        // Determine status color
        $statusRaw = strtolower(trim($row['status']));
        if ($statusRaw === 'successful') {
            $statusBadge = "<span class='badge bg-success text-white'>Successful</span>";
        } elseif ($statusRaw === 'pending' || $statusRaw === '0' || $row['status'] == 0) {
            $statusBadge = "<span class='badge bg-danger text-white'>Pending</span>";
        } else {
            $statusBadge = "<span class='badge bg-secondary text-white'>Unknown</span>";
        }
        ?>
        <tr>
            <td style="white-space: nowrap; color: <?= $tranColor ?>"><?= $amount ?></td>
            <td style="white-space: nowrap; color: <?= $tranColor ?>"><?= $tranType ?></td>
           <td style="white-space: nowrap">
    <?= htmlspecialchars(strlen($row['note']) > 50 ? substr($row['note'], 0, 50) . '...' : $row['note']) ?>
</td>

            <td style="white-space: nowrap"><?= htmlspecialchars($row['trans_id']) ?></td>
            <td style="white-space: nowrap"><?= htmlspecialchars($row['date']) ?></td>
            <td class="text-center"><?= $statusBadge ?></td>
            <td class="text-center">
                <a href="trx_receipt.php?id=<?= $row['id'] ?>">
                    <span class="badge bg-primary text-white">Get Receipt</span>
                </a>
            </td>
        </tr>
        <?php
    }
    ?>
    </tbody>
    <?php
}
?>


              
</tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
 
 
 
 </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
	
	 <script type="text/javascript"> 
 
 
function generate() {  
    var doc = new jsPDF('p', 'pt', 'letter');  
    var htmlstring = '';  
    var tempVarToCheckPageHeight = 0;  
    var pageHeight = 0;  
    pageHeight = doc.internal.pageSize.height;  
    specialElementHandlers = {  
        // element with id of "bypass" - jQuery style selector  
        '#bypassme': function(element, renderer) {  
            // true = "handled elsewhere, bypass text extraction"  
            return true  
        }  
    };  
    margins = {  
        top: 150,  
        bottom: 60,  
        left: 40,  
        right: 40,  
        width: 600  
    };  
    var y = 20;  
    doc.setLineWidth(2);  
   
    
     doc.text(200, y = y + 30," <?php echo $domain_name ?>"); 
 
    doc.autoTable({  
        html: '#dataexample',  
        startY: 70,  
        theme: 'striped',  
        columnStyles: {  
            0: {  
                cellWidth: 30,  
            },  
            1: {  
                cellWidth: 120,  
            },  
            2: {  
                cellWidth: 70,  
            },
            3: {  
                cellWidth: 80,  
            },
            4: {  
                cellWidth: 80,  
            },
            5: {  
                cellWidth: 80,  
            },
            6: {  
                cellWidth: 80,  
            }
       
        },  
        styles: {  
            minCellHeight: 20  
        }  
    })  
    doc.save('account_statement.pdf');  
}  
</script> 
 
 
	
    <?php require ("footer.php") ?>