
<head>

    <meta charset="utf-8">
    <title>DIGITAL ACCOUNTS MANAGEMENT</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Charisma, a fully featured, responsive, HTML5, Bootstrap admin template.">
    <meta name="author" content="KASHIF ALI">

    <!-- The styles -->
    <link id="bs-css" href="css/bootstrap-cerulean.min.css" rel="stylesheet">

    <link href="css/charisma-app.css" rel="stylesheet">
    <link href='bower_components/fullcalendar/dist/fullcalendar.css' rel='stylesheet'>
    <link href='bower_components/fullcalendar/dist/fullcalendar.print.css' rel='stylesheet' media='print'>
    <link href='bower_components/chosen/chosen.min.css' rel='stylesheet'>
    <link href='bower_components/colorbox/example3/colorbox.css' rel='stylesheet'>
    <link href='bower_components/responsive-tables/responsive-tables.css' rel='stylesheet'>
    <link href='bower_components/bootstrap-tour/build/css/bootstrap-tour.min.css' rel='stylesheet'>
    <link href='css/jquery.noty.css' rel='stylesheet'>
    <link href='css/noty_theme_default.css' rel='stylesheet'>
    <link href='css/elfinder.min.css' rel='stylesheet'>
    <link href='css/elfinder.theme.css' rel='stylesheet'>
    <link href='css/jquery.iphone.toggle.css' rel='stylesheet'>
    <link href='css/uploadify.css' rel='stylesheet'>
    <link href='css/animate.min.css' rel='stylesheet'>


 <link rel="stylesheet" href="css/jquery-ui.css">
  <!-- <link rel="stylesheet" href="/resources/demos/style.css"> -->
  <script src="js/jquery-1.12.4.js"></script>
  <script src="js/jquery-ui.js"></script>
    <link rel="stylesheet" href="css/bootsrap_my.css" />


    <!-- jQuery -->
    <script src="bower_components/jquery/jquery.min.js"></script>

    <link rel="shortcut icon" href="img/favicon.ico">
<!-- ****************************************** -->

  <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"> -->
  <link rel="stylesheet" href="css/font-awesome.min2.css">
  <link rel="stylesheet" href="dist/css/bootstrap-select.css">

<!-- ************************************************ -->
</head>

 <body  style="background-color: white; margin-top: 2%; ">
 <div  class="container"> 

<?php 

  echo @$_GET['msg'];
  session_start();
  if(isset($_SESSION['userId'])){ 
  if($_SESSION['userId']==2){ 

 	require 'connection.php';
extract($_GET);

$qry1 = "SELECT * FROM accreg where accid='$accid'";
             $run1 = mysqli_query($connect, $qry1) or die(mysqli_error($connect));
             $sr=1;
    $row = mysqli_fetch_array($run1);
    $supname = $row['accname'];
 			// 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;">
  -->
<div class="col-12">
<button   class="btn btn-warning btn-sm" id="closebtn">close</button>

</div>
<h3 style="margin-left: 20px;">  <label>Pending Voucher Detail&nbsp; &nbsp;</label></h3>



  <div class="col-lg-12 col-md-12">
    <h3 style="margin-left: 20px;">  <label><?php echo $supname; ?>&nbsp; &nbsp;</label></h3>

<input style="margin-left: 50%; border-radius: 5px;"  placeholder="Enter Supplier Rate" type="text" onkeypress="return (event.charCode !=8 && event.charCode ==0 || (event.charCode >= 48 && event.charCode <= 57))" name="" id="suprate">

<input id="supid" hidden style="margin-left: 50%; border-radius: 5px; background-color: red"  value="<?php echo $accid; ?>" type="text" name="" id="suplesrate">
<button id="postall" class="btn btn-primary btn-sm" style="background-color: red; color: white;">Post All Voucher</button>
<br>
<br>
                            <div class="card card-widget">
                                <div class="card-body">
                                  <div class="table-responsive">
                                  <label id="chkposted"></label>
                                  <table class="table  table-stripped col-md-12">
                                    <tr>
                                  <th>Dated</th>
                                  <th>Vno.</th>
                                    <th>Product</th>
                                    <th hidden>itemid</th>
                                    <th hidden>supid</th>
                                    <th hidden>accid</th>
                                    <th>Qty</th>
                                    <th>Kat</th>
                                    <th>Sup_Rate</th>
                                    <th>Cus_Rate</th>
                                    <th hidden>dated</th>
                                    <th>Action</th>
                                 
                                    
                                    </tr>

                                    <tr>
                                      <?php
                    require 'connection.php';
 // order by vno ASC
                 
                 $qry = "SELECT * FROM broilertransfer where vrate='0' and supid='$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 $itid= $row['itemid']; 
    $qryitname = "SELECT itemname FROM itemreg where itemid='$itid'";
             $runitname = mysqli_query($connect, $qryitname) or die(mysqli_error($connect));
   $rowitname = mysqli_fetch_array($runitname);
   echo $rowitname['itemname'];
    ?>
      
    </td>
  <td hidden><?php echo $row['itemid']; ?></td>
  <td hidden><?php echo $row['supid']; ?></td>
  <td hidden><?php echo $row['accid']; ?></td>

  <td><?php echo $row['qty']; ?></td>
  <td><?php echo $row['kat']; ?></td>
  <td><?php echo $row['vrate']; ?></td>
  <td><?php echo $row['crate']; ?></td>
  <td hidden><?php echo $row['dated']; ?></td>
  <td> <button class="btn btn-success btn-sm 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
}
}
else{
   header('location: index.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(10)').text();
    var vno = currow.find('td:eq(1)').text();
    var itemid = currow.find('td:eq(3)').text();
    var supid = currow.find('td:eq(4)').text();
    var accid = currow.find('td:eq(5)').text();
    var qty = currow.find('td:eq(6)').text();
    var kat = currow.find('td:eq(7)').text();
    var crate = currow.find('td:eq(9)').text();
    var srate = $('#suprate').val();
if(srate==""){
  alert("Please Enter Supplier Rate")
  $('#suprate').focus();
}

else
{
 var rs = confirm("Do you want to post this voucher");
 if(rs){
  currow.find('td:eq(11)').css("background-color", "red");
var currow = $(this).closest('tr').remove();
         event.preventDefault();
 
             $.ajax({
         url: 'postvchr.php',
         method: 'POST',
        data: {kat: kat, supid: supid, accid: accid, dated: dated, vno: vno, itemid: itemid, qty: qty, crate: crate, srate: srate},
         success: function(data){
           alert(data);
    

      
         }
       })
 }
 }
  });

