
<?php include("conn.php");
$page='Inventory Items';
$location_page='item';?>
<!DOCTYPE html>
<html lang="en">
<?php include("common/head.php");
if ($inventory=='none') {
  echo"<script>alert('You are not allow to access this page, contact your admintrator'); window.location.href='login'</script>";
}
?>
<style>
    #panel {
  display: none;
}
#panel1 {
  display: none;
}
</style>
<body>
<?php include("common/menu.php")?>
<!---side nav bar end-->
<?php include("common/tittle.php")?>

          

            <!--Main body Start-->
            <div class="col-sm-12 mt-2">
            
               <!--search section start-->


               <center>

               <?php include('inventory_button.php')?>
              
              </center>            
      <hr class="bg-success">
                <!--search section end-->
                <!--Orders start-->
                
            <?php 
            $today= date("F j, Y ,h:ia");
            $order_id='T'.date('ymdhi').mt_rand(10,100);
            
    

      
            ?>
                <div style=" font-family: 'Convergence'!important;" id="myList" class="menu-analytics row no-gutters">
                    <div class="daily-report ">
                       <!--- <div class="daily-report-item
                    ">
                                    <b><i class="fa fa-money" aria-hidden="true"></i></b>
                                    <p class="text-center order-text-order-managment"><b>Revenue</b></p>
                                    <p class="text-center order-text-order-managment"><b></b></p>
                        </div> --->

                  
                    </div>


                    <div  id="collapseOne" class="  col-sm-12  " data-parent="#accordions">
                    <h5 class="text-center">All Items added to stock</h5>
                    
                    <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target=".bd-example-modal-lg">Add Receipt</button>

                    <table id="example_table" class="table-customer table-striped   w-100 table-bordered">
                        <thead>
                        <tr>
                        <th>id</th>
                            <th>Item Name</th>
                            <th>Quantity Unit</th>
                            <th>Total Quantity</th>
                            <th>Per Unit Price</th>
                            <th>Total Price</th>
                            <th>Supplier</th>
                            <th>Supplier Contact</th>
                            <th>Date Uploaded</th>
                            <th>Action</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php


