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

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


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



											/*$SQ = "SELECT product_name, unit_c FROM product_table where product_name = 'laptop' ";
											
											$resul = mysqli_query($db_handle, $SQ);
											$db_foun = mysqli_fetch_assoc($resul);
											echo $unit_qty_cost = $db_foun['unit_c'].'<br>';
*/

											


?>



<!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>
	
	
	
	
	<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:;
}

	
		
	
            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(),unit_ac(),bulk_ac(),crude_ac(),view_a()">


	
	
	<!--newheader-->
	
	
	
	
	<!--new headeer-->
	
	
	<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>

	
	
	
	<div class="jumbotron" style="background-color:  <?php echo $background_color; ?>; height: auto">
			
			
<div class="loader" id="spin" style="margin: auto"></div>		
			
			
			<div style="color:; text-align:  center  "><h4><b><span style="color: <?php echo $text_color; ?> "><?php echo $_SESSION['biz_name']; ?></span></b></h4></div>
	
	
		
		<div class="row">
		
				<div class="col-md-12" id="">
			
					<table style="margin: auto; width: auto" >
		
	
						<tr>
				
							<td>
					
					
								<input type="submit" value='DAYS' onClick="unit_ac()" class="btn btn-info" style= "width: inherit; height: 70px" name = "A"  >
					
					
			
							</td>
	
							<td>
		
								<input type="button" onClick="bulk_ac()" value="MONTHS" class="btn btn-info" style= "width: ; height: 70px" name = "A" >
				
							</td>
	
							<td>
		
								<input type="submit" value="YEAR" class="btn btn-info" style= "width: inherit; height: 70px" name = "year" onClick="crude_ac()" >
			
							</td>
	
	
	
				
						</tr>
		
					</table>
		
				</div>
	
    
			</div>
			
			
			
		
		<div class="row">
			
				<table style="margin: auto;width: auto" >
		
	
					<tr>
				
						<td>
					
					 
							<input type="submit" onClick= "window.print()" value="Print" class="btn btn-danger" style= "width: inherit; height: 70px" name = "A" >
					
					
				
						</td>
	
						<td>
		
							 <input type="submit" value="Download" class="btn btn-danger" onClick="window.print()" style= "width: inherit; height: 70px" name = 
															   "A" >
				
						</td>
	
						<td>
		 
						<a href="dashboard.php">	<input type="submit"  onClick="spinner()"  value="Home" class="btn btn-danger" style= "width: inherit; height: 70px" name = "A"  ></a>
				
						</td>
	
	
	
					</tr>
			
			
				</table>
		
		
			
			</div>
				
	
		
			
	
	</div>
	
	
	<!--cscript to accounts and transaction history-->
	
	

	
	
	
		

	<div class="container-fluid" >
		
		
		
		
			<div class="jumbotron-fluid" style="background-color: ">
		
		
			
				<div class="row">
				
				
					<div class="col-md-4" style="padding-top: 8px" id="unit_ac">
					
						<div id="">
											
						
							<form METHOD ="POST" ACTION = "report_wizard.php" style="width: 100%">
							
								<table width="100%">
				
										<tr>
				
					
					
				
											<td>  <select class="custom-select"  style="width:"  id="inputGroupSelect03" name="product">
										
											<option selected><?php  echo 'Select work days';   ?></option>
		
											<?php
											
											$SQL = "SELECT DISTINCT date FROM txn_table ORDER BY date DESC  ";
											
											$result = mysqli_query($db_handle, $SQL);
											
											$i =1;

											
											while ( $db_found = mysqli_fetch_assoc($result) ) {
											
												echo'<option value="'. $db_found['date'].'">'. $db_found['date'].'</option>'; 
																									  }
		
											?>
											
											</select> 
					
										</td>
					
									<td>
					
				
					 
										<input type="submit" value="GENERATE" class="btn-dark" style= "width: 100%" name = "A" onClick="spinner()" >
										
									</td>
						 
												
						 												
						 
							
								</tr>
			
								</table>
			 
							
								
							</form>
							
						</div>	
											
						
					</div>
										
					
					
					<div class="col-md-4" style="padding-top: 8px" id="bulk_ac">
 
						<form METHOD ="POST" ACTION = "report_wizard.php" style="width: 100%">
						
							<table width="100%">
				
								<tr>
				
					
					
					
									<td> 
										<select class="custom-select"  style="width:"  id="inputGroupSelect03" name = "man">
										
											<option selected >Select Year</option>
		
											<?php
											
											$SQL_year = "SELECT  DISTINCT year FROM txn_table ORDER BY product_id ASC ";
											
											$result = mysqli_query($db_handle, $SQL_year);
											
											$i =1;

											
											while ( $db_found = mysqli_fetch_assoc($result) ) {
											
												echo'<option value="'. $db_found['year'].'">'. $db_found['year'].'</option>'; 
																									  }
		
											?>
											
											</select> 
					
										</td>
					
									<td>  <select class="custom-select"  style="width:"  id="inputGroupSelect03" name="month">
										
											<option selected>Select Month</option>
		
											<?php
											
											$SQL = "SELECT DISTINCT month FROM txn_table 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['month'].'">'. $db_found['month'].'</option>'; 
																									  }
		
											?>
											
											</select> 
					
										</td>
						 
												
						 												
						 
							
								</tr>
			
							</table>
			 
							<input type="submit" value="GENERATE" class="btn-info" style= "width: 100%" name = "crude" onClick="spinner()" >
											
							
						</form>
						
					</div>
					
										
								
				
					<div class="col-md-4" style="padding-top: 8px; background-color:" id="crude_ac"  >
					
 
						<form METHOD ="POST" ACTION = "report_wizard.php" style="width: 100%">
						
							<table width="100%">
				
								<tr>
				
					
					
					<td>  <select class="custom-select"  style="width:"  id="inputGroupSelect03" name="yea">
										
											<option selected>Select Business Year</option>
		
											<?php
											
											$SQL = "SELECT DISTINCT year FROM txn_table 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['year'].'">'. $db_found['year'].'</option>'; 
																									  }
		
											?>
											
											</select> 
					
										</td>
					
									<td>
					
				
					 
										<input type="submit" value="GENERATE" class="btn-dark" style= "width: 100%" name = "year" onClick="spinner()" >
										
									</td>
						 
												
						 												
						 
							
								</tr>
			
							</table>
			
											
							
						</form>
				
					</div>


				
				</div>
		
		
		</div>
		
		
		
		<!--open-->
		
			<?php
		

		
			 echo  $date = date("Y-m-d");
	
		
			$SQL_sum = "SELECT SUM(amount), SUM(s_qty), SUM(unit_c) FROM txn_table where date = '$date'";
	  
			$sum = mysqli_query($db_handle, $SQL_sum);
	  
			$db_found_sum = mysqli_fetch_assoc($sum) ;
	
			
			
			
		
		
	  		?>
		
	
			<?PHP
		
			echo '<div class="jumbotron-fluid" style="background-color: " id="view_ac">';
		
				?>
			
			<div class="row " style="margin-top: 1px; background-color:">
	
			
			
				<div class = "col-md-6 " style="background-color:;padding: 10px">
				 
			  
			<?php
					echo	'<div class="jumbotron-fluid scroll" style="font-size:12; ">';
				  	
						echo	'<table class="table table-danger table-hover" style="font-size:12; width:100%  " >';
  
							echo	'<tbody>';
    
								
 			
		



								
