com.webgocommerce.client.view.uidocventa.UIDocVentaImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.webgocommerce.client.view.uidocventa.UIDocVentaImpl.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.webgocommerce.client.view.uidocventa;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.SimpleEventBus;
import com.google.web.bindery.requestfactory.shared.Receiver;
import com.google.web.bindery.requestfactory.shared.Request;
import com.google.web.bindery.requestfactory.shared.ServerFailure;
import com.webgocommerce.client.beanproxy.CabeceraVentaProxy;
import com.webgocommerce.client.beanproxy.CorrelativoProxy;
import com.webgocommerce.client.beanproxy.DetalleVentaProxy;
import com.webgocommerce.client.requestfactory.ContextGestionFacturacion;
import com.webgocommerce.client.requestfactory.ContextMantenimientoCorrelativo;
import com.webgocommerce.client.requestfactory.FactoryGestion;
import com.webgocommerce.client.uiutil.Notification;
import com.webgocommerce.client.uiutil.PopupProgress;
import com.webgocommerce.client.uiutil.TableToExcel;
import com.webgocommerce.client.view.uihomedocventa.UIHomeDocVenta;
import com.webgocommerce.client.view.uisesion.UISesion;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author SISTEMAS
 */
public class UIDocVentaImpl extends UIDocVenta {
    private DateTimeFormat dateFormat = DateTimeFormat.getFormat("dd/MM/yyyy");
    PopupProgress popup = new PopupProgress();
    private final FactoryGestion FACTORY = GWT.create(FactoryGestion.class);
    private final EventBus EVENTBUS = new SimpleEventBus();
    private UIHomeDocVenta uiHomeDocVenta;

    public UIDocVentaImpl(UIHomeDocVenta uiHomeDocVenta) {
        this.uiHomeDocVenta = uiHomeDocVenta;
        loadSeriesUserVenta();
        gridUpdate();
    }

    public void gridUpdate() {
        grid.removeColumn(grid.estadoAct);
        grid.removeColumn(grid.codProy);
        grid.removeColumn(grid.totalPlan);
        grid2.removeColumn(grid2.equipos);
    }

    @Override
    public void loadSeriesUserVenta() {
        ContextMantenimientoCorrelativo context = FACTORY.contextMantenimientoCorrelativo();
        FACTORY.initialize(EVENTBUS);
        String keyPublic = UISesion.keyPublic;
        Request<List<CorrelativoProxy>> request = context.getSerieUserVenta(keyPublic, UISesion.beanUsuario.getId(),
                UISesion.beanUsuario.getIdPuntoEmision());
        request.fire(new Receiver<List<CorrelativoProxy>>() {

            @Override
            public void onSuccess(List<CorrelativoProxy> response) {
                if (response.size() > 0) {
                    String series = "";
                    for (int i = 0; i < response.size(); i++) {
                        series = series + "," + response.get(i).getDocSerie();
                    }
                    series = series.substring(1);
                    docSeries = series;
                    loadTable();
                } else {
                    Notification not = new Notification(Notification.ALERT,
                            "Usuario no administra series de venta");
                    not.showPopup();
                }

            }
        });
    }

    @Override
    public void loadTable() {
        popup.showPopup();
        ContextGestionFacturacion context = FACTORY.contextGestionFacturacion();
        FACTORY.initialize(EVENTBUS);
        String keyPublic = UISesion.keyPublic;
        String rucCliente = "";
        String descCliente = "";
        String correlativo = "";
        if (lstFiltro.getSelectedIndex() == 0) {
            rucCliente = txtBuscar.getText();
        } else if (lstFiltro.getSelectedIndex() == 1) {
            descCliente = txtBuscar.getText();
        } else if (lstFiltro.getSelectedIndex() == 2) {
            correlativo = txtBuscar.getText();
        }
        Request<List<CabeceraVentaProxy>> request = context.listarVentas(keyPublic, boxDateIni.getValue(),
                boxDateFin.getValue(), rucCliente, descCliente, docSeries, correlativo,
                chkSoloAnulados.getValue() ? "A" : "S", chkExcluirFechas.getValue() ? "S" : "N");
        request.fire(new Receiver<List<CabeceraVentaProxy>>() {

            @Override
            public void onSuccess(List<CabeceraVentaProxy> response) {
                grid.getSelectionModel().clear();
                grid.setData(response);
                grid2.getSelectionModel().clear();
                grid2.setData(new ArrayList<DetalleVentaProxy>());
                //lstBdEmpresa.setData(grid.getData());
                popup.hidePopup();
                txtBuscar.textBox.setText(null);
                grid.getDataProvider().resetFilter();
            }

            @Override
            public void onFailure(ServerFailure error) {
                popup.hidePopup();
                //Window.alert(error.getMessage());                    
                Notification not = new Notification(Notification.WARNING, error.getMessage());
                not.showPopup();
            }
        });
    }

