






<?php
 $txnid= $_GET['txnId'];
 




			session_start();

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

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









if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
	header ("Location: ../login.php");
}
		


?>


<?php
require 'config.php';

			 $db_handle = mysqli_connect(DB_SERVER, DB_USER, DB_PASS);
			 $database = $_SESSION['database'];
			$db_found = mysqli_select_db($db_handle, $database);
			
		//$SQL = "DELETE FROM product_table WHERE product_id=$txnid";
   //$query_del = mysqli_query($db_handle, $SQL);



  if($db_found){
	 


	
	$SQL = "SELECT* FROM txn_table WHERE product_id=$txnid";
   $result = mysqli_query($db_handle, $SQL);
	  $db_fd = mysqli_fetch_assoc($result) ;
	   
	  
	  
	  
	// header ("Location: inventory_ac.php");

	 
	  
	  
	  
	  
  }
	
else{
	
	echo "database not found";
}

 
if(isset($_POST['A'])){
	 
    $product_name = $_POST['product'];
	$unit_q = $_POST['unit_q'] ;
	$unit_p = $_POST['unit_p'] ;
	
	$unit_c = $_POST['unit_c'] ;
	//$bundle_q = $_POST['bundle_q'] ;
	//$bundle_p = $_POST['bundle_p'] ;

	

	$db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );

		/*
			$SQL = $db_found->prepare("INSERT INTO product_table (product_name, unit_q, unit_p,bundle_q,bundle_p,user_id) VALUES (?,?,?,?,?,?)");
			$SQL->bind_param('ssssss', $product_name, $unit_q,$unit_p,$bundle_q,$bundle_p,$_SESSION['user_id'] );
			$SQL->execute();
			header ("Location: inventory_ac.php");
			
			
		*/
	/*
	
	$SQl_update = "UPDATE product_table SET  product_name='$product_name', unit_q= '$unit_q', unit_p= '$unit_p', unit_c = '$unit_c' WHERE product_name = '$product_name' ";
	
	mysqli_query($db_found,$SQl_update);
	
	*/
	
	
	$SQl_update = "UPDATE txn_table SET unit_q = $unit_q WHERE product_name = '$product' ";
	
	mysqli_query($db_found,$SQl_update);
	
		echo  "operation successfull";




}

	  
	  	 



?>






	<html>
		
			<title>Delete_script</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>

<script>
	
	
	
	
function repay(str) {
	
	var amount =  parseInt(document.getElementById("amount").value) ;
	var full_amount =  parseInt(document.getElementById("full_amount").value) ;
		var balance = parseInt (document.getElementById("balance").value);
	var new_balance = parseInt (document.getElementById("new_balance").value);
	var add_amt = parseInt (document.getElementById("add_amt").value);
 
 
	if(str == "")
		
		{
		document.getElementById("new_balance").value = "";
		document.getElementById("full_amount").value ="";
			document.getElementById("label").innerHTML =balance;
			
			// customAlert.alert('Error||field cant be empty','LBS');
			 //document.getElementById("add_amt").value = 0;
			return;
		}
	else if(add_amt > balance){
		
		
		
		//window.alert();
		
		
		
	 customAlert.alert('excessive amount','LBS');
			
		
		
			}
		
else {   
		
	var result = balance - add_amt;
		var rst_amt = amount + add_amt ;
		
		document.getElementById("full_amount").value = rst_amt;
	
		document.getElementById("new_balance").value = result;
	document.getElementById("label").innerHTML = result;
	
		
		//parseInt(document.getElementById("amount").value) = rst_amt; 
		//parseInt (document.getElementById("balance").value) = result;
		
		
	
	//window.alert();
	//document.getElementById("add_amt").value = "" ;
	

	
}   
		  
 
   
}
		
		
	
	
	
