<?php 
if(!isset($_SESSION)) { 
  session_start(); 
  include('../includes/dbcon.php');
}
if(empty($_SESSION['hrm_id'])):
header('Location:../index.php');




endif;
$userid=$_SESSION['hrm_id'];


$loc_id=$_SESSION['loc_id'];
$emp_id=$_SESSION['hrm_emp_id'];
$hrm_emp_id=$_SESSION['hrm_emp_id'];
$cval=0;
$grn_no=0;

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

    while($row=mysqli_fetch_array($querydoc)){ 
    $invd_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 | Sales Management </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">
                Sales Return
            </h3>
          
          </div>
          <div class="col-22 grid-margin">
              <div class="card">
                <div class="card-body">
              
                          
    <form class="needs-validation" novalidate method="post" action="sri_new_add.php" enctype="multipart/form-data" onsubmit="return validateForm()">                   
                    <div class="row">                     
                      <div class="col-md-4">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">SR Ref: </label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="lname" name="lname" value=<?php echo $invd_no ; ?> readonly>
                             
                          </div>
                        </div>




                      </div>
                      <div class="col-md-4">                  
                          <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Location </label>
                          <div class="col-sm-9">
                           <select class="form-control select2" style="width: 100%;" name="loc_id" id="loc_id"  >
          

          <?php            
          $querydoc=mysqli_query($con,"select * from stock_locations  ")or die(mysqli_error());
          
          while($rowd=mysqli_fetch_array($querydoc)){

            if($loc_id==$rowd['loc_id']){ ?>
 <option value="<?php echo $rowd['loc_id'];?>" selected><?php echo $rowd['loc_name'];?></option>

           <?php  } else {

          ?>
          <option value="<?php echo $rowd['loc_id'];?>"><?php echo $rowd['loc_name'];?></option>        
          <?php } } ?>
          </select> 
                          </div> 

                          </div>  

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

                          </div>
                        </div>

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

            

</div>



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



</div>
</div>
                <div class="col-md-8">                  
                          <div class="form-group row">
                          <label class="col-sm-2 col-form-label">Customer :</label>
                          <div class="col-sm-9">           

                              <select class="form-control select2" style="width: 100%;" name="cus_id" id="cus_id" required >
           <option value="0">~~~Select ~~~~</option>  
          <?php            
          $querydoc=mysqli_query($con,"select *,CONCAT(`customer_master`.`cus_name`,', ',`customer_master`.`cus_code`) AS `cus` from customer_master  ")or die(mysqli_error());
          
          while($rowd=mysqli_fetch_array($querydoc)){
            if($cus_id_s==$rowd['cus_id']  ){
          ?>
   <option value="<?php echo $rowd['cus_id'];?>" selected><?php echo $rowd['cus'];?></option>
 <?php } else {  ?>
    <option value="<?php echo $rowd['cus_id'];?>"><?php echo $rowd['cus'];?></option>        
          <?php } }?>
          </select> 

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

  <div class="row">                     
  <div class="col-md-4">
  <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">Next</button>
                    <button class="btn btn-light">Cancel</button>
                  </form>
     </div><!-----End of <div class="card-body">--~~~~~~---->
     </div><!-----End of <div class="card">--~~~~~~---->
     </div><!-----End of  <div class="col-22 grid-margin">--~~~~~~---->







 
     <div class="col-22 grid-margin" >
     <div class="card" style="background-color:#D0E5F8;">   
                <div class="card-body">
                  <h4 >Draft </h4>
                  <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>Customer</th>
                          <th>Edit</th> 
                        </tr>
                      </thead>
                      <tbody>
<?php
$rcount=0;
$query=mysqli_query($con,"SELECT inv_temp_header.*,stock_locations.loc_name,customer_master.cus_name
 FROM inv_temp_header
LEFT JOIN stock_locations ON stock_locations.loc_id=inv_temp_header.loc_id
LEFT JOIN customer_master ON customer_master.cus_id=inv_temp_header.cus_id where inv_type=2")or die(mysqli_error()); 
 while($row=mysqli_fetch_array($query)){   $rcount=$rcount+1;
             
                $invd_id=$row['invd_id'];
                $invd_date=$row['invd_date']; 
                $loc_name=$row['loc_name'];
                $cus_name=$row['cus_name'];
               ?>
   <tr>
                         <td><?php echo $rcount;  ?></td>
                         <td><?php echo $row['invd_id'];?></td>
                         <td><?php echo $row['invd_date'];?></td>
                         <td><?php echo $row['loc_name'];?></td>
                         <td><?php echo $row['cus_name'];?></td>
                         <td> <form method="post" action="#" enctype="multipart/form-data">
                            <input type="hidden" class="form-control pull-right" id="inv_no" name="inv_no"  value=" <?php echo $invd_id; ?>">
         <button type="submit" formaction="sri_new1.php" class="btn btn-outline-secondary btn-rounded btn-icon">
         <i class="fas fa-edit text-danger"></i>
         </button>


            <button type="submit" formaction="sri_remove.php" class="btn btn-outline-secondary btn-rounded btn-icon">
            <i class="fas fa-trash text-danger"></i>
            </button>


          </form>
          </td>
 

</tr>

 <?php }  ?>

                      </tbody>
                    </table>



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

     </div><!-----End of <div class="card-body">--~~~~~~---->
     </div><!-----End of <div class="card">--~~~~~~---->
     </div><!-----End of  <div class="col-22 grid-margin">--~~~~~~---->



     </div><!-----End of   <div class="content-wrapper">--~~~~~~---->
      

 </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() { 

   if ($('#loc_id').val() == 0){
    //if($('#loc_id').val().trim().length == 0) {
           alert("Please select the Location !!!");               
            return false;
    } ////``````````````````````````````````````````

   if ($('#cus_id').val() == 0){
    //if($('#loc_id').val().trim().length == 0) {
           alert("Please select the Customer !!!");               
            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>



