<?php include("connection.php");
error_reporting(E_ERROR | E_PARSE); 
 $pagename = basename($_SERVER['PHP_SELF']);

 $bill_no=$_REQUEST["bill_no"];


 $bill=mysqli_query($con,"select * from onshop where `bill_no`='".$bill_no."' and `status`='active' and `bill_status`='pending' "); $billr=mysqli_fetch_array($bill,MYSQLI_ASSOC);
  $billn=mysqli_num_rows($bill);

?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- /Added by HTTrack --><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--
<link type="text/css" rel="stylesheet" href="javax.faces.resource/themeab55.css?ln=primefaces-aristo" />
<link type="text/css" rel="stylesheet" href="javax.faces.resource/dist-butterfaces-bootstrap.min4e5d.css?ln=butterfaces-dist-css" />
-->
<link type="text/css" rel="stylesheet" href="javax.faces.resource/css/default.css" />
<link type="text/css" rel="stylesheet" href="javax.faces.resource/css/cssLayout.css" />
<link type="text/css" rel="stylesheet" href="javax.faces.resource/css/bootstrap.css" />
<link type="text/css" rel="stylesheet" href="javax.faces.resource/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="javax.faces.resource/css/popup.css" />
<link type="text/css" rel="stylesheet" href="javax.faces.resource/css/menu.css" />
<!--
<script type="text/javascript" src="javax.faces.resource/butterfaces-all-with-jquery-and-bootstrap-bundle.min686a.js?ln=butterfaces-dist-bundle-js"></script>
<script type="text/javascript" src="javax.faces.resource/js/jquery-3.4.0.min.js"></script>
<script type="text/javascript" src="javax.faces.resource/js/bootstrap.js"></script>
<script type="text/javascript" src="javax.faces.resource/js/jquery-1.11.2.js"></script>
<script type="text/javascript" src="javax.faces.resource/js/jssor.slider-27.5.0.min.js"></script>
<script type="text/javascript" src="javax.faces.resource/jquery8490.js?ln=js"></script>
<script type="text/javascript" src="javax.faces.resource/menu8490.js?ln=js"></script>
<script type="text/javascript" src="javax.faces.resource/js/canvasjs.min.js"></script>
        
  -->     
  <!-- Table Search start -->
<link href='https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css' rel='stylesheet' type='text/css'>
<link href='https://cdn.datatables.net/buttons/1.5.6/css/buttons.dataTables.min.css' rel='stylesheet' type='text/css'>
 <!-- Table Search end -->
        <script type="text/javascript">
            $(function() {
                $('ul.nav li.dropdown').hover(function() {
                    $(this).find('.dropdown-menu').stop(true, true).delay(100).fadeIn(500);
                }, function() {
                    $(this).find('.dropdown-menu').stop(true, true).delay(100).fadeOut(500);
                });
            });
        </script>
        <script type="text/javascript">
            $(function() {
                $("#notice").fadeIn("slow").append('');
                $(".dismis").click(function() {
                    $("#notice").fadeOut("slow");
                });
            });
        </script>
		
<script>
function lfn_SelectSection(p_Class)
    {
        document.getElementById('cusname').disabled=false;
		
  
        $.ajax({
		
                    type: "GET",
                    url: "ajax_location.html?classID=" + p_Class,
                    success: function(state) {
                    document.getElementById('cusname').innerHTML=state;    
					
                    }
        });
		
	 
		
		
    }

</script>
<style> 
        input.largerCheckbox { 
            width: 20px; 
            height: 20px; 
			
        } 
    </style> 
        <title>Katha O Cafe</title></head><body>

        <div id="top">


                    <div class="container-fluid text-center" style="margin-left: 5px"> 
                        <div class="row">
                            <div class="col-sm-1">
							<!-- Logo -->
							
							
                            </div>                           
                                       
                           
                        </div>
                    </div>

                    <!-- Menu start  -->

                    <nav class="navbar navbar-expand-lg header-m" role="navigation">
                        <div class="container-fluid">
                            <div class="navbar-header">
                                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                                    <span class="sr-only">Toggle navigation</span>
                                    <span class="icon-bar" style="background-color: #fff;"></span>
                                    <span class="icon-bar" style="background-color: #fff;"></span>
                                    <span class="icon-bar" style="background-color: #fff;"></span>
                                </button>
                                <a class="navbar-brand" href="#"></a>
                            </div>

                            <!-- Collect the nav links, forms, and other content for toggling -->
                            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                                 <?php include("include/header.php"); ?>
                            </div>

                            <!-- /.navbar-collapse -->
                        </div>
                        <!-- /.container-fluid -->
                    </nav>

        </div>

        <div id="content" class="center_content" style="background-image:url(wall.jpg)">

                    <div class="container-fluid text-center">    
                        <div class="row">
                            <div class="col-sm-2" style="padding-right: 0px;">
							
							
							
							
							
                                <?php include("include/left.php"); ?>

                                </div>

                            </div>

                            <div class="col-sm-8" style="padding-right: 2px; padding-left:2px;">

                                <div class="row" >
                                    <div class="col-sm-12" >

                                        <div class="panel panel-primary" style="background-color: rgb(186,233,254);border: 1px solid #000; margin-bottom: 0px; background-image:url(wall.jpg)  ">
                                            <div class="panel-heading" style="font-size: 20px; font-family: serif; background-color: #007de8; color:#CCFF00"> <b>Purchase Report</b></div>
                                            <div class="panel-body" style="text-align: justify;padding-bottom: 0px; padding-top: 6px;"><p style="font-family: Cambria;"><strong>
					 
					 
