com.demo.bean.ExportarGestionesBean.java Source code

Java tutorial

Introduction

Here is the source code for com.demo.bean.ExportarGestionesBean.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.demo.bean;

import com.demo.dao.GestionesDAO;
import com.demo.dao.GestoresDao;
import com.demo.impl.GestionesImplement;
import com.demo.impl.GestoresImpl;
import com.demo.model.CatGestores;
import com.demo.model.Gestiones;
import com.demo.util.LogSistema;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;

/**
 *
 * @author chris55
 */
@ManagedBean(name = "exportarGestionesBean")
@ViewScoped
public class ExportarGestionesBean implements Serializable {

    private Date FechaInicio;
    private Date FechaFin;
    private CatGestores Gestor;
    private List<CatGestores> listaGestores;
    private GestoresDao gestDao;
    private int gestorElegido;
    private String familiaElegida;
    private String productoElegido;
    private String producto;
    private List<Gestiones> gestiones;
    private GestionesDAO gestionesDAO;

    private Map<String, String> FamiliaProducto;
    private Map<String, Map<String, String>> productos;
    private Map<String, String> FamiliaProductoR;

    private String NombreArchivo;

    private boolean agregado; // Indica si la columna sebe o no ser cargada a la base de datos
    private List<String> listaCampos;

