<%@ page import="org.apache.log4j.Logger" %>
<%@ page import="ro.emid.common.types.Deranjament" %>
<%@ page import="ro.emid.common.db.framework.ReportStatement" %>
<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="ro.emid.common.db.IncidentAccessDB" %>
<%@ page import="ro.emid.incidente.db.RCAccessDB" %>
<%@ page import="ro.emid.incidente.obj.RC" %>
<%@ page import="java.io.File" %>
<%@ page import="java.sql.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.types.Category" %>
<%@ page import="ro.emid.common.utils.RaportIndicatoriDirtyExcelExporter" %>
<%@ page import="ro.emid.common.constants.*" %>
<%@ page import="ro.emid.common.utils.FSC" %>
<%@ page import="ro.emid.common.utils.FSCUtils" %>

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

<% final Logger LOG = Logger.getLogger("rapoarteIndicatoriCuDeranjamenteDirty_jsp"); %>

<%! boolean skipSAIFI = false; %>
<%! boolean skipSAIDI = false; %>
<%! boolean skipAIT = false; %>
<%! boolean skipENS = false; %>
<%! boolean showTestValues = false; %>

<% final boolean editMode = request.getAttribute("pw.edt.rc") != null; %>


<%
    final long tStart = System.currentTimeMillis();

    RC rc = new RC();

    String strDataStart = "";
    String strDataStop  = "";

    Date dataStart = null;
    Date dataStop  = null;

    String adTemp = null;

    int anRaport = -1;

    FSC fscRaport = FSCUtils.getFsc(request);

    
    if (editMode){
        int anSelected = ObjectUtils.getIntValue( request.getParameter("an"), 0);

        if ( anSelected <= 0) {
            anSelected = ro.emid.common.utils.Util.getCurrentYear();
        }

        strDataStart = "01.01."+anSelected;
        strDataStop  = "31.12."+anSelected;

    }else{

        strDataStart = request.getParameter("dataStart");
        strDataStop  = request.getParameter("dataStop");

    }
    adTemp = request.getParameter("Ad");

    dataStart = ObjectUtils.getDateValue( strDataStart, AppConstants.FORMAT_DATA);
    dataStop  = ObjectUtils.getDateValue( strDataStop, AppConstants.FORMAT_DATA);
    final double _ad = ObjectUtils.getDoubleValue(adTemp, 0);