<form method="post">
   Type : <select name="report_type" style="height:26px;" id="report_type" >
        <option value="0" <?php if($_REQUEST["report_type"]=="0") { ?> selected <?php } else {} ?>>All Report</option>
        <option value="Coffee" <?php if($_REQUEST["report_type"]=="Coffee") { ?> selected <?php } else {} ?>>Coffee</option>
        <option value="Tea" <?php if($_REQUEST["report_type"]=="Tea") { ?> selected <?php } else {} ?> >Tea</option>
        <option value="Sandwitch" <?php if($_REQUEST["report_type"]=="Sandwitch") { ?> selected <?php } else {} ?> >Sandwitch</option>
		
		       
        <option value="Coffee" <?php if($_REQUEST["report_type"]=="Coffee") { ?> selected <?php } else {} ?>>Coffee</option>
        <option value="Starter(Veg" <?php if($_REQUEST["report_type"]=="Starter(Veg)") { ?> selected <?php } else {} ?> >Starter(Veg)</option>
        <option value="Starter(NonVeg)" <?php if($_REQUEST["report_type"]=="Starter(NonVeg)") { ?> selected <?php } else {} ?> >Starter(NonVeg)</option>
		
		        <option value="Burger" <?php if($_REQUEST["report_type"]=="Burger") { ?> selected <?php } else {} ?>>Burger</option>
        <option value="Patis" <?php if($_REQUEST["report_type"]=="Patis") { ?> selected <?php } else {} ?>>Patis</option>
        <option value="Momo" <?php if($_REQUEST["report_type"]=="Momo") { ?> selected <?php } else {} ?> >Momo</option>
        <option value="Drinks" <?php if($_REQUEST["report_type"]=="Drinks") { ?> selected <?php } else {} ?> >Drinks</option>
		
		        <option value="Snacks" <?php if($_REQUEST["report_type"]=="Snacks") { ?> selected <?php } else {} ?> >Snacks</option>
        <option value="Kitchen" <?php if($_REQUEST["report_type"]=="Kitchen") { ?> selected <?php } else {} ?> >Kitchen</option>
    </select>
<b><font color="red">From Date : </font></b>
<input type="date" name="fd" id="cat1" style="width:20%; height:26px; background-color:#99FF66" value="<?php echo $_REQUEST['fd']; ?>">&nbsp;&nbsp;&nbsp;
To : &nbsp;&nbsp;&nbsp;<input type="date" name="td" id="cat2" style="width:20%; height:26px; background-color:#99FF66" onChange="show_p()" value="<?php echo $_REQUEST['td']; ?>"> 
</form>
<p>&nbsp;</p>
<script>
function show_p() {
 var v=document.getElementById("cat1").value;
 var vv=document.getElementById("cat2").value;
 var vvv=document.getElementById("report_type").value;
 window.location.href="?fd="+v+"&td="+vv+"&report_type="+vvv;
}
</script>	

Purchase Report type of <?php echo $_REQUEST["report_type"] ?> As on <?php echo $_REQUEST["fd"] ?> To <?php echo $_REQUEST["td"] ?>	
<table class="table table-bordered table-hover" id="example"	>
    <thead>
<tr style="height:30px; background-color:#0066FF; color:#FFFFFF;">
<th align="center"><b>Sl No.</b></th>
<th align="center"><b>Date</b></th>

<th align="center"><b>Product Name </b></th>
<th align="center"><b>Volume </b></th>
<th align="center"><b>Quantity </b></th>

<th align="center"><b>Pur. Rate</b></th>
<th align="center"><b>Amount</b></th>

</tr>
</thead>
<tbody>
<?php 
	 $from_date=$_REQUEST["fd"];
	 $to_date=$_REQUEST["td"];
	 $report_type=$_REQUEST[report_type];
	 $t=0;
