<%@ page import="ro.emid.common.constants.NomConstants" %>
<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="ro.emid.incidente.obj.*" %>
<%@ page import="ro.emid.common.db.NomAccessDB" %>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.db.EchipamentAccessDB" %>
<%@ page import="ro.emid.incidente.db.EvenimentAccessDB" %>
<%@ page import="java.sql.Date" %>
<%@ page import="ro.emid.common.db.framework.DatabaseException" %>
<%@ page import="ro.emid.common.db.DataDB" %>
<%@ page import="ro.emid.common.types.*" %>


<%!
    private String getNomText(final long id) {
        Nomenclator nom = null;
        try {
            if (id > 0) nom = NomAccessDB.getNom(id);
        } catch (DatabaseException e) {
        }

        String result = "-";
        if (nom != null) {
            result = nom.getCod() + " - " + nom.getDescriere();
        }
        return result;
    }

    private String getNomSAPText(final long id, final int tip) {
        DataObj data = null;


        try {
            if (id > 0) data = DataDB.getById(id, DataDB.isLocFunctional(tip));
        } catch (DatabaseException e) {
        }

        String result = "-";
        if (data != null) {
            result = data.getNume();
        }
        return result;
    }

    private String getText(final String str) {
        String result = (str != null && !"null".equalsIgnoreCase(str.trim())) ? str : "-";

        int i = 0;
        while( (i = result.indexOf('\n', i)) >=0){
            result = result.substring(0, i) + "<br />" + result.substring(i+1);
        }
        return result;
    }
%>


<style>
    .fl {/* field Label*/
        font-weight: bolder;
    }

    .fv { /* field Value */
        /*font-weight: bolder;*/
    }
    span.fv{
        white-space:wrap !important;
    }
</style>

<%
    final long id = ObjectUtils.getLongValue(request.getParameter("id"), -1);
    final Echipament bean = EchipamentAccessDB.getEchipament(id);

    Category filialaBean = CategoryAccessDB.getById(bean.getFilialaId());
    if (filialaBean == null) filialaBean = new Category();

    Category sucursalaBean = CategoryAccessDB.getById(bean.getSucursalaId());
    if (sucursalaBean == null) sucursalaBean = new Category();

    Category centruBean = CategoryAccessDB.getById( bean.getCentruId());
    if( centruBean == null) centruBean = new Category();

    formatiaDeLucru = CategoryAccessDB.getById( bean.getFormatiaDeLucruId());
    if( formatiaDeLucru == null) formatiaDeLucru = new Category();
%>

<TABLE border=1 cellPadding=5 cellSpacing=1 width="100%" class="gSAPTHEAD">
  <TR>
   <TH class="gsapthead" colSpan=2 height=25 noWrap>
       <span style="float:right;">v. <%=ObjectUtils.getStringValue(bean.getVersion())%></span>
       Fisa de Echipament deteriorat&nbsp;(vizualizare)&nbsp;<%=bean.getNumarFI_FE()%>
   </TH>
  </TR>
<TR>
  <TD>
   <b>1.</b> <span class="fl">Numar curent fisa incident:</span>
  </TD>
  <TD>
   <span class="fv"><%=bean.getNumarIncident() != -1 ? String.valueOf(bean.getNumarIncident()) : "-"%></span>
  </TD>
</TR>

<TR>
  <TD width="25%">
   <b>2.</b> <span class="fl">Numar curent fisa echipament deteriorat:</span>
  </TD>
  <TD wdth="75%">   
   <span class="fv"> <%=bean.getNumarEchipament()%></span>
  </TD>
</TR>

<TR>
  <TD>
   <b>3.</b> <span class="fl">Data deteriorarii:</span>
  </TD>
  <TD>
   <span class="fv"><%=AppConstants.format(bean.getDataDeterioarare())%></span>
  </TD>
</TR>

<TR>
  <TD width="25%">
   <b>4.</b> <span class="fl">Echipament / componenta:</span>
  </TD>
  <TD wdth="75%">
      <span class="fv"><%=getNomText( bean.getComponentaId())%></span>
   </TD>
</TR>

<TR>
<TD valign=top>
   <b>5.</b> <span class="fl">Localizare echipament deteriorat:</span>
    <br>
    <% final String nrComanda = EvenimentAccessDB.getNumarComandaByResultIdAndResultType( bean.getId(), Eveniment.STATUS_TRECUT_ECHIPAMENT);%>
    <b>Nr. Comanda:</b> <%=getText( nrComanda)%>
</TD>
<TD>
<TABLE class="gsapthead">

<TR class="gSAPGroup">
  <TD>
   <b>5.1</b> <span class="fl">Cod filiala:</span>
  </TD>
  <TD>
   <span class="fv"><%=filialaBean.getName()%></span>
  </TD>
</TR>

<TR class="gSAPGroup">
  <TD>
   <b>5.2</b> <span class="fl">Cod sucursala:</span>
  </TD>
  <TD>
   <span class="fv"><%=sucursalaBean.getCodSap()%> - <%=sucursalaBean.getName()%></span>
  </TD>