//this script is for per day report search only
	  
	  								if(isset($_POST['A'])){
										
		    $product = $_POST['product'];
										
			//$Ist_date = '2022-07-25';
			//$second_date = '2022-07-28';
										
			$SQL_sum = "SELECT SUM(amount), SUM(s_qty), SUM(unit_c) FROM txn_table where date = '$product'";
			
				//$SQL_sum = "SELECT SUM(amount), SUM(s_qty), SUM(unit_c) FROM txn_table where date  BETWEEN '$Ist_date' AND '$second_date'";							
	  
			$sum = mysqli_query($db_handle, $SQL_sum);
	  
			$db_found_sum = mysqli_fetch_assoc($sum) ;
	
										
										//this set of codes are used to manipulate the daily account
			$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);
										
			$daily_bep = $db_found_even['SUM(amount/30)'];  
			
			
			$gross_profit = $db_found_sum['SUM(unit_c)'];
			
			$net_profit = $gross_profit - $daily_bep;
			$adjusted_netprf = "";
			$remark = "fail";
			
			if($net_profit >0){
				
				$adjusted_netprf= $net_profit;
			}
			
										
							if($net_profit >0){
				
				$remark= "congratulations";
			}
										
										
										
										
										
										echo '<strong >'.'<span style="color:#260B4D;color: #086310;padding: ">'.'ACCOUNT AS @'.$product. '<br>';
								
										
									echo	'<br> Total Sales( '. $db_found_sum['SUM(amount)']. ')';
							
							echo '<br>Gross Profit('.  $gross_profit .')';
							
							
							
							echo '<br>Break Even Point('.  $daily_bep.')';
							
							
							
							
							echo '<br>Net Profit('. $adjusted_netprf.')';
										
										echo '<br>Remark:'. $remark;
										
										
							
							
										
									
										echo	'<br>Total Qty/Vol  ( '.  $db_found_sum['SUM(s_qty)'].' )    </span></strong>';
		
										
										echo '<tr>';
											
						
										
										
	
										
									

		
			$SQL_sum = "SELECT SUM(amount), SUM(s_qty), SUM(unit_c) FROM txn_table where date = '$product'";
	  
			$sum = mysqli_query($db_handle, $SQL_sum);
	  
			$db_found_sum = mysqli_fetch_assoc($sum) ;
	
			
		
			
						
																
										echo 	'<table class="table  table-hover" style="font-size:12; width:100%  " >';
  									
										echo '<tr  style="background-color: ; text-align: center; color: black">';
      
									
										echo 	'<th scope="col">s/n</th>';
	
									
										echo 	'<th scope="col">Description </th>';
										
									 
										echo 	'<th scope="col">Total Sales</th>';
      
									
										echo 	'<th scope="col">Gross Profit</th>';
										
										echo 	'<th scope="col">Quantity/Vol</th>';
		 

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

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

									$i =1;
	  
