<?php

include("includes/header.php"); 
include("includes/sidebar.php"); 

$saving_plans = $db_handle->runBaseQuery("SELECT * FROM savings_plans WHERE userID = $id ORDER BY id DESC");

 ?>
 
 
 <div class="main-content app-content">
 	<div class="container-fluid">
 	    
 	    <div class="d-flex justify-content-between align-items-center mb-3 mt-3 p-4 rounded-4 shadow-sm text-white" 
     style="background: #C81D25;">
  
  <div>
    <h5 class="fw-bold mb-1 text-light">Savings Plan History</h5>
    <p class="mb-0 opacity-75">View your savings progress and past transactions.</p>
  </div>

  <div>
    <i class="bi bi-piggy-bank-fill" style="font-size: 2.5rem;"></i>
  </div>
</div>
<div class="row mt-3">
            <div class="col-xl-12">
                <div class="card custom-card">
                    <div class="card-header justify-content-between border-bottom-0">
                        <div class="card-title"> Your Transactions </div>
                        <div class="d-flex flex-wrap ms-auto gap-2">
                           
                            
                        </div>
                    </div>
                    <div class="card-body p-3">
                        <div class="table-responsive">
                            <table class="table text-nowrap table-bordered" id="TableTab">
                                <thead>
                                    <tr>
                                        <th scope="col">#</th>
                                       
                                        <th scope="col">Duration</th>
                                       
                                        <th scope="col">Start Date</th>
                                        <th scope="col">End Date</th>
                                        <th scope="col">Date Created</th>
                                        <th scope="col">Status</th>
                                        
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    
                                        if($saving_plans){
                                        $i = 1;
                                    foreach($saving_plans as $saving_plan){
                                        
                                   echo "<tr>";
                                    echo '<td class="fw-medium">'.$i.'</td>';
                                   
                                      
                                        echo '<td> <span class="fw-medium">'.$saving_plan['duration_months'].' Months</span></td>';
                                       
                                        echo '<td> <span class="">'.$saving_plan['start_date'].'</span> </td>';
                                        echo '<td> <span class="">'.$saving_plan['end_date'].'</span> </td>';
                                        echo '<td> <span class="">'.$saving_plan['created_at'].'</span> </td>';
                                        
                                        echo '<td> <span class="">'.$saving_plan['status'].'</span> </td>';

                                    
                                       
                                    echo '</tr>';

                                    $i++;
                                    
                                    }

                                }
                                    
                           ?>         
                                   
                                   
                                </tbody>
                            </table>
                        </div>
                    </div>
                    
                </div>
            </div>
        </div>
        
        
        
    </div>
 </div>
  <?php

include("includes/footer.php"); 
 ?>