<?PHP


session_start();
$status = $_SESSION['status'];
$notification = "Reverse ";						

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

//echo 'WELCOME'.'    '.$_SESSION['name'].'   '.'<A HREF = logout.php>Log out</A>';

?>

<?php

$privilage = $_SESSION['privilage']; 

 

$app_name = $_SESSION['app_name'];
//echo "<br>";


if($status === "inactive"){
//echo "it works";
	
	header ("Location: payment_activate.php");
	
 }


?>






<?php
require 'config.php';

$db_handle = mysqli_connect(DB_SERVER, DB_USER, DB_PASS);
$database = $_SESSION['database'];
//$database = "lawped_app";

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


?>

<?php

	
$notification = "";

if(isset($_POST['A'])){
	
	echo $date = $_POST['date'];
	 
    $product = $_POST['product'];
	$amount = $_POST['amount'] ;
	$s_qty = $_POST['s_qty'] ;
	
		$customers = $_POST['customer'];
	
if($product=="Select Product" or $amount=="" or $s_qty==""){
	 $notification = 'OPERATION FAILED|| amount or quantity or product field is blank';
}
	
	
else{	
	
		//to select unit cost of goods sold from product database
	
	$SQ = "SELECT product_name, unit_c, unit_q FROM product_table where product_name = '$product' ";
												$resul = mysqli_query($db_handle, $SQ);
											$db_foun = mysqli_fetch_assoc($resul);
											 $unit_qty_cost = $db_foun['unit_c'].'<br>';
	
	
	$qty = $db_foun['unit_q'].'<br>';
	
	$totalcost = intval($unit_qty_cost) *$s_qty.'<br>';
	
  	 "grossprofit". $gross_profit = intval($amount) -intval($totalcost);
	 "avilableqnty". $avail_qnty = 	intval($qty) - $s_qty;		
	
	
	
	
	
	
	
	if($avail_qnty<=0){
		
		 $notification = 'OPERATION FAILED|| '.$product." is out of stock || available Quantity ".($qty);
		}
	

	
	else{
		
	$notification = "";
	$db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );
	
	$SQl_update = "UPDATE product_table SET unit_q = $avail_qnty WHERE product_name = '$product' ";
	
	mysqli_query($db_found,$SQl_update);
				
	// $date = date("Y-m-d");
	 $month = date("M");
	 $year = date("Y");
	 $time = date("h-i-s");
	
	//$time = date("h-m-d");
	
		//$db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );

	
		
		
			$SQL = $db_found->prepare("INSERT INTO txn_table (product_name,customers_name, amount,unit_c,s_qty, user_id,month,year,time,date) VALUES (?,?,?,?,?,?,?,?,?,?)");
			$SQL->bind_param('ssssssssss', $product,$customers, $amount,$gross_profit,$s_qty, $_SESSION['user_id'],$month,$year,$time, $date );
			$SQL->execute();
			//header ("Location: dashboard.php");
		

	
	
	
		 $notification = "operation successfull";
	
		
		
	}
	
	
	
	
	
	
	}
	
	
	
	

}