echo "<p></p>";
echo "<b>PRODUCT/SERVICE BASED RETURNS</b>";
									while ( $db_found = mysqli_fetch_assoc($result) ) {
	   
	
										echo'<tr style="text-align: center;background-color:; color:black" >';
   
	
	
										echo '<td>'.$i++.'</td>';
	
	 
										echo '<td>'.$db_found['product_name'].'</td>';
	
	
	

	
	//echo '<td>'.$db_found['amount'].'</td>';
	
										echo '<td>'.$db_found['SUM(amount)'].'</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>';

	
			
									}

							echo '</tbody>';

							echo '</table>';
						
										
										
								//===========================================================================
									
	
	
	
	
	
  
	
	
					echo	'</div>';

					?>
						</div>
				
										
				
						<div class="col-md-6">
<B>CLIENT BASED RETURNS</B>
				<div class=" scroll" >
					
					
			<?php
									
										
					echo 	'<table class="table  table-hover" style="font-size:12; width:100%  " >';
  									
										echo '<tr  style="background-color: ; text-align: center; color: black">';
      
									
										echo 	'<th scope="col">s/n</th>';
	
									
										echo 	'<th scope="col">Name of Client </th>';
										
									 
										echo 	'<th scope="col">Total Sales</th>';
      
									
										echo 	'<th scope="col">Gross Profit</th>';
										
										echo 	'<th scope="col">Quantity/Vol</th>';
		 

										
										
										
										
										
	  
									$SQL = "SELECT  customers_name,product_id,SUM(amount),SUM(unit_c),SUM(s_qty) FROM txn_table   where date= '$product' GROUP BY customers_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:black" >';
   
	
	
										echo '<td>'.$i++.'</td>';
	
	 
										echo '<td>'.$db_found['customers_name'].'</td>';
	
	
	

	
	//echo '<td>'.$db_found['amount'].'</td>';
	
										echo '<td>'.$db_found['SUM(amount)'].'</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>';

	
			
									}

							echo '</tbody>';

							echo '</table>';
						
										
										
							//===========================================================================
							// end of returns based on clients		
	
		?>
					
				</div>
				</div>
					
				</div>
			
			
			<!--this is the transaction table of the code-->
			<div class="row">
			
					<div class = "col-md-12 " style="background-color: #494747">
			
				  	
						<strong > <span style="color:red;padding: 4px; background-color:"> <br>TRANSACTION HISTORY
					    
						</span> </strong>
				
					
					<div class="jumbotron-fluid scroll_history" style="font-size:12; ">
				  
				  
				 
	  
						<table class="table  table-hover" style="font-size:12; width:100%  " >
  
								<tbody>
    
								<tr  style="background-color: #99DBFB; text-align: center; color: #000000">
      
										<?php
										
										echo '<th scope="col">s/n</th>';
	
										echo '<th scope="col">Transaction ID </th>';
										
										echo '<th scope="col">IDN</th>';
      
										echo '<th scope="col">Description</th>';
										
										echo '<th scope="col">Customers</th>';
		 
		
	
		   
										echo '<th scope="col">Total Sale</th>';
										echo '<th scope="col">Gross Profit</th>';
										echo '<th scope="col">QTY/VOL</th>';
		
										
		 
										echo '<th scope="col">TIME</th>';
										
			
     
    
									echo '</tr>';
 			
		



