<?PHP
session_start();


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


$privilage = $_SESSION['privilage']; 
$background_color =$_SESSION['bottom_backgroundcolor'];
$text_color =$_SESSION['text_color'];


$background =$_SESSION['background_color'];

$notification = "Inventory Mgt System";

  $branch_key = $_SESSION['branch_key'];

 $biz_nature = 	$_SESSION['biz_nature'];

 $app_code = 	$_SESSION['app_code'];

$address = $_SESSION['address'];





 $date = date("Y-m-d");




if($address === ""){
//echo "it works";
	
	header ("Location: location.php");
	
 }







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

	



//script to check the validity of a product


$SQLEXPIRED = "SELECT * FROM product_table where service = 'product' and unit_q < '6' and branch_key ='$branch_key'and service != 'cash' ORDER BY product_id DESC   ";

	  //$SQL = "SELECT  product_name,product_id,user_id, amount, time FROM txn_table   where date= current_date  ORDER BY product_id DESC";

	  $result = mysqli_query($db_handle, $SQLEXPIRED);
	  
if ($result->num_rows >= 1) {
	
	
	$notification = 'low inventory| check table';
	
}



?>


<?php
if(isset($_POST['A']))
{
	
	   $cat = $_POST['cat'];
	
	 $automanage = $_POST['automanage'];
	
    $product_name = $_POST['product'];
	$unit_q = $_POST['unit_q'] ;
	$unit_p = $_POST['unit_p'] ;
	
	$unit_c = $_POST['unit_c'] ;
	
	$unite = $_POST['unite'] ;
	
	
	$service = $_POST['service'] ;
	
	
	
	$expiry_date = $_POST['expiry_date'] ;
	
	
	
	if($service == 'product')
	{
	
	$description =   'Added '.$unit_q. $unite.' of '.$product_name.' by '.$_SESSION['name'].' that will expire '.$expiry_date;
	
	}
	else{
		
		$description =   'Added '.$product_name.' services'.' by '.$_SESSION['name'];
	}
		
		
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	 $time = date("h-i-s");
	//$bundle_q = $_POST['bundle_q'] ;
	//$bundle_p = $_POST['bundle_p'] ;
if($cat=="" or $product_name=="" or $unit_q==""){
	
 $notification ="failed|empty fields";
//echo	'<button ><a href = " inventory_ac.php">Ok</a></button';
	
}
	

	else{
		
		$db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );

		/*
			$SQL = $db_found->prepare("INSERT INTO product_table (product_name, unit_q, unit_p,bundle_q,bundle_p,user_id) VALUES (?,?,?,?,?,?)");
			$SQL->bind_param('ssssss', $product_name, $unit_q,$unit_p,$bundle_q,$bundle_p,$_SESSION['user_id'] );
			$SQL->execute();
			header ("Location: inventory_ac.php");
			
			
		*/
		
		
		
	$SQL = $db_found->prepare("INSERT INTO product_table (cat,product_name,auto_manage, unit_q, unit_p,unit_c,time,date,user_id,branch_key,app_code,unite,service,expiry_date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
			$SQL->bind_param('ssssssssssssss', $cat, $product_name,$automanage,$unit_q,$unit_p,$unit_c, $time, $date,$_SESSION['user_id'],$branch_key,$app_code,$unite,$service,$expiry_date );
			$SQL->execute();
		
		
		
		
		
		
		//history
	$SQL = $db_found->prepare("INSERT INTO bmhistory (cat,product_name,auto_manage, unit_q, unit_p,unit_c,time,date,user_id,branch_key,app_code,unite,service,expiry_date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
			$SQL->bind_param('ssssssssssssss', $cat, $description,$automanage,$unit_q,$unit_p,$unit_c, $time, $date,$_SESSION['user_id'],$branch_key,$app_code,$unite,$service,$expiry_date );
			$SQL->execute();
		
		
		
		
		// history
		
		/*
		
		$discription = 'it really works well';
		
		
	$SQL = $db_found->prepare("INSERT INTO history (date,user_id,branch_key,app_code) VALUES (?,?,?,?,?)");
			$SQL->bind_param('sssss',   $date, $_SESSION['user_id'],$branch_key,$app_code );
			$SQL->execute();
	
		*/
		
		
		
	/*
	$SQL = $db_found->prepare("INSERT INTO product_table (cat,product_name, unit_q, unit_p,unit_c,time,date,user_id) VALUES (?,?,?,?,?,?,?,?)");
			$SQL->bind_param('ssssssss', $cat, $product_name,$unit_q,$unit_p,$unit_c, $time, $date,$_SESSION['user_id'] );
			$SQL->execute();
	*/
	 $notification ="success";
			//header ("Location: inventory_ac.php");
		


		
	}


}



else if(isset($_POST['category']))
{
	
	   $cat = $_POST['cat'];
	 $date = date("Y-m-d");
    
	if($cat =="")
	{
		$notification = "error|blank field";
	}
	
	else {
	
		
		
	
	// $time = date("h-i-s");
	//$bundle_q = $_POST['bundle_q'] ;
	//$bundle_p = $_POST['bundle_p'] ;

	

	$db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );

		/*
			$SQL = $db_found->prepare("INSERT INTO product_table (product_name, unit_q, unit_p,bundle_q,bundle_p,user_id) VALUES (?,?,?,?,?,?)");
			$SQL->bind_param('ssssss', $product_name, $unit_q,$unit_p,$bundle_q,$bundle_p,$_SESSION['user_id'] );
			$SQL->execute();
			header ("Location: inventory_ac.php");
			
			
		*/
	
	$SQL = $db_found->prepare("INSERT INTO product_cat (cat_name,date,branch_key,app_code,biz_nature) VALUES (?,?,?,?,?)");
			$SQL->bind_param('sssss', $cat,$date,$branch_key,$app_code,$biz_nature );
			$SQL->execute();
	
	 $notification ="success";
			//header ("Location: inventory_ac.php");
		

		
	}
	



}




