<?php include_once 'init-lite.php'; 
?>
<script type="text/javascript">
 </script>

<form class="ui-filterable">
      <input id="myFilter" placeholder="根据名称搜索"  data-type="search" data-clear-btn="true">
    </form>
    <span id="myDiv"></span>
  <table data-role="table" id="myTable"  data-mode="columntoggle" class="ui-responsive table-stroke" data-filter="true" data-input="#myFilter" data-autodividers="true"  data-column-btn-text="选择显示列">

    <thead>
        <tr>
          <th>日期</th>
          <th>类型</th>
          <th>付款</th>
          <th>金额</th>
        </tr>
      </thead>
      <tbody>
<?php
$sql = "SELECT      RequiredDate, ShipType,  PaymentType , sum( SubTotal) as SubTotal
FROM         Orders ";

if (!empty($_POST['Status']) && strlen($_POST['Status'])>0 &&  $_POST['Status']=='All') 
	$sqlselect = " where ";    
elseif (!empty($_POST['Status']) && strlen($_POST['Status'])>0) 
	$sqlselect = " where  Status=".GetSQLValueStringGBK($_POST['Status'], "text");    
else
	$sqlselect = " where  Status=".GetSQLValueStringGBK('结账中', "text"); 
 
if (!empty($_POST['date']) && strlen($_POST['date'])>0) 
	$sqlselect .= "  and RequiredDate like '".$_POST['date']."%'";  
else
	$sqlselect .= "  and RequiredDate like '".date("Y-m")."%'"; 

if (!empty($_POST['Status2']) && strlen($_POST['Status2'])>0) 
	if ($_POST['Status2']=='all')
		$sql .= $sqlselect . "  group by RequiredDate,Status"; 
	else if ($_POST['Status2']=='filter')
		$sql .= $sqlselect . "  group by RequiredDate,Status,ShipType, PaymentType "; 
else
	$sql .= $sqlselect . "  group by RequiredDate,Status,ShipType,  PaymentType "; 

//echo $sql;

$values = $orders->query($sql);
if (is_iterable($values)){
  foreach ($values as $pProductsAddMenu){ 
$Line1++; 
$pProductsAddMenu['ShipType']=loadFromMssql($pProductsAddMenu['ShipType']);
$pProductsAddMenu['PaymentType']=loadFromMssql($pProductsAddMenu['PaymentType']);
$pProductsAddMenu['Status']=loadFromMssql($pProductsAddMenu['Status']);

$ShipType		=$pProductsAddMenu['ShipType'];
$PaymentType	=$pProductsAddMenu['PaymentType'];
$Status			=$pProductsAddMenu['Status'];
	switch ($pProductsAddMenu['Status']) {
			case "结账中":
				$Status='已下单';
				break;
			case "服务中":
				$Status='下单中';
				break;
			default:
			   $Status='';
		}
		switch ($pProductsAddMenu['PaymentType']) {
			case "cash":
				$PaymentTypeInfo='现金';
				break;
			case "vor":
				$PaymentTypeInfo='饭票';
				break;
			case "other":
				$PaymentTypeInfo='其他';
				break;
			default:
			   $PaymentTypeInfo='xx';
		}   
 	switch ($pProductsAddMenu['ShipType']) {
			case "takeaway":
				$ShipTypeInfo='外卖';
				break;
			case "inside":
				$ShipTypeInfo='店内';
				break;
			case "takemyself":
				$ShipTypeInfo='自提';
				break;
			default:
			   $ShipTypeInfo='xx';
		}

	?>                         
<tr>
<td ><a href="<?php echo $pProductsAddMenu['RequiredDate']; ?>" data-rel="external"><?php echo $pProductsAddMenu['RequiredDate']; ?></a></td>
<td ><?php echo $ShipTypeInfo; ?></td>
<td ><?php echo $PaymentTypeInfo; ?></td>
<td ><?php echo $pProductsAddMenu['SubTotal']; ?></td>
</tr> <?php } ?>
<tr>
<td >&nbsp;</td>
<td >&nbsp;</td>
<td bgcolor="#FFCC00" ><strong>合计 ：&nbsp;</strong></td>
<td bgcolor="#FFCC00" ><strong><?php
$sql = "SELECT     sum(SubTotal) as SubTotal, RequiredDate
FROM         Orders ". $sqlselect ; 

//echo $sql;

$values = $orders->query($sql);
if (is_iterable($values)){
  foreach ($values as $pProductsAddMenu){ 
	echo  $pProductsAddMenu['SubTotal'];
}
}
}
	?></strong></td>
</tr>      </tbody>
    </table>
       