<%@ page import="ro.emid.common.types.Incident" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationController" %>
<%@ page import="java.util.Date" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationData" %>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.utils.sort.SortController" %>
<%@ page import="ro.emid.common.utils.sort.SortData" %>

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

<%
        /**
         * @see ro.emid.incidente.action.ShowRaportLucrariAccidentaleIncidenteAction
         */

    int durataIncidentH = ObjectUtils.getIntValue(request.getParameter("durataIncidentH"), -1);    // in db -> minute
    int durataIncidentM = ObjectUtils.getIntValue(request.getParameter("durataIncidentM"), -1);
    int durataSelect = ObjectUtils.getIntValue(request.getParameter("durataSelect"), -1);
    int mediuSelect = ObjectUtils.getIntValue(request.getParameter("mediuSelect"), -1);


    String titluRaport = (String) request.getAttribute("title");
    Date dataStart = (Date) request.getAttribute("dataStart");
    Date dataStop  = (Date) request.getAttribute("dataStop");

    PaginationData pd = (PaginationData) request.getAttribute("pd");
    SortData sd = (SortData) request.getAttribute("sd");

    Incident[] incidenteArray = (Incident[]) request.getAttribute("result");

%>

<%-- @@@@@@@@@@@@@@@ HEADER --%>
<style type="text/css">
    .clasu {
        width: 50px;
        text-align: right;
    }

    .trclass0{

    }

    .trclass1{
        background-color: #EEE;
    }

</style>

<SPAN style="FONT-SIZE: 12px; FONT-WEIGHT: bold">Lucrări accidentale incidente</span>

