<?PHP
session_start();
$status = $_SESSION['status'];
$privilage = $_SESSION['privilage']; 


$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");
}




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


//this is an Ajax script for poping on and off of product or service prices and quantity when selected.


?>


<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"></script>

<script>
	
	// Wrap every letter in a span
var textWrapper = document.querySelector('.ml9 .letters');
textWrapper.innerHTML = textWrapper.textContent.replace(/\S/g, "<span class='letter'>$&</span>");

anime.timeline({loop: true})
  .add({
    targets: '.ml9 .letter',
    scale: [0, 1],
    duration: 1500,
    elasticity: 600,
    delay: (el, i) => 45 * (i+1)
  }).add({
    targets: '.ml9',
    opacity: 0,
    duration: 1000,
    easing: "easeOutExpo",
    delay: 1000
  });
	
	
</script>



	<script>
	

		
	
		
		
				
	
function showUse(str) {
  if (str == "") {
    document.getElementById("txtHint").innerHTML = "";
	 
	  
	//    document.getElementById("txtHint").innerHTML = window.alert();
    return;
  } 
	
	
	else {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        document.getElementById("txtHint").innerHTML = this.responseText;
		//  var myobj =JSON.parse(this.responseText);
		  
		  var strArray = xmlhttp.responseText.split(":::");
 // window.alert();
		
	
			
			 
		   
      }
    };
    xmlhttp.open("GET","get_details.php?q="+str,true);
    xmlhttp.send();
  }
}


			
function showUser(str) {
  if (str == "") {
    document.getElementById("cat").innerHTML = "";
	 
	  
	//    document.getElementById("txtHint").innerHTML = window.alert();
    return;
  } 
	
	
	else {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        document.getElementById("cat").innerHTML = this.responseText;
		//  var myobj =JSON.parse(this.responseText);
		  
		  var strArray = xmlhttp.responseText.split(":::");
 // window.alert();
		
	
			
			 
		   
      }
    };
    xmlhttp.open("GET","getuserlist.php?q="+str,true);
    xmlhttp.send();
  }
}

	
	
	

function multiply(str) {
 
	if(str == "")
		
		{
			document.getElementById("amount").value == "";
			return;
		}
	
		
else {   
		var qty =  parseInt(document.getElementById("qty").value) ;
		var total_amount = parseInt (document.getElementById("unit_p").value);
		
		
	var sum = qty*total_amount;
	document.getElementById("amount").value = sum;
		}   
		  
 
   
}
</script>
	

<?php


$app_name = $_SESSION['app_name'];
  $db_size = $_SESSION['db_size'];




$current_date = date("Y-m-d");
$activation_d = $_SESSION['activation_date'];
$expiration_d = $_SESSION['expiration_date'];
/*
$activation_d ="2013-03-15";
$expiration_d ="2013-03-30" ;

*/
//echo "<br>";


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



?>


<?php


$date1 = date_create("$current_date");

$date2 = date_create($expiration_d);

$date_diff = date_diff($date1,$date2);

  $date_diff->format("%a ")
	
	 ?>

<?php
	
	
if($date_diff->format("%R%a ") <0){
		
	header ("Location: expired_sub.php");
	}	
	  


if ($privilage == "suspend")
	
{
	echo $notification = "Suspended App";
	
	header ("Location: /login.php?txnfailed=$notification");
	//header ("Location: ../login.php?");
}



	
$notification = "";



if($date_diff->format("%a ") <=30){
		$notification = $date_diff->format("%a")."  "."days Remaining";
	}	
	
?>





<?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);




$SQL = "SELECT  date FROM txn_table ORDER BY product_id ASC  ";
											
$result = mysqli_query($db_handle, $SQL);
   $txn_nbr = mysqli_num_rows($result);
$progress = (mysqli_num_rows($result)/$db_size*100);





?>

<?php




