<%@ page import="org.apache.log4j.Logger"%>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.types.ConsultareClient" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.callcenter.util.CallcenterHelper" %>
<%@ page import="java.util.List" %>
<%
    final Logger LOG = Logger.getLogger("cautClientResp_jsp");

    final String whatToSearch = ObjectUtils.getStringValue(request.getParameter("q")).trim();
    final String judet = ObjectUtils.getStringValue(request.getParameter("judet"));
    final String localitate = ObjectUtils.getStringValue(request.getParameter("loc"));
    final String localitate2 = ObjectUtils.getStringValue(request.getParameter("loc2"));
    final String tipArtera = ObjectUtils.getStringValue(request.getParameter("tipArtera"));
    final long codStrada = ObjectUtils.getLongValue(request.getParameter("codStrada"), -1);
    final String denStrada = ObjectUtils.getStringValue(request.getParameter("strada"));

    final String nr = ObjectUtils.getStringValue(request.getParameter("nr")).trim();

    final String bloc = ObjectUtils.getStringValue(request.getParameter("bloc")).trim();
    final String scara = ObjectUtils.getStringValue(request.getParameter("scara")).trim();
    final String etaj = ObjectUtils.getStringValue(request.getParameter("etaj")).trim();
    final String ap = ObjectUtils.getStringValue(request.getParameter("ap")).trim();

    final String codLoc2 = ObjectUtils.getStringValue(request.getParameter("codLoc2")).trim();


    LOG.debug(" whatToSearch=" + whatToSearch);
    try {
        /*
        String condSql = "";

        if (nr.length() > 0) {
            condSql += " AND  NUMAR = '" + nr + "' ";
        }

        if (bloc.length() > 0) {
            condSql += " AND UPPER( BLOC) LIKE '%" + ro.emid.common.utils.Util.escapeToSql(bloc.toUpperCase()) + "%' ";
        }

        if (scara.length() > 0) {
            condSql += " AND UPPER( SCARA) LIKE '%" + ro.emid.common.utils.Util.escapeToSql(scara.toUpperCase()) + "%' ";
        }

//        if (etaj.length() > 0) {
//            condSql += " AND UPPER( SUBSTR(  cgv, 0, INSTR( cgv, '/')-1)) LIKE '%" + Util.escapeToSql( etaj.toUpperCase()) + "%' ";
//        }

        if (ap.length() > 0) {
            condSql += " AND UPPER( AP) LIKE '%" + ro.emid.common.utils.Util.escapeToSql(ap.toUpperCase()) + "%' ";
        }

        Client[] clienti = OpenSCGAccessDB.searchClient(whatToSearch, localitate, tipArtera, denStrada, condSql, " AND ROWNUM < 100 ");
        */



        List<ConsultareClient> clienti = CallcenterHelper.getIntegrationApi().getConsultareClienti(whatToSearch, judet, localitate, localitate2, tipArtera, denStrada, nr, bloc, scara, ap, codLoc2);
        LOG.debug("GASIT " + clienti.size() + " CLIENTI");
%>
<respmesg>
    <% if(clienti.size() == 0){%>
    <div onSelect="this.txtBox.value = '';">
        Nu exista informatii ...
    </div>
    <%}else for (ConsultareClient client : clienti) {  %>
    <div onSelect="this.txtBox.value = '<%=client.getNumeClient()%>';
                completeazaAdresa(
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  client.getJudet()))%>',
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  client.getCodMunicipiu()))%>',
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  client.getMunicipiu()))%>',
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  client.getCodLocalitate()))%>',
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  client.getLocalitate()))%>',
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  client.getTipArtera()))%>',
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  client.getDenStrada()))%>',
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  client.getNr()))%>',
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  client.getBloc()))%>',
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  client.getScara()))%>',
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  ""))%>',
                        '<%=ro.emid.common.utils.Util.escapeToJs( AppConstants.format(  client.getAp()))%>'
                    ); " >
        <%=client.getNumeClient()%>
    </div>
    <% }%>
</respmesg>
<%} catch (Throwable t) {
    LOG.error( "Eroare get lista nomen", t);
}%>