//    if( dataStart == null) dataStart = ObjectUtils.getDateValue( "01.01." + Util.getCurrentYear(), GlobalAppConstants.FORMAT_DATA);
    if( dataStart == null) dataStart = new Date(System.currentTimeMillis()); 
    if( dataStop == null) dataStop = new Date(System.currentTimeMillis());

    anRaport = ro.emid.common.utils.Util.getAn(dataStop);

    rc = RCAccessDB.getEntry( anRaport, RC.Tip.RAPORT_INDICATORI_SAIFI_SAIDI);

    LOG.debug("RC obtinut: "+ rc);

    if( rc == null) {

        rc = new RC();
        rc.setAn( anRaport);
        rc.setTip( RC.Tip.RAPORT_INDICATORI_SAIFI_SAIDI);
    }

    String titluRaport = "";
    final Category[]centre;

    Category centruExploatareFsc = CategoryAccessDB.getById(fscRaport.getCentruId());
    if (centruExploatareFsc == null) {
        centruExploatareFsc = new Category();
    }

    Category sucursalaFsc = CategoryAccessDB.getById(fscRaport.getSucursalaId());
    if (sucursalaFsc == null){
        sucursalaFsc = new Category();
    }
    Category filialaFsc = CategoryAccessDB.getById(fscRaport.getFilialaId());
    if (filialaFsc == null){
        filialaFsc = new Category();
    }

    if( centruExploatareFsc.getId() > 0){
        centre = new Category[1];
        centre[0] = centruExploatareFsc;
        titluRaport = filialaFsc.getName() + " - " + sucursalaFsc.getName() + " - " + centruExploatareFsc.getName();
    }else if( sucursalaFsc.getId() > 0){
        //extragem toate centrele din sucursala
        centre = CategoryAccessDB.getAllCategoriesByParentId( sucursalaFsc.getId());
        titluRaport = filialaFsc.getName() + " - " + sucursalaFsc.getName();
    }else if( filialaFsc.getId() > 0){
        //extragem toate centrele din filiala
        final Category[] sucursale = CategoryAccessDB.getAllCategoriesByParentId( filialaFsc.getId());
        final StringBuffer csv = new StringBuffer();
        for (int i = 0; i < sucursale.length; i++) {
            final Category s = sucursale[i];
            if( csv.length() > 0) csv.append(", ");
            csv.append( s.getId());
        }

        centre = CategoryAccessDB.getAllCategories(" AND ID_PARENT IN (" + csv + ')');
        titluRaport = filialaFsc.getName();
    } else {
        //Electrica SA
        //extragem toate filialele
        final StringBuffer csv = new StringBuffer();
        final Category[] filiale = CategoryAccessDB.getAllCategoriesByParentId( -1);
        for (int i = 0; i < filiale.length; i++) {
            final Category f = filiale[i];
            final Category[] sucursale = CategoryAccessDB.getAllCategoriesByParentId( f.getId());
            for (int j = 0; j < sucursale.length; j++) {
                final Category s = sucursale[ j];
                if( csv.length() > 0) csv.append(", ");
                csv.append( s.getId());
            }
        }

        centre = CategoryAccessDB.getAllCategories(" AND ID_PARENT IN ("+csv+ ')');
        titluRaport = "Electrica SA";
    }

    final StringBuffer buffer = new StringBuffer();
    buffer.append(" SELECT c.COD_SAP, ").append(
            " SUM( lfInfo.NUMAR_CONSUMATORI_JT), SUM( lfInfo.NUMAR_CONSUMATORI_MT), SUM( lfInfo.NUMAR_CONSUMATORI_IT) ").append(
            " FROM VW_INTR_PLANIFICATE lp ").append(
            " INNER JOIN LPD_INSTALATIE_AFECTATA leg ON ( lp.ID = leg.LUCRARE_ID) " ).append(
            " INNER JOIN lf_info lfInfo ON ( leg.COD_LF = lfInfo.COD_SAP_LF ) " ).append(
            " INNER JOIN categories c ON ( lp.CENTRU_ID = c.ID) ");

    //LPD - Numar consumatori intrerupti de lucrari programate, grupati pe centre
    final ReportStatement nrConsumatoriAfectatiLP = new ReportStatement(
        buffer.toString()
    ).addStringCriteria(
            " AND TO_CHAR( lp.DATA_START_IC, 'YYYY')=lfInfo.AN"
    ).setGroupStatement(" GROUP BY c.COD_SAP ");

    buffer.delete(0, buffer.length());
    buffer.append(" SELECT c.COD_SAP, SUM( UTILIZATORI_JT), SUM( UTILIZATORI_MT), SUM( UTILIZATORI_IT) ").append(
            " FROM VW_INTR_PLANIFICATE lp " ).append(
            "INNER JOIN categories c ON (lp.CENTRU_ID = c.ID) ");

    //LPD - Numar consumatori intrerupti de lucrari programate, grupati pe centre, din fise lucrari programate
    final ReportStatement nrConsumatoriAfectatiDinFLP = new ReportStatement(
        buffer.toString()
    ).addStringCriteria(
            " AND (SELECT count(*) FROM LPD_INSTALATIE_AFECTATA WHERE LUCRARE_ID = lp.ID)=0 "
    ).setGroupStatement(" GROUP BY c.COD_SAP ");

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

    final StringBuffer criteria = new StringBuffer();

    buffer.append(" SELECT c.COD_SAP, ").append(
            " SUM( lfInfo.NUMAR_CONSUMATORI_JT), SUM( lfInfo.NUMAR_CONSUMATORI_MT), SUM( lfInfo.NUMAR_CONSUMATORI_IT) ").append(
            " FROM incidente i, ").append(
            " incidente_lf leg, lf_info lfInfo, " ).append(
            " nomenclator nGrupeCauze, nomenclator nCauze, categories c");
    //IE - Numar consumatori afectati de incidente, grupati pe centre, din nomenclator, completati automat
    criteria.append(" AND i.SECTIE_ID=c.ID AND i.ID=leg.INCIDENT_ID AND leg.COD_LF=lfInfo.COD_SAP_LF ").append(
            " AND TO_CHAR(i.DATA, 'YYYY')=lfInfo.AN AND nGrupeCauze.COD=nCauze.COD_GRUPA ").append(
            " AND nGrupeCauze.TIP =").append(NomConstants.NOM_CAUZE_GRUPE).append(" AND nCauze.TIP = ").append(NomConstants.NOM_CAUZE).append(
            " AND i.MOD_COMPL_CONS = ").append(ro.emid.common.constants.IncidentConstants.ConsumatoriCompletati.AUTOMAT).append(
            " AND i.CAUZA_GR_ID=nGrupeCauze.ID AND i.CAUZA_ID = nCauze.ID ");

    final ReportStatement nrConsumatoriAfectatiIncidente = new ReportStatement(
        buffer.toString()
    ).addStringCriteria(
        criteria.toString()
    ).setGroupStatement(" GROUP BY c.COD_SAP ");

    buffer.delete(0, buffer.length());
    buffer.append(" SELECT c.COD_SAP, ").append(
            " SUM( i.UTILIZATORI_JT), SUM(i.UTILIZATORI_MT), SUM( i.UTILIZATORI_IT) ").append(
            " FROM incidente i, " ).append(
            " nomenclator nGrupeCauze, nomenclator nCauze, categories c");

    criteria.delete(0, criteria.length());
    criteria.append(" AND i.SECTIE_ID=c.ID ").append(
            " AND nGrupeCauze.COD=nCauze.COD_GRUPA ").append(
            " AND nGrupeCauze.TIP =").append(NomConstants.NOM_CAUZE_GRUPE).append(" AND nCauze.TIP = ").append(NomConstants.NOM_CAUZE).append(
            " AND i.MOD_COMPL_CONS = ").append(IncidentConstants.ConsumatoriCompletati.MANUAL).append(
            " AND i.CAUZA_GR_ID=nGrupeCauze.ID AND i.CAUZA_ID = nCauze.ID ");
    final ReportStatement nrConsumatoriAfectatiIncidenteDinFi = new ReportStatement(
        buffer.toString()
    ).addStringCriteria(
        criteria.toString()
    ).setGroupStatement(" GROUP BY c.COD_SAP ");

    //Numar consumatori afectati de deranjamente, grupati pe centre
    final ReportStatement nrConsumatoriAfectatiDeranjamente = new ReportStatement(
            " SELECT c.COD_SAP, sum(d.nr_case + d.nr_ap + d.nr_mici + d.nr_mari) FROM deranjamente d, categories c "
    ).addStringCriteria(
            " AND d.sectie_id=c.id "
    ).setGroupStatement(
            " GROUP BY c.COD_SAP "
    );

    //pt SAIDI
    //LPD
    buffer.delete(0, buffer.length());
    buffer.append(" SELECT c.COD_SAP, ").append(
            "SUM( lfInfo.NUMAR_CONSUMATORI_JT * (CASE WHEN leg.DURATA_INTRERUPERE > 0 THEN leg.DURATA_INTRERUPERE ELSE lp.DURATA_INTR END))," ).append(
            "SUM( lfInfo.NUMAR_CONSUMATORI_MT * (CASE WHEN leg.DURATA_INTRERUPERE > 0 THEN leg.DURATA_INTRERUPERE ELSE lp.DURATA_INTR END))," ).append(
            "SUM( lfInfo.NUMAR_CONSUMATORI_IT * (CASE WHEN leg.DURATA_INTRERUPERE > 0 THEN leg.DURATA_INTRERUPERE ELSE lp.DURATA_INTR END)) " ).append(
            " FROM LPD_LUCRARE_PROGRAMATA lp " ).append(
            " INNER JOIN LPD_INSTALATIE_AFECTATA leg ON ( lp.ID = leg.LUCRARE_ID) " ).append(
            " INNER JOIN lf_info lfInfo ON ( leg.COD_LF = lfInfo.COD_SAP_LF AND TO_CHAR( lp.DATA_INTR_START, 'YYYY')=lfInfo.AN ) " ).append(
            " INNER JOIN categories c ON ( lp.CENTRU_ID = c.ID) ");

    final ReportStatement nrConsumatoriAfectatiPTOriDurataIntreruperePT_LP = new ReportStatement(
        buffer.toString()
    ).setGroupStatement(
            " GROUP BY c.COD_SAP "
    );

    buffer.delete(0, buffer.length());
    buffer.append("\n SELECT c.COD_SAP, \n").append(
            "       SUM( lp.UTILIZATORI_JT * lp.DURATA_INTR ), \n" ).append(
            "       SUM( lp.UTILIZATORI_MT * lp.DURATA_INTR ), \n" ).append(
            "       SUM( lp.UTILIZATORI_IT * lp.DURATA_INTR )  \n" ).append(
            " FROM LPD_LUCRARE_PROGRAMATA lp \n" ).append(
            "       INNER JOIN categories c ON ( lp.CENTRU_ID = c.ID) \n");

    //LPD
    final ReportStatement nrConsumatoriAfectatiPTOriDurataIntrerupereDinFLP = new ReportStatement(
        buffer.toString()
    ).addStringCriteria(
            " AND (SELECT count(*) FROM LPD_INSTALATIE_AFECTATA WHERE LUCRARE_ID = lp.ID)=0 "
    ).setGroupStatement(
            " GROUP BY c.COD_SAP "
    );

    buffer.delete(0, buffer.length());
    buffer.append(" SELECT c.COD_SAP, ").append(
            "SUM( lfInfo.NUMAR_CONSUMATORI_JT * (CASE WHEN leg.DURATA_INTRERUPERE > 0 THEN leg.DURATA_INTRERUPERE ELSE i.DURATA_INCIDENT END))," ).append(
            "SUM( lfInfo.NUMAR_CONSUMATORI_MT * (CASE WHEN leg.DURATA_INTRERUPERE > 0 THEN leg.DURATA_INTRERUPERE ELSE i.DURATA_INCIDENT END))," ).append(
            "SUM( lfInfo.NUMAR_CONSUMATORI_IT * (CASE WHEN leg.DURATA_INTRERUPERE > 0 THEN leg.DURATA_INTRERUPERE ELSE i.DURATA_INCIDENT END)) " ).append(
            " FROM incidente i, incidente_lf leg, lf_info lfInfo, nomenclator nGrupeCauze, nomenclator nCauze, categories c ");

    criteria.delete(0, buffer.length());
    criteria.append(" AND i.SECTIE_ID=c.ID AND i.ID=leg.INCIDENT_ID AND leg.COD_LF=lfInfo.COD_SAP_LF ").append(
            " AND TO_CHAR(i.DATA, 'YYYY')=lfInfo.AN AND nGrupeCauze.COD=nCauze.COD_GRUPA " ).append(
            " AND nGrupeCauze.TIP =").append(NomConstants.NOM_CAUZE_GRUPE ).append(" AND nCauze.TIP = ").append(NomConstants.NOM_CAUZE).append(
            " AND i.CAUZA_GR_ID=nGrupeCauze.ID AND i.CAUZA_ID = nCauze.ID " ).append(
            " AND i.MOD_COMPL_CONS = " ).append(IncidentConstants.ConsumatoriCompletati.AUTOMAT);

    //IE - automat
    final ReportStatement nrConsumatoriAfectatiPTOriDurataIntreruperePT = new ReportStatement(
        buffer.toString()
    ).addStringCriteria(
        criteria.toString()
    ).setGroupStatement(
            " GROUP BY c.COD_SAP "
    );

    buffer.delete(0, buffer.length());
    buffer.append(" SELECT c.COD_SAP, " ).append(
            "SUM( i.UTILIZATORI_JT * i.DURATA_INCIDENT )," ).append(
            "SUM( i.UTILIZATORI_MT * i.DURATA_INCIDENT )," ).append(
            "SUM( i.UTILIZATORI_IT * i.DURATA_INCIDENT ) " ).append(
            " FROM incidente i, nomenclator nGrupeCauze, nomenclator nCauze, categories c ");

    criteria.delete(0, criteria.length());
    criteria.append(" AND i.SECTIE_ID=c.ID AND nGrupeCauze.COD=nCauze.COD_GRUPA ").append(
            " AND nGrupeCauze.TIP =").append(NomConstants.NOM_CAUZE_GRUPE).append(" AND nCauze.TIP = " ).append( NomConstants.NOM_CAUZE ).append(
            " AND i.CAUZA_GR_ID=nGrupeCauze.ID AND i.CAUZA_ID = nCauze.ID " ).append(
            " AND i.MOD_COMPL_CONS = ").append(IncidentConstants.ConsumatoriCompletati.MANUAL);

    //IE - manual
    final ReportStatement nrConsumatoriAfectatiOriDurataIncidentDinFi = new ReportStatement(
        buffer.toString()
    ).addStringCriteria(
        criteria.toString()
    ).setGroupStatement( " GROUP BY c.COD_SAP ");

    buffer.delete(0, buffer.length());
    buffer.append(" SELECT SUM(").append(LFInfoConstants.CONSTANT_PNON).append("* lfInfo.SNOM * lfInfo.GRAD_INCARCARE * (CASE WHEN leg.DURATA_INTRERUPERE > 0 THEN leg.DURATA_INTRERUPERE ELSE i.DURATA_INCIDENT END)) ").append(
            " FROM incidente i, incidente_lf leg, lf_info lfInfo ");

    //Numar consumatori afectati de deranjamente*durata deranjament, grupati pe centre
    final ReportStatement nrConsumatoriAfectatiDerOriDurataDer = new ReportStatement(
            " SELECT c.COD_SAP, sum( (d.nr_case + d.nr_ap + d.nr_mici + d.nr_mari) * getDiferentaMinute(d.DATA_REZOLVARE, d.DATA_ANUNTARE)) FROM deranjamente d, categories c ",
            " GROUP BY c.COD_SAP "
    ).addStringCriteria(" AND d.sectie_id=c.id ");

    final ReportStatement ENS = new ReportStatement(
        buffer.toString()
    ).addStringCriteria(" AND i.ID=leg.INCIDENT_ID AND leg.COD_LF=lfInfo.COD_SAP_LF AND TO_CHAR(i.DATA, 'YYYY')=lfInfo.AN");


    //aplicam filtrele
