Example usage for com.google.gwt.i18n.client DateTimeFormat getShortDateFormat

List of usage examples for com.google.gwt.i18n.client DateTimeFormat getShortDateFormat

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client DateTimeFormat getShortDateFormat.

Prototype

@Deprecated
public static DateTimeFormat getShortDateFormat() 

Source Link

Document

Retrieve the DateTimeFormat object for short date format.

Usage

From source file:com.automaster.client.ui.paineis.dialogs.cadastro.NovaIndicacao.java

public void listarClientes() {

    Info.dbService.buscarPorNomeClienteIndicacao(buscaCliente.getValueAsString(),
            new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                @Override// ww  w.j  a va 2  s .c  om
                public void onFailure(Throwable caught) {
                    throw new UnsupportedOperationException("Erro ao Consultar o Nome do Cliente");
                }

                @Override
                public void onSuccess(ArrayList<TreeMap<String, String>> result) {

                    ListGridField codigo = new ListGridField("codigo", "Cdigo");
                    codigo.setHidden(true);
                    ListGridField nome = new ListGridField("nome", "Nome");
                    ListGridField dataAdesao = new ListGridField("dataAdesao", "Data de Adeso");
                    dataAdesao.setAlign(Alignment.CENTER);
                    ListGridField unidade = new ListGridField("unidade", "Unidade");
                    ListGrid clientes = new ListGrid();
                    clientes.setFields(codigo, nome, dataAdesao, unidade);
                    clientes.setCanPickFields(false);
                    clientes.setShowAllRecords(true);

                    if (result != null) {

                        for (TreeMap<String, String> cl : result) {
                            Record registros = new Record();
                            registros.setAttribute("codigo", cl.get("codCliente"));
                            registros.setAttribute("nome", cl.get("nome"));
                            registros.setAttribute("dataAdesao", DateTimeFormat.getShortDateFormat()
                                    .format(new Date(Long.parseLong(cl.get("dataAdesao")))));
                            registros.setAttribute("unidade", cl.get("nomeUnidade"));
                            clientes.addData(registros);
                        }
                        final Window listGridClientes = new Window();
                        listGridClientes.setTitle("Lista de Clientes");
                        listGridClientes.setWidth(500);
                        listGridClientes.setHeight(300);
                        listGridClientes.setShowMinimizeButton(false);
                        listGridClientes.setIsModal(true);
                        listGridClientes.setShowModalMask(true);
                        listGridClientes.centerInPage();
                        listGridClientes.setLayoutAlign(Alignment.CENTER);
                        listGridClientes.addItem(clientes);
                        listGridClientes.setAnimateTime(1200);
                        listGridClientes.animateShow(AnimationEffect.FADE);

                        clientes.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {

                            @Override
                            public void onRecordDoubleClick(RecordDoubleClickEvent event) {
                                final Record record = (Record) event.getRecord();
                                if (record != null) {
                                    //SC.say("Double-clicked cdigo: <b>" + record.getAttribute("codigo") + "</b>");
                                    Info.dbService.buscarVeiculoPorCodCliente(
                                            record.getAttributeAsInt("codigo"),
                                            new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                                                @Override
                                                public void onFailure(Throwable caught) {
                                                    throw new UnsupportedOperationException(
                                                            "Not supported yet.!!!"); //To change body of generated methods, choose Tools | Templates.
                                                }

                                                @Override
                                                public void onSuccess(
                                                        ArrayList<TreeMap<String, String>> result) {

                                                    if (result != null) {
                                                        final LinkedHashMap<String, String> valueMapVeic = new LinkedHashMap<String, String>();
                                                        for (final TreeMap<String, String> veiculos : result) {
                                                            Info.dbService.buscarIndicacoesPorVeiculo(
                                                                    Integer.parseInt(
                                                                            veiculos.get("codVeiculo")),
                                                                    new AsyncCallback<Integer>() {

                                                                        @Override
                                                                        public void onFailure(
                                                                                Throwable caught) {
                                                                            throw new UnsupportedOperationException(
                                                                                    "Not supported yet.?????"); //To change body of generated methods, choose Tools | Templates.
                                                                        }

                                                                        @Override
                                                                        public void onSuccess(Integer result) {
                                                                            valueMapVeic.put(
                                                                                    veiculos.get("codVeiculo"),
                                                                                    veiculos.get("placa") + "/"
                                                                                            + veiculos.get(
                                                                                                    "fabricante")
                                                                                            + "/"
                                                                                            + veiculos.get(
                                                                                                    "modelo")
                                                                                            + "/"
                                                                                            + veiculos
                                                                                                    .get("cor")
                                                                                            + "/Ind: "
                                                                                            + String.valueOf(
                                                                                                    result));
                                                                            selectVeiculos
                                                                                    .setValueMap(valueMapVeic);
                                                                        }
                                                                    });

                                                        }
                                                        selectVeiculos.setDisabled(false);
                                                        selectVeiculos.setRequired(true);
                                                        buscaCliente
                                                                .setValue(record.getAttributeAsString("nome"));
                                                        cadastrar.enable();
                                                        limpar.enable();
                                                        listGridClientes.destroy();

                                                    } else {
                                                        SC.warn("Este Cliente no Possui Veculo");
                                                    }
                                                }
                                            });

                                } else {
                                    SC.warn("No foi selecionado nenhum registro");
                                }
                            }
                        });

                    } else {
                        Window listGridClientes = new Window();
                        listGridClientes.setTitle("Lista de Clientes");
                        listGridClientes.setWidth(500);
                        listGridClientes.setHeight(500);
                        listGridClientes.setShowMinimizeButton(false);
                        listGridClientes.setIsModal(true);
                        listGridClientes.setShowModalMask(true);
                        listGridClientes.centerInPage();
                        listGridClientes.setLayoutAlign(Alignment.CENTER);
                        listGridClientes.addItem(clientes);
                        listGridClientes.setAnimateTime(1200);
                        listGridClientes.animateShow(AnimationEffect.FADE);
                    }
                }
            });

}

From source file:com.automaster.client.ui.paineis.dialogs.editar.EditarClienteProprietario.java

public void listarClientes() {

    Info.dbService.buscarPorNomeClienteIndicacao(buscaCliente.getValueAsString(),
            new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                @Override/*w w w  .  ja  v  a  2  s  .c om*/
                public void onFailure(Throwable caught) {
                    throw new UnsupportedOperationException("Erro ao Consultar o Nome do Cliente");
                }

                @Override
                public void onSuccess(ArrayList<TreeMap<String, String>> result) {

                    ListGridField codigo = new ListGridField("codigo", "Cdigo");
                    codigo.setHidden(true);
                    ListGridField nome = new ListGridField("nome", "Nome");
                    ListGridField dataAdesao = new ListGridField("dataAdesao", "Data de Adeso");
                    ListGridField unidade = new ListGridField("unidade", "Unidade");
                    ListGrid clientes = new ListGrid();
                    clientes.setFields(codigo, nome, dataAdesao, unidade);
                    clientes.setCanPickFields(false);
                    clientes.setShowAllRecords(true);

                    if (result != null) {

                        for (TreeMap<String, String> cl : result) {
                            Record registros = new Record();
                            registros.setAttribute("codigo", cl.get("codCliente"));
                            registros.setAttribute("nome", cl.get("nome"));
                            registros.setAttribute("dataAdesao", DateTimeFormat.getShortDateFormat()
                                    .format(new Date(Long.parseLong(cl.get("dataAdesao")))));
                            registros.setAttribute("unidade", cl.get("nomeUnidade"));
                            clientes.addData(registros);
                        }
                        final Window listGridClientes = new Window();
                        listGridClientes.setTitle("Lista de Clientes");
                        listGridClientes.setWidth(500);
                        listGridClientes.setHeight(300);
                        listGridClientes.setShowMinimizeButton(false);
                        listGridClientes.setIsModal(true);
                        listGridClientes.setShowModalMask(true);
                        listGridClientes.centerInPage();
                        listGridClientes.setLayoutAlign(Alignment.CENTER);
                        listGridClientes.addItem(clientes);
                        listGridClientes.setAnimateTime(1200);
                        listGridClientes.animateShow(AnimationEffect.FADE);

                        clientes.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {

                            @Override
                            public void onRecordDoubleClick(RecordDoubleClickEvent event) {
                                final Record record = (Record) event.getRecord();
                                if (record != null) {
                                    final LinkedHashMap<String, String> valueMapVeic = new LinkedHashMap<String, String>();
                                    valueMapVeic.put(record.getAttributeAsString("codigo"),
                                            record.getAttributeAsString("nome"));
                                    selectCliente.setValueMap(valueMapVeic);
                                    selectCliente.setDisabled(false);
                                    selectCliente.setRequired(true);
                                    buscaCliente.setValue(record.getAttributeAsString("nome"));
                                    //buscaCliente.setDisabled(true);
                                    selectCliente.setDefaultToFirstOption(true);
                                    cadastrar.enable();
                                    limpar.enable();
                                    listGridClientes.destroy();

                                } else {
                                    SC.warn("No foi selecionado nenhum registro");
                                }
                            }
                        });

                    } else {
                        Window listGridClientes = new Window();
                        listGridClientes.setTitle("Lista de Clientes");
                        listGridClientes.setWidth(500);
                        listGridClientes.setHeight(500);
                        listGridClientes.setShowMinimizeButton(false);
                        listGridClientes.setIsModal(true);
                        listGridClientes.setShowModalMask(true);
                        listGridClientes.centerInPage();
                        listGridClientes.setLayoutAlign(Alignment.CENTER);
                        listGridClientes.addItem(clientes);
                        listGridClientes.setAnimateTime(1200);
                        listGridClientes.animateShow(AnimationEffect.FADE);
                    }
                }
            });

}

From source file:com.automaster.client.ui.paineis.tabs.financeiro.dialogs.EditarFatura.java

public EditarFatura(final int codCliente, final ListGrid listLancamentos, final ListGrid listFaturas,
        final ListGridRecord recordFatura, final Label labelLanc, final Label labelfaturas,
        final Label labelSaldo, final TabConsultaFaturaLancamento objFaturaLancamento) {

    final EditarFatura novaFaturaAux = this;

    setTitle("Editar fatura");
    setWidth(500);/* w ww  . ja  va2s.  c om*/
    setHeight(300);
    setShowMinimizeButton(false);
    setShowCloseButton(false);
    setIsModal(true);
    setShowModalMask(true);
    centerInPage();
    setLayoutAlign(Alignment.CENTER);
    setMembersMargin(5);

    Label label = new Label("<strong><h3>Cadastrar nova Fatura</h3></strong>");
    label.setAlign(Alignment.CENTER);

    final DynamicForm formNovaFatura = new DynamicForm();
    formNovaFatura.setAutoFocus(true);
    formNovaFatura.setWidth(490);
    formNovaFatura.setMargin(15);
    formNovaFatura.setLayoutAlign(Alignment.CENTER);

    final TextItem itemMesRef = new TextItem();
    itemMesRef.setTitle("Ms de ref.");
    itemMesRef.setName("mesRef");
    itemMesRef.setMask(">LLL/####");
    itemMesRef.setRequired(true);
    itemMesRef.setHint("<nbr>*</nbr>");
    itemMesRef.setMaskSaveLiterals(true);
    itemMesRef.setCharacterCasing(CharacterCasing.UPPER);
    itemMesRef.setWidth(300);
    itemMesRef.setHint("<nbr>*</nbr>");
    itemMesRef.setValue(recordFatura.getAttribute("mesReferencia"));

    final DateItem dataVencimeto = new DateItem();
    dataVencimeto.setTitle("Data de Venc.");
    dataVencimeto.setName("dataVencimento");
    dataVencimeto.setUseTextField(true);
    dataVencimeto.setHint("<nbr>*</nbr>");
    dataVencimeto.setUseMask(true);
    dataVencimeto.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATE);
    dataVencimeto.setRequired(true);
    dataVencimeto.setWidth(300);
    dataVencimeto.setValue(recordFatura.getAttribute("dataFatura"));

    final TextItem itemValor = new TextItem();
    itemValor.setTitle("Valor");
    itemValor.setName("valor");
    itemValor.setRequired(true);
    itemValor.setHint("<nbr>*</nbr>");
    itemValor.setMaskSaveLiterals(true);
    itemValor.setCharacterCasing(CharacterCasing.UPPER);
    itemValor.setWidth(300);
    itemValor.setHint("<nbr>*</nbr>");
    itemValor.setValue(recordFatura.getAttribute("valor"));
    itemValor.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            String tecla;
            tecla = event.getKeyName();
            //GWT.log("Tecla " + tecla + " KeyCod = " + event.getCharacterValue());
            //GWT.log("Objeto JavaScript "+ Info.FormataMoeda(itemValor.getValueAsString(), ".", ",", tecla));
            String aux = "";
            if (event.getCharacterValue() != null && event.getCharacterValue() >= 48
                    && event.getCharacterValue() <= 57) {
                aux = Info.FormataMoeda(
                        (itemValor.getValueAsString() != null) ? itemValor.getValueAsString() : "0", ".", ",",
                        tecla);
                flagItemValor = true;
            }
            //GWT.log("Aux=" + aux);
            //itemValor.setValue(aux);
            campo = aux;
            //Info.FormataMoeda(itemValor.getJsObj(), ".", ",", tecla);
        }
    });
    itemValor.addChangedHandler(new ChangedHandler() {

        @Override
        public void onChanged(ChangedEvent event) {
            //GWT.log("Entrou no changed: " + event.getValue());
            if (flagItemValor) {
                itemValor.setValue(campo);
            }
            flagItemValor = false;
        }
    });

    formNovaFatura.setItems(itemMesRef, dataVencimeto, itemValor);

    //        formNovaFatura.addDrawHandler(new DrawHandler() {
    //            
    //            @Override
    //            public void onDraw(DrawEvent event) {
    //                formNovaFatura.focusInItem(itemValor);
    //            }
    //        });

    HLayout hButoes = new HLayout();
    hButoes.setWidth(100);
    hButoes.setMembersMargin(3);
    hButoes.setLayoutAlign(Alignment.CENTER);
    IButton salvar = new IButton("Salvar");
    hButoes.setMargin(5);
    hButoes.addMember(salvar);

    salvar.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (formNovaFatura.validate()) {
                contador = 0;
                final Window janelaCarregando = new Window();
                janelaCarregando.setShowTitle(false);
                janelaCarregando.setWidth(100);
                janelaCarregando.setHeight(50);
                janelaCarregando.setShowEdges(false);
                janelaCarregando.setShowCloseButton(false);
                janelaCarregando.setShowMinimizeButton(false);
                janelaCarregando.setIsModal(true);
                janelaCarregando.setShowModalMask(true);
                janelaCarregando.centerInPage();
                janelaCarregando.setLayoutAlign(Alignment.CENTER);
                final Label mensagem = new Label("Carregando..");
                mensagem.setHeight(16);

                new Timer() {
                    public void run() {

                        if (contador != 100) {
                            contador += 1 + (int) (5 * Math.random());
                            schedule(1 + (int) (50 * Math.random()));
                            mensagem.setContents("Carregando: " + contador + "%");
                            janelaCarregando.addItem(mensagem);
                            janelaCarregando.setAnimateTime(1200);
                            janelaCarregando.animateShow(AnimationEffect.FADE);

                            if (contador >= 100) {
                                mensagem.setContents("Carregando: 100%");
                                listFaturas.setData(new RecordList());
                                TreeMap<String, String> novaFatura = new TreeMap<String, String>();
                                novaFatura.put("codFatura", recordFatura.getAttributeAsString("codigo"));
                                novaFatura.put("codCliente", String.valueOf(codCliente));
                                novaFatura.put("mes", itemMesRef.getValueAsString());
                                novaFatura.put("valor", itemValor.getValueAsString().replaceAll("\\.", "")
                                        .replaceAll(",", "\\."));
                                Date dataVencimento = dataVencimeto.getValueAsDate();
                                Info.dbService.alterarFatura(novaFatura, dataVencimento,
                                        new AsyncCallback<Boolean>() {

                                            @Override
                                            public void onFailure(Throwable caught) {
                                                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                            }

                                            @Override
                                            public void onSuccess(Boolean result) {
                                                if (result == true) {
                                                    SC.say("Fatura atualizada com sucesso");
                                                    //////////////////*******************************************************///////////////////////////////////////////////////
                                                    Info.dbService.buscarTodasTaxas(
                                                            new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                                                                @Override
                                                                public void onFailure(Throwable caught) {
                                                                    throw new UnsupportedOperationException(
                                                                            "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                                }

                                                                @Override
                                                                public void onSuccess(
                                                                        ArrayList<TreeMap<String, String>> taxas) {
                                                                    if (taxas != null) {
                                                                        for (TreeMap<String, String> txs : taxas) {
                                                                            if (Integer.parseInt(
                                                                                    txs.get("codTaxa")) == 1) {
                                                                                multa = Double.parseDouble(
                                                                                        txs.get("valor"));
                                                                            } else if (Integer.parseInt(
                                                                                    txs.get("codTaxa")) == 2) {
                                                                                juros = Double.parseDouble(
                                                                                        txs.get("valor"));
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            });
                                                    Info.dbService.buscarFaturaPorCliente(codCliente,
                                                            new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                                                                @Override
                                                                public void onFailure(Throwable caught) {
                                                                    throw new UnsupportedOperationException(
                                                                            "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                                }

                                                                @Override
                                                                public void onSuccess(
                                                                        ArrayList<TreeMap<String, String>> faturasCliente) {
                                                                    Date dataAtual = new Date(
                                                                            System.currentTimeMillis());
                                                                    long diaAtual = dataAtual.getTime();
                                                                    long diferencaDeDatas = 0;
                                                                    long diaVencimento = 0;
                                                                    TreeMap<String, String> faturaAuxiliar = new TreeMap<String, String>();
                                                                    if (faturasCliente != null) {
                                                                        for (TreeMap<String, String> fats : faturasCliente) {
                                                                            if (faturasCliente.get(0)
                                                                                    .get("codFatura") != null
                                                                                    && faturaAuxiliar.get(fats
                                                                                            .get("codFatura")) == null) {
                                                                                Date dataDeVencimento = new Date(
                                                                                        Long.parseLong(fats.get(
                                                                                                "dataVencimento")));
                                                                                diaVencimento = dataDeVencimento
                                                                                        .getTime();
                                                                                diferencaDeDatas = diaAtual
                                                                                        - diaVencimento;
                                                                                TreeMap<String, String> faturaBD = new TreeMap<String, String>();
                                                                                faturaBD.put("codFatura",
                                                                                        fats.get("codFatura"));
                                                                                faturaBD.put("codCliente",
                                                                                        fats.get("codCliente"));
                                                                                faturaBD.put("dataVencimento",
                                                                                        fats.get(
                                                                                                "dataVencimento"));
                                                                                faturaBD.put("valor",
                                                                                        String.valueOf(Info
                                                                                                .formataSaldo(
                                                                                                        Double.parseDouble(
                                                                                                                fats.get(
                                                                                                                        "valor")))));
                                                                                faturaBD.put("estado",
                                                                                        fats.get("estado"));
                                                                                faturaBD.put("valorPago", (fats
                                                                                        .get("totalLancamentos") == null)
                                                                                                ? String.valueOf(
                                                                                                        Info.formataSaldo(
                                                                                                                0))
                                                                                                : String.valueOf(
                                                                                                        Info.formataSaldo(
                                                                                                                Double.parseDouble(
                                                                                                                        fats.get(
                                                                                                                                "totalLancamentos")))));
                                                                                faturaBD.put("mesReferencia",
                                                                                        fats.get("mes"));
                                                                                faturaBD.put("count", "0");
                                                                                //GWT.log("" + fats.get("valorApagar"));
                                                                                double totalPago = (fats.get(
                                                                                        "totalLancamentos") == null)
                                                                                                ? 0
                                                                                                : (Double
                                                                                                        .parseDouble(
                                                                                                                fats.get(
                                                                                                                        "totalLancamentos")));
                                                                                //GWT.log("Valor a pagar"+(Double.parseDouble(fats.get("valor")) - (totalPago)));
                                                                                if (diferencaDeDatas <= 0) {
                                                                                    double valor = Double
                                                                                            .parseDouble(fats
                                                                                                    .get("valor"));
                                                                                    double valorAtualFatura = (totalPago == 0)
                                                                                            ? Info.formataDecimal(
                                                                                                    valor)
                                                                                            : Info.formataDecimal(
                                                                                                    Double.parseDouble(
                                                                                                            fats.get(
                                                                                                                    "valor"))
                                                                                                            - (totalPago));
                                                                                    faturaBD.put("jurosEmulta",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Double.parseDouble(
                                                                                                                    "0"))));
                                                                                    faturaBD.put("valorApagar",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Info.formataDecimal(
                                                                                                                    (valorAtualFatura)))));
                                                                                    faturaBD.put("valorTotal",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Info.formataDecimal(
                                                                                                                    Double.parseDouble(
                                                                                                                            fats.get(
                                                                                                                                    "valor"))))));
                                                                                    diferencaDeDatas = 0;
                                                                                } else if (diferencaDeDatas > 0
                                                                                        && diferencaDeDatas < 86400000) {
                                                                                    double valor = Double
                                                                                            .parseDouble(fats
                                                                                                    .get("valor"));
                                                                                    double valorAtualFatura = (totalPago == 0)
                                                                                            ? Info.formataDecimal(
                                                                                                    valor)
                                                                                                    + (valor * multa)
                                                                                            : Info.formataDecimal(
                                                                                                    Double.parseDouble(
                                                                                                            fats.get(
                                                                                                                    "valor"))
                                                                                                            - (totalPago)
                                                                                                            + (valor * multa));
                                                                                    faturaBD.put("jurosEmulta",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            (Info.formataDecimal(
                                                                                                                    valor * multa)))));
                                                                                    faturaBD.put("valorApagar",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            valorAtualFatura)));
                                                                                    faturaBD.put("valorTotal",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Info.formataDecimal(
                                                                                                                    Double.parseDouble(
                                                                                                                            fats.get(
                                                                                                                                    "valor"))
                                                                                                                            + ((Double
                                                                                                                                    .parseDouble(
                                                                                                                                            fats.get(
                                                                                                                                                    "valor"))
                                                                                                                                    * multa))))));
                                                                                    diferencaDeDatas = 0;
                                                                                } else if (diferencaDeDatas > 86400000) {
                                                                                    double valor = Double
                                                                                            .parseDouble(fats
                                                                                                    .get("valor"));
                                                                                    double valorAtualFatura = (totalPago == 0)
                                                                                            ? Info.formataDecimal(
                                                                                                    valor)
                                                                                                    + (valor * multa)
                                                                                                    + ((diferencaDeDatas
                                                                                                            / 86400000)
                                                                                                            * (juros * valor))
                                                                                            : Info.formataDecimal(
                                                                                                    Double.parseDouble(
                                                                                                            fats.get(
                                                                                                                    "valor"))
                                                                                                            - (totalPago)
                                                                                                            + (valor * multa)
                                                                                                            + ((diferencaDeDatas
                                                                                                                    / 86400000)
                                                                                                                    * (juros * valor)));
                                                                                    faturaBD.put("jurosEmulta",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Info.formataDecimal(
                                                                                                                    (valor * multa)
                                                                                                                            + ((diferencaDeDatas
                                                                                                                                    / 86400000)
                                                                                                                                    * (juros * valor))))));
                                                                                    faturaBD.put("valorApagar",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            valorAtualFatura)));
                                                                                    faturaBD.put("valorTotal",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Info.formataDecimal(
                                                                                                                    Double.parseDouble(
                                                                                                                            fats.get(
                                                                                                                                    "valor"))
                                                                                                                            + ((Double
                                                                                                                                    .parseDouble(
                                                                                                                                            fats.get(
                                                                                                                                                    "valor"))
                                                                                                                                    * multa))
                                                                                                                            + ((diferencaDeDatas
                                                                                                                                    / 86400000)
                                                                                                                                    * (juros * Double
                                                                                                                                            .parseDouble(
                                                                                                                                                    fats.get(
                                                                                                                                                            "valor"))))))));
                                                                                    diferencaDeDatas = 0;
                                                                                }
                                                                                arrayFaturasBD.add(faturaBD);
                                                                                faturaAuxiliar.put(
                                                                                        fats.get("codFatura"),
                                                                                        fats.get("codFatura"));
                                                                            }
                                                                        }
                                                                        objFaturaLancamento
                                                                                .setTotalLancamentos(0);
                                                                        objFaturaLancamento.setTotalFaturas(0);
                                                                        objFaturaLancamento.setSaldo(0);
                                                                        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++////////////
                                                                        for (TreeMap<String, String> fatsGrid : arrayFaturasBD) {
                                                                            Record fat = new Record();
                                                                            fat.setAttribute("codigo",
                                                                                    fatsGrid.get("codFatura"));
                                                                            fat.setAttribute("codCliente",
                                                                                    fatsGrid.get("codCliente"));
                                                                            fat.setAttribute("dataFatura",
                                                                                    DateTimeFormat
                                                                                            .getShortDateFormat()
                                                                                            .format(new Date(
                                                                                                    Long.parseLong(
                                                                                                            fatsGrid.get(
                                                                                                                    "dataVencimento")))));
                                                                            fat.setAttribute("valor",
                                                                                    fatsGrid.get("valor"));
                                                                            fat.setAttribute("estado", (Boolean
                                                                                    .parseBoolean(fatsGrid.get(
                                                                                            "estado")) == false)
                                                                                                    ? "<nbr class=\negativo\"> Em aberto</nbr>"
                                                                                                    : "<nbr class=\"positivo\">Quitada</nbr>");
                                                                            fat.setAttribute("valorPago",
                                                                                    fatsGrid.get("valorPago"));
                                                                            fat.setAttribute("mesReferencia",
                                                                                    fatsGrid.get(
                                                                                            "mesReferencia"));
                                                                            fat.setAttribute("valorApagar",
                                                                                    (Boolean.parseBoolean(
                                                                                            fatsGrid.get(
                                                                                                    "estado")) == false)
                                                                                                            ? fatsGrid
                                                                                                                    .get("valorApagar")
                                                                                                            : Info.formataSaldo(
                                                                                                                    0));
                                                                            fat.setAttribute("valorTotal",
                                                                                    fatsGrid.get("valorTotal"));
                                                                            fat.setAttribute("jurosEmulta",
                                                                                    (Boolean.parseBoolean(
                                                                                            fatsGrid.get(
                                                                                                    "estado")) == false)
                                                                                                            ? fatsGrid
                                                                                                                    .get("jurosEmulta")
                                                                                                            : Info.formataSaldo(
                                                                                                                    0));
                                                                            fat.setAttribute("count",
                                                                                    Integer.parseInt(fatsGrid
                                                                                            .get("count")));
                                                                            listFaturas.addData(fat);
                                                                            objFaturaLancamento.setTotalFaturas(
                                                                                    objFaturaLancamento
                                                                                            .getTotalFaturas()
                                                                                            + ((Double
                                                                                                    .parseDouble(
                                                                                                            fat.getAttributeAsString(
                                                                                                                    "valorPago")
                                                                                                                    .replaceAll(
                                                                                                                            "\\.",
                                                                                                                            "")
                                                                                                                    .replaceAll(
                                                                                                                            ",",
                                                                                                                            ".")) > 0
                                                                                                    && Boolean
                                                                                                            .parseBoolean(
                                                                                                                    fatsGrid.get(
                                                                                                                            "estado")) == true)
                                                                                                                                    ? Double.parseDouble(
                                                                                                                                            fat.getAttributeAsString(
                                                                                                                                                    "valorPago")
                                                                                                                                                    .replaceAll(
                                                                                                                                                            "\\.",
                                                                                                                                                            "")
                                                                                                                                                    .replaceAll(
                                                                                                                                                            ",",
                                                                                                                                                            "."))
                                                                                                                                    : (Double
                                                                                                                                            .parseDouble(
                                                                                                                                                    fat.getAttributeAsString(
                                                                                                                                                            "valorPago")
                                                                                                                                                            .replaceAll(
                                                                                                                                                                    "\\.",
                                                                                                                                                                    "")
                                                                                                                                                            .replaceAll(
                                                                                                                                                                    ",",
                                                                                                                                                                    "."))
                                                                                                                                            + Double.parseDouble(
                                                                                                                                                    fat.getAttributeAsString(
                                                                                                                                                            "valorApagar")
                                                                                                                                                            .replaceAll(
                                                                                                                                                                    "\\.",
                                                                                                                                                                    "")
                                                                                                                                                            .replaceAll(
                                                                                                                                                                    ",",
                                                                                                                                                                    ".")))));
                                                                        }
                                                                        Info.dbService.buscarTotalLancamentos(
                                                                                codCliente,
                                                                                new AsyncCallback<Double>() {

                                                                                    @Override
                                                                                    public void onFailure(
                                                                                            Throwable caught) {
                                                                                        throw new UnsupportedOperationException(
                                                                                                "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                                                    }

                                                                                    @Override
                                                                                    public void onSuccess(
                                                                                            Double totLanc) {
                                                                                        labelLanc.redraw();
                                                                                        labelLanc.setContents(
                                                                                                "<strong style=\"font-size:20px; \">Total de Lanamentos: R$"
                                                                                                        + Info.formataSaldo(
                                                                                                                Info.formataDecimal(
                                                                                                                        totLanc))
                                                                                                        + "</strong>");
                                                                                        objFaturaLancamento
                                                                                                .setTotalLancamentos(
                                                                                                        totLanc);
                                                                                        labelfaturas.redraw();
                                                                                        labelfaturas
                                                                                                .setContents(
                                                                                                        "<strong style=\"font-size:20px; \">Total de Faturas: R$"
                                                                                                                + Info.formataSaldo(
                                                                                                                        Info.formataDecimal(
                                                                                                                                objFaturaLancamento
                                                                                                                                        .getTotalFaturas()))
                                                                                                                + "</strong>");
                                                                                        objFaturaLancamento
                                                                                                .setSaldo(
                                                                                                        objFaturaLancamento
                                                                                                                .getTotalLancamentos()
                                                                                                                - objFaturaLancamento
                                                                                                                        .getTotalFaturas());
                                                                                        if (objFaturaLancamento
                                                                                                .getSaldo() == 0) {
                                                                                            labelSaldo.redraw();
                                                                                            labelSaldo
                                                                                                    .setContents(
                                                                                                            "<strong style=\"font-size:25px; \">Saldo Atual: R$00,00\n</strong>");
                                                                                        } else if (objFaturaLancamento
                                                                                                .getSaldo() > 0) {
                                                                                            labelSaldo.redraw();
                                                                                            labelSaldo
                                                                                                    .setContents(
                                                                                                            "<strong class=\"saldo-positivo\">Crdito Atual: R$"
                                                                                                                    + Info.formataSaldo(
                                                                                                                            Info.formataDecimal(
                                                                                                                                    objFaturaLancamento
                                                                                                                                            .getSaldo()))
                                                                                                                    + "\n</strong>");
                                                                                        } else {
                                                                                            labelSaldo.redraw();
                                                                                            labelSaldo
                                                                                                    .setContents(
                                                                                                            "<strong class=\"saldo-negativo\">Dbito Atual: R$"
                                                                                                                    + Info.formataSaldo(
                                                                                                                            Info.formataDecimal(
                                                                                                                                    objFaturaLancamento
                                                                                                                                            .getSaldo()))
                                                                                                                    + "\n</strong>");
                                                                                        }
                                                                                    }
                                                                                });
                                                                    }
                                                                }
                                                            });
                                                    //////////////////*******************************************************///////////////////////////////////////////////////
                                                } else {
                                                    SC.warn("ERRO ao atualizar fatura");
                                                }
                                            }
                                        });
                                janelaCarregando.addItem(mensagem);
                                janelaCarregando.setAnimateTime(1200);
                                janelaCarregando.animateHide(AnimationEffect.FADE);
                                contador = 100;
                                janelaCarregando.destroy();
                                novaFaturaAux.destroy();
                            }
                        } else {
                            contador = 0;
                        }

                    }
                }.schedule(50);

            }
        }
    });
    addItem(label);
    addItem(formNovaFatura);
    addItem(hButoes);

}

