<?php
	session_start();
	require_once("db/db.php");	
	require_once("common/common.php");
	ini_set('session.gc_maxlifetime', 99999999); //设置时间 永不过期
	//判断是否登录系统		
	if($_SESSION['main_wx_userlogined']!="1" | $_SESSION['main_wx_userno']=="")
	{
		//没有登录开始启动登录
		header('location:..\loginwx.php?rset=0');
		exit;
	}
	
	$datday1=$_REQUEST["datday1"];
	$datday2=$_REQUEST["datday2"];
	
	//echo $datday1."**".$datday2;;
	
	if($datday1=="" | $datday2=="")
	{
		//设置默认日期
		$strtemp=getdate();
		$strtemp1=date("Y-m-d",strtotime("-20 day"));
		//$strtemp1=date('Y-m-d',$strtemp - 1*24*60*60);
		$datday1= $strtemp1;//[year]."-".sprintf("%02d",$strtemp1[mon])."-".sprintf("%02d",$strtemp1[mday]);
		$datday2= $strtemp[year]."-".sprintf("%02d",$strtemp[mon])."-".sprintf("%02d",$strtemp[mday]);
	}
	//echo $datday1."+++".$datday2."**".$strtemp1;
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="gb2312">	
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
	<meta name="apple-mobile-web-app-capable" content="1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=0">
	<meta name="apple-touch-fullscreen" content="1">
	
	<Meta http-equiv="Page-Enter" Content="blendTrans(Duration=0.5)"> 
	<Meta http-equiv="Page-Exit" Content="blendTrans(Duration=0.5)">
	
	<title><?php echo $_SESSION['ChainName']?></title>
	
	<link rel="stylesheet" href="jsp4/jquery.mobile-1.4.3.min.css">
	<script src="jsp4/jquery.js"></script>
	<script src="jsp4/jquery.mobile-1.4.3.min.js"></script>
	
	<link rel="stylesheet" href="css/mycss.css"> 
	<link rel="stylesheet" href="jsp4/jquery.mobile.datepicker.css">
	<script src="jsp4/jquery.ui.datepicker.js"></script>
	<script id="mobile-datepicker" src="jsp4/jquery.mobile.datepicker.js"></script>
	
</head>

<script>	
		//隐藏维信右上角菜单
		function onBridgeReady(){
			WeixinJSBridge.call('hideOptionMenu');
		}

		if (typeof WeixinJSBridge == "undefined")
		{
			if( document.addEventListener )
			{
				document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
			}
			else if (document.attachEvent)
			{
				document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
				document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
			}
		}
		else
		{
			onBridgeReady();
		}
	</script>
	
<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">

