<%@ page import="ro.emid.common.db.AccessDB" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationController" %>
<%@ page import="ro.emid.common.utils.sort.SortData" %>
<%@ page import="ro.emid.common.db.LucrareProgramataAccessDB" %>
<%@ page import="java.text.MessageFormat" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.List" %>
<%@ page import="ro.emid.lpod.obj.*" %>
<%@ page import="ro.emid.common.utils.LucrareProgramataUtils" %>
<%@ page import="ro.emid.common.types.NivelTensiune" %>
<%@ page import="ro.emid.common.utils.*" %>
<%@ page import="ro.emid.common.types.Adresa" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationData" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.utils.sort.SortController" %>


<%

    FSC fscRaport = FSCUtils.getFsc(request);

    final String mediu =  ObjectUtils.getStringValue( request.getParameter("mediu"));
    final String snt =  ObjectUtils.getStringValue( request.getParameter("nt"));

    final String durataCond1 =  ObjectUtils.getStringValue( request.getParameter("durataCond1"));
    final String durataCond2 =  ObjectUtils.getStringValue( request.getParameter("durataCond2"));

    String durata =  ObjectUtils.getStringValue( request.getParameter("durata"));
    if( StringUtils.isZeroLength( durata)) durata = "durata_intr";  //default

    final String durataValue1 =  ObjectUtils.getStringValue( request.getParameter("durataValue1"));
    final String durataValue2 =  ObjectUtils.getStringValue( request.getParameter("durataValue2"));
    final String um_timp =  ObjectUtils.getStringValue( request.getParameter("um_timp"));

    Date dataStart = ObjectUtils.getDateValue( request.getParameter("data_start"), AppConstants.FORMAT_DATA_TIME);
    if( dataStart == null) dataStart = getDefaultStartDate();

    Date dataStop = ObjectUtils.getDateValue(request.getParameter("data_stop"), AppConstants.FORMAT_DATA_TIME);
    if( dataStop == null) dataStop = getDefaultStopDate();

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

    String durataInterval =  ObjectUtils.getStringValue( request.getParameter("durataInterval"));
    if( StringUtils.isZeroLength( durataInterval)) durataInterval = "durata_progr"; //default


    final PaginationData pd = PaginationController.getPaginationData( request, 20);
    final SortData sd = SortController.getSortData( request, "SUCURSALA", "ASC");

    final StringBuffer sqlCond = new StringBuffer();

    if( fscRaport.getFilialaId() > 0){
        sqlCond.append( " AND lp.FILIALA_ID = " ).append(fscRaport.getFilialaId());
    }

    if( fscRaport.getSucursalaId() > 0){
        sqlCond.append( " AND lp.SUCURSALA_ID = " ).append(fscRaport.getSucursalaId());
    }

    if( fscRaport.getCentruId() > 0){
        sqlCond.append( " AND lp.CENTRU_ID = " ).append( fscRaport.getCentruId());
    }

    if( Mediu.is(mediu, Mediu.URBAN) || Mediu.is( mediu, Mediu.RURAL)){
        sqlCond.append( " AND lp.MEDIU = '" ).append( mediu).append("' ");
    }

    if( NivelTensiune.is(snt, NivelTensiune.JT) || NivelTensiune.is( snt, NivelTensiune.MT) || NivelTensiune.is( snt, NivelTensiune.IT)){
        sqlCond.append( " AND lp.NIVEL_TENSIUNE = '" ).append( snt).append("' ");
    }


    String durataColumn = "";
    if( durata.equals("durata_intr")){
        durataColumn = "lp.DURATA_INTR";
    }else if( durata.equals("durata_lucrare")){
        durataColumn = "lp.DURATA_LUCR";
    }else if( durata.equals("durata_progr")){
        durataColumn = "lp.DURATA_PROGR";
    }

    if( !StringUtils.isZeroLength( durataCond1) && !StringUtils.isZeroLength(durataValue1)){
        final String durataValue = (um_timp.equals("ore") ? durataValue1 + "*60" : durataValue1);
        sqlCond.append( " AND ").append( durataColumn).append(' ').append( durataCond1).append(' ').append( durataValue).append(' ');
    }

    if( !StringUtils.isZeroLength( durataCond2) && !StringUtils.isZeroLength( durataValue2)){
        final String durataValue = (um_timp.equals("ore") ? durataValue2 + "*60" : durataValue2);
        sqlCond.append( " AND ").append( durataColumn).append(' ').append( durataCond2).append(' ').append( durataValue).append(' ');
    }

    if( durataInterval.equals("durata_intr")){
        durataColumn = "lp.DATA_INTR_START";
    }else if( durataInterval.equals("durata_lucrare")){
        durataColumn = "lp.DATA_START";
    }else if( durataInterval.equals("durata_progr")){
        durataColumn = "lp.DATA_PROGRAMARE_START";
    }

    if( dataStart != null){
        sqlCond.append(" AND ").append(" ( ( ").append(durataColumn).append(" >= TO_DATE('").append(AppConstants.format(value_data_start)).append("', 'DD.MM.YYYY HH24:MI' ) ");
    }

    if( dataStop != null){
        sqlCond.append(" AND ").append(durataColumn).append(" <= TO_DATE('").append(AppConstants.format(value_data_stop)).append("', 'DD.MM.YYYY HH24:MI' ) ").append(" ) ");
    }

    // cautam si pe intervale cu aceleasi conditii
    sqlCond.append(" OR (( select count(*) " )
            .append(" FROM LPD_INTERVAL_LUCRARE intv ")
            .append(" WHERE "                         )
            .append(  " (intv.DATA_START BETWEEN TO_DATE('" +  value_data_start + "', 'DD.MM.YYYY HH24:MI' ) AND TO_DATE('" +  value_data_stop  + "', 'DD.MM.YYYY HH24:MI' ) " )
            .append(   " OR intv.DATA_STOP  BETWEEN TO_DATE('" +  value_data_start + "', 'DD.MM.YYYY HH24:MI' ) AND TO_DATE('" +  value_data_stop  + "', 'DD.MM.YYYY HH24:MI' ) " )
            .append(   " OR TO_DATE('" +  value_data_start + "', 'DD.MM.YYYY HH24:MI' )  BETWEEN intv.DATA_START AND intv.DATA_STOP) ");

    if( durataInterval.equals("durata_intr")){
        sqlCond.append(   "AND intv.TIP = 'II' ");
    }else if( durataInterval.equals("durata_lucrare")){
        sqlCond.append(   "AND intv.TIP = 'IL' ");
    }else if( durataInterval.equals("durata_progr")){
        sqlCond.append(   "AND intv.TIP = 'ILPR' ");
    }else{
        throw new RuntimeException("durataColumn nu a putut fi determinata:" + durataInterval);
    }
    sqlCond.append(   " AND intv.FK_ID_LUCRARE = lp.id) > 0) " ).append(" ) ");

    final String baseSql =
            new StringBuffer().
                    append("SELECT \n").
                    append("    lp.ID,\n").
                    append("    lp.NUMAR,\n").
                    append("    lp.DATA_INSERT,\n").
                    append("    s.NAME SUCURSALA,\n").
                    append("    c.NAME CENTRU,\n").
                    append("    lp.NIVEL_TENSIUNE NT,\n").
                    append("    lp.MEDIU,\n").
                    append("    a.DESCRIERE ANSAMBLU,\n").
                    append("    statie.DESC_LF STATIE ,\n").
                    append("    linie.DESC_LF LINIE,\n").
                    append("    post.DESC_LF POST,\n").
                    append("    trafo.DESC_EQ TRAFO,\n").
                    append("    bobina.DESC_EQ BOBINA,\n").
                    append("    celula.DESC_EQ CELULA,\n").
                    append("    bara.DESC_EQ BARA,\n").
                    append("    der.DESC_EQ DER,\n").
                    append("    lp.EXPLICATII,\n").
                    append("    lp.CAT_INSTALATII,\n").
                    append("    lp.INSTALATIA,\n").
                    append("    lp.DEN_INST,\n").
                    append("    lp.UTILIZATORI_IT,\n").
                    append("    lp.UTILIZATORI_MT,\n").
                    append("    lp.UTILIZATORI_JT,\n").
                    append("    lp.DATA_PROGRAMARE_START,\n").
                    append("    lp.DATA_PROGRAMARE_STOP,\n").
                    append("    lp.DURATA_PROGR,\n").
                    append("    lp.DATA_INTR_START,\n").
                    append("    lp.DATA_INTR_STOP,\n").
                    append("    lp.DURATA_INTR, \n").
                    append("    (SELECT COUNT(*) FROM LPD_ADRESA a WHERE a.FK_ID_LUCRARE = lp.ID ) CNT_A, \n").
                    append("    (SELECT COUNT(*) FROM LPD_INTERVAL_LUCRARE i WHERE i.TIP = ''ILPR'' AND i.FK_ID_LUCRARE = lp.ID ) CNT_IP, \n").
                    append("    (SELECT COUNT(*) FROM LPD_INTERVAL_LUCRARE ic WHERE ic.TIP = ''II'' AND ic.FK_ID_LUCRARE = lp.ID ) CNT_IC \n").
                    append("FROM LPD_LUCRARE_PROGRAMATA lp \n").
                    append("    inner join categories f ON ( lp.FILIALA_ID = f.ID)\n").
                    append("    inner join categories s ON ( lp.SUCURSALA_ID = s.ID)\n").
                    append("    inner join categories c ON ( lp.CENTRU_ID = c.ID)\n").
                    append("    left join NOMENCLATOR a ON ( lp.ANSAMBLU_ID = a.ID )\n").
                    append("    left join LF statie ON ( lp.STATIE_ID = statie.ID )\n").
                    append("    left join LF linie ON ( lp.LINIE_ID = linie.ID )\n").
                    append("    left join LF post ON ( lp.PAPT_ID = post.ID )\n").
                    append("    left join EQ trafo ON ( lp.TRAFO_ID = trafo.ID )\n").
                    append("    left join EQ bobina ON ( lp.BOBINA_ID = bobina.ID )\n").
                    append("    left join EQ celula ON ( lp.CELULA_ID = celula.ID )\n").
                    append("    left join EQ bara ON ( lp.BARA_ID = bara.ID )\n").
                    append("    left join EQ der ON ( lp.DERIVATIE_ID = der.ID )\n").
                    append("WHERE 0=0 {0}\n").
                    append("ORDER BY {1} {2}\n").toString()
            ;

    final List list = AccessDB.getListOfArrays(MessageFormat.format(
            "SELECT * FROM (SELECT a.*, ROWNUM AS rn FROM (\n"+
                    baseSql +
                    ")a WHERE ROWNUM <= {4}  ) WHERE {3} <= rn",
            new Object[]{
                    sqlCond.toString(),
                    sd.getColumnName(),
                    sd.getDirection(),
                    String.valueOf(pd.getStartIndex()),
                    String.valueOf(pd.getQueryEndIndex())
            }), "Raport Lucrari Programate");



    long count =  AccessDB.getCount2( MessageFormat.format(
            "SELECT count(*) \n" +
                    "FROM LPD_LUCRARE_PROGRAMATA lp \n" +
                    "    inner join categories f ON ( lp.FILIALA_ID = f.ID)\n" +
                    "    inner join categories s ON ( lp.SUCURSALA_ID = s.ID)\n" +
                    "    inner join categories c ON ( lp.CENTRU_ID = c.ID)\n" +
                    "    left join NOMENCLATOR a ON ( lp.ANSAMBLU_ID = a.ID )\n" +
                    "WHERE 0=0 {0}\n", new Object[]{ sqlCond.toString()}
    ), "Count lucrari programate").longValue();


    pd.setTotalRowsCount( count);
    pd.setResultRowCount( list.size());
