<?php

 //echo $product_name = $_POST['product'];



session_start();

 $txn_id = $_SESSION['edit_record'] ;
//$privilage = $_SESSION['privilage']; 


 $data_base = $_SESSION['database'];


$status = $_SESSION['status'];

$background_color =$_SESSION['bottom_backgroundcolor'];
$text_color =$_SESSION['bottom_textcolor'];



$app_name = $_SESSION['app_name'];
$app_code = $_SESSION['app_code'];
  $db_size = $_SESSION['db_size'];
$biz_name = $_SESSION['biz_name'];
$biz_nature = $_SESSION['biz_nature'];
$privilage = $_SESSION['privilage'];




$current_date = date("Y-m-d");
$activation_d = $_SESSION['activation_date'];
$expiration_d = $_SESSION['expiration_date'];


if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {

	header ("Location: login.php");

}
		
else if($privilage == "Priviledge" or $privilage == "Sales Rep" or $privilage == "Sales Rep" or $privilage == "Receptionist" or $privilage == "Inventory Manager" or $privilage == "Secetary"/*or $privilage == "Manager"*/)
{
	
	header ("Location: not_authorized.php");
	
}




?>


<?php

$error = "";

require 'config.php';


$db_handle = mysqli_connect(DB_SERVER, DB_USER, DB_PASS);

//$database = $_SESSION['database'];
$database = $data_base;


$db_found = mysqli_select_db($db_handle, $database);


//this script is to check if database parameters has alredy been taken
$db_found_db = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );
			
		//$SQL = "DELETE FROM product_table WHERE product_id=$txnid";
   //$query_del = mysqli_query($db_handle, $SQL);



//$_SESSION['edit_record']  = $_GET['txnId'];

 $txn_id = $_SESSION['edit_record'] ;


  
if($db_found){
if(isset($_POST['A']))
{
	
	
	   $c_name =  $_POST['c_name'] ;
		$p_name =$_POST['p_name'] ;
		$p_method = $_POST['p_method'] ;
	
		$sales = $_POST['sales'] ;
		$bal = $_POST['bal'] ;
		$qty = $_POST['qty'] ;
		
	

	
	
	 if( $c_name =="" or $p_name==""  or $p_method=="" or $sales=="" or $bal=="" or $qty =="")
		
			{
					$error = "OPERATION FAILED|| one of the fields is blank";
			}
	
	
	else{
	
		$SQl_update ="UPDATE `txn_table` SET `product_name`='$p_name',`payment`='$p_method',`customers_name`='$c_name',`amount`='$sales',`balance`='$bal',`s_qty`='$qty' WHERE product_id = $txn_id";

		
	
	//	$SQl_update = "UPDATE txn_table SET customers_name = '$c_name' WHERE 370";
	
	mysqli_query($db_found_db,$SQl_update);
	
	 $error =  "operation successfull";
	
		}
			
		
			 
			
				
		
		
	
			
		
			
			
			
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
	

	
	
	
	
	
	
	
}
	  
	  
	// header ("Location: inventory_ac.php");

	 
	  
  
  }
	  
  
else{
	
	$error =  "database not found";

	}

 

?>





	<html>
		
			<title>edit_transaction</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->	
		 <link href="css/bootstrap-4.4.1.css" rel="stylesheet">
		 <link href="css/popup.css" rel="stylesheet">
		
		
		
	<head>



	</head>
		
		<style>
			.loader {
  border: 16px solid #f3f3f3;
  border-radius: 30%;
  border-top: 5px solid blue;
  border-right: 5px solid green;
  border-bottom: 5px solid red;
  border-left: 5px solid yellow;
  width: 40px;
  height: 40px;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 1s linear infinite;
}

		
		
@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

			
			
			div.scroll_history {
                //margin:4px, 4px;
               // padding:4px;
                background-color: #494747;
                width: 100%;
                height: 80%;
                //overflow-x: hidden;
                //overflow-y: auto;
				overflow: auto;
                text-align:justify;
            }
		
			
			
		
		body, html {
background-color: <?php echo $background_color; ?>;
			}
		</style>
		
		
		
	<body onLoad= "spinner(), <?php echo "customAlert.alert('$error','LBS App Builder')"; ?>">



		<div class="jumbotron-fluid" style="background-color: #757672; color: #F0ECEC">
	
				