</script>

		
		
		
		<style>
		
			
			
			body, html {
background-color:<?php echo $bottom_backgroundcolor; ?>;
}

			
			
			
		
				.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid blue;
  border-right: 16px solid green;
  border-bottom: 16px solid red;
  border-left: 16px solid pink;
  width: 120px;
  height: 120px;
  -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); }
}
		
		</style>
		
		
		
		
		
		
		<body onLoad="spinner()">


			
	<div class="jumbotron" style="text-align: center;background-color:<?php echo $background_color ?>;color:<?php echo $bottom_textcolor ?> ">
		
		
		
		
		
		<div class="row">
			
			
		
			<div class="col-md-6">
			
				
						<table style="width: 100%">
					
		
	
			
			
					
					
				
		 			<?php $txnid;?>
			
					<form METHOD ="POST" ACTION = "debtors_del_repay.php" style="width: inherit">
					
						<tr>
						
							<td>
							<label style="font-size: 70px;color: #ECE3E3" id="label"><?php echo $db_fd['balance']; ?></label>
							
							</td>
						
						</tr>
				
							<tr>
							
								<td>  
								
									<div class="input-group mb-3">
											
										<input type="hidden" value="<?php echo $db_fd['product_id']; ?>" id = "" name="product_id">
										<input type="hidden" value="<?php echo $db_fd['customers_name']; ?>" id = "product_id" name="customer">
									
										<!--initial_amount--><input type="hidden" value="<?php echo $db_fd['amount']; ?>" id = "amount" name="">
										<!--new_amount--><input type="hidden" value="" id="full_amount"  name="amount">
										
										<!--initial_bal--><input type="hidden" value="<?php echo $db_fd['balance']; ?>" id ="balance" name="">
										<!--new_bal--><input type="hidden" value="" id ="new_balance" name="balance">
										
										<input type="hidden" value="<?php echo $db_fd['customers_name']; ?>"  name="customers_name">
										
											
										<input type="hidden" value="<?php  echo $db_fd['product_id']; ?>"  name="debt_id">
											
											
											
  
									
										<input type="hidden" class="form-control" placeholder="eg.book,rice,doors etc" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $db_fd['product_name'];?>" name="product">

									</div>
					
									
									<div class="input-group mb-3">
  
										<div class="input-group-prepend">
    
										
  
										</di v>
  
								
													<input type="hidden" class="form-control" placeholder="0.00" aria-label="Username" aria-describedby="basic-addon1" name="unit_c" value="<?php echo $db_fd['unit_c'];?>">

									</div>
										
											
										
									
									<table>
									
									
										
										<tr>
											
											<td>
											
												<div class="input-group mb-3" style="">
  
													<div class="input-group-prepend">
    
														
														<span class="input-group-text" id="basic-addon1" >Debt(<?php echo $db_fd['balance'];?>)</span>
															<input type="number" class="form-control" placeholder="0.00" aria-label="Username" aria-describedby="basic-addon1" name="add_amt" id="add_amt" onKeyUp="repay(this.value)">
  
													</div>
  

												

												</div>	
												
											</td>
											
										</tr>
										
									</table>
									
									
										
					
								</td>
								 
					
							</tr>
			
					
						<tr>
						<td>
							<a href="debtors.php"><input type="button" value="BACK" onClick="spinner()" style= "width:; height: inherit; float: " class="btn btn-dark" > </a>
					<input type="submit" value="SETTLE" onClick="spinner()" name = "A" style= "width:; height: inherit;; float: " class="btn btn-dark" >  
							
							</td>
						
						
						</tr>
			


			</table>
				 
					
											
						
					</form>
		
		        
	
				
				
				
			</div>
			
			
			<div class="col-md-6">
			
			</div>
			
			
		</div>
		
	
	
		
			
			</div>
			
	
		<div class="loader" id="spin" style="margin: auto"></div>

	
		</body>
	
			</html>

		
		

<script>


		function spinner() {
  
			var x = document.getElementById("spin");
	
	
	
  if (x.style.display === "none") {
    x.style.display = "block ";
	  
	  
  }
	else {
    x.style.display = "none";
  }
	
	
}
	
		

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>