<%@ page import="ro.emid.callcenter.obj.binder.DeranjamentBinder" %>
<%@ page import="ro.emid.common.types.Deranjament" %>
<%@ page import="ro.emid.common.constants.DeranjamentConstants" %>
<%@ page import="ro.emid.common.constants.GlobalAppConstants" %>
<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="ro.emid.common.types.Category" %>

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

<%
    final Deranjament bean = (Deranjament) request.getAttribute("deranjament");
%>

<% if( bean == null){ %>
    <span style="color: red">Nu exista deranjament cu id : <%=request.getParameter("id")%></span>
<% return;} %>

<%
    Category _f = CategoryAccessDB.getById(bean.getFilialaId());
    if( _f == null ) _f = new Category();

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

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

%>

<%@ include file="../layout/messages.jspf"%>

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

<TABLE border=1 cellPadding=2 cellSpacing=1 width="100%" class="gSAPTHEAD">
  <TR>
   <TH class="gsapthead" colSpan=2 height=25 noWrap>&nbsp;Deranjament&nbsp;</TH>
  </TR>
  <tr><td>
   <fieldset>
       <legend><b>&nbsp;Localizare Deranjament</b></legend>
       <table width="100%" style="font-size:12" >
           <tr>
               <td>
                Filiala: <b><%=GlobalAppConstants.format(_f.getName())%></b>
                &nbsp;&nbsp;

                Sucursala: <b><%=GlobalAppConstants.format(_s.getName())%></b>
                &nbsp;&nbsp;

                C.E.: <b><%=GlobalAppConstants.format(_c.getName())%></b>
                &nbsp;&nbsp;
            </td>
           </tr>
       </table>
   </fieldset>
   <br>
   &nbsp;&nbsp;&nbsp;Data deranjament: <span class="dataCell"><%=GlobalAppConstants.format(bean.getDataCreareDeranjament())%></span> (data creare)
   &nbsp;&nbsp;&nbsp;Nume utilizator: <span class="dataCell"><%=bean.getUserInsert()%></span> <br>
<fieldset>
<table border="0" width="100%" style="font-size:12" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            Data anuntarii reclamatiei
        </td>
        <td>
            Data sosirii echipei
        </td>
        <td>
            Data rezolvarii
        </td>
        <td width="100px">
            DS - DA
        </td>
        <td width="100px">
            DR - DA
        </td>
    </tr>
    <tr>
        <td class="dataCell">
            <%=GlobalAppConstants.format(bean.getDataAnuntareReclamatie(), "Necompletata")%>
        </td>
        <td class="dataCell">
            <%=GlobalAppConstants.format(bean.getDataSosireEchipa(), "Necompletata")%>
        </td>
        <td class="dataCell">
            <%=GlobalAppConstants.format(bean.getDataRezolvare(), "Necompletata")%>
        </td>
        <td width="100px">
            <%
                final long durataSosire = bean.getDurataSosireEchipa();
                final long durataRemediere = bean.getDurataRemediere();
            %>
            <span class="dataCell"><%=durataSosire/60%>:<%=durataSosire%60%></span>
        </td>
        <td width="100px" class="dataCell">
            <%=durataRemediere/60%>:<%=durataRemediere%60%>
        </td>
    </tr>
</table>
</fieldset>

<table style="font-size:12px">
    <tr>
        <td align="right" width="300" >
            Efectul asupra consumatorilor - <br>
            Cu intreruperea tensiunii
        </td>
        <td width="100" class="dataCell">
            <%=bean.getEfectulAsupraConsumatorilor() > 0 ? "DA" : "NU"%>
        </td>
        <td >
            &nbsp;&nbsp;&nbsp;&nbsp; Tip deranjament: <br>
            <span class="dataCell">
                <%=bean.getTipDeranjament() == Deranjament.TIP_COLECTIV ? "Colectiv" : ""%>
                <%=bean.getTipDeranjament() == Deranjament.TIP_INDIVIDUAL ? "Individual" : ""%>
            </span>
        </td>

        <td>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            Forta majora: <span class="dataCell"><%=bean.getFortaMajora() == 1 ? "DA" : "NU"%></span>
        </td>
    </tr>