else if(isset($_POST['del_category']))
{
	
	

	   $catt = $_POST['del_cat'];
	
if($catt == "")
{
	$notification = "failed|Select Category";
}
	
	else{
		
		
	$SQL = "DELETE FROM product_cat WHERE cat_name='$catt'";
   $query_del = mysqli_query($db_handle, $SQL);
	
	  $notification ="success";
	}
	//header ("Location: inventory_ac.php");
	

	
    
}



else{
	
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
	<title>Lawped</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	
	  <!--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>
	 <link href="css/popup.css" rel="stylesheet">
	
	
<!--===============================================================================================-->	
		 <link href="css/bootstrap-4.4.1.css" rel="stylesheet">
	
<!--===============================================================================================-->
	
</head>
	
	 <script src="js/main.js"></script>
	
	
	
	
	<style>

.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid blue;
  border-right: 16px solid green;
  border-bottom: 16px solid red;
  border-left: 16px solid pink;
  width: 120px;
  height: 120px;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 1s linear infinite;
}

@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
		
















	body, html {
background-color: <?php echo $background_color; ?> ;
}

	
		
	
            div.scroll {
                //margin:4px, 4px;
               // padding:4px;
                background-color: #494747;
                width: 100%;
                height: 310px;
               // 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: 310px;
                //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()">


	
		<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; ?>">
			
			<div style="color: <?php echo $text_color; ?>;  "><h5><b><marquee behavior="alternate">Inventory Management System</marquee></b></h5></div>
	
	<div class="row">
		<DIV class="col-md-12" id="">
			<table style="margin: auto; width: auto" >
		
	<tr>
				<td>
					
					 <input type="submit" value='Add Product ' onClick="unit_ac(),close_prdct()" class="" style= "width: inherit; height: " name = "A"  >
					
					
				</td>
	<td>
		 <input type="submit" onClick="bulk_ac(),add_service(),close_services()" value="Add Service" class="" style= "width: inherit; height: " name = "A" >
				</td>
	
		
	
	
 	
				</tr>
			</table>
		</DIV>
	
    </div>
			
			
				<div class="row">
			<table style="margin: auto" >
		
	<tr>
				<td>
					
					 <input type="button" onClick="view_ac()" value="Accounts" class="" style= "width: inherit; height: " name = "A" >
					
					
				</td>
	<td>
		
		
		<input type="button"   onClick = "crude_ac(),close_service()"   value="(+) General Name" class="" style= "width: inherit; height: "  >
				</td>
	<td>
		 <a href="dashboard.php"><input type="button"  onClick = "spinner()"  value="BACK" class="" style= "width: inherit; height: "  ></a>
				</td>
	
	
	</tr>
			
			</table>
		
		
			</div>
	
		</div>
	
	
	<!--script to show recent inserted record-->
	
	
		<?php
			  //==================================================================================
			 //script to show recent inserted record
			//==================================================================================
	
	
	  $SQL_recent = "SELECT * FROM product_table where branch_key ='$branch_key'  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:black; width: inherit; color: #5A6CF8 ">
		
		<h6>  <?php  echo $db_found_recent['product_name'].' was added as @'.$db_found_recent['time']." ". ' ('.$db_found_recent['date'].')'; ?> </h6>
	
	</div>
	<!--script to show recent inserted record-->
	
	
<div class="loader" id="spin" style="margin: auto"></div>		
	
	<div class="container-fluid" style="" >
		
		
		
		<div class="jumbotron-fluid" style="background-color: ">
		
		
				<div class="row" style="">
				
										<div class="col-md-4" style="padding-top: 8px;background-color:" id="unit_ac" >
							
											
													<div id="">
											
										
														<form METHOD ="POST" ACTION = "inventory_ac.php" style="width: 100%">
											<table width="100%">
				<tr>
					
									<td>  
										
											<div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon1">General Name</span>
  </div>
 <select class="custom-select"  style="background-color:yellow"   name="cat" id="product" onchange="add_prdct() " >
										
											<option value="" selected> Choose</option>
		
											<?php
											
											$SQL = "SELECT  DISTINCT cat_name FROM product_cat where biz_nature ='$biz_nature'  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> 
</div>
										
										<div id="prdct">
										
										
										
											
												<div class="input-group mb-3">
 <!-- <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon1">Product Name</span>
  </div>-->
  <input type="text" class="form-control" placeholder="Name of product" aria-label="Username" aria-describedby="basic-addon1" name="product">
											
											
										 <select class=""  style="background-color:"   name="automanage"  >
										
											<option value="enabled" selected>Auto Man</option>
											<option value="disabled " >disabled</option>
										
											
											</select> 
											
											
											
											
						</div>
											
											
											
											
											
											
												<div class="input-group mb-3">
 <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon1">Expiry Date</span>
  </div>
 
											
										
											
  <input type="date" required class="form-control" placeholder="" aria-label="Username" aria-describedby="basic-addon1" name="expiry_date">
								
											
											
											
						</div>
											
											
											
											
								
										
									
					
											<div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon1">Qty(Unit)</span>
  </div>
	  <input type="text" class="form-control" placeholder="Volume of Goods" aria-label="Username" aria-describedby="basic-addon1" name="unit_q">

													 <input type="text" class="form-control" placeholder="Volume of Goods" aria-label="Username" aria-describedby="basic-addon1" value="product" name="service" hidden>	

												
												
												
												
												
														<select class="tryy"  style="width:50px"  id="" name="unite">
										
											<option value="unit" selected>unit </option>
											<option value="Qty">Quantity</option>
											<option value="Vol">Volume</option>
											<option value="Bags">Bags</option>
											<option value="papers">papers</option>
											<option value="film">film</option>
											<option value="crates">crates</option>
												<option value="bottles">bottles</option>
											<option value="baskets">baskets</option>
											<option value="cups">cups</option>
											<option value="piecis">pieces</option>
											<option value="KG">KG</option>
												<option value="booklet">booklet</option>
												<option value="dozen">dozen</option>
												
											
											
											
											</select> 
													
												
												
												
												
												
												
												
												
												
											
												
												
												
												
												
												
</div>
															
										<table>
										
											
											<tr>
														<td>
												<div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon1">Selling P</span>
  </div>
  <input type="text" class="form-control" placeholder="0.00" aria-label="Username" aria-describedby="basic-addon1" name="unit_p">
</div>
														</td>
														<td>
														  <div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon1">Cost P</span>
  </div>
  <input type="text" class="form-control" placeholder="0.00" aria-label="Username" aria-describedby="basic-addon1" name="unit_c">
</div>	
														</td>
											</tr>
										</table>
										
											
											<textarea cols="50" rows = "3" style="width:100%"  id="note"  placeholder="product description" class="form-control" aria-label="Amount (to the nearest dollar)" name="note"></textarea>
										
											<p></p>
										
										</div>
									
									    
								
										
										
										
					</td>
					
	
											 
							
											 
							</tr>
			</table>
			 <input type="submit" value="ENTER" class="btn-dark" style= "width: 100%" name = "A" onClick = "spinner()">
											
											</form>
											</div>	
											
											
											
										</div>
										
					
										<div class="col-md-4" style="padding-top: 8px" id="bulk_ac">
										  <div id="">
											
										
														<form METHOD ="POST" ACTION = "inventory_ac.php" style="width: 100%">
											<table width="100%">
				<tr>
					
									<td>  
										
											<div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon1">General Name</span>
  </div>
 <select class="custom-select"  style="background-color:"   name="cat" id="service" onchange=" add_service() " >
										
											<option value="" selected> Choose</option>
		
											<?php
											
											$SQL = "SELECT  DISTINCT cat_name FROM product_cat where biz_nature ='$biz_nature'  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> 
</div>
										
										<div id="2service">
										
										
										
											
												<div class="input-group mb-3">
 <!-- <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon1">Product Name</span>
  </div>-->
  <input type="text" class="form-control" placeholder="Name of services" aria-label="Username" aria-describedby="basic-addon1"  name="product" >
											
											
											<select class="tryy"  style="width:50px"  id="" name="unite" hidden>
										
											<option value="unit" selected>unit </option>
											<option value="Qty">Quantity</option>
											<option value="Vol">Volume</option>
											<option value="Bags">Bags</option>
											<option value="papers">papers</option>
											<option value="film">film</option>
											<option value="crates">crates</option>
												<option value="bottles">bottles</option>
											<option value="baskets">baskets</option>
											<option value="cups">cups</option>
											<option value="piecis">pieces</option>
											<option value="KG">KG</option>
												<option value="booklet">booklet</option>
												<option value="dozen">dozen</option>
												
											
											
											
											</select> 
											
											
											
																				
 
											
						</div>					
								
										
									
					
											<div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon1" hidden>Qty(Unit)</span>
  </div>
 										

												
												
												 <select class=""  style="background-color:"   name="automanage" hidden >
										
											<option value="enabled"  >Auto Man</option>
											<option value="disabled " selected   >disabled</option>
										
											
											</select> 
											
												
												
												
												
												
												
</div>
															
										<table>
										
											
											<tr>
														<td>
												<div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon1">Selling P</span>
  </div>
  <input type="text" class="form-control" placeholder="0.00" aria-label="Username" aria-describedby="basic-addon1" name="unit_p">
</div>
														</td>
														<td>
														  <div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon1">Cost P</span>
  </div>
  <input type="text" class="form-control" placeholder="0.00" aria-label="Username" aria-describedby="basic-addon1" name="unit_c">
</div>	
														</td>
											</tr>
										</table>
										
											
											
															
																<textarea cols="50" rows = "3" style="width:100%"   placeholder="service description" class="form-control" aria-label="Amount (to the nearest dollar)" name="note"></textarea>
															<p></p>
											
										
										</div>
										
										
									
									    
									
										
										
										
					</td>
					
	
											 
							
											 
							</tr>
			</table>
															
															
															 <input type="date" class="form-control" placeholder="" aria-label="Username" aria-describedby="basic-addon1" name="expiry_date" hidden="">
															
															
															 <input type="text" class="form-control" placeholder="Volume of Goods" aria-label="Username" aria-describedby="basic-addon1" value="100000" name="unit_q" hidden>
												
 <input type="text" class="form-control" placeholder="Volume of Goods" aria-label="Username" aria-describedby="basic-addon1" value="service" name="service" hidden>		
															
															
															
															
			 <input type="submit" value="ENTER" class="btn-dark" style= "width: 100%" name = "A" onClick = "spinner()">
											
											</form>
										  </div>									
											
											
											
											
											
				  </div>
					
										
								
				<div class="col-md-4" style="padding-top: 8px; background-color:" id="crude_ac"  >
					
 <form METHOD ="POST" ACTION = "inventory_ac.php" style="width: 100%">
											<table width="100%">
												
												<tr>
												<td>
													
													
												  <select class="custom-select"  style="background-color:#3E3C3C;color: aliceblue"   name = "del_cat"  >
										
											<option value="" selected>Select general name</option>
		
											<?php
											
											$SQL = "SELECT  DISTINCT cat_name FROM product_cat where biz_nature = '$biz_nature' and 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['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>
					
				 <input type="submit" value="Delete" class="ustom-select btn-dark" style= "width: 100%" onClick="spinner()" name = "del_category" >
					
												  </td>
												
												</tr>
												
				
												<tr>
				  </form>						
					
	  <form METHOD ="POST" ACTION = "inventory_ac.php" style="width: 100%">
					
					<td>  
					<input type="text" class="form-control" name="cat" placeholder="input General name" aria-label="Recipient's username" aria-describedby="basic-addon2" style="background-color: #E1E1E1">
					</td>
			
						 
											
							</tr>
												
												<tr>
														<td>
					
				
					 <input type="submit" value="SAVE" class="btn-group" style= "width: 100%"  onClick="spinner()" name = "category" >
												  </td>
												
												</tr>
												
												
			</table>
			
											
				  </form>
				</div>


				</div>
		
		
		</div>
		
		
		
		
		<?php
			  //==================================================================================
			 //this junk of code is to sum up daily transaction
			//==================================================================================
	  $SQL_sum = "SELECT SUM(amount) FROM txn_table where date= current_date   ";
	  $sum = mysqli_query($db_handle, $SQL_sum);
	  $db_found_sum = mysqli_fetch_assoc($sum) ;
	  //===================================================================================
	  		?>
		
	
	
		
		<div class="jumbotron-fluid" style="background-color: " id="view_ac">
		
					<div class="row " style="margin-top: 1px; background-color:#494747;padding: 10">
		
		
				  		
				
				
				
				
				
				
				<div class = "col-md-6 " style="background-color: ">
					
					 <strong ><span style="color:#FAF7FF;padding: 4px"><br>PRODUCT(Goods) A/C
					     </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: 12px">
  <tbody>
    <tr  style="background-color: <?php echo  $background_color;?>; text-align: center; color: ">
      <th scope="col"></th>
		
	<th scope="col"> </th>
    
		
		 
		<!-- <th scope="col">DESCRIPTION</th>-->
	
		 <th scope="col" style="background-color: "><input type="button" value="Avail Qty"></th>
		 <th scope="col"style="background-color: "><input type="button" value="(Per_unit) Selling_Price"></th>
		 <th scope="col"style="background-color: "><input type="button" value="(Per_unit) Cost_Price"></th>
		
		 <th scope="col"style="background-color: "><input type="button" value="Total cost of goods"></th>
		
		
		 <th scope="col"style="background-color: "><input type="button" value="Total Worth of goods"></th>
		
		 <th scope="col"style="background-color: "><input type="button" value="Expiry date"></th>
		
		<th scope="col"style="background-color: "><input type="button" value="Auto Manage"></th>
		
		<!--<th scope="col" style="background-color: black"> (Bundle/Carton/Basket) Available_Quantity</th>
		 <th scope="col" style="background-color: black">(Bundle/Carton/Basket) Selling_Price </th>
		-->
		<!--<th scope="col" style="background-color: ">   TIME  </th>
		 <th scope="col" style="background-color: ">   DATE</th>
		-->
     
    </tr>
 			
		


<?PHP

	  
	  
$SQL = "SELECT * FROM product_table where branch_key ='$branch_key' and service = 'product' ORDER BY product_id DESC   ";

	  //$SQL = "SELECT  product_name,product_id,user_id, amount, time FROM txn_table   where date= current_date  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:blue; background-color:white;width:100%;" >';
     // echo '<td>'.$db_found['user_id'].'</td>';
	
	
	echo '<td>'.$i++.'</td>';
	//echo '<td>'.$db_found['product_id'].'</td>';
	?>
	
  <td><a href="restock.php?txnId=<?php echo $db_found["product_id"]?>">
   <input type="button" value="<?php echo $db_found['product_name']?>"  onClick = "spinner()"></a></td> 
		 
		 <?php
	echo '<td style="background-color: ">'.$db_found['unit_q'].'</td>';
	// echo '<td>'.$db_found['user_id'].'</td>';
	
	
	// echo '<td>'.'<a href="www.lawped.com.ng?id=$db_found['product_id']">details</a>'.'</td>';
	
	// $db_found_sum['SUM(amount)'];
	
	
	 echo '<td style="background-color: ">'.$db_found['unit_p'].'</td>';
	echo '<td style="background-color: ">'.$db_found['unit_c'].'</td>';
	
	
	echo '<td style="background-color: ">'.$db_found['unit_q']*$db_found['unit_c'].'</td>';
	
	
	echo '<td style="background-color: ">'.$db_found['unit_p']*$db_found['unit_q'].'</td>';
	
	echo '<td style="background-color: ">'.$db_found['expiry_date'].'</td>';
	
	echo '<td style="background-color: ">'.$db_found['auto_manage'].'</td>';
	
	
	
	
	 
	 
	?>

	  
	 
	    <td><a href="restock.php?txnId=<?php echo $db_found["product_id"]?>">
   <input type="button" value="Re-Stock"  onClick = "spinner()"></a></td> 
	  
	  
	  
	   <td><a href="delete2.php?txnId=<?php echo $db_found["product_id"]?>">
   <input type="button" value="Delete"  onClick = "spinner()"></a></td>
	
	  
	  
	  
	  <?php
	echo '</tr>';

	
	
}

