<?php 


$fromDate = $_REQUEST['fromDate'];
$toDate = $_REQUEST['toDate'] . " 23:59:59";


$salesman = $_REQUEST['sm'];




 ?>
 
 <!DOCTYPE html>
 <html lang="en">
   <head>
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <title><?= $config['CompanyName'] ?> - Analysis Report - <?= $salesman->Name ?></title>
 
     <!-- Bootstrap -->
     <link href="../css/bootstrap.min.css" rel="stylesheet">
     <link rel="stylesheet" href="../css/bootstrap-combobox.css" />
 
     <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
     <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
     <!--[if lt IE 9]>
       <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
       <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
       <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
           <!-- Include all compiled plugins (below), or include individual files as needed -->
           <script src="../js/bootstrap.min.js"></script>
       	 <script src="../js/bootstrap-combobox.js"></script>
       	 <script src="../js/excellentexport.js"></script>
				 <script src="../js/functions.js"></script>
           <script type="text/javascript">
             $(document).ready(function(){
       //        $('.grpline').css("width", "100px");
             });
           </script>

     <![endif]-->
	<link rel="stylesheet" href="../css/styles.css"/>
	<style>
		.listPanel {
			height: 500px;
			background-color: #eee;
			
		}
		@media print {
			.breakBefore {page-break-before: always;}
		}
		a[href]:after{
	    content:"";
		}
	</style>
   </head>
   <body>
   
       <?php
			 //include("navbar.php");
			 
			 ?>     

<?php
if($salesman == "ALL"){
	$q = "SELECT ID FROM SALESMAN WHERE ID != 'FJ' AND ID != 'AR' AND ID != '91' AND ID != '96' AND ID != '97' AND ID != '0' AND ID != '98' AND ID != '99' AND ID != '30' AND ID != 'PXX'";
	
	$rslt = mysqli_query($con, $q);
	while($rw = mysqli_fetch_array($rslt)){
		displaySAR_EJAS($rw['ID']);
	
		displaySAR_EV($rw['ID']);
		echo '<div class="breakBefore"></div>';
	}
}else{
	
	displaySAR_EJAS($salesman);
	
	displaySAR_EV($salesman);
	echo '<div class="breakBefore"></div>';
}