From source file:com.automaster.client.ui.paineis.tabs.financeiro.dialogs.NovaFatura.java

public NovaFatura(final int codCliente, final ListGrid listLancamentos, final ListGrid listFaturas,
        final Label labelLanc, final Label labelfaturas, final Label labelSaldo,
        final TabConsultaFaturaLancamento objFaturaLancamento) {

    final NovaFatura novaFaturaAux = this;

    setTitle("Nova fatura");
    setWidth(500);/*w w  w .ja v a 2s.  c  o  m*/
    setHeight(300);
    setShowMinimizeButton(false);
    setIsModal(true);
    setShowModalMask(true);
    centerInPage();
    setLayoutAlign(Alignment.CENTER);
    setMembersMargin(5);

    Label label = new Label("<strong><h3>Cadastrar nova Fatura</h3></strong>");
    label.setAlign(Alignment.CENTER);

    final DynamicForm formNovaFatura = new DynamicForm();
    formNovaFatura.setAutoFocus(true);
    formNovaFatura.setWidth(490);
    formNovaFatura.setMargin(15);
    formNovaFatura.setLayoutAlign(Alignment.CENTER);

    final TextItem itemMesRef = new TextItem();
    itemMesRef.setTitle("Ms de ref.");
    itemMesRef.setName("mesRef");
    itemMesRef.setMask(">LLL/####");
    itemMesRef.setRequired(true);
    itemMesRef.setHint("<nbr>*</nbr>");
    itemMesRef.setMaskSaveLiterals(true);
    itemMesRef.setCharacterCasing(CharacterCasing.UPPER);
    itemMesRef.setWidth(300);
    itemMesRef.setHint("<nbr>*</nbr>");

    final DateItem dataVencimeto = new DateItem();
    dataVencimeto.setTitle("Data de Venc.");
    dataVencimeto.setName("dataVencimento");
    dataVencimeto.setUseTextField(true);
    dataVencimeto.setHint("<nbr>*</nbr>");
    dataVencimeto.setUseMask(true);
    dataVencimeto.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATE);
    dataVencimeto.setRequired(true);
    dataVencimeto.setWidth(300);
    dataVencimeto.setValue(new Date(System.currentTimeMillis()));

    final TextItem itemValor = new TextItem();
    itemValor.setTitle("Valor");
    itemValor.setName("valor");
    itemValor.setRequired(true);
    itemValor.setHint("<nbr>*</nbr>");
    itemValor.setMaskSaveLiterals(true);
    itemValor.setCharacterCasing(CharacterCasing.UPPER);
    itemValor.setWidth(300);
    itemValor.setHint("<nbr>*</nbr>");
    itemValor.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            String tecla;
            tecla = event.getKeyName();
            //GWT.log("Tecla " + tecla + " KeyCod = " + event.getCharacterValue());
            //GWT.log("Objeto JavaScript "+ Info.FormataMoeda(itemValor.getValueAsString(), ".", ",", tecla));
            String aux = "";
            if (event.getCharacterValue() != null && event.getCharacterValue() >= 48
                    && event.getCharacterValue() <= 57) {
                aux = Info.FormataMoeda(
                        (itemValor.getValueAsString() != null) ? itemValor.getValueAsString() : "0", ".", ",",
                        tecla);
                flagItemValor = true;
            }
            //GWT.log("Aux=" + aux);
            //itemValor.setValue(aux);
            campo = aux;
            //Info.FormataMoeda(itemValor.getJsObj(), ".", ",", tecla);
        }
    });
    itemValor.addChangedHandler(new ChangedHandler() {

        @Override
        public void onChanged(ChangedEvent event) {
            //GWT.log("Entrou no changed: " + event.getValue());
            if (flagItemValor) {
                itemValor.setValue(campo);
            }
            flagItemValor = false;
        }
    });

    formNovaFatura.setItems(itemMesRef, dataVencimeto, itemValor);

    //        formNovaFatura.addDrawHandler(new DrawHandler() {
    //            
    //            @Override
    //            public void onDraw(DrawEvent event) {
    //                formNovaFatura.focusInItem(itemValor);
    //            }
    //        });

    HLayout hButoes = new HLayout();
    hButoes.setWidth(100);
    hButoes.setMembersMargin(3);
    hButoes.setLayoutAlign(Alignment.CENTER);
    IButton cadastrar = new IButton("Cadastrar");
    IButton limpar = new IButton("Limpar");
    hButoes.setMargin(5);
    hButoes.addMember(cadastrar);
    hButoes.addMember(limpar);

    cadastrar.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (formNovaFatura.validate()) {
                contador = 0;
                final Window janelaCarregando = new Window();
                janelaCarregando.setShowTitle(false);
                janelaCarregando.setWidth(100);
                janelaCarregando.setHeight(50);
                janelaCarregando.setShowEdges(false);
                janelaCarregando.setShowCloseButton(false);
                janelaCarregando.setShowMinimizeButton(false);
                janelaCarregando.setIsModal(true);
                janelaCarregando.setShowModalMask(true);
                janelaCarregando.centerInPage();
                janelaCarregando.setLayoutAlign(Alignment.CENTER);
                final Label mensagem = new Label("Carregando..");
                mensagem.setHeight(16);

                new Timer() {
                    public void run() {

                        if (contador != 100) {

                            contador += 1 + (int) (5 * Math.random());
                            schedule(1 + (int) (50 * Math.random()));
                            mensagem.setContents("Carregando: " + contador + "%");

                            janelaCarregando.addItem(mensagem);
                            janelaCarregando.setAnimateTime(1200);
                            janelaCarregando.animateShow(AnimationEffect.FADE);

                            if (contador >= 100) {
                                mensagem.setContents("Carregando: 100%");
                                listFaturas.setData(new RecordList());
                                TreeMap<String, String> novaFatura = new TreeMap<String, String>();
                                novaFatura.put("codCliente", String.valueOf(codCliente));
                                novaFatura.put("mes", itemMesRef.getValueAsString());
                                novaFatura.put("valor", itemValor.getValueAsString().replaceAll("\\.", "")
                                        .replaceAll(",", "\\."));
                                Date dataVencimento = dataVencimeto.getValueAsDate();
                                Info.dbService.cadastrarFatura(novaFatura, dataVencimento,
                                        new AsyncCallback<Boolean>() {

                                            @Override
                                            public void onFailure(Throwable caught) {
                                                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                            }

                                            @Override
                                            public void onSuccess(Boolean result) {
                                                if (result == true) {
                                                    SC.say("Nova fatura cadastrada com sucesso");
                                                    //////////////////*******************************************************///////////////////////////////////////////////////
                                                    Info.dbService.buscarTodasTaxas(
                                                            new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                                                                @Override
                                                                public void onFailure(Throwable caught) {
                                                                    throw new UnsupportedOperationException(
                                                                            "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                                }

                                                                @Override
                                                                public void onSuccess(
                                                                        ArrayList<TreeMap<String, String>> taxas) {
                                                                    if (taxas != null) {
                                                                        for (TreeMap<String, String> txs : taxas) {
                                                                            if (Integer.parseInt(
                                                                                    txs.get("codTaxa")) == 1) {
                                                                                multa = Double.parseDouble(
                                                                                        txs.get("valor"));
                                                                            } else if (Integer.parseInt(
                                                                                    txs.get("codTaxa")) == 2) {
                                                                                juros = Double.parseDouble(
                                                                                        txs.get("valor"));
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            });
                                                    Info.dbService.buscarFaturaPorCliente(codCliente,
                                                            new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                                                                @Override
                                                                public void onFailure(Throwable caught) {
                                                                    throw new UnsupportedOperationException(
                                                                            "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                                }

                                                                @Override
                                                                public void onSuccess(
                                                                        ArrayList<TreeMap<String, String>> faturasCliente) {
                                                                    Date dataAtual = new Date(
                                                                            System.currentTimeMillis());
                                                                    long diaAtual = dataAtual.getTime();
                                                                    long diferencaDeDatas = 0;
                                                                    long diaVencimento = 0;
                                                                    TreeMap<String, String> faturaAuxiliar = new TreeMap<String, String>();
                                                                    if (faturasCliente != null) {
                                                                        for (TreeMap<String, String> fats : faturasCliente) {
                                                                            if (faturasCliente.get(0)
                                                                                    .get("codFatura") != null
                                                                                    && faturaAuxiliar.get(fats
                                                                                            .get("codFatura")) == null) {
                                                                                Date dataDeVencimento = new Date(
                                                                                        Long.parseLong(fats.get(
                                                                                                "dataVencimento")));
                                                                                diaVencimento = dataDeVencimento
                                                                                        .getTime();
                                                                                diferencaDeDatas = diaAtual
                                                                                        - diaVencimento;
                                                                                TreeMap<String, String> faturaBD = new TreeMap<String, String>();
                                                                                faturaBD.put("codFatura",
                                                                                        fats.get("codFatura"));
                                                                                faturaBD.put("codCliente",
                                                                                        fats.get("codCliente"));
                                                                                faturaBD.put("dataVencimento",
                                                                                        fats.get(
                                                                                                "dataVencimento"));
                                                                                faturaBD.put("valor",
                                                                                        String.valueOf(Info
                                                                                                .formataSaldo(
                                                                                                        Double.parseDouble(
                                                                                                                fats.get(
                                                                                                                        "valor")))));
                                                                                faturaBD.put("estado",
                                                                                        fats.get("estado"));
                                                                                faturaBD.put("valorPago", (fats
                                                                                        .get("totalLancamentos") == null)
                                                                                                ? String.valueOf(
                                                                                                        Info.formataSaldo(
                                                                                                                0))
                                                                                                : String.valueOf(
                                                                                                        Info.formataSaldo(
                                                                                                                Double.parseDouble(
                                                                                                                        fats.get(
                                                                                                                                "totalLancamentos")))));
                                                                                faturaBD.put("mesReferencia",
                                                                                        fats.get("mes"));
                                                                                faturaBD.put("count", "0");
                                                                                //GWT.log("" + fats.get("valorApagar"));
                                                                                double totalPago = (fats.get(
                                                                                        "totalLancamentos") == null)
                                                                                                ? 0
                                                                                                : (Double
                                                                                                        .parseDouble(
                                                                                                                fats.get(
                                                                                                                        "totalLancamentos")));
                                                                                //GWT.log("Valor a pagar"+(Double.parseDouble(fats.get("valor")) - (totalPago)));
                                                                                if (diferencaDeDatas <= 0) {
                                                                                    double valor = Double
                                                                                            .parseDouble(fats
                                                                                                    .get("valor"));
                                                                                    double valorAtualFatura = (totalPago == 0)
                                                                                            ? Info.formataDecimal(
                                                                                                    valor)
                                                                                            : Info.formataDecimal(
                                                                                                    Double.parseDouble(
                                                                                                            fats.get(
                                                                                                                    "valor"))
                                                                                                            - (totalPago));
                                                                                    faturaBD.put("jurosEmulta",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Double.parseDouble(
                                                                                                                    "0"))));
                                                                                    faturaBD.put("valorApagar",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Info.formataDecimal(
                                                                                                                    (valorAtualFatura)))));
                                                                                    faturaBD.put("valorTotal",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Info.formataDecimal(
                                                                                                                    Double.parseDouble(
                                                                                                                            fats.get(
                                                                                                                                    "valor"))))));
                                                                                    diferencaDeDatas = 0;
                                                                                } else if (diferencaDeDatas > 0
                                                                                        && diferencaDeDatas < 86400000) {
                                                                                    double valor = Double
                                                                                            .parseDouble(fats
                                                                                                    .get("valor"));
                                                                                    double valorAtualFatura = (totalPago == 0)
                                                                                            ? Info.formataDecimal(
                                                                                                    valor)
                                                                                                    + (valor * multa)
                                                                                            : Info.formataDecimal(
                                                                                                    Double.parseDouble(
                                                                                                            fats.get(
                                                                                                                    "valor"))
                                                                                                            - (totalPago)
                                                                                                            + (valor * multa));
                                                                                    faturaBD.put("jurosEmulta",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            (Info.formataDecimal(
                                                                                                                    valor * multa)))));
                                                                                    faturaBD.put("valorApagar",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            valorAtualFatura)));
                                                                                    faturaBD.put("valorTotal",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Info.formataDecimal(
                                                                                                                    Double.parseDouble(
                                                                                                                            fats.get(
                                                                                                                                    "valor"))
                                                                                                                            + ((Double
                                                                                                                                    .parseDouble(
                                                                                                                                            fats.get(
                                                                                                                                                    "valor"))
                                                                                                                                    * multa))))));
                                                                                    diferencaDeDatas = 0;
                                                                                } else if (diferencaDeDatas > 86400000) {
                                                                                    double valor = Double
                                                                                            .parseDouble(fats
                                                                                                    .get("valor"));
                                                                                    double valorAtualFatura = (totalPago == 0)
                                                                                            ? Info.formataDecimal(
                                                                                                    valor)
                                                                                                    + (valor * multa)
                                                                                                    + ((diferencaDeDatas
                                                                                                            / 86400000)
                                                                                                            * (juros * valor))
                                                                                            : Info.formataDecimal(
                                                                                                    Double.parseDouble(
                                                                                                            fats.get(
                                                                                                                    "valor"))
                                                                                                            - (totalPago)
                                                                                                            + (valor * multa)
                                                                                                            + ((diferencaDeDatas
                                                                                                                    / 86400000)
                                                                                                                    * (juros * valor)));
                                                                                    faturaBD.put("jurosEmulta",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Info.formataDecimal(
                                                                                                                    (valor * multa)
                                                                                                                            + ((diferencaDeDatas
                                                                                                                                    / 86400000)
                                                                                                                                    * (juros * valor))))));
                                                                                    faturaBD.put("valorApagar",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            valorAtualFatura)));
                                                                                    faturaBD.put("valorTotal",
                                                                                            String.valueOf(Info
                                                                                                    .formataSaldo(
                                                                                                            Info.formataDecimal(
                                                                                                                    Double.parseDouble(
                                                                                                                            fats.get(
                                                                                                                                    "valor"))
                                                                                                                            + ((Double
                                                                                                                                    .parseDouble(
                                                                                                                                            fats.get(
                                                                                                                                                    "valor"))
                                                                                                                                    * multa))
                                                                                                                            + ((diferencaDeDatas
                                                                                                                                    / 86400000)
                                                                                                                                    * (juros * Double
                                                                                                                                            .parseDouble(
                                                                                                                                                    fats.get(
                                                                                                                                                            "valor"))))))));
                                                                                    diferencaDeDatas = 0;
                                                                                }
                                                                                arrayFaturasBD.add(faturaBD);
                                                                                faturaAuxiliar.put(
                                                                                        fats.get("codFatura"),
                                                                                        fats.get("codFatura"));
                                                                            }
                                                                        }
                                                                        objFaturaLancamento
                                                                                .setTotalLancamentos(0);
                                                                        objFaturaLancamento.setTotalFaturas(0);
                                                                        objFaturaLancamento.setSaldo(0);
                                                                        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++////////////
                                                                        for (TreeMap<String, String> fatsGrid : arrayFaturasBD) {
                                                                            Record fat = new Record();
                                                                            fat.setAttribute("codigo",
                                                                                    fatsGrid.get("codFatura"));
                                                                            fat.setAttribute("codCliente",
                                                                                    fatsGrid.get("codCliente"));
                                                                            fat.setAttribute("dataFatura",
                                                                                    DateTimeFormat
                                                                                            .getShortDateFormat()
                                                                                            .format(new Date(
                                                                                                    Long.parseLong(
                                                                                                            fatsGrid.get(
                                                                                                                    "dataVencimento")))));
                                                                            fat.setAttribute("valor",
                                                                                    fatsGrid.get("valor"));
                                                                            fat.setAttribute("estado", (Boolean
                                                                                    .parseBoolean(fatsGrid.get(
                                                                                            "estado")) == false)
                                                                                                    ? "<nbr class=\negativo\"> Em aberto</nbr>"
                                                                                                    : "<nbr class=\"positivo\">Quitada</nbr>");
                                                                            fat.setAttribute("valorPago",
                                                                                    fatsGrid.get("valorPago"));
                                                                            fat.setAttribute("mesReferencia",
                                                                                    fatsGrid.get(
                                                                                            "mesReferencia"));
                                                                            fat.setAttribute("valorApagar",
                                                                                    (Boolean.parseBoolean(
                                                                                            fatsGrid.get(
                                                                                                    "estado")) == false)
                                                                                                            ? fatsGrid
                                                                                                                    .get("valorApagar")
                                                                                                            : Info.formataSaldo(
                                                                                                                    0));
                                                                            fat.setAttribute("valorTotal",
                                                                                    fatsGrid.get("valorTotal"));
                                                                            fat.setAttribute("jurosEmulta",
                                                                                    (Boolean.parseBoolean(
                                                                                            fatsGrid.get(
                                                                                                    "estado")) == false)
                                                                                                            ? fatsGrid
                                                                                                                    .get("jurosEmulta")
                                                                                                            : Info.formataSaldo(
                                                                                                                    0));
                                                                            fat.setAttribute("count",
                                                                                    Integer.parseInt(fatsGrid
                                                                                            .get("count")));
                                                                            listFaturas.addData(fat);
                                                                            objFaturaLancamento.setTotalFaturas(
                                                                                    objFaturaLancamento
                                                                                            .getTotalFaturas()
                                                                                            + ((Double
                                                                                                    .parseDouble(
                                                                                                            fat.getAttributeAsString(
                                                                                                                    "valorPago")
                                                                                                                    .replaceAll(
                                                                                                                            "\\.",
                                                                                                                            "")
                                                                                                                    .replaceAll(
                                                                                                                            ",",
                                                                                                                            ".")) > 0
                                                                                                    && Boolean
                                                                                                            .parseBoolean(
                                                                                                                    fatsGrid.get(
                                                                                                                            "estado")) == true)
                                                                                                                                    ? Double.parseDouble(
                                                                                                                                            fat.getAttributeAsString(
                                                                                                                                                    "valorPago")
                                                                                                                                                    .replaceAll(
                                                                                                                                                            "\\.",
                                                                                                                                                            "")
                                                                                                                                                    .replaceAll(
                                                                                                                                                            ",",
                                                                                                                                                            "."))
                                                                                                                                    : (Double
                                                                                                                                            .parseDouble(
                                                                                                                                                    fat.getAttributeAsString(
                                                                                                                                                            "valorPago")
                                                                                                                                                            .replaceAll(
                                                                                                                                                                    "\\.",
                                                                                                                                                                    "")
                                                                                                                                                            .replaceAll(
                                                                                                                                                                    ",",
                                                                                                                                                                    "."))
                                                                                                                                            + Double.parseDouble(
                                                                                                                                                    fat.getAttributeAsString(
                                                                                                                                                            "valorApagar")
                                                                                                                                                            .replaceAll(
                                                                                                                                                                    "\\.",
                                                                                                                                                                    "")
                                                                                                                                                            .replaceAll(
                                                                                                                                                                    ",",
                                                                                                                                                                    ".")))));
                                                                        }
                                                                        Info.dbService.buscarTotalLancamentos(
                                                                                codCliente,
                                                                                new AsyncCallback<Double>() {

                                                                                    @Override
                                                                                    public void onFailure(
                                                                                            Throwable caught) {
                                                                                        throw new UnsupportedOperationException(
                                                                                                "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                                                    }

                                                                                    @Override
                                                                                    public void onSuccess(
                                                                                            Double totLanc) {
                                                                                        labelLanc.redraw();
                                                                                        labelLanc.setContents(
                                                                                                "<strong style=\"font-size:20px; \">Total de Lanamentos: R$"
                                                                                                        + Info.formataSaldo(
                                                                                                                totLanc)
                                                                                                        + "</strong>");
                                                                                        objFaturaLancamento
                                                                                                .setTotalLancamentos(
                                                                                                        totLanc);
                                                                                        labelfaturas.redraw();
                                                                                        labelfaturas
                                                                                                .setContents(
                                                                                                        "<strong style=\"font-size:20px; \">Total de Faturas: R$"
                                                                                                                + Info.formataSaldo(
                                                                                                                        objFaturaLancamento
                                                                                                                                .getTotalFaturas())
                                                                                                                + "</strong>");
                                                                                        objFaturaLancamento
                                                                                                .setSaldo(
                                                                                                        objFaturaLancamento
                                                                                                                .getTotalLancamentos()
                                                                                                                - objFaturaLancamento
                                                                                                                        .getTotalFaturas());
                                                                                        if (objFaturaLancamento
                                                                                                .getSaldo() == 0) {
                                                                                            labelSaldo.redraw();
                                                                                            labelSaldo
                                                                                                    .setContents(
                                                                                                            "<strong style=\"font-size:25px; \">Saldo Atual: R$00,00\n</strong>");
                                                                                        } else if (objFaturaLancamento
                                                                                                .getSaldo() > 0) {
                                                                                            labelSaldo.redraw();
                                                                                            labelSaldo
                                                                                                    .setContents(
                                                                                                            "<strong class=\"saldo-positivo\">Crdito Atual: R$"
                                                                                                                    + Info.formataSaldo(
                                                                                                                            Info.formataDecimal(
                                                                                                                                    objFaturaLancamento
                                                                                                                                            .getSaldo()))
                                                                                                                    + "\n</strong>");
                                                                                        } else {
                                                                                            labelSaldo.redraw();
                                                                                            labelSaldo
                                                                                                    .setContents(
                                                                                                            "<strong class=\"saldo-negativo\">Dbito Atual: R$"
                                                                                                                    + Info.formataSaldo(
                                                                                                                            Info.formataDecimal(
                                                                                                                                    objFaturaLancamento
                                                                                                                                            .getSaldo()))
                                                                                                                    + "\n</strong>");
                                                                                        }
                                                                                    }
                                                                                });
                                                                    }
                                                                }
                                                            });
                                                    //////////////////*******************************************************///////////////////////////////////////////////////
                                                } else {
                                                    SC.warn("ERRO ao cadastradas nova fatura");
                                                }
                                            }
                                        });
                                janelaCarregando.addItem(mensagem);
                                janelaCarregando.setAnimateTime(1200);
                                janelaCarregando.animateHide(AnimationEffect.FADE);
                                contador = 100;
                                janelaCarregando.destroy();
                                novaFaturaAux.destroy();
                            }
                        } else {
                            contador = 0;
                        }

                    }
                }.schedule(50);

            }
        }
    });
    limpar.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            itemMesRef.clearValue();
            itemValor.clearValue();
            dataVencimeto.setValue(new Date(System.currentTimeMillis()));
            formNovaFatura.focusInItem(itemMesRef);
        }
    });
    addItem(label);
    addItem(formNovaFatura);
    addItem(hButoes);

}