else{
	
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
	<title>Lawped</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	 <link rel="apple-touch-icon" sizes="76x76" href="./assets/img/apple-icon.png">
  <link rel="icon" type="image/png" href="assets/img/favicon.png">
	
	
	  <!--manifest file for pwa ap-->
	 <link href="manifest.json"  rel = "manifest">
	   <!--manifest file for pwa ap-->
	  
	  <!--ios support-->
	   <link href="img/icons/icon-96.png"  rel = "apple-touch-icon">
	  <meta name="apple-mobile-web-app-status-bar" content="#00695c">
	  <meta name="theme-color" content="#00695c">
	  <!--ios suppoer-->
	
	  <script src="app.js"></script>
	
	
<!--===============================================================================================-->	
		
	
 <script src="https://kit.fontawesome.com/42d5adcbca.js" crossorigin="anonymous"></script>
  <!-- Material Icons -->
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons+Round" rel="stylesheet">
  <!-- CSS Files -->
  <link id="pagestyle" href="assets/css/material-dashboard.css" rel="stylesheet" />
	
	 <link href="css/bootstrap-4.4.1.css" rel="stylesheet">
	 <link href="css/popup.css" rel="stylesheet">
<!--===============================================================================================-->
	
</head>
	
	 <script src="js/main.js"></script>
	
	
	
	<style>
		
		.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); }
}
		
		
		
		
		
		
		
		
		
		
		
		
		
	body, html {
background-color: #E1E1DB;
}

	
		
	
            div.scroll {
                //margin:4px, 4px;
                padding:4px;
               // background-color: #494747;
                width: 100%;
                height: 210px;
               // overflow-x: hidden;
               // overflow-y: auto;
				overflow: auto;
                text-align:justify;
            }
		
		div.scroll_history {
                //margin:4px, 4px;
               // padding:4px;
                background-color: #494747;
                width: 100%;
                height: 300px;
                //overflow-x: hidden;
                //overflow-y: auto;
				overflow: auto;
                text-align:justify;
            }
		
		
		div.scroll_body {
                margin:4px, 4px;
               // padding:4px;
                //background-color: green;
                width: 100%;
                height: 400px;
                overflow-x: hidden;
                overflow-y: auto;
				//overflow: auto;
                text-align:justify;
            }
		
		

	</style>
	