</TR>

<TR class="gSAPGroup">
  <TD>
   <b>5.3</b> <span class="fl">Cod sectie/C.E.:</span>
  </TD>
  <TD valign="MIDDLE" width="100%" >
      <span class="fv"><%=centruBean.getCodSap()%> - <%=centruBean.getName()%></span>

      &nbsp;&nbsp;<b>2.3.1</b>&nbsp; <span class="fl"> <%=sucursala.isCuSectiiSiCentre() || centruExploatare.isCuSectiiSiCentre() ? "Centru exploatare" : "Formatia de lucru"%>:</span>
      <span class="fv"><%=getText( formatiaDeLucru.getName())%></span>
  </TD>
</TR>

<TR class="gSAPGroup">
 <TD>
 <b>5.4</b> <span class="fl">Ansamblu functional:</span>
 </TD>
  <TD>
      <span class="fv">  <%=getNomText( bean.getAnsambluId())%></span>
      &nbsp;<br> <b>5.4.1</b> <span class="fl">Explicatii:</span> <span class="fv"> <%=getText( bean.getExplicatii())%></span>
   </TD>
</TR>

<TR class="gSAPGroup">
<TD>
<b>5.5</b> <span class="fl">Statie:</span>
</TD>
<TD>
    <span class="fv"><%=AppConstants.format(bean.getStatieDen(), "-")%></span>
    &nbsp;&nbsp;&nbsp;
    <b>5.5.1</b> <span class="fl">Bobina:</span>

    <span class="fv"><%=AppConstants.format(bean.getBobinaDen(), "-")%></span>
</TD>
</TR>
<TR class="gSAPGroup">

<TD>
<b>5.6</b> <span class="fl">Celula:</span>
</TD>
<TD>
    <span class="fv"><%=AppConstants.format(bean.getCelulaDen(), "-")%></span>
    &nbsp;&nbsp;&nbsp;
    <b>5.6.1</b> <span class="fl">Bara:</span>
    <span class="fv"><%=AppConstants.format(bean.getBaraDen(), "-")%></span>
</TD>
</TR>
<TR class="gSAPGroup">

<TD>
<b>5.7</b> <span class="fl">Linie:</span>
</TD>
<TD>
    <span class="fv"><%=AppConstants.format(bean.getLinieDen(), "-")%></span>
    &nbsp;&nbsp;&nbsp;
    <b>5.7.1</b> <span class="fl">Derivatie:</span>
    <span class="fv"><%=AppConstants.format(bean.getDerivatieDen(), "-")%></span>
</TD>
</TR>

<TR class="gSAPGroup">
<TD>
<b>5.8</b> <span class="fl">PA/PT:</span>
</TD>
<TD>
    <span class="fv"><%=AppConstants.format(bean.getPaptDen(), "-")%></span>
</TD>
</TR>

<TR class="gSAPGroup">
<TD>
<b>5.9</b> <span class="fl">Trafo:</span>
</TD>
<TD>
    <span class="fv"><%=AppConstants.format(bean.getTrafoDen())%></span>
</TD>
</TR>
</TABLE>

<TR>
  <TD>
   <b>6.</b> <span class="fl">Parametri nominali echipament:</span>
  </TD>
  <TD>
   <b>6.1</b> <span class="fl">Tensiune maxima pt. echipament:</span> <%=bean.getTensiuneMaxima()%> (kV)
  <BR>
   <b>6.2</b> <span class="fl">Putere:</span> <%=bean.getPutere()%>
        (<%=bean.getTipPutere() == 1 ? "MVA" : bean.getTipPutere() == 2 ? "MVAr" : bean.getTipPutere() == 3 ? "kVA" :
        bean.getTipPutere() == 4 ? "kVAr" : "-" %>)
   <br>
   <b>6.3</b> <span class="fl">Producator:</span>&nbsp;&nbsp;Tara: <%=getNomText( bean.getProducatorTaraId())%>
   &nbsp;Firma: <%=getText( bean.getProducatorFirma())%><BR>
   <b>6.4</b> <span class="fl">Furnizor:</span>&nbsp;&nbsp;Tara: <%=getNomText( bean.getFurnizorTaraId())%>

   &nbsp;Firma: <%=getText( bean.getFurnizorFirma())%><BR>
   <b>6.5</b> <span class="fl">An fabricatie:</span> <%=bean.getAnFabricatie()%><BR>
   <b>6.6</b> <span class='fl'>An punere in functiune:</span> <%=bean.getAnPunereFunctiune()%>
  </TD>
</TR>

<TR>
<TD valign=top>

<b>7.</b> <span class="fl">Aspecte ale deteriorarii:</span>
</TD>
<TD>
  <span class="fv"><%=getText( bean.getPropuneri())%></span>
</TD>
</TR>
<TR>
  <TD>
   <b>8.</b> <span class="fl">Durata de functionare de la PIF:</span>
  </TD>
  <TD>
   <span class="fv"> <%=bean.getDurataFunctPIF()%> sute ore</span>
  </TD>

