<%@ page import="ro.emid.common.db.AccessDB" %>
<%@ page import="ro.emid.common.types.Eveniment" %>
<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="ro.emid.incidente.obj.EvenimentConstants" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.types.Category" %>

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

<TABLE border=0 cellPading=0 cellSpacing=0 width="100%">
    <TR>
        <TD>
            <%@ include file="../header-localizare.jsp"%>
            <span class="slash">/</span> <A class="link" href="<%=AppConstants.APP_NAME%>?action=rapoarte">Rapoarte</A>
            <span class="slash">/</span> Evenimente
        </TD>
    </TR>
</TABLE>

<%
    String locationCondition = "";
    if (formatiaDeLucru.getId() > 0) {
        locationCondition = " AND  INSTR('" + formatiaDeLucru.getCodSap() + "', ev.ID_OBIECT) > 0 ";
    } else if (centruExploatare.getId() > 0) {
        Category[] formatii = CategoryAccessDB.getAllCategoriesByParentId( centruExploatare.getId());
        if (formatii != null && formatii.length > 0) {
            for (int i = 0; i < formatii.length; i++) {
                locationCondition += formatii[i].getCodSap() + (i < formatii.length - 1 ? ";" : "");
            }
            locationCondition = " AND INSTR('" + locationCondition+ "', ev.ID_OBIECT)>0 ";
        }
    } else if (sucursala.getId() > 0) {
        locationCondition = " AND ev.ULPI='" + sucursala.getCodSap() + "' ";
    }  else if( filiala.getId() > 0){
        Category[] sucursale = CategoryAccessDB.getAllCategoriesByParentId( filiala.getId() );
        if (sucursale != null && sucursale.length > 0) {
            for (int i = 0; i < sucursale.length; i++) {
                locationCondition += sucursale[i].getCodSap() + (i < sucursale.length - 1 ? ";" : "");
            }
            locationCondition = " AND INSTR('" + locationCondition+ "', ev.ULPI)>0 ";
        }
    }
%>
<br>
<center>
    <table border=0 width="40%" style="BACKGROUND-COLOR: white" cellspacing="1">
        <tr>
            <td class="gsapthead" ><b>Nr. Evenimente noi</b>:</td>
            <td align=right class="gsapthead" >
                <% Long nrNoi = AccessDB.getCount("EVENIMENTE ev", locationCondition + " AND (ev.STATUS IS NULL OR ev.STATUS = " + Eveniment.STATUS_NEW + ") ");%>
                <%=nrNoi.longValue()%>
            </td>
        </tr>
        <tr>
            <td class="gsapthead" ><b>Nr. Evenimente in arhiva</b>:</td>
            <td align=right class="gsapthead" >
                <% Long nrTotalArhivate = AccessDB.getCount("EVENIMENTE ev", locationCondition + " AND ev.STATUS > " + Eveniment.STATUS_NEW );%>
                <%=nrTotalArhivate%>
            </td>
        </tr>
        <tr>
            <td class="gsapthead" >&nbsp;&nbsp;&nbsp;<b>Nr. Evenimente trimise la Incidente</b>:</td>
            <td align=right class="gsapthead" >
                <% Long nrConvIncidente = AccessDB.getCount("EVENIMENTE ev", locationCondition + " AND ev.STATUS = " + Eveniment.STATUS_TRECUT_INCIDENT);%>
                <%=nrConvIncidente%>
            </td>
        </tr>
        <tr>
            <td class="gsapthead" >&nbsp;&nbsp;&nbsp;<b>Nr. Evenimente trimise la Echipamente</b>:</td>
            <td align=right class="gsapthead" >
                <% Long nrConvEchipamente = AccessDB.getCount("EVENIMENTE ev", locationCondition + " AND ev.STATUS = " + Eveniment.STATUS_TRECUT_ECHIPAMENT);%>
                <%=nrConvEchipamente%>
            </td>
        </tr>
        <tr>
            <td class="gsapthead" >&nbsp;&nbsp;&nbsp;<b>Nr. Evenimente arhivate</b>:</td>
            <td align=right class="gsapthead" >
                <% Long nrArhivate = AccessDB.getCount( "EVENIMENTE ev", locationCondition + " AND ev.STATUS = " + Eveniment.STATUS_ARHIVAT);%>
                <%=nrArhivate%>
            </td>
        </tr>
        <tr>
            <td class="gsapthead" ><b>Nr. Total Evenimente</b>:</td>
            <td align=right class="gsapthead" >
                <% Long nrEvenimente = AccessDB.getCount("EVENIMENTE ev", locationCondition);%>
                <%=nrEvenimente%>
            </td>
        </tr>
    </table>
</center>
<br>