</script>

 <script type="text/javascript">
  $('.table tbody').on('click','.post2',function(){
    var currow = $(this).closest('tr');
    
    var dated = currow.find('td:eq(10)').text();
    var vno = currow.find('td:eq(1)').text();
    var itemid = currow.find('td:eq(3)').text();
    var supid = currow.find('td:eq(4)').text();
    var accid = currow.find('td:eq(5)').text();
    var qty = currow.find('td:eq(6)').text();
    var kat = currow.find('td:eq(7)').text();
    var crate = currow.find('td:eq(9)').text();
    var srat = currow.find('td:eq(9)').text();
   var supless = $('#suplesrate').val();
   var suprt = (srat)-(supless);
   var srate = suprt;
if(supless==""){
 

  {
 var rs = confirm("Do you want to post this voucher");
 if(rs){
  currow.find('td:eq(11)').css("background-color", "red");
var currow = $(this).closest('tr').remove();
         event.preventDefault();
 
             $.ajax({
         url: 'postvchr.php',
         method: 'POST',
        data: {kat: kat, supid: supid, accid: accid, dated: dated, vno: vno, itemid: itemid, qty: qty, crate: crate, srate: srate},
         success: function(data){
           alert(data);
    

      
         }
       })
 }
 }
}

else
{

  var rs = confirm("Do you want to post this voucher");
  if(rs){
   currow.find('td:eq(11)').css("background-color", "red");
 var currow = $(this).closest('tr').remove();
          event.preventDefault();
 
             $.ajax({
         url: 'postvchr.php',
         method: 'POST',
        data: {kat: kat, supid: supid, accid: accid, dated: dated, vno: vno, itemid: itemid, qty: qty, crate: crate, srate: srate},
         success: function(data){
          alert(data);
    

      
         }      
           })
 }
 }
  });

</script>

<!-- *************************************** -->

<!-- FOR POST ALL VOUCHER -->
 <script type="text/javascript">
  $('#postall').click(function(){
    var supid = $("#supid").val();
 var rs = confirm("Do you want to post all voucher");
 if(rs){
         event.preventDefault();
 
             $.ajax({
         url: 'postall.php',
         method: 'POST',
        data: {supid: supid},
         success: function(data){
           alert(data);
    
         }
       })
 }

  });

</script>


<!-- *************************************** -->

<!-- FOR POST SINGLE DATE VOUCHER -->
 <script type="text/javascript">
  $('#singlpost').click(function(){
if($("#suprate").val()!==""){
    var supid = $("#supid").val();
    var dated = $("#ddated").val();
    var rate = $("#suprate").val();

 var rs = confirm("Do you want to post all voucher");
 if(rs){
         event.preventDefault();
 
             $.ajax({
         url: 'postdt.php',
         method: 'POST',
        data: {supid: supid, dated: dated, rate: rate},
         success: function(data){
           alert(data);
    
         }
       })
 }
}
else{
  alert("Enter Sup Rate");
} 

  });

</script>

  <script type="text/javascript">
    var today = new Date();

document.getElementById("ddated").value = today.getFullYear() + '-' + ('0' + (today.getMonth() + 1)).slice(-2) + '-' + ('0' + today.getDate()).slice(-2);

 </script>