//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  product_name,product_id,user_id, amount,time,s_qty,unit_c,customers_name FROM txn_table   where date= '$product'  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:black; background-color: #C3EFA0" >';

	
	
										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['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>-->
	  
	  
	  
									<?php
	
										echo '</tr>';

	
	

									}

										
									
								echo '</tbody>';

							echo '</table>';
						
									mysqli_close($db_handle);
	  	?>
	
					</div>
			
			</div>
			
		
				</div>
		
		
						
			</div>
	
										</div>
		
		<!--open-->
			
		
	
	
	
	
	<!--second report works-->
	

	
<?php
										
										
											}
									
				
					
					
					
					
					
				
					
					
		
					else if(isset($_POST['year'])){
										
		     $product = $_POST['yea'];
			$SQL_sum = "SELECT SUM(amount), SUM(s_qty), SUM(unit_c) FROM txn_table where year = '$product'";
	  
			$sum = mysqli_query($db_handle, $SQL_sum);
	  
			$db_found_sum = mysqli_fetch_assoc($sum) ;
						
						
						
						
						
						
											
										//this set of codes are used to manipulate the daily account
			$SQL_break_even = "SELECT SUM(amount*12) 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);
										
			$daily_bep = $db_found_even['SUM(amount*12)'];  
			
			
			$gross_profit = $db_found_sum['SUM(unit_c)'];
			
			$net_profit = $gross_profit - $daily_bep;
			$adjusted_netprf = "";
			$remark ="fail";
			if($net_profit >0){
				
				$adjusted_netprf= $net_profit;
			}
			
						
						
					
							if($net_profit >0){
				
				$remark= "congratulations";
			}
										
						
										
										
											
									
						echo '<strong >'.'<span style="color:#260B4D;color: #086310;padding: ">'.'ACCOUNT AS @'.$product. '<br>';
								
										
								
						echo	'<br> Total Sales( '. $db_found_sum['SUM(amount)']. ')';
							
						
						echo '<br>Gross Profit('.  $gross_profit .')';
							
							
							
							
						echo '<br>Break Even Point('.  $daily_bep.')';
							
							
							
							
							
						echo '<br>Net Profit('. $adjusted_netprf.')';
						
							echo '<br>Remark:'. $remark;
						
						
						echo	'<br>Total Qty/Vol  ( '.  $db_found_sum['SUM(s_qty)'].' )    </span></strong>';
		
										
						
						echo '<tr>';
											
						
										
										
	
										
									
	
		
			$SQL_sum = "SELECT SUM(amount), SUM(s_qty), SUM(unit_c) FROM txn_table where year = '$product'";
	  
			$sum = mysqli_query($db_handle, $SQL_sum);
	  
			$db_found_sum = mysqli_fetch_assoc($sum) ;
	
			
			echo "<p></p>";
			echo "<b>PRODUCT/SERVICE BASE RETURN</b>";
						
																
										echo 	'<table class="table  table-hover" style="font-size:12; width:100%  " >';
  									
										echo '<tr  style="background-color: ; text-align: center; color: black">';
      
									
										echo 	'<th scope="col">s/n</th>';
	
									
										echo 	'<th scope="col">Description </th>';
										
									 
										echo 	'<th scope="col">Total Sales</th>';
      
									
										echo 	'<th scope="col">Gross Profit</th>';
										
										echo 	'<th scope="col">Quantity/Vol</th>';
		 

										
										
										
										
										
	  
									$SQL = "SELECT  product_name,product_id,SUM(amount),SUM(unit_c),SUM(s_qty) FROM txn_table   where year= '$product' 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:black" >';
   
	
	
										echo '<td>'.$i++.'</td>';
	
	 
										echo '<td>'.$db_found['product_name'].'</td>';
	
	
	

	
	//echo '<td>'.$db_found['amount'].'</td>';
	
										echo '<td>'.$db_found['SUM(amount)'].'</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>';

	
			
									}

							echo '</tbody>';

							echo '</table>';
						
										
										
								//===========================================================================
									
	
	
	
	
	
  
	
	
					echo	'</div>';

					?>
						</div>
				
										
				
	<div class="col-md-6">
	<b> CLIENT BASED RETURNS </b>
		<div class="scroll">
			
			<?php	
																
										echo 	'<table class="table  table-hover" style="font-size:12; width:100%  " >';
  									
										echo '<tr  style="background-color: ; text-align: center; color: black">';
      
									
										echo 	'<th scope="col">s/n</th>';
	
									
										echo 	'<th scope="col">Clients </th>';
										
									 
										echo 	'<th scope="col">Total Sales</th>';
      
									
										echo 	'<th scope="col">Gross Profit</th>';
										
										echo 	'<th scope="col">Quantity/Vol</th>';
		 

										
										
										
										
										
	  
									$SQL = "SELECT  customers_name,product_id,SUM(amount),SUM(unit_c),SUM(s_qty) FROM txn_table   where year= '$product' GROUP BY customers_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:black" >';
   
	
	
										echo '<td>'.$i++.'</td>';
	
	 
										echo '<td>'.$db_found['customers_name'].'</td>';
	
	
	

	
	//echo '<td>'.$db_found['amount'].'</td>';
	
										echo '<td>'.$db_found['SUM(amount)'].'</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>';

	
			
									}

							echo '</tbody>';

							echo '</table>';
						
					
		?>
		
		</div>
		
	
	</div>
		
		
					
				</div>
			
	
	
	
			<!--this is the transaction table of the code-->
			<div class="row">
			
					<div class = "col-md-12 " style="background-color: #494747">
			
				  	
						<strong > <span style="color:red;padding: 4px; background-color:"> <br>TRANSACTION HISTORY
					    
						</span> </strong>
				
					
					<div class="jumbotron-fluid scroll_history" style="font-size:12; ">
				  
				  
				 
	  
						<table class="table  table-hover" style="font-size:12; width:100%  " >
  
								<tbody>
    
								<tr  style="background-color: lightgrey; text-align: center; color: black">
      
										<?php
										
										echo '<th scope="col">s/n</th>';
	
										echo '<th scope="col">Transaction ID </th>';
										
										echo '<th scope="col">IDN</th>';
      
										echo '<th scope="col">Description</th>';
						echo '<th scope="col">Customers</th>';
		 
		
	
		   
										echo '<th scope="col">Total Sale</th>';
										echo '<th scope="col">Gross Profit</th>';
										echo '<th scope="col">QTY/VOL</th>';
		
										
		 
										echo '<th scope="col">TIME</th>';
								echo '<th scope="col">DATE</th>';
										
			
     
    
									echo '</tr>';
 			
		



