<%@ 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.*"%>

<body onload="document.form1.goodsid.focus()">

<script language="JavaScript">

function mySubmit1(){

	document.form1.start_rec_num.value = '1';
	document.form1.action="importItemSearch.do";
	document.form1.submit();
}

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

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


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

function deleteAImportItem(currec, billid, goodsid, confirmflage)
{
	if(confirm("该操作只删除进货明细信息，不影响进货单和库存信息\r\n确定要删除该进货明细信息吗？")) 
	{
		document.form2.start_rec_num.value = currec;
		document.form2.action = "importItemDelete.do?deletebillid="+billid+"&deletegoodsid="+goodsid+"&deleteconfirmflage="+confirmflage;
		document.form2.submit();
	}
}

function exportGoodsForItem(currec, billid, goodsid, confirmflage)
{
	if(confirm("该操作将删除进货明细信息，并调整进货单和库存信息\r\n确定要取消该进货明细信息吗？")) 
	{
		document.form2.start_rec_num.value = currec;
		document.form2.action = "importItemCancel.do?cancelbillid="+billid+"&cancelgoodsid="+goodsid+"&cancelconfirmflage="+confirmflage;
		document.form2.submit();
	}
}


function submitTempImportBill(currec, billid)
{
	if(confirm("该确认操作将确认提交整张临时进货单\r\n确定要提交该单所有进货明细信息吗？")) 
	{
		document.form2.start_rec_num.value = currec;
		document.form2.action = "importItemSubmitTemp.do?submitbillid="+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">   
          
<%//
	//---从页面对象中获取数据---
	ImportItemSearchConFB iiscfb = (ImportItemSearchConFB)request.getAttribute(Globals.REQUEST_IMPORTITEMSEARCHCON);
	List billIdList = iiscfb.getBillIdList();
	List createPersonList = iiscfb.getCreatePersonList();

	int curStartRecNum = iiscfb.getStartRecNum();		//当前起始记录号
	int curPageRecNum = iiscfb.getPageRecNum();		//页记录数
	ImportItemSearchResultInfo iisri = iiscfb.getIisri();	//检索结果可能为空
	ImportItemSearchRule iisr = iiscfb.getIisr();		//检索式可能为空
	//-------

	
	//组织与页、记录相关的信息
	List importItemList = new ArrayList();
	int totalItemNum = 0;
	if(iisri != null)
	{
		totalItemNum = iisri.getTotalRecNum();		//总记录数
		importItemList = iisri.getImportItemList();
		System.out.println("totalItemNum:"+totalItemNum);
		System.out.println("importItemList.size():"+importItemList.size());
	}
	int curPageIndex = curStartRecNum/curPageRecNum+1;	//当前页号
	int totalPageNum = 0;					//总页数
	if(totalItemNum%curPageRecNum==0)
	{
		totalPageNum = totalItemNum/curPageRecNum;
	}else{
		totalPageNum = totalItemNum/curPageRecNum+1;
	}
	int lastPageFirstRecNum = 0;				//最后一页的首记录号
	if(totalItemNum%curPageRecNum==0)
	{
		lastPageFirstRecNum = (totalItemNum/curPageRecNum-1)*(curPageRecNum)+1;
	}else{
		lastPageFirstRecNum = (totalItemNum/curPageRecNum)*(curPageRecNum)+1;
	}
	
	//获得上次检索式的值，由于检索式可能为空，所以设置一个缺省值
	String lastOrderStr = "BillID";
	String lastBillId = "0";
	String lastGoodsId = "";
	String lastGoodsName = "";
	String lastCreatePerson = "";
	String lastConfirmFlage = "";
	if(iisr!=null)
	{
		lastOrderStr = iisr.getOrderStr();
		lastBillId = iisr.getBillId() + "";
		lastGoodsId = iisr.getGoodsId();
		lastGoodsName = iisr.getGoodsName();
		lastCreatePerson = iisr.getCreatePerson();
		lastConfirmFlage = iisr.getConfirmFlage();
	}
	
	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>
            	<input type=text name='goodsid' size="20" class="none" onKeyDown="if(event.keyCode==13) mySubmit1();">
            </td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td  align="right"> 
                <b>录入人员:</b>
            </td>
            <td>
            	<SELECT size=1 name="createperson">
            		<option value="">请选择...</option>
            		<%
            			for(int i=0; i<createPersonList.size(); i++)
            			{
            				tmpStr = (String)createPersonList.get(i);
            		%>
            		<option value="<%=tmpStr%>"><%=tmpStr%></option>
			<%
				}
			%>
            	</SELECT>
            </td>

            <td  align="right"> 
                <b>货物名称:</b>
            </td>
            <td>
            	<input type=text name='goodsname' size="20" class="none" onKeyDown="if(event.keyCode==13) mySubmit1();">
            </td>
            <TD width=20%>
                <input name=searchbutton type=button value="查询" onClick='mySubmit1()' >
	    </TD>
          </tr>
          <tr>
		<TD align="right"><b>单据状态:</b></TD>
		<TD>
			<SELECT name="confirmflage">
				<option value="">请选择...</option>
				<option value="1">确认单</option>
				<option value="0">临时单</option>
			</SELECT>
		</TD>
		<TD align="right"><b>排序方式:</b></TD>
		<TD>
			<SELECT name="orderstr">
				<option value="BillID">进货单号升序</option>
				<option value="BillID DESC">进货单号降序</option>
				<option value="GoodsID">货物标识升序</option>
				<option value="GoodsID DESC">货物标识降序</option>
				<option value="GoodsName">货物名称升序</option>
				<option value="GoodsName DESC">货物名称降序</option>
				<option value="CreateTime">录入时间升序</option>
				<option value="CreateTime DESC">录入时间降序</option>
			</SELECT>
		</TD>
		<td>&nbsp;</td>
          </tr>
	</TABLE>
	</form>

	<br>
	
	<form name="form2" method="post" action="" >
	<font color=#215385><b>进货明细列表</b>（共 <font color="red"><%=totalItemNum%></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="goodsid"  value="<%=lastGoodsId%>">
	<input type="hidden" name="goodsname"  value="<%=lastGoodsName%>">
	<input type="hidden" name="createperson"  value="<%=lastCreatePerson%>">
	<input type="hidden" name="confirmflage"  value="<%=lastConfirmFlage%>">

	<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FFFFFF" class="mailtable">  
		<%
			if(importItemList.size()>0)
			{
		%>
		<tr bgcolor="#C2CEDC">
		<th>单号</th>
		<th></th>
		<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;
	      	GoodsImportItemInfo tmpInfo = null;
	      	
	      	for (index=0; index<importItemList.size(); index++)
		{
	      		tmpInfo = (GoodsImportItemInfo)importItemList.get(index);
	      	%>
	        <tr <%if((index%2)==1){%>bgcolor="#CAE4F4"<%}%> >
	        
	        <td align='center'><%= tmpInfo.getBillId() %></td>
	        <td align='center' width=2%><a href="<%= request.getContextPath() + "/goodsInfoView.do?goodsid=" + tmpInfo.getGoodsId() %>" target='goodsinfo'><IMG src="images/goods.gif" border=0 alt='查看货物信息'></a></td>
	        <td align='center'><%= tmpInfo.getGoodsId() %></td>
	        <td align='center'><%= tmpInfo.getGoodsName() %></td>
		<td align='center'><%= tmpInfo.getImportAmount() %></td>
		<td align='center'><%= nf.format(tmpInfo.getImportUnitPrice()) %></td>
		<td align='center'><%= tmpInfo.getCreatePerson() %></td>
		<td align='center'>
		<%
			String tmpTime = tmpInfo.getCreateTime();
			if(tmpTime==null)tmpTime="";
			if(tmpTime.length()>=19)
			{
		%>
				<%= tmpTime.substring(0,19) %>
		<%
			}
		%>
		</td>
		<td align='center'>
		<%
			if(tmpInfo.getConfirmFlage().equals("0"))
			{
		%>
			<font color=#E61577>临时单</font><font color=#215385>【</font><a href="javascript:submitTempImportBill('<%=curStartRecNum%>', '<%=tmpInfo.getBillId()%>') ">确认</a><font color=#215385>】</font>
		<%
			}else{
		%>
			<font color=#007168>确认单</font>
		<%
			}
		%>
		</td>
		<td align='center'>
			<%
			if(tmpInfo.getCancelAbleFlage().equals("1"))
			{//可退库（即取消进货单）
			%>
			<a href="javascript:exportGoodsForItem('<%=curStartRecNum%>', '<%=tmpInfo.getBillId()%>', '<%=tmpInfo.getGoodsId()%>', '<%=tmpInfo.getConfirmFlage()%>') ">取消</a>
			<%
			}
			%>
		</td>
	        <td align='center'>
	        	<a href="javascript:deleteAImportItem('<%=curStartRecNum%>', '<%=tmpInfo.getBillId()%>', '<%=tmpInfo.getGoodsId()%>', '<%=tmpInfo.getConfirmFlage()%>') "><IMG src="images/delto.gif" border=0></a>
	        </td>
	        </tr>
	        <%
	
	      	}//--for
	        %>
	</TABLE>
	</form>

	<!--
	共 <font color="red"><%//=totalItemNum%></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>
</body>
