<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); 

$pageName = basename($_SERVER['PHP_SELF']);

 $m->where("page_name", $pageName);
 $pageNameAccess=$m->get("eduportal_modules_pages_detail");


$m->where("user_id", $_SESSION['user_id']);
$m->where ("branch_id", $_SESSION['branch']);
$m->where("page_id", $pageNameAccess[0]['page_id']);
$access = $m->get("users_privilege_detail");

?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Add Inventory | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
  
<script type="text/javascript">

function getSubCat(id){
  //alert(id);

    if (window.XMLHttpRequest) {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    } else { // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {

        document.getElementById("subcatgory").innerHTML=xmlhttp.responseText;
       //alert(xmlhttp.responseText);

      }

    }
    xmlhttp.open("GET","get_exp_subcategory.php?id="+id,true);
    xmlhttp.send();
  }
</script> 
  </head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

  <style>
#snackbar {
  visibility: hidden;
  min-width: 250px;
  margin-left: -125px;
  background-color: #1E90FF;
  color: #fff;
  text-align: right;
  border-radius: 2px;
  padding: 16px;
  position: fixed;
  z-index: 1;
  left: 80%;
  bottom: 30px;
  font-size: 17px;
}

#snackbar.show {
  visibility: visible;
  -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
  animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

@-webkit-keyframes fadein {
  from {bottom: 0; opacity: 0;} 
  to {bottom: 30px; opacity: 1;}
}

@keyframes fadein {
  from {bottom: 0; opacity: 0;}
  to {bottom: 30px; opacity: 1;}
}

@-webkit-keyframes fadeout {
  from {bottom: 30px; opacity: 1;} 
  to {bottom: 0; opacity: 0;}
}

@keyframes fadeout {
  from {bottom: 30px; opacity: 1;}
  to {bottom: 0; opacity: 0;}
}
</style>
  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main">

            <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
            Manage Inventory
          <br><br>

          <div class="row" style="background-color: white;">
           
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
   
      

                                    <!-- page content -->
        
    <div class="">
    
      <h3 style="margin-left: 15px;">Add New Inventory/Assets</h3>
            <div class="row">
          
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
            
                  <div class="x_content">
          
     
                    <form action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data" class="form-horizontal form-label-left" >
  <?php
  
  $month;
   if(!isset($_GET['invup'])){?>
        <input type="hidden" name="action" value="add_inventory" />

  <?php $month=date("m");}else {

          $query="select * from eduportal_inventory_system where inventory_id =".$_GET['invup'];
          $invdata = $m->query($query);

          $month=$invdata[0]['month_id'];
?>
              <input type="hidden" name="action" value="update_inventory" />
              <input type="hidden" name="inventory_id"  value="<?php echo $_GET['invup'];?>">

  <?php } ?>        
          
          

            <div class="item form-group">
                        
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Item Name <span class="required"></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                         
                           <input class="form-control col-md-7 col-xs-12"  name="inventory_name" placeholder="eg Table " value="<?php echo $invdata[0]['inventory_name']; ?>">
                        </div>
            </div>

                   
             <div class="item form-group">
                        
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Number of Quantity <span class="required"></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                         
                           <input class="form-control col-md-7 col-xs-12"  name="quantity_number" placeholder="eg 9 " value="<?php echo $invdata[0]['quantity_number']; ?>">
                        </div>
            </div>

                   

           <div class="item form-group">
                        
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Details <span class="required"></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                         
                           <input class="form-control col-md-7 col-xs-12"  name="inventory_details" placeholder="eg Repairing & Fixes " value="<?php echo $invdata[0]['inventory_details']; ?>">
                        </div>
            </div>

           <?php

 
      if($invdata[0]['purchase_date']!="" && $invdata[0]['purchase_date']!=NULL ) {
        $dates=date("Y-m-d",strtotime($invdata[0]['purchase_date']));  

      }else {
        $dates=date("Y-m-d");  
      }
   
                  
                  ?>

                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email"> Purchase Date <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12 ">
                          <input type="date" id="owner_email" name="purchase_date" required class="form-control col-md-7 col-xs-12" value="<?php echo $dates; ?>">
                      
                    </div>
            
                      </div>


                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">Month <span class="required">*</span> 
                        </label>
                        
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select name="month_id" class="form-control" required>
                                <option>Select</option>

                  <?php
                  $query="select * from  eduportal_month_config";
                  $categories = $m->query($query);
                  foreach($categories as $category)
                  { ?>

                         <option <?php if($month==$category['Month_Id']){echo "selected";} ?>  value="<?php echo $category['Month_Id']; ?>"><?php echo $category['Month_Name']; ?></option>


                  <?php } ?>

                            </select>
                        </div>

                      </div>

                     
                      
                    <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Item Amount  <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input class="form-control col-md-7 col-xs-12" name="inventory_amount" required autocomplete="off" type="text" value="<?php echo $invdata[0]['inventory_amount']; ?>">
                        </div>
                      </div>

                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Annual Depreciation  <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input class="form-control col-md-7 col-xs-12" name="annual_depreciation" required autocomplete="off" type="text" value="<?php echo $invdata[0]['annual_depreciation']; ?>">
                        </div>
                      </div>


                      <div class="ln_solid" style="border-top:none;"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          
                          <button id="send" type="submit" class="btn btn-primary" >Submit</button>
                          <button type="submit" class="btn btn-primary" >Cancel</button>

                        </div>
                      </div>

                    </form>
              
          </div>
                </div>
              </div>
            </div>
          </div>
       
        

        <!-- /page content -->



  </div>
  <div class="clearfix"></div>
