<?php
	session_start();	
	require_once("db/db.php");	
	require_once("common/common.php");

	require_once("JpGraph/src/jpgraph.php");
	require_once("JpGraph/src/jpgraph_bar.php");
	require_once("JpGraph/src/jpgraph_line.php");

	ini_set('session.gc_maxlifetime', 99999999); //设置时间 永不过期
	
	//$strHotelDay=$_SESSION['HotelDate_ydtpos'];
	//$strnewchainno=$_SESSION['ChainNo_ydtpos'];
	//$strnewdepart=$_SESSION['ChainDepartName_ydtpos'];
	//$strDepartListNo=trim($_SESSION['ChainDepartListNo_ydtpos']);
	
	$strHotelDay=$_REQUEST['HotelDate'];
	$strnewchainno=$_REQUEST['ChainNo'];
	$strnewdepart=$_REQUEST['DepartName'];
	$strDepartListNo=trim($_REQUEST['DepListNo']);
	
	
	if(strlen($strDepartListNo)<1)
	{
		$strDepartListNo='0';
	}
	
	$strDayName1="00-00";
	$fltDayVal1=0;
	$fltDayB1=0;
	
	$strDayName2="00-00";
	$fltDayVal2=0;
	$fltDayB2=0;
	
	$strDayName3="00-00";
	$fltDayVal3=0;
	$fltDayB3=0;
	
	$strDayName4="00-00";
	$fltDayVal4=0;
	$fltDayB4=0;
	
	$strDayName5="00-00";
	$fltDayVal5=0;
	$fltDayB5=0;
	
	$strDayName6="00-00";
	$fltDayVal6=0;
	$fltDayB6=0;
	
	$strDayName7="00-00";
	$fltDayVal7=0;
	$fltDayB7=0;
	
	$intPos=1;
	$strTemp="";
	$fltTemp=1;
	$fltTempB=0;

	$sql=sprintf("SELECT 1 AS MRID,COUNT(Bill_No)AS BCount,SUM(FactValue)AS DayVal,RIGHT(convert(varchar(10),'%s',120),5)+' 'AS DayName FROM TCP_Bill_Inform WHERE BillState=2 And ReckonTime>='%s'
					AND ReckonTime<='%s' + ' 23:59:59' AND Chain_No='%s' AND DListNo=%s
				UNION SELECT 2 AS MRID,COUNT(Bill_No)AS BCount,SUM(FactValue)AS DayVal,RIGHT(convert(varchar(10),DATEADD(DAY,-1,'%s'),120),5)+' 'AS DayName FROM TCP_Bill_Inform WHERE BillState=2 And ReckonTime>=DATEADD(DAY,-1,'%s')
					AND ReckonTime<=DATEADD(DAY,-1,('%s' + ' 23:59:59')) AND Chain_No='%s' AND DListNo=%s
				UNION SELECT 3 AS MRID,COUNT(Bill_No)AS BCount,SUM(FactValue)AS DayVal,RIGHT(convert(varchar(10),DATEADD(DAY,-2,'%s'),120),5)+' 'AS DayName FROM TCP_Bill_Inform WHERE BillState=2 And ReckonTime>=DATEADD(DAY,-2,'%s')
					AND ReckonTime<=DATEADD(DAY,-2,('%s' + ' 23:59:59')) AND Chain_No='%s' AND DListNo=%s
				UNION SELECT 4 AS MRID,COUNT(Bill_No)AS BCount,SUM(FactValue)AS DayVal,RIGHT(convert(varchar(10),DATEADD(DAY,-3,'%s'),120),5)+' 'AS DayName FROM TCP_Bill_Inform WHERE BillState=2 And ReckonTime>=DATEADD(DAY,-3,'%s')
					AND ReckonTime<=DATEADD(DAY,-3,('%s' + ' 23:59:59')) AND Chain_No='%s' AND DListNo=%s
				UNION SELECT 5 AS MRID,COUNT(Bill_No)AS BCount,SUM(FactValue)AS DayVal,RIGHT(convert(varchar(10),DATEADD(DAY,-4,'%s'),120),5)+' 'AS DayName FROM TCP_Bill_Inform WHERE BillState=2 And ReckonTime>=DATEADD(DAY,-4,'%s')
					AND ReckonTime<=DATEADD(DAY,-4,('%s' + ' 23:59:59')) AND Chain_No='%s' AND DListNo=%s
				UNION SELECT 6 AS MRID,COUNT(Bill_No)AS BCount,SUM(FactValue)AS DayVal,RIGHT(convert(varchar(10),DATEADD(DAY,-5,'%s'),120),5)+' 'AS DayName FROM TCP_Bill_Inform WHERE BillState=2 And ReckonTime>=DATEADD(DAY,-5,'%s')
					AND ReckonTime<=DATEADD(DAY,-5,('%s' + ' 23:59:59')) AND Chain_No='%s' AND DListNo=%s
				UNION SELECT 7 AS MRID,COUNT(Bill_No)AS BCount,SUM(FactValue)AS DayVal,RIGHT(convert(varchar(10),DATEADD(DAY,-6,'%s'),120),5)+' 'AS DayName FROM TCP_Bill_Inform WHERE BillState=2 And ReckonTime>=DATEADD(DAY,-6,'%s')
					AND ReckonTime<=DATEADD(DAY,-6,('%s' + ' 23:59:59')) AND Chain_No='%s' AND DListNo=%s ORDER BY MRID ASC",$strHotelDay,$strHotelDay,$strHotelDay,$strnewchainno,$strDepartListNo,
					$strHotelDay,$strHotelDay,$strHotelDay,$strnewchainno,$strDepartListNo,$strHotelDay,$strHotelDay,$strHotelDay,$strnewchainno,$strDepartListNo,$strHotelDay,$strHotelDay,$strHotelDay,$strnewchainno,$strDepartListNo,
					$strHotelDay,$strHotelDay,$strHotelDay,$strnewchainno,$strDepartListNo,$strHotelDay,$strHotelDay,$strHotelDay,$strnewchainno,$strDepartListNo,$strHotelDay,$strHotelDay,$strHotelDay,$strnewchainno,$strDepartListNo);
						
	$result = querySql($sql);		
	while($row = fetch_array($result))
	{
		$strTemp=$row['DayName'];
		$fltTemp=$row['DayVal'];
		$intPos=$row['MRID'];
		$fltTempB=$row['BCount']*10;
		switch($intPos)
		{
			case 1:
				$strDayName1=$strTemp;
				$fltDayVal1=$fltTemp;
				$fltDayB1=$fltTempB;
				break;
			case 2:
				$strDayName2=$strTemp;
				$fltDayVal2=$fltTemp;
				$fltDayB2=$fltTempB;
				break;
			case 3:
				$strDayName3=$strTemp;
				$fltDayVal3=$fltTemp;
				$fltDayB3=$fltTempB;
				break;
			case 4:
				$strDayName4=$strTemp;
				$fltDayVal4=$fltTemp;
				$fltDayB4=$fltTempB;
				break;
			case 5:
				$strDayName5=$strTemp;
				$fltDayVal5=$fltTemp;
				$fltDayB5=$fltTempB;
				break;
			case 6:
				$strDayName6=$strTemp;
				$fltDayVal6=$fltTemp;
				$fltDayB6=$fltTempB;
				break;
			case 7:
				$strDayName7=$strTemp;
				$fltDayVal7=$fltTemp;
				$fltDayB7=$fltTempB;
				break;
			}	
		}
		//释放数据库
		freeResult($result);
		closeDb();	
		
		$strChrTitle=sprintf("最近七日实收金额,折线为单据数（放大10倍）");
		
		//header("content-type:image/jpeg");
		$datay=array($fltDayVal7,$fltDayVal6,$fltDayVal5,$fltDayVal4,$fltDayVal3,$fltDayVal2,$fltDayVal1);	//定义数组
		$datay2=array($fltDayB7,$fltDayB6,$fltDayB5,$fltDayB4,$fltDayB3,$fltDayB2,$fltDayB1);	//定义数组
		$graph=new Graph(330,250,"auto");			//创建画布
		$graph->SetScale('textlin');
		$graph->yaxis->scale->SetGrace(20);
		$graph->SetShadow();						//创建画布阴影
		//设置统计图所在画布的位置，左边距40，右边距30，上边距30，下边距40 单位像素
		$graph->img->SetMargin(30,20,30,30);
		$bplot=new BarPlot($datay);					//创建一个矩形的对象
		$bplot2=new LinePlot($datay2);					//创建一个矩形的对象
		$graph->Add($bplot);						//将柱形图添加到图像中
		$graph->Add($bplot2);						//将柱形图添加到图像中
		//$bplot->SetFillColor('orange');				//设置柱形的颜色
		$bplot->value->SetFormat('%d');				//在柱形图中显示格式化的出租率
		$bplot->value->Show();						//设置显示数字
		//$graph->SetMarginColor('lightblue');		//设置画布背景色为淡蓝色
		$graph->title->Set($strChrTitle);//创建标题
		
		//设置X坐标轴文字
		$a=array($strDayName7,$strDayName6,$strDayName5,$strDayName4,$strDayName3,$strDayName2,$strDayName1);
		$graph->xaxis->SetTickLabels($a);			//设置X轴
		$graph->title->SetFont(FF_SIMSUN);			//设置标题的字体
		$graph->xaxis->SetFont(FF_SIMSUN);			//设置X轴的字体
		$graph->Stroke();							//输出图像
		
?>