//    if( filiala.getId() > 0){
    if( fscRaport.getFilialaId() > 0){
        nrConsumatoriAfectatiLP.addOrSetFilter("AND", "lp.FILIALA_ID", "=", new Long( fscRaport.getFilialaId()));
        nrConsumatoriAfectatiDinFLP.addOrSetFilter("AND", "lp.FILIALA_ID", "=", new Long( fscRaport.getFilialaId()));

        nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "i.FILIALA_ID", "=", new Long( fscRaport.getFilialaId()));
        nrConsumatoriAfectatiIncidenteDinFi.addOrSetFilter("AND", "i.FILIALA_ID", "=", new Long( fscRaport.getFilialaId()));
        nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.FILIALA_ID", "=", new Long( fscRaport.getFilialaId()));

        nrConsumatoriAfectatiPTOriDurataIntreruperePT_LP.addOrSetFilter("AND", "lp.FILIALA_ID", "=", new Long( fscRaport.getFilialaId()));
        nrConsumatoriAfectatiPTOriDurataIntrerupereDinFLP.addOrSetFilter("AND", "lp.FILIALA_ID", "=", new Long( fscRaport.getFilialaId()));

        nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "i.FILIALA_ID", "=", new Long( fscRaport.getFilialaId()));
        nrConsumatoriAfectatiOriDurataIncidentDinFi.addOrSetFilter("AND", "i.FILIALA_ID", "=", new Long( fscRaport.getFilialaId()));
        nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.FILIALA_ID", "=", new Long( fscRaport.getFilialaId()));
        ENS.addOrSetFilter("AND", "i.FILIALA_ID", "=", new Long( fscRaport.getFilialaId()));
    }

//    if( sucursala.getId() > 0){
    if( fscRaport.getSucursalaId() > 0){
        nrConsumatoriAfectatiLP.addOrSetFilter("AND", "lp.SUCURSALA_ID", "=", new Long( fscRaport.getSucursalaId()));
        nrConsumatoriAfectatiDinFLP.addOrSetFilter("AND", "lp.SUCURSALA_ID", "=", new Long( fscRaport.getSucursalaId()));

        nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "i.SUCURSALA_ID", "=", new Long( fscRaport.getSucursalaId()));
        nrConsumatoriAfectatiIncidenteDinFi.addOrSetFilter("AND", "i.SUCURSALA_ID", "=", new Long( fscRaport.getSucursalaId()));
        nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.SUCURSALA_ID", "=", new Long( fscRaport.getSucursalaId()));

        nrConsumatoriAfectatiPTOriDurataIntreruperePT_LP.addOrSetFilter("AND", "lp.SUCURSALA_ID", "=", new Long( fscRaport.getSucursalaId()));
        nrConsumatoriAfectatiPTOriDurataIntrerupereDinFLP.addOrSetFilter("AND", "lp.SUCURSALA_ID", "=", new Long( fscRaport.getSucursalaId()));

        nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "i.SUCURSALA_ID", "=", new Long( fscRaport.getSucursalaId()));
        nrConsumatoriAfectatiOriDurataIncidentDinFi.addOrSetFilter("AND", "i.SUCURSALA_ID", "=", new Long( fscRaport.getSucursalaId()));
        nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.SUCURSALA_ID", "=", new Long( fscRaport.getSucursalaId()));
        ENS.addOrSetFilter("AND", "i.SUCURSALA_ID", "=", new Long( fscRaport.getSucursalaId()));
    }

//    if( centruExploatare.getId()  > 0){
    if( fscRaport.getCentruId() > 0){
        nrConsumatoriAfectatiLP.addOrSetFilter("AND", "lp.CENTRU_ID", "=", new Long( fscRaport.getCentruId()));
        nrConsumatoriAfectatiDinFLP.addOrSetFilter("AND", "lp.CENTRU_ID", "=", new Long( fscRaport.getCentruId()));

        nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "i.SECTIE_ID", "=", new Long( fscRaport.getCentruId()));
        nrConsumatoriAfectatiIncidenteDinFi.addOrSetFilter("AND", "i.SECTIE_ID", "=", new Long( fscRaport.getCentruId()));
        nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.SECTIE_ID", "=", new Long( fscRaport.getCentruId()));

        nrConsumatoriAfectatiPTOriDurataIntreruperePT_LP.addOrSetFilter("AND", "lp.CENTRU_ID", "=", new Long( fscRaport.getCentruId()));
        nrConsumatoriAfectatiPTOriDurataIntrerupereDinFLP.addOrSetFilter("AND", "lp.CENTRU_ID", "=", new Long( fscRaport.getCentruId()));

        nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "i.SECTIE_ID", "=", new Long( fscRaport.getCentruId()));
        nrConsumatoriAfectatiOriDurataIncidentDinFi.addOrSetFilter("AND", "i.SECTIE_ID", "=", new Long( fscRaport.getCentruId()));
        nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.SECTIE_ID", "=", new Long( fscRaport.getCentruId()));
        ENS.addOrSetFilter("AND", "i.SECTIE_ID", "=", new Long( fscRaport.getCentruId()));
    }

    final SimpleDateFormat _df = new SimpleDateFormat("dd.MM.yyyy");
    if( dataStart != null){
        nrConsumatoriAfectatiLP.addOrSetFilter("AND", "lp.DATA_START_IC", ">=", dataStart);
        nrConsumatoriAfectatiDinFLP.addOrSetFilter("AND", "lp.DATA_START_IC", ">=", dataStart);

        nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "i.DATA", ">=", dataStart);
        nrConsumatoriAfectatiIncidenteDinFi.addOrSetFilter("AND", "i.DATA", ">=", dataStart);
        nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.DATA_ANUNTARE", ">=", dataStart);

        nrConsumatoriAfectatiPTOriDurataIntreruperePT_LP.addOrSetFilter("AND", "lp.DATA_INTR_START", ">=", dataStart);
        nrConsumatoriAfectatiPTOriDurataIntrerupereDinFLP.addOrSetFilter("AND", "lp.DATA_INTR_START", ">=", dataStart);        

        nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "i.DATA", ">=", dataStart);
        nrConsumatoriAfectatiOriDurataIncidentDinFi.addOrSetFilter("AND", "i.DATA", ">=", dataStart);
        nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.DATA_ANUNTARE", ">=", dataStart);
//        ENS.addOrSetFilter("AND", "i.DATA", ">=", dataStart);
        ENS.addStringCriteria("AND i.DATA >= to_date('"+_df.format(dataStart)+"','dd.mm.yyyy') ");
    }

    final long oneDay = 24 * 60 * 60 * 1000;

    if( dataStop != null){
        final Date _dataStop = new Date( dataStop.getTime() + oneDay);

        nrConsumatoriAfectatiLP.addOrSetFilter("AND", "lp.DATA_START_IC", "<=", _dataStop);
        nrConsumatoriAfectatiDinFLP.addOrSetFilter("AND", "lp.DATA_START_IC", "<=", _dataStop);

        nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "i.DATA", "<=", _dataStop);
        nrConsumatoriAfectatiIncidenteDinFi.addOrSetFilter("AND", "i.DATA", "<=", _dataStop);
        nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.DATA_ANUNTARE", "<=", _dataStop);

        nrConsumatoriAfectatiPTOriDurataIntreruperePT_LP.addOrSetFilter("AND", "lp.DATA_INTR_START", "<=", _dataStop);
        nrConsumatoriAfectatiPTOriDurataIntrerupereDinFLP.addOrSetFilter("AND", "lp.DATA_INTR_START", "<=", _dataStop);

        nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "i.DATA", "<=", _dataStop);
        nrConsumatoriAfectatiOriDurataIncidentDinFi.addOrSetFilter("AND", "i.DATA", "<=", _dataStop);
        nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.DATA_ANUNTARE", "<=", _dataStop);

//        ENS.addOrSetFilter("AND", "i.DATA", "<=", _dataStop);
        ENS.addStringCriteria("AND i.DATA <= to_date('"+_df.format(_dataStop)+"','dd.mm.yyyy')");
    }


    final StringBuffer csv = new StringBuffer();
    for (int i = 0; i < centre.length; i++) {
        final Category c = centre[i];
        if( csv.length() > 0) csv.append(',');

        csv.append('\'').append(c.getCodSap()).append('\'');
    }
    final ReportStatement nrTotalConsumatori = new ReportStatement(
            "SELECT lfInfo.COD_CE, lfinfo.MEDIU, SUM( lfInfo.NUMAR_CONSUMATORI_JT), SUM( lfInfo.NUMAR_CONSUMATORI_MT), SUM( lfInfo.NUMAR_CONSUMATORI_IT) FROM lf_info lfInfo\n"
    ).setGroupStatement( " GROUP BY lfInfo.COD_CE, lfinfo.MEDIU")
    .addStringCriteria(" AND (lfInfo.AN <= 2014 or lfInfo.AN>2014 and lfInfo.sters=0) AND lfInfo.AN="+anRaport);

    nrTotalConsumatori.addOrSetStringCriteria("AND", "lfInfo.COD_CE", " IN ("+csv+ ')');

    final HashMap dataToExport = new HashMap();

    final List mTotalConsumatori = nrTotalConsumatori.getListOfArrays("Get numar Total Consumatori 2");
    String publicPath = null;

%>

<style type="text/css">
    .clasu{
        width:50px;
        text-align:right;
    }

</style>

<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> Indicatori
        </TD>
    </TR>
</TABLE>

<%--<%@ include file="rapoarteLinks.jsp"%>--%>

<div class="spacer">&nbsp;</div>

