<%@ page import="ro.emid.common.utils.pagination.PaginationController" %>
<%@ page import="ro.emid.common.utils.sort.SortController" %>
<%@ page import="ro.emid.common.utils.sort.SortData" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationConstants" %>
<%@ page import="ro.emid.common.db.AccessDB" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="ro.emid.common.db.framework.DatabaseException" %>
<%@ page import="ro.emid.common.utils.StringUtils" %>
<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="java.util.*" %>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.incidente.IncidenteSessionUtils" %>
<%@ page import="ro.emid.common.types.*" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationData" %>
<%@ page import="ro.emid.common.constants.GlobalAppConstants" %>
<%@ page import="ro.emid.common.constants.RoleConstants" %>

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


<%
    class RaportRow{
        long idLf;
        String codLf;
        String denLf;
        String denSucursala;
        String denCentru;

        long cntEvenimente;
        long durataEvenimente;
        double cheltTotalMent;
        double cheltTotalDaune;
        double cheltTotalExpl;
        double cheltTotalEvenimente;
        double energieNelivrata;

        //date din FI
        long cntIncidente;
        long durataIncidente;
        double cheltIncMent;
        double cheltIncExpl;
        double cheltIncDaune;
        double cheltIncTotal;

        //date din FE
        long cntEchipamente;
        long durataEchipamente;

        double cheltEchMent;
        double cheltEchExpl;
        double cheltEchDaune;
        double cheltEchTotal;
    }

    class Totaluri{
        long countIncidente;
        long countEchipamente;
        long countEvenimente;
        long durataEvenimente;
        double energieNelivrata;
        double costMent;
        double costDaune;
        double costExpl;
        double costTotal;
    }

%>