</table>

<fieldset style="padding: 10px ">
<legend><b>&nbsp;Categoria consumatorilor intrerupti</b></legend>
<table  border="0" align="center"  style="font-size:12px">
    <tr>
        <td>
            Nr. Case
        </td>
        <td >
            Nr. Ap.
        </td>
        <td >
            Nr. Mici
        </td>
        <td >
            Nr. Mari
        </td>
        <td width="100%" align="center" colspan="2">
            Mediul in care sunt amplasati consumatorii intrerupti
        </td>
    </tr>
    <tr>
        <td>
            <span class="dataCell"><%=bean.getNrCase()%></span>
        </td>
        <td class="dataCell">
            <%=bean.getNrAp()%>
        </td>
        <td class="dataCell">
            <%=bean.getNrMici()%>
        </td>
        <td class="dataCell">
            <%=bean.getNrMari()%>
        </td>
        <td align="center">
            <span class="dataCell">
                <%=bean.getMediul() == Deranjament.MEDIU_URBAN ? "Urban" : ""%>
                <%=bean.getMediul() == Deranjament.MEDIU_RURAL ? "Rural" : ""%>
            </span>
        </td>
    </tr>
</table>
</fieldset>
<br/>
<br/>
<fieldset style="padding: 10px ">
<legend><b>&nbsp;Energia electrica nelivrata consumatorilor intrerupti (kWh)</b></legend>
<table   border="0" width="80%" style="font-size:12px">
    <tr align="left">
        <td>
            Casnici
        </td>
        <td>
            Mici consumatori
        </td>
        <td>
            Mari consumatori
        </td>
    </tr>
    <tr align="left">
        <td class="dataCell">
            <%=bean.getEncCasnici()%>
        </td>
        <td class="dataCell">
            <%=bean.getEncMici()%>
        </td>
        <td class="dataCell">
            <%=bean.getEncMari()%>
        </td>
    </tr>
</table>
</fieldset>
<br/>
<br/>

<fieldset style="padding: 10px  " >
<legend><b>&nbsp;Constatari ale echipei care a rezolvat deranjamentul</b></legend>
<table border="0" style="font-size:12px" >
    <tr>
        <td colspan="10">
            Descriere Deranjament<br>
            <span class="dataCell"><%=GlobalAppConstants.format(bean.getDescriere())%></span>
        </td>
    </tr>
</table>

