Location: PHPKode > projects > eCanteen > ecanteen/user/collatepage.php
<?

//Copyright David Byrne 2007

//This file is part of eCanteen.

//    eCanteen is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.

//    eCanteen is distributed in the hope that it will be useful
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.

//    You should have received a copy of the GNU General Public License
//    along with eCanteen.  If not, see <http://www.gnu.org/licenses/>.

  session_start();
if ($_SESSION['userlevel']>=3)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
    
    
<? 

include("../include/constants.php");     mysql_free_result();
	session_start();

$objConnection1  = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
  mysql_select_db(DB_NAME);


$sqlstmt="SELECT customersandorders.`Break\$`, break.`SortOrder`, menuitem.`~SiteID\$`, break.`Break`, break.`BreakID`,itemtype.`ItemTypeID`, break.`~SiteID\$`, itemtype.`ItemType`, menuitem.`MenuItemID`, menuitem.`Item`, menuitem.`Cost`, Sum(customersandorders.`Quantity`) AS SumOfQuantity FROM (itemtype INNER JOIN menuitem ON itemtype.`ItemTypeID` = menuitem.`ItemType\$`) INNER JOIN (customersandorders INNER JOIN break ON customersandorders.`Break\$` = break.`BreakID`) ON menuitem.`MenuItemID` = customersandorders.`MenuItem\$` GROUP BY customersandorders.`OrderDate`, break.`SortOrder`, menuitem.`~SiteID\$`, break.`Break`, break.`BreakID`, itemtype.`ItemType`, menuitem.`Item`, menuitem.`Cost`, menuitem.`MenuItemID` HAVING (((customersandorders.`OrderDate`)>='".$_GET["date1"]."') AND ((customersandorders.`OrderDate`)<='".$_GET["date2"]."') AND ((break.`~SiteID\$`)=".$_SESSION['SiteID'].") AND ((customersandorders.`Break\$`)=".$_GET["BreakID"].")) ORDER BY break.`SortOrder`, itemtype.`ItemType`, menuitem.`Item`;";
//echo $sqlstmt;
//break;
$result=mysql_query($sqlstmt);
//echo mysql_error(); 
$num=mysql_numrows($result);

//break;

?>    
</head>
<body>
<? if ($num==0)
{

?>
All orders cancelled.

<? 

}
  else
{





?>
<table style="width: 800px" border="1">
    <tr>
        <td colspan="5">
        Collated Orders for <?   echo $_GET["date1"];if ($_GET["date1"]!=$_GET["date2"]){echo " to ".$_GET["date2"];};?>
        </td>
        </tr>
        <tr>
            <td >
                Type</td>
            <td >
                Item</td>
            <td >
               Cost</td>
            <td >
                Quantity</td>
            <td >
                Total</td>
            
        </tr>
<?
$menuitemx=0;
$countx=0;
$itemQuantity=0;
$GrandTotal=0;
$menuitemtypex=0;
$typeTotal=0;
$i=0;
  while($i<$num)
  {
    //echo intval($menuitemtypex)."-".mysql_result($result,$i,"ItemTypeID")."<br>";
   if (intval($menuitemx)!=mysql_result($result,$i,"MenuItemID"))
   {
   if (intval($menuitemx)!=0)
      {
      $typeTotal=$typeTotal+($costx*$itemQuantity);
      $GrandTotal=$GrandTotal+($costx*$itemQuantity);
      
  ?>
  
            <td align="right">
                 <?echo $itemQuantity;?></td>
            <td align="right" >
                <?
              echo  "$".number_format($costx*$itemQuantity,2);?></td>
            
  </tr>
  
  
  <?
     $itemQuantity=0;
      
  
  $countx=0;
     }else{
     ?>
     <tr>
            <td >
                <?echo mysql_result($result,$i,"ItemType");?></td>
            <td >
                <?echo mysql_result($result,$i,"Item");?></td>
            <td align="right">$<?echo mysql_result($result,$i,"cost");?></td>    
     <?
     $countx=1;
     $itemQuantity=mysql_result($result,$i,"SumOfQuantity");
     $costx=mysql_result($result,$i,"cost"); 

     
     
     }
  
  if (intval($menuitemtypex)!=mysql_result($result,$i,"ItemTypeID"))
  {
    if (intval($menuitemtypex)!=0)
    {
      ?>
      <tr><td>&nbsp</td><td>&nbsp</td>&nbsp<td>&nbsp</td><td>&nbsp</td><td align="right">
      <?
      echo "$".number_format($typeTotal,2);
      ?>
      </td></tr>
      <?
      $typeTotal=0;
      
     
  }
  
  
  }$menuitemtypex=mysql_result($result,$i,"ItemTypeID");
  $menuitemx=mysql_result($result,$i,"MenuItemID");
  $costx=mysql_result($result,$i,"cost");  
  }else{
     if ($countx==0)
     {
     ?>
     <tr>
            <td >
                <?echo mysql_result($result,$i,"ItemType");?></td>
            <td >
                <?echo mysql_result($result,$i,"Item");?></td>
            <td align="right">$<?echo mysql_result($result,$i,"cost");?></td>
               
     
     
     <?
     $countx=1;
     $itemQuantity=$itemQuantity+mysql_result($result,$i,"SumOfQuantity");
     }
     $itemQuantity=$itemQuantity+mysql_result($result,$i,"SumOfQuantity");
  }
  
   $i++;

  }
  ?>
  <td align="right">
                 <?echo $itemQuantity;?></td>
            <td align="right" >
                <?echo "$".number_format($costx*$itemQuantity,2);?></td>
            
  </tr>
  
  <?
  $typeTotal=$typeTotal+($costx*$itemQuantity);
  $GrandTotal=$GrandTotal+($costx*$itemQuantity);
  
  
$i=0;
?>        
        
<tr><td>&nbsp</td><td>&nbsp</td>&nbsp<td>&nbsp</td><td>&nbsp</td><td align="right">

   
<? 

echo "$".number_format($typeTotal,2);
?>        
        
<tr><td>&nbsp</td><td>&nbsp</td>&nbsp<td>&nbsp</td><td>&nbsp</td><td align="right">

   
<? 
}

echo "$".number_format($GrandTotal,2);
$objConnection1.close;
?>
</td></tr>
</table>
</body>
</html>
<?}?>

Return current item: eCanteen