<%-- @@@@@@@@@@@@@@@ Filter Table--%>
<div class="spacer">&nbsp;</div>
<div class="spacer">&nbsp;</div>
<form name="form" action="<%=AppConstants.APP_NAME%>?action=raport-lucrari-accidentale-incidente" method="post">
    <input type="hidden" name="run_report" value="1"/>
    <%=SortController.initSort(sd)%>
    <table >
        <tr>
            <td>
                <table class="gsaptd" width="100%">
                    <tr>
                        <td align="left">

                            <span style="font-size:16px; font-weight:bold;"><%=ObjectUtils.getStringValue(titluRaport)%></span>
                        </td>
                        <td>
                            <emid:filtru-localizare/>
                        </td>
                        <td align="right">
                            <input type="hidden" name="toExport" value="0">

                            <label>
                                Durata:
                                <select name="durataSelect" id="durataSelect">
                                    <option value="-1"></option>
                                    <option <%=durataSelect == 0 ? "selected=\"true\"" : "" %> value="0">=</option>
                                    <option <%=durataSelect == 1 ? "selected=\"true\"" : "" %> value="1">></option>
                                    <option <%=durataSelect == 2 ? "selected=\"true\"" : "" %> value="2"><</option>
                                </select>
                            </label>
                            <input type="text" id="durataIncidentH" name="durataIncidentH" size="3"
                                   value="<%=durataIncidentH == -1 ? "" : Integer.toString(durataIncidentH)%>"/>h
                            <input type="text" id="durataIncidentM" name="durataIncidentM" size="3"
                                   value="<%=durataIncidentM == -1 ? "" : Integer.toString(durataIncidentM)%>"/>m &nbsp;

                            <label>
                                Perioada: <emid:datefield name="dataStart" value="<%=dataStart%>"/> -
                            </label>
                            <emid:datefield name="dataStop" value="<%=dataStop%>"/> &nbsp;

                            <label>
                                Mediu:
                                <select name="mediuSelect">
                                    <option value="-1"></option>
                                    <option <%=mediuSelect == 1 ? "selected=\"true\"" : "" %> value="1">R</option>
                                    <option <%=mediuSelect == 2 ? "selected=\"true\"" : "" %> value="2">U</option>
                                </select>
                            </label> &nbsp;
                            <input type="submit" value="Rulează" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <%-- @@@@@@@@@@@@@@@ Filter Table END--%>

        <%-- @@@@@@@@@@@@@@@ Main Table--%>
        <tr>
            <td>
                <div class="spacer">&nbsp;</div>
                <table border="0.5" width="100%" style="background-color: white;" cellspacing="1" class="data">
                    <col align="center">
                    <col align="left">
                    <col align="center">
                    <thead>
                    <tr>
                        <th rowspan="2" class="gsapthead"><%=SortController.printSortableColumn("Nr. incident", "NUMAR_INCIDENT", sd)%></th>
                        <th rowspan="2" class="gsapthead">Denumire instalaţie</th>
                        <th rowspan="2" class="gsapthead">Durata incident</th>
                        <th colspan="3" class="gsapthead">Număr utilizatori</th>
                        <th rowspan="2" class="gsapthead"><%=SortController.printSortableColumn("Mediu", "MEDIU", sd)%></th>
                        <th rowspan="2" class="gsapthead">Energie nelivrată</th>
                        <th rowspan="2" class="gsapthead">Forţa majoră</th>
                    </tr>
                    <tr>
                        <th class="gsapthead">JT</th>
                        <th class="gsapthead">MT</th>
                        <th class="gsapthead">IT</th>
                    </tr>
                    </thead>
                    <tbody>
                    <% if (incidenteArray == null || incidenteArray.length == 0 ) {%>
                        <tr>
                            <td colspan="10" class="no-data">
                                Nu există date ...
                            </td>
                        </tr>
                    <% }else for (int i = 0; i < incidenteArray.length; i++) {
                            Incident incident = incidenteArray[i]; %>
                            <tr class='trclass<%=i%2%>' valign="top">
                                <td class="align-center"><%=incident.getNumarIncident()%></td>
                                <td><%=totalDenumireI(incident)%></td>
                                <td class="align-center"><%=incident.getDurataIncident() / 60%>h <%=incident.getDurataIncident() % 60%>'</td>
                                <td class="align-center"><%=incident.getUtilizatori_JT()%></td>
                                <td class="align-center"><%=incident.getUtilizatori_MT()%></td>
                                <td class="align-center"><%=incident.getUtilizatori_IT()%></td>
                                <td class="align-center"><%=incident.getMediu() == 1 ? "R" : incident.getMediu() == 2 ? "U" : ""%></td>
                                <td class="align-center"><%=incident.getEnergieNelivrata()%></td>
                                <td class="align-center"><%=incident.getFortaMajora() == 0 ? "NU" : "DA"%></td>
                            </tr>
                    <% } %>
                    </tbody>
                    <tfoot>
                        <tr>
                            <td class="gsapthead" colspan="10">
                                <%=PaginationController.printPaginationData(pd)%>
                            </td>
                        </tr>
                    </tfoot>
                </table>
            </td>
        </tr>
    </table>

</form>

<%-- @@@@@@@@@@@@@@@ Main Table END--%>

<%!
    private String totalDenumireI(Incident i) {
        String temp = "";
        if (i.getStatieNume() != null && i.getStatieNume().trim().length() > 0)
            temp += "2.5 Statie : " + i.getStatieNume() + "<br/>";
        if (i.getBobinaNume() != null && i.getBobinaNume().trim().length() > 0)
            temp += "2.5.1 Bobina : " + i.getBobinaNume() + "<br/>";
        if (i.getCelulaNume() != null && i.getCelulaNume().trim().length() > 0)
            temp += "2.6 Celula : " + i.getCelulaNume() + "<br/>";
        if (i.getBaraNume() != null && i.getBaraNume().trim().length() > 0)
            temp += "2.6.1 Bara : " + i.getBaraNume() + "<br/>";
        if (i.getLinieNume() != null && i.getLinieNume().trim().length() > 0)
            temp += "2.7 Linie : " + i.getLinieNume() + "<br/>";
        if (i.getDerivatieNume() != null && i.getDerivatieNume().trim().length() > 0)
            temp += "2.7.1 Derivatie : " + i.getDerivatieNume() + "<br/>";
        if (i.getPA_PT_Nume() != null && i.getPA_PT_Nume().trim().length() > 0)
            temp += "2.8 PA/PT : " + i.getPA_PT_Nume() + "<br/>";
        if (i.getTrafoNume() != null && i.getTrafoNume().trim().length() > 0)
            temp += "2.9 Trafo : " + i.getTrafoNume();

        return temp;
    }
%>