<%@ page import="ro.emid.common.db.framework.ReportStatement" %>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="java.sql.Date" %>
<%@ page import="java.util.List" %>
<%@ page import="ro.emid.common.types.Category" %>
<%@ page import="ro.emid.callcenter.CallcenterSessionUtils" %>
<%@ page import="ro.emid.common.types.Deranjament" %>
<%@ page import="ro.emid.common.constants.RoleConstants" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>

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

<%!
    private int tip = -1;
    private static final int STRICT_CATEGORIE  = 1;
    private static final int ALL_SUBCATEGORIES = 2;

    private static final int NIVEL_ELECTRICA = 1;
    private static final int NIVEL_FILIALA = 2;
    private static final int NIVEL_SUCURSALA = 3;
    private static final int NIVEL_CENTRU = 4;


    private static final int COL_CONS_CASNICI = 4;
    private static final int COL_CONS_ALTII   = 5;
    private static final int COL_CONS_TOTAL   = 6;

    private static final int COL_ENC_CASNICI = 4;
    private static final int COL_ENC_ALTII   = 5;
%>


<% final long t1 = System.currentTimeMillis(); %>
<%
    long filialaId = CallcenterSessionUtils.getFilialaId(session);
    long sucursalaId = CallcenterSessionUtils.getSucursalaId(session);
    long centruId = CallcenterSessionUtils.getCentruId(session);

    if (0 < ObjectUtils.getLongValue(request.getParameter("filiala"), -2)) {
        filialaId = ObjectUtils.getLongValue(request.getParameter("filiala"));
    }

    if (0 < ObjectUtils.getLongValue(request.getParameter("sucursala"), -2)) {
        sucursalaId = ObjectUtils.getLongValue(request.getParameter("sucursala"));
    }

    if (0 < ObjectUtils.getLongValue(request.getParameter("centruId"), -2)) {
        centruId = ObjectUtils.getLongValue(request.getParameter("centruId"));
    }

    Category filialaRaport = CategoryAccessDB.getById(filialaId);
    if (filialaRaport == null) filialaRaport = new Category();

    Category sucursalaRaport = CategoryAccessDB.getById(sucursalaId);
    if (sucursalaRaport == null) sucursalaRaport = new Category();

    Category centruRaport = CategoryAccessDB.getById(centruId);
    if (centruRaport == null) centruRaport = new Category();


    Date dataStart = ObjectUtils.getDateValue(request.getParameter("data_start"), AppConstants.FORMAT_DATA);
    Date dataStop  = ObjectUtils.getDateValue(request.getParameter("data_stop"), AppConstants.FORMAT_DATA);

    if( dataStart == null) dataStart = new Date( System.currentTimeMillis());
    if( dataStop  == null) dataStop  = new Date( System.currentTimeMillis());

    final String value_data_start = AppConstants.format(dataStart);
    final String value_data_stop  = AppConstants.format(dataStop);


    // 1 pt raport strict pe "Categoria" selectata
    // 2 pt raport pt toate subCategoriile din categoria selectata 
    tip = ObjectUtils.getIntValue( request.getParameter("tip"), 1);
%>