<%--<center><h3><%=titluRaport%></h3></center>--%>
<div class="spacer">&nbsp;</div>
<form name="zaforma" action="<%=AppConstants.APP_NAME%>" method="post">
    <input type="hidden" name="action" value="showRapoarteIndicatori">
    <input type="hidden" name="run_report" value="1"/>
    <table class="gsaptd" width="100%">
      <tr>
          <td align="left">
              <span style="font-size:16px; font-weight:bold;"><%=titluRaport%></span>
          </td>
          <td align="right">
              <emid:filtru-localizare hideLabels="false"/>
          </td>
          <td align="right">

              <% if( editMode){ %>

                <% final Integer[] ani = ro.emid.common.utils.Util.addCurrentYear(IncidentAccessDB.getAniProducereIncident("")); %>

                Ad = <input type="text" id="Ad" name="Ad" size="5" value="<%=_ad%>" />

                <label for="an">An:</label>

                <select id="an" name="an">
                    <% for (int i = 0; i < ani.length; i++) {
                            final Integer an = ani[i]; %>
                            <option value="<%=an%>" <%=anRaport == an.intValue() ? "selected" : ""%> ><%=an%></option>
                    <% } %>
                </select>

              <% }else{ %>
              <input type="hidden" name="toExport" value="0">
                  Ad =
                  <input type="text" id="Ad" name="Ad" size="5" value="<%=_ad%>" />

                  <label>
                      Perioada:
                      <emid:datefield name="dataStart" value="<%=dataStart%>" width="80px"/>
                  </label>
                  -
                  <emid:datefield name="dataStop" value="<%=dataStop%>" width="80px"/>
              <% } %>

              &nbsp;&nbsp;<input type="submit" value="Aplică"/>
              &nbsp;<input type="button" value="Export" onclick="document.zaforma.toExport.value = '1'; document.zaforma.submit();"/>
      </td></tr>
    </table>
</form>
<div class="spacer">&nbsp;</div>

