<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("cancheckmoney")="" Then
	ef=True
	ec="您没有此操作的权限。"
ElseIf not IsNumeric(Request("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
end if

If RegExpTest("[^A-Za-z0-9]",Request("username")) Then 
	ef=True
	ec="ftp名中有非法字符！"
End if

if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set dsfapiao = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Fapiao order by apptime desc"
if Request("id")<>"" then 	Sql="Select * from FreeHost.FreeHost_Fapiao where id ='"&Request("id")&"' order by apptime desc"
if Request("username")<>"" then Sql="Select * from FreeHost.FreeHost_Fapiao where username='"&Request("username")&"'  order by apptime desc"
	dsfapiao.PageSize = 25
        dsfapiao.Open Sql,conn,1,1
if Request.ServerVariables("QUERY_STRING")<>"" then
ask=Split(Request.ServerVariables("QUERY_STRING"), chr(38)&"pn")
else
ask=Split("freehost=1", "")
ask(0)="freehost=lsoft"
end if
	pn=1
if Request.QueryString ("pn")<>"" then pn=Request.QueryString ("pn")
If dsfapiao.RecordCount <> 0 Then dsfapiao.AbsolutePage = CLng(pn)  
    if clng(pn)<=10 then
    begini=1
      if dsfapiao.PageCount<=10 then
       endini=dsfapiao.PageCount 
       else
       endini=10
      end if
    end if

if Request("id")<>""or Request("username")<>"" then
		Set dsuser = Server.CreateObject("ADODB.Recordset")	
Sql="Select sum(usermoney) from FreeHost.FreeHost_Fapiao where username='"&dsfapiao("username")&"'"
dsuser.Open Sql,conn,1,1
usermoneyALL=dsuser(0)
dsuser.close

		Set dsuser = Server.CreateObject("ADODB.Recordset")	
Sql="Select sum(usermoney) from FreeHost.FreeHost_Fapiao where username='"&dsfapiao ("username")&"' and apptime>'"&year(now)&"-1-1'"
dsuser.Open Sql,conn,1,1
usermoneyALLthisyear=dsuser(0)
dsuser.close
If isnull(usermoneyALLthisyear) Then usermoneyALLthisyear=0
end if

%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html8")%>
<%=htmlwrite("html9")%>

<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0 background="img/midtop4.gif">
  <TBODY>
    <TR>
      <TD width=53 align="left" background="img/midtop1.gif"><strong> 　 </strong><font color="#FFFFFF">─<strong>&gt;</strong></font> </TD>
      <TD align="left"><table height="59"  border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="7" background="img/midtop.gif">&nbsp;</td>
          <td width="90" align="center" valign="middle" background="img/r3.jpg" id="tableTop1" style="Cursor:hand"><a href="fapiao.asp"><font color="#FFFFFF"><strong>发票管理</strong></font></a></td>
          <td width="5" background="img/midtop2.gif">&nbsp;</td>
        </tr>
      </table></TD>
      <TD width="83">&nbsp;</TD>
      <TD width="83" align="left">&nbsp;</TD>
      <TD align="left">&nbsp;</TD>
      <TD width=23 align="right"><IMG height=59 
                  src="img/rtop4.jpg" 
                  width=19></TD>
    </TR>
  </TBODY>
</TABLE>


<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0>
  <TBODY>
    <TR>
      <TD width=19 background="img/midlef.gif" id=rightid>&nbsp;</TD>
      <TD height="300" align="center" vAlign=top bgcolor="#FFFFFF"><div id="truecon">
        <%if Request("id")<>"" then%>
        <form name="form1" method="post" action="fapiao2.asp">
          <table width="98%"  border="0" cellspacing="1" bgcolor="#CCCCCC">
            <tr bgcolor="#EFEFEF">
              <td height="37" colspan="2" align="center"> 修改(编号：<%=dsfapiao("id")%>)发票信息：    
            </tr>
            <tr bgcolor="#FFFFFF">
              <td width="21%" height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">用户名：</font>
              <td align="left" bgcolor="#FFFFFF">　
<a href="searchuser.asp?username=<%=dsfapiao("username")%>"><%=dsfapiao("username")%></a>
              <%if dsfapiao("agent1")<>"n" then%>
(<a href="searchagent.asp?username=<%=dsfapiao("agent1")%>" target="_blank"><font color="#FF0000"><%=dsfapiao("agent1")%></font></a>)
<%end if%>
</td>
</tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">已开票总金额：</font>
              <td align="left" bgcolor="#FFFFFF">　 <font color="#ff6600"><%=usermoneyALL%> 元</font>            
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">总入款金额：</font>
              <td align="left" bgcolor="#FFFFFF">　
                  <%
	Set dsmoney = Server.CreateObject("ADODB.Recordset")	
	Sql="Select sum(abs(usermoney)) from FreeHost.FreeHost_moneylog where username='"&dsfapiao ("username")&"' and isnew='y' and isdel is null and isadd='y' and (bank='在线支付' or bank='中行' or bank='工行' or bank='建行' or bank='农行' or bank='招行' or bank='交行' or bank='邮政' or bank='现金' or bank='公司帐号' or bank='其他' or bank='实收')"
	dsmoney.Open Sql,conn,1,1
totalm=fix(dsmoney(0))
If isnull(totalm) Then totalm=0
response.Write fix(totalm)
%>
    元
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">本年度已开票金额：</font>
              <td align="left" bgcolor="#FFFFFF">　 <font color="#ff6600"><%=usermoneyALLthisyear%> 元</font> (发票只能按开本年度入款开，请您及时申请发票。 )   
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">本年度</font><font color="#666666">入款金额：</font>
              <td align="left" bgcolor="#FFFFFF">　
                  <%
	Set dsmoney = Server.CreateObject("ADODB.Recordset")	
	Sql="Select sum(abs(usermoney)) from FreeHost.FreeHost_moneylog where username='"&dsfapiao ("username")&"' and isnew='y' and isdel is null and isadd='y' and attime>'"&year(now)&"-1-1' and (bank='在线支付' or bank='中行' or bank='工行' or bank='建行' or bank='农行' or bank='招行' or bank='交行' or bank='邮政' or bank='现金' or bank='公司帐号' or bank='其他' or bank='实收')"
	dsmoney.Open Sql,conn,1,1
totalmthisyear=fix(dsmoney(0))	
If isnull(totalmthisyear) Then totalmthisyear=0
response.Write fix(totalmthisyear)
%>
    元            
            </tr>

            <tr bgcolor="#FFFFFF">
              <td width="21%" height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">状态：</font>
              <td align="left" bgcolor="#FFFFFF">　
                <select name="status" id="status">
  <option value="等候处理" <%if dsfapiao("status")="等候处理" then%>selected<%end if%>>等候处理</option>
  <option value="已开出尚未寄出"  <%if dsfapiao("status")="已开出尚未寄出" then%>selected<%end if%>>已开出尚未寄出</option>
  <option value="已寄出" <%if dsfapiao("status")="已寄出" then%>selected<%end if%>>已寄出</option>
</select>

</td>
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">申请金额： </font>
              <td height="25" align="left" bgcolor="#FFFFFF"><font color="#666666">　<strong>
                <input name="usermoney" type="text" id="usermoney" size="5" maxlength="6" <%if Request("id")<>"" And Not dsfapiao.Eof then%>value="<%=dsfapiao("usermoney")%>" readonly<%End if%>>
              </strong>元（可开发票金额为：<%=totalmthisyear-usermoneyALLthisyear%> 元）(最小开票金额为：<%=Application("MinFapiaomoney")%> 元) (将从用户的帐上扣除<%=Application("FapiaoPaypercent")%>%) </font>         
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">发票抬头： </font>
              <td width="79%" height="25" align="left" bgcolor="#FFFFFF"><font color="#666666">　
                    <input name="title" type="text" id="title" size="40" maxlength="100" <%if Request("id")<>"" And Not dsfapiao.Eof then%>value="<%=dsfapiao("title")%>"<%End if%>>
              </font>         
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">纳税人识别号： </font>
              <td height="25" align="left" bgcolor="#FFFFFF"><font color="#666666">　
                    <input name="titleID" type="text" id="titleID" size="15" maxlength="15" <%if Request("id")<>"" And Not dsfapiao.Eof then%>value="<%=dsfapiao("titleID")%>"<%End if%>>
    (没有可以不填写) </font>             
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">收件人： </font>
              <td height="25" align="left" bgcolor="#FFFFFF"><font color="#666666">　
                    <input name="recman" type="text" id="recman" <%if Request("id")<>"" And Not dsfapiao.Eof then%>value="<%=dsfapiao("recman")%>"<%End if%>>
              </font>         
            </tr>
    <tr bgcolor="#FFFFFF">
      <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">收件人联系电话： </font>
      <td height="25" align="left" bgcolor="#FFFFFF"><font color="#666666">　
            <input name="mobi" type="text" id="mobi" <%if Request("id")<>"" And Not dsfapiao.Eof then%>value="<%=dsfapiao("mobi")%>"<%End if%>>
      </font>     
    </tr>
    <tr bgcolor="#FFFFFF">
      <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">邮寄方式： </font>
      <td height="25" align="left" bgcolor="#FFFFFF">　
 <select name="sendtype" id="sendtype" <%if Request("id")<>"" And Not dsfapiao.Eof Then%><%End if%>>
  <option value="平邮" <%if Request("id")<>"" And Not dsfapiao.Eof Then
If dsfapiao("sendtype")="平邮" Then%>selected<% End if%><% End if%>>平邮</option>
  <option value="快递" <%if Request("id")<>"" And Not dsfapiao.Eof Then
If dsfapiao("sendtype")="快递" Then%>selected<% End if%><% End if%>>EMS快递</option>
</select>
(更改邮寄方式后要在财务管理中单独扣费) 
    </tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">邮编： </font>
              <td width="79%" height="25" align="left" bgcolor="#FFFFFF"><font color="#666666">　
                    <input name="postid" type="text" id="postid" size="6" maxlength="6" <%if Request("id")<>"" And Not dsfapiao.Eof then%>value="<%=dsfapiao("postid")%>"<%End if%>>
              </font>         
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">收件人地址：</font>
              <td width="79%" height="25" align="left" bgcolor="#FFFFFF">　<font color="#666666">
                <input name="address" type="text" id="address" size="40" maxlength="100" <%if Request("id")<>"" And Not dsfapiao.Eof then%>value="<%=dsfapiao("address")%>"<%End if%>>
              </font>         
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="90" align="center" bgcolor="#F7F7F7"><font color="#666666">发票内容：</font>
              <td height="90" align="left" bgcolor="#FFFFFF"><font color="#666666"> 　
                    <textarea name="con" cols="40" rows="3" id="con"><%if Request("id")<>"" And Not dsfapiao.Eof then%><%=dsfapiao("con")%><%End if%>
            </textarea>
              </font>         
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="90" align="center" bgcolor="#F7F7F7"><font color="#666666">备注：</font>
              <td height="90" align="left" bgcolor="#FFFFFF"><font color="#666666"> 　
                    <textarea name="usercodeinfo" cols="40" rows="3" id="usercodeinfo"><%if Request("id")<>"" And Not dsfapiao.Eof then%><%=dsfapiao("usercodeinfo")%><%End if%></textarea>
              </font>         
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">寄出时间： </font>
              <td height="25" align="left" bgcolor="#FFFFFF"><font color="#666666">　
                    <input name="sendtime" type="text" id="sendtime" <%if Request("id")<>"" And Not dsfapiao.Eof then%>value="<%=dsfapiao("sendtime")%>"<%End if%>>
格式2008-8-8              </font>             
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="25" align="center" bgcolor="#F7F7F7"><font color="#666666">内部信息： </font>
              <td height="25" align="left" bgcolor="#FFFFFF"><font color="#666666">　
                    <textarea name="admcodeinfo" cols="40" rows="3" id="admcodeinfo"><%if Request("id")<>"" And Not dsfapiao.Eof then%><%=dsfapiao("admcodeinfo")%><%End if%></textarea>
              </font>             
            </tr>
            <tr bgcolor="#FFFFFF">
              <td height="40" colspan="2" align="center" bgcolor="#F7F7F7"><input type="submit" name="Submit" value="提交">
　　　　　　　
<input type="submit" name="Submit" value="删除">
              </tr>
          </table>
          <input name="id" type="hidden" <%if Request("id")<>"" And Not dsfapiao.Eof then%>value="<%=dsfapiao("id")%>"<%End if%>>
        </form>
        <%End if%>
<form action="fapiao.asp" method="get" name="form1">
  <table width="100%" height="20"  border="0" cellpadding="0" cellspacing="0">
    <tr bgcolor="">
      <td>查找发票：</td>
    </tr>
  </table>
  <table width="100%"  border="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
      <td width="9%" height="30" rowspan="2" bgcolor="#FFFFFF"><p>　用户名：
              <input name="username" type="text" size="10">
          <input type="submit" name="Submit" value="查找">
      </p></td>
    </tr>
  </table>
</form>		
<%if Not dsfapiao.Eof then%>
        <table width="98%"  border="0" cellspacing="1" bgcolor="#CCCCCC">
          <tr bgcolor="#EEEEEE">
            <td width="8%" align="center">编号</td>
            <td width="7%" align="center">用户名</td>
            <td width="8%" align="center">发票抬头</td>
            <td width="12%" align="center">金额</td>
            <td width="17%" align="center">发票内容</td>
            <td width="17%" align="center">申请时间</td>
            <td width="17%" align="center">寄出时间</td>
            <td align="center">状态</td>
            <td align="center">操作</td>
          </tr>
<br>


<%if clng(pn)<=10 then%>最新 <%for i=begini to endini
    if clng(pn)=i then%><font color=red>[<%=i%>]</font><%else%><a href="?<%=ask(0)%>&pn=<%=i%>"><font color="#000000">[<%=i%>]</font></a><%end if%>　<%next%> 
        <%else%>　<a href="?<%=ask(0)%>&pn=1"><font color="#000000">最新[1]--[10]</font></a>　　现在是第<font color=red>[<%=pn%>]</font>页 
        　共<%=dsfapiao.PageCount%>页　<%end if%><%If Clng(pn)>1 Then%><a href="?<%=ask(0)%>&pn=<%=pn-1%>">上一页</a><%End If%>|<%If Clng(pn)<dsfapiao.PageCount Then%><a href="?<%=ask(0)%>&pn=<%=pn+1%>">下一页</a><%End If%>


		  
          <%
For N=1 To dsfapiao.PageSize 
					If dsfapiao.RecordCount=0 Then Exit For
%>
          <tr bgcolor="#FFFFFF"  onmouseover=this.bgColor='#E4EAF2'; onmouseout=this.bgColor='#FFFFFF';>
            <td width="8%" height="30" align="center"><%=dsfapiao("id")%></td>
            <td width="7%" align="center"><a href="searchuser.asp?username=<%=dsfapiao("username")%>"><%=dsfapiao("username")%></a><br>
              <%if dsfapiao("agent1")<>"n" then%>
(<a href="searchagent.asp?username=<%=dsfapiao("agent1")%>" target="_blank"><font color="#FF0000"><%=dsfapiao("agent1")%></font></a>)
<%end if%>
</td>
            <td width="8%" align="center"><%=dsfapiao("title")%></td>
            <td width="12%" align="center"><%=dsfapiao("usermoney")%></td>
            <td width="17%" align="center"><%=dsfapiao("con")%></td>
            <td width="17%" align="center"><%=formatdatetime(dsfapiao("apptime"),1)%></td>
            <td width="17%" align="center"><%If Not IsNull(dsfapiao("sendtime")) then%>
                <%=formatdatetime(dsfapiao("sendtime"),1)%>
                <%End if%></td>
            <td align="center"><font color="#000000"><%=dsfapiao("status")%></font></td>
            <td align="center"><a href="fapiao.asp?id=<%=dsfapiao("id")%>"><font color="#000000">
      修改
            </font></a> </td>
          </tr>

<%
If clng(pn)=dsfapiao.PageCount Then
I = dsfapiao.RecordCount - (dsfapiao.PageCount-1) * dsfapiao.PageSize
If N=I Then Exit For
End If
dsfapiao.movenext
Next%>

        </table>

<font color="#666666">已开票总金额：<%=usermoneyALL%>元</font>         

        <%else%>
数据库中没有此项记录。
<%End if%>
</div>

      </TD>
      <TD width=18 background="img/midri.gif">&nbsp;</TD>
    </TR>
  </TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
    <TR>
      <TD width=30><IMG height=19 
                  src="img/rb1.jpg" 
                  width=30></TD>
      <TD 
                background=img/rb2.jpg>&nbsp;</TD>
      <TD width=30><IMG height=19 
                  src="img/rb3.jpg" 
                  width=30></TD>
    </TR>
  </TBODY>
</TABLE>


<%=htmlwrite("html10")%>
<%
end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
