Contabilidad.NuevaFactura.java Source code

Java tutorial

Introduction

Here is the source code for Contabilidad.NuevaFactura.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 Clientes.altaCliente;
import Clientes.buscaCliente;
import Compania.buscaCompania;
import Hibernate.Util.HibernateUtil;
import Hibernate.entidades.Clientes;
import Hibernate.entidades.Compania;
import Hibernate.entidades.Concepto;
import Hibernate.entidades.Configuracion;
import Hibernate.entidades.Factura;
import Hibernate.entidades.Marca;
import Hibernate.entidades.Orden;
import Hibernate.entidades.OrdenExterna;
import Hibernate.entidades.Tipo;
import Hibernate.entidades.Usuario;
import Integral.ExtensionFileFilter;
import Integral.FormatoEditor;
import Integral.FormatoEditorTexto;
import Marca.buscaMarca;
import Tipo.buscaTipo;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Calendar;
import java.util.Vector;
import javax.swing.DefaultCellEditor;
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.hibernate.Session;
import Integral.FormatoTabla;
import Integral.Herramientas;
import Integral.Render1;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
import javax.swing.JTable;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.hibernate.HibernateException;

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

    String[] columnas = new String[] { "Can", "Med", "Descripcin", "Costo c/u", "Descuento", "Total" };
    FormatoTabla formato;
    Usuario user;
    String sessionPrograma;
    Herramientas h;
    DefaultTableModel model;
    int iva = 0;
    Factura factura = new Factura();

    /**
     * Creates new form altaFactura
     */
    public NuevaFactura(Usuario u, String ses, int iva) {
        initComponents();
        this.iva = iva;
        user = u;
        sessionPrograma = ses;
        t_datos.setModel(ModeloTablaReporte(0, columnas));
        formato = new FormatoTabla();
        formatoTabla();

    }

    /**
     * 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() {

        alerta = new javax.swing.JDialog();
        jLabel21 = new javax.swing.JLabel();
        progreso = new javax.swing.JProgressBar();
        addendas = new javax.swing.JDialog();
        jLabel24 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        medida = new javax.swing.JComboBox();
        texto = new javax.swing.JTextField();
        t_receptor = new javax.swing.JTextField();
        t_email = new javax.swing.JTextField();
        aviso = new javax.swing.JFileChooser();
        jPanel1 = new javax.swing.JPanel();
        p_cliente = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        t_cliente = new javax.swing.JTextField();
        t_direccion = new javax.swing.JTextField();
        t_colonia = new javax.swing.JTextField();
        t_rfc = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        t_municipio = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        t_cp = new javax.swing.JTextField();
        c_estado = new javax.swing.JComboBox();
        c_pais = new javax.swing.JComboBox();
        jLabel23 = new javax.swing.JLabel();
        t_numero_exterior = new javax.swing.JTextField();
        c_cliente = new javax.swing.JComboBox();
        b_buscar = new javax.swing.JButton();
        Selecciona2 = new javax.swing.JButton();
        b_actualiza = new javax.swing.JButton();
        t_id = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        p_orden = new javax.swing.JPanel();
        l_asegurado = new javax.swing.JLabel();
        t_asegurado = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        t_marca = new javax.swing.JTextField();
        t_tipo = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        t_serie = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        t_modelo = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        t_placas = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        t_poliza = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        t_siniestro = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        t_reporte = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        t_inc = new javax.swing.JTextField();
        b_tipo = new javax.swing.JButton();
        b_marca = new javax.swing.JButton();
        p_totales = new javax.swing.JPanel();
        b_guardar = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        l_subtotal = new javax.swing.JLabel();
        t_subtotal = new javax.swing.JFormattedTextField();
        t_iva = new javax.swing.JFormattedTextField();
        l_iva = new javax.swing.JLabel();
        l_total = new javax.swing.JLabel();
        t_total = new javax.swing.JFormattedTextField();
        t_iva1 = new javax.swing.JFormattedTextField();
        t_descuento = new javax.swing.JFormattedTextField();
        l_iva1 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        t_noFactura = new javax.swing.JTextField();
        b_mas = new javax.swing.JButton();
        b_menos = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        t_datos = new javax.swing.JTable();

        alerta.setTitle("Conectando");
        alerta.setModalExclusionType(null);
        alerta.setModalityType(null);

        jLabel21.setFont(new java.awt.Font("Droid Sans", 3, 14)); // NOI18N
        jLabel21.setText("Generar Factura Electronica");

        javax.swing.GroupLayout alertaLayout = new javax.swing.GroupLayout(alerta.getContentPane());
        alerta.getContentPane().setLayout(alertaLayout);
        alertaLayout.setHorizontalGroup(alertaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(alertaLayout.createSequentialGroup().addContainerGap().addComponent(jLabel21)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, alertaLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(progreso, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(31, 31, 31)));
        alertaLayout.setVerticalGroup(alertaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(alertaLayout.createSequentialGroup().addContainerGap().addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(progreso, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        addendas.setTitle("Facturacion Electrnica");
        addendas.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);

        jLabel24.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel24.setText("Selecciona el tipo de Addenda a utilizar para facturar");

        jButton1.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jButton1.setText("Qualitas Talleres");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jButton2.setText("Axa Talleres");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton4.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jButton4.setText("GNP Talleres");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jButton5.setText("General");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout addendasLayout = new javax.swing.GroupLayout(addendas.getContentPane());
        addendas.getContentPane().setLayout(addendasLayout);
        addendasLayout.setHorizontalGroup(addendasLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(addendasLayout.createSequentialGroup().addContainerGap().addGroup(addendasLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel24)
                        .addGroup(addendasLayout.createSequentialGroup().addGap(41, 41, 41)
                                .addGroup(addendasLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(addendasLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 98,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 98,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap(13, Short.MAX_VALUE)));
        addendasLayout.setVerticalGroup(addendasLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(addendasLayout.createSequentialGroup().addContainerGap().addComponent(jLabel24)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(addendasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jButton1).addComponent(jButton5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(addendasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton2).addComponent(jButton4))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        addendas.getAccessibleContext().setAccessibleParent(null);

        medida.setFont(new java.awt.Font("Dialog", 0, 9)); // NOI18N
        medida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PZAS", "LTS", "MTS", "CMS", "MMS",
                "GRS", "MLS", "KGS", "HRS", "MIN", "KIT", "FT", "LB", "JGO", "NA" }));

        texto.setBorder(null);
        texto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                textoFocusGained(evt);
            }
        });
        texto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                textoKeyTyped(evt);
            }
        });

        aviso.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
        aviso.setDialogTitle("Examinar");

        setLayout(new java.awt.BorderLayout());

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

        p_cliente.setBackground(new java.awt.Color(254, 254, 254));
        p_cliente.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Datos del cliente",
                javax.swing.border.TitledBorder.RIGHT, javax.swing.border.TitledBorder.TOP));

        jLabel2.setText("R.social");

        jLabel3.setForeground(new java.awt.Color(13, 132, 254));
        jLabel3.setText("Dir:");

        jLabel4.setText("Colonia:");

        t_cliente.setToolTipText("Razn social del receptor");
        t_cliente.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_cliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_clienteKeyTyped(evt);
            }
        });

        t_direccion.setToolTipText("Calle del receptor");
        t_direccion.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_direccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_direccionKeyTyped(evt);
            }
        });

        t_colonia.setToolTipText("Colonia del receptor");
        t_colonia.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_colonia.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_coloniaKeyTyped(evt);
            }
        });

        t_rfc.setToolTipText("RFC del receptor");
        t_rfc.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_rfc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_rfcKeyTyped(evt);
            }
        });

        jLabel5.setForeground(new java.awt.Color(13, 132, 254));
        jLabel5.setText("RFC:");

        jLabel6.setForeground(new java.awt.Color(13, 132, 254));
        jLabel6.setText("Municipio:");

        t_municipio.setToolTipText("Municipio del receptor");
        t_municipio.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_municipio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_municipioKeyTyped(evt);
            }
        });

        jLabel7.setForeground(new java.awt.Color(13, 132, 254));
        jLabel7.setText("Estado:");

        jLabel8.setForeground(new java.awt.Color(13, 132, 254));
        jLabel8.setText("Pais:");

        jLabel9.setForeground(new java.awt.Color(13, 132, 254));
        jLabel9.setText("CP:");

        t_cp.setToolTipText("Codigo postal del receptor");
        t_cp.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_cp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_cpKeyTyped(evt);
            }
        });

        c_estado.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "AGUASCALIENTES", "BAJA CALIFORNIA", "BAJA CALIFORNIA SUR", "CAMPECHE", "CHIAPAS",
                        "CHIHUAHUA", "COAHUILA", "COLIMA", "DISTRITO FEDERAL", "DURANGO", "ESTADO DE MEXICO",
                        "GUANAJUATO", "GUERRERO", "HIDALGO", "JALISCO", "MICHOACAN", "MORELOS", "NAYARIT",
                        "NUEVO LEON", "OAXACA", "PUEBLA", "QUERETARO", "QUINTANA ROO", "SAN LUIS POTOSI", "SINALOA",
                        "SONORA", "TABASCO", "TAMAULIPAS", "TLAXCALA", "VERACRUZ", "YUCATAN", "ZACATECAS" }));
        c_estado.setToolTipText("Estado del receptor");

        c_pais.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AD", "AE", "AF", "AG", "AI", "AL",
                "AM", "AN", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF",
                "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA",
                "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CX", "CY",
                "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ",
                "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP",
                "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL",
                "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM",
                "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV",
                "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR",
                "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO",
                "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS",
                "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH",
                "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SY", "SZ", "TC", "TD", "TF", "TG",
                "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US",
                "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW" }));
        c_pais.setSelectedItem("MX");
        c_pais.setToolTipText("Pais del receptor");

        jLabel23.setForeground(new java.awt.Color(13, 132, 254));
        jLabel23.setText("No Ex:");

        t_numero_exterior.setToolTipText("Nmero exterior del emisor");
        t_numero_exterior.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_numero_exterior.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_numero_exteriorKeyTyped(evt);
            }
        });

        c_cliente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Compaia", "Cliente" }));
        c_cliente.setToolTipText("Tipo de receptor a buscar");
        c_cliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                c_clienteActionPerformed(evt);
            }
        });

        b_buscar.setText("Buscar");
        b_buscar.setToolTipText("Consultar datos de cliente o compaia");
        b_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_buscarActionPerformed(evt);
            }
        });

        Selecciona2.setBackground(new java.awt.Color(2, 135, 242));
        Selecciona2.setForeground(new java.awt.Color(254, 254, 254));
        Selecciona2.setText("Nuevo cliente");
        Selecciona2.setToolTipText("Agregar un registo actual");
        Selecciona2.setFocusable(false);
        Selecciona2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        Selecciona2.setMaximumSize(new java.awt.Dimension(87, 23));
        Selecciona2.setMinimumSize(new java.awt.Dimension(87, 23));
        Selecciona2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Selecciona2ActionPerformed(evt);
            }
        });

        b_actualiza.setBackground(new java.awt.Color(2, 135, 242));
        b_actualiza.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        b_actualiza.setForeground(new java.awt.Color(254, 254, 254));
        b_actualiza.setIcon(new ImageIcon("imagenes/guardar.png"));
        b_actualiza.setText("Actualizar");
        b_actualiza.setToolTipText("Actualizar datos del cliente");
        b_actualiza.setEnabled(false);
        b_actualiza.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_actualizaActionPerformed(evt);
            }
        });

        t_id.setToolTipText("Numero de compaia o cliente");
        t_id.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_id.setEnabled(false);

        jLabel11.setText("Id:");

        javax.swing.GroupLayout p_clienteLayout = new javax.swing.GroupLayout(p_cliente);
        p_cliente.setLayout(p_clienteLayout);
        p_clienteLayout.setHorizontalGroup(p_clienteLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(p_clienteLayout.createSequentialGroup()
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(p_clienteLayout.createSequentialGroup().addComponent(jLabel4)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_colonia, javax.swing.GroupLayout.PREFERRED_SIZE, 220,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(p_clienteLayout.createSequentialGroup().addComponent(jLabel7)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(c_estado, javax.swing.GroupLayout.PREFERRED_SIZE, 220,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel6).addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_clienteLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(t_municipio, javax.swing.GroupLayout.PREFERRED_SIZE, 192,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(p_clienteLayout.createSequentialGroup()
                                        .addComponent(c_pais, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel23)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_numero_exterior, javax.swing.GroupLayout.PREFERRED_SIZE, 75,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                .addGroup(p_clienteLayout.createSequentialGroup()
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel3).addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(t_cliente, javax.swing.GroupLayout.PREFERRED_SIZE, 318,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(t_direccion, javax.swing.GroupLayout.PREFERRED_SIZE, 318,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        p_clienteLayout.createSequentialGroup().addComponent(jLabel5)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_rfc, javax.swing.GroupLayout.PREFERRED_SIZE, 113,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        p_clienteLayout.createSequentialGroup().addComponent(jLabel9)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_cp, javax.swing.GroupLayout.PREFERRED_SIZE, 113,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(p_clienteLayout.createSequentialGroup().addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(t_id, javax.swing.GroupLayout.PREFERRED_SIZE, 113,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(59, 59, 59).addComponent(b_actualiza)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(Selecciona2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(c_cliente, javax.swing.GroupLayout.PREFERRED_SIZE, 136,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(b_buscar)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        p_clienteLayout.setVerticalGroup(p_clienteLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(p_clienteLayout.createSequentialGroup().addGroup(p_clienteLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel11).addComponent(t_id, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(c_cliente, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(b_buscar)
                                .addComponent(Selecciona2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(b_actualiza)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2)
                                .addComponent(t_cliente, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel5).addComponent(t_rfc, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(t_direccion, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel9).addComponent(t_cp, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4)
                                .addComponent(t_colonia, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel6).addComponent(t_municipio,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel7).addComponent(jLabel8)
                                .addComponent(c_estado, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(c_pais, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel23).addComponent(t_numero_exterior,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        p_orden.setBackground(new java.awt.Color(254, 254, 254));
        p_orden.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Datos de la Orden",
                javax.swing.border.TitledBorder.RIGHT, javax.swing.border.TitledBorder.TOP));

        l_asegurado.setText("Asegurado:");

        t_asegurado.setToolTipText("Nombre del asegurado");
        t_asegurado.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_asegurado.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_aseguradoKeyTyped(evt);
            }
        });

        jLabel12.setText("Marca:");

        t_marca.setToolTipText("Marca de la unidad");
        t_marca.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_marca.setEnabled(false);

        t_tipo.setToolTipText("Tipo de la unidad");
        t_tipo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_tipo.setEnabled(false);

        jLabel13.setText("Tipo:");

        t_serie.setToolTipText("Nmero de serie de la unidad");
        t_serie.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_serie.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_serieKeyTyped(evt);
            }
        });

        jLabel14.setText("Serie:");

        jLabel15.setText("Modelo:");

        t_modelo.setToolTipText("Ao de fabricacin de la unidad");
        t_modelo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_modelo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_modeloKeyTyped(evt);
            }
        });

        jLabel16.setText("Placas:");

        t_placas.setToolTipText("Nmero de placas de la unidad");
        t_placas.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_placas.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_placasKeyTyped(evt);
            }
        });

        jLabel17.setText("Poliza:");

        t_poliza.setToolTipText("Nmero de poliza");
        t_poliza.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_poliza.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_polizaKeyTyped(evt);
            }
        });

        jLabel18.setText("Siniestro:");

        t_siniestro.setToolTipText("Nmero de siniestro");
        t_siniestro.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_siniestro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_siniestroKeyTyped(evt);
            }
        });

        jLabel19.setText("Reporte:");

        t_reporte.setToolTipText("Nmero de reporte");
        t_reporte.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_reporte.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_reporteKeyTyped(evt);
            }
        });

        jLabel20.setText("INC:");

        t_inc.setToolTipText("Nmero de inciso");
        t_inc.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_inc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_incKeyTyped(evt);
            }
        });

        b_tipo.setBackground(new java.awt.Color(2, 135, 242));
        b_tipo.setIcon(new ImageIcon("imagenes/buscar.png"));
        b_tipo.setToolTipText("Consultar Tipos de vehculo");
        b_tipo.setMargin(new java.awt.Insets(1, 14, 1, 14));
        b_tipo.setMaximumSize(new java.awt.Dimension(28, 24));
        b_tipo.setMinimumSize(new java.awt.Dimension(28, 24));
        b_tipo.setPreferredSize(new java.awt.Dimension(28, 24));
        b_tipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_tipoActionPerformed(evt);
            }
        });

        b_marca.setBackground(new java.awt.Color(2, 135, 242));
        b_marca.setIcon(new ImageIcon("imagenes/buscar.png"));
        b_marca.setToolTipText("Consultar marcas");
        b_marca.setMaximumSize(new java.awt.Dimension(32, 8));
        b_marca.setMinimumSize(new java.awt.Dimension(32, 8));
        b_marca.setPreferredSize(new java.awt.Dimension(28, 24));
        b_marca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_marcaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout p_ordenLayout = new javax.swing.GroupLayout(p_orden);
        p_orden.setLayout(p_ordenLayout);
        p_ordenLayout.setHorizontalGroup(p_ordenLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(p_ordenLayout.createSequentialGroup().addContainerGap().addGroup(p_ordenLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(p_ordenLayout.createSequentialGroup().addComponent(l_asegurado)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_asegurado, javax.swing.GroupLayout.PREFERRED_SIZE, 212,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel20)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_inc, javax.swing.GroupLayout.PREFERRED_SIZE, 59,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(p_ordenLayout.createSequentialGroup().addGroup(p_ordenLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, p_ordenLayout
                                        .createSequentialGroup().addComponent(jLabel12)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_marca)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(b_marca, javax.swing.GroupLayout.PREFERRED_SIZE, 28,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                        p_ordenLayout.createSequentialGroup().addComponent(jLabel18)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_siniestro, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(0, 0, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                        p_ordenLayout.createSequentialGroup().addComponent(jLabel16)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_placas))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                        p_ordenLayout.createSequentialGroup().addComponent(jLabel14)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_serie)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(p_ordenLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(p_ordenLayout.createSequentialGroup().addGroup(p_ordenLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel19)
                                                .addComponent(jLabel17, javax.swing.GroupLayout.Alignment.TRAILING))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(p_ordenLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(t_poliza).addComponent(t_reporte)))
                                        .addGroup(p_ordenLayout.createSequentialGroup().addGroup(p_ordenLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel13).addComponent(jLabel15))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(p_ordenLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(t_modelo)
                                                        .addGroup(p_ordenLayout.createSequentialGroup()
                                                                .addComponent(t_tipo)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(b_tipo,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 28,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                        .addContainerGap()));
        p_ordenLayout.setVerticalGroup(p_ordenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(p_ordenLayout.createSequentialGroup().addGroup(p_ordenLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel20)
                        .addComponent(t_inc, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(l_asegurado).addComponent(t_asegurado, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_ordenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(p_ordenLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel12)
                                        .addComponent(t_marca, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel13).addComponent(t_tipo,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(b_tipo, javax.swing.GroupLayout.PREFERRED_SIZE, 24,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(b_marca, javax.swing.GroupLayout.PREFERRED_SIZE, 24,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(11, 11, 11)
                        .addGroup(p_ordenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel14)
                                .addComponent(t_serie, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel15).addComponent(t_modelo,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_ordenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel16)
                                .addComponent(t_placas, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel17).addComponent(t_poliza,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_ordenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel18)
                                .addComponent(t_siniestro, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel19).addComponent(t_reporte,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(p_orden, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(6, 6, 6).addComponent(p_cliente, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)));
        jPanel1Layout
                .setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(p_cliente, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(p_orden, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(0, 0, Short.MAX_VALUE)));

        add(jPanel1, java.awt.BorderLayout.PAGE_START);

        p_totales.setBackground(new java.awt.Color(2, 135, 242));

        b_guardar.setIcon(new ImageIcon("imagenes/guardar.png"));
        b_guardar.setText("Guardar");
        b_guardar.setToolTipText("Guardar la factura en la base de datos");
        b_guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_guardarActionPerformed(evt);
            }
        });

        jPanel5.setBackground(new java.awt.Color(2, 135, 242));
        jPanel5.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        l_subtotal.setFont(new java.awt.Font("Arial", 0, 9)); // NOI18N
        l_subtotal.setForeground(new java.awt.Color(255, 255, 255));
        l_subtotal.setText("Subtotal:");
        jPanel5.add(l_subtotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(52, 4, -1, -1));

        t_subtotal.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_subtotal.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        t_subtotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        t_subtotal.setText("0.00");
        t_subtotal.setToolTipText("Subtotal antes de iva");
        t_subtotal.setEnabled(false);
        t_subtotal.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jPanel5.add(t_subtotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(105, 0, 88, -1));

        t_iva.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_iva.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        t_iva.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        t_iva.setText("0.00");
        t_iva.setToolTipText("Total de iva");
        t_iva.setEnabled(false);
        t_iva.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jPanel5.add(t_iva, new org.netbeans.lib.awtextra.AbsoluteConstraints(105, 20, 88, -1));

        l_iva.setFont(new java.awt.Font("Arial", 0, 9)); // NOI18N
        l_iva.setForeground(new java.awt.Color(255, 255, 255));
        l_iva.setText("% I.V.A.:");
        jPanel5.add(l_iva, new org.netbeans.lib.awtextra.AbsoluteConstraints(48, 23, -1, -1));

        l_total.setFont(new java.awt.Font("Arial", 0, 9)); // NOI18N
        l_total.setForeground(new java.awt.Color(255, 255, 255));
        l_total.setText("Total:");
        jPanel5.add(l_total, new org.netbeans.lib.awtextra.AbsoluteConstraints(61, 44, -1, -1));

        t_total.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_total.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        t_total.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        t_total.setText("0.00");
        t_total.setToolTipText("Total neto");
        t_total.setEnabled(false);
        t_total.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jPanel5.add(t_total, new org.netbeans.lib.awtextra.AbsoluteConstraints(105, 41, 88, -1));

        t_iva1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_iva1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        t_iva1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        t_iva1.setToolTipText("Total de IVA");
        t_iva1.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        t_iva1.setValue(16);
        t_iva1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                t_iva1FocusLost(evt);
            }
        });
        t_iva1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_iva1ActionPerformed(evt);
            }
        });
        t_iva1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_iva1KeyTyped(evt);
            }
        });
        jPanel5.add(t_iva1, new org.netbeans.lib.awtextra.AbsoluteConstraints(1, 20, 40, -1));

        t_descuento.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_descuento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("0.00"))));
        t_descuento.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        t_descuento.setToolTipText("Agregar descuento global");
        t_descuento.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        t_descuento.setNextFocusableComponent(t_datos);
        t_descuento.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                t_descuentoFocusLost(evt);
            }
        });

        l_iva1.setFont(new java.awt.Font("Arial", 0, 9)); // NOI18N
        l_iva1.setForeground(new java.awt.Color(255, 255, 255));
        l_iva1.setText("Agregar Descuento:");

        jLabel22.setFont(new java.awt.Font("Arial", 0, 9)); // NOI18N
        jLabel22.setForeground(new java.awt.Color(255, 255, 255));
        jLabel22.setText("No Factura:");

        t_noFactura.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        t_noFactura.setToolTipText("Numero de factura");
        t_noFactura.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_noFactura.setEnabled(false);

        b_mas.setBackground(new java.awt.Color(2, 135, 242));
        b_mas.setForeground(new java.awt.Color(255, 255, 255));
        b_mas.setIcon(new ImageIcon("imagenes/boton_mas.png"));
        b_mas.setToolTipText("Agrega un concepto");
        b_mas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_masActionPerformed(evt);
            }
        });

        b_menos.setBackground(new java.awt.Color(2, 135, 242));
        b_menos.setForeground(new java.awt.Color(255, 255, 255));
        b_menos.setIcon(new ImageIcon("imagenes/boton_menos.png"));
        b_menos.setToolTipText("Eliminar un concepto");
        b_menos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_menosActionPerformed(evt);
            }
        });

        jButton7.setIcon(new ImageIcon("imagenes/nuevo.png"));
        jButton7.setText("Nuevo");
        jButton7.setToolTipText("Nueva factura(Elimina todo texto en los campos)");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton3.setText("Importar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout p_totalesLayout = new javax.swing.GroupLayout(p_totales);
        p_totales.setLayout(p_totalesLayout);
        p_totalesLayout.setHorizontalGroup(p_totalesLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(p_totalesLayout.createSequentialGroup().addContainerGap()
                        .addComponent(b_mas, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(b_menos, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(b_guardar).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton7).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_totalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        p_totalesLayout.createSequentialGroup().addComponent(jButton3)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        315, Short.MAX_VALUE)
                                                .addComponent(l_iva1).addGap(15, 15, 15))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        p_totalesLayout.createSequentialGroup().addComponent(jLabel22)
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(p_totalesLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(t_noFactura).addComponent(t_descuento,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE))
                        .addGap(28, 28, 28).addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 198,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)));
        p_totalesLayout.setVerticalGroup(p_totalesLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(p_totalesLayout.createSequentialGroup().addGroup(p_totalesLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(p_totalesLayout.createSequentialGroup().addGap(6, 6, 6).addGroup(p_totalesLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(p_totalesLayout.createSequentialGroup().addGap(3, 3, 3)
                                        .addGroup(p_totalesLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(l_iva1)
                                                .addComponent(b_mas, javax.swing.GroupLayout.PREFERRED_SIZE, 19,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(b_menos, javax.swing.GroupLayout.PREFERRED_SIZE, 21,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGroup(p_totalesLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(b_guardar).addComponent(jButton7)
                                                        .addComponent(jButton3))))
                                .addGroup(p_totalesLayout.createSequentialGroup()
                                        .addComponent(t_descuento, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(p_totalesLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(t_noFactura, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel22)))))
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        add(p_totales, java.awt.BorderLayout.PAGE_END);

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

        }, new String[] { "Cant", "Med", "Descripcin", "Costo c/u", "Descuento", "Total" }) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.Object.class, java.lang.String.class };
            boolean[] canEdit = new boolean[] { true, true, true, true, true, false };

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

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        t_datos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        t_datos.getTableHeader().setReorderingAllowed(false);
        t_datos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_datosKeyTyped(evt);
            }

            public void keyPressed(java.awt.event.KeyEvent evt) {
                t_datosKeyPressed(evt);
            }

            public void keyReleased(java.awt.event.KeyEvent evt) {
                t_datosKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(t_datos);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void t_clienteKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_clienteKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (t_cliente.getText().length() > 100)
            evt.consume();
    }//GEN-LAST:event_t_clienteKeyTyped

    private void t_direccionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_direccionKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (t_direccion.getText().length() >= 150)
            evt.consume();
    }//GEN-LAST:event_t_direccionKeyTyped

    private void t_coloniaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_coloniaKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (t_colonia.getText().length() >= 100)
            evt.consume();
    }//GEN-LAST:event_t_coloniaKeyTyped

    private void t_rfcKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_rfcKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (t_rfc.getText().length() >= 13)
            evt.consume();
    }//GEN-LAST:event_t_rfcKeyTyped

    private void t_cpKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_cpKeyTyped
        char car = evt.getKeyChar();
        if (t_cp.getText().length() >= 5)
            evt.consume();
        if ((car < '0' || car > '9'))
            evt.consume();
    }//GEN-LAST:event_t_cpKeyTyped

    private void t_municipioKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_municipioKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (t_municipio.getText().length() >= 100)
            evt.consume();
    }//GEN-LAST:event_t_municipioKeyTyped

    private void t_descuentoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_t_descuentoFocusLost
        // TODO add your handling code here:
        try {
            t_descuento.commitEdit();
            if (((Number) t_descuento.getValue()).doubleValue() <= 100.0d
                    && ((Number) t_descuento.getValue()).doubleValue() >= 0.0d) {
                for (int a = 0; a < t_datos.getRowCount(); a++) {
                    t_datos.setValueAt(((Number) t_descuento.getValue()).doubleValue(), a, 4);
                }
            } else
                t_descuento.setValue(0);
            this.sumaTotales();
        } catch (Exception e) {

        }
    }//GEN-LAST:event_t_descuentoFocusLost

    private void b_guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_guardarActionPerformed
        // TODO add your handling code here:
        boolean vacios = false;
        for (int c = 0; c < t_datos.getRowCount(); c++) {
            if (t_datos.getValueAt(c, 2).toString().compareTo("") == 0) {
                vacios = true;
                c = t_datos.getRowCount();
            }
        }
        if (vacios == false) {
            if (t_datos.getRowCount() > 0) {
                if (t_cliente.getText().trim().compareTo("") != 0) {
                    if (t_rfc.getText().compareTo("") != 0) {
                        if (t_direccion.getText().trim().compareTo("") != 0) {
                            if (t_numero_exterior.getText().compareTo("") != 0) {
                                if (t_cp.getText().compareTo("") != 0) {
                                    if (t_municipio.getText().compareTo("") != 0) {
                                        Session session = HibernateUtil.getSessionFactory().openSession();
                                        try {
                                            Calendar c1 = Calendar.getInstance();
                                            //Calendar c2 = new GregorianCalendar();
                                            session.beginTransaction().begin();
                                            OrdenExterna nueva = new OrdenExterna();
                                            if (t_asegurado.getText().trim().compareTo("") != 0)
                                                nueva.setAsegurado(t_asegurado.getText().trim());
                                            if (t_inc.getText().trim().compareTo("") != 0)
                                                nueva.setInciso(t_inc.getText().trim());
                                            if (t_marca.getText().trim().compareTo("") != 0) {
                                                Marca m1 = (Marca) session.get(Marca.class, t_marca.getText());
                                                nueva.setMarca(m1);
                                            }
                                            if (t_tipo.getText().trim().compareTo("") != 0) {
                                                Tipo t1 = (Tipo) session.get(Tipo.class, t_tipo.getText());
                                                nueva.setTipo(t1);
                                            }
                                            if (t_serie.getText().trim().compareTo("") != 0)
                                                nueva.setNoSerie(t_serie.getText().trim());
                                            if (t_modelo.getText().trim().compareTo("") != 0)
                                                nueva.setModelo(Integer.parseInt(t_modelo.getText().trim()));
                                            if (t_placas.getText().trim().compareTo("") != 0)
                                                nueva.setNoPlacas(t_placas.getText().trim());
                                            if (t_poliza.getText().trim().compareTo("") != 0)
                                                nueva.setPoliza(t_poliza.getText().trim());
                                            if (t_siniestro.getText().trim().compareTo("") != 0)
                                                nueva.setSiniestro(t_siniestro.getText().trim());
                                            if (t_reporte.getText().trim().compareTo("") != 0)
                                                nueva.setNoReporte(t_reporte.getText().trim());
                                            nueva.setDeducible(0.00d);
                                            int id = (int) session.save(nueva);
                                            nueva = (OrdenExterna) session.get(OrdenExterna.class, id);

                                            Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
                                            Factura nuevaFactura = new Factura();
                                            nuevaFactura.setOrdenExterna(nueva);
                                            nuevaFactura.setFecha(c1.getTime());// fecha de emision
                                            nuevaFactura.setRfcEmisor(con.getRfc());//RFC emisor
                                            nuevaFactura.setNombreEmisor(con.getNombre());//nombre emisor
                                            nuevaFactura.setCalleEmisor(con.getDireccion());//calle emisor
                                            nuevaFactura.setColoniaEmisor(con.getColonia());//Colonia emisor
                                            nuevaFactura.setNumeroExteriorEmisor(con.getNo());//numero exteerior emisor
                                            nuevaFactura.setMunicipioEmisor(con.getMunicipio());//municipio emisor
                                            nuevaFactura.setEstadoEmisor(con.getEstado());//estado emisor
                                            nuevaFactura.setPaisEmisor(con.getPais());//pais emisor
                                            nuevaFactura.setCpEmisor(con.getCp());//cp emisor
                                            nuevaFactura.setRfcReceptor(t_rfc.getText());
                                            nuevaFactura.setNombreReceptor(t_cliente.getText());
                                            nuevaFactura.setCalleReceptor(t_direccion.getText());
                                            nuevaFactura.setNumeroExteriorReceptor(t_numero_exterior.getText());
                                            nuevaFactura.setColoniaReceptor(t_colonia.getText());
                                            nuevaFactura.setMunicipioReceptor(t_municipio.getText());
                                            nuevaFactura.setEstadoReceptor(c_estado.getSelectedItem().toString());
                                            nuevaFactura.setPaisReceptor(c_pais.getSelectedItem().toString());
                                            nuevaFactura.setCpReceptor(t_cp.getText());
                                            nuevaFactura.setEstadoFactura("Pendiente");
                                            nuevaFactura.setEstatus("PENDIENTE");
                                            nuevaFactura.setDeducible(0.00d);
                                            //f_fiscal
                                            //fecha_fiscal
                                            //serie
                                            //folio
                                            nuevaFactura.setMetodoPago("98");
                                            nuevaFactura.setCuentaPago("");
                                            nuevaFactura.setMoneda("MXN");
                                            nuevaFactura.setFactorCambio(1.0d);
                                            nuevaFactura.setArea("Talleres");
                                            nuevaFactura.setTipoPoliza("AUTOS");
                                            nuevaFactura.setTipoEmisor("MATRIZ");
                                            nuevaFactura.setContactoEmisor(con.getContacto());
                                            nuevaFactura.setCorreoEmisor(con.getMail());
                                            nuevaFactura.setTelefonoEmisor(con.getTel());
                                            nuevaFactura.setTipoReceptor("COORDINADOR");
                                            nuevaFactura.setContactoReceptor(t_receptor.getText());
                                            nuevaFactura.setCorreoReceptor(t_email.getText());
                                            nuevaFactura.setTelefonoReceptor("");
                                            nuevaFactura.setCodigoOficina("");
                                            nuevaFactura.setFoliosElectronicos("");
                                            nuevaFactura.setUsuarioByGenero(user);
                                            //AUTORIZO
                                            //NPOMBRE DE DOCUMENTO
                                            //ERROR
                                            //ADDENDA
                                            //RI_EMOSOR
                                            //RI_RECEPTOR
                                            //PROVEEDOR
                                            nuevaFactura.setCondicionesPago("UNA SOLA EXHIBICION");
                                            //TIPO FACTURACION
                                            //DESCRIPCION EMISOR
                                            nuevaFactura.setMedioPago("NO IDENTIFICADO");
                                            nuevaFactura.setFechaMedioPago(c1.getTime());
                                            //FECHA CONDICIONES DE PAGO
                                            //RIESGO
                                            //ID ORDEN
                                            nuevaFactura.setIva(Integer.parseInt(t_iva1.getValue().toString()));

                                            //crear los conceptos
                                            int noFactura = (Integer) session.save(nuevaFactura);
                                            factura = (Factura) session.get(Factura.class, noFactura);
                                            for (int a = 0; a < t_datos.getRowCount(); a++) {
                                                Concepto renglon = new Concepto();
                                                renglon.setFactura(nuevaFactura);
                                                renglon.setCantidad((double) t_datos.getValueAt(a, 0));
                                                renglon.setMedida(t_datos.getValueAt(a, 1).toString());
                                                renglon.setDescripcion(t_datos.getValueAt(a, 2).toString());
                                                renglon.setPrecio((double) t_datos.getValueAt(a, 3));
                                                renglon.setDescuento((double) t_datos.getValueAt(a, 4));
                                                renglon.setFactura(factura);
                                                session.save(renglon);
                                                //nuevaFactura.getConceptos().add(renglon);
                                            }
                                            session.beginTransaction().commit();
                                            habilita(false);
                                            t_noFactura.setText("" + noFactura);
                                            JOptionPane.showMessageDialog(this,
                                                    "La factura se ha guardado con el numero:" + noFactura);
                                            addendas.setSize(323, 125);
                                            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                                            addendas.setLocation((d.width / 2) - (addendas.getWidth() / 2),
                                                    (d.height / 2) - (addendas.getHeight() / 2));
                                            addendas.setVisible(true);
                                        } catch (Exception e) {
                                            session.beginTransaction().rollback();
                                            e.printStackTrace();
                                            JOptionPane.showMessageDialog(this, "No se pudo guardar la factura.");
                                        } finally {
                                            if (session != null)
                                                if (session.isOpen())
                                                    session.close();
                                        }
                                    } else
                                        JOptionPane.showMessageDialog(this, "Ingrese el Municipio del cliente");
                                } else
                                    JOptionPane.showMessageDialog(this, "Ingrese el CP del cliente");
                            } else
                                JOptionPane.showMessageDialog(this, "Ingrese el nmero exterior del cliente");
                        } else
                            JOptionPane.showMessageDialog(this, "Ingrese la calle del cliente");
                    } else
                        JOptionPane.showMessageDialog(this, "Ingrese el RFC del cliente");
                } else
                    JOptionPane.showMessageDialog(this, "Ingrese en nombre de la razn social");
            } else
                JOptionPane.showMessageDialog(this, "Ingrese conceptos a facturar");
        } else
            JOptionPane.showMessageDialog(this, "Hay conceptos vacios eliminelos antes!");
    }//GEN-LAST:event_b_guardarActionPerformed

    private void t_numero_exteriorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_numero_exteriorKeyTyped
        // TODO add your handling code here:
        if (t_numero_exterior.getText().length() > 10)
            evt.consume();
    }//GEN-LAST:event_t_numero_exteriorKeyTyped

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction().begin();
            factura = (Factura) session.get(Factura.class, factura.getIdFactura());
            session.beginTransaction().commit();
            addendas.setVisible(false);
            QUALITAS genera = new QUALITAS(new javax.swing.JFrame(), true, user, sessionPrograma, factura);
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            genera.setLocation((d.width / 2) - (genera.getWidth() / 2), (d.height / 2) - (genera.getHeight() / 2));
            genera.consulta();
            genera.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Error al consultar la orden");
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction().begin();
            factura = (Factura) session.get(Factura.class, factura.getIdFactura());
            session.beginTransaction().commit();
            addendas.setVisible(false);
            AXA genera = new AXA(new javax.swing.JFrame(), true, user, sessionPrograma, factura);
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            genera.setLocation((d.width / 2) - (genera.getWidth() / 2), (d.height / 2) - (genera.getHeight() / 2));
            genera.consulta();
            genera.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Error al consultar la orden");
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction().begin();
            factura = (Factura) session.get(Factura.class, factura.getIdFactura());
            session.beginTransaction().commit();
            addendas.setVisible(false);
            GNP genera = new GNP(new javax.swing.JFrame(), true, user, sessionPrograma, factura);
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            genera.setLocation((d.width / 2) - (genera.getWidth() / 2), (d.height / 2) - (genera.getHeight() / 2));
            genera.consulta();
            genera.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Error al consultar la orden");
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction().begin();
            factura = (Factura) session.get(Factura.class, factura.getIdFactura());
            session.beginTransaction().commit();
            addendas.setVisible(false);
            General genera = new General(new javax.swing.JFrame(), true, user, sessionPrograma, factura);
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            genera.setLocation((d.width / 2) - (genera.getWidth() / 2), (d.height / 2) - (genera.getHeight() / 2));
            genera.consulta();
            genera.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Error al consultar la orden");
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void b_tipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_tipoActionPerformed
        // TODO add your handling code here:
        h = new Herramientas(this.user, 0);
        h.session(sessionPrograma);

        buscaTipo obj = new buscaTipo(new javax.swing.JFrame(), true, this.sessionPrograma, this.user);
        obj.t_busca.requestFocus();
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        obj.setLocation((d.width / 2) - (obj.getWidth() / 2), (d.height / 2) - (obj.getHeight() / 2));
        obj.setVisible(true);

        String actor = obj.getReturnStatus();
        if (actor != null) {
            t_tipo.setText(actor);
        } else {
            t_tipo.setText("");
        }
    }//GEN-LAST:event_b_tipoActionPerformed

    private void b_marcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_marcaActionPerformed
        // TODO add your handling code here:
        h = new Herramientas(user, 0);
        h.session(sessionPrograma);

        buscaMarca obj = new buscaMarca(new javax.swing.JFrame(), true, this.sessionPrograma, this.user);
        obj.t_busca.requestFocus();
        obj.formatoTabla();
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        obj.setLocation((d.width / 2) - (obj.getWidth() / 2), (d.height / 2) - (obj.getHeight() / 2));
        obj.setVisible(true);

        Marca actor = obj.getReturnStatus();
        if (actor != null) {
            //l_nombre_marca.setText(actor.getMarcaNombre());
            t_marca.setText(actor.getIdMarca());
        } else {
            //l_nombre_marca.setText("Selecciones una Marca");
            t_marca.setText("");
        }
    }//GEN-LAST:event_b_marcaActionPerformed

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

    private void b_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_buscarActionPerformed
        // TODO add your handling code here:
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction().begin();
            if (c_cliente.getSelectedItem().toString().compareTo("Cliente") == 0) {
                h = new Herramientas(user, 0);
                h.session(sessionPrograma);

                buscaCliente obj = new buscaCliente(new javax.swing.JFrame(), true);
                obj.t_busca.requestFocus();
                Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                obj.setLocation((d.width / 2) - (obj.getWidth() / 2), (d.height / 2) - (obj.getHeight() / 2));
                obj.setVisible(true);

                Clientes actor = obj.getReturnStatus();
                if (actor != null) {
                    actor = (Clientes) session.get(Clientes.class, actor.getIdClientes());
                    t_id.setText("" + actor.getIdClientes());
                    t_cliente.setText(actor.getNombre());

                    if (actor.getRfc() != null)
                        t_rfc.setText(actor.getRfc());
                    else
                        t_rfc.setText("");

                    if (actor.getDireccion() != null)
                        t_direccion.setText(actor.getDireccion());
                    else
                        t_direccion.setText("");

                    if (actor.getCp() != null)
                        t_cp.setText("" + actor.getCp());
                    else
                        t_cp.setText("");

                    if (actor.getColonia() != null)
                        t_colonia.setText(actor.getColonia());
                    else
                        t_colonia.setText(actor.getColonia());

                    if (actor.getMunicipio() != null)
                        t_municipio.setText(actor.getMunicipio());
                    else
                        t_municipio.setText("");

                    if (actor.getEstado() != null)
                        c_estado.setSelectedItem(actor.getEstado());

                    if (actor.getPais() != null)
                        c_pais.setSelectedItem(actor.getPais());
                    else
                        c_pais.setSelectedItem("");
                    if (actor.getNumeroExterior() != null)
                        t_numero_exterior.setText(actor.getNumeroExterior());
                    else
                        t_numero_exterior.setText("");
                    if (actor.getReceptor() != null)
                        t_receptor.setText(actor.getReceptor());
                    else
                        t_receptor.setText("");
                    if (actor.getEmailReceptor() != null)
                        t_email.setText(actor.getEmailReceptor());
                    else
                        t_email.setText("");
                    b_actualiza.setEnabled(true);
                }
            }
            if (c_cliente.getSelectedItem().toString().compareTo("Compaia") == 0) {
                h = new Herramientas(user, 0);
                h.session(sessionPrograma);

                buscaCompania obj = new buscaCompania(new javax.swing.JFrame(), true, this.sessionPrograma,
                        this.user);
                obj.t_busca.requestFocus();
                Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                obj.setLocation((d.width / 2) - (obj.getWidth() / 2), (d.height / 2) - (obj.getHeight() / 2));
                obj.setVisible(true);

                Compania actor = obj.getReturnStatus();
                if (actor != null) {
                    actor = (Compania) session.get(Compania.class, actor.getIdCompania());
                    t_id.setText("" + actor.getIdCompania());
                    t_cliente.setText(actor.getSocial());

                    if (actor.getRfc() != null)
                        t_rfc.setText(actor.getRfc());
                    else
                        t_rfc.setText("");

                    if (actor.getDireccion() != null)
                        t_direccion.setText(actor.getDireccion());
                    else
                        t_direccion.setText("");

                    if (actor.getCp() != null)
                        t_cp.setText("" + actor.getCp());
                    else
                        t_cp.setText("");

                    if (actor.getColonia() != null)
                        t_colonia.setText(actor.getColonia());
                    else
                        t_colonia.setText(actor.getColonia());

                    if (actor.getMunicipio() != null)
                        t_municipio.setText(actor.getMunicipio());
                    else
                        t_municipio.setText("");

                    if (actor.getEstado() != null)
                        c_estado.setSelectedItem(actor.getEstado());

                    if (actor.getPais() != null)
                        c_pais.setSelectedItem(actor.getPais());
                    else
                        c_pais.setSelectedItem("");
                    if (actor.getNumeroExterior() != null)
                        t_numero_exterior.setText(actor.getNumeroExterior());
                    else
                        t_numero_exterior.setText("");

                    if (actor.getRepresentante2() != null)
                        t_receptor.setText(actor.getRepresentante2());
                    else
                        t_receptor.setText("");

                    if (actor.getR2Puesto() != null)
                        t_email.setText(actor.getR2Puesto());
                    else
                        t_email.setText("");
                    b_actualiza.setEnabled(true);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Error al consultar los datos");
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
        }
    }//GEN-LAST:event_b_buscarActionPerformed

    private void b_masActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_masActionPerformed
        h = new Herramientas(this.user, 0);
        h.session(sessionPrograma);
        DefaultTableModel temp = (DefaultTableModel) t_datos.getModel();
        Object nuevo[] = { 0.0d, "PZAS", "", 0.0d, 0.0d, 0.0d };
        temp.addRow(nuevo);
        formatoTabla();
        t_datos.setRowSelectionInterval(t_datos.getRowCount() - 1, t_datos.getRowCount() - 1);
        t_datos.setColumnSelectionInterval(0, 0);
        t_datos.requestFocus();
    }//GEN-LAST:event_b_masActionPerformed

    private void b_menosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_menosActionPerformed
        h = new Herramientas(user, 0);
        h.session(sessionPrograma);
        if (t_datos.getRowCount() > 0 && t_datos.getSelectedRow() >= 0) {
            DefaultTableModel temp = (DefaultTableModel) t_datos.getModel();
            temp.removeRow(t_datos.getSelectedRow());
            sumaTotales();
            if (t_datos.getRowCount() > 0) {
                t_datos.setRowSelectionInterval(t_datos.getRowCount() - 1, t_datos.getRowCount() - 1);
                t_datos.setColumnSelectionInterval(0, 0);
            }
        }
    }//GEN-LAST:event_b_menosActionPerformed

    private void textoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textoKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (texto.getText().length() >= 250)
            evt.consume();
    }//GEN-LAST:event_textoKeyTyped

    private void t_datosKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_datosKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
    }//GEN-LAST:event_t_datosKeyTyped

    private void t_aseguradoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_aseguradoKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (t_asegurado.getText().length() >= 150)
            evt.consume();
    }//GEN-LAST:event_t_aseguradoKeyTyped

    private void t_incKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_incKeyTyped
        // TODO add your handling code here:
        if (t_inc.getText().length() >= 10)
            evt.consume();
    }//GEN-LAST:event_t_incKeyTyped

    private void t_serieKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_serieKeyTyped
        // TODO add your handling code here:
        if (t_serie.getText().length() >= 20)
            evt.consume();
    }//GEN-LAST:event_t_serieKeyTyped

    private void t_modeloKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_modeloKeyTyped
        // TODO add your handling code here:
        char car = evt.getKeyChar();
        if (t_modelo.getText().length() >= 4)
            evt.consume();
        if ((car < '0' || car > '9'))
            evt.consume();
    }//GEN-LAST:event_t_modeloKeyTyped

    private void t_placasKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_placasKeyTyped
        // TODO add your handling code here:
        if (t_placas.getText().length() >= 8)
            evt.consume();
    }//GEN-LAST:event_t_placasKeyTyped

    private void t_polizaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_polizaKeyTyped
        // TODO add your handling code here:
        if (t_poliza.getText().length() >= 20)
            evt.consume();
    }//GEN-LAST:event_t_polizaKeyTyped

    private void t_siniestroKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_siniestroKeyTyped
        // TODO add your handling code here:
        if (t_siniestro.getText().length() >= 20)
            evt.consume();
    }//GEN-LAST:event_t_siniestroKeyTyped

    private void t_reporteKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_reporteKeyTyped
        // TODO add your handling code here:
        if (t_reporte.getText().length() >= 11)
            evt.consume();
    }//GEN-LAST:event_t_reporteKeyTyped

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        // TODO add your handling code here:
        borra_cajas();
        habilita(true);
        t_datos.setModel(ModeloTablaReporte(0, columnas));
        formatoTabla();
        t_noFactura.setText("");
        sumaTotales();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void Selecciona2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Selecciona2ActionPerformed
        h = new Herramientas(user, 0);
        h.session(sessionPrograma);
        Session session = HibernateUtil.getSessionFactory().openSession();
        this.user = (Usuario) session.get(Usuario.class, user.getIdUsuario());
        if (user.getCrearClientes() == true) {
            altaCliente obj = new altaCliente(new javax.swing.JFrame(), true, user, sessionPrograma);
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            obj.setLocation((d.width / 2) - (obj.getWidth() / 2), (d.height / 2) - (obj.getHeight() / 2));
            obj.setVisible(true);
            //borra_cajas();
            //b_actualiza.setEnabled(false);
        } else
            JOptionPane.showMessageDialog(null, "Acceso denegado!");
        if (session != null)
            if (session.isOpen())
                session.close();
    }//GEN-LAST:event_Selecciona2ActionPerformed

    private void t_iva1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_iva1KeyTyped
        // TODO add your handling code here:
        char car = evt.getKeyChar();
        if (t_iva1.getText().length() >= 3)
            evt.consume();
        if ((car < '0' || car > '9'))
            evt.consume();
    }//GEN-LAST:event_t_iva1KeyTyped

    private void t_iva1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_iva1ActionPerformed
        // TODO add your handling code here:
        try {
            t_iva1.commitEdit();
        } catch (Exception e) {
        }
        this.sumaTotales();
    }//GEN-LAST:event_t_iva1ActionPerformed

    private void t_iva1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_t_iva1FocusLost
        // TODO add your handling code here:
        try {
            t_iva1.commitEdit();
        } catch (Exception e) {
        }
        this.sumaTotales();
    }//GEN-LAST:event_t_iva1FocusLost

    private void b_actualizaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_actualizaActionPerformed
        // TODO add your handling code here:
        if (this.c_cliente.getSelectedItem().toString().compareTo("Compaia") == 0) {
            h = new Herramientas(user, 0);
            h.session(sessionPrograma);
            t_cliente.setText(t_cliente.getText().trim());
            if (t_cliente.getText().compareTo("") != 0) {
                Session session = HibernateUtil.getSessionFactory().openSession();
                try {
                    session.beginTransaction().begin();
                    /*Object resp=session.createQuery("from Compania obj where obj.nombre='"+t_cliente.getText()+"' and obj.idCompania!="+t_id.getText()).uniqueResult();
                    if(resp==null)
                    {*/
                    Compania registro = (Compania) session.get(Compania.class, Integer.parseInt(t_id.getText()));
                    registro.setSocial(t_cliente.getText());
                    if (t_direccion.getText().compareTo("") != 0)
                        registro.setDireccion(t_direccion.getText());
                    else
                        registro.setDireccion(null);
                    if (t_colonia.getText().compareTo("") != 0)
                        registro.setColonia(t_colonia.getText());
                    else
                        registro.setColonia(null);
                    registro.setEstado(c_estado.getSelectedItem().toString());
                    if (t_rfc.getText().compareTo("") != 0)
                        registro.setRfc(t_rfc.getText());
                    else
                        registro.setRfc("");
                    if (t_cp.getText().compareTo("") != 0)
                        registro.setCp(t_cp.getText());
                    else
                        registro.setCp(null);
                    if (t_municipio.getText().compareTo("") != 0)
                        registro.setMunicipio(t_municipio.getText());
                    else
                        registro.setMunicipio("");
                    registro.setPais(c_pais.getSelectedItem().toString());
                    if (t_numero_exterior.getText().trim().compareTo("") != 0)
                        registro.setNumeroExterior(t_numero_exterior.getText().trim());

                    session.update(registro);
                    session.getTransaction().commit();
                    JOptionPane.showMessageDialog(null, "Registro modificado");
                    /*}
                    else
                    {
                    session.getTransaction().rollback();
                    JOptionPane.showMessageDialog(null, "En nombre de la Compaa ya existe!");
                    t_cliente.requestFocus();
                    }*/
                } catch (HibernateException he) {
                    he.printStackTrace();
                    session.getTransaction().rollback();
                } finally {
                    if (session != null)
                        if (session.isOpen())
                            session.close();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Debe introducir el nombre de la compaa!");
                t_cliente.requestFocus();
            }
        }
        if (this.c_cliente.getSelectedItem().toString().compareTo("Cliente") == 0) {
            h = new Herramientas(user, 0);
            h.session(sessionPrograma);
            Session session = HibernateUtil.getSessionFactory().openSession();
            try {
                session.beginTransaction();
                Object resp = session.createQuery("from Clientes obj where obj.nombre='" + t_cliente.getText()
                        + "' and obj.idClientes!=" + t_id.getText()).uniqueResult();
                if (resp == null) {
                    Clientes objeto = (Clientes) session.get(Clientes.class, Integer.parseInt(t_id.getText()));
                    objeto.setNombre(t_cliente.getText());
                    if (t_direccion.getText().compareTo("") != 1)
                        objeto.setDireccion(t_direccion.getText());
                    else
                        objeto.setDireccion("");
                    if (t_colonia.getText().compareTo("") != 1)
                        objeto.setColonia(t_colonia.getText());
                    else
                        objeto.setColonia("");
                    objeto.setEstado(c_estado.getSelectedItem().toString());
                    if (t_rfc.getText().compareTo("") != 1)
                        objeto.setRfc(t_rfc.getText());
                    else
                        objeto.setRfc("");
                    if (t_cp.getText().compareTo("") == 0)
                        objeto.setCp(null);
                    else
                        objeto.setCp(Integer.parseInt(t_cp.getText()));
                    if (t_municipio.getText().compareTo("") != 0)
                        objeto.setMunicipio(t_municipio.getText());
                    else
                        objeto.setMunicipio("");
                    objeto.setPais(c_pais.getSelectedItem().toString());
                    if (t_numero_exterior.getText().trim().compareTo("") != 0)
                        objeto.setNumeroExterior(t_numero_exterior.getText().trim());
                    session.update(objeto);
                    session.getTransaction().commit();
                    JOptionPane.showMessageDialog(null, "Registro modificado");
                } else {
                    JOptionPane.showMessageDialog(null, "Error: No se pueden guardar nombres duplicados!");
                }
            } catch (HibernateException he) {
                he.printStackTrace();
                System.out.println(he.hashCode());
                session.getTransaction().rollback();
            } finally {
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        }
    }//GEN-LAST:event_b_actualizaActionPerformed

    private void t_datosKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_datosKeyReleased
        // TODO add your handling code here:
        /*if (!t_datos.isEditing() && t_datos.editCellAt(t_datos.getSelectedRow(), t_datos.getSelectedColumn())) 
        {
        /*if(t_datos.getSelectedColumn()==1)
            t_datos.getEditorComponent().requestFocusInWindow();
        }*/
    }//GEN-LAST:event_t_datosKeyReleased

    private void textoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_textoFocusGained
        // TODO add your handling code here:
        texto.selectAll();
    }//GEN-LAST:event_textoFocusGained

    private void t_datosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_datosKeyPressed
        // TODO add your handling code here:
        int code = evt.getKeyCode();
        if (code == KeyEvent.VK_ENTER) {
            if (t_datos.isCellEditable(t_datos.getSelectedRow(), t_datos.getSelectedColumn()) == true) {
                if (t_datos.getSelectedColumn() > -1) {
                    Class edo = t_datos.getColumnClass(t_datos.getSelectedColumn());
                    if (edo == Boolean.class) {
                        boolean val = (boolean) t_datos.getValueAt(t_datos.getSelectedRow(),
                                t_datos.getSelectedColumn());
                        if (val == false)
                            t_datos.setValueAt(true, t_datos.getSelectedRow(), t_datos.getSelectedColumn());
                        else
                            t_datos.setValueAt(false, t_datos.getSelectedRow(), t_datos.getSelectedColumn());
                    }
                }
            }
            t_datos.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
                    .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "selectNextColumnCell");
        }
    }//GEN-LAST:event_t_datosKeyPressed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        aviso.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" }));
        int resp = aviso.showOpenDialog(null);
        if (resp == aviso.APPROVE_OPTION) {
            File archivoXLS = aviso.getSelectedFile();
            if (archivoXLS.exists() == true) {
                Session session = HibernateUtil.getSessionFactory().openSession();
                try {
                    FileInputStream archivo = new FileInputStream(archivoXLS);
                    POIFSFileSystem fsFileSystem = new POIFSFileSystem(archivo);
                    Workbook libro1 = new HSSFWorkbook(fsFileSystem);
                    Sheet datos = libro1.getSheetAt(0);
                    Iterator rowIterator;
                    int r = 0;

                    //**********cargamos datos************************
                    //DefaultTableModel temp = (DefaultTableModel) t_datos.getModel();
                    t_datos.setModel(ModeloTablaReporte(0, columnas));
                    rowIterator = datos.rowIterator();
                    r = 0;
                    while (rowIterator.hasNext()) {
                        HSSFRow renglon = (HSSFRow) rowIterator.next();
                        if (r > 0) {
                            System.out.println(renglon.getCell(0).getNumericCellValue());
                            double cant = renglon.getCell(0).getNumericCellValue();
                            double cu = renglon.getCell(3).getNumericCellValue();
                            double descuento = renglon.getCell(4).getNumericCellValue();
                            double suma = cant * cu;
                            double desc = descuento / 100;
                            double total = suma - (suma * desc);
                            Object nuevo[] = { cant, renglon.getCell(1).getStringCellValue(),
                                    renglon.getCell(2).getStringCellValue(), cu, descuento, total };
                            model.addRow(nuevo);
                        } else
                            r = 1;
                    }
                    formatoTabla();
                    this.sumaTotales();
                    t_datos.setRowSelectionInterval(t_datos.getRowCount() - 1, t_datos.getRowCount() - 1);
                    t_datos.setColumnSelectionInterval(0, 0);
                    t_datos.requestFocus();
                } catch (Exception e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(this, "No se pudo abrir el archivo");
                }
                if (session != null)
                    if (session.isOpen() == true)
                        session.close();
            }
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Selecciona2;
    private javax.swing.JDialog addendas;
    private javax.swing.JDialog alerta;
    private javax.swing.JFileChooser aviso;
    private javax.swing.JButton b_actualiza;
    private javax.swing.JButton b_buscar;
    private javax.swing.JButton b_guardar;
    private javax.swing.JButton b_marca;
    private javax.swing.JButton b_mas;
    private javax.swing.JButton b_menos;
    private javax.swing.JButton b_tipo;
    private javax.swing.JComboBox c_cliente;
    private javax.swing.JComboBox c_estado;
    private javax.swing.JComboBox c_pais;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton7;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel l_asegurado;
    private javax.swing.JLabel l_iva;
    private javax.swing.JLabel l_iva1;
    private javax.swing.JLabel l_subtotal;
    private javax.swing.JLabel l_total;
    private javax.swing.JComboBox medida;
    private javax.swing.JPanel p_cliente;
    private javax.swing.JPanel p_orden;
    private javax.swing.JPanel p_totales;
    private javax.swing.JProgressBar progreso;
    private javax.swing.JTextField t_asegurado;
    private javax.swing.JTextField t_cliente;
    private javax.swing.JTextField t_colonia;
    private javax.swing.JTextField t_cp;
    private javax.swing.JTable t_datos;
    private javax.swing.JFormattedTextField t_descuento;
    private javax.swing.JTextField t_direccion;
    private javax.swing.JTextField t_email;
    private javax.swing.JTextField t_id;
    private javax.swing.JTextField t_inc;
    private javax.swing.JFormattedTextField t_iva;
    private javax.swing.JFormattedTextField t_iva1;
    private javax.swing.JTextField t_marca;
    private javax.swing.JTextField t_modelo;
    private javax.swing.JTextField t_municipio;
    private javax.swing.JTextField t_noFactura;
    private javax.swing.JTextField t_numero_exterior;
    private javax.swing.JTextField t_placas;
    private javax.swing.JTextField t_poliza;
    private javax.swing.JTextField t_receptor;
    private javax.swing.JTextField t_reporte;
    private javax.swing.JTextField t_rfc;
    private javax.swing.JTextField t_serie;
    private javax.swing.JTextField t_siniestro;
    private javax.swing.JFormattedTextField t_subtotal;
    private javax.swing.JTextField t_tipo;
    private javax.swing.JFormattedTextField t_total;
    private javax.swing.JTextField texto;
    // End of variables declaration//GEN-END:variables

    void habilita(boolean estado) {
        t_asegurado.setEnabled(estado);
        b_marca.setEnabled(estado);
        b_tipo.setEnabled(estado);
        t_serie.setEnabled(estado);
        t_modelo.setEnabled(estado);
        t_placas.setEnabled(estado);
        t_poliza.setEnabled(estado);
        t_siniestro.setEnabled(estado);
        t_reporte.setEnabled(estado);
        t_inc.setEnabled(estado);

        t_cliente.setEnabled(estado);
        t_direccion.setEnabled(estado);
        t_numero_exterior.setEnabled(estado);
        t_colonia.setEnabled(estado);
        c_estado.setEnabled(estado);
        t_rfc.setEnabled(estado);
        t_cp.setEnabled(estado);
        t_municipio.setEnabled(estado);
        c_pais.setEnabled(estado);
        b_guardar.setEnabled(estado);
        t_datos.setEnabled(estado);
        t_descuento.setEnabled(estado);

        c_cliente.setEnabled(estado);
        b_buscar.setEnabled(estado);
        b_mas.setEnabled(estado);
        b_menos.setEnabled(estado);
        b_guardar.setEnabled(estado);
        b_actualiza.setEnabled(false);
    }

    void borra_cajas() {
        t_asegurado.setText("");
        t_marca.setText("");
        t_tipo.setText("");
        t_serie.setText("");
        t_modelo.setText("");
        t_placas.setText("");
        t_poliza.setText("");
        t_siniestro.setText("");
        t_reporte.setText("");
        t_inc.setText("");

        t_cliente.setText("");
        t_rfc.setText("");
        t_direccion.setText("");
        t_numero_exterior.setText("");
        t_cp.setText("");
        t_colonia.setText("");
        t_municipio.setText("");
        c_estado.setSelectedIndex(0);
        c_pais.setSelectedItem("MX");
        t_subtotal.setValue(0);
        t_iva.setValue(0);
        t_total.setValue(0);
        t_descuento.setValue(0);
        t_noFactura.setText("");
        t_receptor.setText("");
        t_email.setText("");
        t_datos.setModel(ModeloTablaReporte(0, columnas));
        formatoTabla();
    }

public void tabla_tamaos()
{
    TableColumnModel col_model = t_datos.getColumnModel();
    DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
    tcr.setHorizontalAlignment(SwingConstants.RIGHT);
    FormatoEditor fe=new FormatoEditor();
    FormatoEditorTexto fet=new FormatoEditorTexto();
    t_datos.setDefaultEditor(Double.class, fe);
    t_datos.setDefaultEditor(String.class, fet);
    for (int i=0; i<t_datos.getColumnCount(); i++)
    {
       TableColumn column = col_model.getColumn(i);
          switch(i)
          {
              case 0:
                  column.setPreferredWidth(20);
                  break;
              case 1:
                  column.setPreferredWidth(20);
                  DefaultCellEditor editor = new DefaultCellEditor(medida);
                  column.setCellEditor(editor); 
                  editor.setClickCountToStart(1);
                  break;
              case 2:
                  column.setPreferredWidth(350);
                  /*DefaultCellEditor editorT = new DefaultCellEditor(texto);
                  editorT.setClickCountToStart(1);
                  column.setCellEditor(editorT); */
                  break;
              case 3:
                  column.setPreferredWidth(100);
                  break;
              case 4:
                  column.setPreferredWidth(40);
                  break;
              case 5:
                  column.setPreferredWidth(40);
                  break;
              case 6:
                  column.setPreferredWidth(40);
                  break;
              default:
                  column.setPreferredWidth(40);
                  break;
          }
    }
    JTableHeader header = t_datos.getTableHeader();
    header.setForeground(Color.white);
}

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(Integer.class, formato);
    t_datos.setDefaultRenderer(String.class, formato);
    t_datos.setDefaultRenderer(Boolean.class, formato);
}

    DefaultTableModel ModeloTablaReporte(int renglones, String columnas[]) {
        model = new DefaultTableModel(new Object[renglones][6], columnas) {
            Class[] types = new Class[] { java.lang.Double.class, java.lang.String.class, java.lang.String.class,
                    java.lang.Double.class, java.lang.Double.class, java.lang.Double.class };
            boolean[] canEdit = new boolean[] { true, true, true, true, true, false };

            public void setValueAt(Object value, int row, int col) {
                Vector vector = (Vector) this.dataVector.elementAt(row);
                Object celda = ((Vector) this.dataVector.elementAt(row)).elementAt(col);
                switch (col) {
                case 0:
                    if (vector.get(col) == null) {
                        vector.setElementAt(value, col);
                        this.dataVector.setElementAt(vector, row);
                        fireTableCellUpdated(row, col);
                    } else {
                        if ((double) value >= 0.0d) {
                            vector.setElementAt(value, col);
                            this.dataVector.setElementAt(vector, row);
                            fireTableCellUpdated(row, col);
                            double suma = (((double) t_datos.getValueAt(row, 3)) * ((double) value));
                            double desc = ((double) t_datos.getValueAt(row, 4)) / 100;
                            double total = suma - (suma * desc);
                            t_datos.setValueAt(total, row, 5);
                        }
                        sumaTotales();
                    }
                    break;
                case 3:
                    if (vector.get(col) == null) {
                        vector.setElementAt(value, col);
                        this.dataVector.setElementAt(vector, row);
                        fireTableCellUpdated(row, col);
                    } else {
                        if ((double) value >= 0.0d) {
                            vector.setElementAt(value, col);
                            this.dataVector.setElementAt(vector, row);
                            fireTableCellUpdated(row, col);
                            double suma = (((double) value) * ((double) t_datos.getValueAt(row, 0)));
                            double desc = ((double) t_datos.getValueAt(row, 4)) / 100;
                            double total = suma - (suma * desc);
                            t_datos.setValueAt(total, row, 5);
                        }
                        sumaTotales();
                    }
                    break;
                case 4:
                    if (vector.get(col) == null) {
                        vector.setElementAt(value, col);
                        this.dataVector.setElementAt(vector, row);
                        fireTableCellUpdated(row, col);
                    } else {
                        if ((double) value <= 100.0d && (double) value >= 0.0d) {
                            vector.setElementAt(value, col);
                            this.dataVector.setElementAt(vector, row);
                            fireTableCellUpdated(row, col);
                            double suma = (((double) t_datos.getValueAt(row, 3))
                                    * ((double) t_datos.getValueAt(row, 0)));
                            double desc = ((double) value) / 100;
                            double total = suma - (suma * desc);
                            t_datos.setValueAt(total, row, 5);
                        }
                        sumaTotales();
                    }
                    break;
                default:
                    vector.setElementAt(value, col);
                    this.dataVector.setElementAt(vector, row);
                    fireTableCellUpdated(row, col);
                    break;
                }
            }

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

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        };
        return model;
    }

    public void sumaTotales() {
        try {
            iva = Integer.parseInt(t_iva1.getValue().toString());
            double total = 0.0;
            for (int ren = 0; ren < t_datos.getRowCount(); ren++) {
                total += (double) t_datos.getValueAt(ren, 5);
            }
            t_subtotal.setText("" + total);
            t_subtotal.setValue(total);
            double valor_iva = total * (iva * 0.01);
            t_iva.setText("" + iva);
            t_iva.setValue(new Double(valor_iva));
            total += valor_iva;
            t_total.setValue(total);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int OrdenFacturado(Orden or) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            Orden a = (Orden) session.get(Orden.class, or.getIdOrden());
            Factura[] fac = (Factura[]) a.getFacturas().toArray(new Factura[0]);
            for (int r = 0; r < fac.length; r++) {
                if (fac[r].getEstadoFactura().compareTo("Pendiente") == 0
                        || fac[r].getEstadoFactura().compareTo("Facturado") == 0)
                    return fac[r].getIdFactura();
            }
            return -1;
        } catch (Exception e) {
            System.out.println(e);
            return -1;
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
        }
    }
}