    /**
     * Creates a new instance of ExportarGestionesBean
     */
    public ExportarGestionesBean() {

        FamiliaProducto = new HashMap<String, String>();
        productos = new HashMap<String, Map<String, String>>();
        FamiliaProductoR = new HashMap<String, String>();
        gestDao = new GestoresImpl();
        FechaInicio = new Date();
        FechaFin = new Date();
        Gestor = new CatGestores();
        listaGestores = gestDao.todos();
        gestionesDAO = new GestionesImplement();

        gestiones = new ArrayList();
        listaCampos = new ArrayList();

        //familias Productos
        FamiliaProducto.put("SOFOM COMERCIAL", "SOFOM COMERCIAL");
        FamiliaProducto.put("SOFOM PERSONAL", "SOFOM PERSONAL");
        FamiliaProducto.put("CT EXPRESS", "CT EXPRESS");
        FamiliaProducto.put("LINEA TELMEX", "LINEA TELMEX");
        FamiliaProducto.put("TELNOR LT", "TELNOR LT");
        FamiliaProducto.put("TELNOR SOFOM", "TELNOR SOFOM");
        FamiliaProducto.put("TELNOR PERSONAL", "TELNOR PERSONAL");
        FamiliaProducto.put("CT CASTIGO", "CT CASTIGO");
        FamiliaProducto.put("QUEBRANTO COMERCIAL", "QUEBRANTO COMERCIAL");

        ////
        Map<String, String> SubSOFOMCOMERCIAL = new HashMap<String, String>();
        SubSOFOMCOMERCIAL.put("A_LINEA CREDITO TELMEX PF 50", "A_LINEA CREDITO TELMEX PF 50");
        SubSOFOMCOMERCIAL.put("A_LINEA CREDITO TELMEX PM 50", "A_LINEA CREDITO TELMEX PM 50");
        SubSOFOMCOMERCIAL.put("EX LINEA CREDITO TELMEX PF", "EX LINEA CREDITO TELMEX PF");
        SubSOFOMCOMERCIAL.put("EX LINEA CREDITO TELMEX PM", "EX LINEA CREDITO TELMEX PM");

        Map<String, String> SubSOFOMPERSONAL = new HashMap<String, String>();
        SubSOFOMPERSONAL.put("A_LINEA CREDITO TELMEX PERSONAL 38", "A_LINEA CREDITO TELMEX PERSONAL 38");
        SubSOFOMPERSONAL.put("EX LINEA CREDITO TELMEX PERSONAL 38", "EX LINEA CREDITO TELMEX PERSONAL 38");

        Map<String, String> SubCTEXPRESS = new HashMap<String, String>();
        SubCTEXPRESS.put("CT EXPRESS PF", "CT EXPRESS PF");
        SubCTEXPRESS.put("CT EXPRESS PM", "CT EXPRESS PM");
        SubCTEXPRESS.put("CREDITOS EXPRESS PF", "CREDITOS EXPRESS PF");
        SubCTEXPRESS.put("CREDITOS EXPRESS PM", "CREDITOS EXPRESS PM");
        SubCTEXPRESS.put("EXPRESS ABIERTO PF", "EXPRESS ABIERTO PF");
        SubCTEXPRESS.put("EXPRESS ABIERTO PM", "EXPRESS ABIERTO PM");

        Map<String, String> SubLINEATELMEX = new HashMap<String, String>();
        SubLINEATELMEX.put("LINEA CREDITO TELMEX PF", "LINEA CREDITO TELMEX PF");
        SubLINEATELMEX.put("LINEA CREDITO TELMEX PM", "LINEA CREDITO TELMEX PM");
        SubLINEATELMEX.put("EXLINEA CREDITO TELMEX PF", "EXLINEA CREDITO TELMEX PF");
        SubLINEATELMEX.put("EXLINEA CREDITO TELMEX PM", "EXLINEA CREDITO TELMEX PM");

        Map<String, String> SubTELNORLT = new HashMap<String, String>();
        SubTELNORLT.put("LINEA CREDITO TELNOR PF", "LINEA CREDITO TELNOR PF");
        SubTELNORLT.put("LINEA CREDITO TELNOR PM", "LINEA CREDITO TELNOR PM");
        SubTELNORLT.put("EX LINEA CREDITO TELNOR PF", "EX LINEA CREDITO TELNOR PF");
        SubTELNORLT.put("EXLINEA CREDITO TELNOR PM", "EXLINEA CREDITO TELNOR PM");

        Map<String, String> SubTELNORSOFOM = new HashMap<String, String>();
        SubTELNORSOFOM.put("A_LINEA CREDITO TELNOR PF 50", "A_LINEA CREDITO TELNOR PF 50");
        SubTELNORSOFOM.put("A_LINEA CREDITO TELNOR PM 50", "A_LINEA CREDITO TELNOR PM 50");
        SubTELNORSOFOM.put("A_EX LINEA CREDITO TELNOR PF 50", "A_EX LINEA CREDITO TELNOR PF 50");
        SubTELNORSOFOM.put("A_EXLINEA CREDITO TELNOR PM 50", "A_EXLINEA CREDITO TELNOR PM 50");

        Map<String, String> SubTELNORPERSONAL = new HashMap<>();
        SubTELNORPERSONAL.put("A_LINEA CREDITO TELNOR PERSONAL 38", "A_LINEA CREDITO TELNOR PERSONAL 38");
        SubTELNORPERSONAL.put("EX CREDITO TELNOR PERSONAL 38", "EX CREDITO TELNOR PERSONAL 38");

        Map<String, String> SubCTCASTIGO = new HashMap<String, String>();
        SubCTCASTIGO.put("CT EXPRESS PF CASTIGO", "CT EXPRESS PF CASTIGO");
        SubCTCASTIGO.put("CT EXPRESS PM CASTIGO", "CT EXPRESS PM CASTIGO");

        Map<String, String> SubQUEBRANTOCORMERCIAL = new HashMap<String, String>();
        SubQUEBRANTOCORMERCIAL.put("LINEA CREDITO TELMEX PF 50 QUEBRANTO", "LINEA CREDITO TELMEX PF 50 QUEBRANTO");
        SubQUEBRANTOCORMERCIAL.put("LINEA CREDITO TELMEX PM 50 QUEBRANTO", "LINEA CREDITO TELMEX PM 50 QUEBRANTO");
        SubQUEBRANTOCORMERCIAL.put("EX LINEA CREDITO TELMEX PF 50 QUEBRANTO",
                "EX LINEA CREDITO TELMEX PF 50 QUEBRANTO");
        SubQUEBRANTOCORMERCIAL.put("EXLINEA CREDITO TELMEX PM 50 QUEBRANTO",
                "EXLINEA CREDITO TELMEX PM 50 QUEBRANTO");
        SubQUEBRANTOCORMERCIAL.put("LINEA CREDITO TELMEX PF QUEBRANTO", "LINEA CREDITO TELMEX PF QUEBRANTO");
        SubQUEBRANTOCORMERCIAL.put("LINEA CREDITO TELMEX PM QUEBRANTO", "LINEA CREDITO TELMEX PM QUEBRANTO");
        SubQUEBRANTOCORMERCIAL.put("EX LINEA CREDITO TELMEX PF QUEBRANTO", "EX LINEA CREDITO TELMEX PF QUEBRANTO");
        SubQUEBRANTOCORMERCIAL.put("EXLINEA CREDITO TELMEX PM QUEBRANTO", "EXLINEA CREDITO TELMEX PM QUEBRANTO");

        productos.put("SOFOM COMERCIAL", SubSOFOMCOMERCIAL);
        productos.put("SOFOM PERSONAL", SubSOFOMPERSONAL);
        productos.put("CT EXPRESS", SubCTEXPRESS);
        productos.put("LINEA TELMEX", SubLINEATELMEX);
        productos.put("TELNOR LT", SubTELNORLT);
        productos.put("TELNOR SOFOM", SubTELNORSOFOM);
        productos.put("TELNOR PERSONAL", SubTELNORPERSONAL);
        productos.put("CT CASTIGO", SubCTCASTIGO);
        productos.put("QUEBRANTO COMERCIAL", SubQUEBRANTOCORMERCIAL);

        agregado = true; // Por default, todas las columnas se agregan a la base de datos
        listaCampos.add("CREDITO");
        listaCampos.add("NOMBRE");
        listaCampos.add("REFERENCIA");
        listaCampos.add("TIPO DE CREDITO");
        listaCampos.add("LINEA");
        listaCampos.add("EST");
        listaCampos.add("MV");
        listaCampos.add("ASIGNACION");
        listaCampos.add("DESPACHO");
        listaCampos.add("INICIO CREDITO");
        listaCampos.add("VENCIMIENTO");
        listaCampos.add("MONTO");
        listaCampos.add("MENSUALIDAD");
        listaCampos.add("SALDO CAPITAL");
        listaCampos.add("SALDO VENCIDO");
        listaCampos.add("TASA");
        listaCampos.add("CUENTA DE PAGO");
        listaCampos.add("ESTATUS CUENTA");
        listaCampos.add("FECHA ULTIMO PAGO");
        listaCampos.add("ULTIMO VENCIMIENTO PAGADO");
        listaCampos.add("ID CLIENTE");
        listaCampos.add("RFC");

    }

