Location: PHPKode > projects > eCanteen > ecanteen/user/CollatePage2.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.`OrderDate`, break.`SortOrder`, break.`~SiteID$`, break.`Break`, customersandorders.`Break$`, itemtype.`ItemType`, menuitem.`Item`, menuitem.`Cost`, Sum(customersandorders.`Quantity`) AS `SumOfQuantity`, Sum(menuitem.`Cost`) AS `SumOfCost`  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`, break.`Break`, customersandorders.`Break$`, itemtype.`ItemType`, menuitem.`Item`, menuitem.`Cost` HAVING (((customersandorders.`OrderDate`)='".$_GET["date"]."') AND ((break.`~SiteID$`)=".$_SESSION['SiteID'].") AND ((customersandorders.`Break$`)=".$_GET["BreakID"].")) ORDER BY break.`SortOrder`, itemtype.`ItemType`, menuitem.`Item`;";

//$sqlstmt="SELECT customersandorders.`OrderDate`, break.`SortOrder`, break.`~SiteID$`, break.`Break`, break.`BreakID`, customersandorders.`Break$`, itemtype.`ItemType`, menuitem.`Item`, menuitem.`Cost`, Sum(customersandorders.`Quantity`) AS `SumOfQuantity`, Sum(menuitem.`Cost`) AS `SumOfCost`  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 break.`SortOrder`, break.`Break`, customersandorders.`Break$`, itemtype.`ItemType`, menuitem.`Item`, menuitem.`Cost` 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`;";

$sqlstmt="SELECT customersandorders.`Break\$`, break.`SortOrder`, menuitem.`~SiteID\$`, break.`Break`, break.`BreakID`, break.`~SiteID\$`, itemtype.`ItemType`, 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`   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 <?   echo $_GET["Break"];?> 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>
        <tr>
   <? 
  $StName="testtest";
  $ItemName="testtest";
	$i=0;
  while($i<$num)
  {

    if ($StName!=mysql_result($result,$i,"ItemType"))
    {


      if ($StName!="testtest")
      {
?>
   <tr><td colspan="6" align=right><?         echo "$".number_format($TotalCost,2);?></td></tr>
   <?       } ?>
   <td ><?       echo mysql_result($result,$i,"ItemType");?></td>
   <? 
      $StName=mysql_result($result,$i,"ItemType");
      $TotalCost=0;

    }
      else
    {

?>
   <td >
                </td>
   
   <?     } 

         if ($ItemName!=mysql_result($result,$i,"Item"))
         {
         //show total and start new line
         if ($ItemName!="testtest")
      {
?>
   <td align=right><?echo "$".number_format($itemTotal,2);?></td><td><?echo "$".number_format($itemQuantity,0);?></td></tr>
   <?       } ?>
   <td ><?       echo mysql_result($result,$i,"Item");?></td>
   <? 
      $StName=mysql_result($result,$i,"Item");
      $itemQuantity=0;
      $itemTotal=0;
         
         
         
         }else{
         //continue counting and adding.
         $itemTotal=$itemTotal+mysql_result($result,$i,"cost")*mysql_result($result,$i,"SumOfQuantity");
         $itemQuantity=$itemQuantity+mysql_result($result,$i,"SumOfQuantity");
         
         
         }
    
        
        
    $TotalCost=$TotalCost+mysql_result($result,$i,"cost")*mysql_result($result,$i,"SumOfQuantity");
    $GrandTotal=$GrandTotal+mysql_result($result,$i,"cost")*mysql_result($result,$i,"SumOfQuantity");
    $i++;

  } ?>
        <tr><td colspan="6" align=right><?   echo "$".$TotalCost;?></td></tr>
        <tr><td colspan="6" align=right><?   echo "$".$GrandTotal;?></td></tr>
    </table>
<? 
} 
$objConnection1.close;
?>
</body>
</html>
<?}?>

Return current item: eCanteen