<?php 
		
	echo $_SESSION['name'].'   '.' (IDN '. $_SESSION['user_id'].' ) ';
			
			

		?>
			<div class="" style="float: right; color: #ED0307;"><a HREF = "logout.php" onClick="spinner()"><span style="color: #F9F833">Log out</span></a></div>
			<!--<button onclick="myFunction()">Click Me</button>-->
			

			
		</div>

				
		<?php 
		
		
		$SQL_recent = "SELECT * FROM txn_table where product_id = $txn_id  ";
	
	$recent_record = mysqli_query($db_handle, $SQL_recent);
	
	$db_found_recent = mysqli_fetch_array($recent_record) ;
		
		
		
		
		?>
		

		<div class="jumbotron" style="text-align: center">
		
		
		
		
		<div class="row">
			
			
					<div class="col-md-6">
			
			
				<table style="margin: auto;width:;background-color: " >
				
		
					<tr>
				<td>
				
		 			<span style="background-color: black; color: white;">  <?php echo $error; ?></span>
			<h3><b> <span style="color: <?php echo $text_color; ?>">MODIFY Record</span> </b></h3>
				
					<form METHOD ="POST" ACTION = "tran_edit_edit.php" style="width: 100%">
				
						
						
						
					
						
						
					
					
						
						
						<table style = "border:2px solid <?php echo $text_color?>" >
				
							<tr>
									<td>  
	
										<div class="input-group mb-3">
											
											
											<input type="hidden" class="form-control" placeholder="eg.Lawped Limited" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $biz_name ?>" name="biz_name">
				
										</div>
										
										<div class="input-group mb-3">
											
										
										
											<input type="hidden" class="form-control" placeholder="eg.Provision Store,Supermarket,Gas station etc" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $biz_nature ?>" name="biz_nature">
				
										</div>
										
										
										
										
					
										<div class="input-group mb-3">
  					
											<div class="input-group-prepend">
    
												<span class="input-group-text" id="basic-addon1">Customers Name</span>
  
												</div>
  
												
												<select class="custom-select"  style="background-color: "    id="sss" onChange="show_cat(), window.alert('Kindly Select Category')" name = "c_name" required  >
										
											<option value="<?php echo $db_found_recent['customers_name'];?>" selected><?php echo $db_found_recent['customers_name'];?></option>
		
											<?php
											
											$SQL = "SELECT  DISTINCT name FROM customers_table ORDER BY id ASC ";
											
											$result = mysqli_query($db_handle, $SQL);
											
											//$i =1;

											
											while ( $db_found = mysqli_fetch_assoc($result) ) {
											
												/*echo'<option value="'. $db_found['product_name'].'">'. $db_found['product_name'].'(Qty'. $db_found['unit_q'].', Amt '. $db_found['unit_p'].')</option>'; */
												
												echo'<option value="'. $db_found['name'].'">'. $db_found['name'].'</option>'; 
																									  }
		
											?>
											
											</select> 
											
											
											

											
										</div>
										
											<div class="input-group mb-3">
											
											
												
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Job Description</span>
					
											</div>
										
										
												
												
												
												
												
												
												
												
												
													<select class="custom-select"  style="background-color: "     onChange="show_cat(), window.alert('Kindly Select Category')"  name="p_name" required >
										
											<option value="<?php echo $db_found_recent['product_name'];?>" selected><?php echo $db_found_recent['product_name'];?></option>
		
											<?php
											
										//	$SQL = "SELECT  DISTINCT name FROM customers_table ORDER BY id ASC ";
													
													
													$SQL = "SELECT DISTINCT product_name FROM product_table      ORDER BY product_name ASC";
											
											$result = mysqli_query($db_handle, $SQL);
											
											//$i =1;

											
											while ( $db_found = mysqli_fetch_assoc($result) ) {
											
												/*echo'<option value="'. $db_found['product_name'].'">'. $db_found['product_name'].'(Qty'. $db_found['unit_q'].', Amt '. $db_found['unit_p'].')</option>'; */
												
												echo'<option value="'. $db_found['product_name'].'">'. $db_found['product_name'].'</option>'; 
																									  }
		
											?>
											
											</select> 
												
												
												
												
												
												
												
												
												
												
												
												
												
				
										</div>
										
										<div class="input-group mb-3">
											
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Payment Method</span>
					
											</div>
										
										
											
											
											<select class="custom-select"   style="width:100%"  id="inputGroupSelect03"  name ="p_method" required onChange="spinner()">
										
												<option Value = "<?php echo $db_found_recent['payment']; ?>" selected ><?php echo $db_found_recent['payment']; ?></option>
																		
									
											
												
												
												
												<option value="Cash">Cash</option>
												<option value="Transfer">Transfer</option>
												<option value="others">others</option>
											
																									  }
		
											
											
											</select> 
											
											
				
										</div>
										
										
										
										
											<div class="input-group mb-3">
											
											
												
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Sales</span>
					
											</div>
										
											<input type="text" class="form-control" placeholder="please fill" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $db_found_recent['amount'];?>"  name = "sales" required>
				
										</div>
										
										<div class="input-group mb-3">
											
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Balance</span>
					
											</div>
										
											<input type="text" class="form-control" placeholder="0" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $db_found_recent['balance'];?>" name="bal" required>
				
										</div>
										
										
											<div class="input-group mb-3">
											
												
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Quantity</span>
					
											</div>
										
											<input type="text" class="form-control" placeholder="please fill" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $db_found_recent['s_qty'];?>" name="qty" required>
				
										</div>
										
										<div class="input-group mb-3">
											
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Unit Cost</span>
					
											</div>
										
											<input type="text" class="form-control" placeholder="please fill" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $db_found_recent['unit_c'];?>" name="re_pass" readonly>
												
												
												
												
										
												
				
										</div>
										
										
										
										
										
										<div class="input-group mb-3">
											
											<div class="input-group-prepend">
				
												<span class="input-group-text" id="basic-addon1">Transaction Date</span>
					
											</div>
										
											<input type="text" class="form-control" placeholder="please fill" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $db_found_recent['date'];?>" name="re_pass" readonly>
												
												
												
												
										
												
				
										</div>
										
										
									
										
							
					</td>
					
	
						</tr>
							
					</table>
						<table>
						<td>
			<input type="submit" value="       UPDATE      "  name = "A" style= "width:auto; height: 70px" class="btn btn-info" onClick="spinclose()" > 
						</td>
							
							<td>
							
							<div class="loader" id="load" style="margin: auto"></div>
							</td>
							
							
				<td>		
						<input type="button" value=" BACK "  name = "" style= "width:auto; height: 70px" class="btn btn-danger" onClick="spinclose(),history.back()"> 
				</td>
							
								<td>		
						<a href="dashboard.php"> <input type="button" value=" HOME "  name = "" style= "width:auto; height: 70px" class="btn btn-danger" onClick="spinclose()"> </a>
				</td>
											
								</table>
					</form>
		
		        
					
					
				
		</td>
					
			
	
				</tr>

			
			
			</table>
				
				
				
				
				
				</div>

			
			
			
			
					<div class = "col-md-6 " style="background-color: #494747">
				  	
						<strong ><span style="color:#FAF7FF;padding: 4px"><br>RECORD
					    
							</span> </strong>
				
						 
						<div class="jumbotron-fluid scroll_history" style="font-size:12; ">
				  
				  <!--<strong ><span style="color:#260B4D;background-color: #FBFBFC;padding: 4px">TRANSACTION HISTORY
					     </span></strong>-->
				  
	  
			
							
										<table class="table  table-hover" style="font-size:13; width:100%  " >
  
								<tbody>
    
									<tr  style="background-color: #A22E2E; text-align: center; color: white">
      
									<!--	<th scope="col"></th>
	
										<th scope="col"></th>
										
										<th scope="col"></th>-->
										
										<th scope="col"></th>
      
										<th scope="col"><input type="button" value="Description"></th>
										<th scope="col"><input type="button" value="Payment"></th>
										
										<th scope="col"><input type="button" value="Customer"></th>
		 
		<!-- <th scope="col">DESCRIPTION</th>-->
	
		   
										<th scope="col"><input type="button" value="Sales"></th>
										<th scope="col"><input type="button" value="Balance"></th>
									<!--	<th scope="col"><input type="button" value="Gross Profit:"></th>-->
										<th scope="col"><input type="button" value="QTY"></th>
		
										
		 
									<!--	<th scope="col"><input type="button" value="TIME"></th>-->
										
		
     
    
									</tr>
 			
		



									<?PHP