</section>           

<?php

$branch=$_SESSION['branch']; 

$sql = "SELECT * FROM eduportal_inventory_system as b where b.branch_id='$branch' order by inventory_id desc ";


// echo $sql;

$categories = $m->query($sql);
 //print_r($categories);
 
     ?>




     <div class="t col-md-12 col-sm-12 col-xs-12">
                <h3>Inventory List<small> (<?php echo count($categories);?> records)</small></h3>
     </div>
                  
              
               <div class="col-md-3 " style="float: right;">
                <div class="form-group ">
                <a href="print_inventory_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>" target="_blank" class=" btn btn-primary" style="margin-top: -64px;"> Print Report </a>
                </div>
              </div> 
                   

          
          

<table id="datatable" class="table table-striped table-bordered"style="background-color: white;">
                      <thead>
                        <tr>
                          <th width="1%">S.No</th>
                           <th width="10%">Item Name</th>
                          <th width="10%">Quantity</th>
                          <th width="20%">Details</th>
                          <th width="10%">Date</th>
                          <th width="10%">Month</th>
                          <th width="8%">Amount</th>
                          <th width="10%">Depriciation</th>
                          <th width="8%">Action</th>
                         

                        </tr>
                      </thead>
                      <tbody>

                        
<?php  $count=1;
$date= date("Y-m-d");

foreach($categories as $category){

  $m->where("category_id", $category['category_id']);
  $ctgry=$m->get("eduportal_expanse_category");

  $m->where("subcategory_id", $category['subcategory_id']);
  $sbctgry=$m->get("eduportal_expanse_subcategory");

  $m->where("Month_Id", $category['month_id']);
  $months=$m->get("eduportal_month_config");


?>
                        <tr>
                          <td style="text-align:center;"><?php echo $count; $count++;?></td>
                         

                          <td><?php echo $category['inventory_name'];?></td>
                          <td><?php echo $category['quantity_number'];?></td>
                          <td><?php echo $category['inventory_details'];?></td>
                          <td><?php echo $category['purchase_date'];?></td>
                          <td><?php echo $months[0]['Month_Name'];?></td>
                          <td><?php echo $category['inventory_amount'];?></td>
                          <td><?php echo $category['annual_depreciation'];?></td> 
                                                  

                          <td>
          <?php if ($access[0]['edit_access']!=NULL) { ?>

          <a style="padding: 0px 5px; font-size:14px;"  href="inventory.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&invup=<?php echo $category['inventory_id'];?>" style="cursor:pointer;"  class="btn btn-success"> <i class="fa fa-pencil" aria-hidden="true"></i></a> 

          <?php } ?>


          <?php if ($access[0]['delete_access']!=NULL) { ?>

        <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?inventory_id=<?php echo $category['inventory_id'];?>&action=DeleteInventory" style="padding: 0px 5px; font-size:14px;" onClick="return confirm('Are you sure you want to delete this record');"  class="btn btn-danger"><i class="fa fa-remove"></i> </a>

         <?php } ?>
                          </td>

                        </tr>
<?php } ?>
                      

                      </tbody>
                    </table>
           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

    
  <?php include('RootMe/js_linksscript.php');?>
  </body>
</html>
<script>
function toastFunction() {
  var x = document.getElementById("snackbar");
  x.className = "show";
  setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}
</script>