
<?PHP


session_start();


require 'config.php';

$db_handle = mysqli_connect(DB_SERVER, DB_USER, DB_PASS);
 $database = $_SESSION['database'];

 $branch_key = $_SESSION['branch_key'];

//$database = "lawpedc3_lbs_users";

$db_found = mysqli_select_db($db_handle, $database);






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


$notification = "Receipt Wizard";

 $app_code = $_SESSION['app_code'];

 $privilage = $_SESSION['privilage']; 



if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
	header ("Location: ../login.php");
}






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

?>



<?php





?>


<?php


if(isset($_POST['A']))
{
	
	   $cat = $_POST['cat'];
	
	
	
}
	
	
	

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

	
		
	
            div.scroll {
                //margin:4px, 4px;
               // padding:4px;
                background-color: ;
                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]')"; ?>,bulk_ac(),view_ac(),unit_ac(), spinner()">


	
		<div class="jumbotron-fluid" style="background-color: #030CAB; 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>
	
	
	 <input type="submit" value='Receipt' onClick="unit_ac()" class="" style= "width: inherit; height: " name = "A"  >	
	
	 <input type="submit" value='Invoice' onClick="unit_ac()" class="" style= "width: inherit; height: " name = "A"  >	

	 <input type="submit" value='settings' onClick="unit_ac()" class="" style= "width: inherit; height: " name = "A"  >	

	
	<!-- <input type="submit" value='Generate Receipt(MAN)' onClick="window.alert('inactive(function under-review)')" class="" style= "width: inherit; height: " name = "A"  >	

	
	 <input type="submit" value='Generate Invoice' onClick="window.alert('inactive(function under-review)')" class="" style= "width: inherit; height: " name = "A"  >	-->

	 <input type="submit" value='Back' onClick="spinner(),document.location='dashboard.php'" class="" style= "width: inherit; height: " name = "A"  >	

	
	
		<div class="jumbotron" style="background-color:">
			
			<div style="color: blue;  "><h5><b><marquee behavior="alternate">
			RECEIPT/INVOICE WIZARD
			</marquee></b></h5></div>
	
	<div class="row">
		<DIV class="col-md-12" id="">
			<table style="margin: auto; width: auto" >
		
	<tr>
			
 	
				</tr>
			</table>
		</DIV>
	
    </div>
			
			
				<div class="row">
			<table style="margin: auto" >

			</table>
		
		
			</div>
	
		</div>
	
	
	<!--script to show recent inserted record-->
	
	
		<?php
			  //==================================================================================
			 //script to show recent inserted record
			//==================================================================================
	
	
	
	// echo $db_found_recent['amount'];
	
	  //===================================================================================
	  		?>
	
	

	
<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-3" style="padding-top: 8px;background-color:" id="unit_ac" >
							
											
													<div id="">
											
										
														<form METHOD ="POST" ACTION = "receiptwiz.php" style="width: 100%">
											<table width="100%">
				<tr>
					
									<td>  
											<div class="input-group mb-3">
  
</div>
										
										
										
										
										
										
										
										<div class="input-group mb-3">
 
 <select class="custom-select"  style="background-color:"   name="name" id="product" onchange="showUser(this.value) " >
										
											<option value="" selected>Select Customer</option>
		
											<?php
	
	

											
											
		
					
						$SQL = "SELECT DISTINCT customers_name FROM txn_table   where  branch_key='$branch_key'and type = ''  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['product_name'].'">'. $db_found['product_name'].'(Qty'. $db_found['unit_q'].', Amt '. $db_found['unit_p'].')</option>'; */
												
												echo'<option value="'. $db_found['customers_name'].'">'. $db_found['customers_name'].'</option>'; 
																									  }
		
											?>
	 
	 
	 
	 										<option value=""> Prepare Manually	 </option>'; 
											
											</select> 
</div>
										
										
										
										
										
										
									
															
									
										
									    
		
					</td>
					
	
											 
							
											 
							</tr>
			</table>
			 <input type="submit" value="Continue" class="btn-dark" style= "width: 100%" name = "AA" onClick = "spinner()">
											
											</form>
											</div>	
											
											
											
										</div>
										
					
										<div class="col-md-2" style="padding-top: 8px" id="bulk_ac">
											
				
										</div>
					
										
								 
				<div class="col-md-7" style="padding-top: 8px; background-color:" id="crude_ac"  >
					
					
					
					<div class="scroll">
					
					
					<table class="table  table-hover" style="font-size:13; width:100%  " >
					
	<tr>
						
						
	<?php
		
		
		
		
if(isset($_POST['AA']))
{
	
	   $name = $_POST['name'];
	
	
	
		
					
						$SQL = "SELECT *FROM txn_table   where  branch_key='$branch_key'and type = '' and  customers_name = '$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; color:; background-color:" >';

	
	
										echo '<td>'.$i++.'</td>';
		
										//echo '<td>'.$db_found['product_id'].'</td>';
										
										
										
										
										//echo '<td>  <button>'.$db_found['product_id'].'</botton></td>';
										
										?>
										
										
									
									<td>
										
										
										<a href="invoice.php?txnId=<?php echo $db_found["product_id"]?>">
   
										<input type="button" value="Issue Reciept" onClick="spinner(), view_ac()"></a>
		
		
		
		</td>
									
									
									
									
								
									<?php
									//echo '<td>'.$db_found['user_id'].'</td>';
										
										
										
										
		 
											
										echo '<td>'.$db_found['product_name'].'</td>';
		
										
										
	
										echo '<td>'.$db_found['date'].'</td>';
										
										
										
										
										echo '</tr>';

	
	

									}

								//	mysqli_close($db_handle);
}
			
					?>
					
						</tr>
					
						</table>
					
						</div>
	
				</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>
		
		
	
		
	
</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";
  }
}		
		
			
		

		


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