<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Digital Accounts Management</title>
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="images/favicon.png">
    <!-- Pignose Calender -->
    <link href="./plugins/pg-calendar/css/pignose.calendar.min.css" rel="stylesheet">
    <!-- Chartist -->
    <link rel="stylesheet" href="./plugins/chartist/css/chartist.min.css">
    <link rel="stylesheet" href="./plugins/chartist-plugin-tooltips/css/chartist-plugin-tooltip.css">
    <!-- Custom Stylesheet -->
    <link href="css/style.css" rel="stylesheet">

</head>

<?php 

  echo @$_GET['msg'];
  session_start();
  if(isset($_SESSION['userId'])){ 
    $accid=($_GET['accid']);
  require 'connection.php';


      // Get account ID grom purchase table
//              $qry = "SELECT accid FROM purchase where prid='$prid'";
//              $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
//           $row = mysqli_fetch_array($run);
//           $accid= $row['accid'];
//           // Get account Detail By accid
//      $qryacc = "SELECT * FROM accreg where accid='$accid'";
//             $runacc = mysqli_query($connect, $qryacc) or die(mysqli_error($connect));
//           $rowacc = mysqli_fetch_array($runacc);
// // Check posted or not
// $qrychk = "SELECT * FROM purchase where prid='$prid'";
//             $runchk = mysqli_query($connect, $qrychk) or die(mysqli_error($connect));
//          $rowchk = mysqli_fetch_array($runchk);
    
//          if($rowchk['posted']!==""){
//           $ckpost='hidden';
//          } else{
//          $ckpost='';
//          }
?>

 <body style="background-color: black;">

  
<div class="container" style="background-color: white; border-radius: 20px;">
  <div class="row" style="align-items: center; margin-top: 60px;">
 
<br><br><br>
<div class="col-12">
<button  class="btn btn-primary pull-right" id="closebtn">close</button>
<a href="pendingvchr.php">
<!-- <button class="btn btn-primary" id="Refreshbtn" >Refresh</button> -->
</a>
</div>
<h3 style="margin-left: 20px;">  <label>Pending Bilty Detail&nbsp; &nbsp;</label></h3>
<br>


  <div class="col-lg-12 col-md-12">
<!-- <label style="margin-left: 50%;">Supplier rate: &nbsp; &nbsp;</label> -->

                            <div class="card card-widget">
                                <div class="card-body">
                                  <div class="table-responsive">
                                    <label class="pull-right">Dr</label>
                                    <input class="pull-right" id="debit" style=" border-radius: 5px;" type="text" name="">
                                    <!--   -->
                                   <br> 
                                   <br> 
                                   <label class="pull-right">Cr</label>
                                   <input class="pull-right" id="credit" style="border-radius: 5px;" type="text" name="">

                                    <!--  -->
 <table class="table  table-stripped col-md-12">
                                   <tr>
                                     
                                     <label style="font-size: 16px;">
                              <?php         
 $qryitname = "SELECT accname FROM accreg where accid='$accid'";
             $runitname = mysqli_query($connect, $qryitname) or die(mysqli_error($connect));
   $rowitname = mysqli_fetch_array($runitname);
   echo $rowitname['accname'];
   ?>

                                     </label>
                                   </tr>
                                    <tr>
                                  <th>Dated</th>
                                  <th>Vno.</th>
                                    <th>Accid</th>
                                   
                                    <th>Acc Name</th>
                                    <th>Trid</th>
                               
                                    <th>Action</th>
                                 
                                    
                                    </tr>

                                    <tr>
                                      <?php
                    require 'connection.php';

                 $qry = "SELECT * FROM ledger where debit='0' and credit='0' and qty='0' and smid='1' and accid='$accid'";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
             $sr=1;
    while($row = mysqli_fetch_array($run)){
?>

<tr>
  <td><?php
  $dt = date_create($row['dated']);
   echo date_format($dt,"d-m-Y"); ?></td>
   <td><?php echo $row['vno'];
    ?></td>
    <td> <?php echo $row['accid']; ?> </td>
  <td>
    <?php $itid= $row['vno']; 
    $qryitname = "SELECT accname,qty FROM accreg inner join feedinout on accreg.accid=feedinout.custid where feedinout.vno='$itid'";
             $runitname = mysqli_query($connect, $qryitname) or die(mysqli_error($connect));
   $rowitname = mysqli_fetch_array($runitname);
   echo $rowitname['accname'] ." Bag= " .$rowitname['qty'];
    ?>
      
    </td>
  <td ><?php echo $row['trid']; ?></td>
 
  <td> <button class="btn btn-primary post">Submit</button>
  </td>
                                    </tr>
                                    <?php
                                    $sr++;
}?>
                                    <tbody id="itemdetail">
                           
                              </tbody>
                            </table>
                            
                            </div>

                                </div>

                            </div>
                           
                        </div>

        <!-- Save button -->
    
      <br>
      <br>
      <br>
      <br>
      <br>



       </div>

</div>
 </body>
<?php
}
 ?>
   <script src="plugins/common/common.min.js"></script>
    <script src="js/custom.min.js"></script>
    <script src="js/settings.js"></script>
    <script src="js/gleek.js"></script>
    <script src="js/styleSwitcher.js"></script>


<script type="text/javascript">

   $(document).keypress(function(e){
              if (e.which == 120){
                   $("#closebtn").click();
              }
           });
          $("#closebtn").click(function(){
           window.close();
          })

     </script>
     <script type="text/javascript">
  $('.table tbody').on('click','.post',function(){
    var currow = $(this).closest('tr');
    
    var dated = currow.find('td:eq(0)').text();
    var vno = currow.find('td:eq(1)').text();
    var accid = currow.find('td:eq(2)').text();
    var trid = currow.find('td:eq(4)').text();
    var dr = $('#debit').val();
    var cr = $('#credit').val();
if(dr==""){
  var amtcr = $('#credit').val();
} 
else{
  var amtdr = $('#debit').val();

}

if(dr=="" && cr==""){
  alert("Please Enter Amount")
}
else
{
 var rs = confirm("Do you want to post Bilty in Account");
 if(rs){
  currow.find('td:eq(11)').css("background-color", "red");
var currow = $(this).closest('tr').remove();
         event.preventDefault();
 
             $.ajax({
         url: 'postblty.php',
         method: 'POST',
        data: {dated: dated, vno: vno, accid: accid, trid: trid, amtdr: amtdr, amtcr: amtcr},
         success: function(data){
           alert(data);
    

      
         }
       })
 }
 }
  });

</script>