<% if( editMode){ %>
    <form action="<%=AppConstants.APP_NAME%>" method="post">
        <input type="hidden" name="action" value="saveRC">
        <input type="hidden" name="cid" value="<%=rc.getId()%>">
        <input type="hidden" name="can" value="<%=rc.getAn()%>">
        <input type="hidden" name="ctip" value="<%=rc.getTip()%>">
<% } %>
<%if(_ad > 0) {%>
<table border="1" bgcolor="white" width="100%">
    <col align="center">
    <col>
    <col align="center">
    <col align="center">
    <col align="center">
    <col align="center">
    <col align="center">
    <thead>
        <tr>
            <th class="gsapthead">Indicator</th>
            <th class="gsapthead">Cauza intreruperii</th>
            <th class="gsapthead">Rural/Urban</th>
            <th class="gsapthead">Tipul utilizatorului</th>
            <th class="gsapthead">Nivel tensiune</th>
            <th class="gsapthead">Valoarea realizata anual</th>
            <th class="gsapthead">Nr.</th>

            <% if( editMode){ %>
                <th class="gsapthead">C. <input type="submit" value="S"></th>
            <% } %>
        </tr>
    </thead>
    <tbody valign="top">
        <% int i = 0;  %>
        <% List mDinNomInst = null; %>
        <% List mDinFise = null;%>
        <% List mDer = null; %>
        <% double c = 0; %>
        <% double indicator = 0;  %>
        <% if( !skipSAIFI){%>
        <%
            System.out.println("[EMID] SAIFI A.");
        %>

        <!--a. intreruperi planificate ( din lucrari programate) -->
        <%  mDinNomInst = nrConsumatoriAfectatiLP.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori --LP-- SAIFI.A.RURAL");%>
        <%  mDinFise = nrConsumatoriAfectatiDinFLP.addOrSetFilter("AND", "lp.MEDIU", "=", "R").getListOfArrays("Get numar Consumatori --LP-- Din fise SAIFI.A.RURAL");%>
        
        <tr>
            <td rowspan="6">SAIFI</td>
            <td rowspan="6">a. intreruperi planificate</td>
            <td rowspan="3">rural</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL,  COLUMN_INDEX_JT, c = getConstanta(i+1, rc) ); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("1", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("2", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
			<% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("3", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>

        <%  mDinNomInst = nrConsumatoriAfectatiLP.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori --LP-- SAIFI.A.URBAN");%>
        <%  mDinFise = nrConsumatoriAfectatiDinFLP.addOrSetFilter("AND", "lp.MEDIU", "=", "U").getListOfArrays("Get numar Consumatori --LP-- Din fise SAIFI.A.URBAN");%>
        <tr>
            <td rowspan="3">urban</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_JT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("4", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("5", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("6", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>


        <!-- din incidente -->
        <%  nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "i.FORTA_MAJORA", "=", new Integer( 1)); %>
        <%  nrConsumatoriAfectatiIncidenteDinFi.addOrSetFilter("AND", "i.FORTA_MAJORA", "=", new Integer( 1)); %>

        <%  mDinNomInst = nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori --INCIDENTE-- SAIFI.B.RURAL");%>

        <%  addRuralCondition( nrConsumatoriAfectatiIncidenteDinFi); %>
        <%  mDinFise = nrConsumatoriAfectatiIncidenteDinFi.getListOfArrays("Get numar Consumatori --INCIDENTE-- Din FI SAIFI.B.RURAL");%>

        <%  nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.FORTA_MAJORA",  "=", new Integer(1)); %>
        <%  mDer = nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori --DERANJAMENTE-- SAIFI.B.RURAL");%>

        <tr>
            <td rowspan="18">SAIFI</td>
            <td rowspan="6">b. intreruperi neplanificate cauzate de forta majora</td>
            <td rowspan="3">rural</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIFIJT( centre, mDinNomInst, mDinFise, mDer, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, c = getConstanta(i+1, rc)); %>
            <%--<% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_JT, c = getConstanta(i+1, rc) ); %>--%>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("7", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("8", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
			<% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("9", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>

        <%  mDinNomInst = nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori SAIFI.A.URBAN");%>
        <%  addUrbanCondition( nrConsumatoriAfectatiIncidenteDinFi); %>
        <%  mDinFise = nrConsumatoriAfectatiIncidenteDinFi.getListOfArrays("Get numar Consumatori din FI SAIFI.A.URBAN");%>
        <%  mDer = nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori --DERANJAMENTE-- SAIFI.B.RURAL");%>

        <!--intreruperi neplanificate cauzate de forta majora URBAN-->
        <tr>
            <td rowspan="3">urban</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <%--<% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN,  COLUMN_INDEX_JT, c = getConstanta(i+1, rc)); %>--%>
            <% indicator = getSAIFIJT( centre, mDinNomInst, mDinFise, mDer, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("10", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("11", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("12", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>

        <%
            System.out.println("[EMID] SAIFI C.");
        %>
        <%  nrConsumatoriAfectatiIncidente.removeFilter("i.FORTA_MAJORA");  %>
        <%  nrConsumatoriAfectatiIncidente.removeFilter("nGrupeCauze.COD");  %>
        <%  nrConsumatoriAfectatiIncidente.addOrSetStringCriteria("AND", "nGrupeCauze.COD", "="+ NomConstants.COD_CAUZA_GRUPA_INTRERUPERI_USERI); %>
        <%  nrConsumatoriAfectatiIncidente.addOrSetStringCriteria("AND", "nCauze.COD", " IN (91, 92, 93) "); %>
        <%  nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "i.FORTA_MAJORA", "=", new Integer(0)); //si nu este forta majora %>
        <%  nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "i.DURATA_INCIDENT", ">", new Integer(3));  %>
        <%  mDinNomInst = nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori --INCIDENTE-- SAIFI.B.RURAL");%>

        <%  nrConsumatoriAfectatiIncidenteDinFi.removeFilter("i.FORTA_MAJORA");  %>
        <%  nrConsumatoriAfectatiIncidenteDinFi.removeFilter("nGrupeCauze.COD");  %>
        <%  nrConsumatoriAfectatiIncidenteDinFi.addOrSetStringCriteria("AND", "nGrupeCauze.COD", "="+ NomConstants.COD_CAUZA_GRUPA_INTRERUPERI_USERI); %>
        <%  nrConsumatoriAfectatiIncidenteDinFi.addOrSetStringCriteria("AND", "nCauze.COD", " IN (91, 92, 93) "); %>
        <%  nrConsumatoriAfectatiIncidenteDinFi.addOrSetFilter("AND", "i.FORTA_MAJORA", "=", new Integer(0)); //si nu este forta majora %>
        <%  nrConsumatoriAfectatiIncidenteDinFi.addOrSetFilter("AND", "i.DURATA_INCIDENT", ">", new Integer(3));  %>
        <%  addRuralCondition( nrConsumatoriAfectatiIncidenteDinFi); %>
        <%  mDinFise = nrConsumatoriAfectatiIncidenteDinFi.getListOfArrays("Get numar Consumatori --INCIDENTE-- SAIFI.B.RURAL");%>

        <%  nrConsumatoriAfectatiDeranjamente.removeFilter( "d.FORTA_MAJORA"); %>
        <%  nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.FORTA_MAJORA",  "=", new Integer(0)); %>
        <%  nrConsumatoriAfectatiDeranjamente.addOrSetStringCriteria("AND (", "d.CAUZA", "="+ DeranjamentConstants.INDEX_CAUZA_RAPORT_INDICATORI_PUNCTUL_B + " OR d.APARTENENTA_INST = " + Deranjament.APARTINE_CONSUMATOR + ')');  %>
        <%  mDer = nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori --DERANJAMENTE-- SAIFI.B.RURAL");%>
        <!--intreruperi neplanificate cauzate de utilizatori RURAL-->

        <tr>
            <td rowspan="6">c. intreruperi neplanificate cauzate de utilizatori</td>
            <td rowspan="3">rural</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIFIJT( centre, mDinNomInst, mDinFise, mDer, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>" > <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("13", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("14", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("15", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        
        <%  mDinNomInst = nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori --INCIDENTE-- SAIFI.B.URBAN");%>
        <%  addUrbanCondition( nrConsumatoriAfectatiIncidenteDinFi); %>
        <%  mDinFise = nrConsumatoriAfectatiIncidenteDinFi.getListOfArrays("Get numar Consumatori --INCIDENTE-- din FI SAIFI.B.URBAN");%>
        <%  mDer = nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori --DERANJAMENTE-- SAIFI.B.URBAN");%>
        <!--intreruperi neplanificate cauzate de utilizatori URBAN-->
        <tr>
            <td rowspan="3">urban</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIFIJT( centre, mDinNomInst, mDinFise, mDer, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("16", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("17", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("18", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>

        <%
            System.out.println("[EMID] SAIFI C.");
        %>
        <%  nrConsumatoriAfectatiIncidente.removeFilter("i.FORTA_MAJORA");%>
        <%  nrConsumatoriAfectatiIncidente.removeFilter("i.DURATA_INCIDENT");%>
        <%  nrConsumatoriAfectatiIncidente.removeFilter("nGrupeCauze.COD");%>
        <%  nrConsumatoriAfectatiIncidente.removeFilter("nCauze.COD");%>
        <%  nrConsumatoriAfectatiIncidente.addStringCriteria( "AND NOT (i.FORTA_MAJORA=1)" ); %>
        <%  nrConsumatoriAfectatiIncidente.addStringCriteria( "AND NOT (i.FORTA_MAJORA=0 AND i.DURATA_INCIDENT > 3 AND nGrupeCauze.COD = " + NomConstants.COD_CAUZA_GRUPA_INTRERUPERI_USERI + " AND nCauze.COD IN (91, 92, 93))" ); %>
        <%  mDinNomInst = nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori --INCIDENTE-- SAIFI.C.RURAL");%>

        <%  nrConsumatoriAfectatiIncidenteDinFi.removeFilter("i.FORTA_MAJORA");%>
        <%  nrConsumatoriAfectatiIncidenteDinFi.removeFilter("i.DURATA_INCIDENT");%>
        <%  nrConsumatoriAfectatiIncidenteDinFi.removeFilter("nGrupeCauze.COD");%>
        <%  nrConsumatoriAfectatiIncidenteDinFi.removeFilter("nCauze.COD");%>
        <%  nrConsumatoriAfectatiIncidenteDinFi.addStringCriteria( "AND NOT (i.FORTA_MAJORA=1)" ); %>
        <%  nrConsumatoriAfectatiIncidenteDinFi.addStringCriteria( "AND NOT (i.FORTA_MAJORA=0 AND i.DURATA_INCIDENT > 3 AND nGrupeCauze.COD = " + NomConstants.COD_CAUZA_GRUPA_INTRERUPERI_USERI + " AND nCauze.COD IN (91, 92, 93))" ); %>
        <%  addRuralCondition( nrConsumatoriAfectatiIncidenteDinFi); %>
        <%  mDinFise = nrConsumatoriAfectatiIncidenteDinFi.getListOfArrays("Get numar Consumatori --INCIDENTE-- Din FI SAIFI.C.RURAL");%>

        <%  nrConsumatoriAfectatiDeranjamente.removeFilter("d.CAUZA"); %>
        <%  nrConsumatoriAfectatiDeranjamente.removeFilter("d.FORTA_MAJORA"); %>
        <%  nrConsumatoriAfectatiDeranjamente.addStringCriteria( "AND NOT (d.FORTA_MAJORA=1)" ); %>
        <%  nrConsumatoriAfectatiDeranjamente.addOrSetStringCriteria("AND NOT (", "d.CAUZA", "="+ DeranjamentConstants.INDEX_CAUZA_RAPORT_INDICATORI_PUNCTUL_B + " OR d.APARTENENTA_INST = " + Deranjament.APARTINE_CONSUMATOR + " AND d.FORTA_MAJORA=0 )");  %>
        <%  mDer = nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori --DERANJAMENTE-- SAIFI.C.RURAL");%>
        <!--intreruperi neplanificate cauzate de utilizatori RURAL-->
        <tr>
            <td rowspan="6">d. intreruperi neplanificate exclusiv intreruperile de la punctele b si c</td>
            <td rowspan="3">rural</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIFIJT( centre, mDinNomInst, mDinFise, mDer, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>" > <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("19", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("20", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("21", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>


        <%  mDinNomInst = nrConsumatoriAfectatiIncidente.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori --INCIDENTE-- SAIFI.C.URBAN");%>
        <%  addUrbanCondition( nrConsumatoriAfectatiIncidenteDinFi); %>
        <%  mDinFise = nrConsumatoriAfectatiIncidenteDinFi.getListOfArrays("Get numar Consumatori --INCIDENTE-- Din FI SAIFI.C.URBAN");%>
        <%  mDer = nrConsumatoriAfectatiDeranjamente.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori --DERANJAMENTE-- SAIFI.C.URBAN");%>
        <tr>
            <td rowspan="3">urban</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIFIJT( centre, mDinNomInst, mDinFise, mDer, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("22", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("23", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIFI2( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("24", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <%  nrConsumatoriAfectatiIncidente.removeFilter("i.DURATA_INCIDENT");%>
        <%  nrConsumatoriAfectatiIncidente.removeFilter("i.FORTA_MAJORA");%>

        <%}%>


        <%if( !skipSAIDI ){%>
        <!--SAIDI-->
        <%
            System.out.println("[EMID] SAIDI A.");
        %>

        <%  mDinNomInst = nrConsumatoriAfectatiPTOriDurataIntreruperePT_LP.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori --LP-- SAIFI.A.RURAL");%>
        <%  mDinFise = nrConsumatoriAfectatiPTOriDurataIntrerupereDinFLP.addOrSetFilter("AND", "lp.MEDIU", "=", "R").getListOfArrays("Get numar Consumatori --LP-- Din fise SAIFI.A.RURAL");%>
        <!-- lucrarile programate -->
        <tr>
            <td rowspan="6">SAIDI</td>
            <td rowspan="6">a. intreruperi planificate</td>
            <td rowspan="3">rural</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>

            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_JT, c = getConstanta(i+1, rc) ); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("25", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("26", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
			<% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("27", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>

        <%  mDinNomInst = nrConsumatoriAfectatiPTOriDurataIntreruperePT_LP.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori --LP-- SAIFI.A.URBAN");%>
        <%  mDinFise = nrConsumatoriAfectatiPTOriDurataIntrerupereDinFLP.addOrSetFilter("AND", "lp.MEDIU", "=", "U").getListOfArrays("Get numar Consumatori --LP-- Din fise SAIFI.A.URBAN");%>
        <tr>
            <td rowspan="3">urban</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN,  COLUMN_INDEX_JT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("28", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("29", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"><%=AppConstants.format3(indicator)%></td>
            <% dataToExport.put("30", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>

        <!--b. intreruperi neplanificate cauzate de forta majora-->
        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "i.FORTA_MAJORA","=", new Integer( 1)); %>
        <%  mDinNomInst = nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori INCIDENT SAIDI.B.RURAL");%>

        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.addOrSetFilter("AND", "i.FORTA_MAJORA","=", new Integer( 1)); %>
        <%  addRuralCondition( nrConsumatoriAfectatiOriDurataIncidentDinFi); %>
        <%  mDinFise = nrConsumatoriAfectatiOriDurataIncidentDinFi.getListOfArrays("Get numar Consumatori INCIDENT Din FI SAIDI.B.RURAL");%>


        <%  nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.FORTA_MAJORA", "=", new Integer( 1)); %>
        <%  mDer = nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori DER SAIDI.B.RURAL");%>

        <tr>
            <td rowspan="18">SAIDI</td>
            <td rowspan="6">b. intreruperi neplanificate cauzate de forta majora</td>
            <td rowspan="3">rural</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIDIJT( centre, mDinNomInst, mDinFise, mDer, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("31", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_MT, c = getConstanta(i+1, rc));  %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("32", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("33", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>

        <%  mDinNomInst = nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori INCIDENT SAIDI.B.URBAN");%>
        <%
            addUrbanCondition( nrConsumatoriAfectatiOriDurataIncidentDinFi);
            mDinFise = nrConsumatoriAfectatiOriDurataIncidentDinFi.getListOfArrays("Get numar Consumatori INCIDENT Din FI SAIDI.B.URBAN");
        %>

        <%  mDer = nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori DER SAIDI.B.URBAN");%>

        <!--intreruperi neplanificate cauzate de forta majora URBAN-->
        <tr>
            <td rowspan="3">urban</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIDIJT( centre, mDinNomInst, mDinFise, mDer, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("34", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_MT, c = getConstanta(i+1, rc));  %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("35", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("36", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>



        <%
            System.out.println("[EMID] SAIDI C.");
        %>

        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.removeFilter("i.FORTA_MAJORA");  %>
        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.removeFilter("nGrupeCauze.COD");  %>
        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetStringCriteria("AND", "nGrupeCauze.COD", "="+ NomConstants.COD_CAUZA_GRUPA_INTRERUPERI_USERI); %>
        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetStringCriteria("AND", "nCauze.COD", " IN (91, 92, 93) "); %>
        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "i.FORTA_MAJORA", "=", new Integer(0)); //si nu este forta majora %>
        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "i.DURATA_INCIDENT", ">", new Integer(3));  %>
        <%  mDinNomInst = nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori INC SAIDI.C.RURAL");%>

        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.removeFilter("i.FORTA_MAJORA");  %>
        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.removeFilter("nGrupeCauze.COD");  %>
        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.addOrSetStringCriteria("AND", "nGrupeCauze.COD", "="+ NomConstants.COD_CAUZA_GRUPA_INTRERUPERI_USERI); %>
        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.addOrSetStringCriteria("AND", "nCauze.COD", " IN (91, 92, 93) "); %>
        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.addOrSetFilter("AND", "i.FORTA_MAJORA", "=", new Integer(0)); //si nu este forta majora %>
        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.addOrSetFilter("AND", "i.DURATA_INCIDENT", ">", new Integer(3));  %>
        <%  addRuralCondition( nrConsumatoriAfectatiOriDurataIncidentDinFi); %>
        <%  mDinFise = nrConsumatoriAfectatiOriDurataIncidentDinFi.getListOfArrays("Get numar Consumatori INCIDENT Din FI SAIDI.C.RURAL");%>

        <%  nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.FORTA_MAJORA", "=", new Integer(0)); %>
        <%  nrConsumatoriAfectatiDerOriDurataDer.addOrSetStringCriteria("AND (", "d.CAUZA", "="+ DeranjamentConstants.INDEX_CAUZA_RAPORT_INDICATORI_PUNCTUL_B + " OR d.APARTENENTA_INST = " + Deranjament.APARTINE_CONSUMATOR + ')');  %>
        <%  mDer = nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori DER SAIDI.C.RURAL");%>

        <!--intreruperi neplanificate cauzate de utilizatori RURAL-->
        <tr>
            <td rowspan="6">c. intreruperi neplanificate cauzate de utilizatori</td>
            <td rowspan="3">rural</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIDIJT( centre, mDinNomInst, mDinFise, mDer, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("37", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, COLUMN_INDEX_MT, LFInfoConstants.MEDIU_RURAL, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("38", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("39", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>

        <%  mDinNomInst = nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori INC SAIDI.C.URBAN");%>
        <%  mDer = nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori DER SAIDI.C.URBAN");%>

        <%  addUrbanCondition( nrConsumatoriAfectatiOriDurataIncidentDinFi); %>
        <%  mDinFise = nrConsumatoriAfectatiOriDurataIncidentDinFi.getListOfArrays("Get numar Consumatori INCIDENT Din FI SAIDI.C.URBAN");%>

        <!--intreruperi neplanificate cauzate de utilizatori URBAN-->
        <tr>
            <td rowspan="3">urban</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIDIJT( centre, mDinNomInst, mDinFise, mDer, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, c = getConstanta(i+1, rc)) ;%>
            <td title="<%=indicator%>" > <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("40", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("41", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("42", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>


        <%
            System.out.println("[EMID] SAIDI D.");
        %>

        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.removeFilter("i.FORTA_MAJORA");%>
        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.removeFilter("i.DURATA_INCIDENT");%>
        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.removeFilter("nGrupeCauze.COD");%>
        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.removeFilter("nCauze.COD");%>
        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.addStringCriteria( "AND NOT (i.FORTA_MAJORA=1)" ); %>
        <%  nrConsumatoriAfectatiPTOriDurataIntreruperePT.addStringCriteria( "AND NOT (i.FORTA_MAJORA=0 AND i.DURATA_INCIDENT > 3 AND nGrupeCauze.COD = " + NomConstants.COD_CAUZA_GRUPA_INTRERUPERI_USERI + " AND nCauze.COD IN (91, 92, 93))" ); %>
        <%  mDinNomInst = nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori INC SAIDI.C.URBAN");%>

        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.removeFilter("i.FORTA_MAJORA");%>
        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.removeFilter("i.DURATA_INCIDENT");%>
        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.removeFilter("nGrupeCauze.COD");%>
        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.removeFilter("nCauze.COD");%>
        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.addStringCriteria( "AND NOT (i.FORTA_MAJORA=1)" ); %>
        <%  nrConsumatoriAfectatiOriDurataIncidentDinFi.addStringCriteria( "AND NOT (i.FORTA_MAJORA=0 AND i.DURATA_INCIDENT > 3 AND nGrupeCauze.COD = " + NomConstants.COD_CAUZA_GRUPA_INTRERUPERI_USERI + " AND nCauze.COD IN (91, 92, 93))" ); %>
        <%  addRuralCondition( nrConsumatoriAfectatiOriDurataIncidentDinFi); %>
        <%  mDinFise = nrConsumatoriAfectatiOriDurataIncidentDinFi.getListOfArrays( "Get numar Consumatori INC SAIDI.C.RURAL");%>

        <%  nrConsumatoriAfectatiDerOriDurataDer.removeFilter("d.FORTA_MAJORA"); %>
        <%  nrConsumatoriAfectatiDerOriDurataDer.removeFilter("d.CAUZA"); %>
        <%  nrConsumatoriAfectatiDerOriDurataDer.addOrSetStringCriteria("AND NOT (", "d.CAUZA", "="+ DeranjamentConstants.INDEX_CAUZA_RAPORT_INDICATORI_PUNCTUL_B + " OR d.APARTENENTA_INST = " + Deranjament.APARTINE_CONSUMATOR + " AND d.FORTA_MAJORA=0)");  %>
        <%  mDer = nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_RURAL)).getListOfArrays("Get numar Consumatori DER SAIDI.C.URBAN");%>

        <!--intreruperi neplanificate cauzate de utilizatori RURAL-->
        <tr>
            <td rowspan="6">d. intreruperi neplanificate exclusiv intreruperile de la punctele b si c</td>
            <td rowspan="3">rural</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIDIJT( centre, mDinNomInst, mDinFise, mDer, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("43", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, COLUMN_INDEX_MT, LFInfoConstants.MEDIU_RURAL, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>" > <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("44", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, COLUMN_INDEX_IT, LFInfoConstants.MEDIU_RURAL, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("45", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>


        <%  mDinNomInst = nrConsumatoriAfectatiPTOriDurataIntreruperePT.addOrSetFilter("AND", "lfInfo.MEDIU", "=", new Integer(LFInfoConstants.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori INC SAIDI.C.URBAN");%>
        <%  mDer = nrConsumatoriAfectatiDerOriDurataDer.addOrSetFilter("AND", "d.MEDIUL", "=", new Integer(Deranjament.MEDIU_URBAN)).getListOfArrays("Get numar Consumatori DER SAIDI.C.URBAN");%>

        <%  addUrbanCondition( nrConsumatoriAfectatiOriDurataIncidentDinFi); %>
        <%  mDinFise = nrConsumatoriAfectatiOriDurataIncidentDinFi.getListOfArrays( "Get numar Consumatori INC SAIDI.C.URBAN");%>
        <tr>
            <td rowspan="3">urban</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <% indicator = getSAIDIJT( centre, mDinNomInst, mDinFise, mDer,  mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("46", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>
        <tr>
            <td><b>MT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise,  mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_MT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("47", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>
        <tr>
            <td><b>IT</b></td>
            <% indicator = getSAIDI( centre, mDinNomInst, mDinFise, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_IT, c = getConstanta(i+1, rc)); %>
            <td title="<%=indicator%>"> <%=AppConstants.format3(indicator)%> </td>
            <% dataToExport.put("48", new Double(indicator));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>

        <%}%>

        <%
            double AIT_JT = 0;
            double AIT_MT = 0;
            double AIT_IT = 0;
        %>

        <%if( !skipENS){%>
        <%System.out.println("[EMID] ENS");%>

        <%
            final double ENS_JT = ENS.addOrSetStringCriteria("AND", "NUMAR_CONSUMATORI_JT", " > 0").getDoubleResult()/60.0;

            ENS.removeFilter("NUMAR_CONSUMATORI_JT");
            final double ENS_MT = ENS.addOrSetStringCriteria("AND", "NUMAR_CONSUMATORI_MT", " > 0").getDoubleResult()/60.0;

            ENS.removeFilter("NUMAR_CONSUMATORI_MT");
            final double ENS_IT = ENS.addOrSetStringCriteria("AND", "NUMAR_CONSUMATORI_IT", " > 0").getDoubleResult()/60.0;
            //v1 :
//            final double Ad = AdEntryAccessDB.getAdMediu( filiala.getId(), dataStart, dataStop);
            //v2 :
            final double Ad = _ad;


            AIT_JT = Ad != 0 ? 8760*60*ENS_JT/Ad : -1; 
            AIT_MT = Ad != 0 ? 8760*60*ENS_MT/Ad : -1;
            AIT_IT = Ad != 0 ? 8760*60*ENS_IT/Ad : -1;
        %>
        
        <tr>
            <td rowspan="1">ENS</td>
            <td rowspan="1">toate cauzele</td>
            <td rowspan="1">cumulat</td>
            <td rowspan="1">cumulat</td>
            <td><b>IT</b></td>
            <td><%=AppConstants.format3(applyC(ENS_IT, (c = getConstanta(i + 1, rc))))%></td>
            <% dataToExport.put("49", new Double(applyC( ENS_IT, ( c = getConstanta(i+1, rc)))));%>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>
        <%}%>


        <%if ( !skipAIT){ %>
        <tr>
            <td rowspan="1">AIT</td>
            <td rowspan="1">toate cauzele</td>
            <td rowspan="1">cumulat</td>
            <td rowspan="1">cumulat</td>
            <td><b>IT</b></td>
            <td>
                <% c = getConstanta(i+1, rc);%>
                <% if( AIT_IT != -1 ){%>
                    <%=AppConstants.format3(applyC(AIT_IT, c))%>
                    <% dataToExport.put("50", new Double(applyC(AIT_IT, c)));%>
                <%}else{%>
                    Ad=0!
                <% dataToExport.put("50", new Double(0));%>
                <%}%>
            </td>
            <td><%=++i%></td>
            <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>

        </tr>
        <%}%>

        <tr>
            <td rowspan="6">Numar de utilizatori deserviti</td>
            <td rowspan="6">N/A</td>
            <td rowspan="3">rural</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <td><%=getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_JT, ( c = getConstanta(i+1, rc)))%></td>
            <% dataToExport.put("51", new Long(getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_JT, ( c = getConstanta(i+1, rc)))));%>
            <td><%=++i%></td>
             <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <td><%=getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_MT, ( c = getConstanta(i+1, rc)))%></td>
            <% dataToExport.put("52", new Long(getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_MT, ( c = getConstanta(i+1, rc)))));%>
            <td><%=++i%></td>
             <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
            <td><%=getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_IT, ( c = getConstanta(i+1, rc)))%></td>
            <% dataToExport.put("53", new Long(getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_RURAL, COLUMN_INDEX_IT, ( c = getConstanta(i+1, rc)))));%>
            <td><%=++i%></td>
             <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>

        <tr>
            <td rowspan="3">urban</td>
            <td rowspan="3">toti</td>
            <td><b>JT</b></td>
            <td><%=getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_JT, ( c = getConstanta(i+1, rc)))%></td>
            <% dataToExport.put("54", new Long( getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_JT, ( c = getConstanta(i+1, rc)))));%>
            <td><%=++i%></td>
             <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>MT</b></td>
            <td><%=getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_MT, ( c = getConstanta(i+1, rc)))%></td>
            <% dataToExport.put("55", new Long(getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_MT, ( c = getConstanta(i+1, rc)))));%>
            <td><%=++i%></td>
             <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
        <tr>
            <td><b>IT</b></td>
            <td><%=getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_IT, ( c = getConstanta(i+1, rc)))%></td>
            <% dataToExport.put("56", new Long(getTotalConsumatoriDeserviti( centre, mTotalConsumatori, LFInfoConstants.MEDIU_URBAN, COLUMN_INDEX_IT, ( c = getConstanta(i+1, rc)))));%>
            <td><%=++i%></td>
             <% if( editMode){%>
                <td>
                    <input type="text" class="clasu" name="c<%=i%>" value="<%=c%>">
                </td>
            <% } %>
        </tr>
    </tbody>
</table>
<%}%>
<% if( editMode){ %>
    </form>
<% } %>

<%if(_ad > 0) {%>
<div style="font-size:10px">
    Nota: <br>
    <li>
        La a. (intreruperi planificate) - include lucrarile programate cu intreruperea consumatorilor
    <li>
        La b. (intreruperi neplanificate cauzate de forta majora) -  include incidentele care in F.I. au bifata "Forta majora"
        <!--si Cauza Grupa: Grupa = 8. Conditii meteorologice deosebite sau calamitati naturale-->
    </li>
    <li>La c. (intreruperi neplanificate cauzate de utilizatori) - sunt incluse incidentele care NU au bifata "Forta majora" si au o durata > 3 minute
	      SI AU CAUZA 9 - CAUZE EXTERIOARE GESTIONARULUI, punctele : 9.1, 9.2, 9.3;
          Plus deranjamentele care au selectata cauza: "Sigurante necalibrate la abonat" SAU
	      La "Apartenenta instalatiilor in care a fost localizata cauza deranjamentului" este selectat "Consumator"
    </li>

    <li>La d. (intreruperi neplanificate exclusiv intreruperile de la punctele b si c) - restul de incidente si deranjamente </li>
</div>
<%} else {%>
<div style="font-size:10px">
    Inserati o valoare pentru constanta Ad pentru vizualizarea raportului !!
</div>
<%}%>

<%
    if( ObjectUtils.getIntValue(request.getParameter("toExport"), 0) == 1  && _ad != 0){

            final String root = AppConstants.PUBLIC_RESOURCE_PATH + File.separator + "raport";
            final String folder = _df.format( new java.util.Date());
            //cleanup...
            final File[]folders = new File( root).listFiles();
            if( folders != null) for (int i = 0; i < folders.length; i++) {
                final File file = folders[i];
                if( !file.getName().equals( folder)){
                    final File[]d=file.listFiles();
                    if( d!=null) for (int j = 0; j < d.length; j++) {
                        final File file1 = d[j];
                        file1.delete();
                    }
                    file.delete( );  //cleanup
                }
            }

            File f = new File( root, folder);
            if (!f.exists()) f.mkdir();

            final String fileName = "Raport indicatori - " + System.currentTimeMillis() + ".xls";
            final String privatePath = root + File.separator + folder + File.separator + fileName;
            final String templatePath = GlobalAppConstants.PRIVATE_PATH + File.separator + "template" + File.separator + "Raport Indicatori.xls";

          publicPath = AppConstants.WEB_RESOURCE_PATH + "/raport/" + folder + '/' + fileName;

            f = new File(privatePath);
            if (f.exists()) {
                f.delete();
            }

          final RaportIndicatoriDirtyExcelExporter exporter = new RaportIndicatoriDirtyExcelExporter();
          exporter.begin(templatePath, privatePath);

        try{
          exporter.export(dataToExport);
        } catch(Throwable th){
            LOG.debug("de aici sare - " + th);
        }

          exporter.end();
      }
%>

<%! private static final int COLUMN_INDEX_JT = 1; %>
<%! private static final int COLUMN_INDEX_MT = 2; %>
<%! private static final int COLUMN_INDEX_IT = 3; %>


<%! private long getLong(final String codCentru, final List matrix, final int columnIndex){
        long result = 0;
        try {
            for (int i = 0; i < matrix.size(); i++) {
                final Object[] arr = (Object[]) matrix.get(i);

                final String _codCentru = (String )arr[0];

                if( codCentru.equalsIgnoreCase( _codCentru)){
                    result = Long.parseLong( arr[ columnIndex].toString());
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return result;
}%>

<%! private long getLong(final String codCentru, final int mediu, final List matrix,  final int columnIndex){
        long result = 0;
        try {
            for (int i = 0; i < matrix.size(); i++) {
                final Object[] arr = (Object[]) matrix.get(i);

                final String _codCentru = (String )arr[0];
                final int _mediu = Integer.parseInt (arr[1] != null ? arr [ 1].toString() : "-1");

                if( codCentru.equalsIgnoreCase( _codCentru) && _mediu == mediu){
                    result = Long.parseLong( arr[ columnIndex].toString());
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return result;
}%>

<%! private void printMatrix(final List matrix){
    for (int i = 0; i < matrix.size(); i++) {
        final Object[] arr = (Object[]) matrix.get(i);
        for (int j = 0; j < arr.length; j++) {
            final Object o = arr[j];
            System.out.print( o + ", ");
        }
        System.out.println("");
    }

}%>

<%! private long getConsumatoriAfectati(final String codCentru, final List matrix, final int columnIndex){
        return getLong( codCentru, matrix, columnIndex);
}%>

<%! private long getTotalConsumatori(final String codCentru, final List matrix, final int columnIndex){
        return getLong( codCentru, matrix, columnIndex);
}%>

<%! private long getProdus(final String codCentru, final List matrix, final int columnIndex){
        return getLong( codCentru, matrix, columnIndex);
}%>


<%!
    private long getTotalConsumatoriDeserviti( final Category[] centre,
                             final List matrixTotalConsumatori,
                             final int mediu,
                             final int columnIndex,
                             final double c
    ){

    long numarTotalConsumatori = 0;
    for (int j = 0; j < centre.length; j++) {
        final Category centru = centre[j];
        numarTotalConsumatori += getLong( centru.getCodSap(), mediu, matrixTotalConsumatori, columnIndex + 1) * c;
    }
    return numarTotalConsumatori;
}
%>

<%!
    /**
        matrixConsumatoriAfectatiIncidenteCuPosturi - sume grupate pe centre din fi cu posturi
        matrixConsumatoriAfectatiIncidenteDinFi - sume grupate pe centre din fi
    */
    private double getSAIFI2( final Category[] centre,
                             final List matrixConsumatoriAfectatiIncidenteCuPosturi,
                             final List matrixConsumatoriAfectatiIncidenteDinFi,
                             final List matrixTotalConsumatori,
                             final int mediu,
                             final int columnIndex,
                             final double c
    ){
        System.out.println("[EMID] SAIFI");
        System.out.println("[EMID] MATRIX Incidente matrixConsumatoriAfectatiIncidenteCuPosturi");
        printMatrix( matrixConsumatoriAfectatiIncidenteCuPosturi);
        System.out.println("[EMID] MATRIX Incidente matrixConsumatoriAfectatiIncidenteDinFi");
        printMatrix( matrixConsumatoriAfectatiIncidenteDinFi);


        double SAIFI = 0.0;
        long numarConsumatoriAfectati = 0;
        long numarTotalConsumatori = 0;
        for (int j = 0; j < centre.length; j++) {
            final Category centru = centre[j];
            numarConsumatoriAfectati +=
                    getConsumatoriAfectati( centru.getCodSap(), matrixConsumatoriAfectatiIncidenteCuPosturi, columnIndex) +
                    getConsumatoriAfectati( centru.getCodSap(), matrixConsumatoriAfectatiIncidenteDinFi, columnIndex);

            numarTotalConsumatori += getLong( centru.getCodSap(), mediu, matrixTotalConsumatori, columnIndex + 1);
        }

        System.out.println("[EMID] numarConsumatoriAfectati = " + numarConsumatoriAfectati);
        System.out.println("[EMID] numarTotalConsumatori = " + numarTotalConsumatori);

        if( numarTotalConsumatori != 0){
            SAIFI = (1.0 * numarConsumatoriAfectati) / numarTotalConsumatori;
        }
        return applyC( SAIFI, c);
}%>

<%! private double getSAIFIJT( final Category[] centre,
                               final List matrixConsumatoriAfectatiIncidente,
                               final List matrixConsumatoriAfectatiIncidenteDinFI,
                               final List matrixConsumatoriAfectatiDeranjamente,
                               final List matrixTotalConsumatori,
                               final int mediul,
                               final double c
){
        final int columnIndex = COLUMN_INDEX_JT;
        double SAIFI = 0.0;

        System.out.println("[EMID] MATRIX INCIDENTE");
        printMatrix(matrixConsumatoriAfectatiIncidente);

        System.out.println("[EMID] MATRIX DERANJAMENTE");
        printMatrix(matrixConsumatoriAfectatiDeranjamente);
        long numarConsumatoriAfectati = 0;
        long numarTotalConsumatori = 0;
        for (int j = 0; j < centre.length; j++) {
            final Category centru = centre[j];
            final long numarConsumatoriAfectatiPerCentruIncidente = getConsumatoriAfectati( centru.getCodSap(), matrixConsumatoriAfectatiIncidente, columnIndex);
            final long numarConsumatoriAfectatiPerCentruIncidenteDinFi = getConsumatoriAfectati( centru.getCodSap(), matrixConsumatoriAfectatiIncidenteDinFI, columnIndex);
            final long numarConsumatoriAfectatiPerCentruDeranjamente = getConsumatoriAfectati( centru.getCodSap(), matrixConsumatoriAfectatiDeranjamente, columnIndex);

            numarConsumatoriAfectati += (numarConsumatoriAfectatiPerCentruIncidente + numarConsumatoriAfectatiPerCentruIncidenteDinFi + numarConsumatoriAfectatiPerCentruDeranjamente);
            

            numarTotalConsumatori += getLong( centru.getCodSap(), mediul, matrixTotalConsumatori, columnIndex + 1);
        }

        if( numarTotalConsumatori != 0){
            SAIFI = (1.0 * numarConsumatoriAfectati) / numarTotalConsumatori;
           
        }
        return applyC( SAIFI, c);
}%>


<%! private double getSAIDI( final Category[] centre,
                             final List matrixConsumatoriPTOriDurataIndisponibilitatePT,
                             final List matrixConsumatoriPTOriDurataIncident,
                             final List matrixTotalConsumatori,
                             final int mediul,
                             final int columnIndex,
                             final double c
                             ){
        double SAIDI = 0.0;
        long produs = 0;
        long numarTotalConsumatori = 0;

        System.out.println("[EMID] SAIDI Matrix Npt*Dpt");
        printMatrix( matrixConsumatoriPTOriDurataIndisponibilitatePT);
        for (int j = 0; j < centre.length; j++) {
            final Category centru = centre[j];
            produs += getProdus( centru.getCodSap(), matrixConsumatoriPTOriDurataIndisponibilitatePT, columnIndex);
            produs += getProdus( centru.getCodSap(), matrixConsumatoriPTOriDurataIncident, columnIndex);
            numarTotalConsumatori += getLong( centru.getCodSap(), mediul, matrixTotalConsumatori, columnIndex + 1);
        }

        System.out.println("[EMID] SAIDI : produs = " + produs);
        System.out.println("[EMID] SAIDI : numarTotalConsumatori = " + numarTotalConsumatori);

        if( numarTotalConsumatori != 0){
            SAIDI = (1.0 * produs) / numarTotalConsumatori;
        }
        return applyC( SAIDI, c);
}%>

<%! private double getSAIDIJT( final Category[] centre,
                               final List matrixConsumatoriPTOriDurataIndisponibilitatePT,
                               final List matrixConsumatoriPTOriDurataIncident,
                               final List matrixConsumatoriDerOriDurataDer,
                               final List matrixTotalConsumatori,
                               final int mediul,
                               final double c
){

        final int columnIndex = COLUMN_INDEX_JT;
        double SAIDI = 0.0;
        long produsIncident = 0;
        long produsDeranjament = 0;
        long numarTotalConsumatori = 0;


        System.out.println("[EMID] SAIDI.JT matrix matrixConsumatoriPTOriDurataIndisponibilitatePT:");
        printMatrix( matrixConsumatoriPTOriDurataIndisponibilitatePT);

        System.out.println("[EMID] SAIDI.JT matrix matrixConsumatoriPTOriDurataIncident:");
        printMatrix( matrixConsumatoriPTOriDurataIncident);

        System.out.println("[EMID] SAIDI.JT matrix matrixConsumatoriDerOriDurataDer:");
        printMatrix( matrixConsumatoriDerOriDurataDer);

        for (int j = 0; j < centre.length; j++) {
            final Category centru = centre[j];
            produsIncident += (
                    getProdus( centru.getCodSap(), matrixConsumatoriPTOriDurataIndisponibilitatePT, columnIndex) +
                    getProdus( centru.getCodSap(), matrixConsumatoriPTOriDurataIncident, columnIndex)
            );
            produsDeranjament += getProdus( centru.getCodSap(), matrixConsumatoriDerOriDurataDer, columnIndex);
            numarTotalConsumatori += getLong( centru.getCodSap(), mediul, matrixTotalConsumatori, columnIndex + 1);
        }

        if( numarTotalConsumatori != 0){
            SAIDI = (1.0 * produsIncident + 1.0 * produsDeranjament) / numarTotalConsumatori;
        }

        return applyC( SAIDI, c);
}%>


<%! private double applyC( double indicator, final double c){
        if( showTestValues) {
            indicator = 1;
        }
        indicator = indicator * c;
        return indicator;
}%>


<%!
    private void addRuralCondition(final ReportStatement statement){
//        statement.addOrSetStringCriteria("AND", "i.SECTIE_ID", " IN ( " + -10 + ")");
//        statement.addOrSetStringCriteria("AND", "i.SECTIE_ID", " IN ( " + idCentreRural + ")");
        statement.addOrSetStringCriteria("AND", "i.MEDIU", "="+LFInfoConstants.MEDIU_RURAL);
    }

    private void addUrbanCondition(final ReportStatement statement){
//        statement.addOrSetStringCriteria("AND", "i.SECTIE_ID", " IN ( " + -10 + ")");
//        statement.addOrSetStringCriteria("AND", "i.SECTIE_ID", " NOT IN ( " + idCentreRural + ")");
        statement.addOrSetStringCriteria("AND", "i.MEDIU", "="+LFInfoConstants.MEDIU_URBAN);
    }
%>


<%!
    public double getConstanta( final int index, final RC rc){
        switch ( index){
            case 1: return rc.getC1();
            case 2: return rc.getC2();
            case 3: return rc.getC3();
            case 4: return rc.getC4();
            case 5: return rc.getC5();
            case 6: return rc.getC6();
            case 7: return rc.getC7();
            case 8: return rc.getC8();
            case 9: return rc.getC9();
            case 10: return rc.getC10();
            case 11: return rc.getC11();
            case 12: return rc.getC12();
            case 13: return rc.getC13();
            case 14: return rc.getC14();
            case 15: return rc.getC15();
            case 16: return rc.getC16();
            case 17: return rc.getC17();
            case 18: return rc.getC18();
            case 19: return rc.getC19();
            case 20: return rc.getC20();
            case 21: return rc.getC21();
            case 22: return rc.getC22();
            case 23: return rc.getC23();
            case 24: return rc.getC24();
            case 25: return rc.getC25();
            case 26: return rc.getC26();
            case 27: return rc.getC27();
            case 28: return rc.getC28();
            case 29: return rc.getC29();
            case 30: return rc.getC30();
            case 31: return rc.getC31();
            case 32: return rc.getC32();
            case 33: return rc.getC33();
            case 34: return rc.getC34();
            case 35: return rc.getC35();
            case 36: return rc.getC36();
            case 37: return rc.getC37();
            case 38: return rc.getC38();
            case 39: return rc.getC39();
            case 40: return rc.getC40();
            case 41: return rc.getC41();
            case 42: return rc.getC42();
            case 43: return rc.getC43();
            case 44: return rc.getC44();
            case 45: return rc.getC45();
            case 46: return rc.getC46();
            case 47: return rc.getC47();
            case 48: return rc.getC48();
            case 49: return rc.getC49();
            case 50: return rc.getC50();
            case 51: return rc.getC51();
            case 52: return rc.getC52();
            case 53: return rc.getC53();
            case 54: return rc.getC54();
            case 55: return rc.getC55();
            case 56: return rc.getC56();
            case 57: return rc.getC57();
            case 58: return rc.getC58();
            case 59: return rc.getC59();
            case 60: return rc.getC60();
        }

        return 1;
    }
%>


<%
    final long tStop = System.currentTimeMillis();

    System.out.println("[EMID] Timp executie:" + (tStop - tStart) + " ms");
%>

<span style="font-size:10px; float:right;"><%=tStop - tStart%></span>

<script type="text/javascript">
    <% if ( publicPath != null){ %>

        setTimeout(function(){
            window.location = '<%=publicPath%>';
        }, 500);

    <% } %>
</script>