//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  product_name,product_id,user_id, amount,time,s_qty,unit_c,date,customers_name FROM txn_table   where year= '$product'  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:black; background-color: orange" >';

	
	
										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>';
										
										
	 
	 
	
									?>
<!--	  
  <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>-->
	  
	  
	  
									<?php
	
										echo '</tr>';

	
	

									}

										
									
								echo '</tbody>';

							echo '</table>';
						
									mysqli_close($db_handle);
	  	?>
	
					</div>
			
			</div>
			
			
		
				</div>
		
		
			</div>
	
										</div>
		
		<!--open-->
			
		
	
	
	
	
	<!--second report works-->
	

	
<?php
										
										
											}
					
					
					
					else if(isset($_POST['crude'])){
						
						
						
									  $year = $_POST['man'];
	
						
					$month = $_POST['month'];
										
						
										
		   // $product = $_POST['product'];
			//$SQL_sum = "SELECT SUM(amount), SUM(s_qty), SUM(unit_c) FROM txn_table where year = '$product'";
	  	$SQL_sum = "SELECT SUM(amount), SUM(s_qty), SUM(unit_c) FROM txn_table where year = '$year' && month ='$month'  ";
			$sum = mysqli_query($db_handle, $SQL_sum);
	  
			$db_found_sum = mysqli_fetch_assoc($sum) ;
						
						
						
						
						
						
											
										//this set of codes are used to manipulate the daily account
			$SQL_break_even = "SELECT SUM(amount) 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);
										
			$daily_bep = $db_found_even['SUM(amount)'];  
			
			
			$gross_profit = $db_found_sum['SUM(unit_c)'];
			
			$net_profit = $gross_profit - $daily_bep;
			$adjusted_netprf = "";
			$remark ="fail";
			if($net_profit >0){
				
				$adjusted_netprf= $net_profit;
			}
			
						
						
					
							if($net_profit >0){
				
				$remark= "congratulations";
			}
										
						
										
										
											
									
						echo '<strong >'.'<span style="color:#260B4D;color: #086310;padding: ">'.'ACCOUNT AS @'.$month.$year.'<br>';
								
										
								
						echo	'<br> Total Sales( '. $db_found_sum['SUM(amount)']. ')';
							
						
						echo '<br>Gross Profit('.  $gross_profit .')';
							
							
							
							
						echo '<br>Break Even Point('.  $daily_bep.')';
							
							
							
							
							
						echo '<br>Net Profit('. $adjusted_netprf.')';
						
							echo '<br>Remark:'. $remark;
						
						
						echo	'<br>Total Qty/Vol  ( '.  $db_found_sum['SUM(s_qty)'].' )    </span></strong>';
		
										
						
						echo '<tr>';
											
						
										
										
	
										
									
	
		
			$SQL_su = "SELECT SUM(amount), SUM(s_qty), SUM(unit_c) FROM txn_table where year = '$year' and month ='$month'  ";
	  
			$sum = mysqli_query($db_handle, $SQL_su);
	  
			$db_found_sum = mysqli_fetch_assoc($sum) ;
	
			
				echo '<p></p>';
			
						
										 echo "<b>PRODUCT/SERVIE BASED RETURNS</b>";		
					
										echo 	'<table class="table  table-hover" style="font-size:12; width:100%  " >';
  									
										echo '<tr  style="background-color: ; text-align: center; color: black">';
      
									
										echo 	'<th scope="col">s/n</th>';
	
									
										echo 	'<th scope="col">Description </th>';
										
									 
										echo 	'<th scope="col">Total Sales</th>';
      
									
										echo 	'<th scope="col">Gross Profit</th>';
										
										echo 	'<th scope="col">Quantity/Vol</th>';
		 

										
										
										
										
										
	  
									$SQL = "SELECT  product_name,product_id,SUM(amount),SUM(unit_c),SUM(s_qty) FROM txn_table   where year= '$year' and month='$month' 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:black" >';
   
	
	
										echo '<td>'.$i++.'</td>';
	
	 
										echo '<td>'.$db_found['product_name'].'</td>';
	
	
	

	
	//echo '<td>'.$db_found['amount'].'</td>';
	
										echo '<td>'.$db_found['SUM(amount)'].'</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>';

	
			
									}

							echo '</tbody>';

							echo '</table>';
						
										
										
								//===========================================================================
									
	

	
	
	
  
	
	
					echo	'</div>';

					?>
						</div>
				
										
				<!--this code is the clients monthly return-->
						
		<div class="col-md-6 ">
			
			<B> CLIENT BASED RETURNS</B>
			<div class=" scroll">
			
			<?php
			echo 	'<table class="table  table-hover" style="font-size:12; width:100%  " >';
  									
										echo '<tr  style="background-color: ; text-align: center; color: black">';
      
									
										echo 	'<th scope="col">s/n</th>';
	
									
										echo 	'<th scope="col">Clients </th>';
										
									 
										echo 	'<th scope="col">Total Sales</th>';
      
									
										echo 	'<th scope="col">Gross Profit</th>';
										
										echo 	'<th scope="col">Quantity/Vol</th>';
		 

										
										
										
										
							
	  
									$SQL = "SELECT  customers_name,product_id,SUM(amount),SUM(unit_c),SUM(s_qty) FROM txn_table   where year= '$year' and month='$month' GROUP BY customers_name  ORDER BY product_id ASC";

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

									$i =1;
	  


									while ( $db_found = mysqli_fetch_assoc($result) ) {
	   
	
										echo'<tr style="text-align: center;background-color:; color:black" >';
   
	
	
										echo '<td>'.$i++.'</td>';
	
	 
										echo '<td>'.$db_found['customers_name'].'</td>';
	
	
	

	
	//echo '<td>'.$db_found['amount'].'</td>';
	
										echo '<td>'.$db_found['SUM(amount)'].'</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>';

	
			
									}

							echo '</tbody>';

							echo '</table>';
						
				?>						
			</div>
		</div>
		
					
				</div>
			
			
			<!--this is the transaction table of the code-->
			<div class="row">
			
					<div class = "col-md-12 " style="background-color: #494747">
			
				  	
						<strong > <span style="color:red;padding: 4px; background-color:"> <br>TRANSACTION HISTORY
					    
						</span> </strong>
				
					
					<div class="jumbotron-fluid scroll_history" style="font-size:12; ">
				  
				  
				 
	  
						<table class="table  table-hover" style="font-size:12; width:100%  " >
  
								<tbody>
    
								<tr  style="background-color: #CBF8A7; text-align: center; color: black">
      
										<?php
										
										echo '<th scope="col">s/n</th>';
	
										echo '<th scope="col">Transaction ID </th>';
										
										echo '<th scope="col">IDN</th>';
      
										echo '<th scope="col">Description</th>';
						
							echo '<th scope="col">Customers Name</th>';
		 
		
	
		   
										echo '<th scope="col">Total Sale</th>';
										echo '<th scope="col">Gross Profit</th>';
										echo '<th scope="col">QTY/VOL</th>';
		
										
		 
										echo '<th scope="col">TIME</th>';
						echo '<th scope="col">DATE</th>';
										
			
     
    
									echo '</tr>';
 			
		



//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  product_name,product_id,user_id, amount,time,s_qty,unit_c,date, customers_name FROM txn_table   where year= '$year' and month ='$month'  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:black; background-color: white" >';

	
	
										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>-->
	  
	  
	  
									<?php
	
										echo '</tr>';

	
	

									}

										
									
								echo '</tbody>';

							echo '</table>';
						
									mysqli_close($db_handle);
	  	?>
	
					</div>
			
			</div>
			
			
		
				</div>
		
		
			</div>
	
										</div>
		
		<!--open-->
			
		
	
	
	
	
	<!--second report works-->
	

	
<?php
										
										
											}	
					
					else {
						
					}
					
?>


	
	
	
		</body>

</html>




	<script>
		
		

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