Contabilidad.FacturarOrden.java Source code

Java tutorial

Introduction

Here is the source code for Contabilidad.FacturarOrden.java

Source

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

package Contabilidad;

import Hibernate.Util.HibernateUtil;
import Hibernate.entidades.Adicionales;
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.Partida;
import Hibernate.entidades.Tipo;
import Hibernate.entidades.Usuario;
import Integral.ExtensionFileFilter;
import Integral.FormatoEditor;
import Servicios.buscaOrden;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.util.Calendar;
import java.util.Vector;
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.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import Integral.FormatoTabla;
import Integral.Herramientas;
import Integral.Render1;
import Marca.buscaMarca;
import Tipo.buscaTipo;
import java.io.File;
import java.io.FileInputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import javax.swing.DefaultCellEditor;
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;

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

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

    /**
     * Creates new form altaFactura
     */
    public FacturarOrden(Usuario u, String ses) {
        initComponents();
        user = u;
        sessionPrograma = ses;
        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();
        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();
        jLabel10 = new javax.swing.JLabel();
        c_cliente = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        t_id = new javax.swing.JTextField();
        b_actualiza = new javax.swing.JButton();
        c_estado = new javax.swing.JComboBox();
        c_pais = new javax.swing.JComboBox();
        jLabel23 = new javax.swing.JLabel();
        t_numero_exterior = new javax.swing.JTextField();
        p_orden = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        t_orden = new javax.swing.JTextField();
        b_orden = new javax.swing.JButton();
        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_actualiza1 = new javax.swing.JButton();
        b_marca = new javax.swing.JButton();
        b_tipo = new javax.swing.JButton();
        l_marca = new javax.swing.JTextField();
        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();
        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(42, 42, 42)
                                .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.UNRELATED)
                        .addGroup(addendasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton1).addComponent(jButton5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(addendasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton2).addComponent(jButton4))
                        .addContainerGap(22, 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" }));

        t_receptor.setText("jTextField1");

        t_email.setText("jTextField2");

        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("Cliente:");

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

        jLabel4.setText("Colonia:");

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

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

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

        t_rfc.setToolTipText("RFC del cliente");
        t_rfc.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_rfc.setEnabled(false);
        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 cliente");
        t_municipio.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_municipio.setEnabled(false);
        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("CP del cliente");
        t_cp.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_cp.setEnabled(false);
        t_cp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_cpKeyTyped(evt);
            }
        });

        jLabel10.setText("Facturar a:");

        c_cliente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Compaia", "Cliente" }));
        c_cliente.setEnabled(false);
        c_cliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                c_clienteActionPerformed(evt);
            }
        });

        jLabel11.setText("Id:");

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

        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);
            }
        });

        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 cliente");
        c_estado.setEnabled(false);

        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 cliente");
        c_pais.setEnabled(false);

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

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

        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().addContainerGap().addGroup(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)))
                                .addGap(0, 0, Short.MAX_VALUE))
                        .addGroup(p_clienteLayout.createSequentialGroup().addGroup(p_clienteLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(p_clienteLayout.createSequentialGroup().addComponent(jLabel10)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(c_cliente, javax.swing.GroupLayout.PREFERRED_SIZE, 136,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(109, 109, 109).addComponent(b_actualiza))
                                .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(javax.swing.GroupLayout.Alignment.TRAILING,
                                                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)))))
                        .addContainerGap()));
        p_clienteLayout.setVerticalGroup(p_clienteLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, p_clienteLayout.createSequentialGroup()
                        .addGroup(p_clienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel10)
                                .addComponent(c_cliente, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel11)
                                .addComponent(t_id, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(b_actualiza))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .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()));

        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));

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

        t_orden.setToolTipText("Nmero de orden");
        t_orden.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_orden.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_ordenActionPerformed(evt);
            }
        });
        t_orden.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_ordenKeyTyped(evt);
            }
        });

        b_orden.setBackground(new java.awt.Color(2, 135, 242));
        b_orden.setIcon(new ImageIcon("imagenes/buscar.png"));
        b_orden.setMnemonic(KeyEvent.VK_F1);
        b_orden.setToolTipText("Buscar ordenes");
        b_orden.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_ordenActionPerformed(evt);
            }
        });

        l_asegurado.setText("Asegurado:");

        t_asegurado.setToolTipText("Nombre del asegurado");
        t_asegurado.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_asegurado.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                t_aseguradoFocusLost(evt);
            }
        });
        t_asegurado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_aseguradoActionPerformed(evt);
            }
        });
        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("Numero serie de la unidad");
        t_serie.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_serie.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                t_serieFocusLost(evt);
            }
        });
        t_serie.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_serieActionPerformed(evt);
            }
        });
        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("Modelo de la unidad");
        t_modelo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_modelo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                t_modeloFocusLost(evt);
            }
        });
        t_modelo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_modeloActionPerformed(evt);
            }
        });

        jLabel16.setText("Placas:");

        t_placas.setToolTipText("Nmero de placas");
        t_placas.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_placas.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                t_placasFocusLost(evt);
            }
        });
        t_placas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_placasActionPerformed(evt);
            }
        });
        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.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                t_polizaFocusLost(evt);
            }
        });
        t_poliza.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_polizaActionPerformed(evt);
            }
        });
        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.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                t_siniestroFocusLost(evt);
            }
        });
        t_siniestro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_siniestroActionPerformed(evt);
            }
        });
        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.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                t_reporteFocusLost(evt);
            }
        });
        t_reporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_reporteActionPerformed(evt);
            }
        });
        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.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                t_incFocusLost(evt);
            }
        });
        t_inc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_incActionPerformed(evt);
            }
        });
        t_inc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_incKeyTyped(evt);
            }
        });

        b_actualiza1.setBackground(new java.awt.Color(2, 135, 242));
        b_actualiza1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        b_actualiza1.setForeground(new java.awt.Color(254, 254, 254));
        b_actualiza1.setIcon(new ImageIcon("imagenes/guardar.png"));
        b_actualiza1.setText("Actualizar");
        b_actualiza1.setToolTipText("Actualizar datos del cliente");
        b_actualiza1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_actualiza1ActionPerformed(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);
            }
        });

        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);
            }
        });

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

        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(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_orden, javax.swing.GroupLayout.PREFERRED_SIZE, 84,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(b_orden, javax.swing.GroupLayout.PREFERRED_SIZE, 28,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel20)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_inc, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                .addGap(63, 63, 63).addComponent(b_actualiza1))
                        .addGroup(p_ordenLayout.createSequentialGroup().addComponent(l_asegurado)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_asegurado))
                        .addGroup(p_ordenLayout.createSequentialGroup().addGroup(p_ordenLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                        p_ordenLayout
                                                .createSequentialGroup().addComponent(jLabel18).addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_siniestro))
                                .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()
                                        .addGroup(p_ordenLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel14).addComponent(jLabel12))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(p_ordenLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(p_ordenLayout.createSequentialGroup()
                                                        .addComponent(l_marca,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .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))
                                                .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.LEADING)
                        .addGroup(p_ordenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(t_orden, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel1).addComponent(b_orden, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        24, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .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(b_actualiza1)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(p_ordenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .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,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(
                                p_ordenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, 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(l_marca, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(b_marca, javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 24,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(b_tipo, javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 24,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .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 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)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).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)
                .addComponent(p_cliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)
                .addComponent(p_orden, javax.swing.GroupLayout.Alignment.TRAILING,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        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("Almacenar la factura");
        b_guardar.setEnabled(false);
        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 general");
        t_descuento.setEnabled(false);
        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);
            }
        });

        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)
                        .addGap(18, 18, 18)
                        .addGroup(p_totalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        p_totalesLayout.createSequentialGroup().addComponent(b_guardar)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jButton3)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        397, Short.MAX_VALUE)
                                                .addComponent(l_iva1).addGap(15, 15, 15))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        p_totalesLayout.createSequentialGroup().addComponent(jLabel22).addGap(18,
                                                18, 18)))
                        .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))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel5,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 197, 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().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)
                                                        .addComponent(l_iva1))
                                                .addComponent(t_descuento, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, p_totalesLayout
                                        .createSequentialGroup().addContainerGap()
                                        .addGroup(p_totalesLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .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(jButton3)))))
                                .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))
                        .addGap(2, 2, 2)));

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

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

        }, new String[] { "Cant", "Med", "Descripcin", "N Parte", "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.String.class, java.lang.Object.class,
                    java.lang.String.class };
            boolean[] canEdit = new boolean[] { false, false, true, false, 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);
        jScrollPane1.setViewportView(t_datos);

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

    private void t_ordenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_ordenActionPerformed
        // TODO add your handling code here:
        if (t_orden.getText().compareTo("") != 0) {
            Session session = HibernateUtil.getSessionFactory().openSession();
            try {
                session.beginTransaction().begin();
                orden_act = (Orden) session.get(Orden.class, Integer.parseInt(t_orden.getText()));
                if (orden_act != null) {
                    if (orden_act.getAutorizadoFacturar() == true) {
                        int id_fac = OrdenFacturado(orden_act);
                        if (id_fac == -1) {
                            this.t_orden.setText("" + orden_act.getIdOrden());
                            consultaOrden();
                        } else {
                            t_orden.setText("");
                            orden_act = null;
                            borra_cajas();
                            habilita(false);
                            t_orden.requestFocus();
                            int op = JOptionPane.showConfirmDialog(null,
                                    "La orden ya esta en facturacin con el nmero:" + id_fac
                                            + " desea consultarla?",
                                    "En proceso de Facturacin", JOptionPane.YES_NO_OPTION);
                            if (op == 0) {
                                try {
                                    session.beginTransaction().begin();
                                    factura = (Factura) session.get(Factura.class, id_fac);
                                    session.beginTransaction().commit();
                                    Dimension d;
                                    if (factura.getAddenda() != null
                                            && factura.getEstadoFactura().compareTo("Facturado") == 0) {
                                        switch (factura.getAddenda()) {
                                        case "qualitas":
                                            QUALITAS genera = new QUALITAS(new Frame(), true, this.user,
                                                    sessionPrograma, factura);
                                            d = Toolkit.getDefaultToolkit().getScreenSize();
                                            genera.setLocation((d.width / 2) - (genera.getWidth() / 2),
                                                    (d.height / 2) - (genera.getHeight() / 2));
                                            genera.consulta();
                                            genera.setVisible(true);
                                            genera.dispose();
                                            genera = null;
                                            //factura=genera.getReturnStatus();
                                            break;
                                        case "axa":
                                            AXA genera1 = new AXA(new Frame(), true, this.user, sessionPrograma,
                                                    factura);
                                            d = Toolkit.getDefaultToolkit().getScreenSize();
                                            genera1.setLocation((d.width / 2) - (genera1.getWidth() / 2),
                                                    (d.height / 2) - (genera1.getHeight() / 2));
                                            genera1.consulta();
                                            genera1.setVisible(true);
                                            genera1.dispose();
                                            genera1 = null;
                                            //factura=genera1.getReturnStatus();
                                            break;
                                        case "gnp":
                                            GNP genera2 = new GNP(new Frame(), true, this.user, sessionPrograma,
                                                    factura);
                                            d = Toolkit.getDefaultToolkit().getScreenSize();
                                            genera2.setLocation((d.width / 2) - (genera2.getWidth() / 2),
                                                    (d.height / 2) - (genera2.getHeight() / 2));
                                            genera2.consulta();
                                            genera2.setVisible(true);
                                            genera2.dispose();
                                            genera2 = null;
                                            //factura=genera2.getReturnStatus();
                                            break;
                                        //case "mapfre":
                                        //                                            break;
                                        case "general":
                                            General genera3 = new General(new Frame(), true, this.user,
                                                    sessionPrograma, factura);
                                            d = Toolkit.getDefaultToolkit().getScreenSize();
                                            genera3.setLocation((d.width / 2) - (genera3.getWidth() / 2),
                                                    (d.height / 2) - (genera3.getHeight() / 2));
                                            genera3.consulta();
                                            genera3.setVisible(true);
                                            genera3.dispose();
                                            genera3 = null;
                                            //factura=genera3.getReturnStatus();
                                            break;
                                        default:
                                            addendas.setSize(324, 135);
                                            d = Toolkit.getDefaultToolkit().getScreenSize();
                                            addendas.setLocation((d.width / 2) - (addendas.getWidth() / 2),
                                                    (d.height / 2) - (addendas.getHeight() / 2));
                                            addendas.setVisible(true);
                                            break;
                                        }
                                    } else {
                                        addendas.setSize(324, 135);
                                        d = Toolkit.getDefaultToolkit().getScreenSize();
                                        addendas.setLocation((d.width / 2) - (addendas.getWidth() / 2),
                                                (d.height / 2) - (addendas.getHeight() / 2));
                                        addendas.setVisible(true);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    JOptionPane.showMessageDialog(null, "Error al consultar la orden");
                                }
                            }
                        }
                    } else {
                        t_orden.setText("");
                        orden_act = null;
                        borra_cajas();
                        habilita(false);
                        t_datos.setModel(ModeloTablaReporte(0, columnas));
                        this.formatoTabla();
                        JOptionPane.showMessageDialog(null, "La orden aun no esta lista para facturar");
                        t_orden.requestFocus();
                    }
                } else {
                    h = new Herramientas(user, 0);
                    t_orden.setText("");
                    orden_act = null;
                    borra_cajas();
                    habilita(false);
                    t_datos.setModel(ModeloTablaReporte(0, columnas));
                    formatoTabla();
                    t_orden.requestFocus();
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        } else {
            h = new Herramientas(user, 0);
            t_orden.setText("");
            orden_act = null;
            borra_cajas();
            habilita(false);
            t_datos.setModel(ModeloTablaReporte(0, columnas));
            formatoTabla();
            t_orden.requestFocus();
        }
    }//GEN-LAST:event_t_ordenActionPerformed

    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 t_ordenKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_ordenKeyTyped
        // TODO add your handling code here:
        char car = evt.getKeyChar();
        if (t_orden.getText().length() > 5)
            evt.consume();
        if ((car < '0' || car > '9'))
            evt.consume();
    }//GEN-LAST:event_t_ordenKeyTyped

    private void b_ordenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_ordenActionPerformed
        // TODO add your handling code here:
        h = new Herramientas(user, 0);
        h.session(sessionPrograma);
        buscaOrden obj = new buscaOrden(new javax.swing.JFrame(), true, user, 1);
        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);
        orden_act = obj.getReturnStatus();
        if (orden_act != null) {
            if (orden_act.getAutorizadoFacturar() == true) {
                Session session = HibernateUtil.getSessionFactory().openSession();
                try {
                    orden_act = (Orden) session.get(Orden.class, orden_act.getIdOrden());
                    int id_fac = OrdenFacturado(orden_act);
                    if (id_fac == -1) {
                        this.t_orden.setText("" + orden_act.getIdOrden());
                        consultaOrden();
                    } else {
                        t_orden.setText("");
                        orden_act = null;
                        borra_cajas();
                        habilita(true);
                        t_orden.requestFocus();
                        int op = JOptionPane.showConfirmDialog(null,
                                "La orden ya esta en facturacin con el nmero:" + id_fac
                                        + " desea consultarla?",
                                "En proceso de Facturacin", JOptionPane.YES_NO_OPTION);
                        if (op == 0) {
                            session.beginTransaction().begin();
                            Factura factura = (Factura) session.get(Factura.class, id_fac);
                            if (factura.getAddenda() != null
                                    && factura.getEstadoFactura().compareTo("Facturado") == 0) {
                                switch (factura.getAddenda()) {
                                case "qualitas":
                                    session.beginTransaction().commit();
                                    QUALITAS genera = new QUALITAS(new Frame(), true, this.user, sessionPrograma,
                                            factura);
                                    d = Toolkit.getDefaultToolkit().getScreenSize();
                                    genera.setLocation((d.width / 2) - (genera.getWidth() / 2),
                                            (d.height / 2) - (genera.getHeight() / 2));
                                    genera.consulta();
                                    genera.setVisible(true);
                                    factura = genera.getReturnStatus();
                                    break;
                                case "axa":
                                    AXA genera1 = new AXA(new Frame(), true, this.user, sessionPrograma, factura);
                                    d = Toolkit.getDefaultToolkit().getScreenSize();
                                    genera1.setLocation((d.width / 2) - (genera1.getWidth() / 2),
                                            (d.height / 2) - (genera1.getHeight() / 2));
                                    genera1.consulta();
                                    genera1.setVisible(true);
                                    factura = genera1.getReturnStatus();
                                    break;
                                case "gnp":
                                    GNP genera2 = new GNP(new Frame(), true, this.user, sessionPrograma, factura);
                                    d = Toolkit.getDefaultToolkit().getScreenSize();
                                    genera2.setLocation((d.width / 2) - (genera2.getWidth() / 2),
                                            (d.height / 2) - (genera2.getHeight() / 2));
                                    genera2.consulta();
                                    genera2.setVisible(true);
                                    factura = genera2.getReturnStatus();
                                    break;
                                //case "mapfre":
                                //break;
                                case "general":
                                    General genera3 = new General(new Frame(), true, this.user, sessionPrograma,
                                            factura);
                                    d = Toolkit.getDefaultToolkit().getScreenSize();
                                    genera3.setLocation((d.width / 2) - (genera3.getWidth() / 2),
                                            (d.height / 2) - (genera3.getHeight() / 2));
                                    genera3.consulta();
                                    genera3.setVisible(true);
                                    factura = genera3.getReturnStatus();
                                    break;
                                default:
                                    addendas.setSize(324, 135);
                                    d = Toolkit.getDefaultToolkit().getScreenSize();
                                    addendas.setLocation((d.width / 2) - (addendas.getWidth() / 2),
                                            (d.height / 2) - (addendas.getHeight() / 2));
                                    addendas.setVisible(true);
                                    break;
                                }
                            } else {
                                addendas.setSize(324, 135);
                                d = Toolkit.getDefaultToolkit().getScreenSize();
                                addendas.setLocation((d.width / 2) - (addendas.getWidth() / 2),
                                        (d.height / 2) - (addendas.getHeight() / 2));
                                addendas.setVisible(true);
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(null, "Error al consultar la orden");
                } finally {
                    if (session != null)
                        if (session.isOpen())
                            session.close();
                }
            } else {
                t_orden.setText("");
                orden_act = null;
                borra_cajas();
                habilita(false);
                t_orden.requestFocus();
                JOptionPane.showMessageDialog(null, "La orden aun no esta lista para facturar");
            }
        } else {
            t_orden.setText("");
            orden_act = null;
            borra_cajas();
            habilita(false);
            t_orden.requestFocus();
        }
    }//GEN-LAST:event_b_ordenActionPerformed

    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_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() >= 150)
            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() >= 20)
            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, 5);
                }
            } 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:
        if (t_datos.getRowCount() > 0) {
            if (t_orden.getText().compareTo("") != 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();
                                            orden_act = (Orden) session.get(Orden.class, orden_act.getIdOrden());
                                            if (orden_act.getAutorizadoFacturar() == true) {
                                                Configuracion con = (Configuracion) session.get(Configuracion.class,
                                                        1);
                                                Factura nuevaFactura = new Factura();
                                                nuevaFactura.setOrden(orden_act);
                                                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());
                                                //DEDUCIBLE
                                                nuevaFactura.setEstadoFactura("Pendiente");
                                                nuevaFactura.setEstatus("PENDIENTE");
                                                //f_fiscal
                                                //fecha_fiscal
                                                //serie
                                                //folio
                                                if (orden_act.getCompania().getIdCompania() == 15
                                                        || orden_act.getCompania().getIdCompania() == 13
                                                        || orden_act.getCompania().getIdCompania() == 1)
                                                    nuevaFactura.setMetodoPago("03");
                                                else
                                                    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()));

                                                int noFactura = (Integer) session.save(nuevaFactura);
                                                factura = (Factura) session.get(Factura.class, noFactura);
                                                //crear los conceptos
                                                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, 4));
                                                    renglon.setDescuento((double) t_datos.getValueAt(a, 5));
                                                    renglon.setFactura(factura);
                                                    session.save(renglon);
                                                    //nuevaFactura.getConceptos().add(renglon);
                                                }

                                                orden_act.setNoFactura(noFactura);
                                                orden_act.setUsuarioByRFactura(user);
                                                orden_act.setFehaFectura(nuevaFactura.getFecha());

                                                //orden_act.setFechaCierre(nuevaFactura.getFecha());
                                                //orden_act.setUsuarioByRCierre(user);
                                                session.update(orden_act);
                                                session.beginTransaction().commit();
                                                habilita(false);
                                                t_noFactura.setText("" + noFactura);
                                                JOptionPane.showMessageDialog(this,
                                                        "La factura se ha guardado con el nmero:" + noFactura);
                                                addendas.setSize(324, 135);
                                                Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                                                addendas.setLocation((d.width / 2) - (addendas.getWidth() / 2),
                                                        (d.height / 2) - (addendas.getHeight() / 2));
                                                addendas.setVisible(true);
                                            } else {
                                                t_orden.setText("");
                                                orden_act = null;
                                                borra_cajas();
                                                habilita(false);
                                                t_orden.requestFocus();
                                                JOptionPane.showMessageDialog(this,
                                                        "La factura no esta lista para facturar");
                                            }

                                        } 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 el nmero de orden a facturar");
        } else
            JOptionPane.showMessageDialog(this, "Ingrese conceptos a facturar");

    }//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:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        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_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);
    }//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 b_actualiza1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_actualiza1ActionPerformed
        // TODO add your handling code here:
        if (t_orden.getText().compareTo("") != 0) {
            if (t_asegurado.getText().compareTo("") != 0) {
                if (t_tipo.getText().compareTo("") != 0) {
                    if (t_marca.getText().compareTo("") != 0) {
                        if (t_modelo.getText().compareTo("") != 0) {
                            boolean respuesta = guardarOrden();
                            if (respuesta == true) {
                                JOptionPane.showMessageDialog(null, "Orden actualizada!");
                            } else {
                                JOptionPane.showMessageDialog(null, "Error al actualizar los datos!");
                                t_tipo.requestFocus();
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "Debe ingresar un modelo!");
                            t_modelo.requestFocus();
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "Debe seleccionar una marca!");
                        t_marca.requestFocus();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "Debe seleccionar un tipo de unidad!");
                    t_tipo.requestFocus();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Debe introducir el nombre del cliente!");
                t_cliente.requestFocus();
            }
        } else
            JOptionPane.showMessageDialog(null, "Debe introducir numero de orden!");
    }//GEN-LAST:event_b_actualiza1ActionPerformed

    private void b_marcaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_marcaActionPerformed
        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) {
            t_marca.setText(actor.getMarcaNombre());
            l_marca.setText(actor.getIdMarca());
        } else {
            l_marca.setText("");
            t_marca.setText("");
        }
    }//GEN-LAST:event_b_marcaActionPerformed

    private void b_tipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_tipoActionPerformed
        // TODO add your handling code here:
        h = new Herramientas(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 t_incFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_t_incFocusLost
        // TODO add your handling code here:
        if (t_inc.getText().length() > 10) {
            t_inc.setText(t_inc.getText().substring(0, 10));
        }
    }//GEN-LAST:event_t_incFocusLost

    private void t_incActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_incActionPerformed
        // TODO add your handling code here:
        b_actualiza1.requestFocus();
    }//GEN-LAST:event_t_incActionPerformed

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

    private void t_aseguradoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_aseguradoActionPerformed
        // TODO add your handling code here:
        b_actualiza1.requestFocus();
    }//GEN-LAST:event_t_aseguradoActionPerformed

    private void t_aseguradoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_t_aseguradoFocusLost
        // TODO add your handling code here:
        if (t_asegurado.getText().length() > 150) {
            t_asegurado.setText(t_asegurado.getText().substring(0, 150));
        }
    }//GEN-LAST:event_t_aseguradoFocusLost

    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()));
        char car = evt.getKeyChar();
        if (t_asegurado.getText().length() >= 150)
            evt.consume();
    }//GEN-LAST:event_t_aseguradoKeyTyped

    private void t_serieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_serieActionPerformed
        // TODO add your handling code here:
        b_actualiza1.requestFocus();
    }//GEN-LAST:event_t_serieActionPerformed

    private void t_serieFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_t_serieFocusLost
        // TODO add your handling code here:
        if (t_serie.getText().length() > 20) {
            t_serie.setText(t_serie.getText().substring(0, 20));
        }
    }//GEN-LAST:event_t_serieFocusLost

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

    private void t_modeloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_modeloActionPerformed
        // TODO add your handling code here:
        b_actualiza1.requestFocus();
    }//GEN-LAST:event_t_modeloActionPerformed

    private void t_modeloFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_t_modeloFocusLost
        // TODO add your handling code here:
        if (t_modelo.getText().length() > 4) {
            t_modelo.setText(t_modelo.getText().substring(0, 4));
            try {
                Integer.parseInt(t_modelo.getText());
            } catch (Exception e) {
                e.printStackTrace();
                t_modelo.setText("");
            }
        } else {
            try {
                Integer.parseInt(t_modelo.getText());
            } catch (Exception e) {
                e.printStackTrace();
                t_modelo.setText("");
            }
        }

    }//GEN-LAST:event_t_modeloFocusLost

    private void t_placasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_placasActionPerformed
        // TODO add your handling code here:
        b_actualiza1.requestFocus();
    }//GEN-LAST:event_t_placasActionPerformed

    private void t_placasFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_t_placasFocusLost
        // TODO add your handling code here:
        if (t_placas.getText().length() > 8) {
            t_placas.setText(t_placas.getText().substring(0, 8));
        }
    }//GEN-LAST:event_t_placasFocusLost

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

    private void t_polizaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_polizaActionPerformed
        // TODO add your handling code here:
        b_actualiza1.requestFocus();
    }//GEN-LAST:event_t_polizaActionPerformed

    private void t_polizaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_t_polizaFocusLost
        // TODO add your handling code here:
        if (t_poliza.getText().length() > 20) {
            t_poliza.setText(t_poliza.getText().substring(0, 20));
        }
    }//GEN-LAST:event_t_polizaFocusLost

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

    private void t_siniestroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_siniestroActionPerformed
        // TODO add your handling code here:
        b_actualiza.requestFocus();
    }//GEN-LAST:event_t_siniestroActionPerformed

    private void t_siniestroFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_t_siniestroFocusLost
        // TODO add your handling code here:
        if (t_siniestro.getText().length() > 20) {
            t_siniestro.setText(t_siniestro.getText().substring(0, 20));
        }
    }//GEN-LAST:event_t_siniestroFocusLost

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

    private void t_reporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_reporteActionPerformed
        // TODO add your handling code here:
        b_actualiza1.requestFocus();
    }//GEN-LAST:event_t_reporteActionPerformed

    private void t_reporteFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_t_reporteFocusLost
        // TODO add your handling code here:
        if (t_reporte.getText().length() > 11) {
            t_reporte.setText(t_reporte.getText().substring(0, 11));
        }
    }//GEN-LAST:event_t_reporteFocusLost

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

    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 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) {
                            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.JDialog addendas;
    private javax.swing.JDialog alerta;
    private javax.swing.JFileChooser aviso;
    private javax.swing.JButton b_actualiza;
    private javax.swing.JButton b_actualiza1;
    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_orden;
    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.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    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.JTextField l_marca;
    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;
    public javax.swing.JTextField t_orden;
    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;
    // End of variables declaration//GEN-END:variables

    void habilita(boolean estado) {
        c_cliente.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);
        b_actualiza.setEnabled(estado);
    }

    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("");

        c_cliente.setSelectedItem("Compaia");
        t_id.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 consultaOrden() {
        h = new Herramientas(user, 0);
        h.session(sessionPrograma);
        if (t_orden.getText().compareTo("") != 0) {
            borra_cajas();
            if (orden_act != null) {
                Session session = HibernateUtil.getSessionFactory().openSession();
                try {
                    session.beginTransaction().begin();
                    orden_act = (Orden) session.get(Orden.class, orden_act.getIdOrden());
                    int id_fac = OrdenFacturado(orden_act);
                    if (id_fac == -1) {
                        t_inc.setText(orden_act.getInciso());
                        t_asegurado.setText(orden_act.getClientes().getNombre());
                        l_marca.setText(orden_act.getMarca().getIdMarca());
                        t_marca.setText(orden_act.getMarca().getMarcaNombre());
                        t_tipo.setText(orden_act.getTipo().getTipoNombre());
                        if (orden_act.getNoSerie() != null)
                            t_serie.setText(orden_act.getNoSerie());
                        else
                            t_serie.setText("");
                        t_modelo.setText("" + orden_act.getModelo());
                        if (orden_act.getNoPlacas() != null)
                            t_placas.setText(orden_act.getNoPlacas());
                        else
                            t_placas.setText("");
                        t_poliza.setText(orden_act.getPoliza());
                        t_siniestro.setText(orden_act.getSiniestro());
                        t_reporte.setText(orden_act.getNoReporte());

                        String tipo_cliente = orden_act.getTipoCliente();

                        if (tipo_cliente != null) {
                            switch (tipo_cliente) {
                            case "1":
                                l_asegurado.setText("Asegurado:");
                                break;

                            case "2":
                                l_asegurado.setText("Tercero:");
                                break;

                            case "3":
                                l_asegurado.setText("Tercero Asegurado:");
                                break;

                            case "4":
                                l_asegurado.setText("Particular");
                                break;
                            }
                        }
                        //cargar las partidas
                        b_guardar.setEnabled(true);
                        c_cliente.setEnabled(true);
                        habilita(true);
                        Partida[] partidas = (Partida[]) session.createCriteria(Partida.class)
                                .add(Restrictions.eq("ordenByIdOrden.idOrden", orden_act.getIdOrden()))
                                .add(Restrictions.eq("facturado", true)).add(Restrictions.eq("incluida", false))
                                .add(Restrictions.isNull("ordenByEnlazada")).addOrder(Order.asc("idEvaluacion"))
                                .addOrder(Order.asc("subPartida")).list().toArray(new Partida[0]);
                        Partida[] enlazadas = (Partida[]) session.createCriteria(Partida.class)
                                .add(Restrictions.eq("ordenByEnlazada.idOrden", orden_act.getIdOrden()))
                                .add(Restrictions.eq("incluida", true)).addOrder(Order.asc("idEvaluacion"))
                                .addOrder(Order.asc("subPartida")).list().toArray(new Partida[0]);
                        //Partida[] enlazadas = (Partida[])orden_act.getPartidasForEnlazada().toArray(new Partida[0]);
                        Adicionales[] adicionales = (Adicionales[]) orden_act.getAdicionaleses()
                                .toArray(new Adicionales[0]);
                        DefaultTableModel modelo = ModeloTablaReporte(0, columnas);
                        for (int a = 0; a < partidas.length; a++) {
                            String noParte = "";
                            if (partidas[a].getEjemplar() != null)
                                noParte = partidas[a].getEjemplar().getIdParte();
                            double descuento = 0.0d;//descuento de la partida
                            double total = (partidas[a].getPrecioFactura() * partidas[a].getCantidadFactura())
                                    * (1 + (descuento / 100));
                            modelo.addRow(new Object[] { partidas[a].getCantidadFactura(), partidas[a].getMed(),
                                    partidas[a].getDescripcionFactura(), noParte, partidas[a].getPrecioFactura(),
                                    descuento, total });
                        }
                        for (int b = 0; b < enlazadas.length; b++) {
                            String noParte2 = "";
                            if (enlazadas[b].getEjemplar() != null)
                                noParte2 = enlazadas[b].getEjemplar().getIdParte();
                            double descuento2 = 0.0;//descuento de la partida
                            double total2 = (enlazadas[b].getPrecioFactura() * enlazadas[b].getCantidadFactura())
                                    * (1 + (descuento2 / 100));
                            modelo.addRow(new Object[] { enlazadas[b].getCantidadFactura(), enlazadas[b].getMed(),
                                    enlazadas[b].getDescripcionFactura(), noParte2, enlazadas[b].getPrecioFactura(),
                                    descuento2, total2 });
                        }
                        for (int c = 0; c < adicionales.length; c++) {
                            double descuento3 = adicionales[c].getDescuento();//descuento de la partida
                            double total3 = (adicionales[c].getPrecio() * adicionales[c].getCantidad())
                                    * (1 + (descuento3 / 100));
                            modelo.addRow(new Object[] { adicionales[c].getCantidad(), adicionales[c].getMedida(),
                                    adicionales[c].getDescripcion(), "", adicionales[c].getPrecio(), descuento3,
                                    total3 });
                        }
                        if (orden_act.getMoDirecta() > 0.0d) {
                            modelo.addRow(new Object[] { 1.0, "NA", "MANO DE OBRA", "", orden_act.getMoDirecta(),
                                    0.0, orden_act.getMoDirecta() });
                        } else {
                            Query query = session
                                    .createQuery("SELECT SUM( " + "(CASE WHEN dm>0 THEN (dm*cant) ELSE 0 END) + "
                                            + "(CASE WHEN cam>0 THEN (cam*cant) ELSE 0 END) + "
                                            + "(CASE WHEN repMin>0 THEN (repMin*cant) ELSE 0 END) + "
                                            + "(CASE WHEN repMed>0 THEN (repMed*cant) ELSE 0 END) + "
                                            + "(CASE WHEN repMax>0 THEN (repMax*cant) ELSE 0 END) + "
                                            + "(CASE WHEN pint>0 THEN (pint*cant) ELSE 0 END) " + ") from Partida "
                                            + "where ordenByIdOrden.idOrden =" + orden_act.getIdOrden()
                                            + " or ordenByEnlazada.idOrden=" + orden_act.getIdOrden());
                            Object ent = query.uniqueResult();
                            if (ent != null) {
                                double res = orden_act.getCompania().getImporteHora()
                                        * Double.parseDouble(ent.toString());
                                if (res > 0.0d)
                                    modelo.addRow(new Object[] { 1.0, "NA", "MANO DE OBRA", "", res, 0.0, res });
                            }
                            /*else
                            {
                            modelo.addRow(new Object[]{1.0, "NA", "MANO DE OBRA", "", 0.0, 0.0, 0.0});
                            }*/
                        }
                        Configuracion configuracion = (Configuracion) session.get(Configuracion.class, 1);
                        iva = configuracion.getIva();
                        session.beginTransaction().commit();
                        t_datos.setModel(modelo);
                        formatoTabla();
                        cargaCliente();
                    } else {
                        orden_act = null;
                        t_orden.setText("");
                        borra_cajas();
                        b_guardar.setEnabled(false);
                        c_cliente.setEnabled(false);
                        habilita(false);
                        JOptionPane.showMessageDialog(null,
                                "La orden ya fue Facturada con la Factura No:" + id_fac);
                        t_orden.requestFocus();
                    }
                } catch (HibernateException he) {
                    he.printStackTrace();
                    session.getTransaction().rollback();
                    orden_act = null;
                    t_orden.setText("");
                    borra_cajas();
                    b_guardar.setEnabled(false);
                    c_cliente.setEnabled(false);
                    habilita(false);
                    JOptionPane.showMessageDialog(null, "Error al consultar la Orden");
                    t_orden.requestFocus();
                } finally {
                    if (session != null)
                        if (session.isOpen())
                            session.close();
                }
            } else {
                orden_act = null;
                t_orden.setText("");
                borra_cajas();
                b_guardar.setEnabled(false);
                c_cliente.setEnabled(false);
                habilita(false);
                JOptionPane.showMessageDialog(null, "El nmero de orden no existe!");
                t_orden.requestFocus();
            }
        } else {
            orden_act = null;
            borra_cajas();
            this.orden_act = null;
            b_guardar.setEnabled(false);
            c_cliente.setEnabled(false);
            habilita(false);
        }
        sumaTotales();
        this.updateUI();
    }

    void cargaCliente() {
        if (orden_act != null) {
            Session session = HibernateUtil.getSessionFactory().openSession();
            try {
                session.beginTransaction().begin();
                orden_act = (Orden) session.get(Orden.class, orden_act.getIdOrden());
                if (c_cliente.getSelectedItem().toString().compareTo("Compaia") == 0) {
                    t_id.setText("" + orden_act.getCompania().getIdCompania());
                    t_cliente.setText(orden_act.getCompania().getSocial());
                    if (orden_act.getCompania().getDireccion() != null)
                        t_direccion.setText(orden_act.getCompania().getDireccion());
                    else
                        t_direccion.setText("");
                    if (orden_act.getCompania().getColonia() != null)
                        t_colonia.setText(orden_act.getCompania().getColonia());
                    else
                        t_colonia.setText("");
                    c_estado.setSelectedItem(orden_act.getCompania().getEstado());
                    if (orden_act.getCompania().getRfc() != null)
                        this.t_rfc.setText(orden_act.getCompania().getRfc());
                    else
                        this.t_rfc.setText("");
                    if (orden_act.getCompania().getCp() != null)
                        t_cp.setText(orden_act.getCompania().getCp());
                    else
                        t_cp.setText("");
                    if (orden_act.getCompania().getMunicipio() != null)
                        t_municipio.setText(orden_act.getCompania().getMunicipio());
                    else
                        t_municipio.setText("");
                    if (orden_act.getCompania().getNumeroExterior() != null)
                        t_numero_exterior.setText(orden_act.getCompania().getNumeroExterior());
                    else
                        t_numero_exterior.setText("");
                    if (orden_act.getCompania().getRepresentante2() != null)
                        t_receptor.setText(orden_act.getCompania().getRepresentante2());
                    else
                        t_receptor.setText("");

                    if (orden_act.getCompania().getR2Puesto() != null)
                        t_email.setText(orden_act.getCompania().getR2Puesto());
                    else
                        t_email.setText("");
                    c_pais.setSelectedItem(orden_act.getCompania().getPais());

                } else {
                    t_id.setText("" + orden_act.getClientes().getIdClientes());
                    t_cliente.setText(orden_act.getClientes().getNombre());
                    if (orden_act.getClientes().getDireccion() != null)
                        t_direccion.setText(orden_act.getClientes().getDireccion());
                    else
                        t_direccion.setText("");
                    if (orden_act.getClientes().getColonia() != null)
                        t_colonia.setText(orden_act.getClientes().getColonia());
                    else
                        t_colonia.setText("");
                    c_estado.setSelectedItem(orden_act.getClientes().getEstado());
                    if (orden_act.getClientes().getRfc() != null)
                        this.t_rfc.setText(orden_act.getClientes().getRfc());
                    else
                        this.t_rfc.setText("");
                    try {
                        int cp = orden_act.getClientes().getCp();
                        t_cp.setText("" + cp);
                    } catch (Exception e) {
                        t_cp.setText("");
                    }
                    if (orden_act.getClientes().getMunicipio() != null)
                        t_municipio.setText(orden_act.getClientes().getMunicipio());
                    else
                        t_municipio.setText("");
                    c_pais.setSelectedItem(orden_act.getClientes().getPais());
                    if (orden_act.getClientes().getNumeroExterior() != null)
                        t_numero_exterior.setText(orden_act.getClientes().getNumeroExterior());
                    else
                        t_numero_exterior.setText("");
                    if (orden_act.getClientes().getReceptor() != null)
                        t_receptor.setText(orden_act.getClientes().getReceptor());
                    else
                        t_receptor.setText("");
                    if (orden_act.getClientes().getEmailReceptor() != null)
                        t_email.setText(orden_act.getClientes().getEmailReceptor());
                    else
                        t_email.setText("");
                }
                session.close();
            } catch (Exception e) {
                System.out.println(e);
            } finally {
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        }
    }

public void tabla_tamaos()
{
    TableColumnModel col_model = t_datos.getColumnModel();
    FormatoEditor fe=new FormatoEditor();
    t_datos.setDefaultEditor(Double.class, fe);
    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(2);
                  break;
              case 2:
                  column.setPreferredWidth(350);
                  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.String.class, java.lang.Double.class, java.lang.Double.class,
                    java.lang.Double.class };
            boolean[] canEdit = new boolean[] { true, 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, 4)) * ((double) value));
                            double desc = ((double) t_datos.getValueAt(row, 5)) / 100;
                            double total = suma - (suma * desc);
                            t_datos.setValueAt(total, row, 6);
                        }
                        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 >= 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, 5)) / 100;
                            double total = suma - (suma * desc);
                            t_datos.setValueAt(total, row, 6);
                        }
                        sumaTotales();
                    }
                    break;
                case 5:
                    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, 4))
                                    * ((double) t_datos.getValueAt(row, 0)));
                            double desc = ((double) value) / 100;
                            double total = suma - (suma * desc);
                            t_datos.setValueAt(total, row, 6);
                        }
                        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 {
            /*if(orden_act==null)
            iva=0;*/
            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, 6);
            }
            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) {
        int val = -1;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            Factura[] fac = (Factura[]) or.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) {
                    factura = fac[r];
                    val = fac[r].getIdFactura();
                }
            }
        } catch (Exception e) {
            val = -1;
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
        }
        return val;
    }

    private boolean guardarOrden() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        boolean ID = false;
        try {
            session.beginTransaction().begin();
            orden_act = (Orden) session.get(Orden.class, Integer.parseInt(t_orden.getText()));
            //**********Almacenamos el Registro*******************
            Clientes cliente = new Clientes();
            Tipo unidad_tipo = new Tipo();
            Marca mr = new Marca();

            if (t_inc.getText().compareTo("") != 0)
                orden_act.setInciso(t_inc.getText());
            else
                orden_act.setInciso(null);

            /*if(t_nombre_cliente.getText().compareTo("")!=0)
            {
            cliente.setIdClientes(Integer.parseInt(l_id_cliente.getText()));
            registro.setClientes(cliente);
            }*/

            if (t_siniestro.getText().compareTo("") != 0)
                orden_act.setSiniestro(t_siniestro.getText());
            else
                orden_act.setSiniestro(null);

            if (t_poliza.getText().compareTo("") != 0)
                orden_act.setPoliza(t_poliza.getText());
            else
                orden_act.setPoliza(null);

            if (t_reporte.getText().compareTo("") != 0)
                orden_act.setNoReporte(t_reporte.getText());
            else
                orden_act.setNoReporte(null);

            if (t_tipo.getText().compareTo("") != 0) {
                unidad_tipo.setTipoNombre(t_tipo.getText());
                orden_act.setTipo(unidad_tipo);
            }

            if (t_marca.getText().compareTo("") != 0) {
                mr.setIdMarca(l_marca.getText());
                orden_act.setMarca(mr);
            }

            if (t_placas.getText().compareTo("") != 0)
                orden_act.setNoPlacas(t_placas.getText());
            else
                orden_act.setNoPlacas(null);

            if (t_modelo.getText().compareTo("") != 0)
                orden_act.setModelo(Integer.parseInt(t_modelo.getText()));

            if (t_serie.getText().compareTo("") != 0)
                orden_act.setNoSerie(t_serie.getText());
            else
                orden_act.setNoSerie(null);

            //registro.setKm(t_km.getText());
            orden_act.setUsuarioByIdModificado(user);

            session.update(orden_act);
            session.getTransaction().commit();
            ID = true;
        } catch (HibernateException he) {
            he.printStackTrace();
            session.getTransaction().rollback();
            ID = false;
        }
        if (session != null)
            if (session.isOpen())
                session.close();
        return ID;
    }
}