<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/9/11
  Time: 12:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.*" %>
<%@ page import="com.censoft.common.db.ConnectionFactory" %>
<%@ page import="com.censoft.common.base.Pub" %>
<%@ page import="org.omg.CosCollection.IteratorInBetween" %>
<%!
    Pub pub = new Pub();

    public String getCounts(ConnectionFactory cf,Connection conn,String id,String ly_user_view){
        Hashtable ht1 = new Hashtable();
        String jiazhi="";
        int jz_total=0;
        Vector list = cf.doQuery(conn,"select jiazhi from zc_register where zc_id in (select  zc_id from zc_ly where ly_id =? and ly_user=?)",null,new Object[]{id,ly_user_view});
        if(list==null){
            System.out.println("查询出错"+cf.getMsg());
        }
        if(list!=null && list.size()>0){
            for(int i=0;i<list.size();i++){
                ht1=(Hashtable)list.get(i);
                jiazhi=pub.trimNull((String)ht1.get("jiazhi"));
                if("".equals(jiazhi)){
                    jiazhi="0";
                }
                jz_total=Integer.parseInt(jiazhi)+jz_total;
            }
        }
        return list.size()+","+jz_total;
    }
%>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    String page_number = pub.trimNull(request.getParameter("page_number"));
    if ("".equals(page_number)) page_number = "1";
    String login_user = (String) session.getAttribute("session_login_id");
    String login_name = (String) session.getAttribute("session_login_name");
    String page_size = pub.trimNull(request.getParameter("page_size"));
    String xm_id = pub.trimNull(request.getParameter("xm_id"));
    String ly_id = pub.trimNull(request.getParameter("ly_id"));
    String ly_dept = pub.trimNull(request.getParameter("ly_dept"));
    String ly_user = pub.trimNull(request.getParameter("ly_user"));
    String ly_status = pub.trimNull(request.getParameter("ly_status"));
    String b_jiazhi = pub.trimNull(request.getParameter("b_jiazhi"));
    String e_jiazhi = pub.trimNull(request.getParameter("e_jiazhi"));
    String b_time = pub.trimNull(request.getParameter("b_time"));
    String e_time = pub.trimNull(request.getParameter("e_time"));
    if ("".equals(page_size)) page_size = "10";
    List list_s = new ArrayList();
    try {
        StringBuffer sb = new StringBuffer();
        sb.append("select distinct ly_id,xm_id,ly_dept,ly_time,ly_user,ly_status,add_time from zc_ly where 1=1 ");
        if(!"".equals(xm_id)){
            sb.append(" and xm_id = ?");
            list_s.add(xm_id);
        }if(!"".equals(ly_id)){
            sb.append(" and ly_id like ?");
            list_s.add("%"+ly_id+"%");
        }if(!"".equals(ly_dept)){
            sb.append(" and ly_dept like ?");
            list_s.add("%"+ly_dept+"%");
        }
        if("admin".equals(login_user)){
            if(!"".equals(ly_user)){
                sb.append(" and ly_user like ?");
                list_s.add("%"+ly_user+"%");
            }
        }else{
            sb.append(" and ly_user = ?");
            list_s.add(login_name);
        }
        if(!"".equals(ly_status)){
            sb.append(" and ly_status = ?");
            list_s.add(ly_status);
        }if(!"".equals(b_time)){
            sb.append(" and ly_time >= ?");
            list_s.add(b_time);
        }if(!"".equals(e_time)){
            sb.append(" and ly_time <= ?");
            list_s.add(e_time);
        }
        sb.append(" order by add_time desc");

        conn = com.censoft.db.DBUtil.getConnection();
        v_list = cf.doPageQueryWithCount(conn, sb.toString(), page_number, page_size, null, list_s.toArray());
        if (v_list == null) {
            out.println("查询出错" + cf.getMsg());
            return;
        }

    Hashtable ht_row = (Hashtable) v_list.get(0);
    String rowCnt = pub.trimNull((String) ht_row.get("ROWCOUNT"));
    String telSegmentUrl="./list_ly-t.jsp";
%>
<div>
    <a class="btn btn-primary radius" onclick="addRules('<%=telSegmentUrl%>');" >
        领用
    </a>
</div>
<div class="table-list">
    <table class="table  table-hover table-bg">
        <thead>
        <tr class="text-c">
            <th width="120px">所属项目</th>
            <th width="150px">领用编号</th>
            <th width="120px">领用单位</th>
            <th width="50px">领用时间</th>
            <th width="50px">领用人</th>
            <th width="50px">价值</th>
            <th width="50px">领用数量</th>
            <th width="50px">领用状态</th>
            <th width="50px">操作</th>
        </tr>
        </thead>
        <tbody>
        <%
            if (v_list != null && v_list.size() > 0) {
                    for (int i = 1; i < v_list.size(); i++) {
                        Hashtable ht = (Hashtable) v_list.get(i);
                        String ly_id_view = pub.trimNull((String) ht.get("ly_id"));
                        String ly_user_view = pub.trimNull((String) ht.get("ly_user"));
                        String jiazhi_counts=getCounts(cf,conn,ly_id_view,ly_user_view);
                        String jiazhi_view="";
                        String counts_view="";
                        if(jiazhi_counts.length()>1){
                            jiazhi_view=jiazhi_counts.split(",")[1];
                            counts_view=jiazhi_counts.split(",")[0];
                        }
						if("0".equals(counts_view)){
							counts_view="1";
						}
                        String xm_id_view = pub.trimNull((String) ht.get("xm_id"));
                        String ly_dept_view = pub.trimNull((String) ht.get("ly_dept"));
                        String ly_time_view = pub.trimNull((String) ht.get("ly_time"));
                        if(ly_time_view.length()>=10){
                            ly_time_view=ly_time_view.substring(0,10);
                        }
                        String ly_status_view = pub.trimNull((String) ht.get("ly_status"));
                        String info_url="./ly_info-t.jsp?ly_id="+ly_id_view;
                        String view_name="查看进度";
                        if("0".equals(ly_status_view)){
                            ly_status_view="未提交";
                            view_name="详情";
                            info_url="./list_ly-t.jsp?ly_id="+ly_id_view+"&action=update";
                        }else if("1".equals(ly_status_view)){
                            ly_status_view="已提交";
                        }else if("3".equals(ly_status_view)){
                            ly_status_view="已完结";
							view_name="详情";
                            info_url="./list_ly-t.jsp?ly_id="+ly_id_view+"&action=update";
                        }else if("2".equals(ly_status_view)){
                            ly_status_view="审批中";
                        }else if("4".equals(ly_status_view)){
                            ly_status_view="审批不通过";
                        }
                        %>
                        <tr <%if(i%2==0){%>id="tr_doub"<%}else{%>id="tr_single"<%}%> class="text-c">
                            <td><%=xm_id_view%>
                            </td>
                            <td><%=ly_id_view%>
                            </td>
                            <td><%=ly_dept_view%>
                            </td>
                            <td><%=ly_time_view%>
                            </td>
                            <td><%=ly_user_view%>
                            </td>
                            <td><%=jiazhi_view%>
                            </td>
                            <td><%=counts_view%>
                            </td>
                            <td><%=ly_status_view%>
                            </td>
                            <td>
                                <a title="<%=view_name%>" href="javascript:void(0);" onclick="updateById('<%=info_url%>','<%=ly_id_view%>');" class="ml-5" >
                                    <i class="Hui-iconfont"><%=view_name%></i>
                                </a>
                                <%if("已提交".equals(ly_status_view)){%>
                                <a title="拿回" href="javascript:void(0);" onclick="nahui('<%=ly_id_view%>');" class="ml-5" >
                                    <i class="Hui-iconfont">拿回</i>
                                </a>
                                <%}%>
								<%if("未提交".equals(ly_status_view)){%>
                               <a title="删除" href="javascript:void(0);" onclick="deleteById('<%=ly_id_view%>');" class="ml-5" >
                                    <i class="Hui-iconfont">删除</i>
                                </a>
								<%}%>
                            </td>
                        </tr>
                        <%
                    }
            }
        %>
        </tbody>
    </table>
</div>
<jsp:include page="/common/page_ajax.jsp" >
    <jsp:param name="page_number" value="<%=page_number%>" />
    <jsp:param name="rowCnt" value="<%=rowCnt%>" />
    <jsp:param name="page_size" value="<%=page_size%>" />
</jsp:include>
<%
    } catch (Exception e) {
        out.println("查询异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>