%>


<%!
    public Date getDefaultStartDate() {
        final Calendar c = Calendar.getInstance();

        c.set( Calendar.HOUR_OF_DAY, 7);
        c.set( Calendar.MINUTE, 0);
        c.set( Calendar.SECOND, 0);
        c.set( Calendar.MILLISECOND, 0);
        return c.getTime();
    }

    public Date getDefaultStopDate(){
        final Calendar c = Calendar.getInstance();

        c.set( Calendar.HOUR_OF_DAY, 19);
        c.set( Calendar.MINUTE, 0);
        c.set( Calendar.SECOND, 0);
        c.set( Calendar.MILLISECOND, 0);
        return c.getTime();
    }
%>

<%@ taglib prefix="emid" tagdir="/WEB-INF/tags" %>

<emid:template-lp title="Raport lucrări programate">
    <jsp:attribute name="body">

<span style="font-size: 16px; font-weight:bold;">Raport lucrări programate</span>

<form id="zaforma" name="zaforma" action="<%=AppConstants.APP_NAME%>?action=raport-lucrari-programate" method="post">
<input type="hidden" name="toExport" value="0">
<input type="hidden" name="run_report" value="1"/>


<%=SortController.initSort( sd)%>

<table border=0 >
<tr>
<td>
<table width="100%">
<tr>
    <td>
        <emid:filtru-localizare/>
    </td>
