<?php
include("auth.php");
session_start();


?>


<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Withdrawal</title>
  <meta content="" name="description">
  <meta content="" name="keywords">
    <link href="assets/img/favicon.png" rel="icon">
    <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">
  <?php include("templates/inc.php"); ?>
  
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
          
            $("#btnWithdraw").click(function() {
                 
                var amount = $("#txtAmount").val();
                var bank = $("#txtBank").val();
                var accountholname = $("#txtAccount_holdername").val();
                var accountnumber = $("#txtAccount_Number").val();
                var ifsc = $("#txtIfsc").val();
                

                $.ajax({
                    type: 'post',
                    url: 'withdraw-bank-action.php',
                    data: {
                        'amount': amount,
                        'bank': bank,
                        'accountholname': accountholname,
                        'accountnumber': accountnumber,
                        'ifsc': ifsc,
                        'action': 'withdraw-bank'
                    },
                    success: function(data) {
                        alert(data);
                        location.reload();

                    }
                });



            });


        });
    </script>
</head>

<body>

  <!-- ======= Header ======= -->
  <?php
  include("templates/header.php");
  ?>

  <!-- End Header -->

  <!-- ======= Sidebar ======= -->

  <?php
  include("templates/sidebar.php");

  ?>


  <!-- End Sidebar-->

  <main id="main" class="main">

    <div class="pagetitle">
      <h1>Payments</h1>
     
    </div><!-- End Page Title -->


      
        
    <section class="section">
  <div class="row">
    <div class="col-lg-12">

      <div class="card" style="overflow:scroll;">
        <div class="card-body" id="records">
          <h5 class="card-title">Payment List</h5>
          <table id="example" class="table table-striped dt-responsive nowrap" style="width:100%">
            <thead>
              <tr>
                <th>SL NO</th>
                <th>Date</th>
                <th>Amount</th>
                <th>TDS</th>
                <th>Net Amt</th>
                <th>Description</th>
                <th>Status</th>
              </tr>
            </thead>
            <tbody>
  <?php
  require "./conn.php";
  $sl = 1;
  
  if (!isset($_SESSION['user_id'])) {
    die("Unauthorized access.");
}

$vendor_id = intval($_SESSION['user_id']); // current logged-in vendor id

  // fetch THIS vendor's payment records only
$sql = "SELECT *
        FROM payment
        WHERE vendor_id = $vendor_id
        ORDER BY payment_date DESC";

$rs = mysqli_query($conn, $sql);

  while ($row = mysqli_fetch_assoc($rs)) {
      echo "<tr>";
      echo "<td>" . $sl . "</td>";
      echo "<td>" . $row['payment_date'] . "</td>";
      echo "<td>" . number_format($row['amount'], 2) . "</td>";   // Gross amount
      echo "<td>" . number_format($row['tds'], 2) . "</td>";      // TDS
      echo "<td>" . number_format($row['netamt'], 2) . "</td>";   // Net credited
      echo "<td>" . ($row['description'] ?? '-') . "</td>";
      echo "<td>" . ucfirst($row['status']) . "</td>";
      echo "</tr>";

      $sl++;
  }
  ?>
</tbody>


          </table>
        </div>
      </div>
    </div>
  </div>
</section>


      
      
      
      
      
      
      

     
    
    <br><br><br>
    
    


  </main><!-- End #main -->
  <!-- ======= Footer ======= -->
  <?php
  include("templates/footer.php");
  ?>

  <!-- End Footer -->


  <?php include("templates/vendors.php"); ?>
  
  <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap5.min.js"></script>
<script src="https://cdn.datatables.net/responsive/2.4.1/js/dataTables.responsive.min.js" ></script>

<script>
  $(document).ready(function() {
      $('#example').DataTable();
  } );
  </script>


</html>