Contabilidad.AXA.java Source code

Java tutorial

Introduction

Here is the source code for Contabilidad.AXA.java

Source

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

package Contabilidad;

import Hibernate.Util.HibernateUtil;
import Hibernate.entidades.Concepto;
import Hibernate.entidades.Configuracion;
import Hibernate.entidades.Factura;
import Hibernate.entidades.Orden;
import Hibernate.entidades.OrdenExterna;
import Hibernate.entidades.Usuario;
import Servicios.EnviarCorreo;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.BufferedWriter;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Random;
import java.util.Vector;
import java.util.concurrent.ExecutionException;
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 javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import mx.com.fact.schema.ws.RequestTransaction;
import mx.com.fact.schema.ws.RequestTransactionResponse;
import mysuite.TAllowanceChargeType;
import mysuite.TComprobanteEx;
import mysuite.TConceptoEx;
import mysuite.TCountryCode;
import mysuite.TCurrencyCode;
import mysuite.TDatosAdicionales;
import mysuite.TDescuentosYRecargos;
import mysuite.TDictionaries;
import mysuite.TDictionary;
import mysuite.TDiscountOrRecharge;
import mysuite.TDomicilioComercial;
import mysuite.TFactDocMX;
import mysuite.TImpuestos;
import mysuite.TMTECabecera;
import mysuite.TMTEImportesAdicionales;
import mysuite.TMTEPoliza;
import mysuite.TMTEReaseguradora;
import mysuite.TMTEVehiculo;
import mysuite.TReferenciaCorta;
import mysuite.TRelacionComercial;
import mysuite.TResumenDeDescuentosYRecargos;
import mysuite.TResumenDeImpuestos;
import mysuite.TSettlementType;
import mysuite.TSpecialServicesType;
import mysuite.TTax;
import mysuite.TTaxContext;
import mysuite.TTaxOperation;
import mysuite.TTextoLibre;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import Integral.Comprimir;
import Integral.FormatoTabla;
import Integral.Herramientas;
import Integral.Render1;
import Integral.numeroLetra;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

/**
 *
 * @author salvador
 */
public class AXA extends javax.swing.JDialog {

    private Usuario user;
    String error = "";
    String sessionPrograma = null;
    FormatoTabla formato;
    Herramientas h;
    String abrir = "";
    String idBuscar = "";
    DefaultTableModel model;
    DefaultTableModel modeloFactura;
    boolean permiso = false;
    int iva = 0;
    String[] columnas = new String[] { "Id", "Can", "Med", "Descripcin", "Costo c/u", "Descuento", "Total" };
    String[] columnas1 = new String[] { "RFC", "UUID", "SUCURSAL", "SERIE", "FOLIO", "FECHA", "MONTO", "MONEDA" };
    Factura factura;
    public static final Factura RET_CANCEL = null;
    private Factura returnStatus = RET_CANCEL;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-Ss");

    /**
     * Creates new form QUALITAS
     */
    public AXA(java.awt.Frame parent, boolean modal, Usuario u, String ses, Factura fac) {
        super(parent, modal);
        initComponents();
        factura = fac;
        user = u;
        sessionPrograma = ses;
        formato = new FormatoTabla();
        borra_cajas();
        habilita(true, false);
        //consulta();
    }

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

        jLabel27 = new javax.swing.JLabel();
        consulta = new javax.swing.JDialog();
        jLabel43 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        t_facturas = new javax.swing.JTable();
        jPanel15 = new javax.swing.JPanel();
        b_cancelar = new javax.swing.JButton();
        b_descargar = new javax.swing.JButton();
        aviso = new javax.swing.JFileChooser();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        b_salir = new javax.swing.JButton();
        b_generar = new javax.swing.JButton();
        b_actualizar = new javax.swing.JButton();
        progreso = new javax.swing.JProgressBar();
        jLabel29 = new javax.swing.JLabel();
        contenedor = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        t_social = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        t_rfc = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        t_calle = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        t_no_exterior = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        t_cp = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        t_colonia = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        t_municipio = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        c_estado = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        c_pais = new javax.swing.JComboBox();
        jLabel19 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jPanel9 = 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();
        jLabel20 = new javax.swing.JLabel();
        t_metodo_pago = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        t_cuenta_pago = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        t_forma_pago = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        c_moneda = new javax.swing.JComboBox();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        t_tipo_cambio = new javax.swing.JFormattedTextField();
        t_descuento = new javax.swing.JFormattedTextField();
        l_iva1 = new javax.swing.JLabel();
        b_mas = new javax.swing.JButton();
        b_menos = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        t_datos = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        jLabel30 = new javax.swing.JLabel();
        c_tipo_facturacion = new javax.swing.JComboBox();
        jLabel45 = new javax.swing.JLabel();
        jLabel46 = new javax.swing.JLabel();
        jLabel47 = new javax.swing.JLabel();
        t_inciso = new javax.swing.JTextField();
        jLabel70 = new javax.swing.JLabel();
        jLabel71 = new javax.swing.JLabel();
        t_numero = new javax.swing.JTextField();
        jLabel72 = new javax.swing.JLabel();
        jLabel75 = new javax.swing.JLabel();
        t_siniestro = new javax.swing.JTextField();
        jLabel76 = new javax.swing.JLabel();
        jLabel53 = new javax.swing.JLabel();
        t_deducible = new javax.swing.JFormattedTextField();
        t_tipo_poliza = new javax.swing.JTextField();
        t_riesgo = new javax.swing.JTextField();
        jLabel44 = new javax.swing.JLabel();
        jLabel49 = new javax.swing.JLabel();
        jPanel11 = new javax.swing.JPanel();
        jLabel31 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        t_nombre_emisor = new javax.swing.JTextField();
        jLabel33 = new javax.swing.JLabel();
        t_correo_emisor = new javax.swing.JTextField();
        jLabel34 = new javax.swing.JLabel();
        t_tel_emisor = new javax.swing.JTextField();
        jLabel35 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jLabel65 = new javax.swing.JLabel();
        t_ri_emisor = new javax.swing.JTextField();
        jPanel12 = new javax.swing.JPanel();
        jLabel37 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        t_nombre_receptor = new javax.swing.JTextField();
        jLabel39 = new javax.swing.JLabel();
        t_correo_receptor = new javax.swing.JTextField();
        jLabel40 = new javax.swing.JLabel();
        t_tel_receptor = new javax.swing.JTextField();
        jLabel41 = new javax.swing.JLabel();
        jLabel42 = new javax.swing.JLabel();
        jLabel84 = new javax.swing.JLabel();
        t_ri_receptor = new javax.swing.JTextField();
        jPanel13 = new javax.swing.JPanel();
        jLabel50 = new javax.swing.JLabel();
        t_modelo_vehiculo = new javax.swing.JTextField();
        t_marca_vehiculo = new javax.swing.JTextField();
        jLabel52 = new javax.swing.JLabel();
        jLabel54 = new javax.swing.JLabel();
        t_anio_vehiculo = new javax.swing.JTextField();
        jLabel56 = new javax.swing.JLabel();
        t_serie_vehiculo = new javax.swing.JTextField();
        jLabel57 = new javax.swing.JLabel();
        jLabel58 = new javax.swing.JLabel();
        t_placas_vehiculo = new javax.swing.JTextField();
        jLabel59 = new javax.swing.JLabel();
        jLabel60 = new javax.swing.JLabel();
        jLabel62 = new javax.swing.JLabel();
        t_motor_vehiculo = new javax.swing.JTextField();
        jLabel77 = new javax.swing.JLabel();
        jLabel63 = new javax.swing.JLabel();
        jLabel64 = new javax.swing.JLabel();
        t_proveedor = new javax.swing.JTextField();
        jLabel68 = new javax.swing.JLabel();
        jLabel48 = new javax.swing.JLabel();
        t_codigo = new javax.swing.JTextField();
        jLabel66 = new javax.swing.JLabel();
        t_fecha_factura = new javax.swing.JTextField();
        jLabel85 = new javax.swing.JLabel();
        jLabel87 = new javax.swing.JLabel();
        t_condiciones = new javax.swing.JTextField();
        jLabel88 = new javax.swing.JLabel();
        jPanel14 = new javax.swing.JPanel();
        jLabel79 = new javax.swing.JLabel();
        jLabel80 = new javax.swing.JLabel();
        jLabel81 = new javax.swing.JLabel();
        t_serie_factura = new javax.swing.JTextField();
        t_folio_factura = new javax.swing.JTextField();
        jLabel82 = new javax.swing.JLabel();
        jLabel83 = new javax.swing.JLabel();
        t_xml = new javax.swing.JTextField();
        t_pdf = new javax.swing.JTextField();
        b_xml = new javax.swing.JButton();
        b_pdf = new javax.swing.JButton();
        b_email = new javax.swing.JButton();
        jLabel86 = new javax.swing.JLabel();
        t_uuid_factura = new javax.swing.JTextField();

        jLabel27.setText("*");

        consulta.setAlwaysOnTop(true);
        consulta.setModalityType(java.awt.Dialog.ModalityType.DOCUMENT_MODAL);