<%
    final PaginationData pd = PaginationController.getPaginationData( request, 20);
    final SortData sd = SortController.getSortData(request, "CNT_T", "DESC");

    final Category filialaRaport = filiala;
    final Category sucursalaRaport = sucursala;
    final Category centruRaport = centruExploatare;

    final String tip = StringUtils.getNullSafe( request.getParameter("tip"), "STATIE_COD");
    String tipObCondition = "";

    if( "STATIE_COD".equals( tip)){
        tipObCondition =  "AND lf.TIP_OB = 'UTILIT.ST'";
    }else if ("LINIE_COD".equals( tip)){
        tipObCondition = "AND ( lf.TIP_OB LIKE 'LEA%' OR lf.TIP_OB LIKE 'LES%' )";
    }else if( "PAPT_COD".equals( tip)){
        //tipObCondition =  "AND lf.TIP_OB LIKE 'P%'";
        tipObCondition = "AND lf.TIP_OB IN ('PCAB', 'PTA', 'PTM', 'PT', 'PTS', 'PTZ', 'PTAB', 'PA')";
    }

    final Date dataStart = ObjectUtils.getDateValue( request.getParameter("data_start"), GlobalAppConstants.FORMAT_DATA);
    Date dataStop  = ObjectUtils.getDateValue(request.getParameter("data_stop"), GlobalAppConstants.FORMAT_DATA);
    if( dataStop == null) dataStop = new Date();


    final ro.emid.common.types.CategoryCheckData checkData = IncidenteSessionUtils.getCategoriiSelectate(session);


    final StringBuffer filterIncidente = new StringBuffer();
    final StringBuffer filterEchipamente = new StringBuffer(" AND NVL( INCIDENT_ID, 0) <= 0 ");

    if( filialaRaport != null && filialaRaport.getId() > 0){
        filterIncidente.append(" AND FILIALA_ID = ").append( filialaRaport.getId());
        filterEchipamente.append(" AND FILIALA_ID = ").append( filialaRaport.getId());
    }

    if( sucursalaRaport != null && sucursalaRaport.getId() > 0){
        filterIncidente.append(" AND SUCURSALA_ID = ").append( sucursalaRaport.getId());
        filterEchipamente.append(" AND SUCURSALA_ID = ").append( sucursalaRaport.getId());
    }

    if( centruRaport != null && centruRaport.getId() > 0){
        filterIncidente.append(" AND SECTIE_ID = ").append( centruRaport.getId());
        filterEchipamente.append(" AND SECTIE_ID = ").append( centruRaport.getId());
    }

    if ( dataStart != null){
        filterIncidente.append( " AND DATA >= TO_DATE('").append( AppConstants.format(dataStart)).append("', 'DD.MM.YYYY') " );
        filterEchipamente.append( " AND DATA_DETERIORARE >= TO_DATE('").append( AppConstants.format(dataStart)).append("', 'DD.MM.YYYY') " );
    }

    if ( dataStop != null){
        filterIncidente.append( " AND DATA <= TO_DATE('").append( AppConstants.format(dataStop)).append("', 'DD.MM.YYYY') " );
        filterEchipamente.append( " AND DATA_DETERIORARE <= TO_DATE('").append( AppConstants.format(dataStop)).append("', 'DD.MM.YYYY') " );
    }


    //{Checked Categories
    //Filiale

    long ids[] = checkData.getIdFiliale();
    String condition = " AND (";
    if( ids.length > 0){
        filterIncidente.append( condition);
        filterEchipamente.append( condition);
        filterIncidente.append(" FILIALA_ID IN (");
        filterEchipamente.append(" FILIALA_ID IN (");
        for (int i = 0; i < ids.length; i++) {
            final long id = ids[i];
            filterIncidente.append( id).append( i < ids.length - 1 ? ", " : "") ;
            filterEchipamente.append( id).append( i < ids.length - 1 ? ", " : "") ;
        }
        filterIncidente.append(") ");
        filterEchipamente.append(") ");

        condition = " OR ";
    }

    ids = checkData.getIdSucursale();

    if( ids.length > 0){
        filterIncidente.append( condition);
        filterEchipamente.append( condition);
        filterIncidente.append(" SUCURSALA_ID IN (");
        filterEchipamente.append(" SUCURSALA_ID IN (");
        for (int i = 0; i < ids.length; i++) {
            final long id = ids[i];
            filterIncidente.append( id).append( i < ids.length - 1 ? ", " : "") ;
            filterEchipamente.append( id).append( i < ids.length - 1 ? ", " : "") ;
        }
        filterIncidente.append(") ");
        filterEchipamente.append(") ");

        condition = " OR ";
    }

    ids = checkData.getIdCentre();

    if( ids.length > 0){
        filterIncidente.append( condition);
        filterEchipamente.append( condition);
        filterIncidente.append(" SECTIE_ID IN (");
        filterEchipamente.append(" SECTIE_ID IN (");

        for (int i = 0; i < ids.length; i++) {
            final long id = ids[i];
            filterIncidente.append( id).append( i < ids.length - 1 ? ", " : "") ;
            filterEchipamente.append( id).append( i < ids.length - 1 ? ", " : "") ;
        }

        filterIncidente.append(") ");
        filterEchipamente.append(") ");
        condition = " OR ";
    }

    if( condition.equals(" OR ")){
        filterIncidente.append(')');  //for AND ( FILIALA_ID IN(...) OR SUCURSLA_ID IN (...) OR SECTIE_ID IN (...))
        filterEchipamente.append(')');  //for AND ( FILIALA_ID IN(...) OR SUCURSLA_ID IN (...) OR SECTIE_ID IN (...))
    }
    //}

    final StringBuffer sql = new StringBuffer();

    sql.append("SELECT \n" + "    lf.ID ID_LF, \n" + "    lf.COD_LF, \n" + "    lf.DESC_LF, \n" + "    s.NAME SUCURSALA, \n" + "    c.NAME CENTRU, \n" + "    NVL( i.CNT_INCIDENTE, 0) + NVL( e.CNT_ECHIPAMENTE, 0) CNT_T,\n" + "    NVL( i.DURATA_INCIDENTE, 0) + NVL( e.DURATA_ECHIPAMENTE, 0) DURATA_T,\n" + "    NVL( i.CM, 0) + NVL( e.CM, 0) CM_T,\n" + "    NVL( i.CD, 0) + NVL( e.CD, 0) CD_T,\n" + "    NVL( i.CEXP, 0) + NVL( e.CEXP, 0) CEXP_T,\n" + "    NVL( i.CT, 0) + NVL( e.CT, 0) CT_T, \n" + "    NVL( i.DURATA_INCIDENTE, 0) DURATA_I,\n" + "    NVL( i.CNT_INCIDENTE, 0) CNT_I, \n" + "    NVL( i.CM, 0) CM_I,\n" + "    NVL( i.CD, 0) CD_I,\n" + "    NVL( i.CEXP, 0) CEXP_I,\n" + "    NVL( i.CT, 0) CT_I,\n" + "    NVL( i.EN, 0) EN_I,\n" + "    NVL( e.DURATA_ECHIPAMENTE, 0) DURATA_ECHIPAMENTE,\n" + "    NVL( e.CNT_ECHIPAMENTE, 0) CNT_E,\n" + "    NVL( e.CM, 0) CM_E,\n" + "    NVL( e.CD, 0) CD_E,\n" + "    NVL( e.CEXP, 0) CEXP_E,\n" + "    NVL( e.CT, 0) CT_E\n" + "from lf \n" + "    left join (\n" + "        select \n" + "            /* STATIE_ID */ ").append(tip).append(", \n").append("            COUNT(*) CNT_INCIDENTE,\n").append("            SUM( DURATA_INCIDENT) DURATA_INCIDENTE,\n").append("            SUM( ENERGIE_NELIVR) EN, \n").append("            SUM( CHELT_MENT) CM, \n").append("            SUM( CHELT_DAUNE) CD, \n").append("            SUM( CHELT_EXPLOATARE) CEXP, \n").append("            SUM( CHELT_MENT + CHELT_DAUNE + CHELT_EXPLOATARE) CT\n").append("        from incidente \n").append("        where 0=0  \n").append(filterIncidente.toString()).append('\n').append("        group by /* STATIE_ID */ ").append(tip).append(" \n").append("    )i on (lf.COD_LF = /* i.STATIE_ID */ i.").append(tip).append(" ) \n").append("    left join (\n").append("        select \n").append("            /* STATIE_ID */").append(tip).append(", \n").append("            COUNT(*) CNT_ECHIPAMENTE,\n").append("            SUM( DIAF_ORE * 60 + DIAF_MIN) DURATA_ECHIPAMENTE,\n").append("            SUM( CHELT_MENT) CM, \n").append("            SUM( CHELT_DAUNE) CD, \n").append("            SUM( CHELT_EXPLOATARE) CEXP, \n").append("            SUM( CHELT_MENT + CHELT_DAUNE + CHELT_EXPLOATARE) CT\n").append("        from echipamente \n").append("        WHERE 0=0 \n").append(filterEchipamente.toString()).append('\n').append("        group by /* STATIE_ID */ ").append(tip).append(" \n").append("    ) e on (lf.COD_LF = /* e.STATIE_ID*/ e.").append(tip).append(")\n").append("    INNER JOIN CATEGORIES c ON (lf.CE=c.COD_SAP)\n").append("    INNER JOIN CATEGORIES s ON (c.ID_PARENT=s.ID)\n").append("    INNER JOIN CATEGORIES f ON (s.ID_PARENT=f.ID)\n").append(" WHERE 0=0 ").append(tipObCondition).append(" AND NVL( i.CT, 0) + NVL( e.CT, 0) > 0\n");

    sql.append("ORDER BY ").append(sd.getColumnName()).append(' ').append( sd.getDirection());



    final StringBuffer buffer = new StringBuffer();
    buffer.append( "SELECT * FROM (SELECT a.*, ROWNUM AS rn FROM (\n");
    buffer.append( sql );
    buffer.append( ") a WHERE ROWNUM <= ").append( pd.getQueryEndIndex()).append( " ) WHERE ").append(pd.getStartIndex()).append( " <= rn ");

    //calculare totaluri
    final StringBuffer totalsSql = new StringBuffer("SELECT sum(t.CNT_I) CNT_I, sum(t.CNT_E) CNT_E, sum(t.CNT_T) CNT_T, sum( t.DURATA_T) DURATA_T, sum( EN_I) EN_I, sum(t.CM_T) CM_T, sum(t.CD_T) CD_T, sum(t.CEXP_T) CEXP_T, sum(t.CT_T) CT_T FROM (").append( sql).append(")t ");

    final Totaluri totaluri = (Totaluri) AccessDB.executeSQL( new AccessDB("Raport Top 10 FI FE totaluri") {
        protected Object doWork() throws SQLException, DatabaseException {
            final Totaluri r = new Totaluri();

            createStatementFromString( totalsSql.toString());
            getResultSetFromQuery();

            if (resultSet.next()) {
                final int k = 1;
                r.countIncidente = resultSet.getLong( "CNT_I");
                r.countEchipamente = resultSet.getLong( "CNT_E");
                r.countEvenimente = resultSet.getLong( "CNT_T");
                r.durataEvenimente = resultSet.getLong( "DURATA_T");
                r.energieNelivrata = resultSet.getLong( "EN_I");
                r.costMent = resultSet.getDouble(  "CM_T");
                r.costDaune = resultSet.getDouble( "CD_T");
                r.costExpl = resultSet.getDouble( "CEXP_T");
                r.costTotal = resultSet.getDouble( "CT_T");
            }

            return r;
        }
    });

    final List result = (List) AccessDB.executeSQL( new AccessDB("Raport Top 10 FI FE") {
        protected Object doWork() throws SQLException, DatabaseException {
            final List list = new LinkedList();

            createStatementFromString( buffer.toString());
            getResultSetFromQuery();

            while (resultSet.next()) {
                final RaportRow row = new RaportRow();
                row.idLf = resultSet.getLong( "ID_LF");
                row.codLf = resultSet.getString("COD_LF");
                row.denLf = resultSet.getString("DESC_LF");

                row.denSucursala = resultSet.getString( "SUCURSALA");
                row.denCentru = resultSet.getString("CENTRU");

                row.cntEvenimente = resultSet.getLong( "CNT_T");
                row.durataEvenimente = resultSet.getLong( "DURATA_T");
                row.energieNelivrata = resultSet.getDouble("EN_I");

                row.cntIncidente = resultSet.getLong( "CNT_I");
                row.cntEchipamente = resultSet.getLong( "CNT_E");

                row.cheltTotalMent = resultSet.getLong( "CM_T");
                row.cheltTotalDaune = resultSet.getLong( "CD_T");
                row.cheltTotalExpl = resultSet.getLong( "CEXP_T");
                row.cheltTotalEvenimente = resultSet.getLong( "CT_T");

                list.add( row);
            }

            return list;
        }
    });

    final Integer cnt = (Integer) AccessDB.executeSQL( new AccessDB("cnt") {
        protected Object doWork() throws SQLException, DatabaseException {
            createStatementFromString("SELECT count(*) FROM (" + sql.toString() + " ) ");
            getResultSetFromQuery();

            Integer i = new Integer(0);
            while (resultSet.next()) {
                i = new Integer( resultSet.getInt( 1));
            }
            return i;
        }
    });

    pd.setResultRowCount( result.size());
    pd.setTotalRowsCount( cnt.intValue());


    session.setAttribute("raportTop10_FI_FE_FilterIncidente", filterIncidente);
    session.setAttribute("raportTop10_FI_FE_FilterEchipamente", filterEchipamente);
