<?php
include_once '_function/_funs.php';
$LastOrderID=null;
$CompanyName=null;
$is_exist=null;
$GUID = "";
if (isset($_COOKIE["wechat"])) {
    $GUID = $_COOKIE['wechat'];
}
$MyComputerName = 'PDA';
include_once '_dbdir.php';


//验证和客户
if (!empty($GUID)) {
    if (!$is_exist) {
        //echo "验证和客户";
        $query_RecordsetCFG = "SELECT top 1 CompanyName,CustomerID  FROM Customers where CustomerID='" . save2mssql($GUID) . "'";
        $values             = $orders->query($query_RecordsetCFG);
     	 $LastOrderID="";
        if (is_iterable($values)) {
            foreach ($values as $value) {
                $CompanyName         = loadFromMssql($value['CompanyName']);
                //if ($debug) console_log('CompanyName :' . $CompanyName);

				//启用餐台可以继续编辑结帐中的单据。反之进入结帐中的单据就不可再编辑，点击台号后开新单
				if ($CFG_ShowDesk==1) {
					$deskstr="(Status='". save2mssql('结账中')."' or Status='". save2mssql('服务中')."')";
				}else{ 
					$deskstr="Status='". save2mssql('服务中')."'";
				}
				
				$query_RecordsetCFG2 = "SELECT top 1  Orders.OrderID  FROM Customers   LEFT OUTER JOIN Orders ON Customers.CustomerID = Orders.CustomerID    where Customers.CustomerID='".save2mssql($GUID)."' and ". $deskstr." order by Customers.CustomerID ";
				// die ($query_RecordsetCFG2);
				$values = $orders->query($query_RecordsetCFG2);
				if (is_iterable($values)) {  foreach ($values as $value) {   $LastOrderID = loadFromMssql($value['OrderID']);   }  }
			}//-end-foreach
        } //-end-if (is_iterable($values))
    }//-end-if (!$is_exist)
}//-end-if (!empty($GUID))
?>