Contabilidad.RCuentas.java Source code

Java tutorial

Introduction

Here is the source code for Contabilidad.RCuentas.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 Contabilidad;

import Hibernate.Util.HibernateUtil;
import Hibernate.entidades.Concepto;
import Hibernate.entidades.Configuracion;
import Hibernate.entidades.Factura;
import Hibernate.entidades.Nota;
import Hibernate.entidades.Usuario;
import Integral.ExtensionFileFilter;
import Integral.FormatoTabla;
import Integral.Herramientas;
import Integral.PDF;
import Integral.Render1;
import Integral.calendario;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.GrayColor;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPTable;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author salvador
 */
public class RCuentas extends javax.swing.JPanel {

    DefaultTableModel model, model1;
    Usuario usr;
    int menu, x = 0;
    String sessionPrograma = "";
    Herramientas h;
    String[] columnas = new String[] { "ID", "FECHA", "RFC", "R. SOCIAL", "F. FISCAL", "SERIE", "FOLIO", "MONTO",
            "ESTATUS", "F. ESTATUS", "NOTAS" };
    String[] columnas1 = new String[] { "ID", "FECHA", "RFC", "R. SOCIAL", "F. FISCAL", "SERIE", "FOLIO", "MONTO",
            "ESTATUS" };
    FormatoTabla formato, formato1;
    Object[] valores;
    Object[] valores1;