//}
//else {

//print "Database NOT Found ";

//}

	  
			?>
	
	
	
	
	
  </tbody>
</table>
						
	
	
	</div>
				
			
					
					
				</div>
				
				
						
						
						
						
						
							<div class = "col-md-3 " style="background-color: ">
					
					 <strong ><span style="color:#FAF7FF;padding: 4px"><br>Low Products Account (<5)
					     </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: 12px">
  <tbody>
    <tr  style="background-color: <?php echo  $background_color;?>; text-align: center; color: ">
    
		 
		<!-- <th scope="col">DESCRIPTION</th>-->
		
		
		
	 <th scope="col" style="background-color: "></th>
		 <th scope="col" style="background-color: "><input type="button" value="DESCRIPTION"></th>
		 <th scope="col"style="background-color: "><input type="button" value="Quantity"></th>
	
		
     
    </tr>
 			
		


<?PHP
	  
	   $date = date("Y-m-d");

//if ($db_found) {

//$SQL = "SELECT * FROM product_table ORDER BY product_id ASC ";

	  
	  
$SQLEXPIRED = "SELECT * FROM product_table where service = 'product'  and  service != 'cash'  and unit_q < '6' and branch_key ='$branch_key' ORDER BY product_id DESC   ";

	  //$SQL = "SELECT  product_name,product_id,user_id, amount, time FROM txn_table   where date= current_date  ORDER BY product_id DESC";

	  $result = mysqli_query($db_handle, $SQLEXPIRED);
	  
	  
	
	  
