<%@ page contentType="text/html; charset=gbk" language="java" %>
<%@ page import="mediastore.web.global.*"%>
<%@ page import="mediastore.web.form.*"%>
<%@ page import="mediastore.rule.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>


<script language="JavaScript">

function Calendar_importtime1()
{
var newWindow;
var urlstring = './html/Calendar_importtime1.htm'
newWindow = window.open(urlstring,'','height=200,width=280,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=no')

}
function Calendar_importtime2()
{
var newWindow;
var urlstring = './html/Calendar_importtime2.htm'
newWindow = window.open(urlstring,'','height=200,width=280,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=no')

}
function Calendar_paymenttime1()
{
var newWindow;
var urlstring = './html/Calendar_paymenttime1.htm'
newWindow = window.open(urlstring,'','height=200,width=280,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=no')

}
function Calendar_paymenttime2()
{
var newWindow;
var urlstring = './html/Calendar_paymenttime2.htm'
newWindow = window.open(urlstring,'','height=200,width=280,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=no')

}

function isLeapYear(year) 
{ 
	if((Number(year)%4==0&&Number(year)%100!=0)||(Number(year)%400==0)) 
	{ 
		return true; 
	}  
	return false; 
}

function Trim(str){
 if(str.charAt(0) == " "){
  str = str.slice(1);
  str = Trim(str); 
 }
 return str;
}

//校验，看输入对象的值是否为有效日期yyyy-mm-dd hh:mm:ss
function isDateChen(checktext){

	var datetime;
	var year,month,day,hour,mini,senc;
	var gone,gtwo,gthree,gfour,gfive;
	if(Trim(checktext.value)!=""){
		datetime = Trim(checktext.value);
		if(datetime.length==19){
			year=datetime.substring(0,4);
			if(isNaN(year)==true){
				alert("时间格式不正确\n形如：yyyy-mm-dd hh:mm:ss\n例：2001-02-23 02:56:12");
				checktext.focus();
				return false;
			}
			gone=datetime.substring(4,5);
			month=datetime.substring(5,7);
			if(isNaN(month)==true){
				alert("时间格式不正确\n形如：yyyy-mm-dd hh:mm:ss\n例：2001-02-23 02:56:12");
				checktext.focus();
				return false;
			}
			gtwo=datetime.substring(7,8);
			day=datetime.substring(8,10);
			if(isNaN(day)==true){
				alert("时间格式不正确\n形如：yyyy-mm-dd hh:mm:ss\n例：2001-02-23 02:56:12");
				checktext.focus();
				return false;
			}
			gthree=datetime.substring(10,11);
			firstm = datetime.indexOf(":");//第一个冒号的位置
			//alert("firstm:"+firstm);
			hour=datetime.substring(11,firstm);
			if(isNaN(hour)==true){
				alert("时间格式不正确\n形如：yyyy-mm-dd hh:mm:ss\n例：2001-02-23 02:56:12");
				checktext.focus();
				return false;
			}
			gfour=datetime.substring(firstm,firstm+1);
			
			//alert(datetime.length);
			tempstr = datetime.substring(firstm+1,datetime.length);
			secondm = tempstr.indexOf(":");//第二个冒号的位置
			mini=tempstr.substring(0,secondm);
			if(isNaN(mini)==true){
				alert("时间格式不正确\n形如：yyyy-mm-dd hh:mm:ss\n例：2001-02-23 02:56:12");
				checktext.focus();
				return false;
			}
			gfive=tempstr.substring(secondm,secondm+1);
			senc=tempstr.substring(secondm+1,tempstr.length);
			if(isNaN(senc)==true){
				alert("时间格式不正确\n形如：yyyy-mm-dd hh:mm:ss\n例：2001-02-23 02:56:12");
				checktext.focus();
				return false;
			}
			
			//alert(year+gone+month+gtwo+day+gthree+hour+gfour+mini+gfive+senc)
			
			if((gone=="-")&&(gtwo=="-")){
				if( Number(month)<1 || Number(month)>12 ) { 
					alert("月份必须在01和12之间!"); 
					checktext.focus();
					return false; 
				} 
				if(Number(day)<1 || Number(day)>31){ 
					alert("日期必须在01和31之间!");
					checktext.focus(); 
					return false; 
				}else{
					if(Number(month)==2){  
					
						if(isLeapYear(year)&& Number(day)>29){ 
							alert("2月份日期必须在01到29之间"); 
							checktext.focus();
							return false; 
						}       
						if(!isLeapYear(year)&& Number(day)>28){ 
							alert("2月份日期必须在01到28之间");
							checktext.focus(); 
							return false; 
						} 
					} 
					if((Number(month)==4||Number(month)==6||Number(month)==9||Number(month)==11)&&(Number(day)>30)){ 
						alert("在4、6、9和11月份\n日期必须在01到30之间");
						checktext.focus(); 
						return false; 
					} 
				}
			}else{
				alert("时间格式不正确\n形如：yyyy-mm-dd hh:mm:ss\n例：2001-02-23 02:56:12");
				checktext.focus();
				return false;
			}
		}else{
			alert("时间格式不正确\n形如：yyyy-mm-dd hh:mm:ss\n例：2001-02-23 02:56:12");
			checktext.focus();
			return false;
		}
	}else{
		return true;
	}
	return true;
}