</tr>
<tr>
    <td>
        <select name="durataInterval">
            <option value="durata_progr" <%=durataInterval.equals("durata_progr")?"selected":""%>>Data Progr.</option>
            <option value="durata_lucrare" <%=durataInterval.equals("durata_lucrare")?"selected":""%>>Data Lucr.</option>
            <option value="durata_intr" <%=durataInterval.equals("durata_intr")?"selected":""%>>Data Intr.</option>
        </select>
        : <input type="text" id="data_start" name="data_start" size="14" value="<%=value_data_start%>" /> <a href="#" id="trigger_data_start" ><img src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0" alt="Apasa pt. a selecta data."></a>
        - <input type="text" id="data_stop" name="data_stop" size="14" value="<%=value_data_stop%>" /> <a href="#" id="trigger_data_stop" ><img src="<%=AppConstants.WEB_RESOURCE_PATH + "/images/cal.gif"%>" width="16" height="16" border="0" alt="Apasa pt. a selecta data."></a>
        &nbsp;&nbsp;
        N.T.:
        <select name="nt" class="gSAPSelect">
            <option value=""></option>
            <option value="<%=NivelTensiune.JT%>" <%=NivelTensiune.is( snt, NivelTensiune.JT)?"selected" : ""%> >JT</option>
            <option value="<%=NivelTensiune.MT%>" <%=NivelTensiune.is( snt, NivelTensiune.MT)?"selected" : ""%> >MT</option>
            <option value="<%=NivelTensiune.IT%>" <%=NivelTensiune.is( snt, NivelTensiune.IT)?"selected" : ""%> >IT</option>
        </select>
        &nbsp;&nbsp;

        Mediu:
        <select name="mediu" class="gSAPSelect">
            <option value=""></option>
            <option value="<%=Mediu.RURAL%>" <%=Mediu.is( mediu, Mediu.RURAL)?"selected" : ""%> >R</option>
            <option value="<%=Mediu.URBAN%>" <%=Mediu.is( mediu, Mediu.URBAN)?"selected" : ""%>>U</option>
        </select>
        &nbsp;&nbsp;

        <select name="durata">
            <option value="durata_progr" <%=durata.equals("durata_progr")?"selected":""%>>Durata Progr.</option>
            <option value="durata_lucrare" <%=durata.equals("durata_lucrare")?"selected":""%>>Durata Lucr.</option>
            <option value="durata_intr" <%=durata.equals("durata_intr")?"selected":""%>>Durata Intr.</option>
        </select>
        :
        <select name="durataCond1" >
            <option></option>
            <option value="="  <%="=".equals(durataCond1)? "selected" : ""%>  >=</option>
            <option value="<"  <%="<".equals(durataCond1)? "selected" : ""%>  >&lt;</option>
            <option value="<=" <%="<=".equals(durataCond1)? "selected" : ""%> >&lt;=</option>
            <option value=">"  <%=">".equals(durataCond1)? "selected" : ""%>  >&gt;</option>
            <option value=">=" <%=">=".equals(durataCond1)? "selected" : ""%> >&gt;=</option>
        </select>
        <!--<input type="text" size="5" name="durataValue1" value="<%=AppConstants.format( durataValue1)%>" />-->
		<select name="durataValue1">
			<option></option>
			<option value="4" <%="4".equals(durataValue1)? "selected" : ""%>>4</option>
			<option value="6" <%="6".equals(durataValue1)? "selected" : ""%>>6</option>
			<option value="8" <%="8".equals(durataValue1)? "selected" : ""%>>8</option>
			<option value="12" <%="12".equals(durataValue1)? "selected" : ""%>>12</option>
			<option value="16" <%="16".equals(durataValue1)? "selected" : ""%>>16</option>
			<option value="18" <%="18".equals(durataValue1)? "selected" : ""%>>18</option>
			<option value="24" <%="24".equals(durataValue1)? "selected" : ""%>>24</option>
			<option value="36" <%="36".equals(durataValue1)? "selected" : ""%>>36</option>
			<option value="48" <%="48".equals(durataValue1)? "selected" : ""%>>48</option>
			<option value="72" <%="72".equals(durataValue1)? "selected" : ""%>>72</option>
		</select>
		
        &
        <select name="durataCond2" >
            <option></option>
            <option value="="  <%="=".equals(durataCond2)? "selected" : ""%>  >=</option>
            <option value="<"  <%="<".equals(durataCond2)? "selected" : ""%>  >&lt;</option>
            <option value="<=" <%="<=".equals(durataCond2)? "selected" : ""%> >&lt;=</option>
            <option value=">"  <%=">".equals(durataCond2)? "selected" : ""%>  >&gt;</option>
            <option value=">=" <%=">=".equals(durataCond2)? "selected" : ""%> >&gt;=</option>
        </select>
        
		<!--<input type="text" size="5" name="durataValue2" value="<%=AppConstants.format( durataValue2)%>" />-->
		
		<select name="durataValue2">
			<option></option>
			<option value="4" <%="4".equals(durataValue2)? "selected" : ""%>>4</option>
			<option value="6" <%="6".equals(durataValue2)? "selected" : ""%>>6</option>
			<option value="8" <%="8".equals(durataValue2)? "selected" : ""%>>8</option>
			<option value="12" <%="12".equals(durataValue2)? "selected" : ""%>>12</option>
			<option value="16" <%="16".equals(durataValue2)? "selected" : ""%>>16</option>
			<option value="18" <%="18".equals(durataValue2)? "selected" : ""%>>18</option>
			<option value="24" <%="24".equals(durataValue2)? "selected" : ""%>>24</option>
			<option value="36" <%="36".equals(durataValue2)? "selected" : ""%>>36</option>
			<option value="48" <%="48".equals(durataValue2)? "selected" : ""%>>48</option>
			<option value="72" <%="72".equals(durataValue2)? "selected" : ""%>>72</option>
		</select>
		
        <select name="um_timp">
            <option value="min" <%=um_timp.equals("min")?"selected":""%>>min</option>
            <option value="ore" <%=um_timp.equals("ore")?"selected":""%>>ore</option>
        </select>

        <input type="submit" value="Rulează raport" />
        &nbsp;<input type="button" id= "btn-export-excel-lp" value="Export"
            />
    </td>
