<?php include('header.php'); ?>
<?php include('session.php'); ?>
<?php $get_id = $_GET['id']; ?>
    <body>
		<?php include('navbar.php'); ?>
        <div class="container-fluid">
            <div class="row-fluid">
				<?php include('Device_sidebar.php'); ?>
		
						<div class="span9" id="content">
		                    <div class="row-fluid">
									<a href="toner_stock.php" class="btn btn-info"  id="add" data-placement="right" title="Click to Toner Stock" ><i class="icon-plus-sign icon-large"></i> Toner Stock</a>
					                <script type="text/javascript">
		                             $(document).ready(function(){
		                             $('#add').tooltip('show');
		                             $('#add').tooltip('hide');
		                              });
		                            </script> 
		                        <!-- block -->
		                        <div id="" class="block">
		                            <div class="navbar navbar-inner block-header">
		                                <div class="muted pull-left">Edit Device</div>
										<div class="muted pull-right"><a id="return" data-placement="left" title="Click to Return" href="device_stocks.php"><i class="icon-arrow-left icon-large"></i> Back</a></div>
																<script type="text/javascript">
																$(document).ready(function(){
																	$('#return').tooltip('show');
																	$('#return').tooltip('hide');
																});
																</script>     
		                            </div>
		                            <div class="block-content collapse in">									
									
									<?php
									$query = mysqli_query($con,"select * from cis_toner_instock 
									LEFT JOIN stlocation ON stlocation.stdev_id=cis_toner_instock.loc_id
									where cis_toner_instock.toner_id = '$get_id'");
									$row = mysqli_fetch_array($query);
									$total=$row['quantity'];
									//echo $total;
									?>
									
									    <form class="form-horizontal" method="post">
										<div class="control-group">
											<label class="control-label" for="inputEmail">Location</label>
											<div class="controls">	<input name="loc_id"  value="<?php echo $row['stdev_location_name']; ?>"  readonly="">		
												
											</div>
										</div>
										
										<div class="control-group">
											<label class="control-label" for="inputEmail">Staff Name</label>
											<div class="controls">	<input name="staff_name"  >		
												
											</div>
										</div>
										<div class="control-group">
											<label class="control-label" for="inputEmail">Designation</label>
											<div class="controls">			
												<select id="qtype"  name="designation" required>
													<option>Please Select</option>
													<?php
													$d_q = mysqli_query($con,"select * from config_designation");
													while($q = mysqli_fetch_array($d_q)){
													$s = $q['DESIGNATION'];
													?>
													<option value="<?php echo $q['DESIGNATION']; ?>"><?php echo $q['DESIGNATION'];  ?></option>
													<?php } ?>

												</select>
											</div>
										</div>
										<div class="control-group">
											<label class="control-label" for="inputEmail">Department</label>
											<div class="controls">			
												<select id="qtype"  name="department" required>
												<option>Please Select</option>
													<?php
													$d_q = mysqli_query($con,"select * from config_department");
													while($q = mysqli_fetch_array($d_q)){
													$s = $q['DEPARTMENT'];
													?>
													<option value="<?php echo $q['DEPARTMENT']; ?>"><?php echo $q['DEPARTMENT'];  ?></option>
													<?php } ?>

												</select>
											</div>
										</div>
										<div class="control-group">
											<label class="control-label" for="inputEmail">Toner Model</label>
											<div class="controls">			
												<select id="qtype" name="toner_model" required>

													<option value="<?php echo $row['toner_model']; ?>" ><?php echo $row['toner_model']; ?></option>
													<?php
													$color_q = mysqli_query($con,"select * from toner_model");
													while($q = mysqli_fetch_array($color_q)){
													$s = $q['model'];
													?>
													<option value="<?php echo $q['model']; ?>"><?php echo $q['model'];  ?></option>
													<?php } ?>

												</select>
											</div>
										</div>
										<div class="control-group">
											<label class="control-label" for="inputEmail">Color</label>
											<div class="controls">			
												<select id="qtype"  name="color" required>

													<option value="<?php echo $row['color']; ?>" ><?php echo $row['color']; ?></option>
													<?php
													$color_q = mysqli_query($con,"select * from toner_color");
													while($q = mysqli_fetch_array($color_q)){
													$s = $q['color'];
													?>
													<option value="<?php echo $q['color']; ?>"><?php echo $q['color'];  ?></option>
													<?php } ?>

												</select>
											</div>
										</div>
										 <div class="control-group">
											<label class="control-label" for="inputPassword">Description</label>
											<div class="controls">
													<textarea name="toner_description" >
													<?php echo $row['toner_description']; ?>
													</textarea>
											</div>
										</div>
										 <div class="control-group">
											<label class="control-label" for="inputPassword">Total</label>
											<div class="controls">
													<input name="total" value="<?php echo $total;?>"  readonly="">
													
													</input>
											</div>
									
										</div>
										<div class="control-group">
											<label class="control-label" for="inputPassword">Loan Quantity</label>
											<div class="controls">
													<input  class="span8" name="loan_quantity" ></input>
											</div>
										</div>
										
													<input type="hidden" name="current_bal" ></input>
											
											 <?php 
												 $id=$_SESSION['id'];
												 $admin=mysqli_query($con,"select * from admin WHERE admin_id='$id'");
			                                     while ($row=mysqli_fetch_array($admin)){ 
												 $username=$row['username'];	
																
												 ?>
												 
												 <div class="control-group">
											<label class="control-label" for="inputPassword">Person In Charge (PIC)</label>
											<div class="controls">
													<input  readonly="" class="span8" name="pic" value="<?php echo $username;?>">
													
													</input>
											</div>
									
										</div>
				                                 <?php } ?>
										 
										<div class="control-group">
										<div class="controls">
										
										<button id="update" data-placement="right" title="Click to update" name="update" type="submit" class="btn btn-info"><i class="icon-save icon-large"></i> Update</button>
										</div>
										</div>
										<script type="text/javascript">
										$(document).ready(function(){
										$('#update').tooltip('show');
										$('#update').tooltip('hide');
										});
										</script> 
										</form>
										
										<?php				
										if (isset($_POST['update'])){
										$toner_id = $get_id;
									    $staff_name = $_POST['staff_name'];
										$designation = $_POST['designation'];
										$department = $_POST['department'];
										$toner_model = $_POST['toner_model'];
										$color = $_POST['color'];
										$total = $_POST['total'];
										$loan_quantity = $_POST['loan_quantity'];
										//$current_bal = $_POST['current_bal'];
										$pic = $_POST['pic'];
								
										
										$current_bal=$total-$loan_quantity;
									
										
										
										mysqli_query($con,"insert into  cis_toner_loan (toner_id,staff_name,designation,department,toner_model,color,total,loan_quantity,current_bal,pic)   
										             values('$toner_id','$staff_name','$designation','$department','$toner_model','$color','$total','$loan_quantity','$current_bal','$pic')");
													 
										mysqli_query($con,"insert into  cis_toner_loan_history (toner_id,staff_name,designation,department,toner_model,color,total,loan_quantity,current_bal,pic)   
										              values('$toner_id','$staff_name','$designation','$department','$toner_model','$color','$total','$loan_quantity','$current_bal','$pic')");
													  
										mysqli_query("update cis_toner_instock set quantity = '$current_bal' where toner_id = '$get_id' ");
																						
									    mysqli_query("insert into activity_log (date,username,action) values(NOW(),'$admin_username','Edit Toner info $toner_model')");
										?>
										<script>										
										window.location = "toner_stock.php";
										$.jGrowl("Device Successfully Update", { header: 'Toner update' });
										</script>
										<?php
										}
										
										
										?>
									
								
		                            </div>
		                        </div>
		                        <!-- /block -->
		                    </div>
		                </div>
            </div>
<script>
	jQuery(document).ready(function(){
		jQuery("#opt11").hide();
		jQuery("#opt12").hide();
		jQuery("#opt13").hide();		

		jQuery("#qtype").change(function(){	
			var x = jQuery(this).val();			
			if(x == '1') {
				jQuery("#opt11").show();
				jQuery("#opt12").hide();
				jQuery("#opt13").hide();
			} else if(x == '2') {
				jQuery("#opt11").hide();
				jQuery("#opt12").show();
				jQuery("#opt13").hide();
			}
		});
		
	});
</script>
		<?php include('footer.php'); ?>
        </div>
		<?php include('script.php'); ?>
    </body>

</html>