</TR>

<TR>
  <TD>
   <b>9.</b> <span class="fl">Durata de functionare de la ultima interventie:</span>
  </TD>
  <TD>
   <span class="fv"> <%=bean.getDurataFunctUltimaInterventie()%> zeci ore</span>
  </TD>
</TR>

<TR>
  <TD>
   <b>10.</b> <span class="fl">Durata indisponibilitatii ansamblului functional:</span>
  </TD>
  <TD>
    <%=bean.getDiafOre()%> ore &nbsp;&nbsp;
    <%=bean.getDiafMin()%> min
  </TD>
</TR>

<TR>
  <TD>
   <b>11.</b> <span class="fl">Profil ultimei interventii:</span>
  </TD>
  <TD valign="MIDDLE">
    <span class="fv"><%=getNomText( bean.getProfilInterventieId())%></span>
  </TD>
</TR>

<TR>
  <TD>
  <b>12.</b> <span class="fl">Ultima incercare profilactica:</span>
  </TD>
  <TD>
   <b>12.1</b> Durata: <%=bean.getUipDurata()%> zile<BR>

   <b>12.2</b> Rezultat:
      <span class="fv"><%=getNomText( bean.getUipRezultatId())%></span>      
  </TD>
</TR>

<TR>
 <TD>
 <b>13.</b> <span class="fl">Cauza:</span>
 </TD>
 <TD>
    <b>13.1</b> Grupa: <%=getNomText( bean.getCauzaGrupaId())%><BR>
    <b>13.2</b> Cauza: <%=getNomText( bean.getCauzaId())%>
 </TD>
</TR>

<TR>
  <TD>

  <b>14.</b> <span class="fl">Numar total de echipamente identice deteriorate:</span>
  </TD>
  <TD>
    <span class="fv"><%=bean.getNumarEchipIdenticeDet()%></span>
  </TD>
</TR>

<TR>
  <TD>
   <b>15.</b> <span class="fl">Cheltuieli (RON):</span>
  </TD>

  <TD>
      <table width="80%" cellspacing="1" class="gSAPTHEAD">
          <tr class="gSAPGroup">
              <td>
                  <span <%if(bean.getCheltMentinere() != bean.getSapCheltMentinere()){%> style="color: blue;" <%}else{%> style="color: green;"<%}%>   style=" text-align: right" ><%=AppConstants.format2(bean.getCheltMentinere())%></span> - Mentenanta - Terti<BR>
                  <span <%if(bean.getCheltDaune() != bean.getSapCheltDaune()){%> style="color: blue;" <%}else{%> style="color: green;"<%}%>  style=" text-align: right" ><%=AppConstants.format2(bean.getCheltDaune())%></span> - Daune<BR>
                  <span <%if(bean.getCheltExploatare() != bean.getSapCheltExploatare()){%> style="color: blue;" <%}else{%> style="color: green;"<%}%>  style=" text-align: right" ><%=AppConstants.format2(bean.getCheltExploatare())%></span> - Exploatare / Forte proprii<BR>
                  <span style=" text-align: right" ><%=AppConstants.format2(bean.getCheltMentinere() + bean.getCheltDaune() + bean.getCheltExploatare())%></span> - Total
              </td>              
          </tr>
      </table>   
  </TD>
</TR>

<TR>
 <TD valign=top>
  <b>16.</b> <span class="fl">Masuri pentru prevenire:</span>
 </TD>
 <TD>
	<span class="fv"> <%=getText(bean.getMasuriPrevenire())%> </span>
 </TD>

</TR>

<TR>
 <TD valign=top>
 <b>17.</b> <span class="fl">Observatii:</span>
 </TD>
 <TD>
	<span class="fv"><%=getText( bean.getObservatii())%></span>
 </TD>

</TR>


<TR>
  <TD colspan=2>
   <b>18.</b> <span class="fl">Deteriorarea a fost analizat de:</span>
   <span class="fv"> <%=getText( bean.getAnalizatDe())%></span>
   &nbsp;&nbsp;&nbsp;&nbsp;<span class="fl">Conducatorul sub-unitatii de exploatare:</span>
   <span class="fv"> <%=getText( bean.getConducatorUnitate())%></span>
  </TD>
</TR>


<TR>
  <TD colspan="2">
   <b>19.</b> <span class="fl">Avizul comisiei tehnice:</span>
   <span class="fv"> <%=getText( bean.getAvizComisie())%></span>
  </TD>
</TR>

<TR>
  <TD colspan=2>
   <span class="fl">Conducatorul tehnic:</span>
    <span class="fv"><%=getText( bean.getConducatorTehnic())%></span>
   &nbsp;&nbsp;&nbsp;&nbsp;<span class="fl">Inspector incidente:</span>
    <span class="fv"><%=getText( bean.getInspectorIncidente())%></span>
  </TD>
</TR>

</TABLE>


