<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.constants.GlobalAppConstants" %>
<%@ page import="ro.emid.callcenter.obj.*" %>
<%@ page import="ro.emid.common.utils.ReclamatiiUtils" %>
<%@ page import="ro.emid.common.types.Nomenclator" %>
<%@ page import="ro.emid.common.constants.NomConstants" %>
<%@ page import="ro.emid.callcenter.db.*" %>
<%@ page import="ro.emid.common.types.LucrareProgramata2" %>
<%@ page import="ro.emid.common.utils.StringUtils" %>
<%@ page import="ro.emid.common.types.Deranjament" %>
<%@ page import="ro.emid.common.types.Reclamatie" %>
<%@ page import="ro.emid.common.constants.ReclamatieConstants" %>
<%@ page import="ro.emid.common.db.*" %>
<%@ page import="ro.emid.callcenter.db.LucrareProgramataAccessDB" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.lib.view.ReclamatiexFieldsView" %>


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

<%if( request.getAttribute("ACT") != null){%>
    <script type="text/javascript">
        try{
            //fereastra de cautare reclamatie are functia cautare, pt a pastra rezultatele cautarii
            window.opener.cautare();
        }catch(e){
        }
        window.close();
    </script>
<%}else{%>

<%
    final long reclamatieId = ObjectUtils.getLongValue(request.getParameter("reclamatieId"), -1);
    final Reclamatie reclamatie = ReclamatieAccessDB.getById(reclamatieId);
%>

<% if( reclamatie == null){%>
<center>Nu exista reclamatie cu id <%=reclamatieId%></center>
<%}else{%>
<%
    
	
	String legatLa = "";
    Deranjament deranjament = null;
    Lucrare lucrare = null;
    LucrareProgramata2 lucrare2 = null;
    LittleIncident incident = null;

    if( reclamatie.isArhivata()){
        legatLa = "<span title=\" de catre " + reclamatie.getUserArhivare() + " la data " + AppConstants.format(reclamatie.getDataArhivare()) + "\" > ARHIVATA</span>";
    }else if (reclamatie.getObjectId() != -1) {
        if (reclamatie.getObjectType() == Reclamatie.LEGAT_LA_DERANJAMENT) {
            legatLa = "DERANJAMENT";
            deranjament = DeranjamentAccessDB.getById(reclamatie.getObjectId());
            if (deranjament == null) legatLa += "(nu exista)";
        } else if (reclamatie.getObjectType() == Reclamatie.LEGAT_LA_LUCRARE) {
            legatLa = "LUCRARE PROGRAMATA";
            lucrare = LucrareAccessDB.getById(reclamatie.getObjectId());
            if (lucrare == null) legatLa += "(nu exista)";
        } else if (reclamatie.getObjectType() == Reclamatie.LEGAT_LA_LUCRARE2) {
            legatLa = "LUCRARE PROGRAMATA 2";
            lucrare2 = LucrareProgramataAccessDB.getById(reclamatie.getObjectId());
            if (lucrare == null) legatLa += "(nu exista)";
        } else if (reclamatie.getObjectType() == Reclamatie.LEGAT_LA_INCIDENT) {
            legatLa = "INCIDENT";
            incident = LittleIncidentAccessDB.getById( reclamatie.getObjectId());
            if( incident == null) legatLa += "(nu exista)";
        }
    }

    final Nomenclator zeCir = NomAccessDB.getNom( NomConstants.NOM_CIR, (int)reclamatie.getCodCIR());
	
	ReclamatiexFieldsView reclamatieView = new ReclamatiexFieldsView();
	
%>
<!--<TABLE class="gsapthead" align=center border=0 cellPadding=10 cellSpacing=0 width="100%">-->
<!--<TBODY>-->
<!--<TR>-->
<!--<TD>-->
<form  name="zaforma" action="<%=GlobalAppConstants.APP_NAME%>" method="post">
    <input type="hidden" name="action" value="callcenter_retransmiteReclamatie">
    <input type="hidden" name="id" value="<%=reclamatie.getId()%>">
<TABLE align=center border=0 cellPadding=5 cellSpacing=0 width="100%" class="gsaptd">
<tr>
    <td>
        <table style="font-size: 12">
            <tr>
                <td>Identificator reclamatie: <b><%=reclamatie.getId()%></b></td>
                <td>Data inregistrarii reclamatiei: <b><%=AppConstants.format(reclamatie.getData())%></b></td>
                <td align="center">
                    <span style="color: red"><%=legatLa%></span>
                </td>
            </tr>
            <tr>
                <td>Nume/denumire agent economic :</td>
                <td><input readonly class="gsapinputtext"  size="80" type="text" value="<%=AppConstants.format( reclamatie.getNumeClient())%>"></td>
                <td align="center">
                   <span style="color: #cc0000; font-weight: bold;"> <%=AppConstants.format(zeCir != null ? zeCir.getDescriere() : "")%> </span>
                </td>
            </tr>
			<tr>
				<td>Cod Client: </td>
				<td><input readonly class="gsapinputtext" size="80" type="text" value="<%=reclamatieView.getCodClientView(reclamatie.getId())%>" /></td>
			</tr>
            <tr>
                <td>Reclamatie introdusa de:</td>
                <td><input  readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getAutor())%>"></td>
            </tr>
        </table>
    </td>
</tr>

<tr><td>
<fieldset style="margin-top: 1px; padding-top: 1px">
<legend><b>&nbsp;Detalii CIR</b></legend>
<table style="font-size: 12" border="0" width="100%" align="center">
<%if( reclamatie.getObjectType() == Reclamatie.LEGAT_LA_LUCRARE ){%>
<tr>
    <td>
        <table width="100%" style="font-size: 12">
            <tr>
                <td>
                    Nume:<br>
                    <b><%=lucrare != null ? AppConstants.format(lucrare.getNume()) : ""%></b>
                </td>
                <td>
                    Data start:<br>
                    <b><%=lucrare != null ? AppConstants.format(lucrare.getDataStart()) : ""%></b>
                </td>
                <td>
                    Durata:<br>
                    <b><%=lucrare != null ? AppConstants.format(lucrare.getDurata()) : ""%></b>
                </td>
                <td>
                    ID LUCRARE:<br>
                    <b><%=lucrare!= null ? String.valueOf(lucrare.getId()) : ""%></b>
                </td>
            </tr>
        </table>
    </td>
</tr>
<tr>
    <td>
        <table width="100%" style="font-size: 12" border="0">
            <tr>
                <td width="50%">
                    Descriere lucrare:<br>
                    <textarea readonly rows="3" cols="20" style="width: 100%"><%=lucrare != null ? AppConstants.format(lucrare.getDescriere()) : ""%></textarea>
                </td>
        </table>
    </td>
</tr>
<%}else if( reclamatie.getObjectType() == Reclamatie.LEGAT_LA_LUCRARE2){%>
    <tr>
        <td>
            <table width="100%" style="font-size: 12">
                <tr>
                    <td>
                        Nume:<br>
                        <b><%=lucrare2 != null ? lucrare2.getParametriTitlu().toString()  : ""%></b>
                    </td>
                    <td>
                        Data start:<br>
                        <b><%=lucrare != null ? AppConstants.format(lucrare2.getDataProgramataStart()) : ""%></b>
                    </td>
                    <td>
                        Durata intreruperi:<br>
                        <b><%=lucrare != null ? AppConstants.format(lucrare2.getDurataIntreruperi()) : ""%></b>
                    </td>
                    <td>
                        NUMAR:<br>
                        <b><%=lucrare2!= null ? String.valueOf(lucrare2.getNumar()) : ""%></b>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <table width="100%" style="font-size: 12" border="0">
                <tr>
                    <td width="50%">
                        Descriere lucrare:<br>
                        <textarea readonly rows="3" cols="20" style="width: 100%"><%=lucrare != null ? AppConstants.format(lucrare.getDescriere()) : ""%></textarea>
                    </td>
            </table>
        </td>
    </tr>

<%}else if( reclamatie.getObjectType() == Reclamatie.LEGAT_LA_DERANJAMENT){%>
<tr>
    <td>
        <table width="100%" style="font-size: 12">
            <tr align="center">
                <td width="25%">
                    Sosire echipa:<br>
                    <span style="font-size: 14px; font-weight: bold;" > <%=deranjament != null ? AppConstants.format(deranjament.getDataSosireEchipa()) : ""%></span>
                </td>
                <td width="25%">
                    Remediere deranjament:<br>
                    <span style="font-size: 14px; font-weight: bold;" ><%=deranjament != null ? AppConstants.format(deranjament.getDataRezolvare()) : ""%></span>
                </td>
                <td width="25%">
                    Echipa:<br>
                    <span style="font-size: 14px; font-weight: bold;" ><%=deranjament != null && deranjament.getEchipa() != null ? AppConstants.format(deranjament.getEchipa()) : "-"%></span>
                </td>
                <td width="25%">
                    ID Deranjament:<br>
                    <span style="font-size: 14px; font-weight: bold;" ><%=deranjament != null ? String.valueOf(deranjament.getNumar()) : "-"%></span>
                </td>
            </tr>
        </table>
    </td>
</tr>
<tr>
    <td>
        <table width="100%" style="font-size: 12" border="0">
            <tr>
                <td width="50%">
                    Descriere deranjament:<br>
                    <textarea readonly rows="3" cols="20" style="width: 100%"><%=deranjament != null ? AppConstants.format(deranjament.getDescriere()) : ""%></textarea>
                </td>
                <td width="50%">
                    Mod rezolvare:<br>
                    <textarea style="width: 100%" readonly rows="3" cols="20"><%=deranjament != null ? AppConstants.format(deranjament.getModRezolvare()) : ""%></textarea>
                </td>
            </tr>
        </table>
    </td>
</tr>
<tr>
    <td>Observatii:
        <textarea rows="2" cols="60" style="width:100%"><%=deranjament != null ? AppConstants.format(deranjament.getObservatii()) : ""%></textarea>
    </td>
</tr>
<%}else if(  reclamatie.getObjectType() == Reclamatie.LEGAT_LA_INCIDENT ){%>
<tr>
    <td>
        <table width="100%" style="font-size: 12">
            <tr>
                <td>
                    Data producere: <br>
                    <b><%=incident != null ? AppConstants.format(incident.getDataAnuntare()) : ""%></b>
                </td>
                <td>
                    Data remediere: <br>
                    <b><%=incident != null ? AppConstants.format(incident.getDataRezolvare()) : ""%></b>
                </td>
                <td>
                    ID INCIDENT:<br>
                    <b><%=incident != null ? String.valueOf(incident.getId()) : ""%></b>
                </td>
            </tr>
        </table>
    </td>
</tr>
<tr>
    <td>
        <table width="100%" style="font-size: 12" border="0">
            <tr>
                <td width="100%">
                    Nume Incident:<br>
                    <textarea readonly rows="3" cols="20" style="width: 100%"><%=incident != null ? AppConstants.format(incident.getNume()) : ""%></textarea>
                </td>
            </tr>
        </table>
    </td>
</tr>
<%}%>
</table>
</fieldset>

<fieldset style="margin-top:1px; padding-top:0">
    <legend><b>&nbsp;Adresa</b></legend>
    <table>
        <tr valign="top"><td>
            <table style="font-size: 12;">
                <tr><td>Localitate/Comuna</td>  <td><input readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getLocalitate())%>"></td>   </tr>
                <tr><td>Sat</td>  <td><input readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getLocalitate2())%>"></td>   </tr>
                <tr>    <td>Strada</td>  <td><input readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getStrada())%>"></td>       </tr>
                <tr>    <td>Nr</td>  <td><input readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getNr())%>"></td>           </tr>
                <tr>    <td>Bloc</td>  <td><input readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getBloc())%>"></td>         </tr>
                <tr>    <td>Scara</td>  <td><input readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getScara())%>"></td>        </tr>
                <tr>    <td>Etaj</td>  <td><input readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getEtaj())%>"></td>         </tr>
                <tr>    <td>Interfon</td>  <td><input readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getInterfon())%>"></td>     </tr>
                <tr>    <td>Apartament</td>  <td><input readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getAp())%>"></td>   </tr>
                <tr>    <td>Fix</td>  <td><input readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getFix())%>"></td>      </tr>
                <tr>    <td>Mobil</td>  <td><input readonly class="gsapinputtext" size="80" type="text" value="<%=AppConstants.format( reclamatie.getMobil())%>"></td>      </tr>
                <tr>
                    <td>Puncte de reper</td>
                    <td>
                        <textarea rows="2" cols="60" name="<%=ReclamatieConstants.PUNCTE_REPER%>" ><%=AppConstants.format(reclamatie.getPuncteReper())%></textarea>
                    </td>
                </tr>
            </table>
        </td>
            <td>
                <%
                    final Category f = CategoryAccessDB.getById( reclamatie.getIdFiliala());
                    final Category s = CategoryAccessDB.getById( reclamatie.getIdSucursala());
                    final Category c = CategoryAccessDB.getById(reclamatie.getIdCentru());
                    final String obs = ObjectUtils.getStringValue(reclamatie.getObservatii());
                %>
                <table style="font-size:12px">
                    <tr><td nowrap>
                        <b>Filiala:</b> <%=f != null ? f.getName() : "-"%>
                    </td></tr>
                    <tr><td nowrap>
                        <b>Sucursala:</b> <%=s != null ? s.getName() : "-"%>
                    </td></tr>
                    <tr><td nowrap>
                        <b>C.E.:</b> <%=c != null ? c.getName() : "-"%>
                    </td></tr>
                    <tr><td nowrap>
                        <b>Judet:</b> <%=StringUtils.getNullSafe( reclamatie.getJudet(), "-")%>
                    </td></tr>
                    <tr><td>
                        <b>Observatii:</b> <%=ReclamatieConstants.DB_REP_LOC_CONF_ZONA_OPERATOR.equals( obs)? "Arondata pe C.E. conform zona operator": obs%>
                    </td></tr>
                </table>
            </td>
        </tr>
    </table>

