<?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="itmrg.php">Products</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> Add / Update Products</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">
                 
                                     </select>

                                 <div class="col-md-6">
                        
                      <select id="catid" class="form-control selectpicker"data-live-search="true"> 
                                         <?php
                    require 'connection.php'; 
         $qry = "SELECT * FROM category where catid>2";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
                                         <option value="<?php echo $row['catid']; ?>"><?php echo $row['catname']; ?></option>
                                     <?php } ?>
                                     </select>
                                 </div>
                                 <div class="col-md-12 col-lg-12">

<br>
<input class="inp-box" id="itmname" autocomplete="off"  type="text" placeholder="Enter Product Name" style="padding: 2px; width: 500px; margin-bottom: 10px; margin-top: 10px;"></input>
<br>
<input class="inp-box" id="prate" autocomplete="off"  type="text" placeholder="Purchase Rate" style="padding: 2px; width: 150px; margin-bottom: 10px; margin-top: 10px;"></input>
<input class="inp-box" id="srate" autocomplete="off"  type="text" placeholder="Sale Rate" style="padding: 2px; width: 150px; margin-bottom: 10px; margin-top: 10px;"></input>
<input class="inp-box" id="ministock" autocomplete="off"  type="text" placeholder="Min. Stock" style="padding: 2px; width: 150px; margin-bottom: 10px; margin-top: 10px;"></input>
                   
                                   
                                        <br>
                                     <button id="svbtn" class="btn btn-sm btn-primary">Save Record</button>

                </div>
                </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> List of Products</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>ID</th>
        <th>Product Title</th>
        <th>P_Rate</th>
        <th>S_Rate</th>
        <th>Category</th>
        <th>Actions</th> 
    </tr>
    </thead>
    <tbody>

                      <?php
                    require 'connection.php'; 
         $qry = "SELECT itemid,itemname,rate,srate,catname FROM itemreg inner join category on itemreg.catid=category.catid order by itemid ASC";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
                                     
           <tr>
        <td class="center"><?php echo $row['itemid']; ?></td>
        <td class="center"><?php echo $row['itemname']; ?></td>
        <td class="center"><?php echo $row['rate'];?></td>
        <td class="center"><?php echo $row['srate']; ?></td>
        <td class="center"><?php echo $row['catname']; ?></td>

  
        <td class="center">
            <a class="btn btn-sm btn-info" href="#">
                <i class="glyphicon glyphicon-edit icon-white"></i>
                Edit
            </a>
        </td>
    </tr>

                                     <?php } ?>


         </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>
$(document).ready(function(){

    $("#svbtn").click(function(){

      var itmname = $('#itmname').val();
      var prate = $('#prate').val();
      var srate = $('#srate').val();
      var ministock = $('#ministock').val();
      var catid = $('#catid').val();
      $('#svbtn').hide();
      event.preventDefault();
 
            $.ajax({
        url: 'aditm.php',
        method: 'POST',
       data: {itmname: itmname, prate: prate, srate: srate, ministock: ministock, catid: catid},
        success: function(data){
            // $('#prate').val(data);
            alert(data);
      $('#svbtn').show();

        }
      })

    });


});
</script>


<?php } ?>

