<?php
include("../include/session.php");
if( !$session->isAdmin() && !$session->isRadstoneReceptionUser() ){
	//header("Location: ../Store/storeMenu.php");?>
<script language="javascript" type="text/javascript">
        <!--
		  window.location="denied.php";
        -->
       </script>
<?php 
}else{
	include("../storeHeader.php");
	
	require_once('classes/tc_calendar.php');
	$date = mysql_real_escape_string($_GET['date']);
	
	if ($date==1) {
	$start = mysql_real_escape_string($_GET['date1']);
    $end = mysql_real_escape_string($_GET['date2']);
	}
	else {
	$start = date("Y-m-01");
	$end = date("Y-m-d");
	}
	
		
	if ($date!=1) {
	   $ds = "1"; }
	   else {
		$ds = date("d", strtotime($start) );
	   }
	$ms = date("m", strtotime($start) );
	$ys = date("Y", strtotime($start) );
	
	
	$de = date("d", strtotime($end) );
	$me = date("m", strtotime($end) );
	$ye = date("Y", strtotime($end) );	
	

    $CustNo = mysql_real_escape_string($_GET['CustNo']);
	
	$clientQuery = "SELECT CompanyName FROM nam_customer WHERE CustNo = ".$CustNo;
	$clientResult = execsql($clientQuery);
	$client = mysql_result($clientResult, 0, "CompanyName");
	
	   
	$selectQuery = "SELECT productId, client, SUM(quantity) AS summedQuantity FROM nam_sales  WHERE client ='".$client."' AND date > '".$start."' AND date <= '".$end."' GROUP BY productId, client ";
	$selectResult = execsql($selectQuery);
	$selectNum = mysql_num_rows($selectResult);
		
	
   
	?>
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../css/tablesort.js"></script>
<table id="tableMain" width="595">
  <!--begin of tableMain-->
  <tr>
    <td ><div class="headerbox2"> Customer Deliveries</div>
      <br />
      <p class="main"><label class="std"><font size="3"><?php echo $client ?></font></label> </p>
    <br /></td>
    <!--center of tableMain-->
  </tr>
  <tr>
    <td><div id="coloredContainer">
  <form action="deliveriesCustomer.php" method="get" name="dateform" class="today" id="dateform">
    <span class="style7">
    from:
      &nbsp;&nbsp;
      <?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("../img/iconCalendar.gif");
		$myCalendar->setDate($ds, $ms, $ys);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2000, 2030);
	 	$myCalendar->writeScript();?>
      &nbsp;&nbsp;to:&nbsp;&nbsp;
    <?php
		$myCalendar = new tc_calendar("date2", true);
		$myCalendar->setIcon("../img/iconCalendar.gif");
		$myCalendar->setDate($de, $me, $ye);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2000, 2030);
		$myCalendar->writeScript();?>
      &nbsp;&nbsp;
      <label>
        <input type="submit" name="button" id="button" value="Go" />
        <input name="date" type="hidden" id="date" value="1" />
        
      </label>
      <input name="CustNo" type="hidden" id="CustNo" value="<?php echo $CustNo ?>" />
  </form></div><br />

  
      <table width="576" class="sortable-onload-0 rowstyle-alt no-arrow " id="tableList"  >
        <thead>
          <tr>
            <th width="200" class="sortable-text">Product</th>
            <th width="98" class="sortable-numeric">Delivered</th>
            <th width="138" >&nbsp;</th>
            
            <!--        <th>Reserved Stock</th>-->
          </tr>
        </thead>
        <tbody>
          <?php
  $i=0;
  while ($i < $selectNum) {
			 $b0 = mysql_result($selectResult, $i, "productId");
			     $productQuery = "SELECT productName FROM nam_products WHERE productId = ".$b0;
	             $productResult = execsql($productQuery);
	             $b1 = mysql_result($productResult, 0, "productName");
			 $b2 = mysql_result($selectResult, $i, "summedQuantity"); 
  
  ?>
  <tr>
    <td><?php echo $b1 ?></td>
    <td align="right"><?php echo $b2 ?></td>
    <td>&nbsp;</td>
  </tr>
  <?php
  $i++;
  }
  ?>
        </tbody>
      </table>
    <p>&nbsp; </p></td>
  </tr>
</table>
<!--end of tableMain-->
<p>
  <?php
	}
	include("../footer.php");

?>
</p>
</p>
