<%@ 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>
<%
	//获取模块ID
	//String moduleId = SzConvert.toZeroStr(request.getParameter("moduleId"));
	//查询时间段
	String sSearchBegin = SzConvert.strWriteData(request.getParameter("txtSearchBegin"));
	String sSearchEnd = SzConvert.strWriteData(request.getParameter("txtSearchEnd"));
	//获取选择的部门信息
	String BMID = SzConvert.toZeroStr(request.getParameter("BMID"));
	String BMMC = SzConvert.strWriteData(request.getParameter("BMMC"));
	//车牌号码
	String CPHM = SzConvert.strWriteData(request.getParameter("CPHM"));
	
	//如果开始时间和结束时间都为空，就默认为当前月
	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("");
	//获取Vehicle对象
    Vehicle vehicle = new Vehicle();

	
	//========获取部门信息=============
	SzLogin szLogin = new SzLogin();
	SzLoginInfo szLoginInfo = (SzLoginInfo)szLogin.getInfoByCond(" DLID = " + iDLID_SESSION);
	SzDepart depart = new SzDepart();
	StringBuffer departStr = new StringBuffer(" 1=1 ");
	String strManageDepartID = "";
	
	ArrayList loginList = new ArrayList();
	//是管理员时查询所有部门，否则查询当前用户的部门/选择的部门
	if (BMMC.equals("")){
		 if (!isBarManager_SESSION){
			SzUserHelp szUserHelp = new SzUserHelp(); 
			strManageDepartID = SzConvert.toZeroStr(szUserHelp.getManageDepartID(iDLID_SESSION));			
			if (strManageDepartID.equals("0")){
				departStr.append(" and BMID = "+szLoginInfo.getDLBM());
			} else {
				departStr.append(" and BMID IN( " + strManageDepartID + ")");
				sCond.append(" and XXBMID IN( " + strManageDepartID + ")");
			}
		 }
	 } else {
		 departStr.append(" and BMMC = '"+BMMC+"'");
	 }
	 ArrayList departList = depart.getArrayList(departStr.toString());
	 
	 SzDepartInfo departInfo = null;
	 //如果是管理员，还要显示没有部门的员工
	 if(BMMC.equals("")&&isBarManager_SESSION){
		 departInfo = new SzDepartInfo();
		 departInfo.setBMID(0);
		 departInfo.setBMMC("其他");
		 departList.add(departInfo);
	 }
	 int departSize = departList!=null?departList.size():0;

	String searchStr = vehicle.getStat_SQL(BMMC,"","YC.SQXXMC7", sSearchBegin, sSearchEnd, sCond.toString());

	Map ChuCheCount = vehicle.getChuCheCount(CPHM,searchStr);
	searchStr = vehicle.getStat_SQL(BMMC,"","HCMXXXMC16", sSearchBegin, sSearchEnd, sCond.toString());
	Map ChuCheFeiYong = vehicle.getChuCheFeiYong(CPHM,searchStr);
	
	Map WeiXiuCount = vehicle.getWeiXiuCount(CPHM,searchStr);
	searchStr = vehicle.getStat_SQL(BMMC,"","WZMXXXMC11", sSearchBegin, sSearchEnd, sCond.toString());
	Map ShiGuCount = vehicle.getShiGuCount(CPHM,searchStr);
	Map WeiZhangCount = vehicle.getWeiZhangCount(CPHM,searchStr);
	
	ArrayList clList = vehicle.getChuLiangList(CPHM.equals("")? "1=1":"CLXXXXMC3='"+CPHM+"'");
	int keyCount = clList.size();
	//存放合计数据
	Map sumCount = new HashMap();
	
%>
<!-----上面的工具栏------>
<%@ include file="/docEngine/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="CPHM" class="txtClassSearch" value="<%=CPHM%>">
      开始<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_vehicle.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 colspan="2">出车</td>
    <td colspan="7">费用</td>
    <td rowspan="2">维修</td>
    <td rowspan="2">违章</td>
    <td rowspan="2">事故</td>
  </tr>
  <tr class="trClassTitle_c">
  	<td>次数</td>
    <td>公里数</td>
    
    <td>加油</td>
    <td>过路</td>
    <td>洗车</td>
    <td>停车</td>
    <td>维修</td>
    <td>其他</td>
    <td>合计</td>
  </tr>
  
