<?PHP
ob_start();
session_start();
include 'connect.php';
if(isset($_SESSION['adminemail']))
{
$user=$_SESSION['adminemail'];

$gtp=mysqli_query($conn,"select * from admin where username='$user'");
$gtp1=mysqli_fetch_assoc($gtp);

include 'top.php';
?>


<div id="page-wrapper" >
          <div id="page-inner">
			<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">Home</a>
							</li>
							<li class="active">Routewise Report</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

						<div class="page-header">
                        
<?php

$aca=mysqli_query($conn,"select * from financial where user='$user' order by ID desc");
$aca1=mysqli_fetch_assoc($aca);

$financial=$aca1['financial'];

?>                        
                        
							<table style="width:100%;">
                        
                        <tr><td style="width:50%;">
                        
							<h1>
								Routewise Report
							</h1>
                            
                            </td>
                            
                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">
                            
                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>
                            
                            </td></tr></table>
                            
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->

<script src="assets/js/jquery-2.1.4.min.js"></script>



<?php


	if(isset($_POST['submit']))
	{

		$route=$_POST['route'];
		
		echo"<table>
		
		<tr><td>Route : <b>".$route."</b></td></tr>
		
		</table>
		
		<table class='table table-bordered table-condensed'>
		
		<thead><tr><th style='width:10%;'>Order No.</th><th style='width:10%;'>Date</th>
		<th style='width:25%;'>Customer</th><th style='width:12%;'>Mobile</th>				<th style='width:15%;'>District</th><th style='width:15%;'>Exucutive</th><th style='width:12%;'>Order Value</th></tr></thead>";
		
		$tot=0;
		$sel=mysqli_query($conn,"SELECT sales_order.orderno AS orderno, sales_order.date AS date, sales_order.customer AS customer, sales_order.executive AS executive, sum( sales_order.total ) AS total FROM sales_order LEFT JOIN customer ON sales_order.customer = customer.ID LEFT JOIN route ON route.district = customer.district WHERE route.route = '$route' GROUP BY sales_order.orderno");
		while($sel1=mysqli_fetch_assoc($sel))
		{
			
			$cus=mysqli_query($conn,"select * from customer where ID='$sel1[customer]'");
			$cus1=mysqli_fetch_assoc($cus);
			
			$exc=mysqli_query($conn,"select * from employee where ID='$sel1[executive]'");
			$exc1=mysqli_fetch_assoc($exc);
					$dis=mysqli_query($conn,"select * from districts where ID='$cus1[district]'");			$dis1=mysqli_fetch_assoc($dis);		
			echo"<tr><td>".$sel1['orderno']."</td><td>".date('d-m-Y',strtotime($sel1['date']))."</td>
			<td>".$cus1['name']."</td><td>".$cus1['mobile1']."</td><td>".$dis1['district']."</td><td>".$exc1['name']."</td>						<td style='text-align:right;'>".number_format($sel1['total'],2,'.','')."</td></tr>";
			
			$tot=$tot+$sel1['total'];
		
		}
		
		echo"<tr><td colspan='6' style='text-align:right;'>Total</td><td style='text-align:right;'>".number_format($tot,2,'.','')."</td></tr>
		
		</table><br />
		
		<center><a href='routewisereport.php'>Back</a></center>";

	}

	else
	{

		echo'<center><form action="routewisereport.php" method="post" id="course"><table width="60%">

		<tr><td id="page">Route <span class="red"></span> </td><td></td><td> <select class="form-control" name="route" style="width:220px;">
		<option value="Route 1">-- Select --</option>
		<option value="Route 1">Route 1</option>
		<option value="Route 2">Route 2</option>
		<option value="Route 3">Route 3</option>
		<option value="Route 4">Route 4</option></select></td></tr>

		<tr><td></td><td></td><td style="padding-top:7px;"><input class="btn btn btn-primary" type="submit" name="submit" value="Save" /></td></tr></table></form></center>';

	}

?>




										<!-- PAGE CONTENT ENDS -->
									</div><!-- /.col -->
								</div><!-- /.row -->
							</div><!-- /.page-content -->
						</div>
					</div><!-- /.main-content -->
					</div><!-- /.main-content -->
					</div><!-- /.main-content -->



<?php

include 'bottom.php';

}
else
{

 header("location:login.php");

}


ob_flush();


?>