<body onLoad= "unit_ac(),bulk_ac(),spinner()">


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

		?>
			<div class="" style="float: right"><A HREF = "logout.php" onClick="spinner()">Log out</A></div>
			<!--<button onclick="myFunction()">Click Me</button>-->
			

			
		</div>
	
	
			

	
	
		<div class="jumbotron" style="background-color: #F9FAFB; height: auto">
			
			
			<div style="color: #FDFDF9;  "><h4><b><marquee behavior="alternate"><span style="color: #0D1ED4"><?php echo $_SESSION['biz_name']; ?></span></marquee></b></h4></div>
	
			
			
			<div class="row">
		
				<div class="col-md-12" id="">
			
					<table style="margin: auto; width: auto" >
		
	
						<tr>
				
							<td>
					
					
								<!--<input type="submit" value='Record' onClick="unit_ac()" class="btn btn-info" style= "width: inherit; height: 70px" name = "A"  >-->
					
					
			
							</td>
	
							<td>
		
									<a href="dashboard.php"><input type="button" value="HOME" class="btn btn-danger" onClick=" spinner()" style= "width: inherit; height:"  ></a>
				
							</td>
	
						<!--	<td>
		
							<input type="submit" value="Account" class="btn btn-info" style= "width: inherit; height: 70px" name = "A" onClick="crude_ac()" >
			
							</td>-->
	
	
	
				
						</tr>
		
					</table>
		
				</div>
	
    
			</div>
			
			
		<!--	
			<div class="row">
			
				<table style="margin: auto;width: auto" >
		
	
					<tr>
				
						<td>
					
					 
							<input type="submit" onClick="view_ac()" value="Account" class="btn btn-danger" style= "width: inherit; height: 70px" name = "A" >
					
					
				
						</td>
	
						<td>
		
							<a href="inventory_ac.php"> <input type="submit" value="Inventory" onClick="spinner()" class="btn btn-danger" style= "width: inherit; height: 70px" name = 
															   "A" ></a>
				
						</td>
	
						<td>
		 
							<input type="submit" value="Add users" class="btn btn-danger" style= "width: inherit; height: 70px" name = "A" 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>
	
	
	
					</tr>
			
			
				</table>
		
		
			
			</div>
				-->
	
		<!--	<div class="row">
			
				<table style="margin: auto; width: auto"  >
		
	
					<tr>
				
						<td>
					
					 
							<a href="dashboard.php"><input type="button" value="Refresh" class="btn btn-danger" onClick=" spinner()" style= "width: inherit; height: 70px"  ></a>
					
					
				
						</td>
	
						<td>
		 
							<input type="button" value="Saved Receipts" class="btn btn-danger" style= "width: inherit; height: 70px" name = "A" 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>
		 
							<a href="setup_ac.php"><input type="submit" value="Setup" class="btn btn-danger" style= "width:inherit; height: 70px" name = "A" onClick= "spinner()" ></a>
				
						</td>
	
	
	
			
		
				</table>
	
			
				</tr>
			
	</div>-->
			
	<div style="align-content: center; text-align: center; color: #020202"><?php echo $notification?>  </div>
	
	</div>
	
	
	
	

	
	<div class="loader" id="spin" style="margin: auto">
	</div>
	
	
	
		<div class="container-fluid" style="" >
		
		
		
		
			<div class="jumbotron-fluid" style="background-color: ">
		
		
			
				<div class="row">
				
				
					<div class="col-md-4" style="padding-top: 8px" id="unit_ac">
					
					
											
						
					</div>
										
					
					
					<div class="col-md-4" style="padding-top: 8px" id="bulk_ac">
 
						<form METHOD ="POST" ACTION = "dashboard.php" style="width: 100%">
						
							<table width="100%">
				
								<tr>
				
					
					
					
									<td>  
					
										<input type="text" class="form-control" name="product" placeholder="Job Description" aria-label="Amount" aria-describedby="basic-addon2">
					
									</td>
					
									<td>
					
										<input type="text" class="form-control" name="amount" placeholder="Amount" aria-label="Recipient's username" aria-describedby="basic-addon2">
				
					
										
									</td>
						 
												
						 												
						 
							
								</tr>
			
							</table>
			 
							<input type="submit" value="SAVE" class="btn-info" style= "width: 100%" name = "A" >
											
							
						</form>
						
					</div>
					
										
								
				
					<div class="col-md-4" style="padding-top: 8px; background-color:" id="crude_ac"  >
					
 
						<form METHOD ="POST" ACTION = "transaction.php" style="width: 100%">
						
							<table width="100%">
				
								<tr>
				
					
					
					
									<td>  
					
										<input type="text" class="form-control" name="amount" placeholder="Invoice No:" aria-label="Recipient's username" aria-describedby="basic-addon2" value="<?php echo @ $txnid= $_GET['txnId']; ?>">
					
									</td>
					
									<td>
					
				
					 
										<input type="submit" value="SEARCH" class="btn-dark" style= "width: 100%" name = "id" onClick="spinner(),crude_ac()" >
										
									</td>
						 
												
						 												
						 
							
								</tr>
			
							</table>
			
											
							
						</form>
				
					</div>


				
				</div>
		
		
		</div>
		
		
		
		
		
		
			<div class="jumbotron-fluid" style="background-color: ">
		
			
				<div class="row " style="margin-top: 1px; background-color:" >
		
			
					<div class = "col-md-2 " style="background-color:;padding: 10px">
			
								</tbody>

							</table>
						
	
	
	
						</div>

					
					</div>
						
			
					<div class = "col-md-10 " style="background-color: #494747"  >
				  	
						<strong ><span style="color:#FAF7FF;padding: 4px"><br>TRANSACTION HISTORY
					    
							</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:12; width:100%  " >
  
								<tbody>
    
									<tr  style="background-color: #A22E2E; text-align: center; color: white">
      
										<th scope="col">s/n</th>
	
										<th scope="col">Invoice No: </th>
										
										<th scope="col">IDN</th>
      
										<th scope="col">Description</th>
										
										<th scope="col">Customer</th>
		 
		<!-- <th scope="col">DESCRIPTION</th>-->
	
		   
										<th scope="col">Total Sales</th>
										<th scope="col">Gross Profit</th>
										<th scope="col">QTY</th>
		
										
		 
										<th scope="col">TIME</th>
										
										<th scope="col">DATE</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   ";

							if(isset($_POST['id'])){
									
								
								$amount = $_POST['amount'] ;
								
									$SQL = "SELECT  product_name,product_id,user_id, amount,time,s_qty,unit_c,date,customers_name FROM txn_table   where product_id = '$amount'  ORDER BY product_name DESC";

	  
									
									$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>'.$db_found['user_id'].'</td>';
		 
										echo '<td>'.$db_found['product_name'].'</td>';
										
										echo '<td>'.$db_found['customers_name'].'</td>';
		
										echo '<td>'.$db_found['amount'].'</td>';
									
		
	
										echo '<td>'.$db_found['unit_c'].'</td>';
	
	 
										echo '<td>'.$db_found['s_qty'].'</td>';
										
										
	
										echo '<td>'.$db_found['time'].'</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>
    
										
	  
											<td>
    
									
	   
									<td><a href="record_delete.php?txnId=<?php echo $db_found["product_id"]?>">
   
										<input type="button" value="Reverse" onClick="spinner(), view_ac()"></a></td>
									
									
										<td><a href="modify_record.php?txnId=<?php echo $db_found["product_id"]?>">
   
										<input type="button" value="Edit" onClick="spinner(), view_ac()"></a></td>
	
	  
									<?php
	
										echo '</tr>';

	
	

									}

									mysqli_close($db_handle);
	  
							}
									?>
	

								</tbody>

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

		</div>
	
	



		</body>

