<%@ page import="ro.emid.callcenter.obj.AlocareLocalitateCentru" %>
<%@ page import="ro.emid.common.types.Reclamatie" %>
<%@ page import="ro.emid.common.utils.StringUtils" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationController" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationData" %>
<%@ page import="ro.emid.common.utils.sort.SortController" %>
<%@ page import="ro.emid.common.utils.sort.SortData" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>

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

<%
    /**
     * @see ro.emid.callcenter.action.localitatice.LoadReclamatiiPentruRealocareAction
     */

    AlocareLocalitateCentru alocare = (AlocareLocalitateCentru) request.getAttribute("alocare");
    List<Reclamatie> reclamatii = (List<Reclamatie>) request.getAttribute("reclamatii");
    Map<Long, Category> centre = (Map<Long, Category>) request.getAttribute("centre");

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

<table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr valign="top">
        <td width="180">
            <%@ include file="menu.jsp"%>
        </td>
        <td class="pl5">
            <%@ include file="../../layout/messages.jspf"%>

            Realocare reclamaţii neprocesate inregistrate la adresa j.<%=alocare.getJudet()%>, loc: <%=alocare.getMunicipiu()%>, sat: <%=StringUtils.getNullSafe(alocare.getLocalitate())%> la centru <%=alocare.getNumeCentru()%>

            <% if( reclamatii == null || reclamatii.size() == 0){ %>

            <div class="m5" style="color: red;">
                Nu există reclamaţii neprocesate la adresa alocată avand alt centru decit <%=alocare.getNumeCentru()%> <br/>
            </div>

            <input type="button" value="Inapoi" class="mt5" onclick="window.history.back()"/>

            <% }else{ %>

            <form action="<%=AppConstants.APP_NAME%>" method="get" id="ze-form">
                <input type="hidden" name="action" id="ze-action" value="load-realocare-reclamatii"/>
                <input type="hidden" name="idAlocare" value="<%=alocare.getId()%>"/>
                <%=SortController.initSort(sd)%>

                <div class="m5" style="color: red;">
                    Urmatoarele reclamatii au fost inregistrate la adresa j.<%=alocare.getJudet()%>, loc: <%=alocare.getMunicipiu()%>, sat: <%=StringUtils.getNullSafe(alocare.getLocalitate())%> <br/>
                    Doriti in continuare realocarea lor la centrul <%=alocare.getNumeCentru()%> ?
                </div>

                <div>
                    <table class="table" width="100%" cellpadding="" cellspacing="1">
                        <thead>
                        <tr>
                            <th width="1%">&nbsp;</th>
                            <th width="100">
                                <%=SortController.printSortableColumn("Numar", "ID", sd)%>
                            </th>
                            <th>
                                Adresa
                            </th>
                            <th>
                                Reclamant
                            </th>
                            <th>
                                CE
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        <% for(Reclamatie reclamatie : reclamatii) { %>
                        <%  Category centru = centre.get(reclamatie.getIdCentru());%>
                        <tr>
                            <td>
                                <input type="checkbox" name="idReclamatie" value="<%=reclamatie.getId()%>" checked="checked" />
                            </td>
                            <td>
                                <a class="link" onclick="showDateReclamatie(<%=reclamatie.getId()%>)">
                                    <%=reclamatie.getNiceNumarReclamatie()%>
                                </a>
                            </td>
                            <td><%=reclamatie.getAdresaReclamatie()%></td>
                            <td><%=reclamatie.getNumeClient()%></td>
                            <td data-centru-id="<%=centru != null ? centru.getId() : -1%>"><%=centru != null ? centru.getName() : "-"%></td>
                        </tr>
                        <% } %>
                        </tbody>
                        <tfoot>
                        <tr>
                            <td colspan="5">
                                <div class="pull-right">
                                    <%=PaginationController.printPaginationData(pd)%>
                                </div>
                            </td>
                        </tr>
                        </tfoot>
                    </table>
                </div>

                <div class="mt5">
                    <input type="button" id="btn-realocare" value="Realocă reclamațiile selectate la <%=alocare.getNumeCentru()%>" <%=reclamatii == null || reclamatii.size() == 0 ? "disabled":""%>/>
                    <input type="button" value="Renunță" onclick="window.history.back()"/>
                </div>
            </form>

            <script type="text/javascript">
                jQuery(function(){
                    jQuery("#btn-realocare").click(function(){
                        jQuery("#ze-action").val("realocare-reclamatii");
                        jQuery("#ze-form").submit();
                    });
                });
            </script>

            <% } %>
        </td>
    </tr>
</table>