$i=1; $a=0; 
if($_REQUEST["report_type"]=="0") { 
$c=mysqli_query($con,"select * from purchase where `doe` BETWEEN '".$from_date."' AND '".$to_date."'  "); 
} else {
$c=mysqli_query($con,"select * from purchase where `category`='".$report_type."' and `doe` BETWEEN '".$from_date."' AND '".$to_date."'  "); 
}


// while($cr=mysqli_fetch_array($c,MYSQLI_ASSOC)) { ?><?php //$cat= $cr["bill_no"]; $cp=mysqli_query($con,"select * from onshop where `bill_no`='".$cat."' ");
 
  while($cpr=mysqli_fetch_array($c,MYSQLI_ASSOC)) {
?>
<tr <?php if($i%2 =="0") { ?> style="background-color:#FFE9D2; height:20px" <?php } else { ?> style="background-color:#A4FFA4; height:20px" <?php } ?> height="30" >

<td align="center"><?php echo $i; ?></td>
<td align="center"><?php // echo $cpn= $cpr["doe"]; 
 $temp_date=date_create($cpr["doe"]); echo date_format($temp_date,"d/m/y"); ?>
</td>


<td >&nbsp;<?php echo $cpr["product_name"]; ?></td>
<td >&nbsp;<?php echo $cpr["volume"]; ?> <?php echo $cpr["unit"]; ?></td>
<td >&nbsp;<?php echo $cpr["g_quantity"]; ?> </td>

<td>&nbsp;<?php  $t=$t+$cpr["mrp"]; echo $cpr["mrp"];   ?></td>
<td>&nbsp;<?php  echo ($cpr["mrp"]*$cpr["g_quantity"]); $a=$a+($cpr["mrp"]*$cpr["g_quantity"]);   ?></td>

<?php $i++; }
 ?>
 </tbody>
<tr>
<td colspan="6" align="right" style="height:30px;">Total Rs :&nbsp;&nbsp; </td><td>&nbsp;<?php echo $a; ?> /-</td>
</tr>
<?php if($_REQUEST["report_type"]=="wine") { ?>
<tr>
<td colspan="6" align="right" style="height:30px;">With TCS 1 % :&nbsp;&nbsp; </td><td>&nbsp;<?php echo ($a*1/100)+$a; ?> /-</td>
</tr>
<?php } else {} ?>
</table>





			

<?php   if(isset($_POST["save"]))
        {
		 $pt=$_POST["pt"];
		 $bill_no=$_REQUEST["bill_no"];
$b=mysqli_query($con,"select * from onshop where `bill_status`='pending' and `bill_no`='".$bill_no."'  "); $i=1; while($br=mysqli_fetch_array($b,MYSQLI_ASSOC)) {	
  $p_id=$br["product_id"];
  $p=mysqli_query($con,"select * from product where `id`='".$p_id."'" ); $pr=mysqli_fetch_array($p,MYSQLI_ASSOC);
		 $qnty=$br["qnty"];	
           $quantity=$pr["quantity"];
		if($br["peg_bottle"]=="peg") {  
					
					 $p=mysqli_query($con,"select * from product where `id`='".$p_id."'" ); $pr=mysqli_fetch_array($p,MYSQLI_ASSOC);
					  $total_peg=$pr["total_peg"];  //bottle
					  $current_peg=$pr["curent_peg"]; //bottle
					  
					  $remain=$total_peg - $current_peg; // peg to empty bottle 
					// $current_peg=$current_peg+ $qnty;
		 		if($qnty==$remain) {
		   			  $quantity=$quantity-1; // final quantity
					  $current_peg=0;  // final current peg
		 		} else { 
				     if($qnty > $remain) {  $qnty=$qnty-$remain;   $quantity=$quantity-1;  
					 $bc=intval($qnty/$total_peg);
					 $quantity=$quantity-$bc;
					 $remain2=$bc*$total_peg;
					 $remain2=$qnty-$remain2;
					 $current_peg=$remain2;
					 } else { $quantity;  $current_peg=$current_peg+1; }
				   /* $bc=intval($qnty/$total_peg);
				    $quantity=$quantity-$bc;
					 $remain2=$bc*$total_peg;
					 $remain2=$qnty-$remain2; //remain peg
					if($remain2>=$remain) { echo $quantity=$quantity-1;  echo $current_peg=$remain2-$remain;  } else {  }*/
				   
				}
				mysqli_query($con,"update product set `curent_peg`='".$current_peg."', `quantity`='".$quantity."' where `id`='".$p_id."' ");	
			
		
		} else { 
		$quantity=$pr["quantity"];
		 $quantity=$quantity-$qnty;
	mysqli_query($con,"update product set `quantity`='".$quantity."' where `id`='".$p_id."' ");
		}
		
 		
 mysqli_query($con,"update onshop set `bill_status`='complete', `payable`='".$pt."' where `bill_no`='".$bill_no."' ");	



?><script>window.location.href="index.php";</script><?php 	
}		
		}?>				 