From source file:com.automaster.client.ui.paineis.tabs.financeiro.dialogs.NovoLancamento.java

public NovoLancamento(final int codCliente, final ListGrid listLancamentos, final ListGrid listFaturas,
        final Label labelLanc, final Label labelfaturas, final Label labelSaldo,
        final TabConsultaFaturaLancamento objFaturaLancamento) {

    final NovoLancamento objLancamento = this;

    setTitle("Novo lanamento");
    setWidth(800);//  w w  w  .  j  av  a2  s  .  c  om
    setHeight(550);
    setShowMinimizeButton(false);
    setIsModal(true);
    setShowModalMask(true);
    centerInPage();
    setLayoutAlign(Alignment.CENTER);
    setMembersMargin(5);

    final DynamicForm formNovoLancamento = new DynamicForm();
    formNovoLancamento.setAutoFocus(true);

    Label label = new Label("<strong><h3>Cadastrar novo Lanamento</h3></strong>");
    label.setAlign(Alignment.CENTER);
    label.setHeight(30);
    Label labelListaFat = new Label("<strong><h3>Faturas a pagar</h3></strong>");
    labelListaFat.setAlign(Alignment.CENTER);
    labelListaFat.setHeight(20);
    final Label saldoFaturasApagar = new Label();
    saldoFaturasApagar.setAlign(Alignment.RIGHT);
    saldoFaturasApagar.setHeight(20);
    saldoFaturasApagar.setWidth(750);
    Label labelListaFatSelecionadas = new Label(
            "<strong><h3>Faturas a ser alteradas pelo lanamento</h3></strong>");
    labelListaFatSelecionadas.setAlign(Alignment.CENTER);
    labelListaFatSelecionadas.setHeight(20);

    final DateTimeItem itemDataEhora = new DateTimeItem("dataEhora", "Data e Hora");
    itemDataEhora.setRequired(true);
    itemDataEhora.setWidth(300);
    itemDataEhora.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATETIME);
    itemDataEhora.setDefaultValue(new Date(System.currentTimeMillis()));
    itemDataEhora.setHint("<nbr>*</nbr>");

    final TextItem itemValor = new TextItem();
    itemValor.setTitle("Valor");
    itemValor.setName("valor");
    itemValor.setLength(16);
    itemValor.setRequired(true);
    itemValor.setHint("<nbr>*</nbr>");
    itemValor.setDefaultValue("");
    itemValor.setKeyPressFilter("[0-9]");
    itemValor.setMaskSaveLiterals(true);
    itemValor.setCharacterCasing(CharacterCasing.UPPER);
    itemValor.setWidth(300);
    itemValor.setHint("<nbr>*</nbr>");

    formNovoLancamento.setItems(itemDataEhora, itemValor);

    HLayout hButoes = new HLayout();
    hButoes.setWidth(200);
    hButoes.setMembersMargin(3);
    hButoes.setLayoutAlign(Alignment.CENTER);
    IButton cadastrar = new IButton("Cadastrar");
    IButton limpar = new IButton("Limpar");
    hButoes.setMargin(5);
    hButoes.addMember(cadastrar);
    hButoes.addMember(limpar);

    addCloseClickHandler(new CloseClickHandler() {

        @Override
        public void onCloseClick(CloseClickEvent event) {
            destroy();
        }
    });

    final ListGrid listaDeFaturas = new ListGrid() {

        @Override
        protected Canvas getExpansionComponent(final ListGridRecord record) {

            //final ListGrid grid = this;    
            final Label label = new Label(
                    "<strong style=\"font-size:10px; \">LANAMENTOS PARA ESTA FATURA</strong>");
            label.setAlign(Alignment.CENTER);
            label.setHeight(20);
            VLayout layout = new VLayout(5);
            layout.setPadding(5);
            //GWT.log("" + record.getAttribute("codigo"));
            final ListGridField codLancamento = new ListGridField("codLancamento", "Cdigo lanamento");
            codLancamento.setAlign(Alignment.CENTER);
            codLancamento.setHidden(true);
            final ListGridField codFatura = new ListGridField("codFatura", "Cdigo fatura");
            codFatura.setAlign(Alignment.CENTER);
            codFatura.setHidden(true);
            final ListGridField dataEhora = new ListGridField("dataEhora", "Data e Hora");
            dataEhora.setAlign(Alignment.CENTER);
            final ListGridField valor = new ListGridField("valor", "Valor lan.");
            valor.setAlign(Alignment.CENTER);
            final ListGridField valorPago = new ListGridField("valorPago", "Pago Fat.");
            valorPago.setAlign(Alignment.CENTER);
            final ListGridField estado = new ListGridField("estado", "Status");
            estado.setAlign(Alignment.CENTER);
            estado.setHidden(true);
            final ListGrid lancGrid = new ListGrid();
            lancGrid.setHeight(224);
            lancGrid.setCellHeight(22);
            lancGrid.setFields(codLancamento, codFatura, dataEhora, valor, valorPago, estado);
            Info.dbService.buscarFaturaHasLancamentoPorFatura(record.getAttributeAsInt("codigo"),
                    new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                        }

                        @Override
                        public void onSuccess(ArrayList<TreeMap<String, String>> historico) {
                            if (historico != null) {
                                for (TreeMap<String, String> histFat : historico) {
                                    Record regs = new Record();
                                    regs.setAttribute("codFatura", histFat.get("codFatura"));
                                    regs.setAttribute("codLancamento", histFat.get("codLancamento"));
                                    regs.setAttribute("dataEhora", DateTimeFormat.getShortDateTimeFormat()
                                            .format(new Date(Long.parseLong(histFat.get("dataEhora")))));
                                    regs.setAttribute("valor",
                                            Info.formataSaldo(Double.parseDouble(histFat.get("valor"))));
                                    regs.setAttribute("valorPago",
                                            Info.formataSaldo(Double.parseDouble(histFat.get("valorPago"))));
                                    regs.setAttribute("estado",
                                            (Boolean.parseBoolean(histFat.get("estado")) == false)
                                                    ? "<nbr class=\"negativo\">Em aberto</nbr>"
                                                    : "<nbr class=\"positivo\">Quitada</nbr>");
                                    lancGrid.addData(regs);
                                }
                            }
                        }
                    });
            lancGrid.setShowAllRecords(true);
            lancGrid.setCanPickFields(false);
            layout.addMember(label);
            layout.addMember(lancGrid);
            return layout;
        }

        @Override
        protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {

            String fieldName = this.getFieldName(colNum);
            final ListGrid listAux = this;
            if (fieldName.equals("juroMulta")) {
                HLayout recordCanvas = new HLayout(3);
                recordCanvas.setHeight(22);
                recordCanvas.setWidth100();
                recordCanvas.setAlign(Alignment.CENTER);
                ImgButton jurosMultaImg = new ImgButton();
                jurosMultaImg.setShowDown(false);
                jurosMultaImg.setShowRollOver(false);
                jurosMultaImg.setLayoutAlign(Alignment.CENTER);
                jurosMultaImg.setSrc("[SKIN]actions/remove.png");
                jurosMultaImg.setPrompt("Remover juros e multa");
                jurosMultaImg.setHeight(16);
                jurosMultaImg.setWidth(16);
                jurosMultaImg.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        //arrayFaturasBD.get(listAux.getRecordIndex(record)).put("count", String.valueOf(1));
                        EditarJurosFatura editarFatura = new EditarJurosFatura(listAux, record, arrayFaturasBD,
                                saldoFaturasApagar, totalFaturasApagar, objLancamento);
                        editarFatura.setAnimateTime(1200);
                        editarFatura.animateShow(AnimationEffect.FADE);
                    }
                });
                recordCanvas.addMember(jurosMultaImg);
                return recordCanvas;

            } else {
                return null;
            }

        }
    };
    final ListGrid faturasSelecionadas = new ListGrid();
    faturasSelecionadas.setShowAllRecords(true);
    faturasSelecionadas.setAnimateRollUnder(true);
    faturasSelecionadas.setAlternateRecordStyles(false);
    faturasSelecionadas.setCanPickFields(false);
    faturasSelecionadas.setAnimateSelectionUnder(true);
    faturasSelecionadas.setWidth(789);
    faturasSelecionadas.setHeight(135);

    final ListGridField codClienteFat = new ListGridField("codCliente", "Cdigo Cliente");
    codClienteFat.setAlign(Alignment.CENTER);
    codClienteFat.setHidden(true);
    final ListGridField codigo = new ListGridField("codigo", "Cdigo");
    codigo.setAlign(Alignment.CENTER);
    codigo.setHidden(true);
    final ListGridField valor = new ListGridField("valor", "Valor");
    valor.setAlign(Alignment.CENTER);
    final ListGridField valorPago = new ListGridField("valorPago", "Valor pago");
    valorPago.setAlign(Alignment.CENTER);
    final ListGridField valorTotal = new ListGridField("valorTotal", "Valor Total");
    valorTotal.setAlign(Alignment.CENTER);
    final ListGridField jurosEmulta = new ListGridField("jurosEmulta", "Juros e multa");
    jurosEmulta.setAlign(Alignment.CENTER);
    final ListGridField valorApagar = new ListGridField("valorApagar", "a Pagar");
    valorApagar.setAlign(Alignment.CENTER);
    final ListGridField dataFatura = new ListGridField("dataFatura", "Data");
    dataFatura.setAlign(Alignment.CENTER);
    final ListGridField mes = new ListGridField("mesReferencia", "Ms");
    mes.setAlign(Alignment.CENTER);
    final ListGridField estadoFat = new ListGridField("estado", "Status");
    estadoFat.setAlign(Alignment.CENTER);
    ListGridField removeJurosMulta = new ListGridField("juroMulta", "remover M e J");
    removeJurosMulta.setAlign(Alignment.CENTER);
    ListGridField count = new ListGridField("count", "count");
    count.setAlign(Alignment.CENTER);
    count.setHidden(true);
    ///////////////////////////////////////////////////////////////////////////
    final ListGridField codClienteSelect = new ListGridField("codCliente", "Cdigo Cliente");
    codClienteSelect.setAlign(Alignment.CENTER);
    codClienteSelect.setHidden(true);
    final ListGridField codigoSelect = new ListGridField("codigo", "Cdigo");
    codigoSelect.setAlign(Alignment.CENTER);
    codigoSelect.setHidden(true);
    final ListGridField valorSelect = new ListGridField("valor", "Valor");
    valorSelect.setAlign(Alignment.CENTER);
    final ListGridField valorPagoSelect = new ListGridField("valorPago", "Crdito a lanar");
    valorPagoSelect.setAlign(Alignment.CENTER);
    final ListGridField valorTotalSelect = new ListGridField("valorTotal", "Valor Total");
    valorTotalSelect.setAlign(Alignment.CENTER);
    final ListGridField valorApagarSelect = new ListGridField("valorApagar", "Dbito restante");
    valorApagarSelect.setAlign(Alignment.CENTER);
    final ListGridField dataFaturaSelect = new ListGridField("dataFatura", "Data Venc.");
    dataFaturaSelect.setAlign(Alignment.CENTER);
    final ListGridField mesSelect = new ListGridField("mesReferencia", "Ms");
    mesSelect.setAlign(Alignment.CENTER);
    final ListGridField estadoFatSelect = new ListGridField("estado", "Status");
    estadoFatSelect.setAlign(Alignment.CENTER);
    ////////////////////////////////////////////////////////////////////////////////////////////////////////
    Info.dbService.buscarTodasTaxas(new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

        @Override
        public void onFailure(Throwable caught) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void onSuccess(ArrayList<TreeMap<String, String>> taxas) {
            if (taxas != null) {
                for (TreeMap<String, String> txs : taxas) {
                    if (Integer.parseInt(txs.get("codTaxa")) == 1) {
                        multa = Double.parseDouble(txs.get("valor"));
                    } else if (Integer.parseInt(txs.get("codTaxa")) == 2) {
                        juros = Double.parseDouble(txs.get("valor"));
                    }
                }
            }
        }
    });
    //GWT.log("Linha NL - 01");
    listaDeFaturas.setFields(codClienteFat, codigo, dataFatura, valor, jurosEmulta, mes, valorTotal, valorPago,
            valorApagar, removeJurosMulta, count);
    //GWT.log("Linha NL - 02");
    listaDeFaturas.setWidth(789);
    listaDeFaturas.setHeight(135);
    listaDeFaturas.setShowAllRecords(true);
    listaDeFaturas.setCanPickFields(false);
    //listaDeFaturas.setSortDirection(SortDirection.DESCENDING);
    //listaDeFaturas.setSortField("dataFatura");
    listaDeFaturas.setShowRecordComponents(true);
    listaDeFaturas.setShowRecordComponentsByCell(true);
    listaDeFaturas.setCanResizeFields(true);
    listaDeFaturas.setDrawAheadRatio(4);
    listaDeFaturas.setCanExpandRecords(true);
    ///************************************************************************************************************************************************************////
    Info.dbService.buscarFaturaEmAbertoPorCliente(codCliente,
            new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                @Override
                public void onFailure(Throwable caught) {
                    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                }

                @Override
                public void onSuccess(ArrayList<TreeMap<String, String>> faturasCliente) {
                    //////////////////////////////////////////////////////////////////****************************************\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
                    Date dataAtual = new Date(System.currentTimeMillis());
                    long diaAtual = dataAtual.getTime();
                    long diferencaDeDatas = 0;
                    long diaVencimento = 0;

                    TreeMap<String, String> faturaAuxiliar = new TreeMap<String, String>();
                    if (faturasCliente != null) {
                        for (TreeMap<String, String> fats : faturasCliente) {
                            if (faturasCliente.get(0).get("codFatura") != null
                                    && faturaAuxiliar.get(fats.get("codFatura")) == null) {
                                Date dataDeVencimento = new Date(Long.parseLong(fats.get("dataVencimento")));
                                diaVencimento = dataDeVencimento.getTime();
                                diferencaDeDatas = diaAtual - diaVencimento;
                                TreeMap<String, String> faturaBD = new TreeMap<String, String>();
                                faturaBD.put("codFatura", fats.get("codFatura"));
                                faturaBD.put("codCliente", fats.get("codCliente"));
                                faturaBD.put("dataVencimento", fats.get("dataVencimento"));
                                faturaBD.put("valor", String
                                        .valueOf(Info.formataSaldo(Double.parseDouble(fats.get("valor")))));
                                faturaBD.put("estado", fats.get("estado"));
                                faturaBD.put("valorPago",
                                        (fats.get("totalLancamentos") == null)
                                                ? String.valueOf(Info.formataSaldo(0))
                                                : String.valueOf(Info.formataSaldo(
                                                        Double.parseDouble(fats.get("totalLancamentos")))));
                                faturaBD.put("mesReferencia", fats.get("mes"));
                                faturaBD.put("count", "0");
                                //GWT.log("" + fats.get("valorApagar"));
                                double totalPago = (fats.get("totalLancamentos") == null) ? 0
                                        : (Double.parseDouble(fats.get("totalLancamentos")));
                                //GWT.log("Valor a pagar"+(Double.parseDouble(fats.get("valor")) - (totalPago)));
                                if (diferencaDeDatas <= 0) {
                                    double valor = Double.parseDouble(fats.get("valor"));
                                    double valorAtualFatura = (totalPago == 0) ? Info.formataDecimal(valor)
                                            : Info.formataDecimal(
                                                    Double.parseDouble(fats.get("valor")) - (totalPago));
                                    faturaBD.put("jurosEmulta",
                                            String.valueOf(Info.formataSaldo(Double.parseDouble("0"))));
                                    faturaBD.put("valorApagar", String.valueOf(
                                            Info.formataSaldo(Info.formataDecimal((valorAtualFatura)))));
                                    faturaBD.put("valorTotal", String.valueOf(Info.formataSaldo(
                                            Info.formataDecimal(Double.parseDouble(fats.get("valor"))))));
                                    diferencaDeDatas = 0;
                                } else if (diferencaDeDatas > 0 && diferencaDeDatas < 86400000) {
                                    double valor = Double.parseDouble(fats.get("valor"));
                                    double valorAtualFatura = (totalPago == 0)
                                            ? Info.formataDecimal(valor) + (valor * multa)
                                            : Info.formataDecimal(Double.parseDouble(fats.get("valor"))
                                                    - (totalPago) + (valor * multa));
                                    faturaBD.put("jurosEmulta", String
                                            .valueOf(Info.formataSaldo((Info.formataDecimal(valor * multa)))));
                                    faturaBD.put("valorApagar",
                                            String.valueOf(Info.formataSaldo(valorAtualFatura)));
                                    faturaBD.put("valorTotal", String.valueOf(Info.formataSaldo(
                                            Info.formataDecimal(Double.parseDouble(fats.get("valor"))
                                                    + ((Double.parseDouble(fats.get("valor")) * multa))))));
                                    diferencaDeDatas = 0;
                                } else if (diferencaDeDatas > 86400000) {
                                    double valor = Double.parseDouble(fats.get("valor"));
                                    double valorAtualFatura = (totalPago == 0)
                                            ? Info.formataDecimal(valor) + (valor * multa)
                                                    + ((diferencaDeDatas / 86400000) * (juros * valor))
                                            : Info.formataDecimal(Double.parseDouble(fats.get("valor"))
                                                    - (totalPago) + (valor * multa)
                                                    + ((diferencaDeDatas / 86400000) * (juros * valor)));
                                    faturaBD.put("jurosEmulta",
                                            String.valueOf(Info.formataSaldo(Info.formataDecimal((valor * multa)
                                                    + ((diferencaDeDatas / 86400000) * (juros * valor))))));
                                    faturaBD.put("valorApagar",
                                            String.valueOf(Info.formataSaldo(valorAtualFatura)));
                                    faturaBD.put("valorTotal", String.valueOf(Info.formataSaldo(
                                            Info.formataDecimal(Double.parseDouble(fats.get("valor"))
                                                    + ((Double.parseDouble(fats.get("valor")) * multa))
                                                    + ((diferencaDeDatas / 86400000) * (juros
                                                            * Double.parseDouble(fats.get("valor"))))))));
                                    diferencaDeDatas = 0;
                                }
                                arrayFaturasBD.add(faturaBD);
                                faturaAuxiliar.put(fats.get("codFatura"), fats.get("codFatura"));
                            }
                        }
                    }
                    ////////////////////////////////////////////////////////////////*******************************************\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\            
                    for (TreeMap<String, String> fats : arrayFaturasBD) {
                        Record fat = new Record();
                        fat.setAttribute("codigo", fats.get("codFatura"));
                        fat.setAttribute("codCliente", fats.get("codCliente"));
                        fat.setAttribute("dataFatura", DateTimeFormat.getShortDateFormat()
                                .format(new Date(Long.parseLong(fats.get("dataVencimento")))));
                        fat.setAttribute("valor", fats.get("valor"));
                        fat.setAttribute("estado",
                                (Boolean.parseBoolean(fats.get("estado")) == false)
                                        ? "<nbr class=\negativo\"> Em aberto</nbr>"
                                        : "<nbr class=\"positivo\">Quitada</nbr>");
                        fat.setAttribute("valorPago", fats.get("valorPago"));
                        fat.setAttribute("mesReferencia", fats.get("mesReferencia"));
                        fat.setAttribute("valorApagar", fats.get("valorApagar"));
                        fat.setAttribute("valorTotal", fats.get("valorTotal"));
                        fat.setAttribute("jurosEmulta", fats.get("jurosEmulta"));
                        fat.setAttribute("count", Integer.parseInt(fats.get("count")));
                        listaDeFaturas.addData(fat);
                        totalFaturasApagar = totalFaturasApagar
                                + Double.parseDouble(fats.get("valorApagar").replaceAll(",", "\\."));
                    }
                    saldoFaturasApagar.redraw();
                    saldoFaturasApagar
                            .setContents("<strong style=\"font-size:22px; color:red;\">total de dbito: - R$"
                                    + Info.formataSaldo(Info.formataDecimal(totalFaturasApagar))
                                    + "  </strong>");
                }
            });
    ///************************************************************************************************************************************************************////
    //fats = listaDeFaturas.getRecords();
    faturasSelecionadas.setFields(codClienteSelect, codigoSelect, dataFaturaSelect, valorSelect, mesSelect,
            valorTotalSelect, valorPagoSelect, valorApagarSelect);

    itemValor.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            String tecla;
            tecla = event.getKeyName();
            //GWT.log("Tecla " + tecla + " KeyCod = " + event.getCharacterValue());
            //GWT.log("Objeto JavaScript "+ Info.FormataMoeda(itemValor.getValueAsString(), ".", ",", tecla));
            String aux = "";
            if (event.getCharacterValue() != null && event.getCharacterValue() >= 48
                    && event.getCharacterValue() <= 57) {
                aux = Info.FormataMoeda(
                        (itemValor.getValueAsString() != null) ? itemValor.getValueAsString() : "0", ".", ",",
                        tecla);
                flagItemValor = true;
            }
            //GWT.log("Aux=" + aux);
            //itemValor.setValue(aux);
            campo = aux;
            //Info.FormataMoeda(itemValor.getJsObj(), ".", ",", tecla);
        }
    });
    final TreeMap<String, String> faturaAux = new TreeMap<String, String>();

    itemValor.addChangedHandler(new ChangedHandler() {

        @Override
        public void onChanged(ChangedEvent event) {
            faturasSelecionadas.setData(new RecordList());
            //GWT.log("Entrou no changed: " + event.getValue());
            if (flagItemValor) {
                itemValor.setValue(campo);
            }
            flagItemValor = false;
            final String novoLancamento = campo;
            if ((event.getValue() != null && !novoLancamento.equalsIgnoreCase(""))) {
                double valorNovoApagar = 0;
                double valorNovoLancamento = 0;
                //GWT.log("valorNovoLancamento ReplaceAll: " + itemValor.getDisplayValue().replaceAll("\\.", "").replaceAll(",", "\\."));
                valorNovoLancamento = Double
                        .parseDouble(itemValor.getDisplayValue().replaceAll("\\.", "").replaceAll(",", "\\."));
                //GWT.log("valorNovoLancamento: " + valorNovoLancamento);
                valorNovoLancamento = Info.formataDecimal(valorNovoLancamento);
                fats = listaDeFaturas.getRecords();
                // GWT.log("fats.length: " + fats.length);
                for (int i = 0; i < fats.length; i++) {
                    double valorAtualFatura = Double
                            .parseDouble(arrayFaturasBD.get(i).get("valorApagar").replaceAll(",", "\\."));
                    if (valorAtualFatura <= valorNovoLancamento) {
                        fats[i].setAttribute("valorApagar", String.valueOf(Info.formataSaldo(0)));
                        faturasSelecionadas.addData(fats[i]);
                        valorNovoLancamento = valorNovoLancamento - valorAtualFatura;
                        valorNovoLancamento = Info.formataDecimal(valorNovoLancamento);
                        /*Linha 451*/
                        fats[i].setAttribute("valorPago", String.valueOf(Info.formataSaldo(valorAtualFatura)));
                    } else {
                        //GWT.log("valorNovoLancamento ELSE: " + valorNovoLancamento);
                        if (valorNovoLancamento > 0) {
                            //GWT.log("Valor a pagar ELSE: " + fats[i].getAttribute("valorApagar").replaceAll("\\.", "").replaceAll(",", "\\."));
                            valorNovoApagar = Double.parseDouble((arrayFaturasBD.get(i).get("valorApagar")
                                    .replaceAll("\\.", "").replaceAll(",", "\\."))) - valorNovoLancamento;
                            valorNovoApagar = Info.formataDecimal(valorNovoApagar);
                            fats[i].setAttribute("valorPago",
                                    String.valueOf(Info.formataSaldo(valorNovoLancamento)));
                            fats[i].setAttribute("valorApagar",
                                    String.valueOf(Info.formataSaldo(valorNovoApagar)));
                            faturasSelecionadas.addData(fats[i]);
                            valorNovoLancamento = 0;
                        }
                    }
                }
            } else {
                fatsAux = faturasSelecionadas.getRecords();
                faturaAux.clear();
                if (!faturasSelecionadas.getRecordList().isEmpty()) {
                    for (int i = 0; i < fatsAux.length; i++) {
                        faturasSelecionadas.removeData(fatsAux[i]);
                    }
                }
                fats = listaDeFaturas.getRecords();
                for (int i = 0; i < fats.length; i++) {
                    listaDeFaturas.removeData(fats[i]);
                }
                for (TreeMap<String, String> fats : arrayFaturasBD) {
                    Record fat = new Record();
                    fat.setAttribute("codigo", fats.get("codFatura"));
                    fat.setAttribute("codCliente", fats.get("codCliente"));
                    fat.setAttribute("dataFatura", DateTimeFormat.getShortDateFormat()
                            .format(new Date(Long.parseLong(fats.get("dataVencimento")))));
                    fat.setAttribute("valor", fats.get("valor"));
                    fat.setAttribute("estado",
                            (Boolean.parseBoolean(fats.get("estado")) == false)
                                    ? "<nbr class=\negativo\"> Em aberto</nbr>"
                                    : "<nbr class=\"positivo\">Quitada</nbr>");
                    fat.setAttribute("valorPago", fats.get("valorPago"));
                    fat.setAttribute("mesReferencia", fats.get("mesReferencia"));
                    fat.setAttribute("valorApagar", fats.get("valorApagar"));
                    fat.setAttribute("valorTotal", fats.get("valorTotal"));
                    fat.setAttribute("jurosEmulta", fats.get("jurosEmulta"));
                    fat.setAttribute("count", Integer.parseInt(fats.get("count")));
                    listaDeFaturas.addData(fat);

                }

            }
        }
    });
    //GWT.log("arrayFaturasBD: " + arrayFaturasBD);
    cadastrar.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (formNovoLancamento.validate()) {
                contador = 0;
                final Window janelaCarregando = new Window();
                janelaCarregando.setShowTitle(false);
                janelaCarregando.setWidth(100);
                janelaCarregando.setHeight(50);
                janelaCarregando.setShowEdges(false);
                janelaCarregando.setShowCloseButton(false);
                janelaCarregando.setShowMinimizeButton(false);
                janelaCarregando.setIsModal(true);
                janelaCarregando.setShowModalMask(true);
                janelaCarregando.centerInPage();
                janelaCarregando.setLayoutAlign(Alignment.CENTER);
                final Label mensagem = new Label("Carregando..");
                mensagem.setHeight(16);

                new Timer() {
                    public void run() {

                        if (contador != 100) {
                            contador += 1 + (int) (5 * Math.random());
                            schedule(1 + (int) (50 * Math.random()));
                            mensagem.setContents("Carregando: " + contador + "%");
                            janelaCarregando.addItem(mensagem);
                            janelaCarregando.setAnimateTime(1200);
                            janelaCarregando.animateShow(AnimationEffect.FADE);

                            if (contador >= 100) {
                                mensagem.setContents("Carregando: 100%");
                                /* TreeMap que vai para o banco como Novo lanamento*/
                                TreeMap<String, String> novoLancamento = new TreeMap<String, String>();
                                novoLancamento.put("codCliente", String.valueOf(codCliente));
                                Timestamp dataEhora = new Timestamp(itemDataEhora.getValueAsDate().getTime());
                                String valorFinalLanc = itemValor.getDisplayValue().replaceAll("\\.", "")
                                        .replaceAll(",", "\\.");
                                //GWT.log("Valor Sem virgula:" + valorFinalLanc);
                                novoLancamento.put("valor", valorFinalLanc);
                                /* TreeMap que vai para o banco como Novo lanamento*/

                                /* arrayList de TreeMap que vai para o banco como Novo fatura_has_lancamento*/
                                ArrayList<TreeMap<String, String>> arrayListFaturas = new ArrayList<TreeMap<String, String>>();
                                if (!faturasSelecionadas.getRecordList().isEmpty()) {
                                    ListGridRecord fats[] = faturasSelecionadas.getRecords();
                                    for (int i = 0; i < fats.length; i++) {
                                        //GWT.log("valorApagar: " + arrayFaturasBD.get(i).get("valorApagar"));
                                        TreeMap<String, String> treeMapFatura = new TreeMap<String, String>();
                                        treeMapFatura.put("codCliente", String.valueOf(codCliente));
                                        treeMapFatura.put("codFatura", fats[i].getAttribute("codigo"));
                                        treeMapFatura.put("valorTotal",
                                                Info.formataReaisFloat(fats[i].getAttribute("valorTotal")));
                                        treeMapFatura.put("valorApagar",
                                                Info.formataReaisFloat(fats[i].getAttribute("valorApagar")));
                                        treeMapFatura.put("valorPago",
                                                Info.formataReaisFloat(fats[i].getAttribute("valorPago")));
                                        arrayListFaturas.add(treeMapFatura);
                                    }
                                }

                                Info.dbService.cadastrarLancamento(novoLancamento, arrayListFaturas, dataEhora,
                                        new AsyncCallback<Void>() {

                                            @Override
                                            public void onFailure(Throwable caught) {
                                                //GWT.log("caught: "+caught);
                                                throw new UnsupportedOperationException(
                                                        "Not supported yet.!!!!!!!!!!!!!!"); //To change body of generated methods, choose Tools | Templates.
                                            }

                                            @Override
                                            public void onSuccess(Void result) {
                                                listFaturas.setData(new RecordList());
                                                arrayFaturasBD.clear();
                                                //GWT.log("" + arrayFaturasBD);

                                                Info.dbService.buscarUltimoLancamento(
                                                        new AsyncCallback<TreeMap<String, String>>() {

                                                            @Override
                                                            public void onFailure(Throwable caught) {
                                                                throw new UnsupportedOperationException(
                                                                        "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                            }

                                                            @Override
                                                            public void onSuccess(
                                                                    TreeMap<String, String> ultimoLancamento) {
                                                                if (ultimoLancamento != null) {
                                                                    Record regLancamento = new Record();
                                                                    //GWT.log("codUltimoLanc: " + ultimoLancamento.get("codLancamento"));
                                                                    regLancamento.setAttribute("codCliente",
                                                                            ultimoLancamento.get("codCliente"));
                                                                    regLancamento.setAttribute("codigo",
                                                                            ultimoLancamento
                                                                                    .get("codLancamento"));
                                                                    regLancamento.setAttribute("data",
                                                                            DateTimeFormat
                                                                                    .getShortDateTimeFormat()
                                                                                    .format(new Date(
                                                                                            Long.parseLong(
                                                                                                    ultimoLancamento
                                                                                                            .get("dataEhora")))));
                                                                    regLancamento.setAttribute("valor",
                                                                            "R$" + Info.formataValor(Float
                                                                                    .parseFloat(ultimoLancamento
                                                                                            .get("valor"))));
                                                                    listLancamentos.addData(regLancamento);
                                                                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    Info.dbService.buscarTodasTaxas(
                                                                            new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                                                                                @Override
                                                                                public void onFailure(
                                                                                        Throwable caught) {
                                                                                    throw new UnsupportedOperationException(
                                                                                            "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                                                }

                                                                                @Override
                                                                                public void onSuccess(
                                                                                        ArrayList<TreeMap<String, String>> taxas) {
                                                                                    if (taxas != null) {
                                                                                        for (TreeMap<String, String> txs : taxas) {
                                                                                            if (Integer
                                                                                                    .parseInt(
                                                                                                            txs.get("codTaxa")) == 1) {
                                                                                                multa = Double
                                                                                                        .parseDouble(
                                                                                                                txs.get("valor"));
                                                                                            } else if (Integer
                                                                                                    .parseInt(
                                                                                                            txs.get("codTaxa")) == 2) {
                                                                                                juros = Double
                                                                                                        .parseDouble(
                                                                                                                txs.get("valor"));
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            });
                                                                    Info.dbService.buscarFaturaPorCliente(
                                                                            codCliente,
                                                                            new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                                                                                @Override
                                                                                public void onFailure(
                                                                                        Throwable caught) {
                                                                                    throw new UnsupportedOperationException(
                                                                                            "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                                                }

                                                                                @Override
                                                                                public void onSuccess(
                                                                                        ArrayList<TreeMap<String, String>> faturasCliente) {
                                                                                    Date dataAtual = new Date(
                                                                                            System.currentTimeMillis());
                                                                                    long diaAtual = dataAtual
                                                                                            .getTime();
                                                                                    long diferencaDeDatas = 0;
                                                                                    long diaVencimento = 0;
                                                                                    TreeMap<String, String> faturaAuxiliar = new TreeMap<String, String>();
                                                                                    if (faturasCliente != null) {
                                                                                        for (TreeMap<String, String> fats : faturasCliente) {
                                                                                            if (faturasCliente
                                                                                                    .get(0)
                                                                                                    .get("codFatura") != null
                                                                                                    && faturaAuxiliar
                                                                                                            .get(fats
                                                                                                                    .get("codFatura")) == null) {
                                                                                                Date dataDeVencimento = new Date(
                                                                                                        Long.parseLong(
                                                                                                                fats.get(
                                                                                                                        "dataVencimento")));
                                                                                                diaVencimento = dataDeVencimento
                                                                                                        .getTime();
                                                                                                diferencaDeDatas = diaAtual
                                                                                                        - diaVencimento;
                                                                                                TreeMap<String, String> faturaBD = new TreeMap<String, String>();
                                                                                                faturaBD.put(
                                                                                                        "codFatura",
                                                                                                        fats.get(
                                                                                                                "codFatura"));
                                                                                                faturaBD.put(
                                                                                                        "codCliente",
                                                                                                        fats.get(
                                                                                                                "codCliente"));
                                                                                                faturaBD.put(
                                                                                                        "dataVencimento",
                                                                                                        fats.get(
                                                                                                                "dataVencimento"));
                                                                                                faturaBD.put(
                                                                                                        "valor",
                                                                                                        String.valueOf(
                                                                                                                Info.formataSaldo(
                                                                                                                        Double.parseDouble(
                                                                                                                                fats.get(
                                                                                                                                        "valor")))));
                                                                                                faturaBD.put(
                                                                                                        "estado",
                                                                                                        fats.get(
                                                                                                                "estado"));
                                                                                                faturaBD.put(
                                                                                                        "valorPago",
                                                                                                        (fats.get(
                                                                                                                "totalLancamentos") == null)
                                                                                                                        ? String.valueOf(
                                                                                                                                Info.formataSaldo(
                                                                                                                                        0))
                                                                                                                        : String.valueOf(
                                                                                                                                Info.formataSaldo(
                                                                                                                                        Double.parseDouble(
                                                                                                                                                fats.get(
                                                                                                                                                        "totalLancamentos")))));
                                                                                                faturaBD.put(
                                                                                                        "mesReferencia",
                                                                                                        fats.get(
                                                                                                                "mes"));
                                                                                                faturaBD.put(
                                                                                                        "count",
                                                                                                        "0");
                                                                                                //GWT.log("" + fats.get("valorApagar"));
                                                                                                double totalPago = (fats
                                                                                                        .get("totalLancamentos") == null)
                                                                                                                ? 0
                                                                                                                : (Double
                                                                                                                        .parseDouble(
                                                                                                                                fats.get(
                                                                                                                                        "totalLancamentos")));
                                                                                                //GWT.log("Valor a pagar"+(Double.parseDouble(fats.get("valor")) - (totalPago)));
                                                                                                if (diferencaDeDatas <= 0) {
                                                                                                    double valor = Double
                                                                                                            .parseDouble(
                                                                                                                    fats.get(
                                                                                                                            "valor"));
                                                                                                    double valorAtualFatura = (totalPago == 0)
                                                                                                            ? Info.formataDecimal(
                                                                                                                    valor)
                                                                                                            : Info.formataDecimal(
                                                                                                                    Double.parseDouble(
                                                                                                                            fats.get(
                                                                                                                                    "valor"))
                                                                                                                            - (totalPago));
                                                                                                    faturaBD.put(
                                                                                                            "jurosEmulta",
                                                                                                            String.valueOf(
                                                                                                                    Info.formataSaldo(
                                                                                                                            Double.parseDouble(
                                                                                                                                    "0"))));
                                                                                                    faturaBD.put(
                                                                                                            "valorApagar",
                                                                                                            String.valueOf(
                                                                                                                    Info.formataSaldo(
                                                                                                                            Info.formataDecimal(
                                                                                                                                    (valorAtualFatura)))));
                                                                                                    faturaBD.put(
                                                                                                            "valorTotal",
                                                                                                            String.valueOf(
                                                                                                                    Info.formataSaldo(
                                                                                                                            Info.formataDecimal(
                                                                                                                                    Double.parseDouble(
                                                                                                                                            fats.get(
                                                                                                                                                    "valor"))))));
                                                                                                    diferencaDeDatas = 0;
                                                                                                } else if (diferencaDeDatas > 0
                                                                                                        && diferencaDeDatas < 86400000) {
                                                                                                    double valor = Double
                                                                                                            .parseDouble(
                                                                                                                    fats.get(
                                                                                                                            "valor"));
                                                                                                    double valorAtualFatura = (totalPago == 0)
                                                                                                            ? Info.formataDecimal(
                                                                                                                    valor)
                                                                                                                    + (valor * multa)
                                                                                                            : Info.formataDecimal(
                                                                                                                    Double.parseDouble(
                                                                                                                            fats.get(
                                                                                                                                    "valor"))
                                                                                                                            - (totalPago)
                                                                                                                            + (valor * multa));
                                                                                                    faturaBD.put(
                                                                                                            "jurosEmulta",
                                                                                                            String.valueOf(
                                                                                                                    Info.formataSaldo(
                                                                                                                            (Info.formataDecimal(
                                                                                                                                    valor * multa)))));
                                                                                                    faturaBD.put(
                                                                                                            "valorApagar",
                                                                                                            String.valueOf(
                                                                                                                    Info.formataSaldo(
                                                                                                                            valorAtualFatura)));
                                                                                                    faturaBD.put(
                                                                                                            "valorTotal",
                                                                                                            String.valueOf(
                                                                                                                    Info.formataSaldo(
                                                                                                                            Info.formataDecimal(
                                                                                                                                    Double.parseDouble(
                                                                                                                                            fats.get(
                                                                                                                                                    "valor"))
                                                                                                                                            + ((Double
                                                                                                                                                    .parseDouble(
                                                                                                                                                            fats.get(
                                                                                                                                                                    "valor"))
                                                                                                                                                    * multa))))));
                                                                                                    diferencaDeDatas = 0;
                                                                                                } else if (diferencaDeDatas > 86400000) {
                                                                                                    double valor = Double
                                                                                                            .parseDouble(
                                                                                                                    fats.get(
                                                                                                                            "valor"));
                                                                                                    double valorAtualFatura = (totalPago == 0)
                                                                                                            ? Info.formataDecimal(
                                                                                                                    valor)
                                                                                                                    + (valor * multa)
                                                                                                                    + ((diferencaDeDatas
                                                                                                                            / 86400000)
                                                                                                                            * (juros * valor))
                                                                                                            : Info.formataDecimal(
                                                                                                                    Double.parseDouble(
                                                                                                                            fats.get(
                                                                                                                                    "valor"))
                                                                                                                            - (totalPago)
                                                                                                                            + (valor * multa)
                                                                                                                            + ((diferencaDeDatas
                                                                                                                                    / 86400000)
                                                                                                                                    * (juros * valor)));
                                                                                                    faturaBD.put(
                                                                                                            "jurosEmulta",
                                                                                                            String.valueOf(
                                                                                                                    Info.formataSaldo(
                                                                                                                            Info.formataDecimal(
                                                                                                                                    (valor * multa)
                                                                                                                                            + ((diferencaDeDatas
                                                                                                                                                    / 86400000)
                                                                                                                                                    * (juros * valor))))));
                                                                                                    faturaBD.put(
                                                                                                            "valorApagar",
                                                                                                            String.valueOf(
                                                                                                                    Info.formataSaldo(
                                                                                                                            valorAtualFatura)));
                                                                                                    faturaBD.put(
                                                                                                            "valorTotal",
                                                                                                            String.valueOf(
                                                                                                                    Info.formataSaldo(
                                                                                                                            Info.formataDecimal(
                                                                                                                                    Double.parseDouble(
                                                                                                                                            fats.get(
                                                                                                                                                    "valor"))
                                                                                                                                            + ((Double
                                                                                                                                                    .parseDouble(
                                                                                                                                                            fats.get(
                                                                                                                                                                    "valor"))
                                                                                                                                                    * multa))
                                                                                                                                            + ((diferencaDeDatas
                                                                                                                                                    / 86400000)
                                                                                                                                                    * (juros * Double
                                                                                                                                                            .parseDouble(
                                                                                                                                                                    fats.get(
                                                                                                                                                                            "valor"))))))));
                                                                                                    diferencaDeDatas = 0;
                                                                                                }
                                                                                                arrayFaturasBD
                                                                                                        .add(faturaBD);
                                                                                                faturaAuxiliar
                                                                                                        .put(fats
                                                                                                                .get("codFatura"),
                                                                                                                fats.get(
                                                                                                                        "codFatura"));
                                                                                            }
                                                                                        }
                                                                                        objFaturaLancamento
                                                                                                .setTotalLancamentos(
                                                                                                        0);
                                                                                        objFaturaLancamento
                                                                                                .setTotalFaturas(
                                                                                                        0);
                                                                                        objFaturaLancamento
                                                                                                .setSaldo(0);
                                                                                        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++////////////
                                                                                        for (TreeMap<String, String> fatsGrid : arrayFaturasBD) {
                                                                                            Record fat = new Record();
                                                                                            fat.setAttribute(
                                                                                                    "codigo",
                                                                                                    fatsGrid.get(
                                                                                                            "codFatura"));
                                                                                            fat.setAttribute(
                                                                                                    "codCliente",
                                                                                                    fatsGrid.get(
                                                                                                            "codCliente"));
                                                                                            fat.setAttribute(
                                                                                                    "dataFatura",
                                                                                                    DateTimeFormat
                                                                                                            .getShortDateFormat()
                                                                                                            .format(new Date(
                                                                                                                    Long.parseLong(
                                                                                                                            fatsGrid.get(
                                                                                                                                    "dataVencimento")))));
                                                                                            fat.setAttribute(
                                                                                                    "valor",
                                                                                                    fatsGrid.get(
                                                                                                            "valor"));
                                                                                            fat.setAttribute(
                                                                                                    "estado",
                                                                                                    (Boolean.parseBoolean(
                                                                                                            fatsGrid.get(
                                                                                                                    "estado")) == false)
                                                                                                                            ? "<nbr class=\negativo\"> Em aberto</nbr>"
                                                                                                                            : "<nbr class=\"positivo\">Quitada</nbr>");
                                                                                            fat.setAttribute(
                                                                                                    "valorPago",
                                                                                                    fatsGrid.get(
                                                                                                            "valorPago"));
                                                                                            fat.setAttribute(
                                                                                                    "mesReferencia",
                                                                                                    fatsGrid.get(
                                                                                                            "mesReferencia"));
                                                                                            fat.setAttribute(
                                                                                                    "valorApagar",
                                                                                                    (Boolean.parseBoolean(
                                                                                                            fatsGrid.get(
                                                                                                                    "estado")) == false)
                                                                                                                            ? fatsGrid
                                                                                                                                    .get("valorApagar")
                                                                                                                            : Info.formataSaldo(
                                                                                                                                    0));
                                                                                            fat.setAttribute(
                                                                                                    "valorTotal",
                                                                                                    fatsGrid.get(
                                                                                                            "valorTotal"));
                                                                                            fat.setAttribute(
                                                                                                    "jurosEmulta",
                                                                                                    (Boolean.parseBoolean(
                                                                                                            fatsGrid.get(
                                                                                                                    "estado")) == false)
                                                                                                                            ? fatsGrid
                                                                                                                                    .get("jurosEmulta")
                                                                                                                            : Info.formataSaldo(
                                                                                                                                    0));
                                                                                            fat.setAttribute(
                                                                                                    "count",
                                                                                                    Integer.parseInt(
                                                                                                            fatsGrid.get(
                                                                                                                    "count")));
                                                                                            listFaturas.addData(
                                                                                                    fat);
                                                                                            //GWT.log("fatsGrid.get(\"codFatura\"): "+fatsGrid.get("codFatura"));
                                                                                            //GWT.log("fatsGrid.get(\"estado\")): " + fatsGrid.get("estado"));
                                                                                            //GWT.log("fatsGrid.get(\"valorPago\"): " + fatsGrid.get("valorPago"));
                                                                                            objFaturaLancamento
                                                                                                    .setTotalFaturas(
                                                                                                            objFaturaLancamento
                                                                                                                    .getTotalFaturas()
                                                                                                                    + ((Double
                                                                                                                            .parseDouble(
                                                                                                                                    fat.getAttributeAsString(
                                                                                                                                            "valorPago")
                                                                                                                                            .replaceAll(
                                                                                                                                                    "\\.",
                                                                                                                                                    "")
                                                                                                                                            .replaceAll(
                                                                                                                                                    ",",
                                                                                                                                                    ".")) > 0
                                                                                                                            && Boolean
                                                                                                                                    .parseBoolean(
                                                                                                                                            fatsGrid.get(
                                                                                                                                                    "estado")) == true)
                                                                                                                                                            ? Double.parseDouble(
                                                                                                                                                                    fat.getAttributeAsString(
                                                                                                                                                                            "valorPago")
                                                                                                                                                                            .replaceAll(
                                                                                                                                                                                    "\\.",
                                                                                                                                                                                    "")
                                                                                                                                                                            .replaceAll(
                                                                                                                                                                                    ",",
                                                                                                                                                                                    "."))
                                                                                                                                                            : (Double
                                                                                                                                                                    .parseDouble(
                                                                                                                                                                            fat.getAttributeAsString(
                                                                                                                                                                                    "valorPago")
                                                                                                                                                                                    .replaceAll(
                                                                                                                                                                                            "\\.",
                                                                                                                                                                                            "")
                                                                                                                                                                                    .replaceAll(
                                                                                                                                                                                            ",",
                                                                                                                                                                                            "."))
                                                                                                                                                                    + Double.parseDouble(
                                                                                                                                                                            fat.getAttributeAsString(
                                                                                                                                                                                    "valorApagar")
                                                                                                                                                                                    .replaceAll(
                                                                                                                                                                                            "\\.",
                                                                                                                                                                                            "")
                                                                                                                                                                                    .replaceAll(
                                                                                                                                                                                            ",",
                                                                                                                                                                                            ".")))));
                                                                                        }
                                                                                        Info.dbService
                                                                                                .buscarTotalLancamentos(
                                                                                                        codCliente,
                                                                                                        new AsyncCallback<Double>() {

                                                                                                            @Override
                                                                                                            public void onFailure(
                                                                                                                    Throwable caught) {
                                                                                                                throw new UnsupportedOperationException(
                                                                                                                        "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                                                                            }

                                                                                                            @Override
                                                                                                            public void onSuccess(
                                                                                                                    Double totLanc) {
                                                                                                                labelLanc
                                                                                                                        .redraw();
                                                                                                                labelLanc
                                                                                                                        .setContents(
                                                                                                                                "<strong style=\"font-size:20px; \">Total de Lanamentos: R$"
                                                                                                                                        + Info.formataSaldo(
                                                                                                                                                totLanc)
                                                                                                                                        + "</strong>");
                                                                                                                objFaturaLancamento
                                                                                                                        .setTotalLancamentos(
                                                                                                                                totLanc);
                                                                                                                labelfaturas
                                                                                                                        .redraw();
                                                                                                                labelfaturas
                                                                                                                        .setContents(
                                                                                                                                "<strong style=\"font-size:20px; \">Total de Faturas: R$"
                                                                                                                                        + Info.formataSaldo(
                                                                                                                                                objFaturaLancamento
                                                                                                                                                        .getTotalFaturas())
                                                                                                                                        + "</strong>");
                                                                                                                objFaturaLancamento
                                                                                                                        .setSaldo(
                                                                                                                                objFaturaLancamento
                                                                                                                                        .getTotalLancamentos()
                                                                                                                                        - objFaturaLancamento
                                                                                                                                                .getTotalFaturas());
                                                                                                                if (objFaturaLancamento
                                                                                                                        .getSaldo() == 0) {
                                                                                                                    labelSaldo
                                                                                                                            .redraw();
                                                                                                                    labelSaldo
                                                                                                                            .setContents(
                                                                                                                                    "<strong style=\"font-size:25px; \">Saldo Atual: R$00,00\n</strong>");
                                                                                                                } else if (objFaturaLancamento
                                                                                                                        .getSaldo() > 0) {
                                                                                                                    labelSaldo
                                                                                                                            .redraw();
                                                                                                                    labelSaldo
                                                                                                                            .setContents(
                                                                                                                                    "<strong class=\"saldo-positivo\">Crdito Atual: R$"
                                                                                                                                            + Info.formataSaldo(
                                                                                                                                                    Info.formataDecimal(
                                                                                                                                                            objFaturaLancamento
                                                                                                                                                                    .getSaldo()))
                                                                                                                                            + "\n</strong>");
                                                                                                                } else {
                                                                                                                    labelSaldo
                                                                                                                            .redraw();
                                                                                                                    labelSaldo
                                                                                                                            .setContents(
                                                                                                                                    "<strong class=\"saldo-negativo\">Dbito Atual: R$"
                                                                                                                                            + Info.formataSaldo(
                                                                                                                                                    Info.formataDecimal(
                                                                                                                                                            objFaturaLancamento
                                                                                                                                                                    .getSaldo()))
                                                                                                                                            + "\n</strong>");
                                                                                                                }
                                                                                                            }
                                                                                                        });
                                                                                    } else {
                                                                                        Info.dbService
                                                                                                .buscarTotalLancamentos(
                                                                                                        codCliente,
                                                                                                        new AsyncCallback<Double>() {

                                                                                                            @Override
                                                                                                            public void onFailure(
                                                                                                                    Throwable caught) {
                                                                                                                throw new UnsupportedOperationException(
                                                                                                                        "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                                                                            }

                                                                                                            @Override
                                                                                                            public void onSuccess(
                                                                                                                    Double totLanc) {
                                                                                                                objFaturaLancamento
                                                                                                                        .setTotalLancamentos(
                                                                                                                                totLanc);
                                                                                                                labelLanc
                                                                                                                        .redraw();
                                                                                                                labelLanc
                                                                                                                        .setContents(
                                                                                                                                "<strong style=\"font-size:20px; \">Total de Lanamentos: R$"
                                                                                                                                        + Info.formataSaldo(
                                                                                                                                                Info.formataDecimal(
                                                                                                                                                        objFaturaLancamento
                                                                                                                                                                .getTotalLancamentos()))
                                                                                                                                        + "</strong>");
                                                                                                                labelfaturas
                                                                                                                        .redraw();
                                                                                                                //GWT.log("objFaturaLancamento.getTotalFaturas()): " + objFaturaLancamento.getTotalFaturas());
                                                                                                                labelfaturas
                                                                                                                        .setContents(
                                                                                                                                "<strong style=\"font-size:20px; \">Total de Faturas: R$"
                                                                                                                                        + Info.formataSaldo(
                                                                                                                                                Info.formataDecimal(
                                                                                                                                                        objFaturaLancamento
                                                                                                                                                                .getTotalFaturas()))
                                                                                                                                        + "</strong>");
                                                                                                                objFaturaLancamento
                                                                                                                        .setSaldo(
                                                                                                                                objFaturaLancamento
                                                                                                                                        .getTotalLancamentos()
                                                                                                                                        - objFaturaLancamento
                                                                                                                                                .getTotalFaturas());
                                                                                                                if (objFaturaLancamento
                                                                                                                        .getSaldo() == 0) {
                                                                                                                    labelSaldo
                                                                                                                            .redraw();
                                                                                                                    labelSaldo
                                                                                                                            .setContents(
                                                                                                                                    "<strong style=\"font-size:25px; \">Saldo Atual: R$00,00\n</strong>");
                                                                                                                } else if (objFaturaLancamento
                                                                                                                        .getSaldo() > 0) {
                                                                                                                    labelSaldo
                                                                                                                            .redraw();
                                                                                                                    labelSaldo
                                                                                                                            .setContents(
                                                                                                                                    "<strong class=\"saldo-positivo\">Crdito Atual: R$"
                                                                                                                                            + Info.formataSaldo(
                                                                                                                                                    Info.formataDecimal(
                                                                                                                                                            objFaturaLancamento
                                                                                                                                                                    .getSaldo()))
                                                                                                                                            + "\n</strong>");
                                                                                                                } else {
                                                                                                                    labelSaldo
                                                                                                                            .redraw();
                                                                                                                    labelSaldo
                                                                                                                            .setContents(
                                                                                                                                    "<strong class=\"saldo-negativo\">Dbito Atual: R$"
                                                                                                                                            + Info.formataSaldo(
                                                                                                                                                    Info.formataDecimal(
                                                                                                                                                            objFaturaLancamento
                                                                                                                                                                    .getSaldo()))
                                                                                                                                            + "\n</strong>");
                                                                                                                }
                                                                                                            }
                                                                                                        });
                                                                                    }

                                                                                }
                                                                            });
                                                                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                                                        
                                                                }
                                                            }
                                                        });

                                            }
                                        });

                                janelaCarregando.addItem(mensagem);
                                janelaCarregando.setAnimateTime(1200);
                                janelaCarregando.animateHide(AnimationEffect.FADE);
                                contador = 100;
                                destroy();
                            }
                        } else {
                            contador = 0;
                        }

                    }
                }.schedule(50);
            }
        }

    });
    limpar.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            itemValor.setDefaultValue("");
            itemDataEhora.setValue(new Date(System.currentTimeMillis()));
            formNovoLancamento.focusInItem(itemValor);
        }
    });
    addItem(label);
    addItem(formNovoLancamento);
    addItem(labelListaFat);
    addItem(listaDeFaturas);
    addItem(saldoFaturasApagar);
    addItem(labelListaFatSelecionadas);
    addItem(faturasSelecionadas);
    addItem(hButoes);

}

From source file:com.automaster.client.ui.paineis.tabs.financeiro.TabConsultaFaturaLancamento.java

private void consultaCliente() {

    // Pega o cdigo da Unidade do Usurio Logado Cliente ou Funiconrio
    int codigoUnidade = Integer.parseInt((Info.usuarioLogado.get("codUnidadeCliente") == null)
            ? Info.usuarioLogado.get("codUnidadeFuncionario")
            : Info.usuarioLogado.get("codUnidadeCliente"));
    //final String nomeUnidade = (Info.usuarioLogado.get("nomeUnidadeCliente") == null) ? Info.usuarioLogado.get("nomeUnidadeFuncionario") : Info.usuarioLogado.get("nomeUnidadeCliente");
    if (formBusca.validate() && tipoBusca.getValueAsString().equalsIgnoreCase("1")) {
        //GWT.log("" + codigoUnidade);
        Info.dbService.buscarPorNomeCliente(buscaCliente.getValueAsString(), codigoUnidade,
                new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                    @Override/*from   w w  w . j a v  a  2  s .c o  m*/
                    public void onFailure(Throwable caught) {
                        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                    }

                    @Override
                    public void onSuccess(ArrayList<TreeMap<String, String>> result) {
                        if (result != null) {
                            ListGridField codigo = new ListGridField("codigo", "Cdigo");
                            codigo.setHidden(true);
                            ListGridField nome = new ListGridField("nome", "Nome");
                            ListGridField dataAdesao = new ListGridField("dataAdesao", "Data de Adeso");
                            ListGridField unidade = new ListGridField("unidade", "Unidade");
                            dataAdesao.setAlign(Alignment.CENTER);
                            final ListGrid clientes = new ListGrid();
                            clientes.setCanPickFields(false);
                            clientes.setFields(codigo, nome, dataAdesao, unidade);
                            clientes.setShowAllRecords(true);
                            clientes.setSelectionType(SelectionStyle.SINGLE);

                            for (TreeMap<String, String> cl : result) {
                                Record registros = new Record();
                                registros.setAttribute("codigo", cl.get("codCliente"));
                                registros.setAttribute("nome", cl.get("nome"));
                                registros.setAttribute("dataAdesao", DateTimeFormat.getShortDateFormat()
                                        .format(new Date(Long.parseLong(cl.get("dataAdesao")))));
                                registros.setAttribute("unidade", cl.get("nomeUnidade"));
                                clientes.addData(registros);
                            }
                            clientes.selectRecord(0, true);
                            final Window gridClientes = new Window();
                            gridClientes.setTitle("Lista de Clientes");
                            gridClientes.setWidth(500);
                            gridClientes.setHeight(300);
                            gridClientes.setShowMinimizeButton(false);
                            gridClientes.setIsModal(true);
                            gridClientes.setShowModalMask(true);
                            gridClientes.centerInPage();
                            gridClientes.setLayoutAlign(Alignment.CENTER);
                            gridClientes.addItem(clientes);
                            gridClientes.setAnimateTime(1200);
                            gridClientes.animateShow(AnimationEffect.FADE);
                            gridClientes.addCloseClickHandler(new CloseClickHandler() {

                                @Override
                                public void onCloseClick(CloseClickEvent event) {
                                    gridClientes.destroy();
                                }
                            });

                            clientes.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {

                                @Override
                                public void onRecordDoubleClick(RecordDoubleClickEvent event) {
                                    Record record = event.getRecord();
                                    int codigoCliente = Integer.parseInt(record.getAttribute("codigo"));
                                    buscarPorCodCliente(codigoCliente);
                                    gridClientes.destroy();
                                }

                            });
                        } else {
                            SC.say("Cliente no Cadastrado");
                            buscaCliente.clearValue();
                        }
                    }
                });

    } else if (formBusca.validate() && tipoBusca.getValueAsString().equalsIgnoreCase("2")) {
        Info.dbService.buscarPorCPF(buscaCliente.getValueAsString(), codigoUnidade,
                new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                    }

                    @Override
                    public void onSuccess(ArrayList<TreeMap<String, String>> pessoa) {
                        if (pessoa != null) {
                            ListGridField codigo = new ListGridField("codigo", "Cdigo");
                            codigo.setHidden(true);
                            ListGridField cpf = new ListGridField("cpf", "CPF");
                            cpf.setWidth(80);
                            ListGridField nome = new ListGridField("nome", "Nome");
                            nome.setWidth(180);
                            ListGridField dataAdesao = new ListGridField("dataAdesao", "Data de Adeso");
                            dataAdesao.setAlign(Alignment.CENTER);
                            ListGridField unidade = new ListGridField("unidade", "Unidade");
                            ListGrid clientes = new ListGrid();
                            clientes.setCanPickFields(false);
                            clientes.setFields(codigo, cpf, nome, dataAdesao, unidade);
                            clientes.setShowAllRecords(true);

                            for (TreeMap<String, String> cl : pessoa) {
                                Record registros = new Record();
                                registros.setAttribute("codigo", cl.get("codCliente"));
                                registros.setAttribute("cpf", Info.formataCPF(cl.get("cpf")));
                                registros.setAttribute("nome", cl.get("nome"));
                                registros.setAttribute("dataAdesao", DateTimeFormat.getShortDateFormat()
                                        .format(new Date(Long.parseLong(cl.get("dataAdesao")))));
                                registros.setAttribute("unidade", cl.get("nomeUnidade"));
                                clientes.addData(registros);
                            }
                            clientes.selectRecord(0, true);
                            final Window gridClientes = new Window();
                            gridClientes.setTitle("Lista de Clientes");
                            gridClientes.setWidth(500);
                            gridClientes.setHeight(300);
                            gridClientes.setShowMinimizeButton(false);
                            gridClientes.setIsModal(true);
                            gridClientes.setShowModalMask(true);
                            gridClientes.centerInPage();
                            gridClientes.setLayoutAlign(Alignment.CENTER);
                            gridClientes.addItem(clientes);
                            gridClientes.setAnimateTime(1200);
                            gridClientes.animateShow(AnimationEffect.FADE);
                            gridClientes.addCloseClickHandler(new CloseClickHandler() {

                                @Override
                                public void onCloseClick(CloseClickEvent event) {
                                    gridClientes.destroy();
                                }
                            });

                            clientes.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {

                                @Override
                                public void onRecordDoubleClick(RecordDoubleClickEvent event) {
                                    Record record = event.getRecord();
                                    int codigoCliente = Integer.parseInt(record.getAttribute("codigo"));
                                    buscarPorCodCliente(codigoCliente);
                                    gridClientes.destroy();
                                }

                            });
                        } else {
                            SC.say("Cliente no Cadastrado");
                            buscaCliente.clearValue();
                        }
                    }
                });
    } else if (formBusca.validate() && tipoBusca.getValueAsString().equalsIgnoreCase("3")) {
        Info.dbService.buscarPorCNPJ(buscaCliente.getValueAsString(), codigoUnidade,
                new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                    }

                    @Override
                    public void onSuccess(ArrayList<TreeMap<String, String>> empresa) {

                        if (empresa != null) {
                            ListGridField codigo = new ListGridField("codigo", "Cdigo");
                            codigo.setHidden(true);
                            ListGridField cnpj = new ListGridField("cnpj", "CNPJ");
                            cnpj.setWidth(110);
                            ListGridField nome = new ListGridField("nome", "Nome");
                            nome.setWidth(180);
                            ListGridField dataAdesao = new ListGridField("dataAdesao", "Data de Adeso");
                            dataAdesao.setAlign(Alignment.CENTER);
                            ListGridField unidade = new ListGridField("unidade", "Unidade");
                            ListGrid clientes = new ListGrid();
                            clientes.setCanPickFields(false);
                            clientes.setFields(codigo, cnpj, nome, dataAdesao, unidade);
                            clientes.setShowAllRecords(true);

                            for (TreeMap<String, String> emp : empresa) {
                                Record registros = new Record();
                                registros.setAttribute("codigo", emp.get("codCliente"));
                                registros.setAttribute("cnpj", Info.formataCNPJ(emp.get("cnpj")));
                                registros.setAttribute("nome", emp.get("nome"));
                                registros.setAttribute("dataAdesao", DateTimeFormat.getShortDateFormat()
                                        .format(new Date(Long.parseLong(emp.get("dataAdesao")))));
                                registros.setAttribute("unidade", emp.get("nomeUnidade"));
                                clientes.addData(registros);
                            }
                            clientes.selectRecord(0, true);
                            final Window gridClientes = new Window();
                            gridClientes.setTitle("Lista de Clientes");
                            gridClientes.setWidth(500);
                            gridClientes.setHeight(300);
                            gridClientes.setShowMinimizeButton(false);
                            gridClientes.setIsModal(true);
                            gridClientes.setShowModalMask(true);
                            gridClientes.centerInPage();
                            gridClientes.setLayoutAlign(Alignment.CENTER);
                            gridClientes.addItem(clientes);
                            gridClientes.setAnimateTime(1200);
                            gridClientes.animateShow(AnimationEffect.FADE);
                            gridClientes.addCloseClickHandler(new CloseClickHandler() {

                                @Override
                                public void onCloseClick(CloseClickEvent event) {
                                    gridClientes.destroy();
                                }
                            });

                            clientes.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {

                                @Override
                                public void onRecordDoubleClick(RecordDoubleClickEvent event) {
                                    Record record = event.getRecord();
                                    int codigoCliente = Integer.parseInt(record.getAttribute("codigo"));
                                    buscarPorCodCliente(codigoCliente);
                                    gridClientes.destroy();
                                }

                            });
                        } else {
                            SC.say("Cliente no Cadastrado");
                            buscaCliente.clearValue();
                        }
                    }
                });
    }
}