//if ($db_found) {

//$SQL = "SELECT * FROM product_table ORDER BY product_id ASC ";

	  
	  
//$SQL = "SELECT * FROM txn_table where date= current_date ORDER BY product_id DESC   ";

									
									$SQL = "SELECT *FROM txn_table where product_id = $txn_id   ";

	  
									
									$result = mysqli_query($db_handle, $SQL);

									$i =1;
	  		
									while ( $db_found = mysqli_fetch_assoc($result) ) {
	   
	
										echo'<tr style="text-align: center; color:white; background-color:black" >';

	
	
										echo '<td>'.$i++.'</td>';
		
										//echo '<td>'.$db_found['product_id'].'</td>';
										
										
										
										
										//echo '<td>  <button>'.$db_found['product_id'].'</botton></td>';
										
										?>
									<!--	<td><a href="transaction.php?txnId=<?php echo $db_found["product_id"]?>">
   
										<input type="button" value="Reverse" onClick="spinner(), view_ac()"></a></td>
									
									
									<td><a href="user_id.php?txnId=<?php echo $db_found["user_id"]?>">
   
										<input type="button" value="Staff" onClick="spinner(), view_ac()"></a></td>
									
									
									
									<td><a href="invoice.php?txnId=<?php echo $db_found["product_id"]?>">
   
										<input type="button" value="Issue Reciept" onClick="spinner(), view_ac()"></a></td>
									
									
									-->
									
								
									<?php
									//echo '<td>'.$db_found['user_id'].'</td>';
										
										
										
										
		 
										echo '<td>'.$db_found['product_name'].'</td>';
										
										echo '<td>'.$db_found['payment'].'</td>';
										
										echo '<td>'.$db_found['customers_name'].'</td>';
		
										echo '<td>'.$db_found['amount'].'</td>';
										echo '<td>'.$db_found['balance'].'</td>';
									
		
	
									//	echo '<td>'.$db_found['unit_c'].'</td>';
	
	 
										echo '<td>'.$db_found['s_qty'].'</td>';
										
										
	
									//	echo '<td>'.$db_found['date'].'</td>';
										
										
										
										
	//echo '<td>'.$db_found['SUM(amount)'].'</td>';
	
	//echo $db_found_sum['SUM(amount)']; 
	 
	 
	
									?>
<!--	  
  <td><a href="construction.php?txnId=Receipt">
    <input type="button" value="Issue Receipt"></a></td>
	  
	  <td><a href="construction.php?txnId=Modify Account">
    <input type="button" value="Modify"></a></td>-->
	  
	  <!--
									<td>
    
										<input type="button" value="Issue Receipt"onClick= "window.alert('The page  you requsted is still under Development. Contact us (Alaye David 09055158742, head of iCT LAWPED GROUP,www.lawped.com.ng')"></td>
	  
	  
									<td>
    
										<input type="button" value="Modify"onClick= "window.alert('The page  you requsted is still under Development. Contact us (Alaye David 09055158742, head of iCT LAWPED GROUP,www.lawped.com.ng')" ></td>
	  
	   
									
   
										<input type="button" value="Delete" onClick="spinner(), view_ac()"></a></td>
	
	  -->
									<?php
	
										echo '</tr>';

	
	

									}

									mysqli_close($db_handle);
	  
			
									?>
	

								</tbody>

							</table>
						
							
							
							
							
	
	
						</div>
			
					</div>
			
			
		</div>
			
	
			
			</div>
	
	
	
		
	
		
		</body>
	
		</html>