</html>




	<script>
		
s		

		function spinner() {
  
			var x = document.getElementById("spin");
	
	
	
  if (x.style.display === "none") {
    x.style.display = "block ";
	  
	  
  }
	else {
    x.style.display = "none";
  }
	
	
}
	
		
		
		
		
		
		
		
		
		
		
		function view_ac() {
  
			var x = document.getElementById("view_ac");
	
	 var unit_ac = document.getElementById("unit_ac");
	 var bulk_ac = document.getElementById("bulk_ac");
	 var crude_ac = document.getElementById("crude_ac");
	
  if (x.style.display === "none") {
    x.style.display = "block";
	  
	   
	  unit_ac.style.display="none";
	  crude_ac.style.display="none";
	  bulk_ac.style.display="none";
	  
  }
	else {
    x.style.display = "none";
  }
	
	
}
		
		
	
function unit_ac() {
	var x = document.getElementById("unit_ac");
	 var unit_ac = document.getElementById("bulk_ac");
	 var crude_ac = document.getElementById("crude_ac");
	var view_ac = document.getElementById("view_ac");
	
  if (x.style.display === "none") {
   
	   x.style.display = "block";
	  
	  unit_ac.style.display="none";
	  crude_ac.style.display="none";
	  view_ac.style.display="none";
	  
	  
  } 
	else {
    x.style.display = "none";
		
		
		
  }
	
	
}		
		
		
function bulk_ac() {
  var x = document.getElementById("bulk_ac");
	
	 var unit_ac = document.getElementById("unit_ac");
	 var crude_ac = document.getElementById("crude_ac");
	var view_ac = document.getElementById("view_ac");
	
  if (x.style.display === "none") {
    x.style.display = "block";
	  
	   unit_ac.style.display="none";
	  crude_ac.style.display="none";
	   view_ac.style.display="none";
  } 
	else {
    x.style.display = "none";
  }
}		
		
			
function crude_ac() {
  var x = document.getElementById("crude_ac");
	
	var unit_ac = document.getElementById("unit_ac");
	 var bulk_ac = document.getElementById("bulk_ac");
	var view_ac = document.getElementById("view_ac");
	
  if (x.style.display === "none") {
    x.style.display = "block";
	  unit_ac.style.display="none";
	  bulk_ac.style.display="none";
	  view_ac.style.display="none";
  } 
	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>			
			




 <!--   Core JS Files   -->
  <script src="assets/js/core/popper.min.js"></script>
  <script src="assets/js/core/bootstrap.min.js"></script>
 
  <script>
    var win = navigator.platform.indexOf('Win') > -1;
    if (win && document.querySelector('#sidenav-scrollbar')) {
      var options = {
        damping: '0.5'
      }
      Scrollbar.init(document.querySelector('#sidenav-scrollbar'), options);
    }
  </script>
  <!-- Github buttons -->
  <script async defer src="https://buttons.github.io/buttons.js"></script>
  <!-- Control Center for Material Dashboard: parallax effects, scripts for the example pages etc --