<table style="font-size: 12px" width="100%">
    <tr>
        <td>
            Localizare defect (initial)
        </td>
    </tr>
    <tr>
        <td>
            Categoria de instalatii
        </td>
        <td>
            Nr. / Denumire
        </td>
        <td>
            PT
        </td>
        <td>
            Interventie la echipamentele de masura
        </td>
    </tr>
    <tr>
        <td class="dataCell">
            <%=DeranjamentConstants.getTextFromArray( (int) bean.getCatInstalatii(), DeranjamentConstants.ARR_CAT_INSTALATII, "Neselectat")%>
        </td>
        <td class="dataCell">
            <%=GlobalAppConstants.format(bean.getNrDenumire())%>
        </td>
        <td class="dataCell">
            <%=bean.getPtId() == -1 ? " " : bean.getPtDesc() %>
        </td>
        <td class="dataCell">
            <%=bean.getInterventieLaEchipamente() > 0 ? "DA" : "NU"%>
        </td>
    </tr>

    <tr>
        <td>
             Instalatia
        </td>
        <td>
            Elementul defect
        </td>
        <td>
            Componenta defecta
        </td>
    </tr>
    <tr>
        <td class="dataCell">
            <%=DeranjamentConstants.getTextFromArray( (int) bean.getInstalatia(), DeranjamentConstants.INSTALATII, "Neselectat")%>
        </td>
        <%--<td class="dataCell">--%>
        <td class="dataCell" id="td_elemetul"> <!-- Elementul defect -->
        <% if (bean.getCatInstalatii() > 0 &&
                bean.getElementulDefect() > 0 &&
                bean.getCatInstalatii() < DeranjamentConstants.ARR_ELEMENTE_DEFECTE.length &&
                bean.getElementulDefect() < DeranjamentConstants.ARR_ELEMENTE_DEFECTE[(int) bean.getCatInstalatii()].length
               ) {
        %>
            <%= DeranjamentConstants.ARR_ELEMENTE_DEFECTE[ (int)bean.getCatInstalatii()][ (int)bean.getElementulDefect()]%>
        <%}%>
        &nbsp;
        </td>
        <td class="dataCell" id="td_componenta">
        <%
           if ( bean.getCatInstalatii()  > 0 && bean.getElementulDefect() > 0 && bean.getComponentaDefecta() > 0){
        %>
        <script type="text/javascript">
           var c = componente[ <%=bean.getCatInstalatii()%> - 1][<%=bean.getElementulDefect()%> - 1];
           $('td_componenta').innerHTML = c[<%=bean.getComponentaDefecta()%>][0];
        </script>
         <%}%>
         &nbsp;
        </td>
    </tr>
    <tr>
        <td colspan="2">
             Cauza
        </td>
        <td>
            Factorii favorizati
        </td>
    </tr>
    <tr>
        <td colspan="2" class="dataCell">
            <%=DeranjamentConstants.getTextFromArray( (int) bean.getCauza(), DeranjamentConstants.CAUZE, "Neselectata")%>
        </td>
        <td class="dataCell"> 
            <%=DeranjamentConstants.getTextFromArray((int) bean.getFactoriiFavozizati(), DeranjamentConstants.FACTORI_FAVORIZATI, "Neselectata")%>
        </td>
    </tr>
</table>
<br/>

<fieldset style="width:95%; padding: 10px ">
    <legend><b>&nbsp;Apartenenta instalatiilor in care a fost localizata cauza deranjamentului</b></legend>
    <span class="dataCell">
        <%=bean.getApartenentaInstalatie() == Deranjament.APARTINE_ELECTRICA ? "\"Electrica .... \"" : ""%>
        <%=bean.getApartenentaInstalatie() == Deranjament.APARTINE_CONSUMATOR ? "Consumator" : ""%>
    </span>
</fieldset>
<br/>
<br/>
</fieldset>
<br/>
<br/>

<fieldset style="padding: 10px">
<table style="font-size:12px">
    <tr>
        <td  colspan="3">
            Mod rezolvare<br>
            <span class="dataCell"><%=GlobalAppConstants.format(bean.getModRezolvare())%></span>
        </td>
    </tr>
    <tr valign="bottom">
        <td>
            Masuri luate
        </td>
        <td nowrap>
            Echipa care a rezolvat deranjamentul &nbsp;&nbsp;<br>[Numele si prenumele sefului]
        </td>
        <td>Provizorat</td>
    </tr>
    <tr>
        <td class="dataCell">
            <%=DeranjamentConstants.getTextFromArray( (int) bean.getMasuriLuate(), DeranjamentConstants.MASURI_LUATE_ARR, "Neselectata")%>
        </td>
        <td class="dataCell">
            <%=GlobalAppConstants.format(bean.getEchipa())%>
        </td>
        <td class="dataCell">
             <%=bean.getProvizorat() > 0 ? "DA" : "NU"%>
        </td>
    </tr>
    <tr>
        <td colspan="3">
            Observatii<br>
            <span class="dataCell"><%=GlobalAppConstants.format(bean.getObservatii())%></span>
        </td>
    </tr>
</table>
</fieldset>

</td>
</tr>
</TABLE>
</FORM>



