<?php
session_start();
if(!isset ($_SESSION['user_id'])){
	header("Location:../login.php?msg=Log in first");
    exit();
}else{
	
	include('../Server/connection.php');
	include('includes/session.php');
	echo "<div class='div-request div-hide'>editOrd</div>";
    	
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

	
	 <?php
  include 'title.php';
         ?>
	
	
	<link type = "image/png" rel="icon" href="images/brvision.png" />

    <!-- Bootstrap must-->
    <link href="../vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
	
    <!-- Font Awesome must-->
    <link href="../vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
	
	<!-- custom css -->
    <link rel="stylesheet" href="custom/css/custom.css">
	
    <!-- NProgress must-->
    <link href="../vendors/nprogress/nprogress.css" rel="stylesheet">
	
    <!-- Custom Theme Style must-->
    <link href="../build/css/custom.min.css" rel="stylesheet">
	
	<!-- must-->
	<script src="assests/jquery/jquery.min.js"></script>
	
  <!-- jquery ui -->  
  <link rel="stylesheet" href="assests/jquery-ui/jquery-ui.min.css">
  <script src="assests/jquery-ui/jquery-ui.min.js"></script>
	
  <!-- Must Bootstrap -->
    <script src="../vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	
	
	
  </head>

  <body class="nav-md">
  
    <div class="container body">
	
      <div class="main_container">
        <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
		  
             <?php  
		include 'includes/role.php';
               ?>

            <div class="clearfix"></div>
            
			
			<?php
            include 'includes/profile.php';
			print '</br></br>';
			include 'includes/menu.php';
			?>


           

        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
		  
			
			
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
				  
                    <a href="viewQuotations.php">  <h2><span class="glyphicon glyphicon-step-backward"></span> Back</h2></a>
					
					<?php
				$quot_id = $_GET['i'];
				$sql81 = "SELECT * FROM quotation WHERE quot_id = {$quot_id}";
				$result81 = $conn->query($sql81);
				while($data81 = mysqli_fetch_array($result81))
							{
							$client_id = $data81['client_id'];
							$currency_id = $data81['currency_id'];
							$quot_date = $data81['quot_date'];
							$del_date = $data81['del_date'];
							$totalAmount = number_format($data81['total_amount'],2);
							$totalAmount11 = $data81['total_amount'];
							$orderNo = $data81['orderNo'];
				            }		
				      ?>
					
					
					
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                      
                     
                    </ul>
                    <div class="clearfix"></div>
                  </div>
				  
				
				<div class="x_content" style="overflow: auto;">
				
				<?php if (isset($_SESSION['success_message']) && !empty($_SESSION['success_message'])) { ?>
                        <div class="success-message" style="margin-bottom: 20px;font-size: 20px;color: green;"><?php echo $_SESSION['success_message']; ?></div>
                        <?php
                        unset($_SESSION['success_message']);
                    }
                    ?>	
				 
				  <div class="success-messages"></div> <!--/success-messages-->

               <form class="form-horizontal" method="POST" action="php_action/editQuotation.php" enctype="multipart/form-data">
			   
			    <input type="hidden" name="quot_id" value="<?php echo $quot_id; ?>">
				
				
				<div class="controls">
			  <div class="row">
			  
			  <div class="col-sm-3">
			  <div class="form-group">
                 <label for="form_name">Customer Name </label>
                 <select class="form-control" name="client_id" id="client_id" autocomplete="off" required>
			  						<?php
			  							$productSql = "SELECT * FROM clients where client_id='$client_id'";
			  							$productData = $conn->query($productSql);
			  							while($row = $productData->fetch_array()){									 		
			  								echo "<option value='".$row['client_id']."'>".$row['client_fname'].'&nbsp&nbsp'.$row['client_mname'].'&nbsp&nbsp'.$row['client_lname']."</option>";
										 	} // /while 
											
										$productSql7 = "SELECT * FROM clients where client_id!='$client_id'";
			  							$productData7 = $conn->query($productSql7);
			  							while($row7 = $productData7->fetch_array()){									 		
			  								echo "<option value='".$row7['client_id']."'>".$row7['client_fname'].'&nbsp&nbsp'.$row7['client_mname'].'&nbsp&nbsp'.$row7['client_lname']."</option>";
										 	} // /while 

			  						?>
		  						</select>
                      
                </div>
			   </div>
			   
			  
			  
			   <div class="col-sm-3">
			  <div class="form-group">
                 <label for="form_name">Currency Type </label>
				  <select class="form-control" name="currency_id" id="currency_id" autocomplete="off" required />
			  						<?php
			  							$productSql39 = "SELECT * from currency where currency_id='$currency_id'";
			  							$productData39 = $conn->query($productSql39);

			  							while($row39 = $productData39->fetch_array()){									 		
			  								echo "<option value='".$row39['currency_id']."'>".$row39['currencyName']."</option>";
										 	} // /while 
											
											
										$productSql391 = "SELECT * from currency where currency_id!='$currency_id'";
			  							$productData391 = $conn->query($productSql391);

			  							while($row391 = $productData391->fetch_array()){									 		
			  								echo "<option value='".$row391['currency_id']."'>".$row391['currencyName']."</option>";
										 	} // /while 	

			  						?>
		  						</select>
                      
                    </div>
			  </div>
			  
			  <div class="col-sm-3">
			  <div class="form-group">
                 <label for="form_name">Date </label>
                 
				 <input type="text" class="form-control" id="quot_date" name="quot_date" value="<?php echo $quot_date; ?>" autocomplete="off" required />
                      
                </div>
			   </div>
			   
			    <div class="col-sm-3">
			  <div class="form-group">
                 <label for="form_name">Delivery Date </label>
                 
				 <input type="text" class="form-control" id="del_date" name="del_date" value="<?php echo $del_date; ?>" autocomplete="off" required />
                      
                </div>
			   </div>
			   
			   </div>	  
                </div>
				
		
			

              <table class="table" id="productTable">
			  	<thead>
			  		<tr>			  			
			  			<th style="width:5%;">S/N</th>
						<th style="width:20%;">Items Description</th>
						<th style="width:20%;">Unit Of Measure</th>
			  			<th style="width:15%;">Quantity</th>
			  			<th style="width:15%;">Price</th>			  			
			  			<th style="width:20%;">Total</th>			  			
			  			<th style="width:5%;"></th>
			  		</tr>
			  	</thead>
			  	<tbody>
			  		<?php
			  		//$arrayNumber = 0;
					//$no 	= 1;
			  		//for($x = 1; $x < 4; $x++) { 
					
					$invItemSql = "SELECT * FROM quotation_items WHERE quot_id = {$quot_id}";
					$invItemResult = $conn->query($invItemSql);
						// $orderItemData = $orderItemResult->fetch_all();						
						
						// print_r($orderItemData);
			  		$arrayNumber = 0;
			  		// for($x = 1; $x <= count($orderItemData); $x++) {
			  		$x = 1;
			  		while($invItemData = $invItemResult->fetch_array()) { 
					$serv_desc = $invItemData['services_desc'];
					$invItem_id	 = $invItemData['invItem_id'];
					$measure_id	 = $invItemData['measure_id'];
					          ?>
					
			  			<tr id="row<?php echo $x; ?>" class="<?php echo $arrayNumber; ?>">	
						
						   <td style="padding-left:20px;">
			  					<div class="form-group">
								<?php
								print $x;
								?>
			  					</div>
			  				</td>
							
							
							
							
							 <td style="padding-left:20px;">
			  					<div class="form-group">
								<textarea rows="3" cols="50" name="serv_desc[]" id="serv_desc<?php echo $x; ?>"  class="form-control" style="margin-left:0%;" autocomplete="off" required /> <?php echo htmlspecialchars($serv_desc); ?> </textarea>
								
			  					</div>
			  				</td>
							
							<td style="padding-left:20px;">
			  					<div class="form-group">
								
								<select class="form-control" name="measure_id[]" id="measure_id<?php //echo $x; ?>" required />
			  						<?php
			  							$productSql331 = "SELECT * FROM unit_measure where measure_id='$measure_id'";
			  							$productData331 = $conn->query($productSql331);

			  							while($row331 = $productData331->fetch_array()){									 		
			  								echo "<option value='".$row331['measure_id']."'>".$row331['measure_name']."</option>";
										 	} // /while 
											
											
										$productSql3315 = "SELECT * FROM unit_measure where measure_id!='$measure_id'";
			  							$productData3315 = $conn->query($productSql3315);

			  							while($row3315 = $productData3315->fetch_array()){									 		
			  								echo "<option value='".$row3315['measure_id']."'>".$row3315['measure_name']."</option>";
										 	} // /while 	

			  						?>
		  						</select>
								
								
			  					
								
								</div>
			  				</td>	
							
			  			
							
							<!--choosed -->
			  				<td style="padding-left:20px;">
			  					<div class="form-group">
			  					<input type="number" name="quantity[]" id="quantity<?php echo $x; ?>" onkeyup="getTotal(<?php echo $x ?>)" value="<?php echo $invItemData['qty']; ?>" autocomplete="off" class="form-control" min="1" required />
			  					</div>
			  				</td>
							<!--choosed -->
							
							<td style="padding-left:20px;">			  					
			  					<input type="text" name="rate[]" id="rate<?php echo $x; ?>" onkeyup="getTotal(<?php echo $x ?>)" value="<?php echo $invItemData['unit_price']; ?>" autocomplete="off"  class="form-control" required />			  					
			  					<input type="hidden" name="rateValue[]" id="rateValue<?php echo $x; ?>" value="<?php echo $invItemData['unit_price']; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
							
			  				<td style="padding-left:20px;">			  					
			  					<input type="text" name="total[]" id="total<?php echo $x; ?>" value="<?php echo $invItemData['amount']; ?>" autocomplete="off" class="form-control" disabled="true" />			  					
			  					<input type="hidden" name="totalValue[]" id="totalValue<?php echo $x; ?>" value="<?php echo $invItemData['amount']; ?>" autocomplete="off" class="form-control" />			  					
			  				</td>
							
							
			  				<td>

			  					<button class="btn btn-default removeProductRowBtn" type="button" id="removeProductRowBtn" onclick="removeProductRow(<?php echo $x; ?>)"><i class="glyphicon glyphicon-trash"></i></button>
			  				</td>
			  			</tr>
		  			<?php
		  			//$arrayNumber++;
					//$no++;
			  		//} // /for
					$arrayNumber++;
		  			$x++;
			  		} // /for
			  		?>
			  	</tbody>			  	
			  </table>
			  
			  <div class="col-md-6">
			  
			       <div class="form-group">
				    <div class="col-sm-6">
				      <button type="button" class="btn btn-default" onclick="addRow()" id="addRowBtn" data-loading-text="Loading..."> <i class="glyphicon glyphicon-plus-sign"></i> Add Row </button>
				    </div>
				  </div> <!--/form-group-->	
				  
				 </br>
				 
			  	<div class="form-group">
				    <label for="subTotal" class="col-sm-3 control-label">Sub Total</label>
				    <div class="col-sm-9">
				      <input type="text" class="form-control" id="subTotal" name="subTotal" value="<?php echo $totalAmount; ?>" disabled="true" />
				      <input type="hidden" class="form-control" id="subTotalValue" name="subTotalValue" value="<?php echo $totalAmount11; ?>" />
				    </div>
				  </div> <!--/form-group-->	
				  
				    
	  		  
			  </div> <!--/col-md-6-->
			  
			  
			  </br></br></br></br></br>
			  
			 
			
			  <div class="form-group submitButtonFooter">
			    <div class="col-sm-12">
			      <button type="submit" id="createOrderBtn" data-loading-text="Loading..." class="btn btn-success"><i class="glyphicon glyphicon-ok-sign"></i> Save Changes</button>
                  </br></br>
			      <!--<button type="reset" class="btn btn-default" onclick="resetOrderForm()"><i class="glyphicon glyphicon-erase"></i> Reset</button>-->
			    </div>
			  </div>
			  
			  
			</form>                  
				
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->
		
		
		<?php
		include 'includes/footer.php';
		?>
		
        
      </div>
    </div>
	
	<script>
		$("#quot_date").datepicker();
		$("#del_date").datepicker();
	</script>

   <!-- Must -->
    <script src="custom/js/editInvoice.js"></script>
	
    <!-- Must Custom Theme Scripts -->
    <script src="../build/js/custom.min.js"></script>
	
	<!-- file input -->
	<script src="assests/plugins/fileinput/js/plugins/canvas-to-blob.min.js'); ?>" type="text/javascript"></script>	
	<script src="assests/plugins/fileinput/js/plugins/sortable.min.js" type="text/javascript"></script>	
	<script src="assests/plugins/fileinput/js/plugins/purify.min.js" type="text/javascript"></script>
	<script src="assests/plugins/fileinput/js/fileinput.min.js"></script>	


	<!-- DataTables -->
	<script src="assests/plugins/datatables/jquery.dataTables.min.js"></script>

  </body>
</html>



<?php
}
?>