    /**
     * Creates new form RCuentas
     */
    public RCuentas(Usuario usuario, String ses, int op) {
        initComponents();
        formato = new FormatoTabla();
        formato1 = new FormatoTabla();
        formatoTabla();
        menu = op;
        usr = usuario;
        sessionPrograma = ses;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lista = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        t_datos = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        t_fecha3 = new javax.swing.JTextField();
        b_fecha_siniestro2 = new javax.swing.JButton();
        t_fecha4 = new javax.swing.JTextField();
        b_fecha_siniestro3 = new javax.swing.JButton();
        cb_fecha = new javax.swing.JComboBox();
        cb = new javax.swing.JComboBox();

        setBackground(new java.awt.Color(254, 254, 254));

        jTabbedPane1.setBackground(new java.awt.Color(254, 254, 254));

        jPanel1.setBackground(new java.awt.Color(254, 254, 254));

        jPanel3.setBackground(new java.awt.Color(254, 254, 254));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Estatus",
                javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP,
                new java.awt.Font("Arial", 1, 11))); // NOI18N

        lista.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "POR COBRAR", "COBRADA", "INCOBRABLE", "CANCELADO", "PENDIENTE" };

            public int getSize() {
                return strings.length;
            }

            public Object getElementAt(int i) {
                return strings[i];
            }
        });
        lista.setSelectionBackground(new java.awt.Color(2, 135, 242));
        jScrollPane1.setViewportView(lista);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                        .addContainerGap()));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addContainerGap()));

        jButton1.setIcon(new ImageIcon("imagenes/busca.png"));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setBackground(new java.awt.Color(2, 135, 242));
        jButton3.setIcon(new ImageIcon("imagenes/pdf.png"));
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setBackground(new java.awt.Color(2, 135, 242));
        jButton4.setIcon(new ImageIcon("imagenes/exel.png"));
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        t_datos.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "ID", "FECHA", "RFC", "R. SOCIAL", "F. FISCAL", "SERIE", "FOLIO", "MONTO", "ESTATUS",
                "F. ESTATUS", "NOTAS" }) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class,
                    java.lang.Double.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class };
            boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false, false, false,
                    false, false };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        t_datos.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        t_datos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        t_datos.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(t_datos);

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Filtrar",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP,
                new java.awt.Font("Arial", 1, 11))); // NOI18N

        jLabel3.setText("Inicio:");

        jLabel4.setText("Fin:");

        t_fecha3.setEditable(false);
        t_fecha3.setBackground(new java.awt.Color(204, 255, 255));
        t_fecha3.setText("AAAA-MM-DD");
        t_fecha3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_fecha3.setEnabled(false);

        b_fecha_siniestro2.setBackground(new java.awt.Color(2, 135, 242));
        b_fecha_siniestro2.setIcon(new ImageIcon("imagenes/calendario.png"));
        b_fecha_siniestro2.setToolTipText("Calendario");
        b_fecha_siniestro2.setMaximumSize(new java.awt.Dimension(32, 8));
        b_fecha_siniestro2.setMinimumSize(new java.awt.Dimension(32, 8));
        b_fecha_siniestro2.setPreferredSize(new java.awt.Dimension(32, 8));
        b_fecha_siniestro2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_fecha_siniestro2ActionPerformed(evt);
            }
        });

        t_fecha4.setEditable(false);
        t_fecha4.setBackground(new java.awt.Color(204, 255, 255));
        t_fecha4.setText("AAAA-MM-DD");
        t_fecha4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_fecha4.setEnabled(false);
        t_fecha4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_fecha4ActionPerformed(evt);
            }
        });

        b_fecha_siniestro3.setBackground(new java.awt.Color(2, 135, 242));
        b_fecha_siniestro3.setIcon(new ImageIcon("imagenes/calendario.png"));
        b_fecha_siniestro3.setToolTipText("Calendario");
        b_fecha_siniestro3.setMaximumSize(new java.awt.Dimension(32, 8));
        b_fecha_siniestro3.setMinimumSize(new java.awt.Dimension(32, 8));
        b_fecha_siniestro3.setPreferredSize(new java.awt.Dimension(32, 8));
        b_fecha_siniestro3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_fecha_siniestro3ActionPerformed(evt);
            }
        });

        cb_fecha.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Elaboracin", "Estatus" }));

        cb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "FACTURA", "NOTA" }));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(jPanel4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(cb, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(cb_fecha, javax.swing.GroupLayout.Alignment.LEADING, 0,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                        jPanel4Layout.createSequentialGroup().addGroup(jPanel4Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(jPanel4Layout.createSequentialGroup()
                                                        .addComponent(jLabel4)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(t_fecha4,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 88,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(1, 1, 1).addComponent(b_fecha_siniestro3,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 28,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(jPanel4Layout.createSequentialGroup()
                                                        .addComponent(jLabel3)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(t_fecha3,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 88,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(1, 1, 1).addComponent(b_fecha_siniestro2,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 28,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap()));
        jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(cb, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cb_fecha, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel3)
                                .addGroup(jPanel4Layout.createSequentialGroup().addGap(3, 3, 3).addComponent(
                                        t_fecha3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(b_fecha_siniestro2, javax.swing.GroupLayout.PREFERRED_SIZE, 24,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(
                                        jPanel4Layout.createSequentialGroup().addGap(5, 5, 5).addComponent(jLabel4))
                                .addGroup(jPanel4Layout.createSequentialGroup().addGap(3, 3, 3).addComponent(
                                        t_fecha4, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(b_fecha_siniestro3, javax.swing.GroupLayout.PREFERRED_SIZE, 24,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 888, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
                                        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap()));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 38,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 38,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 38,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
                        .addContainerGap()));

        jTabbedPane1.addTab("Cuentas x Cobrar", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane1));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane1));
    }// </editor-fold>//GEN-END:initComponents

    private void b_fecha_siniestro3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_fecha_siniestro3ActionPerformed
        // TODO add your handling code here:
        calendario cal = new calendario(new javax.swing.JFrame(), true);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        cal.setLocation((d.width / 2) - (cal.getWidth() / 2), (d.height / 2) - (cal.getHeight() / 2));
        cal.setVisible(true);

        Calendar miCalendario = cal.getReturnStatus();
        if (miCalendario != null) {
            String dia = Integer.toString(miCalendario.get(Calendar.DATE));
            ;
            String mes = Integer.toString(miCalendario.get(Calendar.MONTH) + 1);
            String anio = Integer.toString(miCalendario.get(Calendar.YEAR));
            t_fecha4.setText(anio + "-" + mes + "-" + dia);
            model = (DefaultTableModel) t_datos.getModel();
            model.getDataVector().removeAllElements();
            t_datos.revalidate();
        } else {
            t_fecha4.setText("AAAA-MM-DD");
            model = (DefaultTableModel) t_datos.getModel();
            model.getDataVector().removeAllElements();
            t_datos.revalidate();
        }
    }//GEN-LAST:event_b_fecha_siniestro3ActionPerformed

    private void t_fecha4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_fecha4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_t_fecha4ActionPerformed

    private void b_fecha_siniestro2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_fecha_siniestro2ActionPerformed
        // TODO add your handling code here:
        calendario cal = new calendario(new javax.swing.JFrame(), true);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        cal.setLocation((d.width / 2) - (cal.getWidth() / 2), (d.height / 2) - (cal.getHeight() / 2));
        cal.setVisible(true);

        Calendar miCalendario = cal.getReturnStatus();
        if (miCalendario != null) {
            String dia = Integer.toString(miCalendario.get(Calendar.DATE));
            ;
            String mes = Integer.toString(miCalendario.get(Calendar.MONTH) + 1);
            String anio = Integer.toString(miCalendario.get(Calendar.YEAR));
            t_fecha3.setText(anio + "-" + mes + "-" + dia);
            model = (DefaultTableModel) t_datos.getModel();
            model.getDataVector().removeAllElements();
            t_datos.revalidate();
        } else {
            t_fecha3.setText("AAAA-MM-DD");
            model = (DefaultTableModel) t_datos.getModel();
            model.getDataVector().removeAllElements();
            t_datos.revalidate();
        }
    }//GEN-LAST:event_b_fecha_siniestro2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
        jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" }));
        String ruta = null;
        DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
        formatoPorcentaje.setMinimumFractionDigits(2);
        if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
            ruta = jF1.getSelectedFile().getAbsolutePath();
            if (ruta != null) {
                File archivoXLS = new File(ruta + ".xls");
                try {
                    if (archivoXLS.exists())
                        archivoXLS.delete();
                    archivoXLS.createNewFile();
                    Workbook libro = new HSSFWorkbook();
                    FileOutputStream archivo = new FileOutputStream(archivoXLS);
                    Sheet hoja = libro.createSheet("reporte1");
                    for (int ren = 0; ren < (t_datos.getRowCount() + 1); ren++) {
                        Row fila = hoja.createRow(ren);
                        for (int col = 0; col < t_datos.getColumnCount(); col++) {
                            Cell celda = fila.createCell(col);
                            if (ren == 0) {
                                celda.setCellValue(t_datos.getColumnName(col));
                            } else {
                                try {
                                    if (col == 1) {
                                        String[] vec = t_datos.getValueAt(ren, col).toString().split("T");
                                        if (vec.length > 0)
                                            celda.setCellValue(vec[0]);
                                        else
                                            celda.setCellValue("");
                                    } else {
                                        if (col == 7)
                                            celda.setCellValue(
                                                    formatoPorcentaje.format(t_datos.getValueAt(ren - 1, col)));
                                        else
                                            celda.setCellValue(t_datos.getValueAt(ren - 1, col).toString());
                                    }
                                } catch (Exception e) {
                                    celda.setCellValue("");
                                }
                            }
                        }
                    }
                    libro.write(archivo);
                    archivo.close();
                    Desktop.getDesktop().open(archivoXLS);
                } catch (Exception e) {
                    System.out.println(e);
                    JOptionPane.showMessageDialog(this,
                            "No se pudo realizar el reporte si el archivo esta abierto");
                }
            }
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        if (t_datos.getRowCount() > 0) {
            javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
            jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" }));
            String ruta = null;
            if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
                ruta = jF1.getSelectedFile().getAbsolutePath();
                if (ruta != null) {
                    Session session = HibernateUtil.getSessionFactory().openSession();
                    try {
                        DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
                        formatoPorcentaje.setMinimumFractionDigits(2);
                        session.beginTransaction().begin();
                        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
                                BaseFont.NOT_EMBEDDED);
                        //Orden ord=buscaApertura();
                        PDF reporte = new PDF();
                        Date fecha = new Date();
                        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
                        String valor = dateFormat.format(fecha);

                        reporte.Abrir2(PageSize.LETTER.rotate(), "Reporte Contabilidad", ruta + ".pdf");
                        Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL);
                        BaseColor contenido = BaseColor.WHITE;
                        int centro = Element.ALIGN_CENTER;
                        int izquierda = Element.ALIGN_LEFT;
                        int derecha = Element.ALIGN_RIGHT;
                        float[] nuevos = new float[] { 36, 75, 95, 250, 145, 36, 47, 65, 90, 70, 140 };

                        PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_LEFT);

                        cabecera(reporte, bf, tabla, "Reporte de Cuentas por Cobrar", 1);
                        for (int ren = 0; ren < t_datos.getRowCount(); ren++) {
                            for (int col = 0; col < t_datos.getColumnCount(); col++) {
                                try {
                                    if (col == 1) {
                                        String[] vec = t_datos.getValueAt(ren, col).toString().split("T");
                                        if (vec.length > 0)
                                            tabla.addCell(reporte.celda(vec[0], font, contenido, derecha, 0, 1,
                                                    Rectangle.RECTANGLE));
                                        else
                                            tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1,
                                                    Rectangle.RECTANGLE));
                                    } else {
                                        if (col == 7)
                                            tabla.addCell(reporte.celda(
                                                    formatoPorcentaje.format(t_datos.getValueAt(ren, col)), font,
                                                    contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                        else
                                            tabla.addCell(reporte.celda(t_datos.getValueAt(ren, col).toString(),
                                                    font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                                    }
                                } catch (Exception e) {
                                    tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1,
                                            Rectangle.RECTANGLE));
                                }
                            }
                        }
                        tabla.setHeaderRows(1);
                        reporte.agregaObjeto(tabla);
                        reporte.cerrar();
                        reporte.visualizar2(ruta + ".pdf");
                    } catch (Exception e) {
                        System.out.println(e);
                        e.printStackTrace();
                        JOptionPane.showMessageDialog(this,
                                "No se pudo realizar el reporte si el archivo esta abierto.");
                    }
                    if (session != null)
                        if (session.isOpen())
                            session.close();
                }
            }
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            valores = lista.getSelectedValues();
            session.beginTransaction();
            if (cb.getSelectedItem().toString().compareTo("FACTURA") == 0) {
                Criteria consulta = session.createCriteria(Factura.class);
                if (valores.length > 0)
                    consulta.add(Restrictions.in("estatus", valores));
                String campo = "fecha";
                if (cb_fecha.getSelectedItem().toString().compareToIgnoreCase("Estatus") == 0)
                    campo = "f_estatus";
                if (t_fecha3.getText().compareTo("AAAA-MM-DD") != 0) {
                    consulta.add(Restrictions.sqlRestriction(
                            "STR_TO_DATE(" + campo + ", '%Y-%m-%d') >= '" + t_fecha3.getText() + "'"));
                }
                if (t_fecha4.getText().compareTo("AAAA-MM-DD") != 0) {
                    consulta.add(Restrictions.sqlRestriction(
                            "STR_TO_DATE(" + campo + ", '%Y-%m-%d') <= '" + t_fecha4.getText() + "'"));
                }
                Factura[] facturas = (Factura[]) consulta.list().toArray(new Factura[0]);
                model = (DefaultTableModel) t_datos.getModel();
                if (facturas.length > 0) {
                    model.getDataVector().removeAllElements();
                    for (int x = 0; x < facturas.length; x++) {
                        Factura actor = (Factura) facturas[x];
                        Object[] renglon = new Object[11];

                        //"ID", "FECHA", "RFC", "R. SOCIAL", "F. FISCAL", "SERIE", "FOLIO", "MONTO", "ESTATUS", "F. ESTATUS", "NOTAS"
                        renglon[0] = "" + actor.getIdFactura();
                        if (actor.getFechaFiscal() != null)
                            renglon[1] = actor.getFechaFiscal();
                        else
                            renglon[1] = "";
                        renglon[2] = actor.getRfcReceptor();
                        renglon[3] = actor.getNombreReceptor();
                        renglon[4] = actor.getFFiscal();
                        renglon[5] = actor.getSerie();
                        renglon[6] = actor.getFolio();
                        Concepto[] ren = (Concepto[]) actor.getConceptos().toArray(new Concepto[0]);
                        BigDecimal total = new BigDecimal("0.0");
                        for (int w = 0; w < actor.getConceptos().size(); w++) {
                            BigDecimal cantidad = new BigDecimal("" + ren[w].getCantidad());
                            BigDecimal precio = new BigDecimal("" + ren[w].getPrecio());
                            BigDecimal descuento = new BigDecimal("" + ren[w].getDescuento());
                            descuento = descuento.divide(new BigDecimal("100"));
                            BigDecimal subtotal = cantidad.multiply(precio).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal resta = subtotal.multiply(descuento).setScale(2, BigDecimal.ROUND_HALF_UP);
                            total = total.add(subtotal.subtract(resta)).setScale(2, BigDecimal.ROUND_HALF_UP);
                        }
                        BigDecimal iva = new BigDecimal("" + actor.getIva());
                        iva = iva.divide(new BigDecimal("100"));
                        total = total.add(total.multiply(iva));
                        //Double.parseDouble(total.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        renglon[7] = total.setScale(2, RoundingMode.HALF_UP).doubleValue();

                        renglon[8] = actor.getEstatus();
                        if (actor.getfEstatus() != null)
                            renglon[9] = actor.getfEstatus().toString();
                        else
                            renglon[9] = "";
                        renglon[10] = actor.getTexto();
                        model.addRow(renglon);
                    }
                } else
                    model.getDataVector().removeAllElements();
            } else {
                Criteria consulta = session.createCriteria(Nota.class);
                if (valores.length > 0)
                    consulta.add(Restrictions.in("estatus", valores));
                String campo = "fecha";
                if (cb_fecha.getSelectedItem().toString().compareToIgnoreCase("Estatus") == 0)
                    campo = "f_estatus";
                if (t_fecha3.getText().compareTo("AAAA-MM-DD") != 0) {
                    consulta.add(Restrictions.sqlRestriction(
                            "STR_TO_DATE(" + campo + ", '%Y-%m-%d') >= '" + t_fecha3.getText() + "'"));
                }
                if (t_fecha4.getText().compareTo("AAAA-MM-DD") != 0) {
                    consulta.add(Restrictions.sqlRestriction(
                            "STR_TO_DATE(" + campo + ", '%Y-%m-%d') <= '" + t_fecha4.getText() + "'"));
                }
                Nota[] nota = (Nota[]) consulta.list().toArray(new Nota[0]);
                model = (DefaultTableModel) t_datos.getModel();
                if (nota.length > 0) {
                    model.getDataVector().removeAllElements();
                    for (int x = 0; x < nota.length; x++) {
                        Nota actor = (Nota) nota[x];
                        Object[] renglon = new Object[11];

                        //"ID", "FECHA", "RFC", "R. SOCIAL", "F. FISCAL", "SERIE", "FOLIO", "MONTO", "ESTATUS", "F. ESTATUS", "NOTAS"
                        renglon[0] = "" + actor.getIdNota();
                        if (actor.getFechaFiscal() != null)
                            renglon[1] = actor.getFechaFiscal();
                        else
                            renglon[1] = "";
                        renglon[2] = actor.getRfcReceptor();
                        renglon[3] = actor.getNombreReceptor();
                        renglon[4] = actor.getFFiscal();
                        renglon[5] = actor.getSerie();
                        renglon[6] = actor.getFolio();
                        Concepto[] ren = (Concepto[]) actor.getConceptos().toArray(new Concepto[0]);
                        BigDecimal total = new BigDecimal("0.0");
                        for (int w = 0; w < actor.getConceptos().size(); w++) {
                            BigDecimal cantidad = new BigDecimal("" + ren[w].getCantidad());
                            BigDecimal precio = new BigDecimal("" + ren[w].getPrecio());
                            BigDecimal descuento = new BigDecimal("" + ren[w].getDescuento());
                            descuento = descuento.divide(new BigDecimal("100"));
                            BigDecimal subtotal = cantidad.multiply(precio).setScale(2, BigDecimal.ROUND_HALF_UP);
                            BigDecimal resta = subtotal.multiply(descuento).setScale(2, BigDecimal.ROUND_HALF_UP);
                            total = total.add(subtotal.subtract(resta)).setScale(2, BigDecimal.ROUND_HALF_UP);
                        }
                        BigDecimal iva = new BigDecimal("" + actor.getIva());
                        iva = iva.divide(new BigDecimal("100"));
                        total = total.add(total.multiply(iva));
                        //Double.parseDouble(total.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                        renglon[7] = total.setScale(2, RoundingMode.HALF_UP).doubleValue();

                        renglon[8] = actor.getEstatus();
                        if (actor.getfEstatus() != null)
                            renglon[9] = actor.getfEstatus().toString();
                        else
                            renglon[9] = "";
                        renglon[10] = actor.getTexto();
                        model.addRow(renglon);
                    }
                } else
                    model.getDataVector().removeAllElements();
            }
            t_datos.revalidate();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (session != null)
            if (session.isOpen())
                session.close();
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton b_fecha_siniestro2;
    private javax.swing.JButton b_fecha_siniestro3;
    private javax.swing.JComboBox cb;
    private javax.swing.JComboBox cb_fecha;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JList lista;
    private javax.swing.JTable t_datos;
    private javax.swing.JTextField t_fecha3;
    private javax.swing.JTextField t_fecha4;
    // End of variables declaration//GEN-END:variables

public void formatoTabla()
{
    Color c1 = new java.awt.Color(2, 135, 242);
    for(int x=0; x<t_datos.getColumnModel().getColumnCount(); x++)
        t_datos.getColumnModel().getColumn(x).setHeaderRenderer(new Render1(c1));
    tabla_tamaos();
    t_datos.setShowVerticalLines(true);
    t_datos.setShowHorizontalLines(true);
        
    t_datos.setDefaultRenderer(Double.class, formato); 
    t_datos.setDefaultRenderer(String.class, formato); 
}

public void tabla_tamaos()
{
    TableColumnModel col_model = t_datos.getColumnModel();
    for (int i=0; i<t_datos.getColumnCount(); i++)
    {
        TableColumn column = col_model.getColumn(i);
        switch(i)
        {
            case 0:
                column.setPreferredWidth(80);
                break;
            case 1:
                column.setPreferredWidth(140);
                break;    
            case 2:
                column.setPreferredWidth(140);
                break;
            case 3:
                column.setPreferredWidth(320);
                break;      
            case 4:
                column.setPreferredWidth(290);
                break; 
            case 5:
                column.setPreferredWidth(50);
                break; 
            case 6:
                column.setPreferredWidth(80);
                break; 
            case 7:
                column.setPreferredWidth(100);
                break; 
            case 8:
                column.setPreferredWidth(100);
                break; 
            case 9:
                column.setPreferredWidth(100);
                break; 
            case 10:
                column.setPreferredWidth(160);
                break; 
            default:
                column.setPreferredWidth(50);
                break; 
        }
    }
    JTableHeader header = t_datos.getTableHeader();
    header.setForeground(Color.white);
}

    public void cabecera(PDF reporte, BaseFont bf, PdfPTable tabla, String titulo1, int op) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            reporte.contenido.setLineWidth(0.5f);
            reporte.contenido.setColorStroke(new GrayColor(0.2f));
            reporte.contenido.setColorFill(new GrayColor(0.9f));

            Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
            reporte.inicioTexto();
            reporte.contenido.setFontAndSize(bf, 14);
            reporte.contenido.setColorFill(BaseColor.BLACK);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 35, 570, 0);
            reporte.contenido.setFontAndSize(bf, 8);
            reporte.contenido.setColorFill(BaseColor.BLACK);
            String titulo = titulo1;
            if (op == 1) {
                if (t_fecha3.getText().compareTo("AAAA-MM-DD") != 0)
                    titulo += " apartir del " + t_fecha3.getText();

                if (t_fecha4.getText().compareTo("AAAA-MM-DD") != 0)
                    titulo += " al " + t_fecha4.getText();
            }
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, titulo, 35, 560, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                    "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 750, 570, 0);
            if (op == 1) {
                if (valores != null) {
                    String val = "Estatus: ";
                    if (lista.getSelectedValues().length > 0) {
                        for (int m = 0; m < valores.length; m++) {
                            val += valores[m].toString() + ", ";
                        }
                        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT, val, 750, 560, 0);
                    } else {
                        for (int mm = 0; mm < lista.getModel().getSize(); mm++) {
                            val += lista.getModel().getElementAt(mm).toString() + ", ";
                        }
                        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT, val, 750, 560, 0);
                    }
                }
            }

            reporte.finTexto();
            //agregamos renglones vacios para dejar un espacio
            reporte.agregaObjeto(new Paragraph(" "));

            Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);

            BaseColor cabecera = BaseColor.GRAY;
            BaseColor contenido = BaseColor.WHITE;
            int centro = Element.ALIGN_CENTER;
            int izquierda = Element.ALIGN_LEFT;
            int derecha = Element.ALIGN_RIGHT;
            if (op == 1) {
                for (int a = 0; a < tabla.getNumberOfColumns(); a++) {
                    tabla.addCell(reporte.celda(t_datos.getColumnName(a), font, cabecera, centro, 0, 1,
                            Rectangle.RECTANGLE));
                }
            }
        } catch (Exception e) {
            System.out.println(e);
        }
        if (session != null)
            if (session.isOpen())
                session.close();
    }
}