if(isset($_POST['A']))
{
	
 
	$paymethod = $_POST['payment']; 
	
	//exit();
	
    $product = $_POST['product'];
	$amount = $_POST['amount'] ;
	$s_qty = $_POST['s_qty'] ;
	
	$customers = $_POST['customer'];
	
	
	
	if($progress <= $db_size)
	{
	
	
	
	
if($product=="" or $amount=="" or $s_qty=="" or $pm = ""){
	 $notification = 'OPERATION FAILED|| amount or quantity or product field is blank';
}
	
		else if($s_qty ==0){
			
			
				 $notification = 'OPERATION FAILED|| Qauntity Field cant be zero(0)';
		}
	
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'];
	
	$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,payment,customers_name, amount,unit_c,s_qty, user_id,month,year,time,date) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
			$SQL->bind_param('sssssssssss',$product,$paymethod,$customers,$amount,$gross_profit,$s_qty, $_SESSION['user_id'],$month,$year,$time,$date );
			$SQL->execute();
			//header ("Location: dashboard.php");
		

	
	
	
		 $notification = "operation successfull";
	
		
		
	}
	
	
	
	
	
	
	}
	

	
		}
	
	
	
	else {
		
		$notification = "OPERATION FAILD||database is filled";
	
	}
	
}



elseif(isset($_POST['B']))
{
	
 
	$paymethod = $_POST['payment']; 
	
	$expense = $_POST['expense']; 
	
	//exit();
	
    $product = $_POST['product'];
	$amount = $_POST['amount'] ;
	$s_qty = $_POST['s_qty'] ;
	
	$customers = $_POST['customer'];
	 
	
	
	if($progress <= $db_size) 
	{
	
	
	
	
if($product=="" or $amount==""  or $pm = ""){
	 $notification = 'OPERATION FAILED|| amount or quantity or product field is blank';
}
	
		
else{	
	
		//to select unit cost of goods sold from product database
	
		
	$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 );

	
		$SQLL = $db_found->prepare("INSERT INTO txn_table (product_name,type,payment,customers_name,amount,s_qty,user_id,month,year,time,date) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
			$SQLL->bind_param('sssssssssss',$product,$expense,$paymethod,$customers,$amount,$s_qty, $_SESSION['user_id'],$month,$year,$time,$date );
			$SQLL->execute();

			//header ("Location: dashboard.php");
		

	
	
	
		 $notification = "operation successfull";
	
		
		
	
	
	
	
	
	
	
	}
	

	
		}
	
	
	
	
	else {
		
		$notification = "OPERATION FAILD||database is filled";
	
	     }
	
}








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">
	
	
	<!-- import the webpage's javascript file -->
    <script src="script.js" defer></script>
	
	
	 <link rel="stylesheet" href="style.css" />
	
	
	
	
<!--===============================================================================================-->
	
</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-ottom: 16px solid red;
  border-left: 16px solid pink;
  width: 120px;
  height: 120px;
  -webkit-animation: spin 1s 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: <?php echo $bottom_backgroundcolor;  ?>;
		
}

		
	
            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= "<?php echo "customAlert.alert('$notification','$_SESSION[biz_name]<BR>$_SESSION[app_code]')"; ?>,unit_ac(),bulk_ac(),crude_ac(),view_ac(),spinner()">

	


	<!--newheader-->
	
	
	
	
	<!--new headeer-->
	
	
		<div class="jumbotron-fluid" style="background-color: #757672; color: #F0ECEC">
	
				
<?php 
		
	echo $_SESSION['name'].'   '.' (IDN '. $_SESSION['user_id'].' ) '.$date_diff->format("%a ")."days Left";
			
			

		?>
			<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>
	
	
			
