
<?php
session_start();
error_reporting(0);
@ini_set('display_errors', 0);
$id_user=$_SESSION['id'];
$branch=$_SESSION['branch_id'];
$business=$_SESSION['business_id'];
?>
<!DOCTYPE html>
<html>
    <script type="text/javascript">
    function FormatCurrency(ctrl) {
                  //Check if arrow keys are pressed - we want to allow navigation around textbox using arrow keys
                  if (event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40) {
                      return;
                  }

                  var val = ctrl.value;

                  val = val.replace(/,/g, "")
                  ctrl.value = "";
                  val += '';
                  x = val.split('.');
                  x1 = x[0];
                  x2 = x.length > 1 ? '.' + x[1] : '';

                  var rgx = /(\d+)(\d{3})/;

                  while (rgx.test(x1)) {
                      x1 = x1.replace(rgx, '$1' + ',' + '$2');
                  }

                  ctrl.value = x1 + x2;
              }

              function CheckNumeric() {
                  return event.keyCode >= 48 && event.keyCode <= 57 || event.keyCode == 46;
              }
</script>
<?php
    include("../includes/header-links.php");
    
$permissions = mysqli_fetch_array(mysqli_query($con,"SELECT * FROM  
  permissions,users WHERE  permissions.role_id = users.role 
  AND users.id='$id_user' AND users.business_id ='$business' AND users.branch_id ='$branch'"));

if($permissions['nav_products'] != 1){
?>
<script>window.location="../main/dashboard.php"</script>
<?php
}
?>
    
    <head>

    
    <link rel="stylesheet" href="../data-table-css/bootstrap-table.css">
    <link rel="stylesheet" href="../data-table-css/bootstrap-editable.css">
        
    </head>
    
    <body>
        <?php include '../includes/header.php'; ?>
        
        <div class="container-fluid">
    
            <div class="row-fluid">
                <?php include '../includes/sidebar.php'; ?>
                <!--/span-->
                <div class="span10" id="content">
          

                     <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
            
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left"> Consumables Usage</div>
                            </div>
                            <div class="block-content collapse in">
              
                                <div class="span12">
<div class="row">
  <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">

  </div>
  <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
  </div>     
</div>
                                   
        
                                    
                            

                
                                   <?php 
                                   //if($_SESSION['role']=="admin"|| $_SESSION['role']=="Super Admin"){
                                   if( $permissions['add_product'] == 1){
                                    ?>
                                            
                                      </div>
                                          <div class="btn-group">
                                         <a href="consumables.php"class="btn btn-primary"><i class="icon-briefcase icon-white"></i>&nbsp;consumables</a>
                                      </div>
                                      
                                      
                                     

                                    <?php
                                   }
                                   ?>
                                      

                                      
                                   
                                   <?php
include '../includes/connection.php';
       // if($_SESSION['role']=="Super Admin"){

                  
             $sql = mysqli_query($con,"SELECT *,(SELECT name from consumable_items where id=consumable_usage.item_id) as item FROM consumable_usage where  branch_id='$branch'");

              if (mysqli_num_rows($sql) > 0) {
                // output data of each row

                                   ?>
                                    <div class="datatable-dashv1-list custom-datatable-overright">
                                    <div id="toolbar">
                                        
                                    </div>
                                    <table  id="table" data-toggle="table" data-pagination="true" data-search="true" data-show-columns="true" data-show-pagination-switch="true" data-show-refresh="true" data-key-events="true" data-show-toggle="true" data-resizable="true" data-cookie="true"
                                        data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar" data-export-options='{"fileName": "Testing_filename"}'>
                                        <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>Date</th>
                                                <th>Item</th>
                                                <th>Quantity</th>
                                                <th>Given to</th>
                                                <th>Action</th>
                                                
                                             </tr>
                                        </thead>
                                        <tbody>
                                        
                                        <?php
                                        $no=0;
while($row = mysqli_fetch_assoc($sql)) {
   $no++;

        ?>
<tr class="gradeU">
                                                <td><?php echo $no; ?></td>
                                                
                                                <td><?php echo $row['date']; ?></td>
                                                <td><?php echo $row['item']; ?></td>
                                                <td><?php echo $row['quantity']; ?></td>
                                                <td><?php echo $row['given_to']; ?></td>
                                                
                                                
                                                
                                                <td class="center">
                                             
                                                
                                                  
                                                  <a href="#<?php echo $row['id']?>myModal" data-toggle="modal" class="btn btn-primary"><i class="icon-edit icon-white"></i></a>
                                                  <!-- <a href="delete_stockitem.php?id=<?php echo base64_encode($row['id']); ?>"><button class="btn btn-danger"><i class="icon-trash icon-white"></i></button></a> -->
                                                  
                  
                                          
                                                </td>
                                                           <div id="<?php echo $row['id']?>myModal" class="modal hide">
                      <div class="modal-header" style="background-color: #08c; color: white;">
                        <button data-dismiss="modal" class="close" type="button">&times;</button>
                        <h3>Change stock <?php echo $row['item']; ?> </h3>
                      </div>
                      <div class="modal-body" style="max-height: 550px;">
                        <form action="" method="POST" enctype="multipart/form-data"> 
                      <div align="center" id="PcodeMin" class="span12">
                       <div align="center" class="span12">
                         <label>Quantity</label>
                        
                        <input  name="quantity" class="form-control" value="<?php echo $row['quantity']; ?>" style="width: 95%;">
                      </div>

                      
                      </div>
                      <div align="center" id="description" class="span12">
                       
                     
                      
                      
                        <div class="form-actions">
                                          <button type="submit" name="updatestockitem" class="btn btn-primary">Save changes</button>
                                          <a href="" data-dismiss="modal" class="btn btn-danger">Cancel</a>
                                        </div> 
                                        </div> 
                        </form>
                      </div>
                      </div>
                                                
                                            </tr>
                                            
                                            <?php


    }
} else {
    echo "No Items added yet!";
}

mysqli_close($con);

 ?>
                                            
                                        </tbody>
                                    </table>
                                  </div>
                                    
                                </div>
                            </div>
                        </div>
                        <!-- /block -->
                    </div>
                </div>
            </div>
            <hr>
            <?php include '../includes/footer.php'; ?>
        </div>
        <!--/.fluid-container-->

        <!--==========Footer js======-->
    <?php require_once("../includes/footerjs.php");?>
        <!--==========Footer js======-->
       
 



<script src="../data-table-js/bootstrap-table.js"></script>
    <script src="../data-table-js/tableExport.js"></script>
    <script src="../data-table-js/data-table-active.js"></script>
    <script src="../data-table-js/bootstrap-table-editable.js"></script>
    <script src="../data-table-js/bootstrap-editable.js"></script>
    <script src="../data-table-js/bootstrap-table-resizable.js"></script>
    <script src="../data-table-js/colResizable-1.5.source.js"></script>
    <script src="../data-table-js/bootstrap-table-export.js"></script>
    </body>
</html>
