<?php 
if(!isset($_SESSION)) { 
  session_start(); 
  include('../includes/dbcon.php');
}
if(empty($_SESSION['rm_id'])):
header('Location:../index.php');
endif;
$cval=0;
$grn_no=0;

//////////////// Get Sequence Number ----------------------- 
 $querydoc=mysqli_query($con,"select * from sequence where seq_id=3 ")or die(mysqli_error());

    while($row=mysqli_fetch_array($querydoc)){ 
    $grn_no=$row['cno'];  
    }

//////////////////End of gettinh sequence Number ------------------
?>
<!DOCTYPE html>
<html lang="en">


<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>SalesHub | Stock Transfers </title>
  <!-- plugins:css -->
  <?php include('../includes/commonheader.php');?>



</head>
<body>
 <?php include('../includes/header.php');?>
 <?php include('../includes/leftsidebar.php');?>
           <!-- partial -->
 <div class="main-panel">        
        <div class="content-wrapper">

          <div class="page-header">
            <h3 class="page-title">
                Stock Transfers
            </h3>
          
          </div>
          <div class="col-22 grid-margin">
              <div class="card">
                <div class="card-body">
              
                          
    <form class="needs-validation" novalidate method="post" action="stock_trans_add.php" enctype="multipart/form-data" onsubmit="return validateForm()">                   
                    <div class="row">                     
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Ref No: </label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="lname" name="lname" value=<?php echo $grn_no ; ?> readonly>
                          </div>
                        </div>




                      </div>
                                              
                  <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Trn Date: </label>
                          <div class="col-sm-8">
                            <input type="date" class="form-control" id="tdate" name="tdate" >

                          </div>
                        </div>

                    </div> <!-------End of first form raw------->

            

</div>



  <div class="row">                     
  <div class="col-md-6">
  <div class="form-group row">
   <label class="col-sm-3 col-form-label">From Location: </label>
  <div class="col-sm-9">
  <select class="form-control select2" style="width: 100%;" name="fstock" id="fstock" required >
           <option value="0">~~~Select ~~~~</option>  
          <?php            
          $querydoc=mysqli_query($con,"select * from stock_locations  ")or die(mysqli_error());
          
          while($rowd=mysqli_fetch_array($querydoc)){
          ?>
          <option value="<?php echo $rowd['loc_id'];?>"><?php echo $rowd['loc_name'];?></option>        
          <?php }?>
          </select> 
 </div>



</div>
</div>
                <div class="col-md-6">                  
                          <div class="form-group row">
                          <label class="col-sm-3 col-form-label">To Location:</label>
                          <div class="col-sm-9">           

                               <select class="form-control select2" style="width: 100%;" name="estock" id="estock" required >
           <option value="0">~~~Select ~~~~</option>  
          <?php            
          $querydoc=mysqli_query($con,"select * from stock_locations  ")or die(mysqli_error());
          
          while($rowd=mysqli_fetch_array($querydoc)){
          ?>
          <option value="<?php echo $rowd['loc_id'];?>"><?php echo $rowd['loc_name'];?></option>        
          <?php }?>
          </select> 

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

  <div class="row">                     
  <div class="col-md-6">
  <div class="form-group row">
   <label class="col-sm-3 col-form-label">Note: </label>
  <div class="col-sm-9">
 <input type="text" class="form-control" id="note" name="note" >
 </div>



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






                     <button type="submit" class="btn btn-primary">Save</button>
                    <button class="btn btn-light">Cancel</button>
                  </form>
                </div>
              </div>
            </div>








  <div class="content-wrapper">
          <div class="col-lg-22 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <h6 >Draft </h6>
                  <p class="card-description">
                    <button type="button" onclick="document.location='home.php'" class="btn btn-warning "><i class="fas fa-arrow-left"></i> Go Back
                    
                  </button>
                  </p>
                  <div class="table-responsive">
                    <table class="table table-hover">
                      <thead>
                        <tr>
                          <th>#</th>
                          <th>No</th>
                          <th>Date</th>
                          <th>Location</th>
                          <th>Supplier</th>
                          <th>Edit</th> 
                        </tr>
                      </thead>
                      <tbody>
<?php
$rcount=0;
$query=mysqli_query($con,"SELECT stock_trans_temp_header.* ,stock_locations.loc_name AS floc,s2.loc_name AS tloc
FROM stock_trans_temp_header
LEFT JOIN stock_locations ON stock_locations.loc_id=stock_trans_temp_header.from_loc_id
LEFT JOIN stock_locations AS s2 ON s2.loc_id=stock_trans_temp_header.to_loc_id")or die(mysqli_error()); 
 while($row=mysqli_fetch_array($query)){   $rcount=$rcount+1;
             
                $grnd_no=$row['tran_id'];
                $grnd_date=$row['tran_date']; 
                $loc_name=$row['floc'];
                $sup_name=$row['tloc'];
              

 ?>
   <tr>
                         <td><?php echo $rcount;  ?></td>
                         <td><?php echo $row['tran_id'];?></td>
                         <td><?php echo $row['tran_date'];?></td>
                         <td><?php echo $row['floc'];?></td>
                         <td><?php echo $row['tloc'];?></td>
                         <td> <form method="post" action="#" enctype="multipart/form-data">
                            <input type="text" class="form-control pull-right" id="trn_no" name="trn_no"  value=" <?php echo $grnd_no; ?>">
         <button type="submit" formaction="stock_trans1.php" class="btn btn-outline-secondary btn-rounded btn-icon">
                        <i class="fas fa-edit text-danger"></i>
                      </button></form></td>
 

</tr>

 <?php }  ?>

                      </tbody>
                    </table>



        </div>  <!----- <div class="content-wrapper">------>
        </div>
          
          
  </div>

 </div><!-----End of main panel--~~~~~~~~~~~~~~~~~~~~~~~--------------->
 </div><!-----Dont Delete this DIV--~~~~~~~~~~~~~~~~~~~~~~~--------------->
</div>
  <!-- container-scroller -->
<?php include('../includes/footer.php');?>
<?php include('../includes/commonjs.php');?>
 
</body>


</html>

<script>
    $( document ).ready(function() {
         // alert("Please Select Order Type");

    });

function validateForm() { 

    //````````route````````````````````````````````````
    if($('#bname').val().trim().length == 0) {
           alert("Please enter the route you visited !!!");               
            return false;
    } ////``````````````````````````````````````````

    



 } ///validateForm() { 

</script>

 <!-- End custom js for this page-->
  <script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })
  })

</script>