$sql7="select * from inventory  order by id desc ";
$result7 = mysqli_query($conn,$sql7)or die( mysqli_error($conn));
while ($row7=mysqli_fetch_array($result7)) {

  $data=$row7['receipt_id'];
  $item_name=$row7['item_name'];
  $unit=$row7['unit'];
  $unit_value=$row7['unit_value'];
  $price=$row7['price'];
  $quantity=$row7['quantity'];
  $datein=$row7['datein'];



  $sql="select * from receipt where receipt_id=$data";
 $result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
$row=mysqli_fetch_array($result);
$supply=$row['company'];
$contact=$row['company_contact'];
$by=$row['by'];
  if (empty($unit_value)) {
    $unit_text='Individual Items';
   }
   else {
    $unit_text= $unit_value." ".$unit;
   }
   
   $status=0;

 $text='';

 if ($unit=='pcs'){
  $total_price=$price;
 }
 else {
  $total_price=$price*$unit_value;
 }
 
 if ($status==='1') {
   $text='In stock';
   $read='btn-success';
   $de='deactivate';
   $sta=0;
 }
                            else {
   $text='Out of stock';
   $read='btn-danger';
  $de='activate';
  $sta=1;
 }


 $sql2="SELECT * FROM currency ";
 $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
 $row2=mysqli_fetch_array($result2) ;
$currency=$row2['curency'];
$action="inventory_receipt_details?re=$data";
?>
                          <tr>
                            <td><?php echo $data ?></td>
                            <td><?php echo $item_name ?></td>
                            <td><?php echo $unit_text ?></td>
                            <td><?php echo $quantity ?>pcs</td>   
                            <td><?php echo  $currency ?><?php echo number_format($price,2) ?></td>
                            <td><?php echo  $currency ?><?php echo number_format($total_price,2) ?> </td>   
                            <td><?php echo  $supply ?></td>  
                            <td><?php echo  $contact ?></td>                     
                            <td><?php echo  $datein ?></td>
                            <td>
                            <a href="inventory_receipt_details?re=<?php echo $data?>&l=inventory_item" class="btn btn-sm btn-primary"> Details</a>
                        </td>
                        
                        </tr>
                        <?php } ?>
                        </tbody>
                        <thead>
                        <th>id</th>
                            <th>Item Name</th>
                            <th>Quantity Unit</th>
                            <th>Total Quantity</th>
                            <th>Per Unit Price</th>
                            <th>Total Price</th>
                            <th>Supplier</th>
                            <th>Supplier Contact</th>
                            <th>Date Uploaded</th>
                            <th>Action</th>
                        </thead>
                    </table>

                </div>

                    <!-- <div id="chart_div" style="width: 100%; height: 500px;"></div>--->
        
                </div>

         
              
            </div>
            <!--Main body end-->

           


            <div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <h4  class="m-4">Add Reciept</h4>
      <?php
      $sql8="select * from receipt order by id desc ";
      $result8 = mysqli_query($conn,$sql8)or die( mysqli_error($conn));
      $row8=mysqli_fetch_array($result8);
     
        $id=$row8['id'];
    
      

      $id_cal=$id+1;
      $id_new = sprintf('%03d',$id_cal);
      ?>
    <form  method="post" action="inventorys/receipt_submit.php" enctype="multipart/form-data" class="m-4" >
    <span class="text-primary" for="recipient-name" class="col-form-label">Write This Id: <span class="text-white p-2 bg-primary"><?php echo $id_new ?></span> on the receipt, take a picture and Upload!!!</span>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Supplier Name</label>
            <input type="text" class="form-control" name="supplier" id="recipient-name">
          </div>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Supplier Contact </label>
            <input type="number" class="form-control" name="contact" id="recipient-name">
          </div>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Receipt Date </label>
            <input type="date" class="form-control" name="receipt_date" >
          </div>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Total Purchase </label>
            <input type="number" class="form-control" name="total" id="recipient-name">
          </div>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Image</label>
            <input type="file" class="form-control" name="image" id="recipient-name">
          </div>
          <div class="form-group">
            <label for="message-text" class="col-form-label">Additional information:</label>
            <textarea class="form-control" name="info" id="message-text"></textarea>
          </div>
          <input type="hidden" name="receipt_id" value="<?php echo $id_new ?>">
          <input type="hidden" name="datein" value="<?php echo $today ?>">
                <input type="hidden" name="by" value="<?php echo $id_user ?>">
                <button class="btn btn-success btn-sm btn-block"  name="submit">Submit</button>
        </form>
    </div>
  </div>
</div>
             <!-- Modal Add items -->
             <div  class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content ">
        <div class="modal-header">
          <h5 class="modal-title text-center text-dark" id="exampleModalLabel">Add Item</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">


<form method="post" action="inventorys/iventory_submit.php" class="row">
<div id="panel" class="form-group col-sm-6 mb-3">
                 <input type="text" class="form-control" name="item_names" id="exampleFormControlInput1" placeholder="Item name" >
               </div>

               <div id="panel1" class="form-group col-sm-6 mb-3">
                 <input type="text" class="form-control" name="units" id="exampleFormControlInput1" placeholder="unit"  >
               </div>

            <div  id="select_item" class="input-group col-sm-6 mb-3 ">
        <div class="input-group-prepend">
          <a onclick="myFunction()" class=" btn  btn-primary" >+</a>
        </div>
        <?php 
    $query ="SELECT item_name,item_id FROM inventory_cat ";
    $result = $conn->query($query);
    if($result->num_rows> 0){
      $options= mysqli_fetch_all($result, MYSQLI_ASSOC);
    }
?>
                  <select class="form-control" name="item_name">
                  <option value="nan">Select Item</option>
                  <?php 
  foreach ($options as $option) {
  ?>
    <option value="<?php echo $option['item_id']; ?>"><?php echo $option['item_name']; ?> </option>
    <?php 
    }
   ?>
                  </select>
      </div>



      <div id="select_item1" class="input-group col-sm-6 mb-3">
                <div class="input-group-prepend">
          <a  onclick="myFunctions()" class=" btn  btn-primary" >+</a>
        </div>
        <?php 
    $query1 ="SELECT unit FROM inventory_unit ";
    $result1 = $conn->query($query1);
    if($result1->num_rows> 0){
      $optionse= mysqli_fetch_all($result1, MYSQLI_ASSOC);
    }
