<%@ page import="ro.emid.administrare.obj.binder.LFInfoBinder" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.constants.LFInfoConstants" %>
<%@ page import="ro.emid.common.constants.NomConstants" %>
<%@ page import="ro.emid.common.constants.WebConstants" %>
<%@ page import="ro.emid.common.constants.GlobalAppConstants" %>
<%@ page import="ro.emid.common.db.LFInfoAccessDB" %>
<%@ page import="ro.emid.common.types.LFInfo" %>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>

<% if (request.getAttribute("act") !=null) {%>
        <script type="text/javascript">
            <%--opener.refreshData(<%=request.getAttribute("deleted") != null%> );--%>
            window.opener.location.reload();
            window.close();
        </script>
<%}else{%>

<%
    int obj_type = ObjectUtils.getIntValue(request.getParameter("type_ob"), -1);
    session.setAttribute("type_ob", new Integer(obj_type));
    if (obj_type == -1) {
        obj_type = session.getAttribute("type_ob") != null ? ((Integer)session.getAttribute("type_ob")).intValue() : -1;
    }

    final LFInfoBinder binder = (LFInfoBinder) session.getAttribute(LFInfoConstants.BEAN);
    final LFInfo bean = (LFInfo) binder.getBean();


    Integer []aniLf = LFInfoAccessDB.getAniLFInfo(bean.getCodCE());
    aniLf = ro.emid.common.utils.Util.addCurrentYear(aniLf);
%>
<TABLE class="gsapthead" align=center border=0 cellPadding=10 cellSpacing=0 width="100%">
    <TBODY>
        <TR>
            <TD>
                <TABLE align=center border=0 cellPadding=1 cellSpacing=0 width="100%" class="gsaptd">
                    <% if ( obj_type == ro.emid.common.constants.NomConstants.NOM_STATII || obj_type == (NomConstants.NOM_LINII)) { %>
                     <form name="zaforma" action="<%=AppConstants.APP_NAME%>"  method="post">
                         <input type="hidden" name="type_ob" value="<%=obj_type%>">
                         <% } %>
                        <input type="hidden" name="action" value="saveLFInfo">
                        <input type="hidden" name="<%=LFInfoConstants.COD_CE%>" value="<%=bean.getCodCE()%>">
                    
                        <TBODY>
                            <TR>
                                <TD colspan="2">

                                    <CENTER><h3>Alte informatii Loc Functional</h3></CENTER>
                                    <%@ include file="../../layout/messages.jspf"%>
                                    <table align="center" width="100%">
                                        <col align="right">
                                        <col>
                                        <col align="right">
                                        <col>
                                        <tr>
                                            <td>Cod LF</td>
                                            <td>
                                                <input type="text" readonly size="40" class="gsapinputtext" name="<%=LFInfoConstants.COD_SAP_LF%>" value="<%=AppConstants.format( bean.getCodSapLF())%>" >
                                            </td>
                                            <td >
                                                An valabilitate date:
                                            </td>
                                            <td>
                                                <select class="gSAPSelect" name="<%=LFInfoConstants.AN%>" onchange="getLfInfoFromOtherYear( this)">
                                                    <% for (int i = 0; i < aniLf.length; i++) {
                                                            final Integer an = aniLf[i];%>
                                                            <option value="<%=an%>" <%=an.longValue() == bean.getAn() ? "selected" : ""%> ><%=an%></option>
                                                    <% }%>
                                                </select>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Descriere LF</td>
                                            <td>
                                                <input type="text" readonly size="40" class="gsapinputtext" name="<%=LFInfoConstants.DESCRIERE_LF%>" value="<%=AppConstants.format( bean.getDescriereLF())%>" >
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Localitate</td>
                                            <td>
                                                <input type="text" size="40" class="gsapinputtext" name="<%=LFInfoConstants.LOCALITATE%>" value="<%=AppConstants.format( bean.getLocalitate())%>" >
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Comuna/Oras</td>
                                            <td>
                                                <input type="text" size="40" class="gsapinputtext" name="<%=LFInfoConstants.COMUNA_ORAS%>" value="<%=AppConstants.format( bean.getComunaOras())%>" >
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Mediul</td>
                                            <td>
                                                <input type="radio" id="urban" name="<%=LFInfoConstants.MEDIU%>" value="<%=LFInfoConstants.MEDIU_URBAN%>" <%=bean.getMediu() == LFInfoConstants.MEDIU_URBAN ? "checked" : ""%> ><label for="urban">Urban</label>
                                                <input type="radio" id="rural" name="<%=LFInfoConstants.MEDIU%>" value="<%=LFInfoConstants.MEDIU_RURAL%>" <%=bean.getMediu() == LFInfoConstants.MEDIU_RURAL ? "checked" : ""%> ><label for="rural">Rural</label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Proprietar</td>
                                            <td>
                                                <input type="text" size="40" class="gsapinputtext" name="<%=LFInfoConstants.PROPRIETAR%>" value="<%=AppConstants.format( bean.getProprietar())%>" >
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Snom</td>
                                            <td>
                                                <input type="text" size="10" style="text-align: right;" class="gsapinputtext" name="<%=LFInfoConstants.SNOM%>" value="<%=bean.getSNom()%>" > [KVA]
                                            </td>
                                            <td>Pnom</td>
                                            <td>
                                                <input type="text" size="10" style="text-align: right;" class="gsapinputtext" name="<%=LFInfoConstants.PNOM%>" readonly value="<%=AppConstants.format( LFInfoConstants.calculPNom( bean.getSNom()))%>" > [KW]
                                            </td>
                                        </tr>

                                        <tr>
                                            <td>Grad Incarcare</td>
                                            <td>
                                                <input type="text" size="10" style="text-align: right;" class="gsapinputtext" name="<%=LFInfoConstants.GRAD_INCARCARE%>" value="<%=AppConstants.printGradIncarcare(bean.getGradIncarcare())%>"> % <!--[0-1]-->
                                            </td>
                                            <td>An PIF</td>
                                            <td>
                                                <input type="text" size="10" style="text-align: right;" class="gsapinputtext" name="<%=LFInfoConstants.AN_PIF%>" value="<%=bean.getAnPif()%>">
                                            </td>
                                        </tr>

                                        <tr>
                                            <td colspan="4"><hr></td>
                                        </tr>

                                        <tr>
                                            <td>Nr. consumatori Casnici</td>
                                            <td>
                                                <input type="text" size="10" style="text-align: right;" class="gsapinputtext" name="<%=LFInfoConstants.NUMAR_CONSUMATORI_CASNICI%>" value="<%=bean.getNumarConsumatoriCasnici()%>">
                                            </td>

                                            <td>Nr. consumatori JT</td>
                                            <td>
                                                <input type="text" size="10" style="text-align: right;"  class="gsapinputtext" name="<%=LFInfoConstants.NUMAR_CONSUMATORI_JT%>" value="<%=bean.getNumarConsumatoriJT()%>">
                                            </td>

                                        </tr>
                                        <tr>
                                            <td>Nr. consumatori Mici</td>
                                            <td>
                                                <input type="text" size="10" style="text-align: right;" class="gsapinputtext" name="<%=LFInfoConstants.NUMAR_CONSUMATORI_MICI%>" value="<%=bean.getNumarConsumatoriMici()%>">
                                            </td>

                                            <td>Nr. consumatori MT</td>
                                            <td>
                                                <input type="text" size="10" style="text-align: right;" class="gsapinputtext" name="<%=LFInfoConstants.NUMAR_CONSUMATORI_MT%>" value="<%=bean.getNumarConsumatoriMT()%>">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Nr. consumatori Mari</td>
                                            <td>
                                                <input type="text" size="10" style="text-align: right;" class="gsapinputtext" name="<%=LFInfoConstants.NUMAR_CONSUMATORI_MARI%>" value="<%=bean.getNumarConsumatoriMari()%>">
                                            </td>



                                            <td>Nr. consumatori IT</td>
                                            <td>
                                                <input type="text" size="10" style="text-align: right;" class="gsapinputtext" name="<%=LFInfoConstants.NUMAR_CONSUMATORI_IT%>" value="<%=bean.getNumarConsumatoriIT()%>">
                                            </td>
                                        </tr>

                                        <tr>
                                            <td colspan="4"><hr></td>
                                        </tr>

                                        <tr>
                                            <td align="left" colspan="2">
                                                <% if( ro.emid.common.utils.Util.getCurrentYear() == bean.getAn() && null != LFInfoAccessDB.getEntryByCodSapLF(bean.getCodCE(), bean.getCodSapLF(), bean.getAn()-1)){%>
                                                    <a class="link" title="Completeaza cu date din anul <%=(bean.getAn()-1)%>" href="<%=AppConstants.APP_NAME%>?action=copyLfInfoFromLastYear">Completeaza cu date din anul <%=(bean.getAn()-1)%></a>
                                                <% } %>
                                            </td>
                                            <td align="right" colspan="2">

                                                <% if ( obj_type == ro.emid.common.constants.NomConstants.NOM_STATII || obj_type == (NomConstants.NOM_LINII)) { %>
                                                    <% if( ro.emid.common.db.SesiuneRaportareAccessDB.isDeschisa(bean.getAn())){ %>
                                                        <input type="submit" value="Salveaza" title="Salveaza intrarea"> &nbsp;

                                                        <% if( !bean.isNew()){ %>
                                                            <input type="button" value="Sterge" title="Sterge intrarea" onclick=" if(confirm('Stergeti intrarea ?')) window.location='<%=AppConstants.APP_NAME%>?action=deleteLFInfo'"> &nbsp;
                                                        <% } %>
                                                    <% } %>
                                                <% } %>

                                                <input type="button" value="Inchide fereastra" title="Inchide fereastra" onclick="window.close()">
                                            </td>
                                        </tr>
                                    </table>
                                </TD>
                            </TR>
                        </TBODY>
                    </form>
                </TABLE>
            </TD>
        </TR>
    </TBODY>
</TABLE>

<script type="text/javascript">
    document.zaforma.<%=LFInfoConstants.LOCALITATE%>.focus();

    function getLfInfoFromOtherYear( oSelect){
        var anSelectat = oSelect.options[ oSelect.selectedIndex].value;
        window.location = "<%=AppConstants.APP_NAME%>?action=editLFInfo&<%=LFInfoConstants.COD_SAP_LF%>=<%=bean.getCodSapLF()%>&<%=LFInfoConstants.AN%>="+anSelectat;
    }
</script>
<%}%>