        jLabel43.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel43.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel43.setText("Se encontraron las siguentes facturas timbradas y activas en el servidor SAT");
        consulta.getContentPane().add(jLabel43, java.awt.BorderLayout.PAGE_START);

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

        }, new String[] { "RFC", "UUID", "SUCURSAL", "SERIE", "FOLIO", "FECHA", "MONTO", "MONEDA" }) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class,
                    java.lang.String.class };
            boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false, false };

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

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

        consulta.getContentPane().add(jScrollPane2, java.awt.BorderLayout.CENTER);

        b_cancelar.setText("Cancelar factura");
        b_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_cancelarActionPerformed(evt);
            }
        });

        b_descargar.setText("Descargar PDF");
        b_descargar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_descargarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel15Layout = new javax.swing.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout
                .setHorizontalGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                jPanel15Layout.createSequentialGroup().addGap(0, 579, Short.MAX_VALUE)
                                        .addComponent(b_cancelar)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(b_descargar)));
        jPanel15Layout
                .setVerticalGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(b_cancelar).addComponent(b_descargar)));

        consulta.getContentPane().add(jPanel15, java.awt.BorderLayout.PAGE_END);

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

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

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

        jLabel1.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel1.setText("Emisin de facturas a AXA");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout
                .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(355, 355, 355).addComponent(jLabel1)
                                .addContainerGap(564, Short.MAX_VALUE)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING));

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

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

        b_salir.setBackground(new java.awt.Color(2, 135, 242));
        b_salir.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        b_salir.setForeground(new java.awt.Color(254, 254, 254));
        b_salir.setIcon(new ImageIcon("imagenes/salir1.png"));
        b_salir.setText("Salir");
        b_salir.setToolTipText("Cierra la ventana");
        b_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_salirActionPerformed(evt);
            }
        });

        b_generar.setBackground(new java.awt.Color(2, 135, 242));
        b_generar.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        b_generar.setForeground(new java.awt.Color(254, 254, 254));
        b_generar.setIcon(new ImageIcon("imagenes/nube.png"));
        b_generar.setText("Generar comprobante");
        b_generar.setToolTipText("Genera el timbre fiscal");
        b_generar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_generarActionPerformed(evt);
            }
        });

        b_actualizar.setBackground(new java.awt.Color(2, 135, 242));
        b_actualizar.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        b_actualizar.setForeground(new java.awt.Color(254, 254, 254));
        b_actualizar.setIcon(new ImageIcon("imagenes/guardar-documento.png"));
        b_actualizar.setText("Actualizar");
        b_actualizar.setToolTipText("Actualiza el registro en la base de datos");
        b_actualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_actualizarActionPerformed(evt);
            }
        });

        progreso.setString("Listo");
        progreso.setStringPainted(true);

        jLabel29.setText("Los campos marcados con \"*\" son obligatorios");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(progreso, javax.swing.GroupLayout.PREFERRED_SIZE, 300,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel29)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 260, Short.MAX_VALUE)
                        .addComponent(b_actualizar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(b_generar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(b_salir)));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(b_salir).addComponent(b_generar).addComponent(b_actualizar)
                        .addComponent(progreso, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel29)));

        getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_END);

        contenedor.setBackground(new java.awt.Color(254, 254, 254));
        contenedor.setOpaque(true);

        jPanel3.setBackground(new java.awt.Color(254, 254, 254));
        jPanel3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        jPanel6.setBackground(new java.awt.Color(254, 254, 254));
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(
                javax.swing.BorderFactory.createMatteBorder(1, 0, 1, 0, new java.awt.Color(0, 0, 0)),
                "Identificacin", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.ABOVE_TOP,
                new java.awt.Font("Arial", 1, 12))); // NOI18N

        jLabel2.setText("Razn Social:");

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

        jLabel3.setText("RFC:");

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

        jLabel4.setText("*");

        jLabel5.setText("*");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout
                .setHorizontalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel6Layout.createSequentialGroup().addContainerGap().addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_social, javax.swing.GroupLayout.PREFERRED_SIZE, 620,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(7, 7, 7).addComponent(jLabel5).addGap(18, 18, 18).addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_rfc, javax.swing.GroupLayout.PREFERRED_SIZE, 136,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(4, 4, 4).addComponent(jLabel4).addContainerGap(162, Short.MAX_VALUE)));
        jPanel6Layout
                .setVerticalGroup(
                        jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel6Layout.createSequentialGroup().addContainerGap(20, Short.MAX_VALUE)
                                        .addGroup(jPanel6Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel2)
                                                .addComponent(t_social, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel3)
                                                .addComponent(t_rfc, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel4).addComponent(jLabel5))
                                        .addContainerGap()));

        jPanel7.setBackground(new java.awt.Color(254, 254, 254));
        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(
                javax.swing.BorderFactory.createMatteBorder(1, 0, 1, 0, new java.awt.Color(0, 0, 0)),
                "Domicilio Fiscal", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.ABOVE_TOP,
                new java.awt.Font("Arial", 1, 12))); // NOI18N

        jLabel6.setText("Calle:");

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

        jLabel7.setText("*");

        jLabel8.setText("Nmero Ext:");

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

        jLabel9.setText("*");

        jLabel10.setText("CP:");

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

        jLabel11.setText("*");

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

        jLabel12.setText("*");

        jLabel13.setText("Col:");

        jLabel14.setText("Municipio:");

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

        jLabel15.setText("*");

        jLabel16.setText("Edo:");

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

        jLabel17.setText("Pais");

        jLabel18.setText("*");

        c_pais.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MEXICO" }));
        c_pais.setSelectedItem("MX");
        c_pais.setToolTipText("Pais del receptor");

        jLabel19.setText("*");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(jPanel7Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel7Layout.createSequentialGroup().addGroup(jPanel7Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel7Layout.createSequentialGroup().addGap(9, 9, 9).addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_calle, javax.swing.GroupLayout.PREFERRED_SIZE, 478,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(3, 3, 3).addComponent(jLabel7).addGap(37, 37, 37).addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_no_exterior, javax.swing.GroupLayout.PREFERRED_SIZE, 84,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(3, 3, 3).addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_cp, javax.swing.GroupLayout.PREFERRED_SIZE, 84,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(1, 1, 1).addComponent(jLabel11))
                        .addGroup(jPanel7Layout.createSequentialGroup().addGap(18, 18, 18)
                                .addGroup(jPanel7Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel7Layout.createSequentialGroup().addComponent(jLabel16)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(c_estado, javax.swing.GroupLayout.PREFERRED_SIZE, 220,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(2, 2, 2).addComponent(jLabel18).addGap(36, 36, 36)
                                                .addComponent(jLabel17)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(c_pais, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(1, 1, 1).addComponent(jLabel19)
                                                .addGap(0, 0, Short.MAX_VALUE))
                                        .addGroup(jPanel7Layout.createSequentialGroup().addComponent(jLabel13)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_colonia, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        400, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(3, 3, 3).addComponent(jLabel12)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jLabel14)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_municipio, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        332, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(3, 3, 3).addComponent(jLabel15)))))
                        .addContainerGap()));
        jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel7Layout.createSequentialGroup().addGap(24, 24, 24).addGroup(jPanel7Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel6)
                        .addComponent(t_calle, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel7).addComponent(jLabel8)
                        .addComponent(t_no_exterior, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9).addComponent(jLabel10)
                        .addComponent(t_cp, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel11)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel13)
                                .addComponent(t_colonia, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel12).addComponent(jLabel14)
                                .addComponent(t_municipio, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel16)
                                .addComponent(c_estado, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel17).addComponent(jLabel18)
                                .addComponent(c_pais, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel19))
                        .addContainerGap(28, Short.MAX_VALUE)));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap()));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap()
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(262, Short.MAX_VALUE)));

        contenedor.addTab("Receptor", jPanel3);

        jPanel4.setBackground(new java.awt.Color(254, 254, 254));
        jPanel4.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jPanel4.setLayout(new java.awt.BorderLayout());

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

        jPanel9.setBackground(new java.awt.Color(2, 135, 242));
        jPanel9.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:");
        jPanel9.add(l_subtotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(48, 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
        jPanel9.add(t_subtotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(97, 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("Monto de iva");
        t_iva.setEnabled(false);
        t_iva.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        jPanel9.add(t_iva, new org.netbeans.lib.awtextra.AbsoluteConstraints(97, 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.:");
        jPanel9.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:");
        jPanel9.add(l_total, new org.netbeans.lib.awtextra.AbsoluteConstraints(61, 45, -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
        jPanel9.add(t_total, new org.netbeans.lib.awtextra.AbsoluteConstraints(97, 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);
            }
        });
        jPanel9.add(t_iva1, new org.netbeans.lib.awtextra.AbsoluteConstraints(1, 20, 40, -1));

        jLabel20.setForeground(new java.awt.Color(254, 254, 254));
        jLabel20.setText("Metodo de Pago:");

        t_metodo_pago.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        t_metodo_pago.setText("03");
        t_metodo_pago.setToolTipText("Metodo de pago del monto de la factura");
        t_metodo_pago.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_metodo_pago.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_metodo_pagoKeyTyped(evt);
            }
        });

        jLabel21.setForeground(new java.awt.Color(254, 254, 254));
        jLabel21.setText("Cuenta de Pago:");

        t_cuenta_pago.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        t_cuenta_pago.setToolTipText("Nmero de cuenta en caso de que el pago sea por depsito bancario");
        t_cuenta_pago.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_cuenta_pago.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_cuenta_pagoKeyTyped(evt);
            }
        });

        jLabel22.setForeground(new java.awt.Color(254, 254, 254));
        jLabel22.setText("Forma de Pago:");

        t_forma_pago.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        t_forma_pago.setText("PAGO EN UNA SOLA EXHIBICION");
        t_forma_pago.setToolTipText("Forama de pago de la factura");
        t_forma_pago.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_forma_pago.setEnabled(false);

        jLabel23.setForeground(new java.awt.Color(254, 254, 254));
        jLabel23.setText("Moneda:");

        c_moneda.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        c_moneda.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MXN", "USD" }));
        c_moneda.setToolTipText("Tipo de moneda del monto");

        jLabel24.setForeground(new java.awt.Color(254, 254, 254));
        jLabel24.setText("Factor de Cambio");

        jLabel25.setForeground(new java.awt.Color(254, 254, 254));
        jLabel25.setText("*");

        jLabel26.setForeground(new java.awt.Color(254, 254, 254));
        jLabel26.setText("*");

        jLabel28.setForeground(new java.awt.Color(254, 254, 254));
        jLabel28.setText("*");

        t_tipo_cambio.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_tipo_cambio.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        t_tipo_cambio.setToolTipText("Factor de cambio en caso de ser moneda extranjera");
        t_tipo_cambio.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N

        t_descuento.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_descuento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("0.00"))));
        t_descuento.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        t_descuento.setToolTipText("Agregar descuento global");
        t_descuento.setEnabled(false);
        t_descuento.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        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:");

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

        jButton1.setText("Exportar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(jPanel8Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel8Layout.createSequentialGroup()
                                        .addComponent(b_mas, javax.swing.GroupLayout.PREFERRED_SIZE, 19,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(b_menos, javax.swing.GroupLayout.PREFERRED_SIZE, 19,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(30, 30, 30).addComponent(jLabel20)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(t_metodo_pago, javax.swing.GroupLayout.PREFERRED_SIZE, 221,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel25)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel22)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_forma_pago, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel26, javax.swing.GroupLayout.PREFERRED_SIZE, 13,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(l_iva1, javax.swing.GroupLayout.PREFERRED_SIZE, 83,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel8Layout.createSequentialGroup().addContainerGap()
                                        .addComponent(jLabel21)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_cuenta_pago, javax.swing.GroupLayout.PREFERRED_SIZE, 221,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel23)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(c_moneda, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel24)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_tipo_cambio, javax.swing.GroupLayout.PREFERRED_SIZE, 83,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel28).addGap(18, 18, 18).addComponent(jButton1)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(t_descuento, javax.swing.GroupLayout.PREFERRED_SIZE, 87,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(54, 54, 54).addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, 190,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));
        jPanel8Layout.setVerticalGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                .addGroup(jPanel8Layout.createSequentialGroup().addGroup(jPanel8Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(b_mas, javax.swing.GroupLayout.PREFERRED_SIZE, 18,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(b_menos, javax.swing.GroupLayout.PREFERRED_SIZE, 18,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel20)
                                .addComponent(t_metodo_pago, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel25).addComponent(jLabel22))
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel26).addComponent(t_forma_pago,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel8Layout.createSequentialGroup().addGap(3, 3, 3)
                                .addGroup(jPanel8Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(l_iva1).addComponent(t_descuento,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(
                                jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel8Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(t_cuenta_pago, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel21)
                                                .addComponent(c_moneda, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel24).addComponent(jLabel28)
                                                .addComponent(jLabel23).addComponent(t_tipo_cambio,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(jButton1))
                        .addContainerGap(12, Short.MAX_VALUE)));

        jPanel4.add(jPanel8, java.awt.BorderLayout.PAGE_END);

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

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

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

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

        jPanel4.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        contenedor.addTab("Productos y servicios", jPanel4);

        jPanel5.setBackground(new java.awt.Color(254, 254, 254));
        jPanel5.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jPanel5.setForeground(new java.awt.Color(254, 254, 254));

        jPanel10.setBackground(new java.awt.Color(254, 254, 254));
        jPanel10.setBorder(
                javax.swing.BorderFactory.createTitledBorder(
                        javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createMatteBorder(1,
                                0, 1, 0, new java.awt.Color(0, 0, 0)), "Poliza"),
                        "Poliza", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                        javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 10))); // NOI18N

        jLabel30.setText("Tipo Facturacin:");

        c_tipo_facturacion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Autos" }));
        c_tipo_facturacion.setToolTipText("Tipo de factura");

        jLabel45.setText("Tipo poliza:");

        jLabel46.setText("*");

        jLabel47.setText("*");

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

        jLabel70.setText("Inciso");
        jLabel70.setToolTipText("");

        jLabel71.setText("*");

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

        jLabel72.setText("Nmero:");

        jLabel75.setText("Siniestro:");

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

        jLabel76.setText("*");

        jLabel53.setText("Deducible:");

        t_deducible.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_deducible.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        t_deducible.setToolTipText("Monto del deducible");
        t_deducible.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N

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

        t_riesgo.setToolTipText("Tipo de riesgo");
        t_riesgo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_riesgo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_riesgoKeyTyped(evt);
            }
        });

        jLabel44.setText("Riesgo:");

        jLabel49.setText("*");

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout
                .setHorizontalGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel10Layout.createSequentialGroup()
                                .addGroup(jPanel10Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(jPanel10Layout.createSequentialGroup().addComponent(jLabel75)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_siniestro, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel76)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jLabel53)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_deducible, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(26, 26, 26).addComponent(jLabel44)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(
                                                        t_riesgo, javax.swing.GroupLayout.PREFERRED_SIZE, 247,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel10Layout.createSequentialGroup().addComponent(jLabel30)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(c_tipo_facturacion,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 182,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel46).addGap(18, 18, 18).addComponent(jLabel70)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_inciso, javax.swing.GroupLayout.PREFERRED_SIZE, 111,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(47, 47, 47).addComponent(jLabel45)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_tipo_poliza, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        144, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel10Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel10Layout.createSequentialGroup().addComponent(jLabel47)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        163, Short.MAX_VALUE)
                                                .addComponent(jLabel72).addGap(5, 5, 5)
                                                .addComponent(t_numero, javax.swing.GroupLayout.PREFERRED_SIZE, 111,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel71).addGap(32, 32, 32))
                                        .addGroup(jPanel10Layout.createSequentialGroup().addComponent(jLabel49)
                                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        Short.MAX_VALUE)))));
        jPanel10Layout.setVerticalGroup(jPanel10Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel10Layout.createSequentialGroup().addGroup(jPanel10Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel45)
                                .addComponent(t_tipo_poliza, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel47))
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel70).addComponent(t_inciso,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel72)
                                .addComponent(t_numero, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel71))
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel30)
                                .addComponent(c_tipo_facturacion, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel46)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel10Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel44)
                                        .addComponent(t_riesgo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel49).addComponent(jLabel53).addComponent(t_deducible,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel10Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel75)
                                        .addComponent(t_siniestro, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel76)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jPanel11.setBackground(new java.awt.Color(254, 254, 254));
        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder(
                javax.swing.BorderFactory.createMatteBorder(1, 0, 1, 0, new java.awt.Color(0, 0, 0)),
                "Contacto Emisor", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.ABOVE_TOP,
                new java.awt.Font("Arial", 1, 10))); // NOI18N

        jLabel31.setText("RI Emisor");

        jLabel32.setText("Nombre:");

        t_nombre_emisor.setToolTipText("Nombre del contacto emisor");
        t_nombre_emisor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_nombre_emisor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_nombre_emisorKeyTyped(evt);
            }
        });

        jLabel33.setText("Correo:");

        t_correo_emisor.setToolTipText("Correo del contacto emisor");
        t_correo_emisor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_correo_emisor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_correo_emisorKeyTyped(evt);
            }
        });

        jLabel34.setText("Tel:");

        t_tel_emisor.setToolTipText("Telfono del contacto emisor");
        t_tel_emisor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_tel_emisor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_tel_emisorKeyTyped(evt);
            }
        });

        jLabel35.setText("*");

        jLabel36.setText("*");

        jLabel65.setText("*");

        t_ri_emisor.setToolTipText("ID que Interfactura proporciona al contacto emisor");
        t_ri_emisor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_ri_emisor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_ri_emisorKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(jPanel11Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel11Layout.createSequentialGroup()
                        .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel33).addComponent(jLabel31))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel11Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel11Layout.createSequentialGroup()
                                        .addComponent(t_ri_emisor, javax.swing.GroupLayout.PREFERRED_SIZE, 171,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel65).addGap(23, 23, 23).addComponent(jLabel32)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_nombre_emisor, javax.swing.GroupLayout.PREFERRED_SIZE, 498,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel11Layout.createSequentialGroup()
                                        .addComponent(t_correo_emisor, javax.swing.GroupLayout.PREFERRED_SIZE, 461,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel36)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel34)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_tel_emisor, javax.swing.GroupLayout.PREFERRED_SIZE, 171,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel35)
                        .addGap(0, 0, Short.MAX_VALUE)));
        jPanel11Layout.setVerticalGroup(jPanel11Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel11Layout.createSequentialGroup().addContainerGap().addGroup(jPanel11Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel31)
                        .addComponent(jLabel32)
                        .addComponent(t_nombre_emisor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel35).addComponent(jLabel65).addComponent(t_ri_emisor,
                                javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel33)
                                .addComponent(t_correo_emisor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel34)
                                .addComponent(t_tel_emisor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel36))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jPanel12.setBackground(new java.awt.Color(254, 254, 254));
        jPanel12.setBorder(javax.swing.BorderFactory.createTitledBorder(
                javax.swing.BorderFactory.createMatteBorder(1, 0, 1, 0, new java.awt.Color(0, 0, 0)),
                "Contacto Receptor", javax.swing.border.TitledBorder.LEFT,
                javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("Arial", 1, 10))); // NOI18N

        jLabel37.setText("RI Receptor");

        jLabel38.setText("Nombre:");

        t_nombre_receptor.setToolTipText("Nombre del contacto receptor");
        t_nombre_receptor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_nombre_receptor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_nombre_receptorKeyTyped(evt);
            }
        });

        jLabel39.setText("Correo:");

        t_correo_receptor.setToolTipText("Correo del contacto receptor");
        t_correo_receptor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_correo_receptor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_correo_receptorKeyTyped(evt);
            }
        });

        jLabel40.setText("Tel:");

        t_tel_receptor.setToolTipText("Telfono del contacto receptor");
        t_tel_receptor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_tel_receptor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_tel_receptorKeyTyped(evt);
            }
        });

        jLabel41.setText("*");

        jLabel42.setText("*");

        jLabel84.setText("*");

        t_ri_receptor.setToolTipText("ID que Interfactura proporciona al contacto receptor");
        t_ri_receptor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_ri_receptor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_ri_receptorKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(jPanel12Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel12Layout.createSequentialGroup()
                        .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel39).addComponent(jLabel37))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel12Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel12Layout.createSequentialGroup()
                                        .addComponent(t_ri_receptor, javax.swing.GroupLayout.PREFERRED_SIZE, 171,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel84).addGap(18, 18, 18).addComponent(jLabel38)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_nombre_receptor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                453, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel12Layout.createSequentialGroup()
                                        .addComponent(t_correo_receptor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                411, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel42)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel40).addGap(18, 18, 18).addComponent(t_tel_receptor,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 171,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel41)
                        .addGap(0, 0, Short.MAX_VALUE)));
        jPanel12Layout.setVerticalGroup(jPanel12Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel12Layout.createSequentialGroup().addContainerGap().addGroup(jPanel12Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel37).addComponent(jLabel38)
                                .addComponent(t_nombre_receptor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel41).addComponent(t_ri_receptor,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jLabel84, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel12Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel39)
                                        .addComponent(t_correo_receptor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(t_tel_receptor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel42))
                                .addComponent(jLabel40))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jPanel13.setBackground(new java.awt.Color(254, 254, 254));
        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder(
                javax.swing.BorderFactory.createMatteBorder(1, 0, 1, 0, new java.awt.Color(0, 0, 0)), "Vehculo",
                javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.ABOVE_TOP,
                new java.awt.Font("Arial", 1, 10))); // NOI18N

        jLabel50.setText("Modelo:");

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

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

        jLabel52.setText("Marca:");

        jLabel54.setText("*");

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

        jLabel56.setText("Ao:");

        t_serie_vehiculo.setToolTipText("Serie de la unidad");
        t_serie_vehiculo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_serie_vehiculo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_serie_vehiculoKeyTyped(evt);
            }
        });

        jLabel57.setText("Serie:");

        jLabel58.setText("Placas:");

        t_placas_vehiculo.setToolTipText("Placas de la unidad");
        t_placas_vehiculo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_placas_vehiculo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_placas_vehiculoKeyTyped(evt);
            }
        });

        jLabel59.setText("*");

        jLabel60.setText("*");

        jLabel62.setText("No. Motor:");

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

        jLabel77.setText("*");

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout
                .setHorizontalGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel13Layout.createSequentialGroup().addContainerGap().addGroup(jPanel13Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                                        jPanel13Layout.createSequentialGroup().addComponent(jLabel50)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(t_modelo_vehiculo).addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel54))
                                .addGroup(jPanel13Layout
                                        .createSequentialGroup().addComponent(jLabel52).addGap(5, 5, 5)
                                        .addComponent(t_marca_vehiculo).addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel59)))
                                .addGroup(jPanel13Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel13Layout.createSequentialGroup().addGap(46, 46, 46)
                                                .addGroup(jPanel13Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(jPanel13Layout.createSequentialGroup()
                                                                .addGap(38, 38, 38).addComponent(t_serie_vehiculo,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 198,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addComponent(jLabel57))
                                                .addGap(45, 45, 45).addComponent(jLabel62).addGap(18, 18, 18)
                                                .addComponent(t_motor_vehiculo))
                                        .addGroup(jPanel13Layout.createSequentialGroup().addGap(71, 71, 71)
                                                .addComponent(jLabel58).addGap(18, 18, 18)
                                                .addComponent(t_placas_vehiculo,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 170,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel77)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jLabel56).addGap(7, 7, 7)
                                                .addComponent(t_anio_vehiculo,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 198,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel60)))));
        jPanel13Layout.setVerticalGroup(jPanel13Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel13Layout.createSequentialGroup().addContainerGap().addGroup(jPanel13Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel50)
                        .addComponent(t_modelo_vehiculo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel54).addComponent(jLabel58)
                        .addComponent(t_placas_vehiculo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel77).addComponent(jLabel56)
                        .addComponent(t_anio_vehiculo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel60)).addGap(14, 14, 14)
                        .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel13Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel57).addComponent(t_serie_vehiculo,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel13Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel62)
                                        .addComponent(t_motor_vehiculo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel52)
                                        .addComponent(t_marca_vehiculo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel59)))
                        .addContainerGap(37, Short.MAX_VALUE)));

        jLabel63.setText("No:Proveedor:");

        jLabel64.setText("Fecha Prefactura:");

        t_proveedor.setToolTipText("Campo de 5 posiciones que asigna Interfactura");
        t_proveedor.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_proveedor.setEnabled(false);
        t_proveedor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_proveedorKeyTyped(evt);
            }
        });

        jLabel68.setText("*");

        jLabel48.setText("Folio Prefactura:");

        t_codigo.setToolTipText("Folio interno de la factura");
        t_codigo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_codigo.setEnabled(false);
        t_codigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_codigoKeyTyped(evt);
            }
        });

        jLabel66.setText("*");

        t_fecha_factura.setToolTipText("Fecha interna de la factura");
        t_fecha_factura.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_fecha_factura.setEnabled(false);
        t_fecha_factura.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_fecha_facturaKeyTyped(evt);
            }
        });

        jLabel85.setText("*");

        jLabel87.setText("condiciones de Pago:");

        t_condiciones.setToolTipText("Condiciones de pago de la factura");
        t_condiciones.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_condiciones.setEnabled(false);
        t_condiciones.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_condicionesKeyTyped(evt);
            }
        });

        jLabel88.setText("*");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(jPanel5Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel12, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel13, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel5Layout.createSequentialGroup().addComponent(jLabel63)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(t_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 74,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(1, 1, 1).addComponent(jLabel68).addGap(18, 18, 18)
                                        .addComponent(jLabel48)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 90,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(6, 6, 6).addComponent(jLabel66).addGap(18, 18, 18)
                                        .addComponent(jLabel64)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_fecha_factura, javax.swing.GroupLayout.PREFERRED_SIZE, 142,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(4, 4, 4).addComponent(jLabel85).addGap(18, 18, 18)
                                        .addComponent(jLabel87)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t_condiciones, javax.swing.GroupLayout.PREFERRED_SIZE, 142,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(4, 4, 4).addComponent(jLabel88).addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap()));
        jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap()
                        .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel87)
                                        .addComponent(t_condiciones, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel88))
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel64)
                                        .addComponent(t_fecha_factura, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel85))
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel48)
                                        .addComponent(t_codigo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel66))
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(t_proveedor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel68))
                                .addComponent(jLabel63))
                        .addContainerGap(57, Short.MAX_VALUE)));

        contenedor.addTab("Datos de addenda", jPanel5);

        jPanel14.setBackground(new java.awt.Color(254, 254, 254));
        jPanel14.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        jLabel79.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel79.setText("Datos de la Factura Electrnica");

        jLabel80.setText("Serie:");

        jLabel81.setText("Folio:");

        t_serie_factura.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        t_serie_factura.setToolTipText("Nmero de serie asignado por el PAC");
        t_serie_factura.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_serie_factura.setEnabled(false);

        t_folio_factura.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        t_folio_factura.setToolTipText("Folio asignado por el PAC");
        t_folio_factura.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_folio_factura.setEnabled(false);

        jLabel82.setText("XML:");

        jLabel83.setText("PDF:");

        t_xml.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        t_xml.setToolTipText("Factura en formato XML");
        t_xml.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_xml.setEnabled(false);

        t_pdf.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        t_pdf.setToolTipText("Factura en formato PDF");
        t_pdf.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_pdf.setEnabled(false);

        b_xml.setBackground(new java.awt.Color(2, 135, 242));
        b_xml.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        b_xml.setForeground(new java.awt.Color(254, 254, 254));
        b_xml.setIcon(new ImageIcon("imagenes/xml_icon.png"));
        b_xml.setText("Abrir");
        b_xml.setToolTipText("Abrir factura en formato XML");
        b_xml.setEnabled(false);
        b_xml.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_xmlActionPerformed(evt);
            }
        });

        b_pdf.setBackground(new java.awt.Color(2, 135, 242));
        b_pdf.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        b_pdf.setForeground(new java.awt.Color(254, 254, 254));
        b_pdf.setIcon(new ImageIcon("imagenes/pdf_icon.png"));
        b_pdf.setText("Abrir");
        b_pdf.setToolTipText("Abrir factura en formato PDF");
        b_pdf.setEnabled(false);
        b_pdf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_pdfActionPerformed(evt);
            }
        });

        b_email.setBackground(new java.awt.Color(2, 135, 242));
        b_email.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        b_email.setForeground(new java.awt.Color(254, 254, 254));
        b_email.setIcon(new ImageIcon("imagenes/send2.png"));
        b_email.setText("Enviar al Cliente");
        b_email.setToolTipText("Comprime el XML y el PDF para enviarlo por correo electrnico");
        b_email.setEnabled(false);
        b_email.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_emailActionPerformed(evt);
            }
        });

        jLabel86.setText("UUID:");

        t_uuid_factura.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        t_uuid_factura.setToolTipText("Folio fiscal asignado por el SAT");
        t_uuid_factura.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        t_uuid_factura.setEnabled(false);

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(jPanel14Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel14Layout.createSequentialGroup().addGap(325, 325, 325).addGroup(jPanel14Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel79)
                                .addGroup(jPanel14Layout.createSequentialGroup().addGroup(jPanel14Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(jPanel14Layout.createSequentialGroup().addComponent(jLabel86)
                                                .addGap(18, 18, 18).addComponent(t_uuid_factura,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 160,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel14Layout.createSequentialGroup().addGroup(jPanel14Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel80).addComponent(jLabel81)).addGap(18, 18, 18)
                                                .addGroup(jPanel14Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(t_folio_factura,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 160,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(t_serie_factura,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 160,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))))
                                        .addGap(45, 45, 45)))
                        .addGroup(jPanel14Layout.createSequentialGroup().addGap(4, 4, 4)
                                .addGroup(jPanel14Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel82).addComponent(jLabel83))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel14Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel14Layout.createSequentialGroup()
                                                .addComponent(t_pdf, javax.swing.GroupLayout.PREFERRED_SIZE, 160,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(b_pdf))
                                        .addGroup(jPanel14Layout.createSequentialGroup()
                                                .addComponent(t_xml, javax.swing.GroupLayout.PREFERRED_SIZE, 160,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(b_xml))
                                        .addComponent(b_email))))
                        .addContainerGap(496, Short.MAX_VALUE)));
        jPanel14Layout.setVerticalGroup(jPanel14Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel14Layout.createSequentialGroup().addGap(97, 97, 97).addComponent(jLabel79)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel80).addComponent(t_serie_factura,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel81).addComponent(t_folio_factura,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel86).addComponent(t_uuid_factura,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel82)
                                .addComponent(t_xml, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(b_xml))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel83)
                                .addComponent(t_pdf, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(b_pdf))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(b_email)
                        .addContainerGap(201, Short.MAX_VALUE)));

        contenedor.addTab("Factura Electrnica", jPanel14);

        getContentPane().add(contenedor, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void b_generarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_generarActionPerformed
        // TODO add your handling code here:
        if (t_social.getText().trim().compareTo("") != 0) {
            if (t_rfc.getText().trim().compareTo("") != 0) {
                if (t_calle.getText().trim().compareTo("") != 0) {
                    if (t_colonia.getText().trim().compareTo("") != 0) {
                        if (c_estado.getSelectedIndex() >= 0) {
                            if (c_pais.getSelectedIndex() >= 0) {
                                if (t_no_exterior.getText().trim().compareTo("") != 0) {
                                    if (t_cp.getText().trim().compareTo("") != 0) {
                                        if (t_municipio.getText().trim().compareTo("") != 0) {
                                            if (t_metodo_pago.getText().trim().compareTo("") != 0) {
                                                if (c_moneda.getSelectedIndex() >= 0) {
                                                    if (t_tipo_cambio.getText().trim().compareTo("") != 0) {
                                                        if (t_datos.getRowCount() > 0) {
                                                            if (c_tipo_facturacion.getSelectedIndex() >= 0) {
                                                                if (t_inciso.getText().trim().compareTo("") != 0) {
                                                                    if (t_numero.getText().trim()
                                                                            .compareTo("") != 0) {
                                                                        if (t_tipo_poliza.getText().trim()
                                                                                .compareTo("") != 0) {
                                                                            if (t_siniestro.getText().trim()
                                                                                    .compareTo("") != 0) {
                                                                                if (t_ri_emisor.getText().trim()
                                                                                        .compareTo("") != 0) {
                                                                                    if (t_nombre_emisor.getText()
                                                                                            .trim()
                                                                                            .compareTo("") != 0) {
                                                                                        if (t_correo_emisor
                                                                                                .getText().trim()
                                                                                                .compareTo(
                                                                                                        "") != 0) {
                                                                                            if (t_ri_receptor
                                                                                                    .getText()
                                                                                                    .trim()
                                                                                                    .compareTo(
                                                                                                            "") != 0) {
                                                                                                if (t_nombre_receptor
                                                                                                        .getText()
                                                                                                        .trim()
                                                                                                        .compareTo(
                                                                                                                "") != 0) {
                                                                                                    if (t_correo_receptor
                                                                                                            .getText()
                                                                                                            .trim()
                                                                                                            .compareTo(
                                                                                                                    "") != 0) {
                                                                                                        if (t_modelo_vehiculo
                                                                                                                .getText()
                                                                                                                .trim()
                                                                                                                .compareTo(
                                                                                                                        "") != 0) {
                                                                                                            if (t_marca_vehiculo
                                                                                                                    .getText()
                                                                                                                    .trim()
                                                                                                                    .compareTo(
                                                                                                                            "") != 0) {
                                                                                                                if (t_anio_vehiculo
                                                                                                                        .getText()
                                                                                                                        .trim()
                                                                                                                        .compareTo(
                                                                                                                                "") != 0) {
                                                                                                                    if (t_placas_vehiculo
                                                                                                                            .getText()
                                                                                                                            .trim()
                                                                                                                            .compareTo(
                                                                                                                                    "") != 0) {
                                                                                                                        if (t_proveedor
                                                                                                                                .getText()
                                                                                                                                .trim()
                                                                                                                                .compareTo(
                                                                                                                                        "") != 0) {
                                                                                                                            if (t_condiciones
                                                                                                                                    .getText()
                                                                                                                                    .trim()
                                                                                                                                    .compareTo(
                                                                                                                                            "") != 0) {
                                                                                                                                if (t_riesgo
                                                                                                                                        .getText()
                                                                                                                                        .trim()
                                                                                                                                        .compareTo(
                                                                                                                                                "") != 0) {
                                                                                                                                    habilita(
                                                                                                                                            false,
                                                                                                                                            false);
                                                                                                                                    progreso.setIndeterminate(
                                                                                                                                            true);
                                                                                                                                    progreso.setString(
                                                                                                                                            "Conectando al servidor SAT Espere");
                                                                                                                                    facturaElectronica();
                                                                                                                                } else {
                                                                                                                                    contenedor
                                                                                                                                            .setSelectedIndex(
                                                                                                                                                    2);
                                                                                                                                    JOptionPane
                                                                                                                                            .showMessageDialog(
                                                                                                                                                    null,
                                                                                                                                                    "Debe ingresar el riego");
                                                                                                                                    t_riesgo.requestFocus();
                                                                                                                                }
                                                                                                                            } else {
                                                                                                                                contenedor
                                                                                                                                        .setSelectedIndex(
                                                                                                                                                2);
                                                                                                                                JOptionPane
                                                                                                                                        .showMessageDialog(
                                                                                                                                                null,
                                                                                                                                                "Debe ingresar las condiciones de pago");
                                                                                                                                t_condiciones
                                                                                                                                        .requestFocus();
                                                                                                                            }
                                                                                                                        } else {
                                                                                                                            contenedor
                                                                                                                                    .setSelectedIndex(
                                                                                                                                            2);
                                                                                                                            JOptionPane
                                                                                                                                    .showMessageDialog(
                                                                                                                                            null,
                                                                                                                                            "Debe ingresar el numero de proveedor");
                                                                                                                            t_proveedor
                                                                                                                                    .requestFocus();
                                                                                                                        }
                                                                                                                    } else {
                                                                                                                        contenedor
                                                                                                                                .setSelectedIndex(
                                                                                                                                        2);
                                                                                                                        JOptionPane
                                                                                                                                .showMessageDialog(
                                                                                                                                        null,
                                                                                                                                        "Debe ingresar las placas del vehiculo");
                                                                                                                        t_placas_vehiculo
                                                                                                                                .requestFocus();
                                                                                                                    }
                                                                                                                } else {
                                                                                                                    contenedor
                                                                                                                            .setSelectedIndex(
                                                                                                                                    2);
                                                                                                                    JOptionPane
                                                                                                                            .showMessageDialog(
                                                                                                                                    null,
                                                                                                                                    "Debe ingresar el ao del vehiculo");
                                                                                                                    t_anio_vehiculo
                                                                                                                            .requestFocus();
                                                                                                                }
                                                                                                            } else {
                                                                                                                contenedor
                                                                                                                        .setSelectedIndex(
                                                                                                                                2);
                                                                                                                JOptionPane
                                                                                                                        .showMessageDialog(
                                                                                                                                null,
                                                                                                                                "Debe ingresar la marca del vehiculo");
                                                                                                                t_marca_vehiculo
                                                                                                                        .requestFocus();
                                                                                                            }
                                                                                                        } else {
                                                                                                            contenedor
                                                                                                                    .setSelectedIndex(
                                                                                                                            2);
                                                                                                            JOptionPane
                                                                                                                    .showMessageDialog(
                                                                                                                            null,
                                                                                                                            "Debe ingresar el modelo del vehiculo");
                                                                                                            t_modelo_vehiculo
                                                                                                                    .requestFocus();
                                                                                                        }
                                                                                                    } else {
                                                                                                        contenedor
                                                                                                                .setSelectedIndex(
                                                                                                                        2);
                                                                                                        JOptionPane
                                                                                                                .showMessageDialog(
                                                                                                                        null,
                                                                                                                        "Debes ingresar el correo del receptor");
                                                                                                        t_correo_receptor
                                                                                                                .requestFocus();
                                                                                                    }
                                                                                                } else {
                                                                                                    contenedor
                                                                                                            .setSelectedIndex(
                                                                                                                    2);
                                                                                                    JOptionPane
                                                                                                            .showMessageDialog(
                                                                                                                    null,
                                                                                                                    "Debes ingresar el nombre del receptor");
                                                                                                    t_nombre_receptor
                                                                                                            .requestFocus();
                                                                                                }
                                                                                            } else {
                                                                                                contenedor
                                                                                                        .setSelectedIndex(
                                                                                                                2);
                                                                                                JOptionPane
                                                                                                        .showMessageDialog(
                                                                                                                null,
                                                                                                                "Debes ingresar el RI del receptor");
                                                                                                t_ri_receptor
                                                                                                        .requestFocus();
                                                                                            }
                                                                                        } else {
                                                                                            contenedor
                                                                                                    .setSelectedIndex(
                                                                                                            2);
                                                                                            JOptionPane
                                                                                                    .showMessageDialog(
                                                                                                            null,
                                                                                                            "Debes ingresar el correo del emisor");
                                                                                            t_correo_emisor
                                                                                                    .requestFocus();
                                                                                        }
                                                                                    } else {
                                                                                        contenedor.setSelectedIndex(
                                                                                                2);
                                                                                        JOptionPane
                                                                                                .showMessageDialog(
                                                                                                        null,
                                                                                                        "Debes ingresar el nombre del contacto emisor");
                                                                                        t_nombre_emisor
                                                                                                .requestFocus();
                                                                                    }
                                                                                } else {
                                                                                    contenedor.setSelectedIndex(2);
                                                                                    JOptionPane.showMessageDialog(
                                                                                            null,
                                                                                            "Debes ingresar el RI del contacto emisor");
                                                                                    t_ri_emisor.requestFocus();
                                                                                }
                                                                            } else {
                                                                                contenedor.setSelectedIndex(2);
                                                                                JOptionPane.showMessageDialog(null,
                                                                                        "Debes ingresar el no de siniestro");
                                                                                t_siniestro.requestFocus();
                                                                            }
                                                                        } else {
                                                                            contenedor.setSelectedIndex(2);
                                                                            JOptionPane.showMessageDialog(null,
                                                                                    "Debes el tipo de poliza");
                                                                            t_tipo_poliza.requestFocus();
                                                                        }
                                                                    } else {
                                                                        contenedor.setSelectedIndex(2);
                                                                        JOptionPane.showMessageDialog(null,
                                                                                "debes ingresar el no de poliza");
                                                                        t_numero.requestFocus();
                                                                    }
                                                                } else {
                                                                    contenedor.setSelectedIndex(2);
                                                                    JOptionPane.showMessageDialog(null,
                                                                            "Debes ingresar no de inciso");
                                                                    t_inciso.requestFocus();
                                                                }
                                                            } else {
                                                                contenedor.setSelectedIndex(0);
                                                                JOptionPane.showMessageDialog(null,
                                                                        "Debes ingresar ingresar el area");
                                                                c_tipo_facturacion.requestFocus();
                                                            }
                                                        } else {
                                                            contenedor.setSelectedIndex(1);
                                                            JOptionPane.showMessageDialog(null,
                                                                    "Debes ingresar conceptos para la factura");
                                                        }
                                                    } else {
                                                        contenedor.setSelectedIndex(1);
                                                        JOptionPane.showMessageDialog(null,
                                                                "Debes ingresar el tipo de combio");
                                                        t_tipo_cambio.requestFocus();
                                                    }
                                                } else {
                                                    contenedor.setSelectedIndex(1);
                                                    JOptionPane.showMessageDialog(null,
                                                            "Debes ingresar el tipo de moneda");
                                                    c_moneda.requestFocus();
                                                }
                                            } else {
                                                contenedor.setSelectedIndex(1);
                                                JOptionPane.showMessageDialog(null,
                                                        "Debes ingresar el metodo de pago");
                                                t_metodo_pago.requestFocus();
                                            }
                                        } else {
                                            contenedor.setSelectedIndex(0);
                                            JOptionPane.showMessageDialog(null,
                                                    "Debes ingresar el municipio del receptor");
                                            t_municipio.requestFocus();
                                        }
                                    } else {
                                        contenedor.setSelectedIndex(0);
                                        JOptionPane.showMessageDialog(null, "Debes ingresar el cp del receptor");
                                        t_cp.requestFocus();
                                    }
                                } else {
                                    contenedor.setSelectedIndex(0);
                                    JOptionPane.showMessageDialog(null,
                                            "Debes ingresar el no exterior del receptor");
                                    t_no_exterior.requestFocus();
                                }
                            } else {
                                contenedor.setSelectedIndex(0);
                                JOptionPane.showMessageDialog(null, "Debes ingresar el pais del receptor");
                                c_pais.requestFocus();
                            }
                        } else {
                            contenedor.setSelectedIndex(0);
                            JOptionPane.showMessageDialog(null, "Debes ingresar el estado del del receptor");
                            c_estado.requestFocus();
                        }
                    } else {
                        contenedor.setSelectedIndex(0);
                        JOptionPane.showMessageDialog(null, "Debes ingresar la colonia del receptor");
                        t_colonia.requestFocus();
                    }
                } else {
                    contenedor.setSelectedIndex(0);
                    JOptionPane.showMessageDialog(null, "Debes ingresar la calle del receptor");
                    t_calle.requestFocus();
                }
            } else {
                contenedor.setSelectedIndex(0);
                JOptionPane.showMessageDialog(null, "Debes ingresar el rfc receptor");
                t_rfc.requestFocus();
            }
        } else {
            contenedor.setSelectedIndex(0);
            JOptionPane.showMessageDialog(null, "Debes ingresar la razon social del receptor");
            t_social.requestFocus();
        }
    }//GEN-LAST:event_b_generarActionPerformed

    private void b_actualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_actualizarActionPerformed
        // TODO add your handling code here:
        h = new Herramientas(user, 0);
        h.session(sessionPrograma);
        if (factura != null) {
            String res = guarda();
            if (res.compareTo("") == 0)
                JOptionPane.showMessageDialog(null, "Informacion actualizada");
            else
                JOptionPane.showMessageDialog(null, res);
        }
    }//GEN-LAST:event_b_actualizarActionPerformed

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

    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_calleKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_calleKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (t_calle.getText().length() >= 200)
            evt.consume();
    }//GEN-LAST:event_t_calleKeyTyped

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

    private void t_cpKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_cpKeyTyped
        // TODO add your handling code here:
        char car = evt.getKeyChar();
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (t_cp.getText().length() >= 6)
            evt.consume();
        if ((car < '0' || car > '9'))
            evt.consume();
    }//GEN-LAST:event_t_cpKeyTyped

    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_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() >= 150)
            evt.consume();
    }//GEN-LAST:event_t_municipioKeyTyped

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

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

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

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

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

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

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

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

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

    private void b_emailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_emailActionPerformed
        // TODO add your handling code here:
        String ruta = "";
        try {
            ruta = "";
            FileReader f = new FileReader("config.txt");
            BufferedReader b = new BufferedReader(f);
            if ((ruta = b.readLine()) == null)
                ruta = "";
            b.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        File xml = new File(ruta + "xml-timbrados/" + t_xml.getText());
        File pdf = new File(ruta + "xml-timbrados/" + t_pdf.getText());

        if (xml.exists() == true && pdf.exists() == true) {
            Comprimir zip = new Comprimir();
            List lista = new ArrayList();
            lista.add(ruta + "xml-timbrados/" + t_xml.getText());
            lista.add(ruta + "xml-timbrados/" + t_pdf.getText());
            h = new Herramientas(user, 0);
            h.session(sessionPrograma);
            Session session = HibernateUtil.getSessionFactory().openSession();
            try {
                session.beginTransaction().begin();
                factura = (Factura) session.get(Factura.class, factura.getIdFactura());
                int numeroID = 0;
                if (factura.getOrden() != null)
                    numeroID = factura.getOrden().getIdOrden();
                if (factura.getOrdenExterna() != null)
                    numeroID = factura.getOrdenExterna().getIdOrden();
                zip.zipArchivos(lista, ruta + "xml-timbrados/" + numeroID, Comprimir.Extension.ZIP);
                File envio = new File(ruta + "xml-timbrados/" + numeroID + ".zip");
                if (envio.exists()) {
                    String mail = factura.getCorreoReceptor();
                    EnviarCorreo en = null;
                    if (factura.getOrden() != null) {
                        if (factura.getOrden().getSiniestro() != null)
                            en = new EnviarCorreo(new javax.swing.JFrame(), true, mail, "Envo Factura",
                                    "Hola buen dia, envo XML y PDF correspondiente al siniestro:."
                                            + factura.getOrden().getSiniestro(),
                                    envio, this.user, this.sessionPrograma);
                        else
                            en = new EnviarCorreo(new javax.swing.JFrame(), true, mail, "Envo Factura",
                                    "Hola buen dia, envo XML y PDF", envio, this.user, this.sessionPrograma);
                    }
                    if (factura.getOrdenExterna() != null) {
                        if (factura.getOrdenExterna().getSiniestro() != null)
                            en = new EnviarCorreo(new javax.swing.JFrame(), true, mail, "Envo Factura",
                                    "Hola buen dia, envo XML y PDF correspondiente al siniestro:."
                                            + factura.getOrdenExterna().getSiniestro(),
                                    envio, this.user, this.sessionPrograma);
                        else
                            en = new EnviarCorreo(new javax.swing.JFrame(), true, mail, "Envo Factura",
                                    "Hola buen dia, envo XML y PDF", envio, this.user, this.sessionPrograma);
                    }
                    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                    en.setLocation((d.width / 2) - (en.getWidth() / 2), (d.height / 2) - (en.getHeight() / 2));
                    en.setVisible(true);
                } else
                    JOptionPane.showMessageDialog(null, "error al comprimir.");
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "error al comprimir.");
            } finally {
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        } else {
            JOptionPane.showMessageDialog(null, "No se encontraron los archivos");
        }
    }//GEN-LAST:event_b_emailActionPerformed

    private void b_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_salirActionPerformed
        // TODO add your handling code here:
        doClose(factura);
    }//GEN-LAST:event_b_salirActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        doClose(factura);
    }//GEN-LAST:event_formWindowClosed

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

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

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

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

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

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

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

    private void b_xmlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_xmlActionPerformed
        // TODO add your handling code here:
        if (t_folio_factura.getText().compareTo("") != 0 && t_uuid_factura.getText().compareTo("") != 0) {
            Session session = HibernateUtil.getSessionFactory().openSession();
            try {
                session.beginTransaction().begin();
                String ruta = "";
                try {
                    ruta = "";
                    FileReader f = new FileReader("config.txt");
                    BufferedReader b = new BufferedReader(f);
                    if ((ruta = b.readLine()) == null)
                        ruta = "";
                    b.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                Configuracion config = (Configuracion) session.get(Configuracion.class, 1);
                if (t_xml.getText().compareTo("") == 0)
                    t_xml.setText(config.getRfc() + "_" + t_serie_factura.getText() + "_"
                            + t_folio_factura.getText() + "_" + t_rfc.getText() + ".xml");
                File xml = new File(ruta + "xml-timbrados/" + t_xml.getText());
                if (xml.exists())//existe en nuestro directorio
                    Desktop.getDesktop().open(xml);
                else//descargar el archivo del SAP
                {
                    factura = (Factura) session.get(Factura.class, factura.getIdFactura());
                    RequestTransaction rq = new RequestTransaction();
                    rq.setRequestor(config.getRequestor());//Lo proporcionar MySuite
                    rq.setTransaction("GET_DOCUMENT");//Tipo de Transaccion
                    rq.setCountry("MX");//Codigo de pais
                    rq.setUser(config.getRequestor());//igual que Requestor
                    rq.setUserName(config.getUsuario_1());//Country.Entity.nombre_usuario
                    rq.setEntity(config.getRfc());
                    rq.setData1(t_serie_factura.getText());//serie del documento.
                    rq.setData2(t_folio_factura.getText());//folio
                    rq.setData3("PDF XML");//documentos
                    abrir = "xml";
                    llamarSoapDocumento(rq);
                }
            } catch (Exception e) {
                if (session != null)
                    if (session.isConnected())
                        session.close();
                JOptionPane.showMessageDialog(null, "Error al consultar la base de datos");
            } finally {
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        } else {
            JOptionPane.showMessageDialog(null,
                    "Debes generar comprobante primero para tratar de recuperar los datos del SAP");
        }
    }//GEN-LAST:event_b_xmlActionPerformed

    private void b_pdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_pdfActionPerformed
        // TODO add your handling code here:
        if (t_folio_factura.getText().compareTo("") != 0 && t_uuid_factura.getText().compareTo("") != 0) {
            Session session = HibernateUtil.getSessionFactory().openSession();
            try {
                session.beginTransaction().begin();
                String ruta = "";
                try {
                    ruta = "";
                    FileReader f = new FileReader("config.txt");
                    BufferedReader b = new BufferedReader(f);
                    if ((ruta = b.readLine()) == null)
                        ruta = "";
                    b.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                Configuracion config = (Configuracion) session.get(Configuracion.class, 1);
                if (t_xml.getText().compareTo("") == 0)
                    t_xml.setText(config.getRfc() + "_" + t_serie_factura.getText() + "_"
                            + t_folio_factura.getText() + "_" + t_rfc.getText() + ".pdf");
                File xml = new File(ruta + "xml-timbrados/" + t_pdf.getText());
                if (xml.exists())//existe en nuestro directorio
                    Desktop.getDesktop().open(xml);
                else//descargar el archivo del SAP
                {
                    factura = (Factura) session.get(Factura.class, factura.getIdFactura());
                    RequestTransaction rq = new RequestTransaction();
                    rq.setRequestor(config.getRequestor());//Lo proporcionar MySuite
                    rq.setTransaction("GET_DOCUMENT");//Tipo de Transaccion
                    rq.setCountry("MX");//Codigo de pais
                    rq.setUser(config.getRequestor());//igual que Requestor
                    rq.setUserName(config.getUsuario_1());//Country.Entity.nombre_usuario
                    rq.setEntity(config.getRfc());
                    rq.setData1(t_serie_factura.getText());//serie del documento.
                    rq.setData2(t_folio_factura.getText());//folio
                    rq.setData3("PDF XML");//documentos
                    abrir = "pdf";
                    llamarSoapDocumento(rq);
                }
            } catch (Exception e) {
                if (session != null)
                    if (session.isConnected())
                        session.close();
                JOptionPane.showMessageDialog(null, "Error al consultar la base de datos");
            }
            if (session != null)
                if (session.isOpen())
                    session.close();
        } else {
            JOptionPane.showMessageDialog(null,
                    "Debes generar comprobante primero para tratar de recuperar los datos del SAP");
        }
    }//GEN-LAST:event_b_pdfActionPerformed

    private void b_descargarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_descargarActionPerformed
        // TODO add your handling code here:
        if (t_facturas.getSelectedRow() > -1) {
            habilita2(false);
            progreso.setString("Conectando al servidor SAT Espere");
            progreso.setIndeterminate(true);
            Session session = HibernateUtil.getSessionFactory().openSession();
            try {
                session.beginTransaction().begin();
                Configuracion config = (Configuracion) session.get(Configuracion.class, 1);
                factura = (Factura) session.get(Factura.class, factura.getIdFactura());
                RequestTransaction rq = new RequestTransaction();
                rq.setRequestor(config.getRequestor());//Lo proporcionar MySuite
                rq.setTransaction("GET_DOCUMENT");//Tipo de Transaccion
                rq.setCountry("MX");//Codigo de pais
                rq.setUser(config.getRequestor());//igual que Requestor
                rq.setUserName(config.getUsuario_1());//Country.Entity.nombre_usuario
                rq.setEntity(config.getRfc());
                rq.setData1(t_facturas.getValueAt(t_facturas.getSelectedRow(), 3).toString());//serie del documento.
                rq.setData2(t_facturas.getValueAt(t_facturas.getSelectedRow(), 4).toString());//folio
                rq.setData3("PDF XML");//documentos
                abrir = "pdf";
                llamarSoapDocumento1(rq);
            } catch (Exception e) {
                habilita2(true);
                progreso.setString("Listo");
                progreso.setIndeterminate(false);
                JOptionPane.showMessageDialog(null, "Error al consultar la base de datos");
            } finally {
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        } else
            JOptionPane.showMessageDialog(null, "Debes seleccionar una factura de la lista primero");
    }//GEN-LAST:event_b_descargarActionPerformed

    private void b_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_cancelarActionPerformed
        // TODO add your handling code here:
        if (t_facturas.getSelectedRow() > -1) {
            habilita2(false);
            progreso.setString("Conectando al servidor SAT Espere");
            progreso.setIndeterminate(true);
            Session session = HibernateUtil.getSessionFactory().openSession();
            try {
                idBuscar = t_facturas.getValueAt(t_facturas.getSelectedRow(), 1).toString();
                session.beginTransaction().begin();
                Configuracion config = (Configuracion) session.get(Configuracion.class, 1);
                factura = (Factura) session.get(Factura.class, factura.getIdFactura());
                RequestTransaction rq = new RequestTransaction();
                rq.setRequestor(config.getRequestor());//Lo proporcionar MySuite
                rq.setTransaction("CANCEL_XML");//Tipo de Transaccion
                rq.setCountry("MX");//Codigo de pais
                rq.setUser(config.getRequestor());//igual que Requestor
                rq.setUserName(config.getUsuario_1());//Country.Entity.nombre_usuario
                rq.setEntity(config.getRfc());
                rq.setData1(idBuscar);//GUIID.
                rq.setData2("");
                rq.setData3("");
                llamarSoapCancela(rq);
            } catch (Exception e) {
                habilita2(true);
                progreso.setString("Listo");
                progreso.setIndeterminate(false);
                JOptionPane.showMessageDialog(null, "Error al consultar la base de datos");
            } finally {
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        } else
            JOptionPane.showMessageDialog(null, "Debes seleccionar una factura de la lista primero");
    }//GEN-LAST:event_b_cancelarActionPerformed

    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 t_ri_receptorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_ri_receptorKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (t_ri_receptor.getText().length() >= 20)
            evt.consume();
    }//GEN-LAST:event_t_ri_receptorKeyTyped

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

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

    private void t_fecha_facturaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_fecha_facturaKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_t_fecha_facturaKeyTyped

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

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

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

    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 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_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 b_masActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_masActionPerformed
        // TODO add your handling code here:
        h = new Herramientas(user, 0);
        h.session(sessionPrograma);
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction().begin();
        factura = (Factura) session.get(Factura.class, factura.getIdFactura());
        Concepto con = new Concepto();
        con.setCantidad(0.0);
        con.setMedida("PZAS");
        con.setDescripcion("");
        con.setPrecio(0.0);
        con.setDescuento(0.0);
        con.setFactura(factura);
        int dato = (int) session.save(con);
        session.beginTransaction().commit();

        DefaultTableModel temp = (DefaultTableModel) t_datos.getModel();
        Object nuevo[] = { dato, 0.0d, "PZAS", "", 0.0d, 0.0d, 0.0d };
        temp.addRow(nuevo);
        formatoTabla();
        t_datos.setRowSelectionInterval(t_datos.getRowCount() - 1, t_datos.getRowCount() - 1);
        t_datos.setColumnSelectionInterval(0, 0);
        t_datos.requestFocus();
    }//GEN-LAST:event_b_masActionPerformed

    private void b_menosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_menosActionPerformed
        // TODO add your handling code here:
        if (t_datos.getSelectedRow() > -1) {
            h = new Herramientas(user, 0);
            h.session(sessionPrograma);
            Session session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction().begin();
            Concepto con = (Concepto) session.get(Concepto.class,
                    Integer.parseInt(t_datos.getValueAt(t_datos.getSelectedRow(), 0).toString()));
            session.delete(con);
            session.beginTransaction().commit();

            DefaultTableModel temp = (DefaultTableModel) t_datos.getModel();
            temp.removeRow(t_datos.getSelectedRow());
            formatoTabla();
        }
    }//GEN-LAST:event_b_menosActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        FileNameExtensionFilter filtroImagen = new FileNameExtensionFilter("XLS", "xls");
        aviso.setFileFilter(filtroImagen);
        int r = aviso.showSaveDialog(null);
        if (r == aviso.APPROVE_OPTION) {
            File a = aviso.getSelectedFile();
            File archivoXLS = null;
            if (a.getName().indexOf(".xls") == -1)
                a = new File(a.getAbsoluteFile() + ".xls");
            archivoXLS = a;
            try {
                if (archivoXLS.exists())
                    archivoXLS.delete();
                archivoXLS.createNewFile();
                Workbook libro = new HSSFWorkbook();
                FileOutputStream archivo = new FileOutputStream(archivoXLS);
                Sheet hoja = libro.createSheet("datos");
                Row h1r0 = hoja.createRow(0);
                h1r0.createCell(0).setCellValue("Cant");
                h1r0.createCell(1).setCellValue("Med");
                h1r0.createCell(2).setCellValue("Descripcion");
                h1r0.createCell(3).setCellValue("c/u");
                h1r0.createCell(4).setCellValue("Descuento");
                for (int x = 0; x < t_datos.getRowCount(); x++) {
                    Row h1 = hoja.createRow(x + 1);
                    h1.createCell(0).setCellValue((double) t_datos.getValueAt(x, 1));
                    h1.createCell(1).setCellValue((String) t_datos.getValueAt(x, 2));
                    h1.createCell(2).setCellValue((String) t_datos.getValueAt(x, 3));
                    h1.createCell(3).setCellValue((double) t_datos.getValueAt(x, 4));
                    h1.createCell(4).setCellValue((double) t_datos.getValueAt(x, 5));
                }
                libro.write(archivo);
                Biff8EncryptionKey.setCurrentUserPassword(null);
                archivo.close();
                JOptionPane.showMessageDialog(null, "Archivo guardado!");
            } catch (Exception e) {
                e.printStackTrace();
            }
            ;
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser aviso;
    private javax.swing.JButton b_actualizar;
    private javax.swing.JButton b_cancelar;
    private javax.swing.JButton b_descargar;
    private javax.swing.JButton b_email;
    private javax.swing.JButton b_generar;
    private javax.swing.JButton b_mas;
    private javax.swing.JButton b_menos;
    private javax.swing.JButton b_pdf;
    private javax.swing.JButton b_salir;
    private javax.swing.JButton b_xml;
    private javax.swing.JComboBox c_estado;
    private javax.swing.JComboBox c_moneda;
    private javax.swing.JComboBox c_pais;
    private javax.swing.JComboBox c_tipo_facturacion;
    private javax.swing.JDialog consulta;
    private javax.swing.JTabbedPane contenedor;
    private javax.swing.JButton jButton1;
    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 jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel43;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel49;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel50;
    private javax.swing.JLabel jLabel52;
    private javax.swing.JLabel jLabel53;
    private javax.swing.JLabel jLabel54;
    private javax.swing.JLabel jLabel56;
    private javax.swing.JLabel jLabel57;
    private javax.swing.JLabel jLabel58;
    private javax.swing.JLabel jLabel59;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel60;
    private javax.swing.JLabel jLabel62;
    private javax.swing.JLabel jLabel63;
    private javax.swing.JLabel jLabel64;
    private javax.swing.JLabel jLabel65;
    private javax.swing.JLabel jLabel66;
    private javax.swing.JLabel jLabel68;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel70;
    private javax.swing.JLabel jLabel71;
    private javax.swing.JLabel jLabel72;
    private javax.swing.JLabel jLabel75;
    private javax.swing.JLabel jLabel76;
    private javax.swing.JLabel jLabel77;
    private javax.swing.JLabel jLabel79;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel80;
    private javax.swing.JLabel jLabel81;
    private javax.swing.JLabel jLabel82;
    private javax.swing.JLabel jLabel83;
    private javax.swing.JLabel jLabel84;
    private javax.swing.JLabel jLabel85;
    private javax.swing.JLabel jLabel86;
    private javax.swing.JLabel jLabel87;
    private javax.swing.JLabel jLabel88;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel l_iva;
    private javax.swing.JLabel l_iva1;
    private javax.swing.JLabel l_subtotal;
    private javax.swing.JLabel l_total;
    private javax.swing.JProgressBar progreso;
    private javax.swing.JTextField t_anio_vehiculo;
    private javax.swing.JTextField t_calle;
    private javax.swing.JTextField t_codigo;
    private javax.swing.JTextField t_colonia;
    private javax.swing.JTextField t_condiciones;
    private javax.swing.JTextField t_correo_emisor;
    private javax.swing.JTextField t_correo_receptor;
    private javax.swing.JTextField t_cp;
    private javax.swing.JTextField t_cuenta_pago;
    private javax.swing.JTable t_datos;
    private javax.swing.JFormattedTextField t_deducible;
    private javax.swing.JFormattedTextField t_descuento;
    private javax.swing.JTable t_facturas;
    private javax.swing.JTextField t_fecha_factura;
    private javax.swing.JTextField t_folio_factura;
    private javax.swing.JTextField t_forma_pago;
    private javax.swing.JTextField t_inciso;
    private javax.swing.JFormattedTextField t_iva;
    private javax.swing.JFormattedTextField t_iva1;
    private javax.swing.JTextField t_marca_vehiculo;
    private javax.swing.JTextField t_metodo_pago;
    private javax.swing.JTextField t_modelo_vehiculo;
    private javax.swing.JTextField t_motor_vehiculo;
    private javax.swing.JTextField t_municipio;
    private javax.swing.JTextField t_no_exterior;
    private javax.swing.JTextField t_nombre_emisor;
    private javax.swing.JTextField t_nombre_receptor;
    private javax.swing.JTextField t_numero;
    private javax.swing.JTextField t_pdf;
    private javax.swing.JTextField t_placas_vehiculo;
    private javax.swing.JTextField t_proveedor;
    private javax.swing.JTextField t_rfc;
    private javax.swing.JTextField t_ri_emisor;
    private javax.swing.JTextField t_ri_receptor;
    private javax.swing.JTextField t_riesgo;
    private javax.swing.JTextField t_serie_factura;
    private javax.swing.JTextField t_serie_vehiculo;
    private javax.swing.JTextField t_siniestro;
    private javax.swing.JTextField t_social;
    private javax.swing.JFormattedTextField t_subtotal;
    private javax.swing.JTextField t_tel_emisor;
    private javax.swing.JTextField t_tel_receptor;
    private javax.swing.JFormattedTextField t_tipo_cambio;
    private javax.swing.JTextField t_tipo_poliza;
    private javax.swing.JFormattedTextField t_total;
    private javax.swing.JTextField t_uuid_factura;
    private javax.swing.JTextField t_xml;

    // End of variables declaration//GEN-END:variables
    public void consulta() {
        h = new Herramientas(user, 0);
        h.session(sessionPrograma);
        borra_cajas();
        if (factura != null) {
            Session session = HibernateUtil.getSessionFactory().openSession();
            try {
                session.beginTransaction().begin();
                factura = (Factura) session.get(Factura.class, factura.getIdFactura());
                //Receptor
                t_iva1.setValue(factura.getIva());
                try {
                    t_iva1.commitEdit();
                } catch (Exception e) {
                }
                t_social.setText(factura.getNombreReceptor().trim());
                t_rfc.setText(factura.getRfcReceptor().trim());
                t_calle.setText(factura.getCalleReceptor().trim());
                t_no_exterior.setText(factura.getNumeroExteriorReceptor().trim());
                t_cp.setText(factura.getCpReceptor().trim());
                t_colonia.setText(factura.getColoniaReceptor().trim());
                t_municipio.setText(factura.getMunicipioReceptor().trim());
                c_estado.setSelectedItem(factura.getEstadoReceptor());
                c_pais.setSelectedItem(factura.getPaisReceptor());
                //Productos y servicios
                t_metodo_pago.setText(factura.getMetodoPago().trim());
                t_cuenta_pago.setText(factura.getCuentaPago().trim());
                t_tipo_cambio.setText("" + factura.getFactorCambio());
                t_tipo_cambio.setValue(factura.getFactorCambio());
                c_moneda.setSelectedItem(factura.getMoneda().trim());
                //Addenda
                if (factura.getTipoFacturacion() != null)
                    c_tipo_facturacion.setSelectedItem(factura.getTipoFacturacion());
                if (factura.getTipoPoliza() != null)
                    t_tipo_poliza.setText(factura.getTipoPoliza().trim());
                else
                    t_tipo_poliza.setText("");

                t_codigo.setText("" + factura.getIdFactura());
                if (factura.getOrden() != null) {
                    if (factura.getOrden().getPoliza() != null)
                        t_numero.setText(factura.getOrden().getPoliza().trim());
                    else
                        t_numero.setText("");
                    if (factura.getOrden().getInciso() != null)
                        t_inciso.setText(factura.getOrden().getInciso().trim());
                    else
                        t_inciso.setText("");
                    if (factura.getOrden().getSiniestro() != null)
                        t_siniestro.setText(factura.getOrden().getSiniestro().trim());
                    else
                        t_siniestro.setText("");
                }
                if (factura.getOrdenExterna() != null) {
                    if (factura.getOrdenExterna().getPoliza() != null)
                        t_numero.setText(factura.getOrdenExterna().getPoliza().trim());
                    else
                        t_numero.setText("");
                    if (factura.getOrdenExterna().getInciso() != null)
                        t_inciso.setText(factura.getOrdenExterna().getInciso().trim());
                    else
                        t_inciso.setText("");
                    if (factura.getOrdenExterna().getSiniestro() != null)
                        t_siniestro.setText(factura.getOrdenExterna().getSiniestro().trim());
                    else
                        t_siniestro.setText("");
                }
                Configuracion config = (Configuracion) session.get(Configuracion.class, 1);
                if (factura.getRiEmosor() != null)
                    t_ri_emisor.setText(factura.getRiEmosor().trim());
                else
                    t_ri_emisor.setText("");
                if (factura.getContactoEmisor() != null)
                    t_nombre_emisor.setText(config.getContacto().trim());
                else
                    t_nombre_emisor.setText(factura.getContactoEmisor().trim());
                if (factura.getCorreoEmisor() != null)
                    t_correo_emisor.setText(config.getMail().trim());
                else
                    t_correo_emisor.setText(factura.getCorreoEmisor().trim());
                if (factura.getTelefonoEmisor() != null)
                    t_tel_emisor.setText(factura.getTelefonoEmisor().trim());
                else
                    t_tel_emisor.setText("");

                if (factura.getRiReceptor() != null)
                    t_ri_receptor.setText(factura.getRiReceptor().trim());
                else
                    t_ri_receptor.setText("");
                if (factura.getContactoReceptor() != null)
                    t_nombre_receptor.setText(factura.getContactoReceptor().trim());
                else
                    t_nombre_receptor.setText("");
                if (factura.getCorreoReceptor() != null)
                    t_correo_receptor.setText(factura.getCorreoReceptor().trim());
                else
                    t_correo_receptor.setText("");
                if (factura.getTelefonoReceptor() != null)
                    t_tel_receptor.setText(factura.getTelefonoReceptor().trim());
                else
                    t_tel_receptor.setText("");
                if (factura.getOrden() != null) {
                    t_modelo_vehiculo.setText(factura.getOrden().getTipo().getTipoNombre().trim());
                    t_marca_vehiculo.setText(factura.getOrden().getMarca().getMarcaNombre().trim());
                    t_anio_vehiculo.setText("" + factura.getOrden().getModelo());
                    if (factura.getOrden().getNoSerie() != null)
                        t_serie_vehiculo.setText(factura.getOrden().getNoSerie().trim());
                    if (factura.getOrden().getNoPlacas() != null)
                        t_placas_vehiculo.setText(factura.getOrden().getNoPlacas().trim());
                    if (factura.getOrden().getNoMotor() != null)
                        t_motor_vehiculo.setText(factura.getOrden().getNoMotor().trim());
                    this.t_deducible.setText("" + factura.getOrden().getDeducible());
                    t_deducible.setValue(factura.getOrden().getDeducible());
                }
                if (factura.getOrdenExterna() != null) {
                    if (factura.getOrdenExterna().getTipo() != null)
                        t_modelo_vehiculo.setText(factura.getOrdenExterna().getTipo().getTipoNombre().trim());
                    if (factura.getOrdenExterna().getMarca() != null)
                        t_marca_vehiculo.setText(factura.getOrdenExterna().getMarca().getMarcaNombre().trim());
                    if (factura.getOrdenExterna().getModelo() != null)
                        t_anio_vehiculo.setText("" + factura.getOrdenExterna().getModelo());
                    if (factura.getOrdenExterna().getNoSerie() != null)
                        t_serie_vehiculo.setText(factura.getOrdenExterna().getNoSerie().trim());
                    if (factura.getOrdenExterna().getNoPlacas() != null)
                        t_placas_vehiculo.setText(factura.getOrdenExterna().getNoPlacas().trim());
                    if (factura.getOrdenExterna().getNoMotor() != null)
                        t_motor_vehiculo.setText(factura.getOrdenExterna().getNoMotor().trim());
                    if (factura.getOrdenExterna().getDeducible() != null) {
                        this.t_deducible.setText("" + factura.getOrdenExterna().getDeducible());
                        t_deducible.setValue(factura.getOrdenExterna().getDeducible());
                    }
                }
                if (factura.getProveedor() != null)
                    this.t_proveedor.setText(factura.getProveedor().trim());
                else
                    this.t_proveedor.setText("");
                this.t_fecha_factura.setText("" + factura.getFecha());

                if (factura.getCondicionesPago() != null)
                    this.t_condiciones.setText(factura.getCondicionesPago().trim());
                else
                    this.t_condiciones.setText("");

                if (factura.getRiesgo() != null)
                    t_riesgo.setText(factura.getRiesgo());

                //cargar las partidas
                Concepto[] partidas = (Concepto[]) session.createCriteria(Concepto.class)
                        .add(Restrictions.eq("factura.idFactura", factura.getIdFactura()))
                        .addOrder(Order.asc("idConcepto")).list().toArray(new Concepto[0]);
                for (int a = 0; a < partidas.length; a++) {
                    double total_lista = partidas[a].getPrecio() * partidas[a].getCantidad();
                    double descuento = partidas[a].getDescuento() / 100;
                    double total = total_lista - (total_lista * descuento);
                    model.addRow(new Object[] { partidas[a].getIdConcepto(), partidas[a].getCantidad(),
                            partidas[a].getMedida(), partidas[a].getDescripcion(), partidas[a].getPrecio(),
                            partidas[a].getDescuento(), total });
                }
                iva = config.getIva();
                t_datos.setModel(model);
                formatoTabla();
                sumaTotales();

                if (factura.getEstadoFactura().compareTo("Facturado") == 0) {
                    if (factura.getSerie() != null)
                        t_serie_factura.setText(factura.getSerie());
                    if (factura.getFolio() != null)
                        t_folio_factura.setText(factura.getFolio());
                    if (factura.getNombreDocumento() != null) {
                        t_xml.setText(factura.getNombreDocumento() + ".xml");
                        t_pdf.setText(factura.getNombreDocumento() + ".pdf");
                    }
                    if (factura.getFFiscal() != null)
                        this.t_uuid_factura.setText(factura.getFFiscal());
                    contenedor.setSelectedIndex(3);
                    if (this.user.getAutorizarFactura() == true)
                        permiso = true;
                    else
                        permiso = false;
                    this.habilita(false, true);
                } else {
                    if (factura.getEstadoFactura().compareTo("Cancelado") == 0) {
                        if (factura.getSerie() != null)
                            t_serie_factura.setText(factura.getSerie());
                        if (factura.getFolio() != null)
                            t_folio_factura.setText(factura.getFolio());
                        if (factura.getNombreDocumento() != null) {
                            t_xml.setText(factura.getNombreDocumento() + ".xml");
                            t_pdf.setText(factura.getNombreDocumento() + ".pdf");
                        }
                        if (factura.getFFiscal() != null)
                            t_uuid_factura.setText(factura.getFFiscal());
                        permiso = false;
                        habilita(false, false);
                    } else {
                        if (this.user.getAutorizarFactura() == true)
                            permiso = true;
                        else
                            permiso = false;
                        habilita(true, false);
                    }
                }
                session.beginTransaction().commit();
            } catch (HibernateException he) {
                he.printStackTrace();
                session.getTransaction().rollback();
                borra_cajas();
                habilita(false, false);
                b_generar.setEnabled(false);
                JOptionPane.showMessageDialog(null, "Error al consultar la Factura");
            } finally {
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        } else {
            borra_cajas();
            this.dispose();
        }
    }

    void borra_cajas() {
        //Receptor
        t_social.setText("");
        t_rfc.setText("");
        t_calle.setText("");
        t_no_exterior.setText("");
        t_cp.setText("");
        t_colonia.setText("");
        t_municipio.setText("");
        //Productos y servicios
        t_metodo_pago.setText("03");
        t_cuenta_pago.setText("");
        t_tipo_cambio.setText("1.0000");
        t_tipo_cambio.setValue(1.0d);
        t_datos.setModel(ModeloTablaReporte(0, columnas));
        formatoTabla();
        //Addenda
        t_inciso.setText("");
        t_tipo_poliza.setText("");
        t_numero.setText("");
        t_siniestro.setText("");
        t_deducible.setText("0.00");
        t_deducible.setValue(0.00d);
        t_ri_emisor.setText("");
        t_nombre_emisor.setText("");
        t_correo_emisor.setText("");
        t_tel_emisor.setText("");
        t_ri_receptor.setText("");
        t_nombre_receptor.setText("");
        t_correo_receptor.setText("");
        t_tel_receptor.setText("");
        t_modelo_vehiculo.setText("");
        t_marca_vehiculo.setText("");
        t_anio_vehiculo.setText("");
        t_serie_vehiculo.setText("");
        t_placas_vehiculo.setText("");
        t_motor_vehiculo.setText("");
        t_proveedor.setText("");
        t_codigo.setText("");
        t_fecha_factura.setText("");
        t_condiciones.setText("");

        t_serie_factura.setText("");
        t_folio_factura.setText("");
        t_uuid_factura.setText("");
        t_xml.setText("");
        t_pdf.setText("");
        iva = 0;
    }

    void habilita(boolean edo, boolean edo2) {
        //Receptor
        t_social.setEnabled(edo);
        t_rfc.setEnabled(edo);
        t_calle.setEnabled(edo);
        t_no_exterior.setEnabled(edo);
        t_cp.setEnabled(edo);
        t_colonia.setEnabled(edo);
        t_municipio.setEnabled(edo);
        c_estado.setEnabled(edo);
        c_pais.setEnabled(edo);
        //Productos y servicios
        t_metodo_pago.setEnabled(edo);
        t_cuenta_pago.setEnabled(edo);
        t_tipo_cambio.setEnabled(edo);
        c_moneda.setEnabled(edo);
        t_datos.setEnabled(edo);
        t_iva1.setEnabled(edo);
        b_mas.setEnabled(edo);
        b_menos.setEnabled(edo);
        //Addenda
        c_tipo_facturacion.setEnabled(edo);
        t_riesgo.setEnabled(edo);
        t_inciso.setEnabled(edo);
        t_tipo_poliza.setEnabled(edo);
        t_numero.setEnabled(edo);
        t_siniestro.setEnabled(edo);
        t_deducible.setEnabled(edo);
        ;
        t_ri_emisor.setEnabled(edo);
        t_nombre_emisor.setEnabled(edo);
        t_correo_emisor.setEnabled(edo);
        t_tel_emisor.setEnabled(edo);
        t_ri_receptor.setEnabled(edo);
        t_nombre_receptor.setEnabled(edo);
        t_correo_receptor.setEnabled(edo);
        t_tel_receptor.setEnabled(edo);
        //t_modelo_vehiculo.setEnabled(edo);
        //t_marca_vehiculo.setEnabled(edo);
        t_anio_vehiculo.setEnabled(edo);
        t_serie_vehiculo.setEnabled(edo);
        t_placas_vehiculo.setEnabled(edo);
        t_motor_vehiculo.setEnabled(edo);
        t_proveedor.setEnabled(edo);
        //t_codigo.setEnabled(edo);
        t_fecha_factura.setEnabled(edo);
        t_condiciones.setEnabled(edo);
        t_descuento.setEnabled(edo);
        b_actualizar.setEnabled(edo);

        if (edo == false)
            b_generar.setEnabled(edo);
        else
            b_generar.setEnabled(permiso);

        b_xml.setEnabled(edo2);
        b_pdf.setEnabled(edo2);
        b_email.setEnabled(edo2);
    }

    public void sumaTotales() {
        try {
            iva = Integer.parseInt(t_iva1.getValue().toString());
            BigDecimal total = new BigDecimal("0.0");
            for (int ren = 0; ren < t_datos.getRowCount(); ren++)
                total = total.add(new BigDecimal(t_datos.getValueAt(ren, 6).toString()));
            t_subtotal.setValue(new Double(total.toString()));
            BigDecimal valor_iva = new BigDecimal("" + iva);
            valor_iva = valor_iva.divide(new BigDecimal("100"));
            valor_iva = total.multiply(valor_iva);
            System.out.println("iva:" + iva + "valor:" + valor_iva.toString());
            t_iva.setValue(new Double(valor_iva.toString()));
            total = total.add(valor_iva);
            t_total.setValue(new Double(total.toString()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    DefaultTableModel ModeloTablaReporte(int renglones, String columnas[]) {
        model = new DefaultTableModel(new Object[renglones][7], columnas) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.Double.class, java.lang.String.class,
                    java.lang.String.class, java.lang.Double.class, java.lang.Double.class,
                    java.lang.Double.class };
            boolean[] canEdit = new boolean[] { false, 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:
                    vector.setElementAt(value, col);
                    this.dataVector.setElementAt(vector, row);
                    fireTableCellUpdated(row, col);
                    //calcula_totales();
                    break;

                case 1:
                    if (vector.get(col) == null) {
                        vector.setElementAt(value, col);
                        this.dataVector.setElementAt(vector, row);
                        fireTableCellUpdated(row, col);
                    } else {
                        Session session = HibernateUtil.getSessionFactory().openSession();
                        try {
                            session.beginTransaction().begin();
                            Concepto con = (Concepto) session.get(Concepto.class,
                                    Integer.parseInt(t_datos.getValueAt(row, 0).toString()));
                            con.setCantidad((double) value);
                            session.update(con);
                            session.beginTransaction().commit();

                            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);
                        } catch (Exception e) {
                            session.beginTransaction().rollback();
                            e.printStackTrace();
                            JOptionPane.showMessageDialog(null, "Error al almacenar los datos");
                        } finally {
                            if (session != null)
                                if (session.isOpen())
                                    session.close();
                        }
                    }
                    sumaTotales();
                    break;
                case 2:
                    if (vector.get(col) == null) {
                        vector.setElementAt(value, col);
                        this.dataVector.setElementAt(vector, row);
                        fireTableCellUpdated(row, col);
                    } else {
                        Session session = HibernateUtil.getSessionFactory().openSession();
                        try {
                            session.beginTransaction().begin();
                            Concepto con = (Concepto) session.get(Concepto.class,
                                    Integer.parseInt(t_datos.getValueAt(row, 0).toString()));
                            con.setMedida((String) value);
                            session.update(con);
                            session.beginTransaction().commit();

                            vector.setElementAt(value, col);
                            this.dataVector.setElementAt(vector, row);
                            fireTableCellUpdated(row, col);
                        } catch (Exception e) {
                            session.beginTransaction().rollback();
                            e.printStackTrace();
                            JOptionPane.showMessageDialog(null, "Error al almacenar los datos");
                        } finally {
                            if (session != null)
                                if (session.isOpen())
                                    session.close();
                        }
                    }
                    sumaTotales();
                    break;
                case 3:
                    if (vector.get(col) == null) {
                        vector.setElementAt(value, col);
                        this.dataVector.setElementAt(vector, row);
                        fireTableCellUpdated(row, col);
                    } else {
                        if (value.toString().compareTo("") != 0) {
                            Session session = HibernateUtil.getSessionFactory().openSession();
                            try {
                                session.beginTransaction().begin();
                                Concepto con = (Concepto) session.get(Concepto.class,
                                        Integer.parseInt(t_datos.getValueAt(row, 0).toString()));
                                con.setDescripcion(value.toString());
                                session.update(con);
                                session.beginTransaction().commit();

                                vector.setElementAt(value, col);
                                this.dataVector.setElementAt(vector, row);
                                fireTableCellUpdated(row, col);
                            } catch (Exception e) {
                                session.beginTransaction().rollback();
                                e.printStackTrace();
                                JOptionPane.showMessageDialog(null, "Error al almacenar los datos");
                            } finally {
                                if (session != null)
                                    if (session.isOpen())
                                        session.close();
                            }
                        }
                    }
                    sumaTotales();
                    break;

                case 4:
                    if (vector.get(col) == null) {
                        vector.setElementAt(value, col);
                        this.dataVector.setElementAt(vector, row);
                        fireTableCellUpdated(row, col);
                    } else {
                        Session session = HibernateUtil.getSessionFactory().openSession();
                        try {
                            session.beginTransaction().begin();
                            Concepto con = (Concepto) session.get(Concepto.class,
                                    Integer.parseInt(t_datos.getValueAt(row, 0).toString()));
                            con.setPrecio((double) value);
                            session.update(con);
                            session.beginTransaction().commit();

                            vector.setElementAt(value, col);
                            this.dataVector.setElementAt(vector, row);
                            fireTableCellUpdated(row, col);
                            double suma = (((double) value) * ((double) t_datos.getValueAt(row, 1)));
                            double desc = ((double) t_datos.getValueAt(row, 5)) / 100;
                            double total = suma - (suma * desc);
                            t_datos.setValueAt(total, row, 6);
                        } catch (Exception e) {
                            session.beginTransaction().rollback();
                            e.printStackTrace();
                            JOptionPane.showMessageDialog(null, "Error al almacenar los datos");
                        } finally {
                            if (session != null)
                                if (session.isOpen())
                                    session.close();
                        }
                    }
                    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) {
                            Session session = HibernateUtil.getSessionFactory().openSession();
                            try {
                                session.beginTransaction().begin();
                                Concepto con = (Concepto) session.get(Concepto.class,
                                        Integer.parseInt(t_datos.getValueAt(row, 0).toString()));
                                con.setDescuento((double) value);
                                session.update(con);
                                session.beginTransaction().commit();

                                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, 1)));
                                double desc = ((double) value) / 100;
                                double total = suma - (suma * desc);
                                t_datos.setValueAt(total, row, 6);
                            } catch (Exception e) {
                                session.beginTransaction().rollback();
                                e.printStackTrace();
                                JOptionPane.showMessageDialog(null, "Error al almacenar los datos");
                            } finally {
                                if (session != null)
                                    if (session.isOpen())
                                        session.close();
                            }
                        }
                    }
                    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;
    }

    DefaultTableModel ModeloTablaFactura(int renglones, String columnas[]) {
        modeloFactura = new DefaultTableModel(new Object[renglones][6], columnas) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class };
            boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false, 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) {
                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 modeloFactura;
    }