$i =1;
	  
	  
	  

while ( $db_found = mysqli_fetch_assoc($result) ) {
	   
	echo'<tr style="text-align: center; color:blue; background-color:white;width:100%;" >';
     // echo '<td>'.$db_found['user_id'].'</td>';
	
	
	echo '<td>'.$i++.'</td>';

	


	
//	echo '<td>'.$db_found['product_id'].'</td>';
	?>
	
  <td>
	  
	  
	  
	  
	  
 <?php echo  $db_found['product_name']?>
	  
	  
	  
	  
	  </td> 
		 
		 <?php
	
	
	echo '<td style="background-color: ">'.$db_found['unit_q'].'</td>';
	
	
	
	
	
//	echo '<td>'.'<a href="www.lawped.com.ng?id=$db_found['product_id']">details</a>'.'</td>';
	
	// $db_found_sum['SUM(amount)'];
	
	
	
	 
	 
	?>

	  
	 
	 
	  
	  <?php
	echo '</tr>';

	
	
}

//}
//else {

//print "Database NOT Found ";

//}

	  
			?>
	
	
	
	
	
  </tbody>
</table>
						
	
	
	</div>
				
			
					
					
				</div>
				
						
						
						
						
							<div class = "col-md-3 " style="background-color: ">
					
					 <strong ><span style="color:#FAF7FF;padding: 4px"><br>Expired Products
					     </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: 12px">
  <tbody>
    <tr  style="background-color: <?php echo  $background_color;?>; text-align: center; color: ">
    
		 
		<!-- <th scope="col">DESCRIPTION</th>-->
		
		
		
	 <th scope="col" style="background-color: "></th>
		 <th scope="col" style="background-color: "><input type="button" value="DESCRIPTION"></th>
		
		 <th scope="col"style="background-color: "><input type="button" value="EXPIRY DATE"></th>
		
     
    </tr>
 			
		