function mySubmit1(){

	if(!isDateChen(document.form1.importtime1))
	{//检查输入的时间是否合法
	}
	else if(!isDateChen(document.form1.importtime2))
	{//检查输入的时间是否合法
	}
	else if(!isDateChen(document.form1.paymenttime1))
	{//检查输入的时间是否合法
	}
	else if(!isDateChen(document.form1.paymenttime2))
	{//检查输入的时间是否合法
	}
	else
	{
		document.form1.start_rec_num.value = '1';
		document.form1.action="importBillSearch.do";
		document.form1.submit();
	}
}

function gotoPage(){
	
	//该值为要条转到的页面的起始记录号
	//alert(document.all.gotopagenum.value);

	document.form2.start_rec_num.value = document.all.gotopagenum.value;
	document.form2.action="importBillSearch.do";
	document.form2.submit();
	
}


function gotoPageByN(n){
	
	document.form2.start_rec_num.value = n;
	document.form2.action="importBillSearch.do";
	document.form2.submit();
	
}

function deleteAImportBill(currec, billid)
{
	if(confirm("该操作只删除单据，不影响库存信息\r\n确定要删除该进货单及其进货明细吗？")) 
	{
		document.form2.start_rec_num.value = currec;
		document.form2.action = "importBillDelete.do?deletebillid="+billid+"";
		document.form2.submit();
	}
}

function exportGoodsForBill(currec, billid)
{
	if(confirm("该操作将删除单据，并调整库存信息\r\n确定要取消该进货单吗？")) 
	{
		document.form2.start_rec_num.value = currec;
		document.form2.action = "importBillCancel.do?cancelbillid="+billid+"";
		document.form2.submit();
	}
}


function updatePaymentTime(currec, billid)
{
	if(confirm("确定已对该进货单付款了吗？")) 
	{
		document.form2.start_rec_num.value = currec;
		document.form2.action = "importBillUpdatePayment.do?updatebillid="+billid+"";
		document.form2.submit();
	}
}
</script>




<table width="768" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="5" rowspan="4" class="trtable"></td>
    <td width="6" bgcolor="#214984" height="1"></td>
    <td rowspan="4" bgcolor="#214984" width="1" height="1"></td>
    <td bgcolor="#214984" class="10p" colspan="2" height="1"></td>
    <td rowspan="4" width="1" bgcolor="#214984" height="1"></td>
    <td bgcolor="#214984" width="5" height="1"></td>
    <td width="5" rowspan="4" class="trtable"></td>
  </tr>
  <tr> 
    <td width="6"></td>
    <td width="379" height="20" class="mainhead">进货单查询</td>
    <td class="mainhead" width="379" height="20">&nbsp;</td>
    <td width="5"></td>
  </tr>
<tr> 
    <td width="6"></td>
    <td valign="top" colspan="2"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        
        <tr> 
          <td height="300" align="center" valign="top">   
          