public void tabla_tamaos()
{
    TableColumnModel col_model = t_datos.getColumnModel();
    for (int i=0; i<t_datos.getColumnCount(); i++)
    {
       TableColumn column = col_model.getColumn(i);
          switch(i)
          {
              case 0:
                  column.setPreferredWidth(5);
                  break;
              case 1:
                  column.setPreferredWidth(20);
                  break;
              case 2:
                  column.setPreferredWidth(20);
                  break;
              case 3:
                  column.setPreferredWidth(350);
                  break;
              case 4:
                  column.setPreferredWidth(40);
                  break;
              case 5:
                  column.setPreferredWidth(40);
                  break;
              case 6:
                  column.setPreferredWidth(40);
                  break;
              default:
                  column.setPreferredWidth(5);
                  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);
}

    public void tabla_tamanios_factura() {
        TableColumnModel col_model = t_facturas.getColumnModel();
        for (int i = 0; i < t_facturas.getColumnCount(); i++) {
            TableColumn column = col_model.getColumn(i);
            switch (i) {
            case 0:
                column.setPreferredWidth(90);
                break;
            case 1:
                column.setPreferredWidth(140);
                break;
            case 2:
                column.setPreferredWidth(90);
                break;
            case 3:
                column.setPreferredWidth(30);
                break;
            case 4:
                column.setPreferredWidth(30);
                break;
            case 5:
                column.setPreferredWidth(100);
                break;
            case 6:
                column.setPreferredWidth(90);
                break;
            case 7:
                column.setPreferredWidth(40);
                break;
            default:
                column.setPreferredWidth(30);
                break;
            }
        }
        JTableHeader header = t_facturas.getTableHeader();
        header.setForeground(Color.white);
    }

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

    public int OrdenFacturado(Orden or) {
        int var = -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)
                    return fac[r].getIdFactura();
            }
        } catch (Exception e) {
            System.out.println(e);
            var = -1;
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
            return var;
        }
    }

    public boolean generarXML(Orden ord, String nombre) {
        boolean var = false;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            error = "";
            session.beginTransaction().begin();
            factura = (Factura) session.get(Factura.class, factura.getIdFactura());
            Configuracion config = (Configuracion) session.get(Configuracion.class, 1);
            BigDecimal valorIva = new BigDecimal("" + t_iva1.getValue().toString());
            javaToXML miXML = new javaToXML();
            TFactDocMX documento = new TFactDocMX();
            documento.setVersion(BigInteger.valueOf(5));
            TFactDocMX.Identificacion id = new TFactDocMX.Identificacion();
            id.setCdgPaisEmisor(mysuite.TSenderCountryCode.MX);
            id.setTipoDeComprobante(mysuite.TTipoDeDocumento.FACTURA);
            id.setRFCEmisor(config.getRfc());
            id.setRazonSocialEmisor(config.getNombre());
            id.setUsuario(config.getUsuario_1());
            id.setNumeroInterno(t_codigo.getText());//numero de factura interna
            if (config.getMunicipio().trim().compareTo("") != 0) {
                if (config.getEstado().compareTo("") != 0)
                    id.setLugarExpedicion(config.getMunicipio() + ", " + config.getEstado());
                else
                    id.setLugarExpedicion(config.getMunicipio());
            } else {
                if (config.getEstado().compareTo("") != 0)
                    id.setLugarExpedicion(config.getEstado());
                else
                    id.setLugarExpedicion("TOLUCA, ESTADO DE MEXICO");
            }
            documento.setIdentificacion(id);
            TDictionaries diccionarios = new TDictionaries();
            TDictionary direccion = new TDictionary();
            direccion.setName("email");
            TDictionary.Entry de = new TDictionary.Entry();
            de.setK("from");
            de.setV("ACCOUNT_OWNER");
            direccion.getEntry().add(de);
            TDictionary.Entry para = new TDictionary.Entry();
            para.setK("to");
            para.setV(t_correo_emisor.getText().trim());
            direccion.getEntry().add(para);
            diccionarios.getDictionary().add(direccion);
            documento.setProcesamiento(diccionarios);
            TFactDocMX.Emisor envia = new TFactDocMX.Emisor();
            mysuite.TDomicilioMexicano dFiscal = new mysuite.TDomicilioMexicano();
            dFiscal.setCalle(config.getDireccion().trim());
            dFiscal.setNumeroExterior(config.getNo().trim());
            //dFiscal.setNumeroInterior("");
            //dFiscal.setLocalidad("");
            //dFiscal.setReferencia("");
            dFiscal.setColonia(config.getColonia().trim());
            dFiscal.setMunicipio(config.getMunicipio().trim());
            dFiscal.setEstado(config.getEstado());
            dFiscal.setPais(config.getPais());
            dFiscal.setCodigoPostal(config.getCp().trim());
            //dFiscal.setNomContacto("");
            //dFiscal.setTelContacto("");
            envia.setDomicilioFiscal(dFiscal);
            //si es diferente al domicilio fiscal usar este camposen blanco no obligatorios
            //mysuite.TDomicilioMexicano dEmision= new mysuite.TDomicilioMexicano();
            //dEmision.setCalle("TDomicilioMexicano");
            //dEmision.setNumeroExterior("S/N");
            //dEmision.setNumeroInterior("");
            //dEmision.setLocalidad("");
            //dEmision.setReferencia("");
            //dEmision.setColonia("SAN PEDRO TOTOLTEPE");
            //dEmision.setMunicipio("SAN PEDRO TOTOLTEPEC");
            //dEmision.setEstado("MEXICO");
            //dEmision.setPais("MEXICO");
            //dEmision.setCodigoPostal("50200");
            //dEmision.setNomContacto("");
            //dEmision.setTelContacto("");
            //envia.setDomicilioDeEmision(dEmision);
            TFactDocMX.Emisor.RegimenFiscal enviaRegimen = new TFactDocMX.Emisor.RegimenFiscal();
            enviaRegimen.getRegimen().add("REGIMEN GENERAL DE LEY DE PERSONAS MORALES");
            envia.setRegimenFiscal(enviaRegimen);
            documento.setEmisor(envia);
            TFactDocMX.Receptor recibe = new TFactDocMX.Receptor();
            recibe.setCdgPaisReceptor(TCountryCode.MX);
            recibe.setRFCReceptor(t_rfc.getText().trim());
            recibe.setNombreReceptor(t_social.getText().trim());
            TFactDocMX.Receptor.Domicilio domicilio = new TFactDocMX.Receptor.Domicilio();
            mysuite.TDomicilioMexicano dFiscalRecibe = new mysuite.TDomicilioMexicano();
            dFiscalRecibe.setCalle(t_calle.getText().trim());
            dFiscalRecibe.setNumeroExterior(t_no_exterior.getText().trim());
            //dFiscalRecibe.setNumeroInterior("");
            //dFiscalRecibe.setLocalidad("");
            //dFiscalRecibe.setReferencia("");
            dFiscalRecibe.setColonia(t_colonia.getText().trim());
            dFiscalRecibe.setMunicipio(t_municipio.getText().trim());
            dFiscalRecibe.setEstado(c_estado.getSelectedItem().toString());
            dFiscalRecibe.setPais(c_pais.getSelectedItem().toString());
            dFiscalRecibe.setCodigoPostal(t_cp.getText().trim());
            //dFiscalRecibe.setNomContacto("");
            //dFiscalRecibe.setTelContacto("");
            domicilio.setDomicilioFiscalMexicano(dFiscalRecibe);
            domicilio.setOtroDomicilio(null);
            recibe.setDomicilio(domicilio);
            recibe.setDomicilioDeRecepcion(null);
            documento.setReceptor(recibe);
            TFactDocMX.Conceptos conceptos = new TFactDocMX.Conceptos();
            BigDecimal big_total_bruto = new BigDecimal("0.0");
            BigDecimal big_sub_total = new BigDecimal("0.0");
            TDescuentosYRecargos descuentosyRecargos = new TDescuentosYRecargos(); //agrupa los descuentos y recargos
            for (int ren = 0; ren < t_datos.getRowCount(); ren++) {
                //descuento
                BigDecimal big_descuento = new BigDecimal(t_datos.getValueAt(ren, 5).toString());
                BigDecimal big_porciento_dectuento = big_descuento.divide(new BigDecimal("100"));
                //cantidades de lista
                BigDecimal big_cantidad = new BigDecimal(t_datos.getValueAt(ren, 1).toString());
                BigDecimal big_precio_lista = new BigDecimal(t_datos.getValueAt(ren, 4).toString());
                BigDecimal big_total_lista = big_precio_lista.multiply(big_cantidad);
                big_total_bruto = big_total_bruto.add(big_total_lista);
                //cantidades netas
                BigDecimal big_precio_neto = big_precio_lista
                        .subtract(big_precio_lista.multiply(big_porciento_dectuento));
                BigDecimal big_total_neto = big_precio_neto.multiply(big_cantidad);
                big_sub_total = big_sub_total.add(big_total_neto);

                TFactDocMX.Conceptos.Concepto renglon = new TFactDocMX.Conceptos.Concepto();
                renglon.setCantidad(big_cantidad.setScale(2, BigDecimal.ROUND_HALF_UP));
                renglon.setUnidadDeMedida(t_datos.getValueAt(ren, 2).toString().trim());
                renglon.setDescripcion(t_datos.getValueAt(ren, 3).toString().trim());

                mysuite.TNonNegativeAmount unitario = new mysuite.TNonNegativeAmount();
                unitario.setValue(big_precio_neto.setScale(2, BigDecimal.ROUND_HALF_UP));
                renglon.setValorUnitario(unitario);
                mysuite.TNonNegativeAmount importe = new mysuite.TNonNegativeAmount();
                importe.setValue(big_total_neto.setScale(2, BigDecimal.ROUND_HALF_UP));
                renglon.setImporte(importe);
                TConceptoEx concepto_ext = new TConceptoEx();
                mysuite.TNonNegativeAmount precio_lista = new mysuite.TNonNegativeAmount();
                precio_lista.setValue(big_precio_lista.setScale(2, BigDecimal.ROUND_HALF_UP));
                concepto_ext.setPrecioLista(precio_lista);
                mysuite.TNonNegativeAmount importe_lista = new mysuite.TNonNegativeAmount();
                importe_lista.setValue(big_total_lista.setScale(2, BigDecimal.ROUND_HALF_UP));
                concepto_ext.setImporteLista(importe_lista);
                if (((double) t_datos.getValueAt(ren, 5)) > 0) {
                    TDescuentosYRecargos descuentosRecargos = new TDescuentosYRecargos();//sirve para totales
                    TDiscountOrRecharge desc = new TDiscountOrRecharge();
                    desc.setOperacion(TAllowanceChargeType.DESCUENTO);
                    desc.setImputacion(TSettlementType.FUERA_DE_FACTURA);
                    desc.setServicio(TSpecialServicesType.REBAJA);
                    desc.setDescripcion("Descuento");
                    desc.setBase(importe_lista);
                    desc.setTasa(BigDecimal.valueOf((double) t_datos.getValueAt(ren, 5)).setScale(2,
                            BigDecimal.ROUND_HALF_UP));
                    mysuite.TNonNegativeAmount monto = new mysuite.TNonNegativeAmount();
                    monto.setValue(big_total_lista.multiply(big_porciento_dectuento).setScale(2,
                            BigDecimal.ROUND_HALF_UP));
                    desc.setMonto(monto);
                    descuentosRecargos.getDescuentoORecargo().add(desc);
                    concepto_ext.setDescuentosYRecargos(descuentosRecargos);
                    int posicion = existe(descuentosyRecargos, desc);
                    if (posicion == -1) {
                        TDiscountOrRecharge desc1 = new TDiscountOrRecharge();
                        desc1.setOperacion(TAllowanceChargeType.DESCUENTO);
                        desc1.setImputacion(TSettlementType.FUERA_DE_FACTURA);
                        desc1.setServicio(TSpecialServicesType.REBAJA);
                        desc1.setDescripcion("Descuento");
                        desc1.setBase(importe_lista);
                        desc1.setTasa(BigDecimal.valueOf((double) t_datos.getValueAt(ren, 5)).setScale(2,
                                BigDecimal.ROUND_HALF_UP));
                        mysuite.TNonNegativeAmount monto1 = new mysuite.TNonNegativeAmount();
                        monto1.setValue(big_total_lista.multiply(big_porciento_dectuento).setScale(2,
                                BigDecimal.ROUND_HALF_UP));
                        desc1.setMonto(monto1);
                        descuentosyRecargos.getDescuentoORecargo().add(desc1);
                    } else {
                        TDiscountOrRecharge aux = descuentosyRecargos.getDescuentoORecargo().get(posicion);
                        mysuite.TNonNegativeAmount baseAux = new mysuite.TNonNegativeAmount();
                        BigDecimal n1 = aux.getBase().getValue();
                        BigDecimal n2 = desc.getBase().getValue();
                        BigDecimal n3 = n1.add(n2).setScale(2, BigDecimal.ROUND_HALF_UP);
                        baseAux.setValue(n3);
                        aux.setBase(baseAux);
                        mysuite.TNonNegativeAmount montoAux = new mysuite.TNonNegativeAmount();
                        BigDecimal a1 = aux.getBase().getValue();
                        BigDecimal a2 = aux.getTasa().divide(new BigDecimal("100")).setScale(2,
                                BigDecimal.ROUND_HALF_UP);
                        BigDecimal a3 = a1.multiply(a2).setScale(2, BigDecimal.ROUND_HALF_UP);
                        montoAux.setValue(a3);
                        aux.setMonto(montoAux);
                        descuentosyRecargos.getDescuentoORecargo().set(posicion, aux);
                    }
                }
                TImpuestos impuestos = new TImpuestos();//sirve para totales
                TTax imp = new TTax();
                imp.setContexto(TTaxContext.FEDERAL);
                imp.setOperacion(TTaxOperation.TRASLADO);
                imp.setCodigo("IVA");
                mysuite.TNonNegativeAmount baseIMP = new mysuite.TNonNegativeAmount();
                baseIMP.setValue(big_total_neto.setScale(2, BigDecimal.ROUND_HALF_UP));
                imp.setBase(baseIMP);
                imp.setTasa(valorIva.setScale(2, BigDecimal.ROUND_HALF_UP));
                mysuite.TNonNegativeAmount montoIMP = new mysuite.TNonNegativeAmount();
                BigDecimal porc = valorIva.divide(new BigDecimal("100.0")).setScale(2, BigDecimal.ROUND_HALF_UP);
                BigDecimal monto = big_total_neto.multiply(porc).setScale(2, BigDecimal.ROUND_HALF_UP);
                montoIMP.setValue(monto.setScale(2, BigDecimal.ROUND_HALF_UP));
                imp.setMonto(montoIMP);
                impuestos.getImpuesto().add(imp);
                concepto_ext.setImpuestos(impuestos);
                renglon.setConceptoEx(concepto_ext);
                renglon.setOpciones(null);
                conceptos.getConcepto().add(renglon);//ciclo por el total de conceptos
            }
            documento.setConceptos(conceptos);
            TFactDocMX.Totales totales = new TFactDocMX.Totales();
            totales.setMoneda(TCurrencyCode.MXN);
            totales.setTipoDeCambioVenta(BigDecimal.valueOf(((Number) t_tipo_cambio.getValue()).doubleValue())
                    .setScale(3, BigDecimal.ROUND_HALF_UP));
            mysuite.TNonNegativeAmount sub_total_bruto = new mysuite.TNonNegativeAmount();
            sub_total_bruto.setValue(big_total_bruto.setScale(2, BigDecimal.ROUND_HALF_UP));
            totales.setSubTotalBruto(sub_total_bruto);
            mysuite.TNonNegativeAmount sub_total = new mysuite.TNonNegativeAmount();
            sub_total.setValue(big_sub_total.setScale(2, BigDecimal.ROUND_HALF_UP));
            totales.setSubTotal(sub_total);

            totales.setDescuentosYRecargos(descuentosyRecargos);
            TResumenDeDescuentosYRecargos resumenDescuentos = new TResumenDeDescuentosYRecargos();
            mysuite.TNonNegativeAmount totalDescuentos = new mysuite.TNonNegativeAmount();
            BigDecimal sumaDescuentos = new BigDecimal(0.0).setScale(2, BigDecimal.ROUND_HALF_UP);
            for (int r = 0; r < descuentosyRecargos.getDescuentoORecargo().size(); r++) {
                if (descuentosyRecargos.getDescuentoORecargo().get(r)
                        .getOperacion() == TAllowanceChargeType.DESCUENTO)
                    sumaDescuentos = sumaDescuentos
                            .add(descuentosyRecargos.getDescuentoORecargo().get(r).getMonto().getValue())
                            .setScale(2, BigDecimal.ROUND_HALF_UP);
            }
            totalDescuentos.setValue(sumaDescuentos.setScale(2, BigDecimal.ROUND_HALF_UP));
            resumenDescuentos.setTotalDescuentos(totalDescuentos);
            mysuite.TNonNegativeAmount totalRecargos = new mysuite.TNonNegativeAmount();
            totalRecargos.setValue(BigDecimal.valueOf(0));
            resumenDescuentos.setTotalRecargos(totalRecargos);
            totales.setResumenDeDescuentosYRecargos(resumenDescuentos);
            TImpuestos impuestos = new TImpuestos();
            TTax imp = new TTax();
            imp.setContexto(TTaxContext.FEDERAL);
            imp.setOperacion(TTaxOperation.TRASLADO);
            imp.setCodigo("IVA");
            mysuite.TNonNegativeAmount baseIMP = new mysuite.TNonNegativeAmount();
            baseIMP.setValue(big_sub_total.setScale(2, BigDecimal.ROUND_HALF_UP));
            imp.setBase(baseIMP);
            imp.setTasa(valorIva);
            mysuite.TNonNegativeAmount montoIMP = new mysuite.TNonNegativeAmount();
            BigDecimal big_total_iva = big_sub_total.multiply(valorIva.divide(new BigDecimal("100.0"))).setScale(2,
                    BigDecimal.ROUND_HALF_UP);
            montoIMP.setValue(big_total_iva.setScale(2, BigDecimal.ROUND_HALF_UP));
            imp.setMonto(montoIMP);
            impuestos.getImpuesto().add(imp);
            totales.setImpuestos(impuestos);
            TResumenDeImpuestos resumenImpuestos = new TResumenDeImpuestos();
            mysuite.TNonNegativeAmount total_traslados_federales = new mysuite.TNonNegativeAmount();
            total_traslados_federales.setValue(big_total_iva.setScale(2, BigDecimal.ROUND_HALF_UP));
            resumenImpuestos.setTotalTrasladosFederales(total_traslados_federales);
            mysuite.TNonNegativeAmount total_iva_traslado = new mysuite.TNonNegativeAmount();
            total_iva_traslado.setValue(big_total_iva.setScale(2, BigDecimal.ROUND_HALF_UP));
            resumenImpuestos.setTotalIVATrasladado(total_iva_traslado);
            mysuite.TNonNegativeAmount total_ieps_traslado = new mysuite.TNonNegativeAmount();
            total_ieps_traslado.setValue(BigDecimal.valueOf(0));
            resumenImpuestos.setTotalIEPSTrasladado(total_ieps_traslado);
            mysuite.TNonNegativeAmount total_retenciones_federales = new mysuite.TNonNegativeAmount();
            total_retenciones_federales.setValue(BigDecimal.valueOf(0));
            resumenImpuestos.setTotalRetencionesFederales(total_retenciones_federales);
            mysuite.TNonNegativeAmount total_isr_retenido = new mysuite.TNonNegativeAmount();
            total_isr_retenido.setValue(BigDecimal.valueOf(0));
            resumenImpuestos.setTotalISRRetenido(total_isr_retenido);
            mysuite.TNonNegativeAmount total_iva_retenido = new mysuite.TNonNegativeAmount();
            total_iva_retenido.setValue(BigDecimal.valueOf(0));
            resumenImpuestos.setTotalIVARetenido(total_iva_retenido);
            mysuite.TNonNegativeAmount total_traslados_locales = new mysuite.TNonNegativeAmount();
            total_traslados_locales.setValue(BigDecimal.valueOf(0));
            resumenImpuestos.setTotalTrasladosLocales(total_traslados_locales);
            mysuite.TNonNegativeAmount total_retenciones_locales = new mysuite.TNonNegativeAmount();
            total_retenciones_locales.setValue(BigDecimal.valueOf(0));
            resumenImpuestos.setTotalRetencionesLocales(total_retenciones_locales);
            totales.setResumenDeImpuestos(resumenImpuestos);
            mysuite.TNonNegativeAmount total = new mysuite.TNonNegativeAmount();
            BigDecimal big_total_final = big_sub_total.add(big_total_iva).setScale(2, BigDecimal.ROUND_HALF_UP);
            total.setValue(big_total_final.setScale(2, BigDecimal.ROUND_HALF_UP));
            totales.setTotal(total);
            //totales.setTotalEnLetra("OCHOCIENTOS TREINTA Y CINCO PESOS 20/100 M.N.");
            totales.setTotalEnLetra(numeroLetra.convertNumberToLetter(
                    big_total_final.setScale(2, BigDecimal.ROUND_HALF_UP).toString()) + " M.N.");
            totales.setFormaDePago("PAGO EN UNA SOLA EXHIBICION");
            documento.setTotales(totales);
            TComprobanteEx comprobante_ex = new TComprobanteEx();
            TComprobanteEx.DatosDeNegocio datos_del_negocio = new TComprobanteEx.DatosDeNegocio();
            datos_del_negocio.setSucursal(config.getSucursal());
            comprobante_ex.setDatosDeNegocio(datos_del_negocio);
            TComprobanteEx.DatosComerciales datos_comerciales = new TComprobanteEx.DatosComerciales();
            datos_comerciales.setRelacionComercial(TRelacionComercial.PROVEEDOR);
            datos_comerciales.setNumeroDeProveedor(t_proveedor.getText().trim());
            datos_comerciales.setSubAddenda1("200");
            TReferenciaCorta trc = new TReferenciaCorta();
            GregorianCalendar c = new GregorianCalendar();
            c.setTime(factura.getFecha());
            XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
            trc.setFecha(date2);
            trc.getNumero().add(t_codigo.getText().trim());
            datos_comerciales.setOrdenDeCompra(trc);
            comprobante_ex.setDatosComerciales(datos_comerciales);
            TComprobanteEx.TerminosDePago terminos_de_pago = new TComprobanteEx.TerminosDePago();
            terminos_de_pago.setMetodoDePago(t_metodo_pago.getText().trim());
            terminos_de_pago.setCondicionesDePago(t_condiciones.getText().trim());
            comprobante_ex.setTerminosDePago(terminos_de_pago);
            TComprobanteEx.DatosDeEmbarque datosEmbarque = new TComprobanteEx.DatosDeEmbarque();
            TDomicilioComercial lugarEmbarque = new TDomicilioComercial();
            lugarEmbarque.setCodigo("NA");
            datosEmbarque.setLugarDeEntrega(lugarEmbarque);
            comprobante_ex.setDatosDeEmbarque(datosEmbarque);
            TDatosAdicionales datosAdicionesEmisor = new TDatosAdicionales();
            datosAdicionesEmisor.setRegistroPublico(t_ri_emisor.getText().trim());
            comprobante_ex.setDatosAdicionalesDeEmisor(datosAdicionesEmisor);
            TDatosAdicionales datosAdicionesReceptor = new TDatosAdicionales();
            datosAdicionesReceptor.setRegistroPublico(t_ri_receptor.getText().trim());
            comprobante_ex.setDatosAdicionalesDeReceptor(datosAdicionesReceptor);
            /*TComprobanteEx.ReferenciasBancarias refBanco=new TComprobanteEx.ReferenciasBancarias();
                TReferenciaBancaria rBancaria=new TReferenciaBancaria();
                    rBancaria.setMoneda(TCurrencyCode.MXN);
                    rBancaria.setBanco("BANCO TEST");
                    rBancaria.setTitular("TITULAR TEST");
                    rBancaria.setCuenta("2222222222");
                    rBancaria.setCLABE("22222222222222222");
                    rBancaria.setRefCliente("TITULAR TEST");
                refBanco.getReferenciaBancaria().add(rBancaria);
            comprobante_ex.setReferenciasBancarias(refBanco);*/
            TTextoLibre pie = new TTextoLibre();
            pie.getTexto().add("NA");
            comprobante_ex.setTextosDePie(pie);
            //MAPFRE
            TMTECabecera mapfre = new TMTECabecera();
            /*TMTEContactoEmisor contactoEmisor = new TMTEContactoEmisor();
                contactoEmisor.setTipoDeContacto(c_tipo_emisor.getSelectedItem().toString());
                contactoEmisor.setNombreDePersona(t_nombre_emisor.getText().trim());
                contactoEmisor.setEMail(t_correo_emisor.getText().trim());
                contactoEmisor.setTelefono(t_tel_emisor.getText().trim());
            mapfre.setContactoEmisor(contactoEmisor);
            TMTEContactoReceptor contactoReceptor= new TMTEContactoReceptor();
                contactoReceptor.setTipoDeContacto(c_tipo_receptor.getSelectedItem().toString());
                contactoReceptor.setNombreDePersona(t_nombre_emisor.getText().trim());
                contactoReceptor.setEMail(t_correo_emisor.getText().trim());
                contactoReceptor.setTelefono(t_tel_receptor.getText().trim());
            mapfre.setContactoReceptor(contactoReceptor);*/
            TMTEPoliza poliza = new TMTEPoliza();
            poliza.setTipo(t_tipo_poliza.getText().trim());
            poliza.setNumero(t_numero.getText().trim());
            poliza.setInciso(t_inciso.getText().trim());
            poliza.setSiniestro(t_siniestro.getText().trim());
            mapfre.setPoliza(poliza);
            TMTEVehiculo vehiculo = new TMTEVehiculo();
            vehiculo.setUso("NO APLICA");
            vehiculo.setMarca(t_marca_vehiculo.getText().trim());
            vehiculo.setSubMarca(t_anio_vehiculo.getText().trim());
            vehiculo.setAnoDeProduccion(new BigInteger(t_anio_vehiculo.getText().trim()));
            vehiculo.setColor("NO APLICA");
            vehiculo.setSerie("NO APLICA");
            vehiculo.setPlacas(t_placas_vehiculo.getText().trim());
            mapfre.setVehiculo(vehiculo);
            if (t_deducible.getText().trim().compareTo("") != 0) {
                TMTEImportesAdicionales importesAdicionales = new TMTEImportesAdicionales();
                mysuite.TNonNegativeAmount tot_deducible = new mysuite.TNonNegativeAmount();
                BigDecimal ded = new BigDecimal(((Number) t_deducible.getValue()).doubleValue());
                tot_deducible.setValue(ded.setScale(2, BigDecimal.ROUND_HALF_UP));
                importesAdicionales.setDeducible(tot_deducible);
                mapfre.setImportesAdicionales(importesAdicionales);
            }
            TMTEReaseguradora reaseg = new TMTEReaseguradora();
            reaseg.setClave(c_tipo_facturacion.getSelectedItem().toString());
            mapfre.setReaseguradora(reaseg);
            comprobante_ex.setMapfre(mapfre);
            documento.setComprobanteEx(comprobante_ex);

            if (miXML.creaAndValidaXML(documento, nombre) == true)
                var = true;
            else {
                error = miXML.error;
                var = false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            var = false;
        }
        if (session != null)
            if (session.isOpen())
                session.close();
        return var;
    }

    public void llamarSoapCancela(RequestTransaction rq) {
        System.setProperty("javax.net.ssl.keyStore", "cacerts");
        System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
        System.setProperty("javax.net.ssl.trustStore", "cacerts");
        try { // Call Web Service Operation(async. callback)
            if (rq != null) {
                mx.com.fact.schema.ws.FactWSFront service = new mx.com.fact.schema.ws.FactWSFront();
                mx.com.fact.schema.ws.FactWSFrontSoap port = service.getFactWSFrontSoap();

                // TODO initialize WS operation arguments here
                java.lang.String requestor = rq.getRequestor();
                java.lang.String transaction = rq.getTransaction();
                java.lang.String country = rq.getCountry();
                java.lang.String entity = rq.getEntity();
                java.lang.String userSAP = rq.getUser();
                java.lang.String userName = rq.getUserName();
                java.lang.String data1 = rq.getData1();
                java.lang.String data2 = rq.getData2();
                java.lang.String data3 = rq.getData3();
                javax.xml.ws.AsyncHandler<mx.com.fact.schema.ws.RequestTransactionResponse> asyncHandler = new javax.xml.ws.AsyncHandler<mx.com.fact.schema.ws.RequestTransactionResponse>() {
                    public void handleResponse(
                            final javax.xml.ws.Response<mx.com.fact.schema.ws.RequestTransactionResponse> response) {
                        try {
                            // TODO process asynchronous response here
                            RequestTransactionResponse rtr = response.get();
                            if (rtr.getRequestTransactionResult().getResponse().isResult() == true)//la transaccion se genero
                            {
                                XMLGregorianCalendar fecha_ingreso = rtr.getRequestTransactionResult().getResponse()
                                        .getTimeStamp();
                                Session session = HibernateUtil.getSessionFactory().openSession();
                                try {
                                    session.beginTransaction().begin();
                                    Factura resp = (Factura) session.createCriteria(Factura.class)
                                            .add(Restrictions.eq("FFiscal", idBuscar)).uniqueResult();
                                    if (resp != null) {
                                        resp.setOrden(null);
                                        resp.setEstadoFactura("Cancelado");
                                        session.update(resp);
                                        session.beginTransaction().commit();
                                        DefaultTableModel modelElimina = (DefaultTableModel) t_facturas.getModel();
                                        modelElimina.removeRow(t_facturas.getSelectedRow());
                                        t_facturas.setModel(modelElimina);
                                        formatoTablafactura();
                                    }
                                    habilita2(true);
                                    progreso.setString("Listo");
                                    progreso.setIndeterminate(false);
                                    JOptionPane.showMessageDialog(null, "El UUID ya esta Cancelado");
                                } catch (Exception e) {
                                    session.beginTransaction().rollback();
                                    e.printStackTrace();
                                    habilita2(true);
                                    progreso.setString("Listo");
                                    progreso.setIndeterminate(false);
                                    JOptionPane.showMessageDialog(null,
                                            "El UUID ya esta Cancelado, pero no se pudo almacenar en la base de datos");
                                } finally {
                                    if (session != null)
                                        if (session.isOpen())
                                            session.close();
                                }
                            } else {
                                String error = rtr.getRequestTransactionResult().getResponseData()
                                        .getResponseData2();
                                String aux = "";
                                String numeros = "0123456789";
                                for (int pal = 0; pal < error.length(); pal++) {
                                    if (numeros.contains("" + error.charAt(pal)))
                                        aux += "" + error.charAt(pal);
                                }
                                if (aux.length() > 0) {
                                    switch (aux) {
                                    case "201"://UUID Cancelado 
                                        Session session = HibernateUtil.getSessionFactory().openSession();
                                        try {
                                            session.beginTransaction().begin();
                                            Factura resp = (Factura) session.createCriteria(Factura.class)
                                                    .add(Restrictions.eq("FFiscal", idBuscar)).uniqueResult();
                                            if (resp != null) {
                                                resp.setOrden(null);
                                                resp.setEstadoFactura("Cancelado");
                                                session.update(resp);
                                                session.beginTransaction().commit();
                                            }
                                            habilita2(true);
                                            progreso.setString("Listo");
                                            progreso.setIndeterminate(false);
                                            JOptionPane.showMessageDialog(null, "El UUID ya esta Cancelado");
                                        } catch (Exception e) {
                                            session.beginTransaction().rollback();
                                            e.printStackTrace();
                                            habilita2(true);
                                            progreso.setString("Listo");
                                            progreso.setIndeterminate(false);
                                            JOptionPane.showMessageDialog(null,
                                                    "El UUID ya esta Cancelado, pero no se pudo almacenar en la base de datos");
                                        } finally {
                                            if (session != null)
                                                if (session.isOpen())
                                                    session.close();
                                        }
                                        break;
                                    case "202"://UUID Previamente cancelado
                                        session = HibernateUtil.getSessionFactory().openSession();
                                        try {
                                            session.beginTransaction().begin();
                                            Factura resp = (Factura) session.createCriteria(Factura.class)
                                                    .add(Restrictions.eq("FFiscal", idBuscar)).uniqueResult();
                                            if (resp != null) {
                                                resp.setOrden(null);
                                                resp.setEstadoFactura("Cancelado");
                                                session.update(resp);
                                                session.beginTransaction().commit();
                                            }
                                            habilita2(true);
                                            progreso.setString("Listo");
                                            progreso.setIndeterminate(false);
                                            JOptionPane.showMessageDialog(null, "El UUID ya esta Cancelado");
                                        } catch (Exception e) {
                                            session.beginTransaction().rollback();
                                            e.printStackTrace();
                                            habilita2(true);
                                            progreso.setString("Listo");
                                            progreso.setIndeterminate(false);
                                            JOptionPane.showMessageDialog(null,
                                                    "El UUID ya esta Cancelado, pero no se pudo almacenar en la base de datos");
                                        } finally {
                                            if (session.isOpen())
                                                session.close();
                                        }
                                        break;
                                    case "203"://UUID No corresponde al emisor
                                        habilita2(true);
                                        progreso.setString("Listo");
                                        progreso.setIndeterminate(false);
                                        JOptionPane.showMessageDialog(null, "no corresponde al emisor");
                                        break;
                                    case "204"://UUID No aplicable para cancelacin
                                        habilita2(true);
                                        progreso.setString("Listo");
                                        progreso.setIndeterminate(false);
                                        JOptionPane.showMessageDialog(null, "La factura no corresponde al emisor");
                                        break;
                                    case "205"://UUID No existe
                                        habilita2(true);
                                        progreso.setString("Listo");
                                        progreso.setIndeterminate(false);
                                        JOptionPane.showMessageDialog(null, "La factura no existe en el SAT");
                                        break;
                                    default:
                                        habilita2(true);
                                        progreso.setString("Listo");
                                        progreso.setIndeterminate(false);
                                        JOptionPane.showMessageDialog(null, "error al cancelar en sat");
                                        break;
                                    }
                                    try {
                                        String fecha = rtr.getRequestTransactionResult().getResponse()
                                                .getTimeStamp().toXMLFormat();
                                        Calendar calendario = Calendar.getInstance();
                                        File f = new File("errores/" + sdf.format(calendario.getTime()) + ".txt");
                                        FileWriter w = new FileWriter(f);
                                        BufferedWriter bw = new BufferedWriter(w);
                                        PrintWriter wr = new PrintWriter(bw);
                                        wr.write(rtr.getRequestTransactionResult().getResponse().getDescription());
                                        wr.write(rtr.getRequestTransactionResult().getResponse().getHint());
                                        wr.write(rtr.getRequestTransactionResult().getResponse().getData());
                                        wr.write(rtr.getRequestTransactionResult().getResponseData()
                                                .getResponseData1());
                                        wr.write(rtr.getRequestTransactionResult().getResponseData()
                                                .getResponseData2());
                                        wr.write(rtr.getRequestTransactionResult().getResponseData()
                                                .getResponseData3());
                                        wr.close();
                                        bw.close();
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                } else {
                                    habilita2(true);
                                    progreso.setString("Listo");
                                    progreso.setIndeterminate(false);
                                    JOptionPane.showMessageDialog(null, "error al cancelar en sat");
                                }
                            }
                        } catch (Exception ex) {
                            System.out.println("Error en la conexion con el SAP:" + ex);
                            habilita2(true);
                            progreso.setString("Listo");
                            progreso.setIndeterminate(false);
                            JOptionPane.showMessageDialog(null, "Error en la conexion con el SAP:" + ex);
                        }
                    }
                };
                java.util.concurrent.Future<? extends java.lang.Object> result = port.requestTransactionAsync(
                        requestor, transaction, country, entity, userSAP, userName, data1, data2, data3,
                        asyncHandler);
            } else {
                habilita2(true);
                progreso.setString("Listo");
                progreso.setIndeterminate(false);
            }
        } catch (Exception ex) {
            System.out.println("Error en la conexion con el SAP:" + ex);
            habilita2(true);
            progreso.setString("Listo");
            progreso.setIndeterminate(false);
            JOptionPane.showMessageDialog(null, "Error en la conexion con el SAP:" + ex);
        }
    }

    public void llamarSoapDocumento(RequestTransaction rq) {
        System.setProperty("javax.net.ssl.keyStore", "cacerts");
        System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
        System.setProperty("javax.net.ssl.trustStore", "cacerts");
        try { // Call Web Service Operation(async. callback)
            if (rq != null) {
                mx.com.fact.schema.ws.FactWSFront service = new mx.com.fact.schema.ws.FactWSFront();
                mx.com.fact.schema.ws.FactWSFrontSoap port = service.getFactWSFrontSoap();

                // TODO initialize WS operation arguments here
                java.lang.String requestor = rq.getRequestor();
                java.lang.String transaction = rq.getTransaction();
                java.lang.String country = rq.getCountry();
                java.lang.String entity = rq.getEntity();
                java.lang.String userSAP = rq.getUser();
                java.lang.String userName = rq.getUserName();
                java.lang.String data1 = rq.getData1();
                java.lang.String data2 = rq.getData2();
                java.lang.String data3 = rq.getData3();
                javax.xml.ws.AsyncHandler<mx.com.fact.schema.ws.RequestTransactionResponse> asyncHandler = new javax.xml.ws.AsyncHandler<mx.com.fact.schema.ws.RequestTransactionResponse>() {
                    public void handleResponse(
                            final javax.xml.ws.Response<mx.com.fact.schema.ws.RequestTransactionResponse> response) {
                        try {
                            // TODO process asynchronous response here
                            RequestTransactionResponse rtr = response.get();
                            if (rtr.getRequestTransactionResult().getResponse().isResult() == true)//la transaccion se genero
                            {
                                String serie = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getBatch();
                                String folio = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getSerial();
                                String UUID = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getDocumentGUID();
                                XMLGregorianCalendar fecha_ingreso = rtr.getRequestTransactionResult().getResponse()
                                        .getTimeStamp();
                                String nombre = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getSuggestedFileName();
                                h = new Herramientas(user, 0);
                                h.session(sessionPrograma);
                                if (factura != null) {
                                    Session session = HibernateUtil.getSessionFactory().openSession();
                                    try {
                                        session.beginTransaction().begin();
                                        factura = (Factura) session.get(Factura.class, factura.getIdFactura());

                                        //Datos de timbrado
                                        factura.setEstadoFactura("Facturado");
                                        factura.setFFiscal(UUID);
                                        factura.setFechaFiscal(fecha_ingreso.toXMLFormat());
                                        factura.setSerie(serie);
                                        factura.setFolio(folio);
                                        factura.setNombreDocumento(nombre);
                                        session.update(factura);
                                        session.beginTransaction().commit();

                                        if (rtr.getRequestTransactionResult().getResponseData().getResponseData1()
                                                .compareTo("") != 0) {
                                            rtr.getRequestTransactionResult().getResponse().getIdentifier();
                                            CodeBase64 codificador = new CodeBase64();
                                            codificador.DecodeBase64(
                                                    rtr.getRequestTransactionResult().getResponseData()
                                                            .getResponseData1(),
                                                    "xml-timbrados/" + nombre + ".xml");
                                        }
                                        if (rtr.getRequestTransactionResult().getResponseData().getResponseData3()
                                                .compareTo("") != 0) {
                                            rtr.getRequestTransactionResult().getResponse().getIdentifier();
                                            CodeBase64 codificador = new CodeBase64();
                                            codificador.DecodeBase64(
                                                    rtr.getRequestTransactionResult().getResponseData()
                                                            .getResponseData3(),
                                                    "xml-timbrados/" + nombre + ".pdf");
                                        }
                                        consulta();
                                        try {
                                            File xml;
                                            if (abrir.compareTo("xml") == 0)
                                                xml = new File("xml-timbrados/" + t_xml.getText());
                                            else
                                                xml = new File("xml-timbrados/" + t_pdf.getText());
                                            Desktop.getDesktop().open(xml);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            JOptionPane.showMessageDialog(null, "Error al abrir el archivo xml");
                                        }
                                    } catch (Exception e) {
                                        session.beginTransaction().rollback();
                                        e.printStackTrace();
                                        JOptionPane.showMessageDialog(null, "Error al almacenar los datos");
                                    } finally {
                                        if (session != null)
                                            if (session.isOpen())
                                                session.close();
                                    }
                                }
                            } else {
                                try {
                                    String fecha = rtr.getRequestTransactionResult().getResponse().getTimeStamp()
                                            .toXMLFormat();
                                    Calendar calendario = Calendar.getInstance();
                                    File f = new File("errores/" + sdf.format(calendario.getTime()) + ".txt");
                                    FileWriter w = new FileWriter(f);
                                    BufferedWriter bw = new BufferedWriter(w);
                                    PrintWriter wr = new PrintWriter(bw);
                                    wr.write(rtr.getRequestTransactionResult().getResponse().getDescription());
                                    wr.write(rtr.getRequestTransactionResult().getResponse().getHint());
                                    wr.write(rtr.getRequestTransactionResult().getResponse().getData());
                                    wr.close();
                                    bw.close();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                JOptionPane.showMessageDialog(null, "Error al timbrar la factura:"
                                        + rtr.getRequestTransactionResult().getResponse().getDescription());
                            }
                        } catch (Exception ex) {
                            System.out.println("Error en la conexion con el SAP:" + ex);
                        }
                    }
                };
                java.util.concurrent.Future<? extends java.lang.Object> result = port.requestTransactionAsync(
                        requestor, transaction, country, entity, userSAP, userName, data1, data2, data3,
                        asyncHandler);
                /*while(!result.isDone())
                {
                Thread.sleep(100);
                }*/
            }
        } catch (Exception ex) {
            System.out.println("Error en la conexion con el SAP:" + ex);
            JOptionPane.showMessageDialog(null, "Error en la conexion con el SAP:" + ex);
        }
    }

    public void llamarSoapDocumento1(RequestTransaction rq) {
        System.setProperty("javax.net.ssl.keyStore", "cacerts");
        System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
        System.setProperty("javax.net.ssl.trustStore", "cacerts");
        try { // Call Web Service Operation(async. callback)
            if (rq != null) {
                mx.com.fact.schema.ws.FactWSFront service = new mx.com.fact.schema.ws.FactWSFront();
                mx.com.fact.schema.ws.FactWSFrontSoap port = service.getFactWSFrontSoap();

                // TODO initialize WS operation arguments here
                java.lang.String requestor = rq.getRequestor();
                java.lang.String transaction = rq.getTransaction();
                java.lang.String country = rq.getCountry();
                java.lang.String entity = rq.getEntity();
                java.lang.String userSAP = rq.getUser();
                java.lang.String userName = rq.getUserName();
                java.lang.String data1 = rq.getData1();
                java.lang.String data2 = rq.getData2();
                java.lang.String data3 = rq.getData3();
                javax.xml.ws.AsyncHandler<mx.com.fact.schema.ws.RequestTransactionResponse> asyncHandler = new javax.xml.ws.AsyncHandler<mx.com.fact.schema.ws.RequestTransactionResponse>() {
                    public void handleResponse(
                            final javax.xml.ws.Response<mx.com.fact.schema.ws.RequestTransactionResponse> response) {
                        try {
                            // TODO process asynchronous response here
                            RequestTransactionResponse rtr = response.get();
                            if (rtr.getRequestTransactionResult().getResponse().isResult() == true)//la transaccion se genero
                            {
                                String serie = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getBatch();
                                String folio = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getSerial();
                                String UUID = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getDocumentGUID();
                                XMLGregorianCalendar fecha_ingreso = rtr.getRequestTransactionResult().getResponse()
                                        .getTimeStamp();
                                String nombre = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getSuggestedFileName2();
                                h = new Herramientas(user, 0);
                                h.session(sessionPrograma);
                                if (factura != null) {
                                    Session session = HibernateUtil.getSessionFactory().openSession();
                                    try {
                                        session.beginTransaction().begin();
                                        factura = (Factura) session.get(Factura.class, factura.getIdFactura());

                                        //Datos de timbrado
                                        factura.setEstadoFactura("Facturado");
                                        factura.setFFiscal(UUID);
                                        factura.setFechaFiscal(fecha_ingreso.toXMLFormat());
                                        factura.setSerie(serie);
                                        factura.setFolio(folio);
                                        factura.setNombreDocumento(nombre);
                                        session.update(factura);
                                        session.beginTransaction().commit();

                                        if (rtr.getRequestTransactionResult().getResponseData().getResponseData1()
                                                .compareTo("") != 0) {
                                            rtr.getRequestTransactionResult().getResponse().getIdentifier();
                                            CodeBase64 codificador = new CodeBase64();
                                            codificador.DecodeBase64(
                                                    rtr.getRequestTransactionResult().getResponseData()
                                                            .getResponseData1(),
                                                    "xml-timbrados/" + nombre + ".xml");
                                        }
                                        if (rtr.getRequestTransactionResult().getResponseData().getResponseData3()
                                                .compareTo("") != 0) {
                                            rtr.getRequestTransactionResult().getResponse().getIdentifier();
                                            CodeBase64 codificador = new CodeBase64();
                                            codificador.DecodeBase64(
                                                    rtr.getRequestTransactionResult().getResponseData()
                                                            .getResponseData3(),
                                                    "xml-timbrados/" + nombre + ".pdf");
                                        }
                                        try {
                                            File xml;
                                            if (abrir.compareTo("xml") == 0)
                                                xml = new File("xml-timbrados/" + nombre + ".xml");
                                            else
                                                xml = new File("xml-timbrados/" + nombre + ".pdf");
                                            Desktop.getDesktop().open(xml);
                                            habilita2(true);
                                            progreso.setString("Listo");
                                            progreso.setIndeterminate(false);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            habilita2(true);
                                            progreso.setString("Listo");
                                            progreso.setIndeterminate(false);
                                            JOptionPane.showMessageDialog(null, "Error al abrir el archivo xml");
                                        }
                                    } catch (Exception e) {
                                        session.beginTransaction().rollback();
                                        e.printStackTrace();
                                        habilita2(true);
                                        progreso.setString("Listo");
                                        progreso.setIndeterminate(false);
                                        JOptionPane.showMessageDialog(null, "Error al almacenar los datos");
                                    } finally {
                                        if (session != null)
                                            if (session.isOpen())
                                                session.close();
                                    }
                                } else {
                                    habilita2(true);
                                    progreso.setString("Listo");
                                    progreso.setIndeterminate(false);
                                }
                            } else {
                                try {
                                    String fecha = rtr.getRequestTransactionResult().getResponse().getTimeStamp()
                                            .toXMLFormat();
                                    Calendar calendario = Calendar.getInstance();
                                    File f = new File("errores/" + sdf.format(calendario.getTime()) + ".txt");
                                    FileWriter w = new FileWriter(f);
                                    BufferedWriter bw = new BufferedWriter(w);
                                    PrintWriter wr = new PrintWriter(bw);
                                    wr.write(rtr.getRequestTransactionResult().getResponse().getDescription());
                                    wr.write(rtr.getRequestTransactionResult().getResponse().getHint());
                                    wr.write(rtr.getRequestTransactionResult().getResponse().getData());
                                    wr.close();
                                    bw.close();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                habilita2(true);
                                progreso.setString("Listo");
                                progreso.setIndeterminate(false);
                                JOptionPane.showMessageDialog(null, "Error al consultar la factura:"
                                        + rtr.getRequestTransactionResult().getResponse().getDescription());
                            }
                        } catch (Exception ex) {
                            System.out.println("Error en la conexion con el SAP:" + ex);
                            habilita2(true);
                            progreso.setString("Listo");
                            progreso.setIndeterminate(false);
                            JOptionPane.showMessageDialog(null, "Error en la conexion con el SAP:" + ex);
                        }
                    }
                };
                java.util.concurrent.Future<? extends java.lang.Object> result = port.requestTransactionAsync(
                        requestor, transaction, country, entity, userSAP, userName, data1, data2, data3,
                        asyncHandler);
                /*while(!result.isDone())
                {
                Thread.sleep(100);
                }*/
            } else {
                habilita2(true);
                progreso.setString("Listo");
                progreso.setIndeterminate(false);
            }
        } catch (Exception ex) {
            System.out.println("Error en la conexion con el SAP:" + ex);
            habilita2(true);
            progreso.setString("Listo");
            progreso.setIndeterminate(false);
            JOptionPane.showMessageDialog(null, "Error en la conexion con el SAP:" + ex);
        }
    }

    public void llamarSoapTimbra(RequestTransaction rq) {
        System.setProperty("javax.net.ssl.keyStore", "cacerts");
        System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
        System.setProperty("javax.net.ssl.trustStore", "cacerts");
        try { // Call Web Service Operation(async. callback)
            if (rq != null) {
                mx.com.fact.schema.ws.FactWSFront service = new mx.com.fact.schema.ws.FactWSFront();
                mx.com.fact.schema.ws.FactWSFrontSoap port = service.getFactWSFrontSoap();

                // TODO initialize WS operation arguments here
                java.lang.String requestor = rq.getRequestor();
                java.lang.String transaction = rq.getTransaction();
                java.lang.String country = rq.getCountry();
                java.lang.String entity = rq.getEntity();
                java.lang.String userSAP = rq.getUser();
                java.lang.String userName = rq.getUserName();
                java.lang.String data1 = rq.getData1();
                java.lang.String data2 = rq.getData2();
                java.lang.String data3 = rq.getData3();
                javax.xml.ws.AsyncHandler<mx.com.fact.schema.ws.RequestTransactionResponse> asyncHandler = new javax.xml.ws.AsyncHandler<mx.com.fact.schema.ws.RequestTransactionResponse>() {
                    public void handleResponse(
                            final javax.xml.ws.Response<mx.com.fact.schema.ws.RequestTransactionResponse> response) {
                        try {
                            // TODO process asynchronous response here
                            RequestTransactionResponse rtr = response.get();
                            if (rtr.getRequestTransactionResult().getResponse().isResult() == true)//la transaccion se genero
                            {
                                String serie = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getBatch();
                                String folio = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getSerial();
                                String UUID = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getDocumentGUID();
                                XMLGregorianCalendar fecha_ingreso = rtr.getRequestTransactionResult().getResponse()
                                        .getTimeStamp();
                                String nombre = rtr.getRequestTransactionResult().getResponse().getIdentifier()
                                        .getSuggestedFileName();
                                if (factura != null) {
                                    Session session = HibernateUtil.getSessionFactory().openSession();
                                    try {
                                        session.beginTransaction().begin();
                                        factura = (Factura) session.get(Factura.class, factura.getIdFactura());

                                        //Datos de timbrado
                                        factura.setEstadoFactura("Facturado");
                                        factura.setEstatus("POR COBRAR");
                                        factura.setFFiscal(UUID);
                                        factura.setFechaFiscal(fecha_ingreso.toXMLFormat());
                                        factura.setSerie(serie);
                                        factura.setFolio(folio);
                                        factura.setNombreDocumento(nombre);
                                        session.update(factura);
                                        session.beginTransaction().commit();

                                        if (rtr.getRequestTransactionResult().getResponseData().getResponseData1()
                                                .compareTo("") != 0) {
                                            rtr.getRequestTransactionResult().getResponse().getIdentifier();
                                            CodeBase64 codificador = new CodeBase64();
                                            codificador.DecodeBase64(
                                                    rtr.getRequestTransactionResult().getResponseData()
                                                            .getResponseData1(),
                                                    "xml-timbrados/" + nombre + ".xml");
                                        }
                                        if (rtr.getRequestTransactionResult().getResponseData().getResponseData3()
                                                .compareTo("") != 0) {
                                            rtr.getRequestTransactionResult().getResponse().getIdentifier();
                                            CodeBase64 codificador = new CodeBase64();
                                            codificador.DecodeBase64(
                                                    rtr.getRequestTransactionResult().getResponseData()
                                                            .getResponseData3(),
                                                    "xml-timbrados/" + nombre + ".pdf");
                                        }
                                        habilita(true, false);
                                        progreso.setString("Listo");
                                        progreso.setIndeterminate(false);
                                        guarda();
                                        consulta();
                                    } catch (Exception e) {
                                        session.beginTransaction().rollback();
                                        e.printStackTrace();
                                        habilita(true, false);
                                        progreso.setString("Listo");
                                        progreso.setIndeterminate(false);
                                        JOptionPane.showMessageDialog(null, "Error al almacenar los datos:" + e);
                                    } finally {
                                        if (session != null)
                                            if (session.isOpen())
                                                session.close();
                                    }
                                } else {
                                    habilita(true, false);
                                    progreso.setString("Listo");
                                    progreso.setIndeterminate(false);
                                }
                            } else {
                                try {
                                    String fecha = rtr.getRequestTransactionResult().getResponse().getTimeStamp()
                                            .toXMLFormat();
                                    Calendar calendario = Calendar.getInstance();
                                    File f = new File("errores/" + sdf.format(calendario.getTime()) + ".txt");
                                    FileWriter w = new FileWriter(f);
                                    BufferedWriter bw = new BufferedWriter(w);
                                    PrintWriter wr = new PrintWriter(bw);
                                    wr.write(rtr.getRequestTransactionResult().getResponse().getDescription());
                                    wr.write(rtr.getRequestTransactionResult().getResponse().getHint());
                                    wr.write(rtr.getRequestTransactionResult().getResponse().getData());
                                    wr.close();
                                    bw.close();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    habilita(true, false);
                                    progreso.setString("Listo");
                                    progreso.setIndeterminate(false);
                                    JOptionPane.showMessageDialog(null,
                                            "Error en laguardar archivo de error: " + e);
                                }
                                habilita(true, false);
                                progreso.setString("Listo");
                                progreso.setIndeterminate(false);
                                JOptionPane.showMessageDialog(null, "Error al timbrar la factura:"
                                        + rtr.getRequestTransactionResult().getResponse().getDescription());
                            }
                        } catch (Exception ex) {
                            habilita(true, false);
                            progreso.setString("Listo");
                            progreso.setIndeterminate(false);
                            JOptionPane.showMessageDialog(null, "Error en la conexion con el SAP: " + ex);
                        }
                    }
                };
                java.util.concurrent.Future<? extends java.lang.Object> result = port.requestTransactionAsync(
                        requestor, transaction, country, entity, userSAP, userName, data1, data2, data3,
                        asyncHandler);
                /*while(!result.isDone())
                {
                Thread.sleep(100);
                }*/
            } else {
                habilita(true, false);
                progreso.setString("Listo");
                progreso.setIndeterminate(false);
            }
        } catch (Exception ex) {
            System.out.println("Error en la conexion con el SAP:" + ex);
            habilita(true, false);
            progreso.setString("Listo");
            progreso.setIndeterminate(false);
            JOptionPane.showMessageDialog(null, "Error en la conexion con el SAP:" + ex);
        }
    }

    public boolean llamarSoapConsulta(final RequestTransaction rq) {
        System.setProperty("javax.net.ssl.keyStore", "cacerts");
        System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
        System.setProperty("javax.net.ssl.trustStore", "cacerts");
        if (rq != null) {
            mx.com.fact.schema.ws.FactWSFront service = new mx.com.fact.schema.ws.FactWSFront();
            mx.com.fact.schema.ws.FactWSFrontSoap port = service.getFactWSFrontSoap();

            // TODO initialize WS operation arguments here
            java.lang.String requestor = rq.getRequestor();
            java.lang.String transaction = rq.getTransaction();
            java.lang.String country = rq.getCountry();
            java.lang.String entity = rq.getEntity();
            java.lang.String userSAP = rq.getUser();
            java.lang.String userName = rq.getUserName();
            java.lang.String data1 = rq.getData1();
            java.lang.String data2 = rq.getData2();
            java.lang.String data3 = rq.getData3();
            javax.xml.ws.AsyncHandler<mx.com.fact.schema.ws.RequestTransactionResponse> asyncHandler = new javax.xml.ws.AsyncHandler<mx.com.fact.schema.ws.RequestTransactionResponse>() {
                public final List error = new ArrayList();

                @Override
                public void handleResponse(
                        final javax.xml.ws.Response<mx.com.fact.schema.ws.RequestTransactionResponse> response) {
                    Session session = HibernateUtil.getSessionFactory().openSession();
                    try {
                        // TODO process asynchronous response here
                        session.beginTransaction().begin();
                        factura = (Factura) session.get(Factura.class, factura.getIdFactura());
                        RequestTransactionResponse rtr = response.get();
                        String numero = rtr.getRequestTransactionResult().getResponseData().getResponseData1();
                        if (numero.compareTo("") != 0) {
                            if (Integer.parseInt(numero) > 0) {
                                if (rtr.getRequestTransactionResult().getResponseData().getResponseData1()
                                        .compareTo("") != 0) {
                                    Random rng = new Random();
                                    long dig8 = rng.nextInt(90000000) + 10000000;
                                    rtr.getRequestTransactionResult().getResponse().getIdentifier();
                                    CodeBase64 codificador = new CodeBase64();
                                    boolean respuesta = codificador.DecodeBase64(
                                            rtr.getRequestTransactionResult().getResponseData().getResponseData2(),
                                            "xml-consulta/" + dig8 + ".xml");
                                    if (respuesta == true) {
                                        try {
                                            File fXmlFile = new File("xml-consulta/" + dig8 + ".xml");
                                            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                                            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                                            Document doc = dBuilder.parse(fXmlFile);
                                            //optional, but recommended
                                            //read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
                                            doc.getDocumentElement().normalize();
                                            NodeList nList = doc.getElementsByTagName("doc");
                                            DefaultTableModel modelo = ModeloTablaFactura(0, columnas1);
                                            for (int temp = 0; temp < nList.getLength(); temp++) {
                                                Node nNode = nList.item(temp);
                                                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                                                    Element eElement = (Element) nNode;
                                                    if (eElement.getElementsByTagName("cancelled").item(0)
                                                            .getTextContent().compareTo("") == 0) {
                                                        modelo.addRow(new Object[] {
                                                                eElement.getElementsByTagName("taxId").item(0)
                                                                        .getTextContent(),
                                                                eElement.getElementsByTagName("uuid").item(0)
                                                                        .getTextContent(),
                                                                eElement.getElementsByTagName("branch").item(0)
                                                                        .getTextContent(),
                                                                eElement.getElementsByTagName("batch").item(0)
                                                                        .getTextContent(),
                                                                eElement.getElementsByTagName("serial").item(0)
                                                                        .getTextContent(),
                                                                eElement.getElementsByTagName("issued").item(0)
                                                                        .getTextContent(),
                                                                Double.parseDouble(
                                                                        eElement.getElementsByTagName("total")
                                                                                .item(0).getTextContent()),
                                                                eElement.getElementsByTagName("currency").item(0)
                                                                        .getTextContent() });
                                                    }
                                                }
                                            }
                                            t_facturas.setModel(modelo);
                                            if (t_facturas.getRowCount() == 1)//hay una factura ya generada guardamos los datos en la orden
                                            {
                                                factura.setSerie(t_facturas.getValueAt(0, 3).toString());
                                                factura.setFolio(t_facturas.getValueAt(0, 4).toString());
                                                factura.setFFiscal(t_facturas.getValueAt(0, 1).toString());
                                                factura.setFechaFiscal(t_facturas.getValueAt(0, 5).toString());
                                                factura.setNombreDocumento(t_facturas.getValueAt(0, 0).toString()
                                                        + "_" + t_facturas.getValueAt(0, 3).toString() + "_"
                                                        + t_facturas.getValueAt(0, 4).toString() + "_"
                                                        + t_rfc.getText());
                                                factura.setEstadoFactura("Facturado");
                                                factura.setEstatus("POR COBRAR");
                                                session.update(factura);
                                                session.beginTransaction().commit();
                                                if (session.isOpen())
                                                    session.close();
                                                habilita(true, false);
                                                progreso.setString("Listo");
                                                progreso.setIndeterminate(false);
                                                JOptionPane.showMessageDialog(null,
                                                        "se encontro un registro y se importo la informacin");
                                                guarda();
                                                consulta();
                                            } else//hay mas de 1 factura para el folio enterno
                                            {
                                                habilita(true, false);
                                                progreso.setString("Listo");
                                                progreso.setIndeterminate(false);
                                                formatoTablafactura();
                                                javax.swing.JDialog consulta1 = new javax.swing.JDialog(AXA.this,
                                                        true);
                                                consulta1.setModalityType(
                                                        java.awt.Dialog.ModalityType.DOCUMENT_MODAL);
                                                consulta1.getContentPane().add(jLabel43,
                                                        java.awt.BorderLayout.PAGE_START);
                                                consulta1.getContentPane().add(jScrollPane2,
                                                        java.awt.BorderLayout.CENTER);
                                                consulta1.getContentPane().add(jPanel15,
                                                        java.awt.BorderLayout.PAGE_END);
                                                consulta1.setSize(861, 326);
                                                Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                                                consulta1.setLocation((d.width / 2) - (consulta1.getWidth() / 2),
                                                        (d.height / 2) - (consulta1.getHeight() / 2));
                                                consulta1.setVisible(true);
                                            }
                                        } catch (Exception e) {
                                            habilita(true, false);
                                            progreso.setString("Listo");
                                            progreso.setIndeterminate(false);
                                            JOptionPane.showMessageDialog(null, "Se encontraron " + numero
                                                    + " facturas pero no fue posible leer el xml " + e);
                                        }
                                    } else {
                                        habilita(true, false);
                                        progreso.setString("Listo");
                                        progreso.setIndeterminate(false);
                                        JOptionPane.showMessageDialog(null, "Se encontraron " + numero
                                                + " facturas pero no fue posible decodificar el xml");
                                    }
                                } else {
                                    habilita(true, false);
                                    progreso.setString("Listo");
                                    progreso.setIndeterminate(false);
                                    JOptionPane.showMessageDialog(null, "Se encontraron " + numero
                                            + " facturas pero no fue posible descargar el xml");
                                }
                            } else {
                                CodeBase64 codificador = new CodeBase64();
                                int numeroID = 0;
                                if (factura.getOrden() != null)
                                    numeroID = factura.getOrden().getIdOrden();
                                if (factura.getOrdenExterna() != null)
                                    numeroID = factura.getOrdenExterna().getIdOrden();
                                String cadenaCodificada = codificador
                                        .EncodeArchivo(new File("nativos/" + numeroID + "nativo.xml"));
                                if (cadenaCodificada.compareTo("") != 0) {
                                    //Configuracion config=(Configuracion)session.get(Configuracion.class, 1);
                                    RequestTransaction rq1 = new RequestTransaction();
                                    rq1.setRequestor(rq.getRequestor());//Lo proporcionar MySuite
                                    rq1.setTransaction("CONVERT_NATIVE_XML");//Tipo de Transaccion
                                    rq1.setCountry("MX");//Codigo de pais
                                    rq1.setUser(rq.getUser());//igual que Requestor
                                    rq1.setUserName(rq.getUserName());//Country.Entity.nombre_usuario
                                    rq1.setEntity(rq.getEntity());
                                    rq1.setData1(cadenaCodificada);//XML del CFDI a timbrar (no puede contener addendas ni timbre, y CFDI codificado en base 64).
                                    rq1.setData2("PDF XML");//Vaco
                                    rq1.setData3("");//Vaco
                                    if (session.isOpen())
                                        session.close();
                                    llamarSoapTimbra(rq1);
                                } else {
                                    habilita(true, false);
                                    progreso.setString("Listo");
                                    progreso.setIndeterminate(false);
                                    JOptionPane.showMessageDialog(null, "Error al codificar la cadena a Base 64");
                                }
                            }
                        } else {
                            habilita(true, false);
                            progreso.setString("Listo");
                            progreso.setIndeterminate(false);
                            JOptionPane.showMessageDialog(null, "Error al consultar la factura:"
                                    + rtr.getRequestTransactionResult().getResponse().getDescription());
                        }
                    } catch (InterruptedException ex) {
                        habilita(true, false);
                        progreso.setString("Listo");
                        progreso.setIndeterminate(false);
                        JOptionPane.showMessageDialog(null, "Error en la conexion con el SAP:" + ex);
                    } catch (NumberFormatException ex) {
                        habilita(true, false);
                        progreso.setString("Listo");
                        progreso.setIndeterminate(false);
                        JOptionPane.showMessageDialog(null, "Error al generar el archivo de error");
                    } catch (ExecutionException ex) {
                        habilita(true, false);
                        progreso.setString("Listo");
                        progreso.setIndeterminate(false);
                        JOptionPane.showMessageDialog(null, "Error al obtener la respuesta del SAP:" + ex);
                    } catch (HibernateException ex) {
                        habilita(true, false);
                        progreso.setString("Listo");
                        progreso.setIndeterminate(false);
                        JOptionPane.showMessageDialog(null, "Error al leer la base de datos");
                    } finally {
                        if (session != null)
                            if (session.isOpen())
                                session.close();
                    }
                }
            };
            java.util.concurrent.Future<? extends java.lang.Object> result = port.requestTransactionAsync(requestor,
                    transaction, country, entity, userSAP, userName, data1, data2, data3, asyncHandler);
            /*while(!result.isDone())
            {
            Thread.sleep(100);
            }*/
        }
        return true;
    }

    private void doClose(Factura o) {
        returnStatus = o;
        setVisible(false);
        //dispose();
    }

    public Factura getReturnStatus() {
        return returnStatus;
    }

    public void facturaElectronica() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction().begin();
            factura = (Factura) session.get(Factura.class, factura.getIdFactura());
            int numeroID = 0;
            if (factura.getOrden() != null)
                numeroID = factura.getOrden().getIdOrden();
            if (factura.getOrdenExterna() != null)
                numeroID = factura.getOrdenExterna().getIdOrden();
            if (generarXML(factura.getOrden(), "nativos/" + numeroID + "nativo.xml") == true) {
                Configuracion config = (Configuracion) session.get(Configuracion.class, 1);
                RequestTransaction rq = new RequestTransaction();
                rq.setRequestor(config.getRequestor());//Lo proporcionar MySuite
                rq.setTransaction("LOOKUP_ISSUED_INTERNAL_ID");//Tipo de Transaccion
                rq.setCountry("MX");//Codigo de pais
                rq.setUser(config.getRequestor());//igual que Requestor
                rq.setUserName(config.getUsuario_1());//Country.Entity.nombre_usuario
                rq.setEntity(config.getRfc());
                rq.setData1(t_codigo.getText());//XML del CFDI a timbrar (no puede contener addendas ni timbre, y CFDI codificado en base 64).
                rq.setData2(config.getSucursal());//Vaco
                rq.setData3("");//Vaco
                if (session.isOpen())
                    session.close();
                llamarSoapConsulta(rq);
            } else {
                habilita(true, false);
                progreso.setString("Listo");
                progreso.setIndeterminate(false);
                JOptionPane.showMessageDialog(null, "Error al generar el XML.-" + error);
            }
        } catch (Exception e) {
            habilita(true, false);
            progreso.setString("Listo");
            progreso.setIndeterminate(false);
            JOptionPane.showMessageDialog(null, "Error al Abrir el archivo de configuracin");
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
        }
    }

    public int existe(TDescuentosYRecargos descuentos, TDiscountOrRecharge aux) {
        for (int rec = 0; rec < descuentos.getDescuentoORecargo().size(); rec++) {
            if (descuentos.getDescuentoORecargo().get(rec).getOperacion().value()
                    .compareTo(aux.getOperacion().value()) == 0
                    && descuentos.getDescuentoORecargo().get(rec).getTasa().setScale(2, BigDecimal.ROUND_HALF_UP)
                            .doubleValue() == aux.getTasa().setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()) {
                return rec;
            }
        }
        return -1;
    }

    public void habilita2(boolean edo) {
        t_facturas.setEnabled(edo);
        b_cancelar.setEnabled(edo);
        b_descargar.setEnabled(edo);
    }

    public String guarda() {
        String respuesta = "";
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction().begin();
            factura = (Factura) session.get(Factura.class, factura.getIdFactura());

            //Receptor
            factura.setNombreReceptor(t_social.getText().trim());
            factura.setRfcReceptor(t_rfc.getText().trim());
            factura.setCalleReceptor(t_calle.getText().trim());
            factura.setNumeroExteriorReceptor(t_no_exterior.getText().trim());
            factura.setCpReceptor(t_cp.getText().trim());
            factura.setColoniaReceptor(t_colonia.getText().trim());
            factura.setMunicipioReceptor(t_municipio.getText().trim());
            if (c_estado.getSelectedIndex() != -1)
                factura.setEstadoReceptor(c_estado.getSelectedItem().toString());
            if (c_pais.getSelectedIndex() != -1)
                factura.setPaisReceptor(c_pais.getSelectedItem().toString());
            //Productos y servicios
            factura.setMetodoPago(t_metodo_pago.getText().trim());
            factura.setCuentaPago(t_cuenta_pago.getText().trim());
            factura.setFactorCambio(((Number) t_tipo_cambio.getValue()).doubleValue());
            if (c_moneda.getSelectedIndex() != -1)
                factura.setMoneda(c_moneda.getSelectedItem().toString());

            //Addenda  
            if (c_tipo_facturacion.getSelectedIndex() != -1)
                factura.setTipoFacturacion(c_tipo_facturacion.getSelectedItem().toString());
            factura.setTipoPoliza(t_tipo_poliza.getText().trim());
            factura.setRiEmosor(t_ri_emisor.getText().trim());
            factura.setContactoEmisor(t_nombre_emisor.getText().trim());
            factura.setCorreoEmisor(t_correo_emisor.getText().trim());
            factura.setTelefonoEmisor(t_tel_emisor.getText().trim());
            factura.setRiReceptor(t_ri_receptor.getText().trim());
            factura.setContactoReceptor(t_nombre_receptor.getText().trim());
            factura.setCorreoReceptor(t_correo_receptor.getText().trim());
            factura.setTelefonoReceptor(t_tel_receptor.getText().trim());
            factura.setProveedor(t_proveedor.getText().trim());
            factura.setCondicionesPago(t_condiciones.getText().trim());
            factura.setRiesgo(t_riesgo.getText().trim());
            factura.setAddenda("axa");
            factura.setIva(Integer.parseInt(t_iva1.getValue().toString()));
            session.update(factura);

            if (factura.getOrden() != null) {
                Orden ord = (Orden) session.get(Orden.class, factura.getOrden().getIdOrden());
                ord.setPoliza(t_numero.getText().trim());
                ord.setSiniestro(t_siniestro.getText().trim());
                ord.setDeducible(((Number) t_deducible.getValue()).doubleValue());
                ord.setModelo(Integer.parseInt(t_anio_vehiculo.getText()));
                ord.setNoSerie(t_serie_vehiculo.getText().trim());
                ord.setNoPlacas(t_placas_vehiculo.getText().trim());
                ord.setNoMotor(t_motor_vehiculo.getText().trim());
                ord.setInciso(t_inciso.getText().trim());
                session.update(ord);
            }

            if (factura.getOrdenExterna() != null) {
                OrdenExterna ordE = (OrdenExterna) session.get(OrdenExterna.class,
                        factura.getOrdenExterna().getIdOrden());
                ordE.setPoliza(t_numero.getText().trim());
                ordE.setSiniestro(t_siniestro.getText().trim());
                ordE.setDeducible(((Number) t_deducible.getValue()).doubleValue());
                if (t_anio_vehiculo.getText().trim().compareTo("") != 0)
                    ordE.setModelo(Integer.parseInt(t_anio_vehiculo.getText()));
                ordE.setNoSerie(t_serie_vehiculo.getText().trim());
                ordE.setNoPlacas(t_placas_vehiculo.getText().trim());
                ordE.setNoMotor(t_motor_vehiculo.getText().trim());
                ordE.setInciso(t_inciso.getText().trim());
                session.update(ordE);
            }

            session.beginTransaction().commit();
        } catch (Exception e) {
            session.beginTransaction().rollback();
            e.printStackTrace();
            respuesta = "Error al almacenar los datos";
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
        }
        return respuesta;
    }
}