<p>&nbsp;</p>					 
				
					 
					 
					 
	<!--				 					
											 <select name="class" id="class" class="form-control" onChange="lfn_SelectSection(this.value);">
                                            <option value="">--- Please Select Class ----</option>
                                             <option value="A">A</option>
											 <option value="B">B</option>
											 <option value="C">C</option>
                                             </select>
											Section
											 <select type="text" name="secname" id="secname" class="form-control" >
                                        	<option value="0">------select Section_o------</option>

                                        </select> -->	
										
                                                    </strong></p></div>
                                        </div>



                                    </div>
                                </div>

                            <!--   <div class="well" style="padding: 5px;background-color: rgb(186,233,254); border: 1px solid #000; margin-bottom: 1px;">
                                    <div class="row">
                                        
                                        
                                       
                                        
                                        
                                        
                                    </div> 
                                </div>-->
                                <div class="row">
                                   <!-- <div class="col-sm-2">
                                        <div class="panel panel-primary" style="background-color: antiquewhite;">
                                            <div class="panel-body" style="border: 1px solid #000"><img src="javax.faces.resource/school-educatione0f8.png?ln=img" width="50" />  </div>
                                            <div class="panel-footer" style="padding: 1px 2px; background-color: #007de8; font-size: 13px;"><a href="../e_Pension/AdminLogin.html"> School Education Department Users</a>  </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-2">
                                        <div class="panel panel-primary" style="background-color: #7c5a5e;">
                                            <div class="panel-body" style="border: 1px solid #000"><img src="javax.faces.resource/villagee0f8.png?ln=img" width="50" /></div>
                                            <div class="panel-footer" style="padding: 1px 2px;background-color: #007de8; font-size: 13px;"><a href="../e_Pension/AdminLogin.html">P &amp; R D Department Users</a>  </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-2">
                                        <div class="panel panel-primary" style="background-color: #f6f191;">
                                            <div class="panel-body" style="border: 1px solid #000"><img src="javax.faces.resource/librarye0f8.png?ln=img" width="50" /></div>
                                            <div class="panel-footer" style="padding: 1px 2px;background-color: #007de8; font-size: 13px;"><a href="../e_Pension/AdminLogin.html">UD &amp; MA Department Users</a>  </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-2">
                                        <div class="panel panel-primary" style="background-color: #fff;">
                                            <div class="panel-body" style="border: 1px solid #000"><img src="javax.faces.resource/images6e0f8.png?ln=img" width="50" /></div>
                                            <div class="panel-footer" style="padding: 1px 2px;background-color: #007de8; font-size: 13px;"><a href="../e_Pension/AdminLogin.html"> MEE &amp; LS Department Users</a>  </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-2">
                                        <div class="panel panel-primary" style="background-color: #ffdc6a;">
                                            <div class="panel-body" style="border: 1px solid #000"><img src="javax.faces.resource/treasurye0f8.png?ln=img" width="50" /></div>
                                            <div class="panel-footer" style="padding: 10px 5px;background-color: #007de8; font-size: 13px;"><a href="../e_Pension/AdminLogin.html">Treasury Users</a>  </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-2">
                                        <div class="panel panel-primary" style="background-color: #5cfef2;">
                                            <div class="panel-body" style="border: 1px solid #000"><img src="javax.faces.resource/users-groupe0f8.png?ln=img" width="50" /></div>
                                            <div class="panel-footer" style="padding: 1px 2px;background-color: #007de8; font-size: 12px;"><a href="../e_Pension/AdminLogin.html">Other Departments Users</a>  </div>
                                        </div>
                                    </div>    -->
                                </div>
                            
                               

                            </div>
                            <div class="col-sm-2" style="padding-left:0px;">
 <?php include("include/right.php"); ?>
                            </div>                     
                        </div>

                    </div>
</form>
        </div>


        <?php include("include/footer.php"); ?>
		

	<script src="../assets/plugins/jQuery/jquery-1.12.4.min.js" type="text/javascript"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js" type="text/javascript"></script>
 <script src="https://cdn.datatables.net/buttons/1.5.6/js/dataTables.buttons.min.js" type="text/javascript"></script>
 <script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.flash.min.js" type="text/javascript"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js" type="text/javascript"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js" type="text/javascript"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js" type="text/javascript"></script>
 <script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.html5.min.js" type="text/javascript"></script>
 <script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.print.min.js" type="text/javascript"></script>


    <script >
        $(document).ready(function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    } );
} );
</script>	
		
		</body>



</html>