<%
	System.out.println("----"+request.getServletPath() );
	
	//------
	ImportBillSearchConFB ibscfb = (ImportBillSearchConFB)request.getAttribute(Globals.REQUEST_IMPORTBILLSEARCHCON);
	List billIdList = ibscfb.getBillIdList();
	List sendPersonsList = ibscfb.getSendPersonsList();
	List inceptPersonsList = ibscfb.getInceptPersonsList();
	
	int curStartRecNum = ibscfb.getStartRecNum();		//当前起始记录号
	int curPageRecNum = ibscfb.getPageRecNum();		//页记录数
	ImportBillSearchResultInfo ibsri = ibscfb.getIbsri();	//检索结果可能为空
	ImportBillSearchRule ibsr = ibscfb.getIbsr();		//检索式可能为空
	//-------
	
	//组织与页、记录相关的信息
	List importBillList = new ArrayList();
	int totalBillNum = 0;
	if(ibsri != null)
	{
		totalBillNum = ibsri.getTotalRecNum();		//总记录数
		importBillList = ibsri.getImportBillList();
	}
	int curPageIndex = curStartRecNum/curPageRecNum+1;	//当前页号
	int totalPageNum = 0;					//总页数
	if(totalBillNum%curPageRecNum==0)
	{
		totalPageNum = totalBillNum/curPageRecNum;
	}else{
		totalPageNum = totalBillNum/curPageRecNum+1;
	}
	int lastPageFirstRecNum = 0;				//最后一页的首记录号
	if(totalBillNum%curPageRecNum==0)
	{
		lastPageFirstRecNum = (totalBillNum/curPageRecNum-1)*(curPageRecNum)+1;
	}else{
		lastPageFirstRecNum = (totalBillNum/curPageRecNum)*(curPageRecNum)+1;
	}
	
	//获得上次检索式的值，由于检索式可能为空，所以设置一个缺省值
	String lastOrderStr = "BillID";
	String lastBillId = "0";
	String lastSendPersons = "0";
	String lastInceptPersons = "0";
	String lastImportTime1 = null;
	String lastImportTime2 = null;
	String lastPaymentTime1 = null;
	String lastPaymentTime2 = null;
	if(ibsr!=null)
	{
		lastOrderStr = ibsr.getOrderStr();
		lastBillId = ibsr.getBillId()+"";
		lastSendPersons = ibsr.getSendPersons();
		lastInceptPersons = ibsr.getInceptPersons();
		lastImportTime1 = ibsr.getImportTime1();
		lastImportTime2 = ibsr.getImportTime2();
		lastPaymentTime1 = ibsr.getPaymentTime1();
		lastPaymentTime2 = ibsr.getPaymentTime2();
	}
	
	String tmpStr;
