<?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>Withdrawal</h1>
     
    </div><!-- End Page Title -->


       <?php
			$v_code = $_SESSION['v_code'];
			include "./conn.php";
			$sql = "select * from tbl_vendor where v_code='$v_code'";
			$smt = mysqli_query($conn, $sql);

			$rs = mysqli_fetch_assoc($smt);


			?>



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

                </div>

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


                    <div class="card">
                        <div class="card-body">
                            
<br>
                            <!-- Multi Columns Form -->
                            <form class="row g-3">
                                <div class="col-12">
                                    <label for="text" class="form-label">Amount*</label>
                                    <input type="text" id="txtAmount" name="txtAmount" class="form-control" value=" ">

                                </div>

                                <div class="col-12">
                                    <label for="text" class="form-label">Bank Name*</label>
                                    <input type="text" id="txtBank" name="txtBank" class="form-control" readonly value="  <?php echo $rs['bank_name']; ?>  ">

                                </div>

                                <div class="col-12">
                                    <label for="text" class="form-label">Account Holder*</label>
                                    <input id="txtAccount_holdername" name="txtAccount_holdername" type="text" class="form-control" readonly value=" <?php echo $rs['acc_holder']; ?> ">

                                </div>



                                <div class="col-12">
                                    <label for="txt" class="form-label"> Amount Number*</label>
                                    <input id="txtAccount_Number" name="txtAccount_Number" type="text" class="form-control" readonly value=" <?php echo $rs['acc_no']; ?>">

                                </div>


                                <div class="col-12">
                                    <label for="txt" class="form-label">IFSC Code*</label>
                                    <input id="txtIfsc" name="txtIfsc" type="text" class="form-control" readonly value=" <?php echo $rs['ifsc']; ?>  ">

                                </div>

                                <span style="color:#f00">NOTE - All * Marked fields are required.</span><br> <br>


                                <div class="text-center">
                                    <button type="button" class="btn btn-primary" id="btnWithdraw">Submit</button>
                                </div>
                            </form><!-- End Multi Columns Form -->

                        </div>
                    </div>


                </div>
                <div class="col-lg-1">
                </div>
            </div>
        </section>
        
        
        
        
        
      <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">Withdrawl List</h5>
                <table id="example" class="table table-striped dt-responsive nowrap" style="width:100%">
                  <thead>
                                        <tr>
										    <th>SL NO</th>
											<th>UID</th>
											<th>DATE</th>
											 <th>AMOUNT</th>
											  <th>BANK</th>	
												<th>ACC.HO</th>
												<th>ACC.NO</th>
												 <th>IFSC</th>
												  <th>STATUS</th>
												
                                        </tr>
                                    </thead>
                                    <tbody>
                                        
                                    <?php
									require "./conn.php";
									 $sl=1;
									 
									$cid=$_SESSION['v_code'];
									$sql="select * from   tbl_wallet_withdraw where cid='$cid' order by trans_date desc";
									  $rs=mysqli_query($conn,$sql);
									  while($row=mysqli_fetch_assoc($rs))
									  {
											echo'<td>'.$sl.'</td>';
											echo'<td>'.$row['id'].'</td>';
										  echo'<td>'.$row['trans_date'].'</td>';
											echo'<td>'.$row['amount'].'</td>';
										
											echo'<td>'.$row['bank_name'].'</td>';
											echo'<td>'.$row['account_holder_name'].'</td>';
											echo'<td>'.$row['account_no'].'</td>';
											echo'<td>'.$row['ifsc_code'].'</td>';
										
										
										
                      if ($row['status'] == 'Under Process') {
                        echo '<td><button id=' . $row['id'] . ' class="btn btn-warning btn-sm">Under Process</button></td>';

                      } else {

                        echo '<td> <button id=' . $row['id'] . ' class="btn btn-success btn-sm">Transfered</button></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>