<%
    Category categoryRaport = null;
    String condition = "";
    String columnTitle = "";
    int nivel = -1;
    if (centruRaport.getId() > 0) {
        condition = " AND ID = " + centruRaport.getId();
        categoryRaport = centruRaport;
        nivel = NIVEL_CENTRU;
    } else if (sucursalaRaport.getId() > 0) {
        condition = " AND id_parent = " + sucursalaRaport.getId();
        categoryRaport = sucursalaRaport;
        nivel = NIVEL_SUCURSALA;
    } else if (filialaRaport.getId() > 0) {
        condition = " AND id_parent = " + filialaRaport.getId();
        columnTitle = "SDFEE";
        categoryRaport = filialaRaport;
        nivel = NIVEL_FILIALA;
    } else {
        condition = " AND id_parent = -1";
        columnTitle = "FDFEE";
        categoryRaport = new Category();
        categoryRaport.setName("ELECTRICA SA");
        nivel = NIVEL_ELECTRICA;
    }

    Category[] sucursale_sectii = new Category[0];
    if (tip == STRICT_CATEGORIE) {
        sucursale_sectii = new Category[1];
        sucursale_sectii[0] = categoryRaport;
    } else if (tip == ALL_SUBCATEGORIES) {
        sucursale_sectii = CategoryAccessDB.getAllCategories(condition);
    }

    final ReportStatement raport1 = new ReportStatement(
            " SELECT FILIALA_ID, SUCURSALA_ID, SECTIE_ID, TIP_DERANJAMENT, MEDIUL, count(*) FROM deranjamente "
    ).addStringCriteria(" AND APARTENENTA_INST = " + Deranjament.APARTINE_ELECTRICA )
     .setGroupStatement(" GROUP BY FILIALA_ID, SUCURSALA_ID, SECTIE_ID, TIP_DERANJAMENT, MEDIUL ");

    final StringBuffer buffer = new StringBuffer();
    final StringBuffer groupStatement = new StringBuffer();
    groupStatement.append(" GROUP BY FILIALA_ID, SUCURSALA_ID, SECTIE_ID, ").append(
            "CASE ").append(
            "     WHEN (NR_CASE+NR_AP)   > 0 THEN 1 ").append(
            "     WHEN (NR_MICI+NR_MARI) > 0 THEN 2 ").append(
            "END, ").append(
            "MEDIUL ");


    buffer.append(" SELECT FILIALA_ID, SUCURSALA_ID, SECTIE_ID,  ").append(
            "CASE " ).append(
            "     WHEN (NR_CASE+NR_AP)   > 0 THEN 1 " ).append(
            "     WHEN (NR_MICI+NR_MARI) > 0 THEN 2 " ).append(
            " END AS TIP_DERANJAMENT, " ).append(
            " MEDIUL, count(*) " ).append(
            " FROM deranjamente ");

    final ReportStatement raport2 = new ReportStatement(
            buffer.toString()
    ).addStringCriteria(" AND APARTENENTA_INST = " + Deranjament.APARTINE_ELECTRICA )
     .setGroupStatement(
             groupStatement.toString()
     );


    buffer.delete(0, buffer.length());
    groupStatement.delete(0, groupStatement.length());

    buffer.append(" SELECT FILIALA_ID, SUCURSALA_ID, SECTIE_ID,  " ).append(
            "CASE " ).append(
            "     WHEN (NR_CASE+NR_AP)   > 0 THEN 1 " ).append(
            "     WHEN (NR_MICI+NR_MARI) > 0 THEN 2 " ).append(
            " END AS TIP_DERANJAMENT, " ).append(
            " MEDIUL, count(*) " ).append(
            " FROM deranjamente ");

    groupStatement.append(" GROUP BY FILIALA_ID, SUCURSALA_ID, SECTIE_ID, ").append(
            "CASE " ).append(
            "     WHEN (NR_CASE+NR_AP)   > 0 THEN 1 " ).append(
            "     WHEN (NR_MICI+NR_MARI) > 0 THEN 2 " ).append(
            "END, " ).append(
            "MEDIUL ");

    final ReportStatement raport3 = new ReportStatement(
        buffer.toString()
    ).addStringCriteria(" AND APARTENENTA_INST != " + Deranjament.APARTINE_ELECTRICA )
     .setGroupStatement(
             groupStatement.toString()
     );

    final ReportStatement raport4 = new ReportStatement(
            " SELECT FILIALA_ID, SUCURSALA_ID, SECTIE_ID, 1 AS TIP_DERANJAMENT, MEDIUL, count(*) FROM deranjamente "
    ).addStringCriteria(" AND CAT_INSTALATII IN (" + Deranjament.INDEX_ILUMINAT_PUBLIC_STRADAL_LEAJT + ',' + Deranjament.INDEX_ILUMINAT_PUBLIC_STRADAL_LESJT + ") ")
     .setGroupStatement(" GROUP BY FILIALA_ID, SUCURSALA_ID, SECTIE_ID, 1, MEDIUL ");


    final ReportStatement raport5 = new ReportStatement(
            " SELECT FILIALA_ID, SUCURSALA_ID, SECTIE_ID, 1 AS TIP_DERANJAMENT, MEDIUL, count(*) FROM deranjamente "
    ).addStringCriteria(" AND floor((data_rezolvare - data_anuntare)*24) < 12 ")
     .setGroupStatement(" GROUP BY FILIALA_ID, SUCURSALA_ID, SECTIE_ID, 1, MEDIUL ");


    final ReportStatement raport6 = new ReportStatement(
            " SELECT FILIALA_ID, SUCURSALA_ID, SECTIE_ID, 1 AS TIP_DERANJAMENT, MEDIUL, count(*) FROM deranjamente "
    ).addStringCriteria(" AND floor((data_rezolvare - data_anuntare)*24) < 24 ")
     .setGroupStatement(" GROUP BY FILIALA_ID, SUCURSALA_ID, SECTIE_ID, 1, MEDIUL ");


    final ReportStatement raport7 = new ReportStatement(
            " SELECT FILIALA_ID, SUCURSALA_ID, SECTIE_ID, MEDIUL, SUM(NR_CASE + NR_AP) AS S_C, SUM(NR_MICI + NR_MARI) AS S_A, SUM(NR_CASE+NR_AP+NR_MICI+NR_MARI) AS S_T FROM deranjamente "
    ).setGroupStatement( " GROUP BY FILIALA_ID, SUCURSALA_ID, SECTIE_ID, MEDIUL ");

    buffer.delete(0, buffer.length());
    buffer.append(" SELECT FILIALA_ID, SUCURSALA_ID, SECTIE_ID, MEDIUL, ").append(
            "SUM( (NR_CASE + NR_AP)*(DATA_REZOLVARE - DATA_ANUNTARE)*(24*60) ) AS S_C, " ).append(
            "SUM( (NR_MICI + NR_MARI)*(DATA_REZOLVARE - DATA_ANUNTARE)*(24*60) ) AS S_A, " ).append(
            "SUM( (NR_CASE + NR_AP + NR_MICI + NR_MARI)*(DATA_REZOLVARE - DATA_ANUNTARE)*(24*60) ) AS S_T " ).append(
            " FROM deranjamente ");
    final ReportStatement raport8 = new ReportStatement(
        buffer.toString()
    ).setGroupStatement( " GROUP BY FILIALA_ID, SUCURSALA_ID, SECTIE_ID, MEDIUL ");

    buffer.delete(0, buffer.length());
    buffer.append(" SELECT FILIALA_ID, SUCURSALA_ID, SECTIE_ID, MEDIUL, ").append(
            "SUM( CASE WHEN (NR_CASE+NR_AP) > 0 THEN (DATA_REZOLVARE - DATA_ANUNTARE)*(24*60) ELSE 0 END ) AS S_C, " ).append(
            "SUM( CASE WHEN (NR_MICI+NR_MARI) > 0 THEN (DATA_REZOLVARE - DATA_ANUNTARE)*(24*60) ELSE 0 END ) AS S_A, " ).append(
            "SUM( CASE WHEN (NR_CASE+NR_AP+NR_MICI+NR_MARI) > 0 THEN (DATA_REZOLVARE - DATA_ANUNTARE)*(24*60) ELSE 0 END ) AS S_T " ).append(
            " FROM deranjamente ");
    final ReportStatement raport10 = new ReportStatement(
            buffer.toString()
    ).addStringCriteria(" AND DATA_REZOLVARE IS NOT NULL AND DATA_ANUNTARE IS NOT NULL ")
    .setGroupStatement( " GROUP BY FILIALA_ID, SUCURSALA_ID, SECTIE_ID, MEDIUL ");

    final ReportStatement raport11 = new ReportStatement(" SELECT MEDIUL, AVG (DATA_SOSIRE_ECHIPA - DATA_ANUNTARE)*(24*60) AS DURATA_MEDIE_IN_MINUTE FROM DERANJAMENTE ")
            .setGroupStatement( " GROUP BY MEDIUL")
            .addStringCriteria(" AND DATA_SOSIRE_ECHIPA IS NOT NULL AND DATA_ANUNTARE IS NOT NULL ");

    final ReportStatement raport12 = new ReportStatement("SELECT MEDIUL, AVG (DATA_REZOLVARE - DATA_ANUNTARE)*(24*60) AS DURATA_MEDIE_IN_MINUTE FROM DERANJAMENTE ")
            .setGroupStatement( " GROUP BY MEDIUL")
            .addStringCriteria(" AND DATA_REZOLVARE IS NOT NULL AND DATA_ANUNTARE IS NOT NULL ");

    final ReportStatement raport13 = new ReportStatement(
            " SELECT FILIALA_ID, SUCURSALA_ID, SECTIE_ID, MEDIUL, SUM(ENC_CASNICI) AS S_C, SUM(ENC_MICI + ENC_MARI) AS S_A, SUM(ENC_CASNICI + ENC_MICI + ENC_MARI) AS S_T FROM deranjamente "
    ).setGroupStatement( " GROUP BY FILIALA_ID, SUCURSALA_ID, SECTIE_ID, MEDIUL ");

    ReportStatement report = null;