<?PHP
	  
	   $date = date("Y-m-d");

//if ($db_found) {

//$SQL = "SELECT * FROM product_table ORDER BY product_id ASC ";

	  
	  
$SQLEXPIRED = "SELECT * FROM product_table where service = 'product' and expiry_date < '$date' and branch_key ='$branch_key' ORDER BY product_id DESC   ";

	  //$SQL = "SELECT  product_name,product_id,user_id, amount, time FROM txn_table   where date= current_date  ORDER BY product_id DESC";

	  $result = mysqli_query($db_handle, $SQLEXPIRED);
	  
	  
	
	  
$i =1;
	  
	  
	  

while ( $db_found = mysqli_fetch_assoc($result) ) {
	   
	echo'<tr style="text-align: center; color:blue; background-color:white;width:100%;" >';
     // echo '<td>'.$db_found['user_id'].'</td>';
	
	
	echo '<td>'.$i++.'</td>';

	


	
//	echo '<td>'.$db_found['product_id'].'</td>';
	?>
	
  <td>
	  
	  
	  
	  
	  
 <?php echo  $db_found['product_name']?>
	  
	  
	  
	  
	  </td> 
		 
		 <?php
	echo '<td style="background-color: ">'.$db_found['date'].'</td>';
	
	
	
//	echo '<td>'.'<a href="www.lawped.com.ng?id=$db_found['product_id']">details</a>'.'</td>';
	
	// $db_found_sum['SUM(amount)'];
	
	
	
	 
	 
	?>

	  
	 
	 
	  
	  <?php
	echo '</tr>';

	
	
}