</fieldset>

<fieldset style="margin-top:1px; padding-top:0">
    <legend><b>&nbsp;Sesizare</b></legend>
    <table style="font-size:12px" cellpadding="1px" border="0" align="center" width="100%">
        <tr>
            <td >Continut sesizare(1):</td>
            <td>
                <input readonly type="text" class="gsapinputtext" value="<%=ReclamatieConstants.getSesizare1( reclamatie)%>"> &nbsp;&nbsp;&nbsp;&nbsp;
                Continut sesizare (2): <input readonly type="text" class="gsapinputtext" value="<%=ReclamatieConstants.getSesizare2( reclamatie)%>">
            </td>
        </tr>
        <tr>
            <td>Comentarii:</td>
            <td><textarea name="<%=ReclamatieConstants.COMENTARII%>" rows="2" cols="50" style="width: 100%"><%=AppConstants.format(reclamatie.getComentarii())%></textarea></td>
        </tr>
    </table>
</fieldset>

<br>
<div align="right">

    <%if(GlobalAppConstants.CIR_ACTIV){%>
        <%--<button <% if( reclamatie.getObjectId() != -1 ){%> disabled <%}%> onclick="if( confirm( 'Doriti sa anulati reclamatia ?')) window.location = '<%=GlobalAppConstants.APP_NAME%>?action=callcenter_deleteReclamatie&id=<%=reclamatie.getId()%>'; ">Anulare reclamatie</button> &nbsp;&nbsp;--%>

        <% final long codCir = zeCir != null ? zeCir.getCod() : -1;%>
        <% final Nomenclator[] ciruri = NomAccessDB.getAllNom(NomConstants.NOM_CIR); %>
        Retransmite reclamatia catre:&nbsp;
        <select name="<%=ReclamatieConstants.COD_CIR%>" class="gSAPSelect" >
            <option value="-1">Selectati:</option>
            <% for (int i = 0; i < ciruri.length; i++) { %>
                <option value="<%=ciruri[i].getCod()%>" <%=ciruri[i].getCod() == codCir ? "selected" : ""%>  ><%=ciruri[i].getDescriere()%></option>
            <%} %>
        </select>&nbsp;&nbsp;
        <button onclick="retransmitere()" >Retransmite</button> &nbsp;&nbsp;
    <%}%>
    <button onclick="window.close()">Inchide fereastra</button>
</div>

</td>
</tr>
</TABLE>
</form>
<!--</td></tr></TBODY></TABLE>-->
<%}%>
<%}%>


<script type="text/javascript">
    var inputs = document.getElementsByTagName("input");
    for( var i = 0; i < inputs.length; i++){
        inputs[i].style.fontSize = "12px";
    }

    inputs = document.getElementsByTagName("textarea");
    for( var i = 0; i < inputs.length; i++){
        inputs[i].style.fontSize = "12px";
    }

    function retransmitere(){
        document.zaforma.submit();
    }
</script>