    @Override
    public void showUIOper4() {
        CabeceraVentaProxy bean = grid.getSelectionModel().getSelectedObject();
        if (bean != null) {
            lblTipoDoc.setText(bean.getNomDoc());
            lblSerie.setText(bean.getSerie());
            lblPreImpreso.setText(bean.getPreimpreso());
            popup.showPopup();
            ContextGestionFacturacion context = FACTORY.contextGestionFacturacion();
            FACTORY.initialize(EVENTBUS);
            String keyPublic = UISesion.keyPublic;
            Request<List<DetalleVentaProxy>> request = context.getDetalleVenta(keyPublic, bean.getTipoDoc(),
                    bean.getCorrelativo());
            request.fire(new Receiver<List<DetalleVentaProxy>>() {

                @Override
                public void onSuccess(List<DetalleVentaProxy> response) {
                    grid2.getSelectionModel().clear();
                    grid2.setData(response);
                    popup.hidePopup();
                }

                @Override
                public void onFailure(ServerFailure error) {
                    popup.hidePopup();
                    //Window.alert(error.getMessage());                    
                    Notification not = new Notification(Notification.WARNING, error.getMessage());
                    not.showPopup();
                }
            });
        } else {
            //Window.alert("Seleccione un registro de la tabla\ncon estado activo");
            Notification not = new Notification(Notification.ALERT, "Seleccione un registro de la tabla");
            not.showPopup();
        }
    }

    @Override
    public void exportarData() {
        int row = 0;
        List<CabeceraVentaProxy> lista;
        if (!grid.getDataProvider().hasFilter()) {
            row = grid.getData().size();
            lista = grid.getData();
        } else {
            row = grid.getDataProvider().resulted.size();
            lista = grid.getDataProvider().resulted;
        }
        if (row == 0) {
            Notification not = new Notification(Notification.ALERT, "Grid sin datos");
            not.showPopup();
            return;
        }
        FlexTable flex = new FlexTable();
        flex.setText(0, 0, "FECHA");
        flex.setText(0, 1, "TIPO DOC");
        flex.setText(0, 2, "SERIE");
        flex.setText(0, 3, "PREIMPRESO");
        flex.setText(0, 4, "RUC/DNI");
        flex.setText(0, 5, "CLIENTE");
        flex.setText(0, 6, "CONDICION");
        flex.setText(0, 7, "F. VENC");
        flex.setText(0, 8, "MONEDA");
        flex.setText(0, 9, "TIPO CAMBIO");
        flex.setText(0, 10, "TOTAL AFECTO");
        flex.setText(0, 11, "TOTAL IGV");
        flex.setText(0, 12, "TOTAL NETO");
        flex.setText(0, 13, "VENDEDOR");
        flex.setText(0, 14, "PTO. EMISION");
        flex.setText(0, 15, "TIPO VENTA");
        for (int j = 0; j < 16; j++) {
            flex.getFlexCellFormatter().getElement(0, j).getStyle().setFontWeight(Style.FontWeight.BOLD);
            flex.getFlexCellFormatter().getElement(0, j).getStyle().setFontSize(14, Style.Unit.PX);
            flex.getFlexCellFormatter().getElement(0, j).getStyle().setBackgroundColor("#0170C9");
            flex.getFlexCellFormatter().getElement(0, j).getStyle().setColor("#fff");
        }
        int fila = 1;
        for (int i = 0; i < row; i++) {
            CabeceraVentaProxy bean = lista.get(i);
            flex.setText(fila, 0, dateFormat.format(bean.getFechaEmision()));
            flex.setText(fila, 1, bean.getNomDoc());
            flex.setText(fila, 2, bean.getSerie());
            flex.setText(fila, 3, bean.getPreimpreso());
            flex.setText(fila, 4, bean.getRucCliente());
            flex.setText(fila, 5, bean.getNombreCliente());
            flex.setText(fila, 6, bean.getNomCondicionVenta());
            flex.setText(fila, 7, dateFormat.format(bean.getFechaVencimiento()));
            flex.setText(fila, 8, bean.getIdMoneda());
            flex.setText(fila, 9, bean.getTipoCambio().toString());
            flex.setText(fila, 10, bean.getTotalAfecto().toString());
            flex.setText(fila, 11, bean.getTotalIgv().toString());
            flex.setText(fila, 12, bean.getTotalNeto().toString());
            flex.setText(fila, 13, bean.getNomVendedor());
            flex.setText(fila, 14, bean.getPuntoEmsion());
            flex.setText(fila, 15, bean.getTipoVenta());
            fila = fila + 1;
        }
        TableToExcel.save(flex, "DocVentas" + (new Date()).getTime());
    }

}