//}
//else {

//print "Database NOT Found ";

//}

	  
			?>
	
	
	
	
	
  </tbody>
</table>
						
	
	
	</div>
				
			
					
					
				</div>
				
						
						
				
						
						
						
						
						
						
						
						
						
						
				
				
				
				
			
				
				
				
				
				
				
			</div>
			
	
		
			
			
			
			
			
			
			
			
			
			<div class="row " style="margin-top: 1px; background-color:#494747;padding: 10">
				
						
				
				
						
				<div class = "col-md-4 " style="background-color: ">
					
					 <strong ><span style="color:#FAF7FF;padding: 4px"><br>Services A/C
					     </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: 12px">
  <tbody>
    <tr  style="background-color: <?php echo  $background_color;?>; text-align: center; color: ">
      <th scope="col"></th>
		
	<th scope="col"> </th>
    
		
		 
		<!-- <th scope="col">DESCRIPTION</th>-->
	
		
		 <th scope="col"style="background-color: "><input type="button" value="Amount"></th>
		 <th scope="col"style="background-color: "><input type="button" value="(Per_unit) Cost_Price"></th>
		
		<!-- <th scope="col"style="background-color: "><input type="button" value="Auto Manage"></th>-->
		
		<!--<th scope="col" style="background-color: black"> (Bundle/Carton/Basket) Available_Quantity</th>
		 <th scope="col" style="background-color: black">(Bundle/Carton/Basket) Selling_Price </th>
		-->
		<!--<th scope="col" style="background-color: ">   TIME  </th>
		 <th scope="col" style="background-color: ">   DATE</th>
		-->
     
    </tr>
 			
		


<?PHP

//if ($db_found) {

//$SQL = "SELECT * FROM product_table ORDER BY product_id ASC ";

	  
	  
$SQL = "SELECT * FROM product_table where branch_key ='$branch_key' and service = 'service' ORDER BY product_id DESC   ";

	  //$SQL = "SELECT  product_name,product_id,user_id, amount, time FROM txn_table   where date= current_date  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:blue; background-color:white;width:100%;" >';
     // echo '<td>'.$db_found['user_id'].'</td>';
	
	
	echo '<td>'.$i++.'</td>';