function displaySAR_EJAS($sm){
		global $con;
		global $fromDate;
		global $toDate;
		
$salesman = new Salesman($sm);

?>
   <div class="container-fluid">
		<div class="row">
			<div class="col-xs-12">
				<h2 class="text-center">
					<img style="width: 200px;" src="../img/logo_ej.png" /><br />
					Salesman Analysis Report
				</h2>
			</div>
		</div>
		<div class="row">
			<div class="col-xs-6">
				<h5>
					Salesman: <?=   $salesman->ID . "-" . $salesman->Name ?>
				</h5>
				<h5>
					Today's Date: <?=   date('m/d/Y', time()-(4*60*60))?>
				</h5>
			</div>
			<div class="col-xs-6">
				<h5>
					From: <?= date('m/d/Y',strtotime($_REQUEST['fromDate'])) ?> To: <?=  date('m/d/Y',strtotime($_REQUEST['toDate'])) ?>
				</h5>
			</div>
		</div>
		<div class="row">
					<div class="col-xs-4">
						<?php
								
								
						
						?>
						<h3>
							Sales
						</h3>
						<table class="table table-condensed table-hover">
							<thead>
								<tr>
									<th>ID</th>
									<th>Date</th>
								</tr>
							</thead>
							<tbody>
								<?php
								global $con;
								$query = "SELECT OrderID, OrderDate FROM `ORDER_HEAD` WHERE OrderDate Between '$fromDate' AND '$toDate' AND Salesman = '" . $salesman->ID . "' AND SalesmanOrder = 1";
								$result = mysqli_query($con, $query);
								
								$orderCount  = mysqli_num_rows($result);
								//var_dump($query);
								while($row = mysqli_fetch_array($result)){
								
								?>
								<tr>
									<td>
										<?= $row['OrderID'] ?>
									</td>
									<td>
										<?= date('m/d/Y h:i A', strtotime($row['OrderDate'])) ?>
									</td>
								</tr>
								<?php
								}
								?>
							</tbody>
						</table>
					</div>
					<div class="col-xs-4">
						<h3>
							Payments
						</h3>
						<table class="table table-condensed table-hover">
							<thead>
								<tr>
									<th>ID</th>
									<th>Date</th>
								</tr>
							</thead>
							<tbody>
								<?php
								
								$query = "SELECT ID, PaymentDate FROM `PAYMENT_HEAD` WHERE PaymentDate Between '$fromDate' AND '$toDate' AND SalesmanID = '" . $salesman->ID . "'";
								$result = mysqli_query($con, $query);
								$paymentCount  = mysqli_num_rows($result);
								while($row = mysqli_fetch_array($result)){
								
								?>
									<tr>
									<td>
										<a target="_blank" href="mod.php?p=payment&a=admin.viewpayment&id=<?= $row['ID'] ?>"><?= $row['ID'] ?></a>
									</td>
									<td>
										<?= date('m/d/Y h:i A', strtotime($row['PaymentDate'])) ?>
									</td>
								</tr>
								<?php
								}
								?>
							</tbody>
						</table>
					</div>
					<div class="col-xs-4">
						<h3>
							Pickups
						</h3>
						<table class="table table-condensed table-hover">
							<thead>
								<tr>
									<th>ID</th>
									<th>Date</th>
								</tr>
							</thead>
							<tbody>
								<?php
								
								$query = "SELECT PickupID, PickupDate FROM `PICKUP_HEAD` WHERE PickupDate Between '$fromDate' AND '$toDate' AND Salesman = '" . $salesman->ID . "'";
								$result = mysqli_query($con, $query);
								$pickupCount  = mysqli_num_rows($result);
								while($row = mysqli_fetch_array($result)){
								
								?>
									<tr>
									<td>
										<?= $row['PickupID'] ?>
									</td>
									<td>
										<?= date('m/d/Y h:i A', strtotime($row['PickupDate'])) ?>
									</td>
								</tr>
								<?php
								}
								?>
							</tbody>
						</table>
					</div>
				</div>
		<div class="row">
			<div class="col-xs-4 text-center">
				<h4>Order Count</h4>
				<h1 class="">
					
					<?= $orderCount ?>
				</h1>
			</div>
			<div class="col-xs-4 text-center" >
				<h4>Payment Count</h4>
				<h1 class="text-center" >
					<?= $paymentCount ?>
				</h1>
			</div>
			<div class="col-xs-4 text-center">
				<h4>Pickup Count</h4>
				<h1 class="text-center">
					<?= $pickupCount ?>
				</h1>
			</div>
		</div>
		<hr />
		<!--   START EMPRESAS VELAZQUEZ SECTION   -->
		
		<?php
}
function displaySAR_EV($sid){
	//global $con;
		global $fromDate;
		global $toDate;
		$salesman = new Salesman($sid);
		if($sid == 35 || $sid == 37 || $sid == 38){
		//if salesman is 35 ,37, or 38, substract 20 to get 15, 17 or 18 respectively (Salesmen with 2 numbers)
			$sid -= 20;
		}
		$salesman->ID = $sid;
		
		?>
		
		<div class="row">
			<div class="col-xs-12">
				<h2 class="text-center">
					<img style="width: 300px;" src="../img/logo_velazquez.png" /><br />
					
				</h2>
			</div>
		</div>
		<div class="row">
			<div class="col-xs-6">
				<h5>
					Salesman: <?=   $salesman->ID . "-" . $salesman->Name ?>
				</h5>
				<h5>
					Today's Date: <?=   date('m/d/Y', time()-(4*60*60))?>
				</h5>
			</div>
			<div class="col-xs-6">
				<h5>
					From: <?= date('m/d/Y',strtotime($_REQUEST['fromDate'])) ?> To: <?=  date('m/d/Y',strtotime($_REQUEST['toDate'])) ?>
				</h5>
			</div>
		</div>
		<div class="row">
					<div class="col-xs-4">
						<?php
								
								
						
						?>
						<h3>
							Sales
						</h3>
						<table class="table table-condensed table-hover">
							<thead>
								<tr>
									<th>ID</th>
									<th>Date</th>
								</tr>
							</thead>
							<tbody>
								<?php
								
								$con = mysqli_connect("localhost","grandaut_ev","R334XEmWe2&h%XJQ","grandaut_orders_ev");
								
								$query = "SELECT OrderID, OrderDate FROM `ORDER_HEAD` WHERE OrderDate Between '$fromDate' AND '$toDate' AND Salesman = '" . $salesman->ID . "' AND SalesmanOrder = 1";
								$result = mysqli_query($con, $query);
								$orderCount  = mysqli_num_rows($result);
								
								while($row = mysqli_fetch_array($result)){
								
								?>
								<tr>
									<td>
										<?= $row['OrderID'] ?>
									</td>
									<td>
										<?= date('m/d/Y h:i A', strtotime($row['OrderDate'])) ?>
									</td>
								</tr>
								<?php
								}
								?>
							</tbody>
						</table>
					</div>
					<div class="col-xs-4">
						<h3>
							Payments
						</h3>
						<table class="table table-condensed table-hover">
							<thead>
								<tr>
									<th>ID</th>
									<th>Date</th>
								</tr>
							</thead>
							<tbody>
								<?php
								
								$query = "SELECT ID, PaymentDate FROM `PAYMENT_HEAD` WHERE PaymentDate Between '$fromDate' AND '$toDate' AND SalesmanID = '" . $salesman->ID . "'";
								$result = mysqli_query($con, $query);
								$paymentCount  = mysqli_num_rows($result);
								while($row = mysqli_fetch_array($result)){
								
								?>
									<tr>
									<td>
										<a target="_blank" href="http://orders.empresasvelazquez.com/admin/mod.php?p=payment&a=admin.viewpayment&id=<?= $row['ID'] ?>"><?= $row['ID'] ?></a>
									</td>
									<td>
										<?= date('m/d/Y h:i A', strtotime($row['PaymentDate'])) ?>
									</td>
								</tr>
								<?php
								}
								?>
							</tbody>
						</table>
					</div>
					<div class="col-xs-4">
						<h3>
							Pickups
						</h3>
						<table class="table table-condensed table-hover">
							<thead>
								<tr>
									<th>ID</th>
									<th>Date</th>
								</tr>
							</thead>
							<tbody>
								<?php
								
								$query = "SELECT PickupID, PickupDate FROM `PICKUP_HEAD` WHERE PickupDate Between '$fromDate' AND '$toDate' AND Salesman = '" . $salesman->ID . "'";
								$result = mysqli_query($con, $query);
								$pickupCount  = mysqli_num_rows($result);
								while($row = mysqli_fetch_array($result)){
								
								?>
									<tr>
									<td>
										<?= $row['PickupID'] ?>
									</td>
									<td>
										<?= date('m/d/Y h:i A', strtotime($row['PickupDate'])) ?>
									</td>
								</tr>
								<?php
								}
								?>
							</tbody>
						</table>
					</div>
				</div>
		<div class="row">
			<div class="col-xs-4 text-center">
				<h4>Order Count</h4>
				<h1 class="">
					
					<?= $orderCount ?>
				</h1>
			</div>
			<div class="col-xs-4 text-center" >
				<h4>Payment Count</h4>
				<h1 class="text-center" >
					<?= $paymentCount ?>
				</h1>
			</div>
			<div class="col-xs-4 text-center">
				<h4>Pickup Count</h4>
				<h1 class="text-center">
					<?= $pickupCount ?>
				</h1>
			</div>
		</div>
		
		
		
		
		
		<!--   END EMPRESAS VELAZQUEZ SECTION   -->
		<div class="row">
			<div class="col-xs-12">
				<div class="col-xs-3">
					<h4>Salesman</h4>
				</div>
				<div class="col-xs-9">
					<h4>___________________________</h4>
				</div>
				<br />
				<br />
				<div class="col-xs-3">
					<h4>Sales Manager</h4>
				</div>
				<div class="col-xs-9">
					<h4>___________________________</h4>
				</div>
				
			</div>
		</div>
	</div>
<?php
}
?>
</div>
   </body>
   
 </html>