<?php
 echo @$_GET['msg'];
  session_start();
  if(isset($_SESSION['userId'])){ 
include 'template/header.php';

?>


<div class="ch-container">
    <div class="row">
        
<!-- SIDEBAR HERE-->
<?php

include 'template/sidebar.php';

?>
       <style type="text/css">
@media only screen and (max-width: 600px) {
           .inp-box{
max-width: 100%;
           }
       }



       </style>



        <div id="content" class="col-lg-10 col-sm-10">
            <!-- content starts -->
            <div>
    <ul class="breadcrumb">
        
        <li>
            <a href="dashboard.php">Dashboard</a>
        </li>
         <li>
            <a href="chcks.php">Chicks</a>
        </li>
    </ul>
</div>

<div class="row">
    <div class="box col-md-12">

        <div class="box-inner">
            <div class="box-header well">
                <h2><i class="glyphicon glyphicon-info-sign"></i>Chicks In / Out</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i
                            class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i
                            class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content row">
                <div  class="col-lg-12 col-md-12 col-sm-12">
               
   <input style=" border: none; border-bottom: 1px solid black; float: right; font-size: 2rem" type="date" id="dated">
               
                </div>

<br>
<br>
                <div  class="col-lg-12 col-md-12 col-sm-12">
              
    <label>Creditor / جمع پارٹی</label>
                        
                      <select style="margin-top: 10px;" id="supid" class="form-control selectpicker"data-live-search="true"> 
                                         <?php
                    require 'connection.php'; 
         $qry = "SELECT * FROM accreg";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
                                         <option value="<?php echo $row['accid']; ?>"><?php echo $row['accname']; ?></option>
                                     <?php } ?>
                                     </select>
<br>
<br>
<input class="inp-box" id="qty" autocomplete="off"  type="number" placeholder="Qty" style="padding: 2px; width: 150px; margin-bottom: 10px; margin-top: 10px;"></input>
<input class="inp-box" id="prate" autocomplete="off"  type="number" placeholder="P_Rate" style="padding: 2px; width: 150px; margin-bottom: 10px; margin-top: 10px;"></input>
<input class="inp-box" id="srate" autocomplete="off"  type="number" placeholder="S_Rate" style="padding: 2px; width: 150px; margin-bottom: 10px; margin-top: 10px;"></input>
                   
                                     <br>
                                     <br>
    <label>Debitor / بنام پارٹی</label>
                                          
                      <select id="custid" class="form-control selectpicker"data-live-search="true"> 
                                         <?php
                    require 'connection.php'; 
         $qry = "SELECT * FROM accreg";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
                                         <option value="<?php echo $row['accid']; ?>"><?php echo $row['accname']; ?></option>
                                     <?php } ?>
                                     </select>
                                        <br>
                                        <br>
                                     <button id="svbtn" class="btn btn-sm btn-primary">Save Record</button>

                </div>
            </div>
        </div>
    </div>
</div>


<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well">
                <h2><i class="glyphicon glyphicon-info-sign"></i>Voucher Details</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i
                            class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i
                            class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content row">
                <div class="col-lg-12 col-md-12">
                  <table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
    <thead>
    <tr>
        <th>V.No</th>
        <th>Account Title</th>
        <th>Qty</th>
        <th>Pr_Rate</th>
        <th>Sl_Rate</th> 
        <th>Action</th> 
    </tr>
    </thead>
    <tbody id="itemdetail">

                     


         </tbody>
    </table>
                       



                </div>
            </div>
        </div>
    </div>
</div>



    <!-- content ends -->
    </div><!--/#content.col-md-0-->
</div><!--/fluid-row-->


    <hr>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">

        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">×</button>
                    <h3>Settings</h3>
                </div>
                <div class="modal-body">
                    <p>Here settings can be configured...</p>
                </div>
                <div class="modal-footer">
                    <a href="#" class="btn btn-default" data-dismiss="modal">Close</a>
                    <a href="#" class="btn btn-primary" data-dismiss="modal">Save changes</a>
                </div>
            </div>
        </div>
    </div>

<?php
include 'template/footer.php';
?>

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

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

 </script>

<script>
$(document).ready(function(){
      var dated = $('#dated').val();
               $.ajax({
        url: 'chksdetail.php',
        method: 'POST',
       data: {dated: dated},
        success: function(data){
            $('#itemdetail').html(data);
        }
      });


});
</script>

 <script type="text/javascript">
  $('.table tbody').on('click','.vdltbtn',function(){
    var currow = $(this).closest('tr');
    
    var chkvno = currow.find('td:eq(0)').text();
   var rs = confirm("Do you want to Delete this voucher");
 if(rs){
  // currow.find('td:eq(11)').css("background-color", "red");
var currow = $(this).closest('tr').remove();
         event.preventDefault();
             $.ajax({
         url: 'vchrdlt.php',
         method: 'POST',
        data: {chkvno: chkvno},
         success: function(data){
           alert(data);
    

      
         }
       })
 }
 
  });

</script>


<script>
$("#dated").change(function(){

        var dated = $('#dated').val();
               $.ajax({
        url: 'chksdetail.php',
        method: 'POST',
       data: {dated: dated},
        success: function(data){
            $('#itemdetail').html(data);
        }
      });


    });
</script>



<script>
$("#svbtn").click(function(){

      var supid = $('#supid').val();
      var custid = $('#custid').val();
      var qty = $('#qty').val();
      var prate = $('#prate').val();
      var srate = $('#srate').val();
      var dated = $('#dated').val();
      $('#svbtn').hide();
      event.preventDefault();
 
            $.ajax({
        url: 'adchcks.php',
        method: 'POST',
       data: {supid: supid, custid: custid, qty: qty, prate: prate, srate: srate, dated: dated},
        success: function(data){
            // $('#prate').val(data);
      $('#itemdetail').html(data);

      $('#svbtn').show();
      $("#qty").val("");
      $("#prate").val("");
      $("#srate").val("");
        }
      })

    });
</script>

<?php 
}
?>