From source file:com.automaster.client.ui.paineis.tabs.financeiro.TabConsultaFaturaLancamento.java

private void buscarPorCodCliente(final int codCliente) {

    Info.dbService.buscarPorCodCliente(codCliente,
            new AsyncCallback<TreeMap<String, ArrayList<TreeMap<String, String>>>>() {

                @Override/*from www .  ja  v a 2s.co  m*/
                public void onFailure(Throwable caught) {
                    //GWT.log(caught.getMessage());
                    throw new UnsupportedOperationException("Not supported yet..........................."); //To change body of generated methods, choose Tools | Templates.
                }

                @Override
                public void onSuccess(TreeMap<String, ArrayList<TreeMap<String, String>>> dadosCliente) {
                    if (dadosCliente != null) {
                        ArrayList<TreeMap<String, String>> clienteAuxiliar = dadosCliente
                                .get(dadosCliente.firstKey());
                        if (!cliente.getRecordList().isEmpty()) {
                            cliente.selectAllRecords();
                            cliente.removeSelectedData();
                        }
                        clienteCod = Integer.parseInt(clienteAuxiliar.get(0).get("codCliente"));
                        addImg.setDisabled(false);
                        addFat.setDisabled(false);
                        Record regCliente = new Record();
                        regCliente.setAttribute("codigo", clienteAuxiliar.get(0).get("codCliente"));
                        regCliente.setAttribute("nome", clienteAuxiliar.get(0).get("nomeCliente"));
                        regCliente.setAttribute("dataAdesao", DateTimeFormat.getShortDateFormat()
                                .format(new Date(Long.parseLong(clienteAuxiliar.get(0).get("dataAdesao")))));
                        regCliente.setAttribute("unidade", clienteAuxiliar.get(0).get("nomeUnidade"));

                        codigo.setHidden(true);

                        if (clienteAuxiliar.get(0).get("cpf") == null) {
                            regCliente.setAttribute("cnpj",
                                    Info.formataCNPJ(clienteAuxiliar.get(0).get("cnpj")));
                            regCliente.setAttribute("dataAbert", DateTimeFormat.getShortDateFormat().format(
                                    new Date(Long.parseLong(clienteAuxiliar.get(0).get("dataAbertura")))));
                            cliente.setFields(nome, cnpj, dataAbert, dataAdesao, unidade, codigo);
                        } else {
                            regCliente.setAttribute("cpf", Info.formataCPF(clienteAuxiliar.get(0).get("cpf")));
                            regCliente.setAttribute("dataNasc", DateTimeFormat.getShortDateFormat()
                                    .format(new Date(Long.parseLong(clienteAuxiliar.get(0).get("dataNasc")))));
                            cliente.setFields(nome, cpf, dataNasc, dataAdesao, unidade, codigo);
                        }
                        cliente.addData(regCliente);

                        if (!lancamentos.getRecordList().isEmpty()) {
                            lancamentos.selectAllRecords();
                            lancamentos.removeSelectedData();
                            labelLancamentos.redraw();
                            labelLancamentos.setContents(
                                    "<strong style=\"font-size:20px; \">Total de Lanamentos pendentes: R$00,00</strong>");
                            totalLancamentos = 0;
                        }
                        TreeMap<String, String> lancamentoAuxiliar = new TreeMap<String, String>();
                        for (TreeMap<String, String> lanc : clienteAuxiliar) {
                            if (clienteAuxiliar.get(0).get("codLancamento") != null
                                    && lancamentoAuxiliar.get(lanc.get("codLancamento")) == null) {
                                Record regLanc = new Record();
                                regLanc.setAttribute("codCliente", lanc.get("codCliente"));
                                regLanc.setAttribute("codigo", lanc.get("codLancamento"));
                                regLanc.setAttribute("data", DateTimeFormat.getShortDateTimeFormat()
                                        .format(new Date(Long.parseLong(lanc.get("dataLancamento"))), null));
                                regLanc.setAttribute("valor", "R$"
                                        + Info.formataValor(Float.parseFloat(lanc.get("valorLancamento"))));
                                lancamentos.addData(regLanc);
                                lancamentoAuxiliar.put(lanc.get("codLancamento"), lanc.get("codLancamento"));
                            }
                        }

                        ///************************************************************************************************************************************************************////
                        Info.dbService.buscarFaturaPorCliente(codCliente,
                                new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                                    @Override
                                    public void onFailure(Throwable caught) {
                                        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                    }

                                    @Override
                                    public void onSuccess(ArrayList<TreeMap<String, String>> faturasCliente) {
                                        arrayFaturasBD.clear();
                                        if (!faturas.getRecordList().isEmpty()) {
                                            faturas.selectAllRecords();
                                            faturas.removeSelectedData();
                                            labelFatura.redraw();
                                            labelFatura.setContents(
                                                    "<strong style=\"font-size:20px; \">Total de Faturas a pagar: R$00,00</strong>");
                                            totalFaturas = 0;
                                        }
                                        //////////////////////////////////////////////////////////////////****************************************\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
                                        Date dataAtual = new Date(System.currentTimeMillis());
                                        long diaAtual = dataAtual.getTime();
                                        long diferencaDeDatas = 0;
                                        long diaVencimento = 0;

                                        TreeMap<String, String> faturaAuxiliar = new TreeMap<String, String>();
                                        if (faturasCliente != null) {
                                            for (TreeMap<String, String> fats : faturasCliente) {
                                                if (faturasCliente.get(0).get("codFatura") != null
                                                        && faturaAuxiliar.get(fats.get("codFatura")) == null) {
                                                    Date dataDeVencimento = new Date(
                                                            Long.parseLong(fats.get("dataVencimento")));
                                                    diaVencimento = dataDeVencimento.getTime();
                                                    diferencaDeDatas = diaAtual - diaVencimento;
                                                    TreeMap<String, String> faturaBD = new TreeMap<String, String>();
                                                    faturaBD.put("codFatura", fats.get("codFatura"));
                                                    faturaBD.put("codCliente", fats.get("codCliente"));
                                                    faturaBD.put("dataVencimento", fats.get("dataVencimento"));
                                                    faturaBD.put("valor", String.valueOf(Info.formataSaldo(
                                                            Double.parseDouble(fats.get("valor")))));
                                                    faturaBD.put("estado", fats.get("estado"));
                                                    faturaBD.put("valorPago",
                                                            (fats.get("totalLancamentos") == null)
                                                                    ? String.valueOf(Info.formataSaldo(0))
                                                                    : String.valueOf(Info.formataSaldo(
                                                                            Double.parseDouble(fats.get(
                                                                                    "totalLancamentos")))));
                                                    faturaBD.put("mesReferencia", fats.get("mes"));
                                                    faturaBD.put("count", "0");
                                                    //GWT.log("" + fats.get("valorApagar"));
                                                    double totalPago = (fats.get("totalLancamentos") == null)
                                                            ? 0
                                                            : (Double
                                                                    .parseDouble(fats.get("totalLancamentos")));
                                                    //GWT.log("diferencaDeDatas: "+diferencaDeDatas);
                                                    if (diferencaDeDatas <= 0) {
                                                        double valor = Double.parseDouble(fats.get("valor"));
                                                        double valorAtualFatura = (totalPago == 0)
                                                                ? Info.formataDecimal(valor)
                                                                : Info.formataDecimal(
                                                                        Double.parseDouble(fats.get("valor"))
                                                                                - (totalPago));
                                                        faturaBD.put("jurosEmulta", String.valueOf(
                                                                Info.formataSaldo(Double.parseDouble("0"))));
                                                        faturaBD.put("valorApagar",
                                                                String.valueOf(Info.formataSaldo(Info
                                                                        .formataDecimal((valorAtualFatura)))));
                                                        faturaBD.put("valorTotal", String.valueOf(
                                                                Info.formataSaldo(Info.formataDecimal(Double
                                                                        .parseDouble(fats.get("valor"))))));
                                                        diferencaDeDatas = 0;
                                                    } else if (diferencaDeDatas > 0
                                                            && diferencaDeDatas < 86400000) {
                                                        double valor = Double.parseDouble(fats.get("valor"));
                                                        double valorAtualFatura = (totalPago == 0)
                                                                ? Info.formataDecimal(valor) + (valor * multa)
                                                                : Info.formataDecimal(
                                                                        Double.parseDouble(fats.get("valor"))
                                                                                - (totalPago)
                                                                                + (valor * multa));
                                                        faturaBD.put("jurosEmulta",
                                                                String.valueOf(Info.formataSaldo(
                                                                        (Info.formataDecimal(valor * multa)))));
                                                        faturaBD.put("valorApagar", String
                                                                .valueOf(Info.formataSaldo(valorAtualFatura)));
                                                        faturaBD.put("valorTotal", String.valueOf(
                                                                Info.formataSaldo(Info.formataDecimal(Double
                                                                        .parseDouble(fats.get("valor"))
                                                                        + ((Double
                                                                                .parseDouble(fats.get("valor"))
                                                                                * multa))))));
                                                        diferencaDeDatas = 0;
                                                    } else if (diferencaDeDatas > 86400000) {
                                                        double valor = Double.parseDouble(fats.get("valor"));
                                                        double valorAtualFatura = (totalPago == 0)
                                                                ? Info.formataDecimal(valor) + (valor * multa)
                                                                        + ((diferencaDeDatas / 86400000)
                                                                                * (juros * valor))
                                                                : Info.formataDecimal(
                                                                        Double.parseDouble(fats.get("valor"))
                                                                                - (totalPago) + (valor * multa)
                                                                                + ((diferencaDeDatas / 86400000)
                                                                                        * (juros * valor)));
                                                        faturaBD.put("jurosEmulta",
                                                                String.valueOf(Info.formataSaldo(
                                                                        Info.formataDecimal((valor * multa)
                                                                                + ((diferencaDeDatas / 86400000)
                                                                                        * (juros * valor))))));
                                                        faturaBD.put("valorApagar", String
                                                                .valueOf(Info.formataSaldo(valorAtualFatura)));
                                                        faturaBD.put("valorTotal", String.valueOf(
                                                                Info.formataSaldo(Info.formataDecimal(Double
                                                                        .parseDouble(fats.get("valor"))
                                                                        + ((Double.parseDouble(
                                                                                fats.get("valor")) * multa))
                                                                        + ((diferencaDeDatas / 86400000)
                                                                                * (juros * Double
                                                                                        .parseDouble(fats.get(
                                                                                                "valor"))))))));
                                                        diferencaDeDatas = 0;
                                                    }
                                                    arrayFaturasBD.add(faturaBD);
                                                    faturaAuxiliar.put(fats.get("codFatura"),
                                                            fats.get("codFatura"));
                                                }
                                            }
                                        }
                                        setTotalLancamentos(0);
                                        setTotalFaturas(0);
                                        setSaldo(0);
                                        ////////////////////////////////////////////////////////////////*******************************************\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\            
                                        for (TreeMap<String, String> fats : arrayFaturasBD) {
                                            Record fat = new Record();
                                            fat.setAttribute("codigo", fats.get("codFatura"));
                                            fat.setAttribute("codCliente", fats.get("codCliente"));
                                            fat.setAttribute("dataFatura",
                                                    DateTimeFormat.getShortDateFormat().format(new Date(
                                                            Long.parseLong(fats.get("dataVencimento")))));
                                            fat.setAttribute("valor", fats.get("valor"));
                                            fat.setAttribute("estado",
                                                    (Boolean.parseBoolean(fats.get("estado")) == false)
                                                            ? "<nbr class=\negativo\"> Em aberto</nbr>"
                                                            : "<nbr class=\"positivo\">Quitada</nbr>");
                                            fat.setAttribute("valorPago", fats.get("valorPago"));
                                            fat.setAttribute("mesReferencia", fats.get("mesReferencia"));
                                            fat.setAttribute("valorApagar",
                                                    (Boolean.parseBoolean(fats.get("estado")) == false)
                                                            ? fats.get("valorApagar")
                                                            : Info.formataSaldo(0));
                                            fat.setAttribute("valorTotal", fats.get("valorTotal"));
                                            fat.setAttribute("jurosEmulta",
                                                    (Boolean.parseBoolean(fats.get("estado")) == false)
                                                            ? fats.get("jurosEmulta")
                                                            : Info.formataSaldo(0));
                                            fat.setAttribute("count", Integer.parseInt(fats.get("count")));
                                            faturas.addData(fat);
                                            setTotalFaturas(getTotalFaturas() + ((Double
                                                    .parseDouble(fat.getAttributeAsString("valorPago")
                                                            .replaceAll("\\.", "").replaceAll(",", ".")) > 0
                                                    && Boolean.parseBoolean(fats.get("estado")) == true)
                                                            ? Double.parseDouble(
                                                                    fat.getAttributeAsString("valorPago")
                                                                            .replaceAll(
                                                                                    "\\.", "")
                                                                            .replaceAll(",", "."))
                                                            : (Double.parseDouble(fat
                                                                    .getAttributeAsString("valorPago")
                                                                    .replaceAll("\\.", "").replaceAll(",", "."))
                                                                    + Double.parseDouble(fat
                                                                            .getAttributeAsString("valorApagar")
                                                                            .replaceAll("\\.", "")
                                                                            .replaceAll(",", ".")))));
                                            //GWT.log("getTotalFaturas() 1 : "+Double.parseDouble(fat.getAttributeAsString("valorApagar").replaceAll("\\.", "").replaceAll(",", ".")));
                                            //GWT.log("getTotalFaturas(): "+getTotalFaturas());
                                        }
                                        ////////////////////////////////////////////////////////****************************************************////////////////////////////////////
                                        Info.dbService.buscarTotalLancamentos(codCliente,
                                                new AsyncCallback<Double>() {

                                                    @Override
                                                    public void onFailure(Throwable caught) {
                                                        throw new UnsupportedOperationException(
                                                                "Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                                    }

                                                    @Override
                                                    public void onSuccess(Double totLanc) {
                                                        setTotalLancamentos(totLanc);
                                                        labelLancamentos.redraw();
                                                        labelLancamentos.setContents(
                                                                "<strong style=\"font-size:20px; \">Total de Lanamentos: R$"
                                                                        + Info.formataSaldo(Info.formataDecimal(
                                                                                getTotalLancamentos()))
                                                                        + "</strong>");
                                                        labelFatura.redraw();
                                                        labelFatura.setContents(
                                                                "<strong style=\"font-size:20px; \">Total de Faturas: R$"
                                                                        + Info.formataSaldo(Info.formataDecimal(
                                                                                getTotalFaturas()))
                                                                        + "</strong>");
                                                        setSaldo(getTotalLancamentos() - getTotalFaturas());
                                                        if (getSaldo() == 0) {
                                                            labelSaldo.redraw();
                                                            labelSaldo.setContents(
                                                                    "<strong style=\"font-size:25px; \">Saldo Atual: R$00,00\n</strong>");
                                                        } else if (getSaldo() > 0) {
                                                            labelSaldo.redraw();
                                                            labelSaldo.setContents(
                                                                    "<strong class=\"saldo-positivo\">Crdito Atual: R$"
                                                                            + Info.formataSaldo(Info
                                                                                    .formataDecimal(getSaldo()))
                                                                            + "\n</strong>");
                                                        } else {
                                                            labelSaldo.redraw();
                                                            labelSaldo.setContents(
                                                                    "<strong class=\"saldo-negativo\">Dbito Atual: R$"
                                                                            + Info.formataSaldo(Info
                                                                                    .formataDecimal(getSaldo()))
                                                                            + "\n</strong>");
                                                        }

                                                    }
                                                });
                                    }
                                });

                    } else {
                        SC.warn("Erro ao Consultar Cliente");
                    }

                }
            });

}

From source file:com.automaster.client.ui.paineis.tabs.TabBuscarCliente.java

public TabBuscarCliente() {
    //setanto o titulo da aba TAB 
    setTitle("Buscar Cliente");
    //criando o Vlayout que ir armazenar o painelNovoCliente
    HLayout painelPai = new HLayout();
    painelPai.setWidth100();/*  ww w.  j  av a2 s  .  c  o m*/
    painelPai.setHeight100();
    painelPai.setAlign(Alignment.CENTER);
    //Criando o painel que ir armazenar to tab, sections e butoes
    VLayout painelBuscaCliente = new VLayout();
    painelBuscaCliente.setMembersMargin(15);
    painelBuscaCliente.setWidth(1000);
    painelBuscaCliente.setDefaultLayoutAlign(Alignment.CENTER);
    //criando o painel que ir armazenar os botoes cadastrar e limpar
    editCliente.setDisabled(true);
    editCliente.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            EditarCliente editarCliente = new EditarCliente(getClienteEdicao(), enderecos, telefones, emails,
                    logins, dadosCliente);
            editarCliente.setAnimateTime(1200);
            editarCliente.animateShow(AnimationEffect.FADE);
        }
    });
    HLayout painelBotoesCliente = new HLayout();
    painelBotoesCliente.setMargin(5);
    painelBotoesCliente.setMembersMargin(10);
    painelBotoesCliente.setHeight(40);
    painelBotoesCliente.setAlign(Alignment.RIGHT);
    painelBotoesCliente.addMember(editCliente);

    formBusca.setWidth(600);
    formBusca.setAutoFocus(true);
    formBusca.setLayoutAlign(Alignment.CENTER);

    tipoBusca.setTitle("Tipo de Busca");
    LinkedHashMap<String, String> tp = new LinkedHashMap<>();
    tp.put("1", "Nome do Cliente");
    tp.put("2", "CPF");
    tp.put("3", "CNPJ");
    tipoBusca.setValueMap(tp);
    tipoBusca.setRequired(true);
    tipoBusca.setValue("1");
    //tipoBusca.setShowTitle(false);
    tipoBusca.setAlign(Alignment.CENTER);
    tipoBusca.setTooltip("Buscar Clientes");
    tipoBusca.setWidth(350);
    tipoBusca.setVertical(false);

    buscaCliente.setName("Digite");
    FormItemIcon icon = new FormItemIcon();
    icon.setSrc("[SKIN]actions/view.png");
    icon.setName("buscar");
    buscaCliente.setTooltip("Buscar Cliente");
    buscaCliente.setIcons(icon);
    buscaCliente.setKeyPressFilter("[a-zA-Z? 0-9]");
    buscaCliente.setAlign(Alignment.CENTER);
    final LengthRangeValidator tamanhoTextItem = new LengthRangeValidator();
    tamanhoTextItem.setMin(3);
    buscaCliente.setValidators(tamanhoTextItem);
    buscaCliente.setRequired(true);
    buscaCliente.setWidth(500);
    buscaCliente.setCharacterCasing(CharacterCasing.UPPER);

    tipoBusca.addChangedHandler(new ChangedHandler() {

        @Override
        public void onChanged(ChangedEvent event) {
            String groupItem = (String) event.getValue();
            if (groupItem.equals("1")) {
                buscaCliente.redraw();
                try {
                    buscaCliente.setMask(null);
                    buscaCliente.setKeyPressFilter("[a-zA-Z? 0-9]");
                    tamanhoTextItem.setMin(3);
                } catch (Exception e) {
                    buscaCliente.setValue("");
                    tamanhoTextItem.setMin(3);
                    buscaCliente.setKeyPressFilter("[a-zA-Z? 0-9]");
                    formBusca.focusInItem(buscaCliente);
                }
                buscaCliente.setMaskPromptChar(" ");
            } else if (groupItem.equals("2")) {
                buscaCliente.redraw();
                tamanhoTextItem.setMin(1);
                buscaCliente.setMask("###.###.###-##");
                buscaCliente.setMaskPromptChar("_");
                formBusca.focusInItem(buscaCliente);

            } else if (groupItem.equals("3")) {
                buscaCliente.redraw();
                tamanhoTextItem.setMin(1);
                buscaCliente.setMask("##.###.###/####-##");
                buscaCliente.setMaskPromptChar("_");
                formBusca.focusInItem(buscaCliente);
            }
        }
    });

    formBusca.addDrawHandler(new DrawHandler() {
        @Override
        public void onDraw(DrawEvent event) {
            formBusca.focusInItem(buscaCliente);
        }
    });

    formBusca.setFields(tipoBusca, buscaCliente);

    buscaCliente.addIconClickHandler(new IconClickHandler() {

        @Override
        public void onIconClick(IconClickEvent event) {
            consultaCliente();
        }
    });

    buscaCliente.addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent event) {
            if (event.getKeyName().equals("Enter")) {
                consultaCliente();
            }
        }
    });

    final SectionStackSection formSection = new SectionStackSection();
    formSection.setTitle("Buscar Clientes");
    formSection.setItems(formBusca);
    formSection.setExpanded(true);

    final DynamicForm formCliente = new DynamicForm();
    formCliente.setWidth(600);
    formCliente.setAutoFocus(true);
    formCliente.setLayoutAlign(Alignment.CENTER);

    codigo.setHidden(true);

    dadosCliente.setHeight(60);
    dadosCliente.setCanPickFields(false);
    final ListGridField codigoEnd = new ListGridField("codigo", "Cdigo");
    codigoEnd.setHidden(true);
    final ListGridField descricaoEnd = new ListGridField("descricao", "Descrio");
    descricaoEnd.setWidth(160);
    final ListGridField logradouro = new ListGridField("logradouro", "Logradouro");
    logradouro.setWidth(200);
    final ListGridField numeroEnd = new ListGridField("numero", "N");
    numeroEnd.setWidth(40);
    final ListGridField bairroEnd = new ListGridField("bairro", "Bairro");
    bairroEnd.setWidth(110);
    final ListGridField cep = new ListGridField("cep", "CEP");
    cep.setWidth(60);
    final ListGridField uf = new ListGridField("estado", "UF");
    uf.setWidth(30);
    final ListGridField estadoCod = new ListGridField("estadoCod", "EstadoCod");
    estadoCod.setHidden(true);
    final ListGridField cidade = new ListGridField("cidade", "Cidade");
    cidade.setWidth(100);
    final ListGridField cidadeCod = new ListGridField("cidadeCod", "CidadeCod");
    cidadeCod.setHidden(true);
    final ListGridField referenciaEnd = new ListGridField("referencia", "Referncia");
    enderecos.setHeight(100);
    enderecos.setFields(codigoEnd, descricaoEnd, logradouro, numeroEnd, bairroEnd, cep, cidade, cidadeCod, uf,
            estadoCod, referenciaEnd);
    enderecos.setCanPickFields(false);

    final ListGridField codTel = new ListGridField("codTelefone", "cdigo");
    codTel.setHidden(true);
    final ListGridField descricaoTel = new ListGridField("descricao", "Descrio dos Telefones");
    final ListGridField numeroTel = new ListGridField("numero", "Nmeros");

    telefones.setHeight(90);
    telefones.setFields(codTel, descricaoTel, numeroTel);
    telefones.setCanPickFields(false);

    final ListGridField codEmail = new ListGridField("codigo", "Cdigo");
    codEmail.setHidden(true);
    final ListGridField descricaoEmail = new ListGridField("descricao", "Descrio dos Emails");
    final ListGridField email = new ListGridField("email", "Email");

    emails.setHeight(75);
    emails.setFields(codEmail, descricaoEmail, email);
    emails.setCanPickFields(false);

    final ListGridField codUsuario = new ListGridField("codigo", "Cdigo");
    codUsuario.setHidden(true);
    final ListGridField usuario = new ListGridField("usuario", "Usurios");
    final ListGridField senha = new ListGridField("senha", "Senhas");
    final ListGridField statusCod = new ListGridField("statusCod", "Status");
    statusCod.setHidden(true);
    final ListGridField status = new ListGridField("status", "Status");
    final ListGridField codGrupo = new ListGridField("codGrupo", "cdigoGrupo");
    codGrupo.setHidden(true);
    final ListGridField grupo = new ListGridField("grupo", "grupo");
    final ListGridField reset = new ListGridField("resetUsuario", "Reset");
    //reset.setHidden(true);
    logins.setHeight(75);
    logins.setFields(codUsuario, usuario, senha, statusCod, status, codGrupo, grupo, reset);
    logins.setCanPickFields(false);

    ListGridField codVeic = new ListGridField("codigo", "Cdigo");
    codVeic.setHidden(true);
    ListGridField placaVeic = new ListGridField("placa", "Placas");
    placaVeic.setAlign(Alignment.CENTER);
    placaVeic.setWidth(80);

    veicPlacas.setHeight(310);
    veicPlacas.setWidth(100);
    veicPlacas.setCanPickFields(true);
    veicPlacas.setAutoFetchData(true);
    veicPlacas.setShowFilterEditor(true);
    veicPlacas.setTooltip("Lista de Veculos");
    veicPlacas.setFilterOnKeypress(true);
    veicPlacas.setSelectionType(SelectionStyle.SINGLE);
    veicPlacas.addSelectionUpdatedHandler(new SelectionUpdatedHandler() {

        @Override
        public void onSelectionUpdated(SelectionUpdatedEvent event) {
            String placaVeiculo = veicPlacas.getSelectedRecord().getAttribute("placa");

            if (placaClicada.get(placaVeiculo) == null) {
                editVeiculo.setDisabled(false);
                placaClicada.put(placaVeiculo, placaVeiculo);
            }
            String infoVeiculo = "";
            String table2 = "";
            String table3 = "";
            String cabecalhoPadraoLig = "";
            dadosVeiculo = veiculos.get(placaVeiculo);
            placaVeiculoCopia = placaVeiculo;
            infoVeiculo = "<table width=\"0\" border=\"1\" bordercolor=\"#CCCCCC\">\n"
                    + "  <tr align=\"center\">\n"
                    + "    <td><table width=\"840\" height=\"350\" border=\"0\">\n" + "<tr align=\"center\">\n"
                    + "    <td colspan=\"6\" align=\"center\" bgcolor=\"#CCCCCC\"><strong>INFORMAES DO VE?CULO</strong></td>\n"
                    + "  </tr>\n" + "  <tr align=\"center\">\n"
                    + "    <td width=\"111\"><strong>Placa:</strong></td>\n" + "    \n"
                    + "    <td ><strong>Modelo: </strong></td>\n" + "    <td ><strong>Ano:</strong></td>\n"
                    + "    <td width=\"215\"><strong>Cor: </strong></td>\n"
                    + "    <td width=\"160\"><strong>Fabricante</strong></td>\n"
                    + "    <td width=\"150\" bgcolor=\"#CCCCCC\"><strong>Tipo de Cobrana:</strong></td>"
                    + "  </tr>\n" + "  <tr align=\"center\">\n" + "    <td height=\"24\">"
                    + dadosVeiculo.get(0).get("placaVeiculo") + "</td>\n" + "    <td >"
                    + dadosVeiculo.get(0).get("modelo") + "</td>\n" + "    <td >"
                    + dadosVeiculo.get(0).get("ano") + "</td>\n" + "    <td>" + dadosVeiculo.get(0).get("cor")
                    + "</td>\n" + "    <td>" + dadosVeiculo.get(0).get("fabricante") + "</td>\n"
                    + "    <td bgcolor=\"#CCCCCC\">" + dadosVeiculo.get(0).get("descricaoTc") + "</td>"
                    + "  </tr>\n" + "  <tr align=\"center\">\n"
                    + "    <td width=\"111\"><strong>Chassi:</strong></td>\n"
                    + "    <td width=\"198\"><strong>Data de Adeso</strong></td>\n"
                    + "    <td><strong>Cidade:</strong></td>\n"
                    + "    <td width=\"215\"><strong>Estado</strong>:</td>\n"
                    + "    <td width=\"160\"><strong>Veculo Ativo?</strong></td>\n"
                    + "    <td width=\"150\" bgcolor=\"#CCCCCC\"><strong>N de Parcelas:</strong></td>"
                    + "  </tr>\n" + "  <tr align=\"center\">\n" + "    <td>" + dadosVeiculo.get(0).get("chassi")
                    + "</td>\n" + "    <td>"
                    + DateTimeFormat.getShortDateFormat()
                            .format(new Date(Long.parseLong(dadosVeiculo.get(0).get("dataAdesao"))))
                    + "</td>\n" + "    <td>" + dadosVeiculo.get(0).get("cidadeNome") + "</td>\n" + "    <td>"
                    + dadosVeiculo.get(0).get("estadoNome") + "</td>\n" + "    <td>"
                    + ((dadosVeiculo.get(0).get("ativoVeic").equalsIgnoreCase("t")) ? "Sim" : "No")
                    + "</td>\n" + "    <td bgcolor=\"#CCCCCC\"> 0" + dadosVeiculo.get(0).get("numeroParcela")
                    + "</td>";
            cabecalhoPadraoLig = "  </tr>\n" + "   <tr align=\"center\">\n"
                    + "    <td width=\"111\"><strong>Indicado Por:</strong></td>\n"
                    + "    <td width=\"198\"><strong>Plano:</strong></td>\n"
                    + "    <td><strong>Equipamento:</strong></td>\n"
                    + "    <td width=\"215\"><strong>Instalador</strong></td>\n"
                    + "    <td width=\"160\"><strong>Desconto:</strong></td>\n"
                    + "    <td width=\"150\" bgcolor=\"#CCCCCC\"><strong>Valor:</strong></td>" + "  </tr>\n"
                    + "  <tr align=\"center\">\n" + "    <td>"
                    + ((dadosVeiculo.get(0).get("placaIndicador") == null) ? "Sem informao"
                            : dadosVeiculo.get(0).get("placaIndicador"))
                    + "</td>\n" + "    <td>" + dadosVeiculo.get(0).get("descricaoPlano") + "</td>\n"
                    + "    <td>"
                    + ((dadosVeiculo.get(0).get("codEquipamento") == null) ? "Sem equipamento"
                            : dadosVeiculo.get(0).get("idEquipamento") + " "
                                    + dadosVeiculo.get(0).get("fabricanteMod") + " "
                                    + dadosVeiculo.get(0).get("descricaoModelo"))
                    + "</td>\n" + "    <td>" + dadosVeiculo.get(0).get("nomeInstalador") + "</td>\n"
                    + "    <td>R$"
                    + String.valueOf(Info.formataValor(Float.parseFloat(dadosVeiculo.get(0).get("desconto"))))
                    + "</td>\n" + "    <td bgcolor=\"#CCCCCC\" style=\"font-size:14px;\">R$"
                    + String.valueOf(
                            Info.formataValor(Float.parseFloat(dadosVeiculo.get(0).get("valorParcela"))))
                    + "</td>\n" + "  </tr>\n" + "  <tr align=\"center\">\n"
                    + "    <td colspan=\"6\" style=\"font-size:16px;\"><strong>Valor da Mensalidade</strong>:</td>\n"
                    + "  </tr>\n" + "  <tr align=\"center\">\n"
                    + "    <td colspan=\"6\" style=\"font-size:16px;\"><strong>R$"
                    + String.valueOf(Info.formataValor(Float.parseFloat(dadosVeiculo.get(0).get("valorPlano"))
                            - (Float.parseFloat(dadosVeiculo.get(0).get("desconto")))))
                    + "</strong></td>\n" + "  </tr>\n" + "  <tr align=\"center\">\n"
                    + "    <td colspan=\"6\" align=\"center\" bgcolor=\"#CCCCCC\"><strong>PADRO DE LIGAO</strong></td>\n"
                    + "  </tr>\n" + "  <tr align=\"center\">\n"
                    + "    <td width=\"111\"><strong>Cor do Fio:</strong></td>\n"
                    + "    <td width=\"198\"><strong>Sinal:</strong></td>\n"
                    + "    <td width=\"198\"><strong>Padro:</strong></td>\n"
                    + "    <td width=\"144\"><strong>Funo:</strong></td>\n"
                    + "    <td width=\"215\"><strong>Ativo:</strong></td>\n"
                    + "    <td colspan=\"2\"><strong>Descrio:</strong></td>\n" + "  </tr>\n";
            TreeMap<String, String> codVeiculos = new TreeMap<String, String>();
            //GWT.log("Dados Veculo: "+dadosVeiculo);
            for (TreeMap<String, String> padraoLig : dadosVeiculo) {
                if (padraoLig.get("codPad") != null && codVeiculos.get(padraoLig.get("codPad")) == null) {
                    //GWT.log("Linha 1 busca");
                    table2 = table2 + "<tr align=\"center\">\n" + "<td id=\"corFio\">"
                            + ((padraoLig.get("corFio") == null) ? "Sem informao" : padraoLig.get("corFio"))
                            + "</td>\n" + "<td id=\"corFio\">"
                            + ((padraoLig.get("sinalPad") == null) ? "Sem informao"
                                    : (padraoLig.get("sinalPad").equalsIgnoreCase("t")) ? "Positivo"
                                            : "Negativo")
                            + "</td>\n" + "<td id=\"corFio\">"
                            + ((padraoLig.get("padraoLd") == null) ? "Sem informao"
                                    : (padraoLig.get("padraoLd").equalsIgnoreCase("t")) ? "Ligado"
                                            : "Desligado")
                            + "</td>\n" + "<td id=\"corFio\">"
                            + ((padraoLig.get("funcaoPad") == null) ? "Sem informao"
                                    : (padraoLig.get("funcaoPad").equalsIgnoreCase("t")) ? "Entrada" : "Sada")
                            + "</td>\n" + "<td id=\"corFio\">"
                            + ((padraoLig.get("ativoPad") == null) ? "Sem informao"
                                    : (padraoLig.get("ativoPad").equalsIgnoreCase("t")) ? "Sim" : "No")
                            + "</td>\n" + "<td id=\"descPad\" colspan=\"2\">"
                            + ((padraoLig.get("descricaoPad") == null
                                    || padraoLig.get("descricaoPad").equalsIgnoreCase("")) ? "Sem informao"
                                            : padraoLig.get("descricaoPad"))
                            + "</td>\n</tr>\n";
                    //GWT.log("Linha 2 busca");
                    codVeiculos.put(padraoLig.get("codPad"), padraoLig.get("codPad"));
                }
            }
            //GWT.log("Linha 22 busca");
            String tablePad = "<tr>\n"
                    + "    <td colspan=\"6\" align=\"center\" bgcolor=\"#CCCCCC\"><strong>PESSOA AUTORIZADA</strong></td>\n"
                    + "  </tr>\n" + "  <tr align=\"center\">\n"
                    + "    <td colspan=\"2\"><strong>Nome:</strong></td>    \n"
                    + "    <td width=\"215\"><strong>Telefone:</strong></td>\n"
                    + "    <td width=\"180\" colspan=\"3\"><strong>Descrio:</strong></td>\n" + "  </tr>\n";
            //GWT.log("Linha 2222 busca");
            TreeMap<String, String> codPessoaAutorizada = new TreeMap<String, String>();
            for (TreeMap<String, String> pessoAutorizada : dadosVeiculo) {
                if (pessoAutorizada.get("codPes") != null
                        && codPessoaAutorizada.get(pessoAutorizada.get("codPes")) == null) {
                    //GWT.log("Linha 3 busca");
                    table3 = table3 + "  <tr align=\"center\">\n" + "    <td colspan=\"2\">"
                            + ((pessoAutorizada.get("nomePes") == null) ? "Sem informao"
                                    : pessoAutorizada.get("nomePes"))
                            + "</td>\n" + "    <td>"
                            + ((pessoAutorizada.get("telefonePes") == null) ? "Sem informao"
                                    : Info.formataTelefone(pessoAutorizada.get("telefonePes")))
                            + "</td>\n" + "    <td colspan=\"3\">"
                            + ((pessoAutorizada.get("descricaoPes") == null
                                    || pessoAutorizada.get("descricaoPes").equalsIgnoreCase(""))
                                            ? "Sem informao"
                                            : pessoAutorizada.get("descricaoPes"))
                            + "</td>\n" + "  </tr>\n";
                    //GWT.log("Linha 4 busca");
                    codPessoaAutorizada.put(pessoAutorizada.get("codPes"), pessoAutorizada.get("codPes"));
                }
            }
            String fechaTabela = "</table></td>\n" + "  </tr>\n" + "</table>";
            String veiculoFinal = infoVeiculo + cabecalhoPadraoLig + table2 + tablePad + table3 + fechaTabela;
            tabelaVeiculos.redraw();
            tabelaVeiculos.setContents(veiculoFinal);
        }
    });

    HLayout painelVeiculos = new HLayout();
    painelVeiculos.setMargin(10);
    painelVeiculos.setMembersMargin(10);
    painelVeiculos.setAlign(Alignment.CENTER);

    tabelaVeiculos.setWidth(870);
    tabelaVeiculos.setHeight(310);
    tabelaVeiculos.setContents(tabelaVazia);
    painelVeiculos.addMember(veicPlacas);
    painelVeiculos.addMember(tabelaVeiculos);

    HLayout infoClientes = new HLayout();
    infoClientes.setWidth(1000);
    infoClientes.setHeight(400);

    VLayout listGridInfoClientes = new VLayout();
    listGridInfoClientes.setWidth(650);
    listGridInfoClientes.setHeight(400);
    listGridInfoClientes.addMember(dadosCliente);
    listGridInfoClientes.addMember(enderecos);
    listGridInfoClientes.addMember(telefones);
    listGridInfoClientes.addMember(emails);
    listGridInfoClientes.addMember(logins);

    ListGridField codigoLancamento = new ListGridField("codigo", "Cdigo");
    codigoLancamento.setHidden(true);
    ListGridField dataLanc = new ListGridField("data", "Data e Hora");
    dataLanc.setAlign(Alignment.CENTER);
    dataLanc.setWidth(120);
    ListGridField valorLanc = new ListGridField("valor", "Valor");
    valorLanc.setAlign(Alignment.CENTER);
    ListGridField estadoLanc = new ListGridField("estado", "Estado");
    estadoLanc.setAlign(Alignment.CENTER);
    ListGridField excluir = new ListGridField("excluir", "Excluir");
    excluir.setAlign(Alignment.CENTER);
    excluir.setWidth(40);

    lancamento.setCanPickFields(false);
    lancamento.setFields(codigoLancamento, dataLanc, valorLanc, estadoLanc, excluir);
    lancamento.setShowAllRecords(true);
    lancamento.setShowRecordComponents(true);
    lancamento.setShowRecordComponentsByCell(true);
    lancamento.setShowAllRecords(true);
    lancamento.setCanResizeFields(true);

    addLancamento.setSrc("[SKIN]actions/add.png");
    addLancamento.setSize(16);
    addLancamento.setShowFocused(false);
    addLancamento.setShowRollOver(false);
    addLancamento.setShowDown(false);
    addLancamento.setTooltip("Adicionar lanamento");
    addLancamento.setDisabled(true);

    final SectionStackSection lancamentoSection = new SectionStackSection();
    lancamentoSection.setTitle("<center>Lanamentos</center>");
    lancamentoSection.setControls(addLancamento);
    lancamentoSection.setItems(lancamento);
    lancamentoSection.setExpanded(true);

    addLancamento.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            NovoLancamento novoLancamento = new NovoLancamento(codigoCliente, lancamento, null, null, null,
                    null, null);
            novoLancamento.setAnimateTime(1200);
            novoLancamento.animateShow(AnimationEffect.FADE);
        }
    });

    final SectionStack lancamentosClientes = new SectionStack();
    lancamentosClientes.setSections(lancamentoSection);
    lancamentosClientes.setVisibilityMode(VisibilityMode.MULTIPLE);
    lancamentosClientes.setAnimateSections(true);
    lancamentosClientes.setWidth(350);
    lancamentosClientes.setHeight(400);
    lancamentosClientes.setOverflow(Overflow.VISIBLE);

    infoClientes.addMember(listGridInfoClientes);
    infoClientes.addMember(lancamentosClientes);

    final SectionStackSection clienteSection = new SectionStackSection();
    clienteSection.setTitle("<center>Dados do Cliente</center>");
    clienteSection.setItems(infoClientes, painelBotoesCliente);
    clienteSection.setExpanded(true);

    HLayout painelBotoesVeiculo = new HLayout();
    addVeiculo.setDisabled(true);
    addVeiculo.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            NovoVeiculo novoVeiculo = new NovoVeiculo(codigoCliente, nomeCliente);
            novoVeiculo.setAnimateTime(1200);
            novoVeiculo.animateShow(AnimationEffect.FADE);
        }
    });
    editVeiculo.setDisabled(true);
    editVeiculo.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            EditarVeiculo editarVeiculo = new EditarVeiculo(codigoCliente, nomeCliente, dadosVeiculo,
                    veicPlacas, tabelaVeiculos, veiculos, placaVeiculoCopia);
            editarVeiculo.setAnimateTime(1200);
            editarVeiculo.animateShow(AnimationEffect.FADE);
        }
    });
    painelBotoesVeiculo.setMargin(5);
    painelBotoesVeiculo.setMembersMargin(10);
    painelBotoesVeiculo.setHeight(40);
    painelBotoesVeiculo.setAlign(Alignment.RIGHT);
    painelBotoesVeiculo.addMember(addVeiculo);
    painelBotoesVeiculo.addMember(editVeiculo);

    final SectionStackSection veiculoSection = new SectionStackSection();
    veiculoSection.setTitle("<center>Dados do Veculo</center>");
    veiculoSection.setItems(painelVeiculos, painelBotoesVeiculo);
    veiculoSection.setExpanded(true);

    final SectionStack buscarClientes = new SectionStack();
    buscarClientes.setSections(formSection, clienteSection, veiculoSection);
    buscarClientes.setVisibilityMode(VisibilityMode.MULTIPLE);
    buscarClientes.setAnimateSections(true);
    buscarClientes.setWidth100();
    buscarClientes.setHeight100();
    buscarClientes.setOverflow(Overflow.VISIBLE);

    painelBuscaCliente.addMember(buscarClientes);
    painelPai.addMember(painelBuscaCliente);
    setPane(painelPai);

}