%>

<%!
    private void setLocation(final ReportStatement report, final Category currentCategory, final Category centruRaport, final Category sucursalaRaport, final Category filialaRaport) {
        if (tip == STRICT_CATEGORIE) {
            if (centruRaport.getId() > 0) {
                report.addOrSetFilter("SECTIE_ID", "=", new Long(currentCategory.getId()));
            } else if (sucursalaRaport.getId() > 0) {
                report.addOrSetFilter("SUCURSALA_ID", "=", new Long(currentCategory.getId()));
            } else if (filialaRaport.getId() > 0) {
                report.addOrSetFilter("FILIALA_ID", "=", new Long(currentCategory.getId()));
            } else {
            }
        } else if (tip == ALL_SUBCATEGORIES) {
            if (sucursalaRaport.getId() > 0) {
                report.addOrSetFilter("SECTIE_ID", "=", new Long(currentCategory.getId()));
            } else if (filialaRaport.getId() > 0) {
                report.addOrSetFilter("SUCURSALA_ID", "=", new Long(currentCategory.getId()));
            } else {
                report.addOrSetFilter("FILIALA_ID", "=", new Long(currentCategory.getId()));
            }
        }
    }

    private void setLocation2(final ReportStatement report, final Category centruRaport, final Category sucursalaRaport, final Category filialaRaport) {
        if (centruRaport.getId() > 0) {
            report.addOrSetFilter("SECTIE_ID", "=", new Long( centruRaport.getId()));
        } else if (sucursalaRaport.getId() > 0) {
            report.addOrSetFilter("SUCURSALA_ID", "=", new Long( sucursalaRaport.getId()));
        } else if (filialaRaport.getId() > 0) {
            report.addOrSetFilter("FILIALA_ID", "=", new Long( filialaRaport.getId()));
        } else {
            
        }
    }

    private long getSumValues(final List matrix, final Category currentCategory, final int tipDeranjament1, final int tipDeranjament2 , final int mediul, final int nivel) {
        long result = 0;

        int locationIndex = -1;

        if (tip == STRICT_CATEGORIE) {
            switch ( nivel){
                case NIVEL_ELECTRICA: locationIndex = -1; break;
                case NIVEL_FILIALA: locationIndex = 0; break;
                case NIVEL_SUCURSALA: locationIndex = 1; break;
                case NIVEL_CENTRU: locationIndex = 2; break;
                default: throw new RuntimeException("Nivel necunoscut : " + nivel);
            }
        } else if (tip == ALL_SUBCATEGORIES) {
            switch ( nivel){
                case NIVEL_ELECTRICA: locationIndex = 0; break;
                case NIVEL_FILIALA: locationIndex = 1; break;
                case NIVEL_SUCURSALA: locationIndex = 2; break;
                case NIVEL_CENTRU: locationIndex = 2; break;
                default: throw new RuntimeException("Nivel necunoscut : " + nivel);
            }
        }

        for (int i = 0; i < matrix.size(); i++) {
            final Object[] arr = (Object[]) matrix.get(i);

            if( locationIndex >= 0){
                final long idLocatie = ObjectUtils.getLongValue( arr[locationIndex], -99);
                final long td = ObjectUtils.getLongValue( arr[3], -99);
                final long m = ObjectUtils.getLongValue( arr[4], -99);
                final long v = ObjectUtils.getLongValue( arr[5], -99);

                if((currentCategory.getId() == idLocatie) && (td == tipDeranjament1 || td == tipDeranjament2) && (mediul == m)){
                    result += v;
                }
            }else{

            }
        }
        return result;
    }

    /**
        Matrix de forma: filiala_id, sucursala_id, centru_id, mediu, valoare, valoare, valoare
     */
    private double getSumValues2(final List matrix, final Category currentCategory, final int mediul, final int nivel, final int column1, final int column2) {
        double result = 0;

        int locationIndex = -1;

        if (tip == STRICT_CATEGORIE) {
            switch ( nivel){
                case NIVEL_ELECTRICA: locationIndex = -1; break;
                case NIVEL_FILIALA: locationIndex = 0; break;
                case NIVEL_SUCURSALA: locationIndex = 1; break;
                case NIVEL_CENTRU: locationIndex = 2; break;
                default: throw new RuntimeException("Nivel necunoscut : " + nivel);
            }
        } else if (tip == ALL_SUBCATEGORIES) {
            switch ( nivel){
                case NIVEL_ELECTRICA: locationIndex = 0; break;
                case NIVEL_FILIALA: locationIndex = 1; break;
                case NIVEL_SUCURSALA: locationIndex = 2; break;
                case NIVEL_CENTRU: locationIndex = 2; break;
                default: throw new RuntimeException("Nivel necunoscut : " + nivel);
            }
        }

        for (int i = 0; i < matrix.size(); i++) {
            final Object[] arr = (Object[]) matrix.get(i);

            if( locationIndex >= 0){
                final long idLocatie = ObjectUtils.getLongValue( arr[locationIndex], -99);
                final long m = ObjectUtils.getLongValue( arr[3], -99);

                if((currentCategory.getId() == idLocatie) && (mediul == m)){
                    if( column1 != -1){
                        result += ObjectUtils.getDoubleValue( arr[column1], 0);
                    }

                    if( column2 != -1){
                        result += ObjectUtils.getDoubleValue(arr[column2], 0);
                    }
                }
            }else{

            }
        }
        return result;
    }

    private double getValue( final List matrix, final int mediu){
        double result = 0;
        try {
            for (int i = 0; i < matrix.size(); i++) {
                final Object[] arr = (Object[]) matrix.get(i);

                final long _mediu = ro.emid.common.utils.Util.getIntValue(arr[0], -1);

                final Object v = arr[ 1];

                if ( mediu == _mediu ){

                    result = Double.valueOf( v.toString()).doubleValue();

                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return result;
    }

    private ReportStatement setDataFilter(final ReportStatement report, final Date dataStart, final Date dataStop) {
        if (dataStart != null) {
            report.addOrSetFilter("data_anuntare", ">=", dataStart);
        }


        if (dataStop != null) {
            report.addOrSetFilter("data_anuntare", "<=", new Date(dataStop.getTime() + 24*60*60*1000));
        }

        return report;
    }
%>

<TABLE border=0 cellPading=0 cellSpacing=0 width="100%">
    <TR>
        <TD>
            <SPAN style="FONT-SIZE: 12px; FONT-WEIGHT: bold">

                <A class="link" href="<%=AppConstants.APP_NAME%>?action=rapoarte">Rapoarte</A> - Situatia sintetica
            </span>
        </TD>
    </TR>
</TABLE>

<center>
    <br />
    <span style="font-size:16px">
        <%if( tip == STRICT_CATEGORIE){%>    Situatia sintetica a deranjamentelor produse <%}else if( tip == ALL_SUBCATEGORIES) {%> Situatia sintetica a deranjamentelor produse individual colectiv <%}%>
    </span>
</center>

<div class="spacer"></div>
<table class="gsaptd"><tr><td>
<form name="zaforma" action="<%=AppConstants.APP_NAME%>" method="post">
    <input type="hidden" name="action" value="raport-deranjamente-situatia-sintetica">
    <input type="hidden" name="tip" value="<%=tip%>">

    Filiala:
    <SELECT name="filiala" onchange="fill_sucursala_select()" class="gSAPSelect" <%=user.getIeLevel() == RoleConstants.NIVEL_FULL ? "" : "disabled"%> >
        <OPTION value="-1">ELECTRICA SA:</OPTION>
        <%  final Category [] filiale = CategoryAccessDB.getAllCategoriesByParentId(-1);
          if (filiale != null) for(int i=0;i<filiale.length;i++) {%>
          <OPTION <%=(filiale[i].getId() == filialaRaport.getId()) ? "selected=\"true\" " : ""%>value="<%=filiale[i].getId()%>"><%=filiale[i].getName()%></OPTION>
        <%} %>
    </SELECT>&nbsp;&nbsp;

    Sucursala:
    <span id="sucursalaDiv">
    <SELECT name="sucursala" class="gSAPSelect" onchange="fill_centru_select()" >
          <option value="-1">Selectati:</option>
    </SELECT></span>&nbsp;&nbsp;

    <span <%if( tip == STRICT_CATEGORIE){%> <%}else if(tip == ALL_SUBCATEGORIES) {%> style="display: none" <%}%> >
        C.E.:
        <span id="centruDiv">
            <SELECT name="centruId" class="gSAPSelect">
             <OPTION value="-1">Selectati:</OPTION>
            </SELECT>
        </span>
    </span>

    &nbsp;&nbsp;<input type="text" id="data_start" name="data_start" size="8" value="<%=value_data_start%>" /> <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> -
    <input type="text" id="data_stop" name="data_stop" size="8" value="<%=value_data_stop%>" /> <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>

        <script type="text/javascript">
              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
                }
              );
        </script>
    <input type="submit" value="Aplica">
</form>

    <script type="text/javascript">
        function fill_sucursala_select(selectedValue, disabled, firstShow){
            resetComboLeaveFirstOption( document.zaforma.sucursala);
            resetComboLeaveFirstOption( document.zaforma.centruId);

            var filialaId = document.zaforma.filiala[ document.zaforma.filiala.selectedIndex].value;
            if( filialaId > -1){
                var params = "parentId="+filialaId + "&selectName=sucursala&disabled=" + disabled + (selectedValue ? "&selectedValue=" + selectedValue : "");
                //alert( params);

                getCategoriesFromServer(params, function(originalRequest){
                    //alert( getResponseMesg (originalRequest.responseText));
                    $( 'sucursalaDiv').innerHTML = getResponseMesg (originalRequest.responseText);

                    document.zaforma.sucursala.onchange=fill_centru_select;

                    if( firstShow){
                        fill_centru_select(<%=centruRaport.getId()%>, <%=user.getIeLevel() == RoleConstants.NIVEL_CENTRU || user.getIeLevel() == RoleConstants.NIVEL_FORMATIE%>);
                    }
                });
            }
        }

        function fill_centru_select(selectedValue, disabled){
            resetComboLeaveFirstOption( document.zaforma.centruId);

            var sucursalaId = document.zaforma.sucursala[ document.zaforma.sucursala.selectedIndex].value;
            if( sucursalaId > -1){
                var params = "parentId="+sucursalaId + "&selectName=centruId&disabled=" + disabled + (selectedValue ? "&selectedValue=" + selectedValue : "");
                //alert( params);

                getCategoriesFromServer(params,function(originalRequest){
                    //alert( getResponseMesg (originalRequest.responseText));
                    $( 'centruDiv').innerHTML = getResponseMesg (originalRequest.responseText);
                });
            }
        }


        fill_sucursala_select(<%=sucursalaRaport.getId()%>, <%=user.getIeLevel() == RoleConstants.NIVEL_SUCURSALA || user.getIeLevel() == RoleConstants.NIVEL_CENTRU || user.getIeLevel() == RoleConstants.NIVEL_FORMATIE%>, true);
   </script>  
</td></tr></table>
<div class="spacer"></div>

<TABLE id="table" border=1 cellPadding=2 cellSpacing=1 
       <%if( tip == STRICT_CATEGORIE){%> width="90%" <%}else{%> width="100%" <%}%>
        class="gSAPTHEAD" style="BACKGROUND-COLOR: white">
    <colgroup>
        <col align="center">
    </colgroup>
    <% if( tip == STRICT_CATEGORIE){ %>
        <tr noSelect="true">
            <th class="gsapthead" rowspan="2" width="5" >Nr.<br>crt.</th>
            <th class="gsapthead" rowspan="2" width="55%">Denumire</th>
            <th class="gsapthead" rowspan="2" >Tip deranj./ Tip cons.</th>
            <th class="gsapthead" colspan="2" >Mediul</th>
            <th class="gsapthead" rowspan="2" >Total</th>
        </tr>
        <tr>
            <th class="gsapthead" >Urban</th>
            <th class="gsapthead" >Rural</th>
        </tr>
    <%}else if( tip == ALL_SUBCATEGORIES) {%>
        <tr noSelect="true">
            <th class="gsapthead" rowspan="3" width="5">Nr.<br>crt.</th>
            <th class="gsapthead" rowspan="3">Denumire</th>
            <th class="gsapthead" rowspan="3">Tip deranj./ Tip cons.</th>
            <% for (int i = 0; i < sucursale_sectii.length; i++) {%>
                <th class="gsapthead" colspan="3"><%=sucursale_sectii[i].getName()%></th>
            <%}%>
        </tr>
        <tr noSelect="true">
            <% for (int i = 0; i < sucursale_sectii.length; i++) {%>
                <th class="gsapthead" colspan="2">Mediul</th>
                <th class="gsapthead" rowspan="2">Total</th>
            <%}%>
        </tr>
        <tr noSelect="true">
            <% for (int i = 0; i < sucursale_sectii.length; i++) {%>
                <th class="gsapthead">Urban</th>
                <th class="gsapthead">Rural</th>
            <%}%>
        </tr>
    <%}%>

    <%
        long totalUrban = 0;
        long totalRural = 0;
        long total = 0;
    %>
    <!-- new raport 1-->
    <%
        setDataFilter(raport1, dataStart, dataStop);
        setLocation2(raport1, centruRaport, sucursalaRaport, filialaRaport);
        List result = raport1.getListOfArrays("Rulez raport1");
    %>
    <tr>
        <td rowspan="3">1</td>
        <td rowspan="3">Numar de deranjamente  avand cauze in instalatiile &quot;<%=categoryRaport.getName()%>&quot;</td>
        <td>Individuale</td>
        <%
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = getSumValues(result, category, Deranjament.TIP_INDIVIDUAL, -1, Deranjament.MEDIU_URBAN, nivel);
                totalRural = getSumValues(result, category, Deranjament.TIP_INDIVIDUAL, -1, Deranjament.MEDIU_RURAL, nivel);
                total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
          <%}%>
    </tr>
    <tr>
        <td>Colective</td>
        <%
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = getSumValues(result, category, Deranjament.TIP_COLECTIV, -1, Deranjament.MEDIU_URBAN, nivel);
                totalRural = getSumValues(result, category, Deranjament.TIP_COLECTIV, -1, Deranjament.MEDIU_RURAL, nivel);
                total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
        <% }%>
    </tr>
    <tr>
        <td>Total</td>
        <%
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = getSumValues(result, category, Deranjament.TIP_INDIVIDUAL, Deranjament.TIP_COLECTIV, Deranjament.MEDIU_URBAN, nivel);
                totalRural = getSumValues(result, category, Deranjament.TIP_INDIVIDUAL, Deranjament.TIP_COLECTIV, Deranjament.MEDIU_RURAL, nivel);
                total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
        <% }%>
    </tr>
    
    <!-- new raport 2 -->
    <%
        setDataFilter(raport2, dataStart, dataStop);
        setLocation2(raport2, centruRaport, sucursalaRaport, filialaRaport);
        result = raport2.getListOfArrays("Rulez raport2");
    %>
    <tr>
        <td rowspan="3">2</td>
        <td rowspan="3">Numar de deranjamente  avand cauze in instalatiile &quot;<%=categoryRaport.getName()%>&quot;</td>
        <td>Casnici</td>
        <%
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = getSumValues(result, category, 1, -100, Deranjament.MEDIU_URBAN, nivel);
                totalRural = getSumValues(result, category, 1, -100, Deranjament.MEDIU_RURAL, nivel);
                total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
          <%}%>
    </tr>
    <tr>
        <td>Altii</td>
        <%
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = getSumValues(result, category, 2, -100, Deranjament.MEDIU_URBAN, nivel);
                totalRural = getSumValues(result, category, 2, -100, Deranjament.MEDIU_RURAL, nivel);
                total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
        <% }%>
    </tr>
    <tr>
        <td>Total</td>
        <%
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = getSumValues(result, category, 1, 2, Deranjament.MEDIU_URBAN, nivel);
                totalRural = getSumValues(result, category, 1, 2, Deranjament.MEDIU_RURAL, nivel);
                total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
        <% }%>
    </tr>

    <!-- new raport 3 -->
    <%
        setDataFilter(raport3, dataStart, dataStop);
        setLocation2(raport3, centruRaport, sucursalaRaport, filialaRaport);
        result = raport3.getListOfArrays("Rulez raport3");
    %>
    <tr>
        <td rowspan="3">3</td>
        <td rowspan="3">Numar de deranjamente avand cauze in afara instalatiile &quot;<%=categoryRaport.getName()%>&quot;</td>
        <td>Casnici</td>
        <%
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = getSumValues(result, category, 1, -1, Deranjament.MEDIU_URBAN, nivel);
                totalRural = getSumValues(result, category, 1, -1, Deranjament.MEDIU_RURAL, nivel);
                total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
          <%}%>
    </tr>
    <tr>
        <td>Altii</td>
        <%
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = getSumValues(result, category, 2, -1, Deranjament.MEDIU_URBAN, nivel);
                totalRural = getSumValues(result, category, 2, -1, Deranjament.MEDIU_RURAL, nivel);
                total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
        <% }%>
    </tr>
    <tr>
        <td>Total</td>
        <%
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = getSumValues(result, category, 1, 2, Deranjament.MEDIU_URBAN, nivel);
                totalRural = getSumValues(result, category, 1, 2, Deranjament.MEDIU_RURAL, nivel);
                total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
        <% }%>
    </tr>

    <!-- new raport 4 -->
    <%
        setDataFilter(raport4, dataStart, dataStop);
        setLocation2(raport4, centruRaport, sucursalaRaport, filialaRaport);
        result = raport4.getListOfArrays("Rulez raport4");
    %>
    <tr>
        <td>4</td>
        <td>Numar de deranjamente in instalatiile de iluminat public stradal</td>
        <td>&nbsp;</td>
        <%
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = getSumValues(result, category, 1, -1, Deranjament.MEDIU_URBAN, nivel);
                totalRural = getSumValues(result, category, 1, -1, Deranjament.MEDIU_RURAL, nivel);
                total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
            <%} %>
    </tr>

    <!--new raport 5 -->
    <tr>
        <td>5</td>
        <td>Numar de deranjamente rezolvate intr-un interval mai mic de 12 ore </td>
        <td>&nbsp;</td>
        <%
            setDataFilter(raport5, dataStart, dataStop);
            setLocation2(raport5, centruRaport, sucursalaRaport, filialaRaport);
            result = raport5.getListOfArrays("Rulez raport5");

            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                total = totalUrban = getSumValues(result, category, 1, -1, Deranjament.MEDIU_URBAN, nivel); %>
                <td align="right"><%=totalUrban%></td>
                <td align="right">&nbsp;</td>
                <td align="right"><%=total%></td>
            <%}%>
    </tr>

    <!-- new raport 6 -->
    <tr>
        <td>6</td>
        <td>Numar de deranjamente rezolvate intr-un interval mai mic de 24 ore </td>
        <td>&nbsp;</td>
        <%
            setDataFilter(raport6, dataStart, dataStop);
            setLocation2(raport6, centruRaport, sucursalaRaport, filialaRaport);
            result = raport6.getListOfArrays("Rulez raport6");

            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                total = totalRural = getSumValues(result, category, 1, -1, Deranjament.MEDIU_RURAL, nivel); %>
                <td align="right">&nbsp;</td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
            <%}%>
    </tr>

    <% final long[][] sume = new long[6][ sucursale_sectii.length * 3]; %>
    <!-- new raport 7 -->
    <%
        setDataFilter(raport7, dataStart, dataStop);
        setLocation2(raport7, centruRaport, sucursalaRaport, filialaRaport);
        result = raport7.getListOfArrays("Rulez raport7");
    %>
    <tr>
        <td rowspan="3">7</td>
        <td rowspan="3">Numar de consumatori intrerupti in urma deranjamentelor (Suma nj)</td>
        <td>Casnici</td>
            <% for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                sume[0][i*3]   = totalUrban = (long)getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_CONS_CASNICI, -1);
                sume[0][i*3+1] = totalRural = (long)getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_CONS_CASNICI, -1);
                sume[0][i*3+2] = total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
          <%}%>
    </tr>
    <tr>
        <td>Altii</td>
        <% for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                sume[1][i*3]   = totalUrban = (long)getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_CONS_ALTII, -1);
                sume[1][i*3+1] = totalRural = (long)getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_CONS_ALTII, -1);
                sume[1][i*3+2] = total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
        <% }%>
    </tr>
    <tr>
        <td>Total</td>
        <% for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                sume[2][i*3]   = totalUrban = (long)getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_CONS_TOTAL, -1);
                sume[2][i*3+1] = totalRural = (long)getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_CONS_TOTAL, -1);
                sume[2][i*3+2] = total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban%></td>
                <td align="right"><%=totalRural%></td>
                <td align="right"><%=total%></td>
        <% } %>
    </tr>

    <!-- new raport 8 -->
    <%
        setDataFilter(raport8, dataStart, dataStop);
        setLocation2(raport8, centruRaport, sucursalaRaport, filialaRaport);
        result = raport8.getListOfArrays("Rulez raport8");
    %>
    <tr>
        <td rowspan="3">8</td>
        <td rowspan="3">Suma nj x tj (in ore si minute)</td>
        <td>Casnici</td>
        <% for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                sume[3][i*3]   = totalUrban = (long)getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_CONS_CASNICI, -1);
                sume[3][i*3+1] = totalRural = (long)getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_CONS_CASNICI, -1);
                sume[3][i*3+2] = total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban/60%>h <%=totalUrban%60%>'</td>
                <td align="right"><%=totalRural/60%>h <%=totalRural%60%>'</td>
                <td align="right"><%=total/60%>h <%=total%60%>'</td>
        <% } %>
    </tr>
    <tr>
        <td>Altii</td>
        <% for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                sume[4][i*3]   = totalUrban = (long)getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_CONS_ALTII, -1);
                sume[4][i*3+1] = totalRural = (long)getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_CONS_ALTII, -1);
                sume[4][i*3+2] = total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban/60%>h <%=totalUrban%60%>'</td>
                <td align="right"><%=totalRural/60%>h <%=totalRural%60%>'</td>
                <td align="right"><%=total/60%>h <%=total%60%>'</td>
        <% } %>
    </tr>
    <tr>
        <td>Total</td>
        <% for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                sume[5][i*3]   = totalUrban = (long)getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_CONS_TOTAL, -1);
                sume[5][i*3+1] = totalRural = (long)getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_CONS_TOTAL, -1);
                sume[5][i*3+2] = total = totalUrban + totalRural; %>
                <td align="right"><%=totalUrban/60%>h <%=totalUrban%60%>'</td>
                <td align="right"><%=totalRural/60%>h <%=totalRural%60%>'</td>
                <td align="right"><%=total/60%>h <%=total%60%>'</td>
        <% } %>
    </tr>

    <!-- raport 9 ramine -->
    <tr>
        <td rowspan="3">9</td>
        <td rowspan="3">Durata medie de intrerupere a unui consumator in urma deranjamentelor (D= Suma nj x tj / Suma nj) (in ore si minute)</td>
        <td>Casnici</td>
        <%  for (int i = 0; i < sucursale_sectii.length; i++) {
                totalUrban = (sume[0][i*3] != 0) ? sume[3][i*3]/sume[0][i*3] : 0;
                totalRural = (sume[0][i*3+1] != 0) ? sume[3][i*3+1]/sume[0][i*3+1] : 0;
                total      = (totalUrban + totalRural) / 2;     %>
                <td align="right"><%=totalUrban/60%>h <%=totalUrban%60%>'</td>
                <td align="right"><%=totalRural/60%>h <%=totalRural%60%>'</td>
                <td align="right"><%=total/60%>h <%=total%60%>'</td>
        <%}%>
    </tr>
    <tr>
        <td>Altii</td>
        <%  for (int i = 0; i < sucursale_sectii.length; i++) {
                totalUrban = (sume[1][i*3] != 0) ? sume[4][i*3]/sume[1][i*3] : 0;
                totalRural = (sume[1][i*3+1] != 0) ? sume[4][i*3+1]/sume[1][i*3+1] : 0;
                total      = (totalUrban + totalRural) / 2;     %>
                <td align="right"><%=totalUrban/60%>h <%=totalUrban%60%>'</td>
                <td align="right"><%=totalRural/60%>h <%=totalRural%60%>'</td>
                <td align="right"><%=total/60%>h <%=total%60%>'</td>
        <%}%>
    </tr>
    <tr>
        <td>Total</td>
        <%  for (int i = 0; i < sucursale_sectii.length; i++) {
                totalUrban = (sume[2][i*3] != 0) ? sume[5][i*3]/sume[2][i*3] : 0;
                totalRural = (sume[2][i*3+1] != 0) ? sume[5][i*3+1]/sume[2][i*3+1] : 0;
                total      = (totalUrban + totalRural) / 2;     %>
                <td align="right"><%=totalUrban/60%>h <%=totalUrban%60%>'</td>
                <td align="right"><%=totalRural/60%>h <%=totalRural%60%>'</td>
                <td align="right"><%=total/60%>h <%=total%60%>'</td>
        <%}%>
    </tr>


    <!--new raport 10 -->
    <%
        setDataFilter(raport10, dataStart, dataStop);
        setLocation2(raport10, centruRaport, sucursalaRaport, filialaRaport);
        result = raport10.getListOfArrays("Rulez raport10");
    %>
    <tr>
        <td rowspan="3">10</td>
        <td rowspan="3">Durata totala de intrerupere a consumatorilor in urma deranjamentelor (T=Suma tj) (in ore si minute)</td>
        <td>Casnici</td>
        <%  for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = (long)getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_CONS_CASNICI, -1);
                totalRural = (long)getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_CONS_CASNICI, -1);
                total = totalUrban + totalRural;%>
                <td align="right"><%=totalUrban/60%>h <%=totalUrban%60%>'</td>
                <td align="right"><%=totalRural/60%>h <%=totalRural%60%>'</td>
                <td align="right"><%=total/60%>h <%=total%60%>'</td>
        <% } %>
    </tr>
    <tr>
        <td>Altii</td>
        <%  for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = (long)getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_CONS_ALTII, -1);
                totalRural = (long)getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_CONS_ALTII, -1);
                total = totalUrban + totalRural;%>
                <td align="right"><%=totalUrban/60%>h <%=totalUrban%60%>'</td>
                <td align="right"><%=totalRural/60%>h <%=totalRural%60%>'</td>
                <td align="right"><%=total/60%>h <%=total%60%>'</td>
        <%}%>
    </tr>
    <tr>
        <td>Total</td>
        <%  for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                totalUrban = (long)getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_CONS_TOTAL, -1);
                totalRural = (long)getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_CONS_TOTAL, -1);
                total = totalUrban + totalRural;%>
                <td align="right"><%=totalUrban/60%>h <%=totalUrban%60%>'</td>
                <td align="right"><%=totalRural/60%>h <%=totalRural%60%>'</td>
                <td align="right"><%=total/60%>h <%=total%60%>'</td>
        <%}%>
    </tr>

    <!-- raport 11 ramine -->
    <tr>
        <td>11</td>
        <td>Durata medie de prezentare a echipei la locul deranjamentului (in ore si minute)</td>
        <td>&nbsp;</td>
        <%  report = setDataFilter(raport11, dataStart, dataStop);
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];
                setLocation(report, category, centruRaport, sucursalaRaport, filialaRaport);

                final List m = report.getListOfArrays("raport11");

                totalUrban = (long)getValue( m, Deranjament.MEDIU_URBAN);
                totalRural = (long)getValue( m, Deranjament.MEDIU_RURAL);
                total = (totalUrban + totalRural)/2;
        %>
                <td align="right"><%=totalUrban/60%>h <%=totalUrban%60%>'</td>
                <td align="right"><%=totalRural/60%>h <%=totalRural%60%>'</td>
                <td align="right"><%=total/60%>h <%=total%60%>'</td>
        <%}%>
    </tr>

    <!-- raport 12 ramine -->
    <tr>
        <td>12</td>
        <td>Durata medie de remediere a deranjamentelor (in ore si minute)</td>
        <td>&nbsp;</td>
        <%  report = setDataFilter(raport12, dataStart, dataStop);
            for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];
                setLocation(report, category, centruRaport, sucursalaRaport, filialaRaport);

                final List m = report.getListOfArrays("raport12");

                totalUrban = (long)getValue( m, Deranjament.MEDIU_URBAN);
                totalRural = (long)getValue( m, Deranjament.MEDIU_RURAL);
                total = (totalUrban + totalRural)/2;
        %>
                <td align="right"><%=totalUrban/60%>h <%=totalUrban%60%>'</td>
                <td align="right"><%=totalRural/60%>h <%=totalRural%60%>'</td>
                <td align="right"><%=total/60%>h <%=total%60%>'</td>
        <%}%>
    </tr>

    <!-- new raport 13 -->
    <%
        setDataFilter(raport13, dataStart, dataStop);
        setLocation2(raport13, centruRaport, sucursalaRaport, filialaRaport);
        result = raport13.getListOfArrays("Rulez raport13");

        double enUrban = 0;
        double enRural = 0;
        double enTotal = 0;
    %>
    <tr>
        <td rowspan="3">13</td>
        <td rowspan="3">Energia nelivrata consumatorilor ca urmare a producerii deranjamentelor (in kWh)</td>
        <td>Casnici</td>
        <% for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                enUrban = getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_ENC_CASNICI, -1);
                enRural = getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_ENC_CASNICI, -1);
                enTotal = enUrban + enRural; %>
                <td align="right"><%=AppConstants.format4(enUrban)%></td>
                <td align="right"><%=AppConstants.format4(enRural)%></td>
                <td align="right"><%=AppConstants.format4(enTotal)%></td>
        <% } %>
    </tr>
    <tr>
        <td>Altii</td>
        <% for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                enUrban = getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_ENC_ALTII, -1);
                enRural = getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_ENC_ALTII, -1);
                enTotal = enUrban + enRural; %>
                <td align="right"><%=AppConstants.format4(enUrban)%></td>
                <td align="right"><%=AppConstants.format4(enRural)%></td>
                <td align="right"><%=AppConstants.format4(enTotal)%></td>
        <% } %>
    </tr>
    <tr>
        <td>Total</td>
        <% for (int i = 0; i < sucursale_sectii.length; i++) {
                final Category category = sucursale_sectii[i];

                enUrban = getSumValues2(result, category, Deranjament.MEDIU_URBAN, nivel, COL_ENC_CASNICI, COL_ENC_ALTII);
                enRural = getSumValues2(result, category, Deranjament.MEDIU_RURAL, nivel, COL_ENC_CASNICI, COL_ENC_ALTII);
                enTotal = enUrban + enRural; %>
                <td align="right"><%=AppConstants.format4(enUrban)%></td>
                <td align="right"><%=AppConstants.format4(enRural)%></td>
                <td align="right"><%=AppConstants.format4(enTotal)%></td>
        <% } %>
    </tr>
</TABLE>

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


<% final long t2 = System.currentTimeMillis(); %>

<span style="display:none">tr: <%=t2 - t1%>;</span>