?>
                  <select class="form-control" name="unit" id="exampleFormControlSelect1">
                  <option value="nan">Select Unit</option>
                  <?php 
  foreach ($optionse as $option1) {
  ?>
    <option><?php echo $option1['unit']; ?> </option>
    <?php 
    }
   ?>
                  </select>
      </div>
      <div class="form-group col-sm-4 mb-3">
                 
                 <input type="number" class="form-control" name="unit_value" id="exampleFormControlInput1" placeholder="Unit Value"  >
               </div>
                <div class="form-group col-sm-4 mb-3">
                 
                  <input type="number" class="form-control" name="quantity" id="exampleFormControlInput1" placeholder="Quantity" required>
                </div>
                <div class="form-group col-sm-4 mb-3">
                 
                 <input type="number" class="form-control" name="price" id="exampleFormControlInput1" placeholder=" Price per Unit" required>
               </div>
                <div class="form-group  col-sm-6 mb-3">
                  <input type="text" class="form-control" name="supply" id="exampleFormControlInput1" placeholder=" Supplier"   required >
                </div>

                <div class="form-group  col-sm-6 mb-3">
                  <input type="number" class="form-control" name="supply_contact" id="exampleFormControlInput1" placeholder=" Supplier contact"  required >
                </div>
                <div class="form-group  col-sm-6 mb-3">
                  <input type="text" class="form-control" name="brand" id="exampleFormControlInput1" placeholder=" Brand" >
                </div>

                <div class="form-group  col-sm-6 mb-3">
                  <input type="text" class="form-control" name="receipt_id" id="exampleFormControlInput1" placeholder=" Receipt Id" required >
                </div>

                <div class="form-group  col-sm-6 mb-3">
                <select class="form-control" name="location" id="exampleFormControlSelect1">
                  <option value="nan">Select Location</option>
                  <option value="bar">Bar</option>
                  <option value="Restaurant">Restaurant</option>
                  <option value="House Keeping">House Keeping</option>
                </select>
                </div>
                <input type="hidden" name="datein" value="<?php echo $today ?>">
                <input type="hidden" name="by" value="<?php echo $id_user ?>">
                <input type="hidden" name="item_id_new" value="<?php echo $order_id ?>">
                
                  <button class="btn btn-success btn-sm btn-block"  name="submit">Submit</button>
</form>



        </div>
        <div class="modal-footer">
        </div>
      </div>
    </div>
  </div>
c
               <!--modal delete-->
<!-- Large modal -->
<div id="dataModal1" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div  id="employee_detail1" class="modal-content text-dark">
      
     
    
    </div>
  </div>
</div>
  


          
            <!--Invoice Section end-->



     <!--  isotope plugin cdn  -->
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.6/isotope.pkgd.min.js" integrity="sha256-CBrpuqrMhXwcLLUd5tvQ4euBHCdh7wGlDfNz8vbu/iI=" crossorigin="anonymous"></script>
    <script src="js/script.js"></script>
    <!--  isotope plugin cdn  -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.6/isotope.pkgd.min.js" integrity="sha256-CBrpuqrMhXwcLLUd5tvQ4euBHCdh7wGlDfNz8vbu/iI=" crossorigin="anonymous"></script>
    <script src="js/script.js"></script>
     <!-- jQuery js-->
   <!-- jQuery Datatable js -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" ></script>
     <script src="https://cdn.datatables.net/2.0.5/js/dataTables.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/dataTables.buttons.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.html5.min.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.print.min.js"></script>

     <script>
      $(document).ready( function () {
        new DataTable('#example_table', {
            order:[[2,"asc"]],
            autoFill: true,
            pageLength : 10,
    lengthMenu: [[5, 10, 20, -1], [5, 10, 20, 'Todos']],
    layout: {
        topStart: {
            buttons: ['copy', 'csv', 'excel', 'pdf', 'print']
        }
    }
});
       } );
</script>

<script>
    

    $(document).ready(function(){  
   $('.view_datas').click(function(){  
        var employee_ids = $(this).attr("id");  
        $.ajax({  
             url:"inventory_item_details.php",  
             method:"post",  
             data:{employee_ids:employee_ids},  
             success:function(data){  
                  $('#employee_detail1').html(data);  
                  $('#dataModal1').modal("show");  
             }  
        });  
   });  
});  
</script>
    <!--google graph-->
   
 

    <script>
function myFunction() {
  document.getElementById("panel").style.display = "block";
  document.getElementById("select_item").style.display = "none";
}

function myFunctions() {
  document.getElementById("panel1").style.display = "block";
  document.getElementById("select_item1").style.display = "none";
}
</script>
</body>

</html>