<div class="jumbotron " style="background-color: <?php echo $background_color; ?>;  height: auto">
	
		<!--<div class="jumbotron " style="background-color: #EAFC2F;  height: auto">-->
	
	



	
	
			
		
			<div style="color: #FDFDF9; "><h4><b><marquee behavior="alternate"><span style="color: <?php echo $text_color; ?>"><?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='INCOME' onClick="view_ac()" class="btn btn-dark" style= "width: inherit; height: 70px" name = "A"  >
					
					
			
							</td>
	
							<td>
		
								<a href="report_wizard.php"><input type="button" onClick="spinner()" value="Report" class="btn btn-info" style= "width: ; height: 70px" name = "A" ></a>
				
							</td>
	
							<td>
		
								<a href="app_info.php"><input type="submit" value="APP info" class="btn btn-info" style= "width: inherit; height: 70px" name = "A" onClick="spinner()" ></a>
			
							</td>
	
	
	
				
						</tr>
		
					</table>
		
				</div>
	
    
			</div>
			
			
			
			<div class="row">
			
				<table style="margin: auto;width: auto" >
		
	
					<tr>
				
						<td>
					
					 
							<input type="submit" onClick="unit_ac()" value="EXPENSES" class="btn btn-dark" style= "width: inherit; height: 50px" name = "A" >
					
					
				
						</td>
	
						<td>
		
							<a href="inventory_ac.php"> <input type="submit" value="Inventory" onClick="spinner()" class="btn btn-info" style= "width: inherit; height: 50px" name = 
															   "A" ></a>
				
						</td>
	
						<td>
		 
							<a href="add_user.php"> <input type="submit" value="Add users" onClick="spinner()" class="btn btn-info" style= "width: inherit; height: 50px" name = "A"  ></a>
				
						</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-info" onClick=" spinner()" style= "width: inherit; height: 50px"  ></a>
					
					
				
						</td>
	
						<td>
		 
							<input type="button" value="Saved Receipts" class="btn btn-info" style= "width: inherit; height: 50px" name = "A" onClick="window.alert('inactive, www.lawped.com.ng)')" >
				
						</td>
	
						<td>
		 
							<a href="setup_ac.php"><input type="submit" value="Setup" class="btn btn-info" style= "width:inherit; height: 50px" name = "A" onClick= "spinner()" ></a>
				
						</td>
	
	
	
			
		
				</table>
	
			
		
				</tr>
			
	</div>
	
	<div class="row">
			
				<table style="margin: auto; width: auto"  >
		
	
					<tr>
				
						<td>
					
					 
							<a href="debtors.php"><input type="button" value="DEBT MGT" class="btn btn-info" onClick="spinner()" style= "width: inherit; height: 30px"  ></a>
					
					
				
						</td>

						<td>
		 
						<a href="database.php">	<input type="button" value="database" class="btn btn-info" style= "width: inherit; height: 30px" name = "A" onClick="spinner()"  > </a>
				
						</td>
	
						<td>
		 
							<a href="customers.php"><input type="submit" value="CUSTOMERS" class="btn btn-info" style= "width:inherit; height: 30px" name = "A" onClick="spinner()" ></a>
				
						</td>
	
	
	
			
		
				</table>
	
			
				</tr>
			
	</div>
	
	

			
	<div style="align-content: center; text-align: center; color:<?php echo $text_color; ?>">
		
		<?php echo $notification?> 
		
	
		
	</div>

	
	
	
	</div>
	

	
	<!--script to show recent inserted record-->
	
	
	
	<?php
			  //==================================================================================
			 //script to show recent inserted record
			//==================================================================================
	
	
	
	$SQL_recent = "SELECT * FROM txn_table ORDER BY product_id DESC LIMIT 1 ";
	
	$recent_record = mysqli_query($db_handle, $SQL_recent);
	
	$db_found_recent = mysqli_fetch_array($recent_record) ;
	// echo $db_found_recent['amount'];
	
	  //===================================================================================
	  		?>
	
	<div style="text-align:  center;background-color:#050404; font-size: 2px ">
		<h6> <marquee behavior="scroll" style="color: #F7E81B"> <?php echo "welcome to"."  ".$_SESSION['biz_name']." ||  ".'this App'."  ".$_SESSION['app_code']."  ".'will be inactive on the'."  ". $expiration_d." || "."we are into:".$_SESSION['biz_nature']."   || Company Role: $privilage" ?>
		</marquee></h6>
