<?php  require_once('../auth/auth.php'); ?>
<section class="content">
  <div class="container-fluid">
    <div class="row">
     <div class="col-md-2"></div>
      <div class="col-md-8">
        <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
          <div class="card-header" style="padding: 3px 8px;">
            <h3 class="card-title"><i class="fa fa-plus"></i> Balence Approved</h3>
            <div class="card-tools m-0">
              <button type="button" class="btn btn-tool" data-card-widget="remove">
              <i class="fas fa-times"></i>
              </button>
            </div>
          </div>
          <div class="card-body">
            <div class="col-md-12 my-1">
              <table class="ttable table-sm table-head-fixed text-nowrap">
                <thead>
                  <tr>
                    <th class="text-center w-5"><?php echo language(15);?></th>
                    <th class="text-center w-15">Pay Method</th>
                    <th class="text-center w-15">Sender</th>
                    <th class="text-center w-20">TNX Id</th>
                    <th class="text-center w-15">Amount</th>
                    <th class="text-center w-10">Status</th>
                    <th class="text-center w-15">Action</th>
                    <th class="text-center w-5">#</th>
                  </tr>
                </thead>
                <tbody>
                  <?php
                     $pqry = mysqli_query($conn,"SELECT * FROM add_balance WHERE coid != '$coid' AND status=0")or die(mysqli_error($conn));
                     $i=1;
                     while($brw = mysqli_fetch_assoc($pqry)){
                  ?>
                  <tr class="tr-hover">
                    <td class="text-center"><?php echo $i++;?></td>
                    <td class="text-center"><?php echo $brw['pay_method'];?></td>
                    <td class="text-center"><?php echo $brw['send_gsm'];?></td>
                    <td class="text-center"><?php echo $brw['tnxid'];?></td>
                    <td class="text-center"><?php echo $brw['amount'];?></td>
                    <td class="text-center">
                    <?php if($brw['status']==1){
                        echo '<span class="badge bg-success" style="font-size:100%">Success</span>';
                      } else if($brw['status']==0){
                        echo '<span class="badge bg-danger" style="font-size:100%">Pending</span>';
                      }
                    ?>
                  </td>
                  <td class="text-center">
                     <select class="form-control select2" style="width: 100%;" required="true">
                       <option value="<?php echo $brw['status']?>">Pending</option> 
                       <option value="1">Actived</option>   
                       <option value="2">Rejected</option> 
                     </select>
                  </td>
                  <td class="text-center">
                     <button type="button" class="btn btn-block bg-gradient-success btn-xs" adid="<?php echo $brw['adid'];?>"> Approve</button>
                  </td>
                  </tr>
                <?php } ?>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
      <div class="col-md-2"></div>
    </div>
  </div>
</section>

<script>
   $('select').select2();
   $(document).ready(function() {
   $('[adid]').on('click', function(e){
   e.preventDefault(); 
       let adid   = $(this).attr('adid');
       let action = $(this).parent().parent().find("select").val(); 
        $(this).prop('disabled', true); 
        $.post("../bill_package/balance_db.php",{adid:adid,action:action},function(data){
        if(data==1){
          toastr.success(Successfully, yourdata);
          $('[adid]').parent().parent().fadeOut('slow');
        } else {
          toastr.success(Deleted, yourdata);
          $('[adid]').parent().parent().fadeOut('slow');
        }
      });
     });
   });  
</script>