%>



<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> Raport top 10 (FI + FE)
        </TD>
    </TR>
</TABLE>


<form name="zaforma" action="" method="post" onsubmit="this.<%=PaginationConstants.JSP_RESET%>.value='true';">
    <%=SortController.initSort( sd)%>

    <table width="100%">
        <tr>
            <td>
                Tip:
                <select name="tip">
                <option value="STATIE_COD" <%="STATIE_COD".equals( tip) ? "selected" : ""%> >Statii</option>
                <option value="LINIE_COD" <%="LINIE_COD".equals( tip) ? "selected" : ""%> >Linii</option>
                <option value="PAPT_COD" <%="PAPT_COD".equals( tip) ? "selected" : ""%> >PA/PT</option>
                </select>
            </td>
            <td align="right">
                <%if( user.getIeLevel() < RoleConstants.NIVEL_CENTRU){ %>
                    <A href="#" onClick="openCheckCategorii(); return false" class="link"><IMG alt="Click pentru a selecta mai multe sucursale/C.E." border=0 width=12 height=13 hspace=3 src="<%= AppConstants.WEB_RESOURCE_PATH + "/images/icon_mini_search.gif" %>"></A>
                    <script type="text/javascript">
                        var checkCategoriiWindow = null;
                        function openCheckCategorii(){
                            if( checkCategoriiWindow) checkCategoriiWindow.close();
                            checkCategoriiWindow = window.open('<%=AppConstants.APP_NAME%>?action=checkCategorie','checkCategorie', 'width=800 height=620, scrollbars=yes,status=yes,resizable=yes,top=10,left=50,dependent=yes,alwaysRaised=yes');
                        }
                    </script>
                <% } %>
                <span title="Perioada producerii deranjamentelor" style="font-weight:bold;">Perioada:</span>
                <input type="text" id="data_start" name="data_start" size="8" value="<%=AppConstants.format( dataStart)%>" /> <a href="#" id="trigger_data_start" ><img src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0" alt="Apasa pt. a selecta data."></a>&nbsp;&nbsp;-&nbsp;&nbsp;
                <input type="text" id="data_stop" name="data_stop" size="8" value="<%=AppConstants.format( dataStop)%>" /> <a href="#" id="trigger_data_stop" ><img src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0" alt="Apasa pt. a selecta data."></a>

                &nbsp;&nbsp;
                <input type="submit" value="Ruleaza"/>
            </td>
        </tr>

        <% if( checkData.someDataChecked()){  %>
            <tr>
                <td>
                    <%
                        final StringBuffer strCategorii = new StringBuffer("");
                        final long[] idCentre = checkData.getIdCentre();
                        final Set sucursaleSelectate = new HashSet();
                        final Set filialeSelectate = new HashSet();
                        for (int i = 0; i < idCentre.length; i++) {
                            final long id = idCentre[i];
                            final Category c = CategoryAccessDB.getById(id);
                            if (c != null) {
                                final Category s = CategoryAccessDB.getById(c.getId_parent());
                                if (s != null) {
                                    final Category f = CategoryAccessDB.getById(s.getId_parent());
                                    if (f != null) {
                                        if (strCategorii.length() > 0) strCategorii.append("<br>");
                                        strCategorii.append(f.getName()).append(", ").append(s.getName()).append(", ").append(c.getName());

                                        sucursaleSelectate.add(new Long(s.getId()));
                                        filialeSelectate.add(new Long(f.getId()));
                                    }
                                }
                            }
                        }

                        final long[] idSucursale = checkData.getIdSucursale();
                        for (int i = 0; i < idSucursale.length; i++) {
                            final long id = idSucursale[i];
                            if( !sucursaleSelectate.contains( new Long( id))){
                                final Category s = CategoryAccessDB.getById( id );
                                if( s != null){
                                    final Category f = CategoryAccessDB.getById( s.getId_parent());
                                    if( f != null){
                                        if( strCategorii.length() > 0) strCategorii.append("<br>");
                                        strCategorii.append(f.getName()).append(", ").append(s.getName());
                                    }
                                }
                            }
                        }

                        final long[] idFiliale = checkData.getIdFiliale();
                        for (int i = 0; i < idFiliale.length; i++) {
                            final long id = idFiliale[i];
                            if( !filialeSelectate.contains( new Long( id))){
                                final Category f = CategoryAccessDB.getById( id);
                                if( f != null){
                                    if( strCategorii.length() > 0) strCategorii.append("<br>");
                                    strCategorii.append(f.getName());
                                }
                            }
                        }
                    %>

                    <br/>
                    <%=strCategorii%>
                <td>
            </tr>
        <% } %>
    </table>

    <TABLE id="table" border=1 cellPadding=2 cellSpacing=1 width="100%" class="gSAPTHEAD" style="BACKGROUND-COLOR: white; margin-top:5px">
        <TR noSelect="true">
            <TH rowspan="2" class="gsapthead" noWrap width="10px">#</TH>
            <TH rowspan="2" class="gsapthead" noWrap >Instalatie</TH>
            <TH rowspan="2" class="gsapthead" noWrap width="1%">Sucursala</TH>
            <TH rowspan="2" class="gsapthead" noWrap width="2%">CE</TH>
            <TH class="gsapthead" noWrap width="100px" style="text-decoration:underline" colspan="3"> Nr. Evenimente </TH>
            <TH rowspan="2" class="gsapthead" noWrap width="100px" style="text-decoration:underline">
                <nobr> <%=SortController.printSortableColumn( "Durata Evenimente", "DURATA_T", sd)%></nobr></TH>
            <TH             class="gsapthead" noWrap style="text-decoration:underline"> <%=SortController.printSortableColumn( "Energie nelivr.", "EN_I", sd)%></TH>
            <TH colspan="4" class="gsapthead" noWrap >Cheltuieli (ron)</TH>
        </TR>
        <tr noSelect="true">
            <TH class="gsapthead" noWrap align="center" style="text-decoration:underline"> <%=SortController.printSortableColumn( "FI", "CNT_I", sd)%></TH>
            <TH class="gsapthead" noWrap align="center" style="text-decoration:underline"> <%=SortController.printSortableColumn( "FE", "CNT_E", sd)%></TH>
            <TH class="gsapthead" noWrap align="center" style="text-decoration:underline"> <%=SortController.printSortableColumn( "Total", "CNT_T", sd)%></TH>
            <TH class="gsapthead" noWrap align="center">(kWh)</TH>
            <TH class="gsapthead" noWrap align="center" style="text-decoration:underline"> <%=SortController.printSortableColumn( "Ment.", "CM_T", sd)%></TH>
            <TH class="gsapthead" noWrap align="center" style="text-decoration:underline"> <%=SortController.printSortableColumn( "Daune", "CD_T", sd)%></TH>
            <TH class="gsapthead" noWrap align="center" style="text-decoration:underline"> <%=SortController.printSortableColumn( "Expl.", "CEXP_T", sd)%></TH>
            <TH class="gsapthead" noWrap align="center" style="text-decoration:underline"> <%=SortController.printSortableColumn( "Total.", "CT_T", sd)%></TH>
        </tr>
        <% if( result.size() == 0){ %>
            <tr>
                <td colspan="12">Nu exista fise de incident sau echipament conform filtrului specificat.</td>
            </tr>
        <% }else { %> <% for (int i = 0; i < result.size(); i++) {
            final RaportRow row = (RaportRow) result.get(i);
        %>

        <tr>
            <td align="center"><%=i+1%></td>
            <td>
                <label title=""><nobr><%=row.denLf%></nobr></label>
            </td>
            <td nowrap>
                <label title="Sucursala instalatie">
                    <%=row.denSucursala%>
                </label>
            </td>
            <td nowrap>
                <label title="Centru Exploatare instalatie">
                    <%=row.denCentru%>
                </label>
            </td>
            <td align="center">
                <a class="link" href="javascript: openIncidenteByTipInstalatie( '<%=tip%>', -1, '<%=row.codLf%>')" title="Incidente">
                    <%=row.cntIncidente%>
                </a>
            </td>
            <td align="center">
                <a class="link" href="javascript: openEchipamenteByTipInstalatie( '<%=tip%>', -1, '<%=row.codLf%>')" title="Echipamente">
                    <%=row.cntEchipamente%>
                </a>
            </td>
            <td align="center">
                <%=row.cntEvenimente%>

            </td>
            <td align="right">
                <%=(row.durataEvenimente)/60%>h <%=(row.durataEvenimente)%60%>'
            </td>
            <td align="right"> <%=row.energieNelivrata%> </td>
            <td align="right"> <%=row.cheltTotalMent%> </td>
            <td align="right"> <%=row.cheltTotalDaune%> </td>
            <td align="right"> <%=row.cheltTotalExpl%> </td>
            <td align="right"> <%=row.cheltTotalEvenimente%> </td>
        </tr>

        <% } %>
        <tr noSelect="true" class="paginationRow">
            <td colspan="4" align="left">
                <%=PaginationController.printPaginationData(pd)%>
            </td>
            <td align="center" class="totalCell"><%if( totaluri == null){%> &nbsp; <%}else{%> <%=totaluri.countIncidente%> <%}%></td>
            <td align="center" class="totalCell"><%if( totaluri == null){%> &nbsp; <%}else{%> <%=totaluri.countEchipamente%> <%}%></td>
            <td align="center" class="totalCell"><%if( totaluri == null){%> &nbsp; <%}else{%> <%=totaluri.countEvenimente%> <%}%></td>
            <td align="right" class="totalCell"><%if( totaluri == null){%> &nbsp; <%}else{%> <%=totaluri.durataEvenimente /60%>h <%=totaluri.durataEvenimente %60%>'<%}%></td>
            <td align="right" class="totalCell"><%if( totaluri == null){%> &nbsp; <%}else{%> <%=AppConstants.format2(totaluri.energieNelivrata)%> <%}%></td>
            <td align="right" class="totalCell"><%if( totaluri == null){%> &nbsp; <%}else{%> <%=AppConstants.format2(totaluri.costMent)%> <%}%></td>
            <td align="right" class="totalCell"><%if( totaluri == null){%> &nbsp; <%}else{%> <%=AppConstants.format2(totaluri.costDaune)%> <%}%></td>
            <td align="right" class="totalCell"><%if( totaluri == null){%> &nbsp; <%}else{%> <%=AppConstants.format2(totaluri.costExpl)%> <%}%></td>
            <td align="right" class="totalCell"><%if( totaluri == null){%> &nbsp; <%}else{%> <%=AppConstants.format02(totaluri.costTotal)%> <%}%></td>
        </tr>
        <% } %>
    </TABLE>
</form>


<script type="text/javascript">
    var table = new Table('table', "table");

    Calendar.setup({
        inputField  : "data_start",         // ID of the input field
        ifFormat    : "%d.%m.%Y",    // the date format
        button      : "trigger_data_start"       // ID of the button
    });

    Calendar.setup({
        inputField  : "data_stop",         // ID of the input field
        ifFormat    : "%d.%m.%Y",    // the date format
        button      : "trigger_data_stop"       // ID of the button
    });

    function categoriesChecked(){
        document.zaforma.submit();
    }

    var incidenteWindow = null;
    function openIncidenteByTipInstalatie( tipInstalatie, idInstalatie, codInstalatie){
        if( incidenteWindow != null) incidenteWindow.close();
        incidenteWindow = window.open( '<%=AppConstants.APP_NAME%>?action=showIncidenteFromRaportTop10_FI_FE&tip='+tipInstalatie + "&idInstalatie=" + idInstalatie + '&codInstalatie=' + codInstalatie,
                'incidenteRaport', 'top=50,left=50,width=850, height=550, status=yes,resizable=yes,dependent=yes,alwaysRaised=yes, scrollbars=yes');
    }

    var echipamenteWindow = null;
    function openEchipamenteByTipInstalatie( tipInstalatie, idInstalatie, codInstalatie){
        if( echipamenteWindow != null) echipamenteWindow.close();
        echipamenteWindow = window.open( '<%=AppConstants.APP_NAME%>?action=showEchipamenteFromRaportTop10_FI_FE&tip='+tipInstalatie + "&idInstalatie=" + idInstalatie +'&codInstalatie=' + codInstalatie,
                'echipamenteRaport', 'top=50,left=50,width=850, height=550, status=yes,resizable=yes,dependent=yes,alwaysRaised=yes, scrollbars=yes');
    }

</script>

<style type="text/css">
    .totalCell{
        font-weight: bold;
    }
</style>
