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




?>
<!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 | Item 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="col-12 grid-margin">
              <div class="card">
                <div class="card-body">
<div class="table-responsive">
                    <table id="order-listing" class="table">
                       <thead>
  <tr class="bg-primary text-white">
   
    <th width="7%">#</th>
    <th width="10%">Item Name</th>
    <th width="10%">Description</th>
    <th width="10%">Category</th>
    <th width="10%">Type</th> 
    <th width="10%">Sales Price</th> 
    <th width="10%">Cost Price</th>   
    <th width="4%">QOH</th> 
    <th width="4%">ROL</th> 
    <th width="8%">Case</th>
    <th width="5%">Unit</th>
    <th width="5%">Weight</th>
    <th width="25%">Edit</th>   

   
    </tr>
  </thead>
<tbody>
<?php
$rcount=0;

//echo$tt;

$sql="SELECT * from view_item_master"  ;

$query=mysqli_query($con,$sql)or die(mysqli_error()); 

              while($row=mysqli_fetch_array($query)){   $rcount=$rcount+1;
                $item_name=$row['item_name']; 
                 $item_id=$row['item_id']; 
                $description=$row['description']; 
                $cat_des=$row['cat_des'];
                $type_des=$row['type_des'];
                $sp=$row['sales_price'];
                $cp=$row['cost_price'];
                $qoh=$row['qoh'];
                $rol=$row['rol'];
                 $cat_id=$row['cat_id'];
                  $type_id=$row['type_id'];
                 $case_id=$row['case_id'];
                 $Weight=$row['Weight'];
                  $unit_des=$row['unit_des'];
              ?>   

               <tr>       
                  <td> <?php echo $rcount;   ?></td>
            <td> <?php echo $item_name;   ?></td>
             <td> <?php echo $description;   ?></td>
            <td> <?php echo $cat_des;   ?></td>
            <td><?php echo $type_des; ?></td>
           <td> <?php echo $sp;   ?></td>
            <td><?php echo $cp; ?></td>
            <td> <?php echo  $qoh;   ?></td>
            <td><?php echo $rol; ?></td>   
             <td><?php echo $case_id; ?></td>     
   <td><?php echo $unit_des; ?></td>   
    <td><?php echo $Weight; ?></td>



<td>
       <a href="#addvoucher<?php echo $row['item_id'];?>" data-target="#addvoucher<?php echo $row['item_id'];?>"data-toggle="modal"     </div> <i class="fas fa-edit "></i>  </i> </a> </td>
              

</td>
 <!----------------------Model ------------------------------->
     <div id="addvoucher<?php echo $row['item_id'];?>" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
          <div class="modal-dialog" style="width:80%; aria-hidden="true>
          <div class="modal-content" style="height:auto">        
          <div class="modal-body">
  
             <form class="form-horizontal" method="post" action="admin_item_edit.php" enctype='multipart/form-data'>
      <div class="form-group">
                     <label for="exampleInputPassword1">Item Name</label>
                <input type="text" class="form-control" id="itemname_edit" name="itemname_edit" value="<?php echo $item_name; ?>">
              <input type="hidden" class="form-control" id="itemid_edit" name="itemid_edit" value="<?php echo $row['item_id'];?>">

                </div>  
 <div class="form-group">
                     <label for="exampleInputPassword1">Item Des</label>
                <input type="text" class="form-control" id="itemdes_edit" name="itemdes_edit" value="<?php echo $description; ?>">
      

                </div>  



               <div class="form-group">
              <label for="exampleInputEmail1">Category </label>
         

               <select class="form-control select2" style="width: 100%;" name="cat_edit" id="cat_edit" required >           
          <?php            
          $querydoc=mysqli_query($con,"select * from item_category"
)or die(mysqli_error());          
          while($rowr=mysqli_fetch_array($querydoc)){
            if ($row['cat_id']==$rowr['cat_id']){ ?>            
            <option value="<?php echo $rowr['cat_id'];?>" selected><?php echo $rowr['cat_des'];?></option>
            <?php } else {
          ?>
          <option value="<?php echo $rowr['cat_id'];?>"><?php echo $rowr['cat_des'];?></option>        
          <?php } }?>
          </select> 



               </div>


                  <div class="form-group">
             

                   
<div class="form-group">
                  <label for="exampleInputPassword1">Item Type</label>
 <select class="form-control select2" style="width: 100%;" name="item_type_edit" id="item_type_edit" required >           
          <?php            
          $querydoc=mysqli_query($con,"select * from item_type"
)or die(mysqli_error());          
          while($rowd=mysqli_fetch_array($querydoc)){
            if ($row['type_id']==$rowd['type_id']){ ?>            
            <option value="<?php echo $rowd['type_id'];?>" selected><?php echo $rowd['type_des'];?></option>
            <?php } else {
          ?>
          <option value="<?php echo $rowd['type_id'];?>"><?php echo $rowd['type_des'];?></option>        
          <?php } }?>
          </select>                  
</div>
                </div>  


                <div class="form-group">
                     <label for="exampleInputPassword1">Sales Price</label>
                <input type="text" class="form-control" id="sp_edit" name="sp_edit" value="<?php echo $sp; ?>">    
                </div> 

                <div class="form-group">
                     <label for="exampleInputPassword1">Cost Price</label>
                <input type="text" class="form-control" id="cp_edit" name="cp_edit" value="<?php echo $cp; ?>">    
                </div> 

                 <div class="form-group">
                     <label for="exampleInputPassword1">QOH</label>
                <input type="text" class="form-control" id="qoh_edit" name="qoh_edit" value="<?php echo $qoh; ?>">    
                </div>

                     <div class="form-group">
                     <label for="exampleInputPassword1">ROL</label>
                <input type="text" class="form-control" id="rol_edit" name="rol_edit" value="<?php echo $rol; ?>">    
                </div>


                     <div class="form-group">
                     <label for="exampleInputPassword1">Weight</label>
                <input type="text" class="form-control" id="weight_edit" name="weight_edit" value="<?php echo $Weight; ?>">    
                </div>




                   <div class="modal-footer">
                   <button type="submit" class="btn btn-primary">Save changes</button>
                   <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                   </div>                   
          </form>

   


          </div>
        </div>
      </div>
    </div>
<!--------------- End of Model ------------------------------------>






                    </tr>                
                    <?php }  ?>
                    </tbody>
                    </table>
                  </div>
 </div> </div> </div>

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

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


</html>

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

    });



</script>

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

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

</script>