</div>
	<!--script to show recent inserted record-->
	<div style="text-align:  center;background-color:<?php echo $bottom_backgroundcolor;  ?>; width: inherit;  ">
		<h6 style="color:<?php echo $bottom_textcolor;  ?>">  <?php  echo $db_found_recent['product_name']." of 
	".$db_found_recent['amount'].'naira as @ '.$db_found_recent['time']." ". ' ('.$db_found_recent['date'].')'; ?>
		</h6>
</div>	


<div class="container-fluid" style="background-color:" >
	
<div class = "loader" id="spin" style="margin: auto; background-color: ">

</div>
	
	
	
		<div class="container-fluid" style="background-color:;padding-left: 0;padding-right: 0;" >
		

		
			<?php
		
		
		
		
	
		//	echo $dat = date("h:i") ;
		
		
			  $date = date("Y-m-d");
			  //==================================================================================
			 //this junk of code is to sum up daily transaction
			//==================================================================================
	  //$SQL_sum = "SELECT SUM(amount) FROM txn_table where date =current_date";
		// $SQL_sum = "SELECT SUM(amount) FROM txn_table where date = current_date";
		
		
			$SQL_sum = "SELECT SUM(amount), SUM(s_qty), SUM(unit_c) FROM txn_table  where date = '$date' and type = 'expense'";
	  
			$sum = mysqli_query($db_handle, $SQL_sum);
	  
			$db_found_exp = mysqli_fetch_assoc($sum) ;
	  //===================================================================================
		
			//===================================================
			//this code is used for the break even analyzise
			//====================================================
			
			
		
				
				
				
			//this set of codes are used to manipulate the daily account
			
				
			
			
		//	$gross_profit = $db_found_sum['SUM(unit_c)'];
			
			/*$net_profit = $gross_profit - $daily_bep;
			$adjusted_netprf = "";
			$remark = "";
			
			if($net_profit >0){
				
				$adjusted_netprf= $net_profit;
			}
			
				if($net_profit >0){
				
				$remark= "congratulations";
			}
			*/
			?>
		
		
		
			<div class="jumbotron-fluid" >
		
	
			
				<div class="row">
				
				
					<div class="col-md-12" style="padding-top: 8px; color:  <?php echo $bottom_textcolor;  ?>" id="unit_ac">
									
					
						<div class="row">
							<div class="col-md-4"> 
							
								<style="text-align: center; color: <?php echo $bottom_textcolor; ?>"><b> EXPENDITURE ACCOUNT AS @ <?php echo date("Y-m-d"); ?> </b></style>
								 <p></p>
						<div id="">
											
						
						<!--space for old pay in script-->
						
							
							
					
						<div id="">
											
						
							<form METHOD ="POST" ACTION = "dashboard.php" style="width: 100%">
							
								<table width="100%">
				
									<tr>
				
					
					
					
										<td>  <select class="custom-select"  style="width:"  id="inputGroupSelect03" name="product">
										
											<option selected>Select Expenses</option>
		
											<?php
											
											$SQL = "SELECT * FROM fixed_cost ORDER BY name ASC ";
											
											$result = mysqli_query($db_handle, $SQL);
											
											$i =1;

											
											while ( $db_found = mysqli_fetch_assoc($result) ) {
											
												echo'<option value="'. $db_found['name'].'">'. $db_found['name'].'</option>'; 
																									  }
		
											?>
											
											</select> 
					
										</td>
					
						 
							
										<td>
											
											
											
						 			<select class="custom-select"  style="width:100%"  id="inputGroupSelect03" name="customer">
										
											<option selected>Anonymous</option>
		
											<?php
											
											$SQL_customer = "SELECT * FROM customers_table where type ='supplier' ORDER BY name ASC ";
											
											$result = mysqli_query($db_handle, $SQL_customer);
											
											$i =1;

											
											while ( $db_found = mysqli_fetch_assoc($result) ) {
											
												echo'<option value="'. $db_found['name'].'">'. $db_found['name'].'</option>'; 
																									  }
		
											?>
											
											</select> 												
						 					
										</td>
										
										



  <p style=" color:<?php echo $bottom_textcolor; ?>">Payment Method<br>
  <input type="radio" id="html" name="payment" value="Cash" checked>
  <label for="html" style=" color:<?php echo $bottom_textcolor; ?>">Cash</label>
  <!--<input type="radio" id="css" name="fav_language" value="CSS">
  <label for="css">POS</label>-->
  <input type="radio" id="javascript" name="payment" value="transfer">
  <label for="javascript" style=" color:<?php echo $bottom_textcolor; ?>">Bank Transfer</label>

 


										
											<td>
						 	  <input type= "number" style="width:100%" placeholder="0.00" class="form-control" aria-label="Amount (to the nearest dollar)" name="amount">
												
												<input type= "hidden"  value="expense" style="width:100%" placeholder="0.00" class="form-control" aria-label="Amount (to the nearest dollar)" name="expense">
												
						 	  
											
						 											
						 					
										</td>
									</tr>
			
								</table>
							
								<tr>
								
										<td>  
									
				<!--	<input type= "text" cols="40" rows = "5" style="width:100%" placeholder="description" class="form-control" aria-label="Amount (to the nearest dollar)" name="s_qty">-->
											
											<textarea cols="50" rows = "3" style="width:100%" placeholder="Description" class="form-control" aria-label="Amount (to the nearest dollar)" name="s_qty"></textarea>
										</td>
					
						 
								<td>
									
									<p></p>
							
									<input type="submit" value="Pay Out (OutFlow)" onClick="spinner(), unit_ac()" class="btn-dark" style= "width: 100%" name = "B" >
								</td>
								
								
								</tr>
										
								
							</form>
							
							
							
						</div>	
											
						
						
							
						
							
						</div>	
							
							
							</div>
							
							<div class="col-md-8 ">
								
										<table width="100%" style="color:<?php echo $bottom_textcolor;?>">
							
  <tbody>
	  
   
	 
    <tr>
      <td>Total Expenditure  </td>
      <td>	<span class= "badge-dark">  <a href="transaction.php" onClick="spinner(),unit_ac()">   <input type="button" value=" <?php     echo  $db_found_exp['SUM(amount)'];   ?>">  </a></span> </td>
    </tr>
  
  </tbody>