//	echo '<td>'.$db_found['product_id'].'</td>';
	?>
	
  <td><a href="restock.php?txnId=<?php echo $db_found["product_id"]?>">
   <input type="button" value="<?php echo $db_found['product_name']?>"  onClick = "spinner()"></a></td> 
		 
		 <?php
	//echo '<td style="background-color: ">'.$db_found['unit_q'].'</td>';
	// echo '<td>'.$db_found['user_id'].'</td>';
	
	
	// echo '<td>'.'<a href="www.lawped.com.ng?id=$db_found['product_id']">details</a>'.'</td>';
	
	// $db_found_sum['SUM(amount)'];
	
	
	 echo '<td style="background-color: ">'.$db_found['unit_p'].'</td>';
	echo '<td style="background-color: ">'.$db_found['unit_c'].'</td>';
	
	//echo '<td style="background-color: ">'.$db_found['auto_manage'].'</td>';
	
	 
	 
	?>

	  
	 
	  
	
	  
	  
	    <td><a href="restock.php?txnId=<?php echo $db_found["product_id"]?>">
 <!--  <input type="button" value="Re-Stock"  onClick = "spinner()"></a></td> -->
	  
	  
	  
	   <td><a href="delete2.php?txnId=<?php echo $db_found["product_id"]?>">
   <input type="button" value="Delete"  onClick = "spinner()"></td></a>
	
	  
	  
	  <?php
	echo '</tr>';

	
	
}

//}
//else {

//print "Database NOT Found ";

//}

	  
			?>
	
	
	
	
	
  </tbody>
</table>
						
	
	
	</div>
				
			
					
					
				</div>
						
					
				
				
				
				
				
				
				
				
					<div class = "col-md-2 " style="background-color: ">
					
					 <strong ><span style="color:#FAF7FF;padding: 4px"><br>Cash (impress A/C)
					     </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: 12px">
  <tbody>
    <tr  style="background-color: <?php echo  $background_color;?>; text-align: center; color: ">
      <th scope="col"></th>
		
	<th scope="col"> </th>
    
		 <th scope="col"></th>
		 
		<!-- <th scope="col">DESCRIPTION</th>-->
	
		
		
		
		
		<!-- <th scope="col"style="background-color: "><input type="button" value="Auto Manage"></th>-->
		
		<!--<th scope="col" style="background-color: black"> (Bundle/Carton/Basket) Available_Quantity</th>
		 <th scope="col" style="background-color: black">(Bundle/Carton/Basket) Selling_Price </th>
		-->
		<!--<th scope="col" style="background-color: ">   TIME  </th>
		 <th scope="col" style="background-color: ">   DATE</th>
		-->
     
    </tr>
 			
		


<?PHP

//if ($db_found) {

//$SQL = "SELECT * FROM product_table ORDER BY product_id ASC ";

	  
	  
$SQL = "SELECT * FROM product_table where branch_key ='$branch_key' and service = 'cash' ORDER BY product_id DESC   ";

	  //$SQL = "SELECT  product_name,product_id,user_id, amount, time FROM txn_table   where date= current_date  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:blue; background-color:white;width:100%;" >';
     // echo '<td>'.$db_found['user_id'].'</td>';
	
	

	?>
	
  <td><a href="restock.php?txnId=<?php echo $db_found["product_id"]?>">
   <input type="button" value="<?php echo $db_found['product_name']?>"  onClick = "spinner()"></a></td> 
		 
		 <?php
	//echo '<td style="background-color: ">'.$db_found['unit_q'].'</td>';
	// echo '<td>'.$db_found['user_id'].'</td>';
	
	
	// echo '<td>'.'<a href="www.lawped.com.ng?id=$db_found['product_id']">details</a>'.'</td>';
	
	// $db_found_sum['SUM(amount)'];
	
	
	 echo '<td style="background-color: ">'.$db_found['unit_q'].'</td>';

	
	//echo '<td style="background-color: ">'.$db_found['auto_manage'].'</td>';
	
	 
	 
	?>

	  
	 
	  
	
	  
	  
	    <td>     <a href="restock.php?txnId=<?php echo $db_found["product_id"];?>" dis>
   Add(+)  </a>      </td> 
	  
	  
	  
	 
	
	  
	  
	  <?php
	echo '</tr>';

	
	
}

//}
//else {

//print "Database NOT Found ";

//}

	  
			?>
	
	
	
	
	
  </tbody>