</tr>

<tr>
<td>
<table cellpadding=2 cellspacing=1 width="100%" class="table">
<thead>
<tr>
    <th nowrap rowspan=2><%=SortController.printSortableColumn("Nr:", "NUMAR", sd)%></th>
    <th nowrap rowspan=2 title="Data introducere fisa"><%=SortController.printSortableColumn("Data:", "DATA_INSERT", sd)%></th>
    <th nowrap title="Sucursala" rowspan=2><nobr><%=SortController.printSortableColumn("SD:", "SUCURSALA", sd)%></nobr></th>
    <th nowrap width=90 rowspan=2><%=SortController.printSortableColumn("Centru:", "CENTRU", sd)%></th>
    <th nowrap rowspan=2 title="Nivel Tensiune"><%=SortController.printSortableColumn("N.T.:", "NT", sd)%></th>
    <th nowrap rowspan=2><%=SortController.printSortableColumn("M:", "MEDIU", sd)%></th>
    <th nowrap width=250 rowspan=2>Instalatii Afectate:</th>
    <th nowrap width=250 rowspan=2>Locatii Geografice Afectate:</th>
    <th nowrap align="center" colspan="3">Consumatori afectati</th>
    <th nowrap colspan="3" align="center">Programata</th>
    <th nowrap colspan="3" align="center">Intrerupere cons.</th>