<%
	String[] feiYong = new String[]{"加油费","过路费","洗车费","停车费","维修费","其他费用"};
	int feiYongCount = feiYong.length;
	StringBuffer outSB = new StringBuffer();
	int count = 0;
	int departCount = 0;
	double money = 0;
	double sumAll = 0;
	double sumMoney = 0;
	double sumValue = 0;
	int sum = 0;
	Object obj = null;
	Object objvalue[] = null;
	Object OSum = null;
	String sumStr = "";
    for (int i=0;i<keyCount;i++){
    	obj = clList.get(i);
    	objvalue = (Object[])ChuCheCount.get(obj.toString());
    	out.println("<tr align=\"center\">");
    	out.println("<td>"+ obj +"&nbsp;</td>");
    	
    	OSum = sumCount.get("1");
    	sum = OSum != null? Integer.valueOf(OSum.toString()):0;
    	sumStr = objvalue!=null && !"".equals(objvalue[0])? objvalue[0].toString():"0";
    	sum = sum + Integer.valueOf(sumStr);
    	sumCount.put("1",sum);
    	out.println("<td>"+ sumStr +"&nbsp;</td>");
    	
    	OSum = sumCount.get("2");
    	money = OSum != null? Double.valueOf(OSum.toString()):0;
    	sumStr = objvalue!=null && !"".equals(objvalue[1])? objvalue[1].toString():"0";
    	sumValue = Double.valueOf(sumStr);
    	money = money + sumValue;
    	sumCount.put("2",money);
    	out.println("<td>"+ SzConvert.formatFloat2Str(sumValue) +"&nbsp;</td>");
    	
    	sumMoney = 0;
    	sumAll = 0;
    	
    	for (int j=0;j<feiYongCount;j++){
    		objvalue = (Object[])ChuCheFeiYong.get(obj.toString()+":"+feiYong[j]);
    		OSum = sumCount.get((2+j+1)+"");
    		money = OSum != null? Double.valueOf(OSum.toString()):0.00;
    		sumStr = objvalue!=null && !"".equals(objvalue[0])? objvalue[0].toString():"0.00";
    		sumValue = Double.valueOf(sumStr);
    		money = money + sumValue;
    		sumAll = sumAll + sumValue;
        	sumCount.put((2+j+1)+"",money);
        	sumMoney = sumMoney + money;
        	out.println("<td>"+ SzConvert.formatFloat2Str(sumValue) +"&nbsp;</td>");
        	
    	}
    	out.println("<td>"+ SzConvert.formatFloat2Str(sumAll) +"&nbsp;</td>");
    	sumCount.put((2+feiYongCount+1)+"",sumMoney);
    	
    	objvalue = (Object[])WeiXiuCount.get(obj.toString());
    	OSum = sumCount.get((3+feiYongCount+1)+"");
    	sum = OSum != null? Integer.valueOf(OSum.toString()):0;
    	sumStr = objvalue!=null && !"".equals(objvalue[0])? objvalue[0].toString():"0";
    	sum = sum + Integer.valueOf(sumStr);
    	sumCount.put((3+feiYongCount+1)+"",sum);
    	out.println("<td>"+ sumStr +"&nbsp;</td>");
    	
    	objvalue = (Object[])WeiZhangCount.get(obj.toString());
    	OSum = sumCount.get((3+feiYongCount+2)+"");
    	sum = OSum != null? Integer.valueOf(OSum.toString()):0;
    	sumStr = objvalue!=null && !"".equals(objvalue[0])? objvalue[0].toString():"0";
    	sum = sum + Integer.valueOf(sumStr);
    	sumCount.put((3+feiYongCount+2)+"",sum);
    	out.println("<td>"+ sumStr +"&nbsp;</td>");
    	
    	objvalue = (Object[])ShiGuCount.get(obj.toString());
    	OSum = sumCount.get((3+feiYongCount+3)+"");
    	sum = OSum != null? Integer.valueOf(OSum.toString()):0;
    	sumStr = objvalue!=null && !"".equals(objvalue[0])? objvalue[0].toString():"0";
    	sum = sum + Integer.valueOf(sumStr);
    	sumCount.put((3+feiYongCount+3)+"",sum);
    	out.println("<td>"+ sumStr +"&nbsp;</td>");
    	
    	
    	
    }
    out.println("<tr class=\"trClassTitle2\">");
    out.println("<td style=\"color: red;\">合计</td>");
    for (int i=1;i<=3+feiYongCount+3;i++){
    	obj = sumCount.get(i+"");
    	if (i>=2&&i<10){
    		out.println("<td>"+ SzConvert.formatFloat2Str(Double.valueOf(obj!=null? obj.toString():"0")) +"&nbsp;</td>");
    	} else {
    		out.println("<td>"+ (obj!=null? obj:"-") +"&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("../../../"));
%>
