<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="ro.emid.common.utils.Util" %>
<%@ page import="java.util.Date" %>

<%@ include file="declaratii.jsp"%>

<%
    /**
     * @see ro.emid.incidente.action.category.ShowFilialeAction
     */
    Category[] filiale = CategoryAccessDB.getAllCategoriesByParentId(-1);
    Long nrIncidenteTotal = (Long) request.getAttribute("nrIncidenteTotal");
%>

<TABLE border=0 cellPading=0 cellSpacing=0 width="100%" bgcolor="">
    <TR>
        <TD>
            <%@ include file="../header-localizare.jsp"%>
        </TD>
        <TD align="RIGHT">
            <%--<A href="javascript: alert('[to-do]');" class="link">Lista ultimelor 10 incidente per total</A>--%>
            <%--<IMG alt=FAQ border=0 width=12 height=13 hspace=3 src="<%= AppConstants.WEB_RESOURCE_PATH + "/images/icon_mini_search.gif" %>">--%>
        </TD>
    </TR>
</TABLE>
<TABLE border=0 cellPadding=2 cellSpacing=1 width="100%" class="gSAPTHEAD" style="BACKGROUND-COLOR: white">
    <TR>
        <TH class="gsapthead" colSpan=2 height=25 noWrap>Filiale Electrica:</TH>
        <TH class="gsapthead" noWrap width=60>Nr.incidente</TH>
        <TH class="gsapthead" noWrap width=150>Data ultimei editari</TH>
    </TR>
    <%
        if (null == filiale) {%>
        <TR>
            <TD>
                Nu sunt filiale definite ...
            </TD>
        </TR>
    <%} else {
        for(int i=0; i < filiale.length; i++) {%>
            <TR class="row<%=i%2%>">
                <TD height=50 valign="middle" align="center">
                    <IMG height=25 src="<%= AppConstants.WEB_RESOURCE_PATH + "/images/folder_big.gif" %>" width=46>
                </TD>
                <TD height=50 width="100%">
                    <%=Util.format(filiale[i].getCodSap())%>&nbsp;<A title="Lista sucursale <%=filiale[i].getName()%>" class="link" href="<%=AppConstants.APP_NAME%>?action=showSucursale&filialaId=<%=filiale[i].getId()%>"><%=filiale[i].getName()%></A>&nbsp;
                    <%=(filiale[i].getDescription() == null) ? "": '-' + filiale[i].getDescription()%><BR>
                    <SPAN style="font-size: 10px;"><%
                        final Category[] sucs = (Category[]) request.getAttribute("sucursale-"+filiale[i].getId());
                        if (sucs != null) for(int j=0;j<sucs.length; j++) {%>
                            <%=sucs[j].getName() + ", "%>
                        <%}%>
                    </span>
            </TD>
            <TD height=50 valign="middle" align="center">
                <% Long nrIncidente = (Long) request.getAttribute("nrIncidente-"+filiale[i].getId()); %>
                <SPAN class=gensmall><%=nrIncidente%></SPAN>
            </TD>
            <TD height=50 noWrap valign="middle" align="center">
                <SPAN class=gensmall>
                    <%
                        int year = 0;
                        int day_of_week = 0;
                        Date data = (Date) request.getAttribute("dateLastIncident-" + filiale[i].getId());
                        if (data != null) {
                            day_of_week = data.getDay();
                            year = data.getYear();
                        } else year = 0;
                    %>
                    <%=(year == 0) ? "neintrodusa" : AppConstants.ZILE_SAPTAMINI[day_of_week] + ", " + AppConstants.formatDataTime( data)%>
               </SPAN>
            </TD>
        </TR>
    <%}%>
    <tr style="font-weight:bold;">
        <td class="gsapthead" colspan="2" align="right">&nbsp;Total:&nbsp;</td>
        <td class="gsapthead" align="center"><%=nrIncidenteTotal%></td>
        <td class="gsapthead">&nbsp;</td>
    </tr>

    <%}%>
</TABLE>
