<%@ page import="ro.emid.callcenter.db.ClientEligibilAccessDB" %>
<%@ page import="ro.emid.callcenter.obj.ClientEligibil" %>
<%@ page import="ro.emid.callcenter.obj.LocConsum" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationData" %>
<%@ page import="ro.emid.common.utils.sort.SortData" %>
<%@ page import="ro.emid.callcenter.obj.ClientEligibilConstants" %>
<%@ page import="ro.emid.common.utils.pagination.PaginationController" %>
<%@ page import="ro.emid.common.utils.*" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.utils.sort.SortController" %>

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

<%
    /**
     * @see ro.emid.callcenter.action.ShowClientiEligibiliAction
     */
    final SortData sd = (SortData) request.getAttribute("sortData");
    final PaginationData pd = (PaginationData) request.getAttribute("paginationData");

    ClientEligibil[] clienti = (ClientEligibil[]) request.getAttribute("clienti");
%>

<div class="spacer"></div>
<table width="100%" border=0>
    <tr><td>
        <b>Clienti Eligibili</b>
        <form action="<%=AppConstants.APP_NAME%>?action=show-clienti-eligibili" method="post">
        <%=SortController.initSort(sd)%>
        <TABLE id="table" border=0 cellPadding=2 cellSpacing=1 width="100%" class="gSAPTHEAD" style="BACKGROUND-COLOR: white; margin-top: 5px">
            <thead>
                <tr noSelect="true">
                    <TH class="gsapthead" noWrap width=100>&nbsp;
                        <%=SortController.printSortableColumn("Furnizor", ClientEligibilConstants.NUME_FURNIZOR, sd)%>
                    </TH>
                    <TH class="gsapthead" noWrap width=100>&nbsp;
                        <%=SortController.printSortableColumn("Client", ClientEligibilConstants.NUME_CLIENT, sd)%>
                    </TH>
                    <TH class="gsapthead" align="left" noWrap>&nbsp;NLC - Adresa&nbsp;</TH>
                    <TH class="gsapthead" noWrap width=50>&nbsp;Telefon&nbsp;</TH>
                    <TH class="gsapthead" noWrap width=50>&nbsp;Sucursala/Sectia&nbsp;</TH>
                    <% if(UserUtils.hasRoleAdminCallcenter(user) || ( UserUtils.hasRoleUtilizatorCallcenter(user) && UserUtils.hasCcRightEditareClientiEligibili(user))){%>
                        <TH class="gsapthead" noWrap width="5%">&nbsp;Operatie&nbsp;</TH>
                    <%}%>
                </tr>
            </thead>
            <tbody>
                <% if( clienti.length == 0){%>
                <TR noSelect="true">
                    <TD colspan="10" class="no-data-row">
                        Nu exista date ...
                    </TD>
                </TR>
                <%} else for (int i = 0; i < clienti.length; i++) {
                        final ClientEligibil client = clienti[i];
                        final LocConsum[] locuriConsum = ClientEligibilAccessDB.getLocuriConsum( client.getId());%>
                        <tr valign="top">
                            <td><%=ObjectUtils.getStringValue( client.getFurnizor().getNume())%></td>
                            <td><%=ObjectUtils.getStringValue( client.getNume())%></td>
                            <td align="left">
                                <% for (int j = 0; j < locuriConsum.length; j++) {
                                    final LocConsum locConsum = locuriConsum[j]; %>
                                    <%=locConsum.getNlc()%> -
                                    <%=AppConstants.format(locConsum.getLocalitate())%>,
                                    <%=AppConstants.format(locConsum.getAdresa())%> <br>
                                <%}%>
                            </td>
                            <td><%=AppConstants.format(client.getTelefon())%></td>
                            <td><%=AppConstants.format(client.getFax())%></td>
                            <% if(UserUtils.hasRoleAdminCallcenter(user) || ( UserUtils.hasRoleUtilizatorCallcenter(user) && UserUtils.hasCcRightEditareClientiEligibili(user))){%>
                                <td align="left" nowrap >
                                    <a class="link" title="Editeaza client" href="<%=AppConstants.APP_NAME%>?action=editClientEligibil&id=<%=client.getId()%>">Modifică</a>
                                    <a class="link" title="Sterge client" onclick="return confirm('Stergeti clientul ?')" href="<%=AppConstants.APP_NAME%>?action=deleteClientEligibil&id=<%=client.getId()%>">Şterge</a>
                                </td>
                            <% }%>
                        </tr>
                    <%}%>
            </tbody>
            <tfoot>
                <tr class="paginationRow" noSelect="true">
                    <td colspan="6" >
                        <div style="float: left;margin: 2px;">
                            <%if( UserUtils.hasRoleAdminCallcenter(user) || ( UserUtils.hasRoleUtilizatorCallcenter(user) && UserUtils.hasCcRightEditareClientiEligibili(user))){%>
                                <input type="button" data-href="<%=AppConstants.APP_NAME%>?action=editClientEligibil" value="Adaugă client"/>
                            <%}%>
                        </div>
                        <div style="float: right">
                            <%=PaginationController.printPaginationData(pd)%>
                        </div>
                    </td>
                </tr>
        </TABLE>
    </form>
    </td></tr>
</table>

<script type="text/javascript">
    var table = new Table('table', "table");
</script>