</table>
								
								
								<div class="scroll">
	
							<table class="table  table-hover" style="font-size:12; width:100%  " >
  
								<tbody>
    
									<tr  style="background-color: red; text-align: center; color: ghostwhite">
      
										<th scope="col">s/n</th>
	
										<th scope="col">Invoice No: </th>
										
										<th scope="col">IDN</th>
      
										<th scope="col">Expenditure</th>
										<th scope="col">Payment</th>
										
										<th scope="col">Supplier</th>
		 
		<!-- <th scope="col">DESCRIPTION</th>-->
	
		   
										<th scope="col">Amount</th>
										<!--<th scope="col">Gross Profit</th>-->
										<!--<th scope="col">QTY</th>-->
		
										
		 
										<th scope="col">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 expens_tb   where date= '$date' and type = 'expense' ORDER BY product_id DESC";

										$SQL = "SELECT *FROM txn_table   where date= '$date' and type = 'expense' ORDER BY product_id 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:blue" >';

	
	
										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['payment'].'</td>';
										
										echo '<td>'.$db_found['customers_name'].'</td>';
		
										echo '<td>'.$db_found['amount'].'</td>';
									
		
										
										
	
										echo '<td>'.$db_found['time'].'</td>';
										
										
					
	 
	
									?>
									<?php
	
										echo '</tr>';

	
	

									}

	  
			
									?>
	

								</tbody>

							</table>
						
								
								</div>
								
								
								
								
							</div>
						
						
						</row>
						
						
						
					</div>
										
					
					
					
					<div class="col-md-1" 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 = "dashboard.php" style="width: 100%">
						
							<table width="100%">
				
								<tr>
				
					
					
					
									<td>  
					
										<input type="text" class="form-control" name="amount" placeholder="Amount" aria-label="Recipient's username" aria-describedby="basic-addon2">
					
									</td>
					
									<td>
					
				
					 
										<input type="submit" value="SAVE" class="btn-dark" style= "width: 100%" name = "A" >
										
									</td>
						 
												
						 												
						 
							
								</tr>
			
							</table>
			
											
							
						</form>
				
					</div>


				
				</div>
		
		
		</div>
		
		
		
		
		
			<?php
		
		
		
		
	
		//	echo $dat = date("h:i") ;
		
		
			  $date = date("Y-m-d");
			  //==================================================================================
			 //this junk of code is to sum up daily transaction
			//==================================================================================
	  //$SQL_sum = "SELECT SUM(amount) FROM txn_table where date =current_date";
		// $SQL_sum = "SELECT SUM(amount) FROM txn_table where date = current_date";
		
		
			$SQL_sum = "SELECT SUM(amount), SUM(s_qty), SUM(unit_c) FROM txn_table  where date = '$date' and type = ''";
	  
			$sum = mysqli_query($db_handle, $SQL_sum);
	  
			$db_found_sum = mysqli_fetch_assoc($sum) ;
	  //===================================================================================
		
			//===================================================
			//this code is used for the break even analyzise
			//====================================================
			$SQL_break_even = "SELECT SUM(amount/30) FROM fixed_cost  ORDER BY name ASC   ";
			 $result_break_even = mysqli_query($db_handle, $SQL_break_even);
			$db_found_even = mysqli_fetch_assoc($result_break_even)
				
		
			
		
	  		?>
		
	  <?php     
				
				
				
			//this set of codes are used to manipulate the daily account
			
				
				$daily_bep =round( $db_found_even['SUM(amount/30)']);  
			//$daily_bep = round($daily_bep_ped);
			
			$gross_profit = $db_found_sum['SUM(unit_c)'];
			
			$net_profit = $gross_profit - $daily_bep;
			$adjusted_netprf = "";
			$remark = "";
			
			if($net_profit >0){
				
				$adjusted_netprf= $net_profit;
			}
			
				if($net_profit >0){
				
				$remark= "congratulations";
			}
			
			?>
		
		
			<div class="jumbotron-fluid" style="background-color: " id="view_ac">
		
			
				<div class="row " style="margin-top: 1px; background-color:">
		
			
					
					<!--to pay in script-->
				
					
					
					
					<div class = "col-md-3 " style="color: <?php echo $bottom_textcolor;  ?>;padding: 10px;">
				
							<style="text-align: center; color:"><b>INCOME ACCOUNT AS @ <?php echo date("Y-m-d"); ?> </b></style>
								 <p></p>
						
						
							<form METHOD ="POST" ACTION = "dashboard.php" style="width: 100%">
							
								
								
								
								<table width="100%">

									
									<tr>
									
									
  <p style=" color:<?php echo $bottom_textcolor; ?>">Payment Method<br>
										
  <input type="radio" id="html" name="payment" value="Cash" checked>
  <label for="html" style=" color:<?php echo $bottom_textcolor; ?>">Cash</label>
  <!--<input type="radio" id="css" name="fav_language" value="CSS">
  <label for="css">POS</label>-->
  <input type="radio" id="javascript" name="payment" value="Transfer">
  <label for="javascript" style=" color:<?php echo $bottom_textcolor; ?>">Bank Transfer</label>

 	
	 
	  

										<div id ="txtHint" style="color:<?php echo $bottom_textcolor;  ?>"> 
											
											

											
										
	
											</div>
										
										
									
									</tr>
									
									
									<tr>
				
					
										
										<td>
										
										<select class="custom-select"  style="width:100%;background-color: #AFB5F8"   name="product" id="product"  >
										
											<option value="" selected>Customers</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> 
										</td>
					
					
										<td>  
											<select class="custom-select"  style="background-color:yellow"   name="product" id="product" onchange="showUser(this.value) " >
										
											<option value="" selected>Category</option>
		
											<?php
											
											$SQL = "SELECT  DISTINCT cat_name FROM product_cat ORDER BY product_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['cat_name'].'">'. $db_found['cat_name'].'</option>'; 
																									  }
		
											?>
											
											</select> 
					
										</td>
					
						 
										
										
										<td  id="cat">
										
											
											
										</td>
										
										

										
									</tr>
			
								
								</table>
									
						<table>
								<tr>
								
										<td>  
											 		<input type= "number" style="width:100%;background-color: #EBE7E7" placeholder="QTY" class="form-control" aria-label="Amount (to the nearest dollar)" name="s_qty" onkeyup="multiply(this.value)"  id="qty">
						 													
					
										</td>
						<td>
						 	  
	
												
												
												
											<input type= "number" style="width:100%;background-color: #EBE7E7" placeholder="0.00" class="form-control" aria-label="Amount (to the nearest dollar)" name="amount" id="amount">
						 													
						 					
										</td>
						 
								
								
								
								</tr>
										
								</table>
								
								<table>
								<tr>
									
									<p></p>
							
									<input type="submit" value="PAY IN(Inflow)" onClick="spinner(),view_ac()" class="btn-dark" style= "width: 100%; float: right" name = "A" >
							</tr>
						</table>
						
					</div>	
					
						</form>
						
					
					
					
					
					
					
					
					<div class = "col-md-4 " style="background-color:;padding: 10px">
				 
						<strong ><span style="color:<?php echo $bottom_textcolor;  ?>";>
							
					
									 
						
								 
						<table width="100%" style="color:<?php echo $bottom_textcolor;?>">
							
  <tbody>
	   <tr>
      <td>Total Vol/Qty</td>
      <td> <span class= "badge-dark">  <?php     echo $db_found_sum['SUM(s_qty)'];   ?>   </span> </td>
    </tr>  
   
    <tr>
      <td>Total Sales </td>
      <td>	<span class= "badge-dark">   <?php     echo "  ".$db_found_sum['SUM(amount)']."  ";   ?>    </span></td>
    </tr>
    <tr>
      <td>Gross Profit</td>
      <td> <span class= "badge-dark">   <?php     echo $gross_profit;   ?>   </span> </td>
    </tr>
	  
	  <tr>
      <td>Total Expenses</td>
      <td> <span class= "badge-dark">   <?php    echo $db_found_exp['SUM(amount)'];  ?>   </span> </td>
    </tr>
	  <?php
	  
	  $net = $gross_profit - $db_found_exp['SUM(amount)'];
	   $net_pb = $gross_profit - $db_found_exp['SUM(amount)'];
	  if($net >0){
		  $net = $net;
		   $remak = "congratulations";
	  }
	  
	  else{
		  $net = "";
		  $remak = "loss";
		  $net_pb = 0;
	  }
	  
	  ?>
	   <tr>
      <td>Net Profit</td>
      <td> <span class= "badge-dark">   <?php    echo $net;  ?>   </span> </td>
    </tr>
	  
	 
	 
	  
	  
	  
	  <tr>
      <td>Remark</td>
      <td> <span class= "badge-dark">   <?php    echo $remak;  ?>   </span> </td>
    </tr>
	  
	 
	  
    <tr>
      <td>Daily Break Even Point</td>
      <td> <span class= "badge-dark">   <?php     echo $daily_bep;  ?>    </span> </td>
    </tr>
	  
	    <tr>
			<?php
			$pab = $net_pb - $daily_bep;
				
				if ($pab<0)
				{
					$pab= "";
				}
			?>
			
			
      <td>Profit After B.E.P</td>
      <td> <span class= "badge-dark">   <?php echo $pab;   ?>    </span> </td>
    </tr>
	  
	  
	
  </tbody>
