<?PHP


session_start();
$status = $_SESSION['status'];

						

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>";

$branch_key = $_SESSION['branch_key'];


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 = "lawpedc3_lbs_users";

$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">
<!--===============================================================================================-->
	
</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= "spinner(),document.location='receipt/receipt.php'">


	
	
	<!--newheader-->
	
	
	
	
	<!--new headeer-->
	
	
		
	

		
	
				<a href="dashboard.php"><input type="button" value="Back" class="" onClick=" spinner()" style= "width: inherit; height: "  ></a>
	<input type="button" value="Print" class="" onClick="window.print()" style= "width: inherit; height: "  >
	
		
	<div class="container-fluid" style="padding:" >
			
			
		
		
								
				
						
	
	

	
	
		
		
	
	

			<div class="row">
				
				
				
			
				
	
									<?PHP

							echo		$amount =  $_GET['txnId'];
									
								

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

									
									$result = mysqli_query($db_handle, $SQL);
								
								 $db_found = mysqli_fetch_assoc($result);
				
				
				
				
	  
							
									?>
		
				
				<div class="col-md-4">
				</div>
				
				
				
	<div class="col-md-4" >
	
		<div style="border: 1px solid black; height: auto; padding: 10px; box-shadow: grey 5px 5px 5px; background-color: ">
		
		<div style="background-color:; width: inherit; margin: auto; text-align: center; margin-bottom: 40px;margin-top: 40px ">
						
						<h3><b><span style="margin: auto" ><?php echo $_SESSION['biz_name']; ?></span></b></h3><br>
				
				  <b><em><span style="color: #FDF9F9; background-color: #F50408; padding: 5px">  Cash Reciept  </span></em></b>
			<br><i> No:<?php echo $db_found['product_id'];  ?></i>
						
				
				</div>
			
		
		
						<table width="100%" style="font-size: 16px; margin: auto;color:; border-spacing: 100px; margin-bottom: 30px"  >
		
							
							 <tr style="background-color: ">
							
								  <td>Payment Method</td>
								 <td><?php     echo $db_found['payment'];   ?></td>
      
      						
								 
    </tr>
							
							 <tr style="background-color: ">
							
								  <td>Customer</td>
								 <td><?php     echo $db_found['customers_name'];   ?></td>
      
      						
								 
    </tr>
							
		
							 <tr  style="background-color: ">
								  <td>Description</td>
							 <td > <?php     echo $db_found['product_name'];   ?></td>
      
      						
    </tr>
							
							 <tr style="background-color: ">
								  <td>Quantity</td>
							 <td> <?php     echo $db_found['s_qty'];   ?></td>
      
      						
    </tr>
 
	
					<!--		<strong>	 <tr style="background-color: ">
								  <td>Total Amount</td>
							 <td> <?php     echo "yy". intval($db_found['amount']) + intval($db_found['balance']) ;   ?></td>
      
      						
    </tr>	</strong>-->
							
		 <tr style="background-color: ">
								  <td>Amount Received</td>
							 <td> <?php     echo $db_found['amount'];   ?></td>
      
      						
    </tr>				
	  <tr style="background-color: ">
								  <td>Balance:</td>
							 <td> <?php     echo $db_found['balance'];   ?></td>
      
      						
    </tr>
							
					
							
								  <tr style="background-color: ">
								  <td>Issuer IDN:</td>
							 <td> <?php     echo $db_found['user_id'];   ?></td>
      
      						
    </tr>
							
							  <tr style="background-color: ">
								  <td>Recieved By:</td>
							 <td> <?php     echo $_SESSION['name'];    ?></td>
      
      						
    </tr>
							
							
							
								<tr style="background-color: ">
								  <td>Signed</td>
							 <td> Management</td>
      
      						
    </tr>
	  
	  <tr style="background-color: ">
								  <td>Date</td>
							 <td> <?php     echo $db_found['date'];   ?></td>
      
      						
    </tr>
							
							<tr style="background-color: ">
								  <td>Time</td>
							 <td> <?php     echo date("h-i-s");  ?></td>
      
      						
    </tr>

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

<div class="col-md-4">
				</div>
		</div>
	
	
			</div>

<?php
	
	
	
	//transaction details
	
 $_SESSION['payement_method'] = $db_found['payment']; 
	
	$_SESSION['customer'] = $db_found['customers_name'];
	
	
	$_SESSION['product_name'] = $db_found['product_name']; 
	
	// $_SESSION['received_name'] = $db_found['name'];
	
	$_SESSION['s_qty'] = $db_found['s_qty'];  
	
	
	echo 	$_SESSION['unit_c']  =  $db_found['unit_c'];
	
	$_SESSION['amount'] = $db_found['amount'];
	
	//$_SESSION['description'] = $db_found['description'];
	
	
	if ($_SESSION['balance'] =='')
		
	{
		
		
		
		$_SESSION['balance'] = 0;
		
		
			$_SESSION['total'] = $db_found['amount'] + $_SESSION['balance'] ;
	}
	
	

	
		$_SESSION['balance'] = $db_found['balance'];
	
		$_SESSION['user_id'] =  $db_found['user_id'];
	
	$_SESSION['date'] =  $db_found['date'];
	
	$_SESSION['time'] =  date("h-i-s");
	
	
		$_SESSION['p_description'] =  $db_found['description'];
	
	
	
	
	
	
	
	echo $product_name = $_SESSION['product_name']; 
	
	
	
				
				//product table
				
				  $SQL = "SELECT  * FROM product_table   where     branch_key = $branch_key and product_name = '$product_name' ";

									
									$esult = mysqli_query($db_handle, $SQL);
								
								 $db_f = mysqli_fetch_assoc($esult);
	
		
	echo 'br';
	
							
echo	$_SESSION['unit_p'] =  $db_f['unit_p'];
	
	
	echo 'br';
	
	echo $_SESSION['total_q_p'] =  $db_f['unit_p'] * $_SESSION['s_qty'];
	
	
	
	
	
	
		//customer table
	
	
					echo $customer = $_SESSION['customer']; 
	
	
				  $SQL = "SELECT  * FROM customers_table   where     branch_key = $branch_key and name = '$customer' ";

									
									$esult = mysqli_query($db_handle, $SQL);
								
								 $db_f = mysqli_fetch_assoc($esult);
	
		
	echo 'br';
	
							
echo	$_SESSION['c_phone'] =  $db_f['phone'];
	
	
	echo 'br';
	
	echo $_SESSION['c_address'] =  $db_f['address'];
	
	
	echo 'br';
	
	echo $_SESSION['c_email'] =  $db_f['email'];
	
	
	
	
	if($_SESSION['balance'] == "")
		
		
	{
		
			
echo	$_SESSION['word'] = 'The sum of '.$_SESSION['total'].'.00 naira only  was received from '.$_SESSION['customer'].' for payment of '.$_SESSION['product_name'].'('.$_SESSION['p_description'].')';
	

		
	}
	
	else{
		
		
echo $_SESSION['word'] = 'Part payment of '.$_SESSION['total'].'.00 naira only  was received from '.$_SESSION['customer'].' for payment of '.$_SESSION['product_name'].'('.$_SESSION['p_description'].')'.' with a bal of'.$_SESSION['balance'];
	
	}

	


	
	
	?>
			
	
	<div class="loader" id="spin" style="margin: auto">
	
			
			</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";
  }
}		
		
			
		

		


</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 -->