From source file:com.automaster.client.ui.paineis.tabs.TabBuscarCliente.java

private void consultaCliente() {

    // Pega o cdigo da Unidade do Usurio Logado Cliente ou Funiconrio
    int codigoUnidade = Integer.parseInt((Info.usuarioLogado.get("codUnidadeCliente") == null)
            ? Info.usuarioLogado.get("codUnidadeFuncionario")
            : Info.usuarioLogado.get("codUnidadeCliente"));
    //final String nomeUnidade = (Info.usuarioLogado.get("nomeUnidadeCliente") == null) ? Info.usuarioLogado.get("nomeUnidadeFuncionario") : Info.usuarioLogado.get("nomeUnidadeCliente");
    if (formBusca.validate() && tipoBusca.getValueAsString().equalsIgnoreCase("1")) {
        //GWT.log("" + codigoUnidade);
        Info.dbService.buscarPorNomeCliente(buscaCliente.getValueAsString(), codigoUnidade,
                new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                    @Override//from  ww  w .j a  va  2  s. co  m
                    public void onFailure(Throwable caught) {
                        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                    }

                    @Override
                    public void onSuccess(ArrayList<TreeMap<String, String>> result) {
                        if (result != null) {
                            ListGridField codigo = new ListGridField("codigo", "Cdigo");
                            codigo.setHidden(true);
                            ListGridField nome = new ListGridField("nome", "Nome");
                            ListGridField dataAdesao = new ListGridField("dataAdesao", "Data de Adeso");
                            ListGridField unidade = new ListGridField("unidade", "Unidade");
                            dataAdesao.setAlign(Alignment.CENTER);
                            final ListGrid clientes = new ListGrid();
                            clientes.setCanPickFields(false);
                            clientes.setFields(codigo, nome, dataAdesao, unidade);
                            clientes.setShowAllRecords(true);
                            clientes.setSelectionType(SelectionStyle.SINGLE);

                            for (TreeMap<String, String> cl : result) {
                                Record registros = new Record();
                                registros.setAttribute("codigo", cl.get("codCliente"));
                                registros.setAttribute("nome", cl.get("nome"));
                                registros.setAttribute("dataAdesao", DateTimeFormat.getShortDateFormat()
                                        .format(new Date(Long.parseLong(cl.get("dataAdesao")))));
                                registros.setAttribute("unidade", cl.get("nomeUnidade"));
                                clientes.addData(registros);
                            }
                            clientes.selectRecord(0, true);
                            //clientes.selectRecords(reg, false);
                            final Window gridClientes = new Window();
                            gridClientes.setTitle("Lista de Clientes");
                            gridClientes.setWidth(500);
                            gridClientes.setHeight(300);
                            gridClientes.setShowMinimizeButton(false);
                            gridClientes.setIsModal(true);
                            gridClientes.setShowModalMask(true);
                            gridClientes.centerInPage();
                            gridClientes.setLayoutAlign(Alignment.CENTER);
                            gridClientes.addItem(clientes);
                            gridClientes.setAnimateTime(1200);
                            gridClientes.animateShow(AnimationEffect.FADE);
                            gridClientes.addCloseClickHandler(new CloseClickHandler() {

                                @Override
                                public void onCloseClick(CloseClickEvent event) {
                                    gridClientes.destroy();
                                }
                            });

                            clientes.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {

                                @Override
                                public void onRecordDoubleClick(RecordDoubleClickEvent event) {
                                    Record record = event.getRecord();
                                    buscarPorCodCliente(record.getAttributeAsInt("codigo"));
                                    gridClientes.destroy();
                                }

                            });
                        } else {
                            SC.say("Cliente no Cadastrado");
                            buscaCliente.clearValue();
                        }
                    }
                });

    } else if (formBusca.validate() && tipoBusca.getValueAsString().equalsIgnoreCase("2")) {
        Info.dbService.buscarPorCPF(buscaCliente.getValueAsString(), codigoUnidade,
                new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                    }

                    @Override
                    public void onSuccess(ArrayList<TreeMap<String, String>> pessoa) {
                        if (pessoa != null) {
                            ListGridField codigo = new ListGridField("codigo", "Cdigo");
                            codigo.setHidden(true);
                            ListGridField cpf = new ListGridField("cpf", "CPF");
                            cpf.setWidth(80);
                            ListGridField nome = new ListGridField("nome", "Nome");
                            nome.setWidth(180);
                            ListGridField dataAdesao = new ListGridField("dataAdesao", "Data de Adeso");
                            dataAdesao.setAlign(Alignment.CENTER);
                            ListGridField unidade = new ListGridField("unidade", "Unidade");
                            ListGrid clientes = new ListGrid();
                            clientes.setCanPickFields(false);
                            clientes.setFields(codigo, cpf, nome, dataAdesao, unidade);
                            clientes.setShowAllRecords(true);

                            for (TreeMap<String, String> cl : pessoa) {
                                Record registros = new Record();
                                registros.setAttribute("codigo", cl.get("codCliente"));
                                registros.setAttribute("cpf", Info.formataCPF(cl.get("cpf")));
                                registros.setAttribute("nome", cl.get("nome"));
                                registros.setAttribute("dataAdesao", DateTimeFormat.getShortDateFormat()
                                        .format(new Date(Long.parseLong(cl.get("dataAdesao")))));
                                registros.setAttribute("unidade", cl.get("nomeUnidade"));
                                clientes.addData(registros);
                            }
                            clientes.selectRecord(0, true);
                            final Window gridClientes = new Window();
                            gridClientes.setTitle("Lista de Clientes");
                            gridClientes.setWidth(500);
                            gridClientes.setHeight(300);
                            gridClientes.setShowMinimizeButton(false);
                            gridClientes.setIsModal(true);
                            gridClientes.setShowModalMask(true);
                            gridClientes.centerInPage();
                            gridClientes.setLayoutAlign(Alignment.CENTER);
                            gridClientes.addItem(clientes);
                            gridClientes.setAnimateTime(1200);
                            gridClientes.animateShow(AnimationEffect.FADE);
                            gridClientes.addCloseClickHandler(new CloseClickHandler() {

                                @Override
                                public void onCloseClick(CloseClickEvent event) {
                                    gridClientes.destroy();
                                }
                            });

                            clientes.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {

                                @Override
                                public void onRecordDoubleClick(RecordDoubleClickEvent event) {
                                    Record record = event.getRecord();
                                    buscarPorCodCliente(record.getAttributeAsInt("codigo"));
                                    gridClientes.destroy();
                                }

                            });
                        } else {
                            SC.say("Cliente no Cadastrado");
                            buscaCliente.clearValue();
                        }
                    }
                });
    } else if (formBusca.validate() && tipoBusca.getValueAsString().equalsIgnoreCase("3")) {
        Info.dbService.buscarPorCNPJ(buscaCliente.getValueAsString(), codigoUnidade,
                new AsyncCallback<ArrayList<TreeMap<String, String>>>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                    }

                    @Override
                    public void onSuccess(ArrayList<TreeMap<String, String>> empresa) {

                        if (empresa != null) {
                            ListGridField codigo = new ListGridField("codigo", "Cdigo");
                            codigo.setHidden(true);
                            ListGridField cnpj = new ListGridField("cnpj", "CNPJ");
                            cnpj.setWidth(110);
                            ListGridField nome = new ListGridField("nome", "Nome");
                            nome.setWidth(180);
                            ListGridField dataAdesao = new ListGridField("dataAdesao", "Data de Adeso");
                            dataAdesao.setAlign(Alignment.CENTER);
                            ListGridField unidade = new ListGridField("unidade", "Unidade");
                            ListGrid clientes = new ListGrid();
                            clientes.setCanPickFields(false);
                            clientes.setFields(codigo, cnpj, nome, dataAdesao, unidade);
                            clientes.setShowAllRecords(true);

                            for (TreeMap<String, String> emp : empresa) {
                                Record registros = new Record();
                                registros.setAttribute("codigo", emp.get("codCliente"));
                                registros.setAttribute("cnpj", Info.formataCNPJ(emp.get("cnpj")));
                                registros.setAttribute("nome", emp.get("nome"));
                                registros.setAttribute("dataAdesao", DateTimeFormat.getShortDateFormat()
                                        .format(new Date(Long.parseLong(emp.get("dataAdesao")))));
                                registros.setAttribute("unidade", emp.get("nomeUnidade"));
                                clientes.addData(registros);
                            }
                            clientes.selectRecord(0, true);
                            final Window gridClientes = new Window();
                            gridClientes.setTitle("Lista de Clientes");
                            gridClientes.setWidth(500);
                            gridClientes.setHeight(300);
                            gridClientes.setShowMinimizeButton(false);
                            gridClientes.setIsModal(true);
                            gridClientes.setShowModalMask(true);
                            gridClientes.centerInPage();
                            gridClientes.setLayoutAlign(Alignment.CENTER);
                            gridClientes.addItem(clientes);
                            gridClientes.setAnimateTime(1200);
                            gridClientes.animateShow(AnimationEffect.FADE);
                            gridClientes.addCloseClickHandler(new CloseClickHandler() {

                                @Override
                                public void onCloseClick(CloseClickEvent event) {
                                    gridClientes.destroy();
                                }
                            });

                            clientes.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {

                                @Override
                                public void onRecordDoubleClick(RecordDoubleClickEvent event) {
                                    Record record = event.getRecord();
                                    buscarPorCodCliente(record.getAttributeAsInt("codigo"));
                                    gridClientes.destroy();
                                }

                            });
                        } else {
                            SC.say("Cliente no Cadastrado");
                            buscaCliente.clearValue();
                        }
                    }
                });
    }
}

