<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.tool.SzDateHelp"%>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.SzPageInfo" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.stat.*" %>
<%@ include file="/sessionInfo.jsp"%>

<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../../../share/js/commonTool.js"></script>
</head>
<%
	
	//查询时间段
	String sSearchBegin = SzConvert.strWriteData(request.getParameter("txtSearchBegin"));
	String sSearchEnd = SzConvert.strWriteData(request.getParameter("txtSearchEnd"));
	//用品名称
	String YPMC = SzConvert.strWriteData(request.getParameter("YPMC"));
	//分类名称
	String FLMC = SzConvert.strWriteData(request.getParameter("FLMC"));
	
	//如果开始时间和结束时间都为空，就默认为当前月
	Date curDate = null;
	if(sSearchBegin.equals("")&&sSearchEnd.equals("")){
		curDate = SzDateHelp.getFirstDateMonth();
		sSearchBegin = SzDateHelp.dateToYMD(SzDateHelp.getFirstDateMonth());
		sSearchEnd = SzDateHelp.dateToYMD(SzDateHelp.getLastDateMonth());
	}
	StringBuffer sCond = new StringBuffer("");
	//获取对象信息
    OfficeSupplies officeSupplies = new OfficeSupplies();
	
	String searchType = " AND "+officeSupplies.getStat_SQLOfType("YP.XXMC2",FLMC,"YP.XXMC3",YPMC,"");
	String searchStr = officeSupplies.getStat_SQL("","","","","BI.XXMC3", sSearchBegin, sSearchEnd,searchType);

	Map BuyInMap = officeSupplies.getBuyInMap(searchStr);
	Map BuyInTypeMap = officeSupplies.getBuyInTypeMap(searchStr);
	ArrayList buyInList = officeSupplies.getBuyInTypeList(searchStr);
	int buyInSize = buyInList != null? buyInList.size():0;
	
	
%>
<!-----上面的工具栏------>
<%@ include file="/share/title.jsp"%>
<table width="100%">
  <form name="formBar" method="post">
  <tr>
  	<td valign="bottom" style="padding-bottom: 5px;padding-top: 5px;" align="center">
  		<h4 style="display: inline;">用品采购统计</h4>
  	</td>
  </tr>
  <tr>
    <td>
      分类<input type="text" name="FLMC" class="txtClassSearch" value="<%=FLMC%>">
      用品<input type="text" name="YPMC" class="txtClassSearch" value="<%=YPMC%>">
      开始<input type="text" name="txtSearchBegin" class="txtClassSearch" value="<%=sSearchBegin%>">
      <%=SzPageHelp.calendar2Select("../../../","formBar.txtSearchBegin")%>
      结束<input type="text" name="txtSearchEnd" class="txtClassSearch" value="<%=sSearchEnd%>">
      <%=SzPageHelp.calendar2Select("../../../","formBar.txtSearchEnd")%>
      <%=SzPageHelp.button("查询", "javascript:FormSubmit(formBar,'stat_buyin.jsp');")%>
    </td>
  </tr>
  </form>
</table>

<!-----信息列表----->
<table width="100%" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formList" method="post">
  <tr class="trClassTitle_c">
    <td rowspan="2">分类名称</td>
    <td rowspan="2">用品名称</td>
    <td colspan="3">采购统计</td>
  </tr>
  <tr class="trClassTitle_c">
    <td>采购数量</td>
    <td>平均单价</td>
    <td>采购金额</td>
  </tr>
<%
	
	double count = 0;
	double uCount = 0;
	double flSum = 0;
	double sum = 0;
	Object obj = null;
	
	ArrayList spList = null;
	int spSize = 0;
	String spName = "";
	Object[] value = null;
	int valueSize = 0;
    for (int i=0;i<buyInSize;i++){
    	obj = buyInList.get(i);
    	if (obj == null){
    		continue;
    	}
    	spList = (ArrayList)BuyInTypeMap.get(obj.toString());
    	spSize = spList != null? spList.size():0;
    	out.println("<tr align=\"center\">");
    	out.println("<td rowspan=\""+ spSize +"\">"+ obj.toString() +"&nbsp;</td>");
    	count = 0;
    	flSum = 0;
    	
    	if (spSize <= 0){
    		out.println("<td>&nbsp;</td>");
			out.println("<td>&nbsp;</td>");
			out.println("<td>&nbsp;</td>");
			out.println("<td>&nbsp;</td>");
        	out.println("</tr>");
    	} else {
	    	for (int j =0;j<spSize;j++){
	    		spName = (String)spList.get(j);
	    		if (j != 0){
	    			out.println("<tr align=\"center\">");
	    		}
	    		out.println("<td>"+ spName +"&nbsp;</td>");
	    		value = (Object[])BuyInMap.get(obj.toString()+":"+spName);
	    		valueSize = value != null? value.length:0;
	    		if (value != null) {
	    			double value0 = Double.valueOf(value[0].toString());
	    			double value1 = Double.valueOf(value[1].toString());
	    			count = count + value0;
	    			flSum = flSum + value1;
	    			out.println("<td>"+ SzConvert.formatFloat2Str(value0) +"&nbsp;</td>");
	    			out.println("<td>"+ (value0 != 0? SzConvert.formatFloat2Str(value1/value0):"0.00") +"&nbsp;</td>");
	    			out.println("<td>"+ SzConvert.formatFloat2Str(value1) +"&nbsp;</td>");
	    		} else {
	    			out.println("<td>&nbsp;</td>");
	    			out.println("<td>&nbsp;</td>");
	    			out.println("<td>&nbsp;</td>");
	    		}
	    		out.println("</tr>");
	    	}
    	}
    	out.println("<tr class=\"trClassTitle2\" align=\"center\">");
    	out.println("<td colspan=\"2\">分类合计</td>");
    	out.println("<td>"+ SzConvert.formatFloat2Str(count) +"&nbsp;</td>");
    	out.println("<td>-&nbsp;</td>");
    	out.println("<td>"+ SzConvert.formatFloat2Str(flSum) +"&nbsp;</td>");
    	out.println("<tr>");
    	
    	uCount = uCount + count;
    	sum = sum + flSum;
    }
    out.println("<tr class=\"trClassTitle2\" align=\"center\">");
    out.println("<td colspan=\"2\" style=\"color: red;\">合计</td>");
    out.println("<td>"+ SzConvert.formatFloat2Str(uCount) +"&nbsp;</td>");
	out.println("<td>-&nbsp;</td>");
	out.println("<td>"+ SzConvert.formatFloat2Str(sum) +"&nbsp;</td>");
    out.println("<tr>");
    
    
%>

  </form>
</table>

<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  </form>
</table>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
</form>
<%
    ////如果要使用日历控件，必须输出这个calendarFrame
    out.println(SzPageHelp.calendar2Frame("../../../"));
%>