</table>
						
	
	
	</div>
				
			
					
					
				</div>
				
						
					
				
				
				
				
				
					<div class = "col-md-6 " style="background-color: ">
					
					 <strong ><span style="color:#FAF7FF;padding: 4px"><br>History
					     </span> </strong>
				
				
						 <div class="jumbotron-fluid scroll_history" style="font-size:12; ">
				  
				  <!--<strong ><span style="color:#260B4D;background-color: #FBFBFC;padding: 4px">TRANSACTION HISTORY
					     </span></strong>-->
				  
	  <table class="table table-hover  "  style="font-size: 12px">
  <tbody>
    <tr  style="background-color: <?php echo  $background_color;?>; text-align: center; color: ">
    
		 
		<!-- <th scope="col">DESCRIPTION</th>-->
		
		
		
	 <th scope="col" style="background-color: "><input type="button" value="id"></th>
		 <th scope="col" style="background-color: "><input type="button" value="DESCRIPTION"></th>
		 <th scope="col"style="background-color: "><input type="button" value="DATE"></th>
		 <th scope="col"style="background-color: "><input type="button" value="USER ID"></th>
		
		
     
    </tr>
 			
		


<?PHP

//if ($db_found) {

//$SQL = "SELECT * FROM product_table ORDER BY product_id ASC ";

	  
	  
$SQL = "SELECT * FROM bmhistory where branch_key ='$branch_key' ORDER BY product_id DESC   ";

	  //$SQL = "SELECT  product_name,product_id,user_id, amount, time FROM txn_table   where date= current_date  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:blue; background-color:white;width:100%;" >';
     // echo '<td>'.$db_found['user_id'].'</td>';
	
	
	echo '<td>'.$i++.'</td>';

	


	
//	echo '<td>'.$db_found['product_id'].'</td>';
	?>
	
  <td>
	  
	  
	  
	  
	  
 <?php echo  $db_found['product_name']?>
	  
	  
	  
	  
	  </td> 
		 
		 <?php
	echo '<td style="background-color: ">'.$db_found['date'].'</td>';
	
	
	echo '<td>'.$db_found['user_id'].'</td>';
	
	
//	echo '<td>'.'<a href="www.lawped.com.ng?id=$db_found['product_id']">details</a>'.'</td>';
	
	// $db_found_sum['SUM(amount)'];
	
	
	
	 
	 
	?>

	  
	 
	 
	  
	  <?php
	echo '</tr>';

	
	
}

//}
//else {

//print "Database NOT Found ";

//}

	  
			?>
	
	
	
	
	
  </tbody>
</table>
						
	
	
	</div>
				
			
					
					
				</div>
				
			</div>
			
			
			
			
		</div>
		
		
	
		
	
</div>

		
	
</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 add_prdct() {
  var x = document.getElementById("prdct");
	
	
	
  if (x.style.display === "none") {
    x.style.display = "block";
	 
  } 
	else {
    x.style.display = "block";
  }
}		
		
		
			
function close_prdct() {
  var x = document.getElementById("prdct");
	
	
	

    x.style.display = "none";
  
}		
		
		

		

		
		
		
		
function add_service() {
  var x = document.getElementById("2service");
	
	
	
  if (x.style.display === "none") {
    x.style.display = "block";
	 
  } 
	else {
    x.style.display = "block";
  }
}		
		
		
			
function close_services() {
  var x = document.getElementById("2service");
	
	
	

    x.style.display = "none";
  
}		
		
		
		
		
		
		
			
		
		
		
		
		
		
		
		

		


</script>			
			

<script>


		function spinner() {
  
			var x = document.getElementById("spin");
	
	
	
  if (x.style.display === "none") {
    x.style.display = "block ";
	  
	  
  }
	else {
    x.style.display = "none";
  }
	
	
}
	
		
	
	
	
function CustomAlert(){
  this.alert = function(message,title){
    document.body.innerHTML = document.body.innerHTML + '<div id="dialogoverlay"></div><div id="dialogbox" class="slit-in-vertical"><div><div id="dialogboxhead"></div><div id="dialogboxbody"></div><div id="dialogboxfoot"></div></div></div>';

    let dialogoverlay = document.getElementById('dialogoverlay');
    let dialogbox = document.getElementById('dialogbox');
    
    let winH = window.innerHeight;
    dialogoverlay.style.height = winH+"px";
    
    dialogbox.style.top = "100px";

    dialogoverlay.style.display = "block";
    dialogbox.style.display = "block";
    
    document.getElementById('dialogboxhead').style.display = 'block';

    if(typeof title === 'undefined') {
      document.getElementById('dialogboxhead').style.display = 'none';
    } else {
      document.getElementById('dialogboxhead').innerHTML = '<i class="fa fa-exclamation-circle" aria-hidden="true"></i> '+ title;
    }
    document.getElementById('dialogboxbody').innerHTML = message;
    document.getElementById('dialogboxfoot').innerHTML = '<button class="pure-material-button-contained active" onclick="customAlert.ok()">OK</button>';
  }
  
  this.ok = function(){
    document.getElementById('dialogbox').style.display = "none";
    document.getElementById('dialogoverlay').style.display = "none";
  }
}

let customAlert = new CustomAlert();
	
		



</script>