    public void handleFamiliaChange() {
        if (familiaElegida != null && !familiaElegida.equals("")) {
            {
                FamiliaProductoR = productos.get(familiaElegida);
            }
        } else {

            FamiliaProductoR = new HashMap<String, String>();
        }
    }

    public void verGestiones() {
        this.NombreArchivo = "Gestiones-" + productoElegido + dateToMySQLDate(FechaInicio) + "_a_"
                + dateToMySQLDate(FechaFin);
        this.NombreArchivo = this.NombreArchivo.replace(" ", "_");
        gestiones.clear();
        if (familiaElegida.equalsIgnoreCase("Todos")) {
            productoElegido = "Todos";
        }
        gestiones = gestionesDAO.obtenerGestionesFiltro(FechaInicio, FechaFin, productoElegido, gestorElegido);
        LogSistema.guardarlog(this.getClass().getName()
                + " Method: verGestiones, admin exporto gestiones con filtro, fechaInicio: " + FechaInicio
                + ", fechaFin: " + FechaFin + ", producto: " + productoElegido + ", gestor: " + gestorElegido
                + ", numero de gestiones exportadas : " + gestiones.size());
    }

    public String dateToMySQLDate(Date fecha) {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(fecha);
    }

    public void postProcessXLS(Object document) {
        HSSFWorkbook wb = (HSSFWorkbook) document;
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow header = sheet.getRow(0);

        HSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setFillForegroundColor(HSSFColor.GOLD.index);
        cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
            HSSFCell cell = header.getCell(i);

            cell.setCellStyle(cellStyle);
        }
    }

    public String getNombreArchivo() {
        return NombreArchivo;
    }

    public void setNombreArchivo(String NombreArchivo) {
        this.NombreArchivo = NombreArchivo;
    }

    public List<Gestiones> getGestiones() {
        return gestiones;
    }

    public void setGestiones(List<Gestiones> gestiones) {
        this.gestiones = gestiones;
    }

    public Map<String, String> getFamiliaProducto() {
        return FamiliaProducto;
    }

    public void setFamiliaProducto(Map<String, String> FamiliaProducto) {
        this.FamiliaProducto = FamiliaProducto;
    }

    public Map<String, Map<String, String>> getProductos() {
        return productos;
    }

    public void setProductos(Map<String, Map<String, String>> productos) {
        this.productos = productos;
    }

    public Map<String, String> getFamiliaProductoR() {
        return FamiliaProductoR;
    }

    public void setFamiliaProductoR(Map<String, String> FamiliaProductoR) {
        this.FamiliaProductoR = FamiliaProductoR;
    }

    public int getGestorElegido() {
        return gestorElegido;
    }

    public void setGestorElegido(int gestorElegido) {
        this.gestorElegido = gestorElegido;
    }

    public List<CatGestores> getListaGestores() {
        return listaGestores;
    }

    public void setListaGestores(List<CatGestores> listaGestores) {
        this.listaGestores = listaGestores;
    }

    public String getProductoElegido() {
        return productoElegido;
    }

    public void setProductoElegido(String productoElegido) {
        this.productoElegido = productoElegido;
    }

    public String getProducto() {
        return producto;
    }

    public void setProducto(String producto) {
        this.producto = producto;
    }

    public Date getFechaInicio() {
        return FechaInicio;
    }

    public void setFechaInicio(Date FechaInicio) {
        this.FechaInicio = FechaInicio;
    }

    public Date getFechaFin() {
        return FechaFin;
    }

    public void setFechaFin(Date FechaFin) {
        this.FechaFin = FechaFin;
    }

    public CatGestores getGestor() {
        return Gestor;
    }

    public void setGestor(CatGestores Gestor) {
        this.Gestor = Gestor;
    }

    public String getFamiliaElegida() {
        return familiaElegida;
    }

    public void setFamiliaElegida(String familiaElegida) {
        this.familiaElegida = familiaElegida;
    }

}