</tr>
<tr>
    <th>IT</th>
    <th>MT</th>
    <th>JT</th>
    <th><%=SortController.printSortableColumn("De la:", "DATA_PROGRAMARE_START", sd)%></th>
    <th><%=SortController.printSortableColumn("Pina la:", "DATA_PROGRAMARE_STOP", sd)%></th>
    <th><%=SortController.printSortableColumn("Durata:", "DURATA_PROGR", sd)%></th>
    <th><%=SortController.printSortableColumn("De la:", "DATA_INTR_START", sd)%></th>
    <th><%=SortController.printSortableColumn("Pina la:", "DATA_INTR_STOP", sd)%></th>
    <th><%=SortController.printSortableColumn("Durata:", "DURATA_INTR", sd)%></th>
</tr>
</thead>

<tbody>
<% if( list == null || list.size() == 0){%>
<tr>
    <td colspan="5" class="no-data">
        Nu exista date ...
    </td>
</tr>
<% } else { %>

<% for (int i = 0; i < list.size(); i++) {
    final Object[] row = (Object[]) list.get(i);

    int index = -1;
    final long id = ObjectUtils.getLongValue( row[++index], 0);
    final long numar = ObjectUtils.getLongValue( row[++index], 0);
    final Date dataIntroducere = (Date) row[++index];
    final String s = ObjectUtils.getStringValue( row[++index] == null ? "-" : (String) row[index]);
    final String c = ObjectUtils.getStringValue( row[++index] == null ? "-" : (String) row[index]);
    final String nt = ObjectUtils.getStringValue( row[++index] == null ? "-" : (String) row[index]);
    final String m = ObjectUtils.getStringValue( row[++index] == null ? "-" : (String) row[index]);

    final String a = ObjectUtils.getStringValue( row[++index] == null ? "" : (String) row[index]);
    final String statie = ObjectUtils.getStringValue( row[++index] == null ? "" : (String) row[index]);
    final String linie = ObjectUtils.getStringValue( row[++index] == null ? "" : (String) row[index]);
    final String post = ObjectUtils.getStringValue( row[++index] == null ? "" : (String) row[index]);
    final String trafo = ObjectUtils.getStringValue( row[++index] == null ? "" : (String) row[index]);
    final String bobina = ObjectUtils.getStringValue( row[++index] == null ? "" : (String) row[index]);
    final String celula = ObjectUtils.getStringValue( row[++index] == null ? "" : (String) row[index]);
    final String bara = ObjectUtils.getStringValue( row[++index] == null ? "" : (String) row[index]);
    final String der = ObjectUtils.getStringValue( row[++index] == null ? "" : (String) row[index]);
    final String explicatii = ObjectUtils.getStringValue( row[++index] == null ? "" : (String) row[index]);

    final long catInst = ObjectUtils.getLongValue( row[++index], -1);
    final long inst = ObjectUtils.getLongValue( row[++index], -1);
    final String denInst = ObjectUtils.getStringValue( row[++index] == null ? "-" : (String) row[index]);

    final long ca_it = ObjectUtils.getLongValue( row[++index], 0);
    final long ca_mt = ObjectUtils.getLongValue( row[++index], 0);
    final long ca_jt = ObjectUtils.getLongValue( row[++index], 0);

    final Date dataProgrStart = (Date) row[++index];
    final Date dataProgrStop  = (Date) row[++index];

    final long durataProgr = ObjectUtils.getLongValue( row[++index], 0);

    final Date dataIntrStart = (Date) row[++index];
    final Date dataIntrStop  = (Date) row[++index];

    final long durataIntr = ObjectUtils.getLongValue( row[++index], 0);

    final long countAdrese = ObjectUtils.getLongValue( row[++index], 0);
    final long countIntervaleProgr = ObjectUtils.getLongValue( row[++index], 0);
    final long countIntervaleIntrCons = ObjectUtils.getLongValue( row[++index], 0);
%>
<tr valign="top">
    <td nowrap align="center">
        <a class="link" href="#" onclick="printLucrare( '<%=id%>' ); return false;" title="Vizualizare lucrare programata">
            <%=numar%>
        </a>
    </td>
    <td align="center" nowrap>&nbsp;<%=AppConstants.formatDataTime(dataIntroducere)%></td>
    <td nowrap><%=s%></td>
    <td nowrap><%=c%></td>
    <td align="center"><%=nt%></td>
    <td align="center"><%=m%></td>
    <td >

        <% if(NivelTensiune.is( nt, NivelTensiune.JT)){ %>

        <%=CategoriiInstalatii.Helper.getCategoriiInstalatie( (int)catInst, "-")%>,
        <%=CategoriiInstalatii.Helper.getDenumireInstalatie( (int)inst, "-")%>,
        <%=denInst%>

        <% } else { %>
        <span title="Ansamblu functional"><%=a%></span>
        <% if( !StringUtils.isZeroLength( statie)){ %>
        , <span title="statie"><%=statie%></span>
        <% } %>

        <% if( !StringUtils.isZeroLength( linie)){ %>
        , <span title="linie"><%=linie%></span>
        <% } %>

        <% if( !StringUtils.isZeroLength( post)){ %>
        , <span title="post"><%=post%></span>
        <% } %>

        <% if( !StringUtils.isZeroLength( bobina)){ %>
        , <span title="bobina"><%=bobina%></span>
        <% } %>

        <% if( !StringUtils.isZeroLength( trafo)){ %>
        , <span title="trafo"><%=trafo%></span>
        <% } %>

        <% if( !StringUtils.isZeroLength( bara)){ %>
        , <span title="bara"><%=bara%></span>
        <% } %>

        <% if( !StringUtils.isZeroLength( celula)){ %>
        , <span title="celula"><%=celula%></span>
        <% } %>

        <% if( !StringUtils.isZeroLength( der)){ %>
        , <span title="derivatie"><%=der%></span>
        <% } %>

        <% if( !StringUtils.isZeroLength( explicatii)){ %>
        <br/>
        <b>expl:</b> <span title="explicatii"><%=explicatii%></span>
        <% } %>
        <% } %>
    </td>
    <td>
        <% if((NivelTensiune.is( nt, NivelTensiune.JT) || NivelTensiune.is( nt, NivelTensiune.MT)) && countAdrese > 0){ %>
        <%  final List adrese = LucrareProgramataAccessDB.getAdreseLucrare( id);
            if( adrese != null && adrese.size() > 0){ %>
        <table style="font-size:10px" cellpadding="1" cellspacing="1">
            <% for (int j = 0; j < adrese.size(); j++) {
                final Adresa adresa = (Adresa) adrese.get(j); %>
            <tr valign="top">
                <td >
                    <%=AppConstants.format(adresa.getLocalitate2())%>
                </td>
                <td align="center">
                    <%=AppConstants.format(adresa.getTipArtera()) %>
                </td>
                <td>
                    <%=AppConstants.format(adresa.getDenStrada())%>
                </td>
                <td align="center">
                    <% if ( !StringUtils.isZeroLength( adresa.getNr())){ %>
                    <nobr>nr. <%=AppConstants.format(adresa.getNr())%></nobr>
                    <% } %>
                </td>
                <td align="center">
                    <% if( !StringUtils.isZeroLength( adresa.getBloc())){ %>
                    <nobr>bl. <%=AppConstants.format(adresa.getBloc())%></nobr>
                    <% } %>
                </td>
            </tr>
            <% } %>
        </table>
        <% } %>
        <% } %>
    </td>
    <td align="right">&nbsp;<%=ca_it%>&nbsp;</td>
    <td align="right">&nbsp;<%=ca_mt%>&nbsp;</td>
    <td align="right">&nbsp;<%=ca_jt%>&nbsp;</td>

    <% if( countIntervaleProgr > 0){
        final List ilp = LucrareProgramataUtils.filterListaIntervaleByTip( LucrareProgramataAccessDB.getIntervaleLucrare( id), IntervalLucrare.Tip.INTERVAL_LUCRARE_PROGR);
    %>
    <td align="center" nowrap>
        <%=AppConstants.formatDataTime(dataProgrStart)%><br/>
        <% for (int j = 0; j < ilp.size(); j++) {
            final IntervalLucrare intervalLucrare = (IntervalLucrare) ilp.get(j); %>
        <%=AppConstants.formatDataTime(intervalLucrare.getDataStart())%>
        <% if( i < ilp.size() - 1){%><br/><%}%>
        <% } %>
    </td>
    <td align="center" nowrap>
        <%=AppConstants.formatDataTime(dataProgrStop)%><br/>
        <% for (int j = 0; j < ilp.size(); j++) {
            final IntervalLucrare intervalLucrare = (IntervalLucrare) ilp.get(j); %>
        <%=AppConstants.formatDataTime(intervalLucrare.getDataStop())%>
        <% if( i < ilp.size() - 1){%><br/><%}%>
        <% } %>
    </td>

    <% }else{ %>
    <td align="center" nowrap><%=AppConstants.formatDataTime(dataProgrStart)%>&nbsp;</td>
    <td align="center" nowrap>&nbsp;<%=AppConstants.formatDataTime(dataProgrStop)%></td>
    <% } %>
    <td align="center">
        <%
            long ore = durataProgr/60;
            long min = durataProgr%60;
        %>
        <%=ore%>h <%=min%>'
    </td>

    <% if( countIntervaleIntrCons > 0){
        final List ilp = LucrareProgramataUtils.filterListaIntervaleByTip( LucrareProgramataAccessDB.getIntervaleLucrare( id), IntervalLucrare.Tip.INTERVAL_INTRERUPERE);
    %>
    <td align="center" nowrap>
        <%=AppConstants.formatDataTime(dataIntrStart)%><br/>
        <% for (int j = 0; j < ilp.size(); j++) {
            final IntervalLucrare intervalLucrare = (IntervalLucrare) ilp.get(j); %>
        <%=AppConstants.formatDataTime(intervalLucrare.getDataStart())%>
        <% if( i < ilp.size() - 1){%><br/><%}%>
        <% } %>
    </td>
    <td align="center" nowrap>
        <%=AppConstants.formatDataTime(dataIntrStop)%><br/>
        <% for (int j = 0; j < ilp.size(); j++) {
            final IntervalLucrare intervalLucrare = (IntervalLucrare) ilp.get(j); %>
        <%=AppConstants.formatDataTime(intervalLucrare.getDataStop())%>
        <% if( i < ilp.size() - 1){%><br/><%}%>
        <% } %>
    </td>
    <% }else{ %>
    <td align="center" nowrap><%=AppConstants.formatDataTime(dataIntrStart)%>&nbsp;</td>
    <td align="center" nowrap>&nbsp;<%=AppConstants.formatDataTime(dataIntrStop)%></td>
    <% } %>
    <td align="center">
        <%
            ore = durataIntr/60;
            min = durataIntr%60;
        %>
        <%=ore%>h <%=min%>'
    </td>
</tr>
<% } %>
<% } %>
</tbody>
<tfoot>
<tr>
    <td colspan="18">
        <%=PaginationController.printPaginationData( pd)%>
    </td>
</tr>
</tfoot>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</jsp:attribute>
</emid:template-lp>

<script type="text/javascript">

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

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



<script type="text/javascript">

    new JobButton({
        jobId: "callcenter-lp",
        //Pentru teste configurate in config/DEV/jobs.properties
        //jobId: "callcenter-lp-tn",
        //jobId: "callcenter-lp-ts",
        jobStartAction: "<%=AppConstants.APP_NAME%>?action=job-start-lucrari-programate",
        jobStatusAction: "<%=AppConstants.APP_NAME%>?action=job-status",
        downloadFileFromRepo: "<%=AppConstants.APP_NAME%>?action=download-file-from-repo",
        jobData: {
            form: $('zaforma')
        }
    }, "btn-export-excel-lp");

</script>