<%@ page import="ro.emid.common.types.Instalatie" %>
<%@ page import="ro.emid.common.db.InstalatieDB" %>
<%@ page import="ro.emid.common.constants.LFInfoConstants" %>
<%@ page import="ro.emid.common.types.LFInfo" %>
<%@ page import="ro.emid.common.db.LFInfoAccessDB" %>
<%@ page import="ro.emid.common.constants.GlobalAppConstants" %>
<%@ page import="ro.emid.common.utils.RequestUtils" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>


<%

try{

    final int an = RequestUtils.getInt( request, "an", -1);

    final String codLF = RequestUtils.getString( request, "codLF");

    final Instalatie lf = InstalatieDB.getLFByCodSAP( codLF);

    LFInfo lfInfo = null;
    if( lf != null){
        if( an > 0){
            lfInfo = LFInfoAccessDB.getEntryByCodSapLF( lf.getCodCE(), lf.getCod(), an);
        }

        if( lfInfo == null){
            lfInfo = LFInfoAccessDB.getLastEntryByCodSapLF( lf.getCodCE(), lf.getCod());
        }
    }
%>
<respmesg>
    <%if( lf == null){  %>
        Nu s-a gasit locul functional avand codul <%=codLF%>
    <%}else if( lfInfo == null){%>
        Lipsa date ...<br>
    <%}else{%>
        <table width="95%">
            <tr>
                <td>
                    <%if ( lfInfo.getAn() != an){%>
                        <span style="color: red">
                            Atentie! Datele sunt valabile pentru anul <%=lfInfo.getAn()%>.
                        </span>
                    <%}%>
                    <fieldset class="mt10">
                        <legend>Generale</legend>
                        <table width="100%" class="table no-border" cellspacing="0">
                            <%--<tr><td >Cod:</td><td class="align-right"><%=lf.getCod()%></td></tr>--%>
                            <%--<tr><td>Denumire:</td><td class="align-right"><%=lf.getNume()%></td></tr>--%>
                            <tr><td width="200px">Localitate:</td><td class="align-right"><%=lfInfo.getLocalitate()%></td></tr>
                            <tr><td>Mediul:</td><td class="align-right"><%=lfInfo.getMediu() == LFInfoConstants.MEDIU_URBAN ? "Urban" : ( lfInfo.getMediu() == LFInfoConstants.MEDIU_RURAL ? "Rural" : "-")%></td></tr>
                            <tr><td>Snom:</td><td class="align-right"><%=lfInfo.getSNom()%></td></tr>
                            <tr><td>Pnom=<%=LFInfoConstants.CONSTANT_PNON%> * Snom:</td><td class="align-right"><%=AppConstants.format03(LFInfoConstants.calculPNom(lfInfo.getSNom()))%></td></tr>
                            <tr><td>Grad Incarcare (%):</td><td class="align-right"><%=AppConstants.printGradIncarcare(lfInfo.getGradIncarcare())%></td></tr>
                            <tr><td>An PIF:</td><td class="align-right"><%=lfInfo.getAnPif()%></td></tr>
                            <tr><td>Stare:</td><td class="align-right"><%=lf.getSters() == 1 ? "Sters" : "Activ"%></td></tr>
                            <tr><td>Valabilitate:</td><td class="align-right"><%=AppConstants.format(lfInfo.getAn())%></td></tr>
                            <tr><td>Ultima actualizare:</td><td class="align-right"><%=AppConstants.format(lfInfo.getDataSave())%></td></tr>
                        </table>
                    </fieldset>

                    <%
                        final long total = lfInfo.getNumarConsumatoriCasnici() + lfInfo.getNumarConsumatoriMici() + lfInfo.getNumarConsumatoriMari();
                    %>

                    <fieldset class="mt10">
                        <legend>Numar Consumatori : <span><%=total%></span></legend>
                        <table width="100%" class="table no-border" cellspacing="0">
                            <tr><td width="200px">Casnici:</td><td class="align-right"><%=lfInfo.getNumarConsumatoriCasnici()%></td></tr>
                            <tr><td>Mici:</td><td class="align-right"><%=lfInfo.getNumarConsumatoriMici()%></td></tr>
                            <tr><td>Mari:</td><td class="align-right"><%=lfInfo.getNumarConsumatoriMari()%></td></tr>
                        </table>
                    </fieldset>

                    <fieldset class="mt10">
                        <legend>Nr. consumatori / Nivel tensiune</legend>
                        <table width="100%" class="table no-border" cellspacing="0">
                            <tr><td width="200px">JT:</td><td class="align-right"><%=lfInfo.getNumarConsumatoriJT()%></td></tr>
                            <tr><td>MT:</td><td class="align-right"><%=lfInfo.getNumarConsumatoriMT()%></td></tr>
                            <tr><td>IT:</td><td class="align-right"><%=lfInfo.getNumarConsumatoriIT()%></td></tr>
                        </table>
                    </fieldset>
                </td>
            </tr>

        </table>
    <%}%>
</respmesg>

<%}catch( Exception t){%>
    <%=t.getMessage()%>
<%}%>