<script>


		function spinner()
	{
  
			var x = document.getElementById("load");
	
	
    x.style.display = "none";
  
	
	
}
	
	
	
		function spinclose()
	{
  
			var x = document.getElementById("load");
	
	
    x.style.display = "block";
  
	
	
}
	
		
		
		


</script>





<script>
	
	//pop scripts
	
	
function CustomAlert(){
  this.alert = function(message,title){
    document.body.innerHTML = document.body.innerHTML + '<div id="dialogoverlay"></div><div id="dialogbox" class="slit-in-vertical"><div><div id="dialogboxhead"></div><div id="dialogboxbody"></div><div id="dialogboxfoot"></div></div></div>';

    let dialogoverlay = document.getElementById('dialogoverlay');
    let dialogbox = document.getElementById('dialogbox');
    
    let winH = window.innerHeight;
    dialogoverlay.style.height = winH+"px";
    
    dialogbox.style.top = "100px";

    dialogoverlay.style.display = "block";
    dialogbox.style.display = "block";
    
    document.getElementById('dialogboxhead').style.display = 'block';

    if(typeof title === 'undefined') {
      document.getElementById('dialogboxhead').style.display = 'none';
    } else {
      document.getElementById('dialogboxhead').innerHTML = '<i class="fa fa-exclamation-circle" aria-hidden="true"></i> '+ title;
    }
    document.getElementById('dialogboxbody').innerHTML = message;
    document.getElementById('dialogboxfoot').innerHTML = '<button class="pure-material-button-contained active" onclick="customAlert.ok()">OK</button>';
  }
  
  this.ok = function(){
    document.getElementById('dialogbox').style.display = "none";
    document.getElementById('dialogoverlay').style.display = "none";
  }
}

let customAlert = new CustomAlert();
	</script>