<?php
  //invoice.php  
  include('db_con.php');
  
  include('function.php');
  
  if (isset($_SESSION['user_id'])) {
    $user_type = $_SESSION['user_type'];
    $user_id = $_SESSION['user_id'];
    $user_name = $_SESSION['user_name'];
    $branch_id = $_SESSION['branch_id'];
    $branch_name = $_SESSION['branch_name'];
    $store_id = $_SESSION['store_id'];
    $store_name = $_SESSION['store_name'];
}else{
  header('Location: login');
  die();
}
$sql = "SELECT IFNULL(doc_status,'ON') FROM user_rights WHERE user_id = '".$user_id."' and doc_name = 'inventory_reports_stockavailable'";
            $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
            $inventory_reports_stockavailable = $statement->fetchColumn();
            if($inventory_reports_stockavailable=='OFF'){header('Location: dashboard');}
  if(isset($_POST["print"]))
  {
    stock_update($connect);
     $type_id = $_POST['type_id'];
    
     $stock = $_POST['stock'];
      $item_name = $_POST['item_name'];
   
   
  
      
      //$result = $statement->fetchAll();
      header('location:rpt_stock_available_value_preview?print=1&type_id='.$type_id.'&item_name='.$item_name.'&stock='.$stock.'');
  }
           
  ?>
<!DOCTYPE html>
<html>
<head>
  <title>Stock Available Value</title>
  <?php include('include/head.php'); ?>
  
</head>
<body>
  <?php include('include/header.php'); ?>
  <?php include('include/sidebar.php'); ?>
   <?php include('include/script.php'); ?>
<div class="main-container">
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark"></h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item active">Inventory</li>
              <li class="breadcrumb-item active">Reports </li>
              <li class="breadcrumb-item active">Stock By Store </li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <!-- Small boxes (Stat box) -->
     <span id="alert_action"></span>
    <div class="row">
        <div class="col-12">
          <div class="card">
            <div class="card-header">
            <div class="row">
                          <div class="col-lg-10 col-md-10 col-sm-8 col-xs-6">
                              <h3 class="panel-title">Stock Available Report</h3>
                            </div>
                            
                        </div>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
       <form method="post" id="report_form">
      <br />
      
        <div class="table-responsive">
          <table class="table table-bordered">
            <tr>
              <td colspan="2" align="center"><h2 style="margin-top:10.5px">Stock Available Report</h2></td>
            </tr>
            <tr>
                <td colspan="2">
                  <div class="row">
                    <div class="col-md-4">
                    <br />
                    <br />    
            
            <div class="form-group">
            
              <select name="type_id" id="type_id" class="form-control select2" />
                          <?php echo fill_itemtype($connect);?>
                         
                         
                        </select>
            </div>

              <div class="form-group">
            
           <input type="text" name="item_name" id="item_name" class="form-control input-sm number_only item_name" list="datalist1" value="%%" placeholder="Description">
            </div>

           
         
            
                   
                        <input type="text" name="stock" id="stock" class="form-control"
                        placeholder="Enter Greater Than" />
          
            
              <tr>
                <td colspan="2" align="center">
                <input type="submit" name="print" id="print" class="btn btn-info" value="Preview" />
                 
                 
                </td>
              </tr>
          </table>
        </div>
      </form>
      </div>
              </div>
          </div>
      </div>
             
        
        
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
 
  <!-- /.content-wrapper -->
 
  
  <script src="js/jquery-ui.js"></script>
  <script src="js/jquery-ui.min.js"></script>
    </div>
    </div>
 
  <datalist id="datalist1">
  
</datalist>
</body>
</html>
 
  <script>
  $('.select2').select2();
   $(document).on('select2:select','.select2', function(e){
            var x = $(this).val();

            var item_no = $('#item_no').val();
            var cust_id = $('#cust_id').val();
            var type_id = x;
            $.ajax({
              url:"find_item.php",
              method:"POST",
              data:{type_id:x},
              dataType:"text",
              success:function(data)
              {
                
                $('#item_name').val('');
                $('#datalist1').html(data);
                
              
              }
           
         })
             });
  </script>
     