<section data-role="page" id="pagepayfor1">		
	
	<header data-role="header" data-position="fixed" data-tap-toggle="false">
		<table width="100%" height="35" border="0" cellpadding="0" cellspacing="0">	   
			<tr>
				<td height="35" width="45" align="right">
					<a href="../indexm.php?rset=0" data-role="button" data-icon="home" data-iconpos="notext" rel="external"></a>
				</td>
				<td height="35" width="6" align="right"></td>
				<td height="35" align="left" colspan="2">
					<table width="100%" height="10" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td width="10" align="left"></td>
							<td width="90" align="left"  class="STYLEM2">
								<span style="color:#000 ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;text-shadow:none;">
								<input type="text" id="dtp1" name="dtp1" readonly= "true" value="<?php echo $datday1;?>" data-role="date">
								</span>
							</td>
							
							<td width="20" align="center" ><span style="color:#000 ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;text-shadow:none;">至</span></td>
							
							<td width="90" align="left"  class="STYLEM2">
								<span style="color:#000 ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;text-shadow:none;">
								<input type="text" id="dtp2" name="dtp2" readonly= "true" value="<?php echo $datday2;?>" data-role="date">
								</span>
							</td>
							<td width="5" align="center"></td>
							<td width="80" align="left"  class="STYLEM2">
								<div id="bmtSendOk" onClick="OnSendFindClick()" style="border-radius:3px; width:70px; height:28px; background-color:#D7AA28;opacity:0.9;">
									<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
										<tr><td width="100%" height="100%" align="center">
											<span style="color:#fff ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;text-shadow:none;">查 询</span>
										</td></tr>
									</table>
								</div>
							</td>
							<td align="left">&nbsp;</td>
						</tr>
					</table>
					
					
				</td>
			</tr>		  
			
		</table>
	</header>
	
	
	<article data-role="none" style="background-color:#fff" >
		<table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFF">
			
			<tr>
				<td height="1" width="6" ></td>
				<td height="1">
					<?php				
						$chainno=$_SESSION["ChainNo"];
						
						$intRowID=0;
						
						$strCustomNo='';
						$strCustomName='';
						$strCustomType='';
						$strCustomState='';
						$fltSumBefor=0;		//起初
						$fltSumValue=0;		//
						$fltSumPayFor=0;
						$fltSumSend=0;
						$strAgreeSaler='';
						$strLinkMan='';
						$strLinkTelNo='';
						
						$fltSumLast=0;	//期末
						$strCustomNoName='';
						
						$fltSumVal1=0;
						$fltSumVal2=0;
						$fltSumVal3=0;
						$fltSumVal4=0;
						$fltSumVal5=0;
						
						//开始去房间状态数量
						$sql=sprintf("SELECT a.CustomNo,a.CustomName,a.CustomType,a.CustomState,a.SumAll,a.SumValue,a.SumPayFor,a.SumSendVal,b.AgreeSaler,a.LinkMan,a.LinkTelNo
									FROM dbo.TR_CustomReceiveTJ('%s','%s 00:00:00','%s 23:59:59') a,TR_Custom_Inform b 
									WHERE a.ListNo=b.ListNo ORDER BY a.CustomNo ASC",$chainno,$datday1,$datday2);
									
						$result = querySql($sql);		
						while($row = fetch_array($result))
						{
							$intRowID = $intRowID + 1;
							//得到每一条的记录信息
							$strCustomNo=$row['CustomNo'];
							$strCustomName=$row['CustomName'];
							$strCustomType=$row['CustomType'];
							$strCustomState=$row['CustomState'];
							$fltSumBefor=$row['SumAll'];		//起初
							$fltSumValue=$row['SumValue'];		//
							$fltSumPayFor=$row['SumPayFor'];
							$fltSumSend=$row['SumSendVal'];
							$strAgreeSaler=trim($row['AgreeSaler']);
							$strLinkMan=trim($row['LinkMan']);
							$strLinkTelNo=trim($row['LinkTelNo']);
						
							//计算期末
							$fltSumLast=$fltSumValue + $fltSumValue - $fltSumPayFor - $fltSumSend;
							
						
							$fltSumVal1 = $fltSumVal1 + $fltSumBefor;
							$fltSumVal2 = $fltSumVal2 + $fltSumValue;
							$fltSumVal3 = $fltSumVal3 + $fltSumPayFor;
							$fltSumVal4 = $fltSumVal4 + $fltSumSend;
							$fltSumVal5 = $fltSumVal5 + $fltSumLast;
							
							if(strlen($strCustomName)>0)
							{
								$strCustomNoName=$strCustomNo.'|'.$strCustomName;
							}
							else
							{
								$strCustomNoName=$strCustomNo;
							}
							
							$strLinkManText="";
							if(strlen($strLinkMan)>0)
							{
								$strLinkManText=$strLinkManText.$strLinkMan;
							}
							
							if(strlen($strLinkTelNo)>0)
							{
								if(strlen($strLinkManText)>0)
								{
									$strLinkManText=$strLinkManText.',&nbsp;'.$strLinkTelNo;	
								}
								else
								{
									$strLinkManText=$strLinkTelNo;	
								}
							}
								
					?>
					
					<div data-role="none" class="STYLEM2">
						<table width="100%" height="30" cellpadding="0" cellspacing="0" style="border-left: 1px solid #F6F2F2;border-right: 1px solid #F6F2F2;">
							<tr bgcolor="#F6F2F2">
								<td height="30" width="6"></td>
								<td height="30"  align="left">
									<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo $strCustomNoName;?></span>
								</td>
								
								<td height="30" width="80" align="right">
									<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo $strCustomType;?></span>
								</td>
								
								<td height="30" width="50" align="right">
									<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo $strCustomState;?></span>
								</td>
								<td height="30" width="6"></td>
							</tr>
							
							<tr>
								<td height="30" width="6"></td>
								<td height="30" align="left">
									<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">联系人：<?php echo $strLinkManText;?></span>
								</td>
								<td height="30" width="130" colspan="2" align="right">
									<?php if(strlen($strAgreeSaler)>0) {?>
									<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">营销员：<?php echo $strAgreeSaler;?></span>
									<?php } ?>
								</td>
								<td height="30" width="6"></td>
							</tr>
							
							<tr bgcolor="#fbf9f9">
								<td height="30" width="6"></td>
								<td height="30" colspan="3" align="left">
									<table width="100%" height="30" border="0" cellpadding="0" cellspacing="0">
										<tr>
											<td height="25" width="20%" align="left">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">期初金额</span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">本期发生</span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">本期回款</span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">本期赠送</span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">期末余额</span>
											</td>
										</tr>
										
										<tr>
											<td height="25" width="20%" align="left">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo number_format($fltSumBefor,2);?></span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo number_format($fltSumValue,2);?></span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo number_format($fltSumPayFor,2);?></span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo number_format($fltSumSend,2);?></span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo number_format($fltSumLast,2);?></span>
											</td>
										</tr>
									</table>
								</td>
								<td height="30" width="6"></td>
							</tr>
							
							
							<tr bgcolor="#F6F2F2"><td height="1" colspan="5" align="center"></tr>
							
						</table>
						
						<table width="100%" height="10" border="0"  cellpadding="0" cellspacing="0">
							<tr><td height="10"></td></tr>
						</table>
					</div>
							
					<?php
						}
						//释放数据库 $fltSumVal1
						freeResult($result);
					?>
					

					<div data-role="none" class="STYLEM2">
						<table width="100%" height="25" cellpadding="0" cellspacing="0" style="border-left: 1px solid #F6F2F2;border-right: 1px solid #F6F2F2;">
							
							<tr bgcolor="#f5efe8">
								<td height="25" width="6"></td>
								<td height="25" align="left">
									<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">∑ 区间合计</span>
								</td>
								<td height="25" width="6"></td>
							</tr>
							
							<tr bgcolor="#f3e9e9"><td height="1" colspan="3" align="center"></tr>
							
							<tr bgcolor="#F6F2F2">
								<td height="25" width="6"></td>
								<td height="25" align="left">
									<table width="100%" height="25" border="0" cellpadding="0" cellspacing="0">
										<tr>
											<td height="25" width="20%" align="left">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">期初金额</span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">本期发生</span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">本期回款</span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">本期赠送</span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;">期末余额</span>
											</td>
										</tr>
									</table>
								</td>
								<td height="25" width="6"></td>
							</tr>
							
							<tr bgcolor="#fff">
								<td height="30" width="6"></td>
								<td height="30" align="left">
									<table width="100%" height="30" border="0" cellpadding="0" cellspacing="0">
										<tr>
											<td height="25" width="20%" align="left">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo number_format($fltSumVal1,2);?></span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo number_format($fltSumVal2,2);?></span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo number_format($fltSumVal3,2);?></span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo number_format($fltSumVal4,2);?></span>
											</td>
											<td height="25" width="20%" align="right">
												<span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;text-shadow:none;"><?php echo number_format($fltSumVal5,2);?></span>
											</td>
										</tr>
									</table>
								</td>
								<td height="30" width="6"></td>
							</tr>
							
							<tr bgcolor="#F6F2F2"><td height="1" colspan="3" align="center"></tr>
							
						</table>
						
						<table width="100%" height="10" border="0"  cellpadding="0" cellspacing="0">
							<tr><td height="10"></td></tr>
						</table>
					
					</div>
					
				</td>
				<td height="1" width="6" ></td>
			</tr>
			
		</table>
		
		
	</article>
	
	
	
	<script type="text/javascript">
		//相应查询按钮的事件
		function OnSendFindClick()
		{
			var strday1 = $("#dtp1").val();
			var strday2 = $("#dtp2").val();
			if(strday1=="")
			{	
				$("#dtp1").focus();
				return;
			}
			if(strday2=="")
			{	
				$("#dtp2").focus();
				return;
			}
			parent.window.location.href='repcustomys.php?datday1=' + strday1 + '&datday2=' + strday2;
		};
		 	
	</script>
		
		
</section>

</body>
</html>
