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

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

						

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'];

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


if($status === "inactive"){
//echo "it works";
	
	header ("Location: payment_activate.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");
	
}



?>






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

$SQL = "SELECT  date FROM txn_table where  branch_key ='$branch_key' ORDER BY product_id ASC  ";
											
											$result = mysqli_query($db_handle, $SQL);

											// $progress = mysqli_num_rows($result).'%';
 						
										// $progress = (mysqli_num_rows($result)/$db_size*100).'%';

										 $progress = round((mysqli_num_rows($result)/$db_size*100)).'%';
//	echo $progress = '90%';


?>



<!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 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:  <?php echo $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;
            }
		
		

		
		
		
	
		
		
		
		
		
		
	
		
		
		
		.progress{
    height: 25px;
    background: #eee;
    border-radius: 20px;
    overflow: visible;
    line-height: 15px;
    margin: 20px 0 40px 0;
}
.progress .progress-bar{
    border-radius: 20px;
    position: relative;
    animation: animate-positive 2s;
}
.progress .progress-value{
    position: absolute;
    top: -13px;
    right: 16px;
    font-size: 14px;
    color: #fff;
    padding: 16px 16px;
    //background: #191919;
    //border: 1px solid #000;
}
.progress .progress-value:after{
    content: "";
    border-top: 10px solid #191919;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    position: absolute;
    bottom: -6px;
    left: 25%;
}
@-webkit-keyframes animate-positive{
    0% { width: 0%; }
}
@keyframes animate-positive{
    0% { width: 0%; }
}
		
		
		
		
		
		
		
	</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; ?>">DATABASE </span></b></h4></div>
		<div style="color: <?php echo $text_color; ?>; text-align:  center  "><em>Changes made can't be reversed</em></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="" style= "width: inherit; height: 60px" name = "A"  >
					
					
			
							</td>
	
							<td>
		
								<input type="button" onClick="bulk_ac()" value="MONTHS" class="" style= "width: ; height: 60px" name = "A" >
				
							</td>
	
							<td>
		
								<input type="submit" value="YEAR" class="" style= "width: inherit; height: 60px" name = "year" onClick="crude_ac()" >
			
							</td>
	
	
	
				
						</tr>
		
					</table>
		
				</div>
	
    
			</div>
			
			
			
			<div class="row">
			
				<table style="margin: auto;width: auto" >
		
	
					<tr>
				
						<td>
					
					 
							<input type="submit" value="<?php echo $progress?> of (100%)" class="" style= "width: inherit; height: " name = "A" >
					
					
				
						</td>
	
						<td>
		
							 <input type="submit" value="<?php echo $db_size?>mb" class="" onClick="" style= "width: inherit; height:" name = 
															   "A" >
				
						</td>
	
						<td>
		 
						<a href="dashboard.php">	<input type="submit"  onClick="spinner()"  value="Home" class="" style= "width: inherit; height: 60px" name = "A"  ></a>
				
						</td>
	
	
	
					</tr>
			
			
				</table>
		
		
			
			</div>
				
	
		
			
	
	</div>
	
	
	<!--cscript to accounts and transaction history-->
	
	

	
	
	
		<div class="container-fluid" style="" >
		

		
		
			<div class="jumbotron-fluid" style="background-color: ">
		
		
			
				<div class="row">
				
				
					<div class="col-md-4" style="padding-top: 8px" id="unit_ac">
					
						<div id="">
											
						
							<form METHOD ="POST" ACTION = "database.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 where  branch_key ='$branch_key' ORDER BY product_id 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="ERASE" 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 = "database.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 where  branch_key ='$branch_key' ORDER BY product_id DESC ";
											
											$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 where  branch_key ='$branch_key' ORDER BY product_id DESC ";
											
											$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="ERASE" 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 = "database.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 where  branch_key ='$branch_key' 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="ERASE" class="btn-dark" style= "width: 100%" name = "year" onClick="spinner()" >
										
									</td>
						 
												
						 												
						 
							
								</tr>
			
							</table>
			
											
							
						</form>
				
					</div>


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

		
			   $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'];
			
										
							
										
										//this set of codes are used to manipulate the daily account
			
					?>
						</div>
				
										
				
						
		
		
					
				</div>
			
			
			<!--this is the transaction table of the code-->
			<div class="row">
			
					<div class = "col-md-12 " style="background-color: #494747">
			
				  	
					<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: #C3EFA0; text-align: center; color: #5217CD">
      
										<?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  product_name,product_id,user_id, amount,time,s_qty,unit_c FROM txn_table   where date= '$product'  ORDER BY product_id DESC";*/

										
										$SQL = "DELETE FROM txn_table   where date= '$product' and  branch_key ='$branch_key' ";

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

										
										
										
	//echo '<td>'.$db_found['SUM(amount)'].'</td>';
	
	//echo $db_found_sum['SUM(amount)']; 
	 
	 
	
	
	  					
									//mysqli_close($db_handle);
										
									//	header ('Location: logout.php');
										
	  	?>
	
									
									
									
								
					</div>
			
			</div>
			
			
		
				</div>
		
		
			</div>
	
										</div>
		
		<!--open-->
			
		
	
	
	
	
	<!--second report works-->
	

	
<?php
										
										
											}
									
				
					
					
					
					
					
				
					
					
					else if(isset($_POST['year'])){
										
		     $product = $_POST['yea'];
										
										
								//===========================================================================
									
	
	
	
	
	
  
					?>
						</div>
				
										
				
						
		
		
					
				</div>
			
			
			<!--this is the transaction table of the code-->
		
			
				
				
					
					
				  
				  
				 
										<?php
										
		



									
									$SQL = "DELETE   FROM txn_table   where year= '$product' and  branch_key ='$branch_key'  ";

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

										
		
								//	mysqli_close($db_handle);
						
						
						//header ("Location: logout.php");
	  	?>
	
			
		
		
		
	
									
		
		<!--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'";
	  	
										
										
										
	  

					?>
						</div>
				
										
				
						
		
		
					
				</div>
			
			
			<!--this is the transaction table of the code-->
			<div class="row">
			
					<div class = "col-md-12 " style="background-color: #494747">
			
				  	
					
				
					
					<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: #C3EFA0; text-align: center; color: #5217CD">
      
										<?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 = "DELETE FROM txn_table   where year= '$year' and month ='$month' and branch_key ='$branch_key'  ";

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

									
	  
	  

									}

										
									
								echo '</tbody>';

							echo '</table>';
						
									//mysqli_close($db_handle);
					
					
				//	header ("Location: logout.php");
					
	  	?>
	
					</div>
			
			</div>
			
			
		
				</div>
		
		
			</div>
	
										</div>
		
		<!--open-->
			
		







<div class="jumbotron">
    <div class="row">
       
		
		<div class="col-md-12">
            <div class="progress">
                <div class="progress-bar progress-bar-info progress-bar-striped" style="width: <?php echo $progress?>;">
                    <div class="progress-value">  <?php echo $progress?></div> 
                </div>
            </div>
 
		
        </div>
    </div>
</div>

	


	
	<!--second report works-->

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