%>

    	<form name="form1" method="post" action="" >
    	<font color=#215385><b>查询条件</b></font>
    	<IMG src="images/line1.gif" border=0>
    	<br>
    	<input type="hidden" name="start_rec_num"  value="1">
    	<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FFFFFF" class="mailtable"> 
	  <tr>
            <td  align="right"> 
                <b>进货单号:</b>
            </td>
            <td>
            	<SELECT size=1 name="billid">
            		<option value="0">请选择...</option>
            		<%
            			for(int i=0; i<billIdList.size(); i++)
            			{
            				tmpStr = (String)billIdList.get(i);
            		%>
            		<option value="<%=tmpStr%>"><%=tmpStr%></option>
			<%
				}
			%>
            	</SELECT>
            </td>
            <td  align="right"> 
                <b>发货人员:</b>
            </td>
            <td>
            	<SELECT name="sendpersons">
            		<option value="0">请选择...</option>
            		<%
            			for(int i=0; i<sendPersonsList.size(); i++)
            			{
            				tmpStr = (String)sendPersonsList.get(i);
            		%>
            		<option value="<%=tmpStr%>"><%=tmpStr%></option>
			<%
				}
			%>
            	</SELECT>
            </td>
            <td  align="right"> 
                <b>收货人员:</b>
            </td>
            <td>
            	<SELECT name="inceptpersons">
            		<option value="0">请选择...</option>
            		<%
            			for(int i=0; i<inceptPersonsList.size(); i++)
            			{
            				tmpStr = (String)inceptPersonsList.get(i);
            		%>
            		<option value="<%=tmpStr%>"><%=tmpStr%></option>
			<%
				}
			%>
            	</SELECT>
            </td>
          </tr>
	</TABLE>
    	<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FFFFFF" class="mailtable"> 
	  <tr>
		<TD align="right" width=13%><b>进货时间:</b></TD>
		<TD width=65%>&nbsp;&nbsp;
		起始 
		<input type=text name='importtime1' size="20" class="none">
		<img src="./images/cal.gif" width="16" height="16" border="0" style="cursor:hand;" align="absmiddle" alt="弹出日历菜单"  onClick="Calendar_importtime1()">&nbsp; 
		终止 
		<input type=text name='importtime2'  size="20" class="none"> 
		<img src="./images/cal.gif" width="16" height="16" border="0" style="cursor:hand;" align="absmiddle" alt="弹出日历菜单"  onClick="Calendar_importtime2()">
		</TD>
		<TD>&nbsp;</TD>
          </tr>
	  <tr>
		<TD align="right" width=13%><b>付款时间:</b></TD>
		<TD width=65%>&nbsp;&nbsp;
		起始 
		<input type=text name='paymenttime1'  size="20" class="none"> 
		<img src="./images/cal.gif" width="16" height="16" border="0" style="cursor:hand;" align="absmiddle" alt="弹出日历菜单"  onClick="Calendar_paymenttime1()">&nbsp; 
		终止 
		<input type=text name='paymenttime2'  size="20" class="none"> 
		<img src="./images/cal.gif" width="16" height="16" border="0" style="cursor:hand;" align="absmiddle" alt="弹出日历菜单"  onClick="Calendar_paymenttime2()">
		</TD>
		<TD>&nbsp;&nbsp;&nbsp;
            		<input name=searchbutton type=button value="查询" onClick='mySubmit1()' >
		</TD>
          </tr>
	  <tr>
		<TD align="right" width=13%><b>排序方式:</b></TD>
		<TD width=65%>
			<SELECT name="orderstr">
				<option value="BillID">进货单号升序</option>
				<option value="BillID DESC">进货单号降序</option>
				<option value="ImportTime">进货时间升序</option>
				<option value="ImportTime DESC">进货时间降序</option>
				<option value="PaymentTime">付款时间升序</option>
				<option value="PaymentTime DESC">付款时间降序</option>
			</SELECT>
		</TD>
		<td>&nbsp;</td>
          </tr>
	</TABLE>
	</form>

	
	<form name="form2" method="post" action="" >
	<font color=#215385><b>进货单列表</b>（共 <font color="red"><%=totalBillNum%></font> 张进货单）</font>

	<IMG src="images/line1.gif" border=0>
	
	<input type="hidden" name="start_rec_num"  value=""><!--提交的时候设置-->
	<input type="hidden" name="orderstr"  value="<%=lastOrderStr%>">
	<input type="hidden" name="billid"  value="<%=lastBillId%>">
	<input type="hidden" name="sendpersons"  value="<%=lastSendPersons%>">
	<input type="hidden" name="inceptpersons"  value="<%=lastInceptPersons%>">
	<input type="hidden" name="importtime1"  value="<%=lastImportTime1%>">
	<input type="hidden" name="importtime2"  value="<%=lastImportTime2%>">
	<input type="hidden" name="paymenttime1"  value="<%=lastPaymentTime1%>">
	<input type="hidden" name="paymenttime2"  value="<%=lastPaymentTime2%>">

	<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FFFFFF" class="mailtable">  
		<%
			if(importBillList.size()>0)
			{
		%>
		<tr bgcolor="#C2CEDC">
		<th></th>
		<th>进货单号</th>
		<th>发货人员</th>
		<th>收货人员</th>
		<th>货单总价</th>
		<th>进货时间</th>
		<th>付款时间</th>
		<th>取消</th>
		<th>删除</th>
		</tr>
		<%
			}
		%>
		
		<%
		NumberFormat nf = NumberFormat.getNumberInstance();
		nf.setMaximumFractionDigits(2);
		
		int index = 0;
	      	GoodsImportBillInfo tmpInfo = null;
	      	
	      	for (index=0; index<importBillList.size(); index++)
		{
	      		tmpInfo = (GoodsImportBillInfo)importBillList.get(index);
	      	%>
	        <tr <%if((index%2)==1){%>bgcolor="#CAE4F4"<%}%> >
	        <td align='center' width=2%><a href="<%= request.getContextPath() + "/importItemsView.do?billId=" + tmpInfo.getBillId() %>" target='importitems'><IMG src="images/news1.gif" border=0 alt='查看进货明细'></a></td>
	        <td align='center'><%= tmpInfo.getBillId() %></td>
	        <td align='center'><%= tmpInfo.getSendPersons() %></td>
	        <td align='center'><%= tmpInfo.getInceptPersons() %></td>
		<td align='center'><%= nf.format(tmpInfo.getTotalPrice()) %></td>
		<td align='center'>
		<%
			String tmpTime = tmpInfo.getImportTime();
			if(tmpTime==null)tmpTime="";
			if(tmpTime.length()>=19)
			{
		%>
				<%= tmpTime.substring(0,19) %>
		<%
			}
		%>
		</td>
		<td align='center'>
		<%
			if(tmpInfo.getPaymentTime()==null)
			{
		%>
			<font color=#E61577>未付款</font><font color=#215385>【</font><a href="javascript:updatePaymentTime('<%=curStartRecNum%>', '<%= tmpInfo.getBillId() %>') ">付款</a><font color=#215385>】</font>
		<%
			}else if((tmpInfo.getPaymentTime()).length()>=19){
		%>
			<%= tmpInfo.getPaymentTime().substring(0,19) %>
		<%
			}
		%>
		</td>
		<td align='center'>
		<%
			if(tmpInfo.getCancelAbleFlage().equals("1"))
			{//可退库（即取消进货单）
		%>
				<a href="javascript:exportGoodsForBill('<%=curStartRecNum%>', '<%= tmpInfo.getBillId() %>') ">取消</a>
		<%
			}
		%>
		</td>
	        <td align='center'>
	        	<a href="javascript:deleteAImportBill('<%=curStartRecNum%>', '<%= tmpInfo.getBillId() %>') "><IMG src="images/delto.gif" border=0></a>
	        </td>
	        </tr>
	        <%
	
	      	}//for
	        %>
	</TABLE>
	</form>
	<!--
	共 <font color="red"><%=totalBillNum%></font> 条记录&nbsp;&nbsp;&nbsp;
	每页 <font color="red"><%=curPageRecNum%></font> 条记录&nbsp;&nbsp;&nbsp;
	起始记录为 <font color="red"><%=curStartRecNum%></font> &nbsp;&nbsp;&nbsp;
	共 <font color="red"><%=totalPageNum%></font> 页&nbsp;&nbsp;&nbsp;
	当前为第 <font color="red"><%=curPageIndex%></font> 页&nbsp;&nbsp;&nbsp;
	末页首记录号为 <font color="red"><%=lastPageFirstRecNum%></font> &nbsp;&nbsp;&nbsp;
	-->
	<div align="right">
		<%
			if(curStartRecNum!=1)
			{
		%>
		<a href="javascript:gotoPageByN(1)"><IMG src="images/startpage.gif" border=0 alt='首页'></a>&nbsp;
		<%
			}
			else
			{
		%>
		<IMG src="images/startpage.gif" border=0 alt='首页'>&nbsp;
		<%	
			}
			
			if(curStartRecNum-curPageRecNum>=1)
			{
		%>
		<a href="javascript:gotoPageByN(<%=curStartRecNum-curPageRecNum%>)"><IMG src="images/lastpage.gif" border=0 alt='上一页'></a>&nbsp;&nbsp;
	    	<%
	    		}
			else
			{
		%>
		<IMG src="images/lastpage.gif" border=0 alt='上一页'>&nbsp;&nbsp;
		<%	
			}
			
	    		if(curStartRecNum+curPageRecNum<=lastPageFirstRecNum)
	    		{
	    	%>
	    	<a href="javascript:gotoPageByN(<%=curStartRecNum+curPageRecNum%>)"><IMG src="images/nextpage.gif" border=0 alt='下一页'></a>&nbsp;
	    	<%
	    		}
			else
			{
		%>
		<IMG src="images/nextpage.gif" border=0 alt='下一页'>&nbsp;
		<%	
			}
			
	    		if(curStartRecNum!=lastPageFirstRecNum && lastPageFirstRecNum>=1)
	    		{
	    	%>
	    	<a href="javascript:gotoPageByN(<%=lastPageFirstRecNum%>)"><IMG src="images/endpage.gif" border=0 alt='末页'></a>&nbsp;&nbsp;&nbsp;&nbsp;
	    	<%
	    		}
			else
			{
		%>
		<IMG src="images/endpage.gif" border=0 alt='末页'>&nbsp;&nbsp;&nbsp;&nbsp;
		<%	
			}
	    	%>
    	</div>
    	
    	<div align="center">
		第 <select name="gotopagenum" onChange="gotoPage()">
		<%for(int i=1; i<=totalPageNum; i++)
		  {%>
			<option value="<%=(i-1)*curPageRecNum+1%>" <%if(i==curPageIndex){%>selected<%}%>><%=i%></option>
		<%}%>
		</select> 页
	</div>

	</td>
        </tr>
        <tr> 
          <td valign="middle" align="center">&nbsp;</td>
        </tr>

      </table>
      
    </td>
    <td width="5"></td>
  </tr>
  <tr> 
    <td width="6"></td>
    <td colspan="2" class="mainhead">&nbsp;</td>
    <td width="5"></td>
  </tr>
  <tr> 
    <td colspan="8" bgcolor="#214984" height="2"></td>
  </tr>
</table>

