<%@ Language=VBScript %>
<%'response.end
If session("username")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf not IsNumeric(Request("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
end if
if not ef Then
 Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")

		Set dsuser = Server.CreateObject("ADODB.Recordset")	
Sql="Select sum(usermoney) from FreeHost.FreeHost_Fapiao where username='"&session ("username")&"'"
dsuser.Open Sql,conn,1,1
usermoneyALL=dsuser(0)
dsuser.close
If isnull(usermoneyALL) Then usermoneyALL=0

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

	Set dsfapiao = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Fapiao where username='"&session ("username")&"' order by apptime desc"
if Request("id")<>"" then 	Sql="Select * from FreeHost.FreeHost_Fapiao where username='"&session ("username")&"' and id ='"&Request("id")&"' order by apptime desc"
	dsfapiao.Open Sql,conn,1,1

%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html2")%>发票申请
<%=htmlwrite("html3")%><br>
<form name="form1" method="post" action="fapiao2.asp">
  <table width="100%"  border="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr bgcolor="#EFEFEF">
      <td height="37" colspan="2" align="center"> 发票申请：    
    </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='"&session ("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 width="21%" 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='"&session ("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 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 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 width="79%" 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%>disabled<%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>
(EMS快递将加收<%=Application("Fapiaokuai")%>元) 
    </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="40" colspan="2" align="center" bgcolor="#F7F7F7"><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>
 <%
if Not dsfapiao.Eof then%>
<table width="100%"  border="0" cellspacing="1" bgcolor="#CCCCCC">
          <tr bgcolor="#EEEEEE">
            <td width="8%" align="center">编号</td>
            <td width="15%" 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 width="8%" align="center">状态</td>
            <td align="center">操作</td>
          </tr>
<%
While Not dsfapiao.Eof
%>
          <tr bgcolor="#FFFFFF">
            <td width="8%" align="center"><%=dsfapiao("id")%></td>
            <td width="15%" 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 width="8%" align="center">
              <font color="#000000"><%=dsfapiao("status")%></font></td>
            <td align="center">
<a href="fapiao.asp?id=<%=dsfapiao("id")%>"><font color="#000000">
<%if dsfapiao("status")="已寄出" or dsfapiao("status")="已开出尚未寄出" then%>
查看
<%else%>
修改
<%end if%>
</font></a>
			</td>
          </tr>

        <%
dsfapiao.movenext
wend%>
</table>
<%else%>
您尚未申请过任何发票服务。
<%End if%>
<br>
<br>

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