<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<0008>")) {	//没有权限
		ob_clean();
		header("Location: accesserror.html");
		exit;
	}
?>


<html>

<head>
<title>上网费用结算</title>
</head>

<body background="bkg.bmp">

<p align="center"><font size="5"><b>上网费用结算表</b></font></p>
<hr color="#999966">

<?php
	$timestr=strftime("%Y-%m-%d %H:%M:%S");
	$loginname="";
	$password="";
	$addtime="";
	$usertype="";
	$checktime=$timestr;
	$alltime=trim($_REQUEST["alltime"]);
	$alllength=trim($_REQUEST["alllength"]);
	$money1=trim($_REQUEST["money1"]);			//结算费用
	$money2=trim($_REQUEST["money2"]);			//实际收取费用
	$money3=trim($_REQUEST["money3"]);
	$prepay=trim($_REQUEST["prepay"]);
	$discount=trim($_REQUEST["discount"]);
	$comment=trim($_REQUEST["comment"]);
	$userid = trim($_REQUEST["userid"]);
	$price=trim($_REQUEST["price"]);
	if ($userid!="") {
		$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
		mysql_select_db(get_cfg_var("SIPDB"),$db);
		$rs = mysql_query("select loginname,password,type,addtime from users where userid='".$userid."'",$db);	//取该用户开号数据
		if ($row = mysql_fetch_array($rs)) {
			$loginname=$row[0];
			$password=$row[1];
			$usertype=$row[2];
			$addtime=$row[3];
			mysql_free_result($rs);
			$sqlStr="insert into account(userid,loginname,password,type,addtime,checktime,usetime,datalength,price,money1,discount,money2,comment)";
			$sqlStr=$sqlStr." values('".$userid."','".$loginname."','".$password."','".$usertype."','".$addtime."','".$checktime."',";
			$sqlStr=$sqlStr.$alltime.",".$alllength.",".$price.",".$money1.",".$discount.",".$money2.",'".$comment."')";
			mysql_query($sqlStr,$db);
			mysql_query("update users set checked='y' where userid='".$userid."'",$db);
			mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','结帐销号，用户ID：".$userid."')",$db );
			$m=floatval($money3);
			if ($m!=0) {
				mysql_query( "insert into cash values('".$userid."','".$timestr."',".$money3.",'2','".$_SESSION["operator"]."')",$db );
			}
			echo("<p align=center>结帐成功！</p>");
		} else {
			mysql_free_result($rs);
			echo("<p align=center>该用户ID不存在，或者已经结帐销号！</p>");
		}
		mysql_close($db);
	} else {
		echo("<p align=center>结帐失败！</p>");
	}
?>

<div align="center">
  <center>
  <table border="1" width="632" bordercolor="#008080" cellspacing="0" cellpadding="0" height="308">
    <tr>
      <td width="148" height="30">用户ID</td>
      <td width="468" height="30" align="center"><?php echo $loginname; ?></td>
    </tr>
    <tr>
      <td width="148" height="29">开号时间</td>
      <td width="468" height="29" align="center"><?php echo $addtime; ?></td>
    </tr>
    <tr>
      <td width="148" height="27">计费类型</td>
      <td width="468" height="27" align="center"><?php echo $usertype; ?></td>
    </tr>
    <tr>
      <td width="148" height="29">结帐时间</td>
      <td width="468" height="29" align="center"><?php echo $timestr; ?></td>
    </tr>
    <tr>
      <td width="148" height="28">结算总数量</td>
      <td width="468" height="28" align="center">
      <?php
      		$flowunit="M";
      		if ($usertype=="流量(G)") {
      			$flowunit="G";
      		}
      		if ($usertype=="天") {
      			echo(strval($alltime)."天");
      		} elseif ($usertype=="小时") {
      			echo(strval($alltime)."小时");
      		} elseif ($usertype=="包月") {
      			echo(strval($alltime)."月");
      		} elseif ($usertype=="分钟") {
      			echo(strval($alltime)."分钟");
      		} elseif ($usertype=="年") {
      			echo(strval($alltime)."年");
      		} elseif ($usertype=="流量(M)") {
      			echo(strval($alllength)."M");
      		} elseif ($usertype=="流量(G)") {
      			echo(strval($alllength)."G");
      		} else {		//免费
      			echo("0");
      		}
      ?>
      </td>
    </tr>
    <tr>
      <td width="148" height="28">上网总流量</td>
      <td width="468" height="28" align="center"><?php echo $alllength; ?><?php echo $flowunit; ?></td>
    </tr>
    <tr>
      <td width="148" height="28">单价</td>
      <td width="468" height="28" align="center"><?php echo $price; ?>元</td>
    </tr>
    <tr>
      <td width="148" height="29">结算总费用</td>
      <td width="468" height="29" align="center"><?php echo $money1; ?>元</td>
    </tr>
    <tr>
      <td width="148" height="29">优惠率</td>
      <td width="468" height="29" align="center"><?php echo $discount; ?>%</td>
    </tr>
    <tr>
      <td width="148" height="28">应收费用</td>
      <td width="468" height="28" align="center"><?php echo $money2; ?>元</td>
    </tr>
    <tr>
      <td width="148" height="28">预付押金</td>
      <td width="468" height="28" align="center"><?php echo $prepay; ?>元</td>
    </tr>
    <tr>
      <td width="148" height="28">实际收取</td>
      <td width="468" height="28" align="center"><?php echo $money3; ?>元</td>
    </tr>
    <tr>
      <td width="148" height="29">备注</td>
      <td width="468" height="29" align="center"><?php echo $comment; ?></td>
    </tr>
  </table>
  </center>
</div>
<p align="center">
<?php
	if ($usertype=="流量(M)" || $usertype=="流量(G)") {
		$alltime=$alllength;
	}
?>
<a href="history_print1.php?userid=<?php echo $userid; ?>&pageno=1&loginname=<?php echo $loginname; ?>&usertype=<?php echo $usertype; ?>&price=<?php echo $price; ?>&alltime=<?php echo $alltime; ?>&money1=<?php echo $money1; ?>&discount=<?php echo $discount; ?>&money2=<?php echo $money2; ?>" target="_blank">上网清单打印</a>
</p>
<hr>
<p align="center">SIP酒店上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>

</body>

</html>