</table>

							
							
			
							
							
							
							
							
							
							
							
						
				   </span></strong>
			
			  
						<div class="jumbotron-fluid scroll" style="font-size:12; ">
				  
	  
							<table class="table table-dange table-hover" style="font-size:12; width:100% ;color: <?php echo $bottom_textcolor  ?>" >
  
								<tbody style="color:;bottom_textcolor">
    
									<tr  style="background-color: ; text-align: center; color: ">
      
										<th scope="col">S/N</th>
		
										<!--<th scope="col">TRN ID</th>-->
      
										<th scope="col">Description</th>
		
										<!-- <th scope="col">DESCRIPTION</th>-->
	
		   
										<th scope="col">Total Sales</th>
										<th scope="col">Gross Profit</th>
										<th scope="col">QTY</th>
										
		
     
    
									</tr>
 			
		



									<?PHP

	  
	  
//$SQL = "SELECT * FROM txn_table where date= current_date ORDER BY product_id DESC   ";
//$SQL = "SELECT  product_name,product_id,  SUM(amount) FROM txn_table   where date= current_date GROUP BY product_name  ORDER BY product_id DESC";

	  
									$SQL = "SELECT  product_name,product_id,SUM(amount),SUM(unit_c),SUM(s_qty) FROM txn_table   where date= '$date' and type = '' GROUP BY product_name  ORDER BY product_id DESC";

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

									$i =1;
	  


									while ( $db_found = mysqli_fetch_assoc($result) ) {
	   
	
										echo'<tr style="text-align: center;background-color:; color: echo $text_color " >';
     // echo '<td>'.$db_found['user_id'].'</td>';
	
	
	
										echo '<td>'.$i++.'</td>';
	// echo '<td>'.$db_found['product_id'].'</td>';
	 
										echo '<td>'.$db_found['product_name'].'</td>';
	
	
	// echo '<td>'.'<a href="www.lawped.com.ng?id=$db_found['product_id']">details</a>'.'</td>';
	
	// $db_found_sum['SUM(amount)'];
	
	//echo '<td>'.$db_found['amount'].'</td>';
	
										echo '<td>'.$db_found['SUM(amount)'].'</td>';
										//echo '<td>'.$db_found['SUM(amount-s_qty*unit_c)'].'</td>';
										echo '<td>'.$db_found['SUM(unit_c)'].'</td>';
										echo '<td>'.$db_found['SUM(s_qty)'].'</td>';
										
										
	
	//echo $db_found_sum['SUM(amount)']; 
	 
  
   
   
										echo '</tr>';

	
	
}

//}
//else {

//print "Database NOT Found ";

//}
//mysqli_close($db_handle);
	  
			
									?>
	
	
	
	
	
  
								</tbody>

							</table>
						
	
	
	
						</div>

					
					</div>
						
			
					<div class = "col-md-5 " style="background-color: #494747">
				  	
						<strong ><span style="color:#FAF7FF;padding: 4px"><br>Transaction History<a href="transaction.php" onClick="spinner(),view_ac()"><input type="button" value="<?php echo $txn_nbr?>mb"></a>
					    
							</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">Payment</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>
										
		
     
    
									</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 date= '$date' and type = '' ORDER BY product_id 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['payment'].'</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['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>
	  
	   
									<td><a href="record_delete.php?txnId=<?php echo $db_found["product_id"]?>">
   
										<input type="button" value="Delete" onClick="spinner(), view_ac()"></a></td>
	
	  -->
									<?php
	
										echo '</tr>';

	
	

									}

									mysqli_close($db_handle);
	  
			
									?>
	

								</tbody>

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

		</div>
	
	

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



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