From source file:com.automaster.client.ui.paineis.tabs.TabBuscarCliente.java

private void buscarPorCodCliente(int codCliente) {

    Info.dbService.buscarPorCodCliente(codCliente,
            new AsyncCallback<TreeMap<String, ArrayList<TreeMap<String, String>>>>() {

                @Override//from ww  w.  j a v a2  s . c  om
                public void onFailure(Throwable caught) {
                    //GWT.log(caught.getMessage());
                    throw new UnsupportedOperationException("Not supported yet..........................."); //To change body of generated methods, choose Tools | Templates.
                }

                @Override
                public void onSuccess(TreeMap<String, ArrayList<TreeMap<String, String>>> cliente) {
                    if (cliente != null) {
                        //Fazendo Cpia do Cliente Retornado
                        setClienteEdicao(cliente);
                        //final ArrayList<TreeMap<String, String>> clienteAuxiliar = cliente.pollFirstEntry().getValue();
                        clienteAuxiliar = getClienteEdicao().get(getClienteEdicao().firstKey());
                        if (!dadosCliente.getRecordList().isEmpty()) {
                            dadosCliente.selectAllRecords();
                            dadosCliente.removeSelectedData();
                        }
                        //GWT.log("Tipo: "+clienteAuxiliar.get(0).get("tipoCliente"));
                        codigoCliente = Integer.parseInt(clienteAuxiliar.get(0).get("codCliente"));
                        nomeCliente = clienteAuxiliar.get(0).get("nomeCliente");
                        Record regCliente = new Record();
                        regCliente.setAttribute("nome", clienteAuxiliar.get(0).get("nomeCliente"));
                        regCliente.setAttribute("dataAdesao", DateTimeFormat.getShortDateFormat()
                                .format(new Date(Long.parseLong(clienteAuxiliar.get(0).get("dataAdesao")))));
                        regCliente.setAttribute("unidade", clienteAuxiliar.get(0).get("nomeUnidade"));
                        //GWT.log(""+clienteAuxiliar.get(0).get("cpf"));
                        if (clienteAuxiliar.get(0).get("cpf") == null) {
                            regCliente.setAttribute("cnpj",
                                    Info.formataCNPJ(clienteAuxiliar.get(0).get("cnpj")));
                            regCliente.setAttribute("dataAbert", DateTimeFormat.getShortDateFormat().format(
                                    new Date(Long.parseLong(clienteAuxiliar.get(0).get("dataAbertura")))));
                            dadosCliente.setFields(nome, cnpj, dataAbert, dataAdesao, unidade, codigo);
                        } else {
                            regCliente.setAttribute("cpf", Info.formataCPF(clienteAuxiliar.get(0).get("cpf")));
                            regCliente.setAttribute("dataNasc", DateTimeFormat.getShortDateFormat()
                                    .format(new Date(Long.parseLong(clienteAuxiliar.get(0).get("dataNasc")))));
                            dadosCliente.setFields(nome, cpf, dataNasc, dataAdesao, unidade, codigo);
                        }
                        dadosCliente.addData(regCliente);
                        if (!enderecos.getRecordList().isEmpty()) {
                            enderecos.selectAllRecords();
                            enderecos.removeSelectedData();
                        }
                        TreeMap<String, String> endAuxiliar = new TreeMap<String, String>();
                        for (TreeMap<String, String> ends : clienteAuxiliar) {
                            if (clienteAuxiliar.get(0).get("codEndereco") != null
                                    && endAuxiliar.get(ends.get("codEndereco")) == null) {
                                Record regEnd = new Record();
                                regEnd.setAttribute("codigo", ends.get("codEndereco"));
                                regEnd.setAttribute("descricao", ends.get("descricaoEndereco"));
                                regEnd.setAttribute("logradouro", ends.get("logradouro"));
                                regEnd.setAttribute("numero", ends.get("numeroEndereco"));
                                regEnd.setAttribute("bairro", ends.get("bairro"));
                                regEnd.setAttribute("cep", ends.get("cep"));
                                regEnd.setAttribute("cidade", ends.get("nomeCidade"));
                                regEnd.setAttribute("cidadeCod", ends.get("codCidade"));
                                regEnd.setAttribute("estado", ends.get("estadoUf"));
                                regEnd.setAttribute("estadoCod", ends.get("codEstado"));
                                regEnd.setAttribute("referencia",
                                        (ends.get("referenciaEndereco") == null
                                                || ends.get("referenciaEndereco").equalsIgnoreCase("")
                                                        ? "Sem informao"
                                                        : ends.get("referenciaEndereco")));
                                enderecos.addData(regEnd);
                                endAuxiliar.put(ends.get("codEndereco"), ends.get("codEndereco"));
                            }
                        }
                        if (!telefones.getRecordList().isEmpty()) {
                            telefones.selectAllRecords();
                            telefones.removeSelectedData();
                        }
                        TreeMap<String, String> foneAuxiliar = new TreeMap<String, String>();
                        for (TreeMap<String, String> tels : clienteAuxiliar) {
                            if (clienteAuxiliar.get(0).get("codFone") != null
                                    && foneAuxiliar.get(tels.get("codFone")) == null) {
                                Record regTel = new Record();
                                regTel.setAttribute("codigo", tels.get("codFone"));
                                regTel.setAttribute("descricao", tels.get("descricaoFone"));
                                regTel.setAttribute("numero", Info.formataTelefone(tels.get("numeroFone")));
                                telefones.addData(regTel);
                                foneAuxiliar.put(tels.get("codFone"), tels.get("codFone"));
                            }
                        }
                        if (!emails.getRecordList().isEmpty()) {
                            emails.selectAllRecords();
                            emails.removeSelectedData();
                        }

                        TreeMap<String, String> emailAuxiliar = new TreeMap<String, String>();
                        for (TreeMap<String, String> ems : clienteAuxiliar) {
                            if (clienteAuxiliar.get(0).get("codEmail") != null
                                    && emailAuxiliar.get(ems.get("codEmail")) == null) {
                                Record regEmails = new Record();
                                regEmails.setAttribute("codigo", ems.get("codEmail"));
                                regEmails.setAttribute("descricao", ems.get("descricaoEmail"));
                                regEmails.setAttribute("email", ems.get("email"));
                                emails.addData(regEmails);
                                emailAuxiliar.put(ems.get("codEmail"), ems.get("codEmail"));
                            }
                        }
                        if (!logins.getRecordList().isEmpty()) {
                            logins.selectAllRecords();
                            logins.removeSelectedData();
                        }
                        TreeMap<String, String> usuarioAuxiliar = new TreeMap<String, String>();
                        for (TreeMap<String, String> user : clienteAuxiliar) {
                            if (clienteAuxiliar.get(0).get("codUsuario") != null
                                    && usuarioAuxiliar.get(user.get("codUsuario")) == null) {
                                Record regUsers = new Record();
                                regUsers.setAttribute("codigo", user.get("codUsuario"));
                                regUsers.setAttribute("usuario", user.get("usuario"));
                                regUsers.setAttribute("senha", user.get("senha"));
                                regUsers.setAttribute("statusCod", user.get("ativoUsuario"));
                                regUsers.setAttribute("status",
                                        ((user.get("ativoUsuario").equalsIgnoreCase("t")) ? "Ativo"
                                                : "Bloqueado"));
                                regUsers.setAttribute("codGrupo", user.get("codGrupo"));
                                regUsers.setAttribute("grupo", user.get("nomeGrupo"));
                                regUsers.setAttribute("resetUsuario",
                                        ((user.get("resetUsuario").equalsIgnoreCase("t")) ? "Resetado"
                                                : "Resetar"));
                                logins.addData(regUsers);
                                usuarioAuxiliar.put(user.get("codUsuario"), user.get("codUsuario"));
                            }
                        }
                        if (!lancamento.getRecordList().isEmpty()) {
                            lancamento.selectAllRecords();
                            lancamento.removeSelectedData();
                        }
                        TreeMap<String, String> lancamentoAuxiliar = new TreeMap<String, String>();
                        for (TreeMap<String, String> lanc : clienteAuxiliar) {
                            if (clienteAuxiliar.get(0).get("codLancamento") != null
                                    && lancamentoAuxiliar.get(lanc.get("codLancamento")) == null) {
                                Record regLanc = new Record();
                                regLanc.setAttribute("codigo", lanc.get("codLancamento"));
                                regLanc.setAttribute("data", DateTimeFormat.getShortDateTimeFormat()
                                        .format(new Date(Long.parseLong(lanc.get("dataLancamento")))));
                                regLanc.setAttribute("valor", "R$"
                                        + Info.formataSaldo(Double.parseDouble(lanc.get("valorLancamento"))));
                                lancamento.addData(regLanc);
                                lancamentoAuxiliar.put(lanc.get("codLancamento"), lanc.get("codLancamento"));
                            }
                        }
                        editCliente.setDisabled(false);
                        addLancamento.setDisabled(false);
                        addVeiculo.setDisabled(false);

                        Info.dbService.buscarVeiculoPorCliente(
                                Integer.parseInt(clienteAuxiliar.get(0).get("codCliente")),
                                new AsyncCallback<TreeMap<String, ArrayList<TreeMap<String, String>>>>() {

                                    @Override
                                    public void onFailure(Throwable caught) {
                                        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                                    }

                                    @Override
                                    public void onSuccess(
                                            TreeMap<String, ArrayList<TreeMap<String, String>>> dadosVeic) {

                                        if (dadosVeic != null) {
                                            if (!veicPlacas.getRecordList().isEmpty()) {
                                                veicPlacas.selectAllRecords();
                                                veicPlacas.removeSelectedData();
                                                tabelaVeiculos.redraw();
                                                tabelaVeiculos.setContents(tabelaVazia);
                                            }
                                            veiculos = new TreeMap<String, ArrayList<TreeMap<String, String>>>(
                                                    dadosVeic);

                                            TreeMap<String, ArrayList<TreeMap<String, String>>> veiculosAux = new TreeMap<String, ArrayList<TreeMap<String, String>>>(
                                                    veiculos);

                                            ListGridRecord[] registeredPlacaRecords = new ListGridRecord[dadosVeic
                                                    .size()];
                                            if (veiculos.size() > 0) {

                                                editVeiculo.setDisabled(true);
                                                placaClicada.clear();

                                                for (int i = 0; i < veiculos.size(); i++) {
                                                    final ListGridRecord recordVeiculos = new ListGridRecord();
                                                    recordVeiculos.setAttribute("placa",
                                                            veiculosAux.pollFirstEntry().getValue().get(0)
                                                                    .get("placaVeiculo"));
                                                    registeredPlacaRecords[i] = recordVeiculos;
                                                }

                                                DataSourceTextField placaVeiculo = new DataSourceTextField(
                                                        "placa", "Placa");
                                                placaVeiculo.setRequired(true);
                                                placaVeiculo.setPrimaryKey(true);

                                                DataSource ds = new DataSource();
                                                ds.setClientOnly(true);
                                                ds.setFields(placaVeiculo);
                                                for (int i = 0; i < registeredPlacaRecords.length; i++) {
                                                    ds.addData(registeredPlacaRecords[i]);
                                                }
                                                veicPlacas.setDataSource(ds);
                                                veicPlacas.fetchData();
                                                veicPlacas.setSelectionType(SelectionStyle.SINGLE);

                                            } else {
                                                placaClicada.clear();
                                                editVeiculo.setDisabled(true);
                                            }
                                        }
                                    }
                                });

                    } else {
                        SC.warn("Erro ao Consultar Veculos do Cliente");
                    }

                }
            });

}