com.app.mantenimiento.Comprobantes.java Source code

Java tutorial

Introduction

Here is the source code for com.app.mantenimiento.Comprobantes.java

Source

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

import com.entidades.Caja;
import com.entidades.MtComprobantes;
import com.entidades.MtTipoComprobantes;
import com.entidades.MtSucursales;
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import org.hibernate.HibernateException;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;
import org.hibernate.Query;
import org.hibernate.Session;
import util.FormatearFecha;
import util.HibernateUtil;
import com.app.seguridad.Permisos;

/**
 *
 * @author Carlos Patino
 */
public class Comprobantes extends javax.swing.JDialog {

    private String usuario;
    private String origen;
    private Session st;
    private String formulario;

    /**
     * Creates new form Comprobantes_1
     */
    public Comprobantes() {
        setLocationRelativeTo(null);
        initComponents();
        hibernateSession();
        this.cmdGuardar.setEnabled(false);
        arranque();
        this.usuario = "karu";
        this.formulario = "Comprobantes";
    }

    public Comprobantes(String user) {
        setLocationRelativeTo(null);
        initComponents();
        hibernateSession();
        usuario = user;
        this.formulario = this.getClass().getSimpleName();
        this.cmdGuardar.setEnabled(false);
        arranque();
    }

    private DefaultTableModel model;

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

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        cmdNuevo = new javax.swing.JButton();
        cmdGuardar = new javax.swing.JButton();
        cmdEditar = new javax.swing.JButton();
        cmdBorrar = new javax.swing.JButton();
        cmdCancelar = new javax.swing.JButton();
        cmdReporte = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        txtTribut = new javax.swing.JTextField();
        txtSuc = new javax.swing.JTextField();
        txtInicioLote = new javax.swing.JTextField();
        txtFinLote = new javax.swing.JTextField();
        txtNroDocum = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        chkEstado = new javax.swing.JCheckBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabComprobantes = new javax.swing.JTable();
        jSeparator1 = new javax.swing.JSeparator();
        cmdCerrar = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        txtTimbrado = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtSucursal = new javax.swing.JTextField();
        txtCaja = new javax.swing.JTextField();
        txtNroTrans = new javax.swing.JTextField();
        txtDescSucursal = new javax.swing.JTextField();
        txtDescCaja = new javax.swing.JTextField();
        txtVencimiento = new javax.swing.JTextField();
        cboTipo = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setTitle("Mantenimiento de Comprobantes - KARU SGCG v1.0");
        setMaximumSize(new java.awt.Dimension(704, 521));
        setMinimumSize(new java.awt.Dimension(704, 521));
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Mantenimiento de Comprobantes");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        cmdNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/imagenes/New.png"))); // NOI18N
        cmdNuevo.setToolTipText("Nuevo");
        cmdNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdNuevoActionPerformed(evt);
            }
        });

        cmdGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/imagenes/Save.png"))); // NOI18N
        cmdGuardar.setToolTipText("Guardar");
        cmdGuardar.setEnabled(false);
        cmdGuardar.setMaximumSize(new java.awt.Dimension(450, 510));
        cmdGuardar.setMinimumSize(new java.awt.Dimension(91, 33));
        cmdGuardar.setPreferredSize(new java.awt.Dimension(91, 33));
        cmdGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdGuardarActionPerformed(evt);
            }
        });

        cmdEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/imagenes/edit.png"))); // NOI18N
        cmdEditar.setToolTipText("Editar");
        cmdEditar.setMaximumSize(new java.awt.Dimension(91, 33));
        cmdEditar.setMinimumSize(new java.awt.Dimension(91, 33));
        cmdEditar.setPreferredSize(new java.awt.Dimension(91, 33));
        cmdEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdEditarActionPerformed(evt);
            }
        });

        cmdBorrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/imagenes/Trashcan_empty.png"))); // NOI18N
        cmdBorrar.setToolTipText("Borrar");
        cmdBorrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdBorrarActionPerformed(evt);
            }
        });

        cmdCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/imagenes/cancel32.png"))); // NOI18N
        cmdCancelar.setToolTipText("Cancelar");
        cmdCancelar.setEnabled(false);
        cmdCancelar.setMaximumSize(new java.awt.Dimension(91, 33));
        cmdCancelar.setMinimumSize(new java.awt.Dimension(91, 33));
        cmdCancelar.setPreferredSize(new java.awt.Dimension(91, 33));
        cmdCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdCancelarActionPerformed(evt);
            }
        });

        cmdReporte.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/imagenes/Tasks.png"))); // NOI18N
        cmdReporte.setToolTipText("Informe");
        cmdReporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdReporteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout
                .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                                .addComponent(cmdNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmdGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmdEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmdBorrar, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cmdCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(cmdReporte, javax.swing.GroupLayout.PREFERRED_SIZE, 35,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(cmdCancelar, javax.swing.GroupLayout.Alignment.LEADING,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                        .addComponent(cmdNuevo, javax.swing.GroupLayout.Alignment.LEADING,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                        .addComponent(cmdGuardar, javax.swing.GroupLayout.Alignment.LEADING,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                        .addComponent(cmdEditar, javax.swing.GroupLayout.Alignment.LEADING,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                        .addComponent(cmdBorrar, javax.swing.GroupLayout.Alignment.LEADING,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                        .addComponent(cmdReporte, javax.swing.GroupLayout.Alignment.LEADING,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE))
                        .addGap(0, 3, Short.MAX_VALUE)));

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Comprobante"));

        txtTribut.setEditable(false);
        txtTribut.setBackground(new java.awt.Color(255, 255, 255));
        txtTribut.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtTribut.setNextFocusableComponent(txtSuc);
        txtTribut.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTributKeyTyped(evt);
            }
        });

        txtSuc.setEditable(false);
        txtSuc.setBackground(new java.awt.Color(255, 255, 255));
        txtSuc.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtSuc.setNextFocusableComponent(txtInicioLote);
        txtSuc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSucActionPerformed(evt);
            }
        });
        txtSuc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtSucKeyTyped(evt);
            }
        });

        txtInicioLote.setEditable(false);
        txtInicioLote.setBackground(new java.awt.Color(255, 255, 255));
        txtInicioLote.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtInicioLote.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtInicioLoteKeyTyped(evt);
            }
        });

        txtFinLote.setEditable(false);
        txtFinLote.setBackground(new java.awt.Color(255, 255, 255));
        txtFinLote.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtFinLote.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtFinLoteKeyTyped(evt);
            }
        });

        txtNroDocum.setEditable(false);
        txtNroDocum.setBackground(new java.awt.Color(255, 255, 255));
        txtNroDocum.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtNroDocum.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNroDocumKeyTyped(evt);
            }
        });

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Actual");

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setText("Fin Lote");

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setText("Inicio Lote");

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel11.setText("Tribut.");

        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel12.setText("Suc.");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addGap(43, 43, 43)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtTribut, javax.swing.GroupLayout.PREFERRED_SIZE, 70,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtSuc, javax.swing.GroupLayout.PREFERRED_SIZE, 70,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtInicioLote, javax.swing.GroupLayout.PREFERRED_SIZE, 70,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(
                                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtFinLote).addComponent(jLabel9,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(
                                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtNroDocum).addComponent(jLabel3,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
                        .addGap(35, 35, 35)));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3).addComponent(jLabel9).addComponent(jLabel10)
                                .addComponent(jLabel11).addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txtTribut, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtSuc, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtInicioLote, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtFinLote, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtNroDocum, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Estado"));

        chkEstado.setText("Activo");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout
                .setHorizontalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap()
                                .addComponent(chkEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 64,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup().addGap(19, 19, 19).addComponent(chkEstado)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addGap(8, 8, 8)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(64, Short.MAX_VALUE)));
        jPanel2Layout
                .setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addContainerGap(13, Short.MAX_VALUE)));

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        tabComprobantes.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        tabComprobantes.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "Suc.", "Caja", "Tipo", "Cod. Tribut.", "Cod. Suc.", "Factura", "Inicio Lote", "Fin Lote",
                "Timbrado", "Vencimiento", "Activo", "Nro. Trans" }) {
            boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false, false, false,
                    false, false, false };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        tabComprobantes.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tabComprobantes.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tabComprobantes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabComprobantesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tabComprobantes);

        cmdCerrar.setText("Cerrar");
        cmdCerrar.setToolTipText("Cerrar");
        cmdCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdCerrarActionPerformed(evt);
            }
        });

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel6.setText("Caja");

        txtTimbrado.setEditable(false);
        txtTimbrado.setBackground(new java.awt.Color(255, 255, 255));
        txtTimbrado.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTimbradoKeyTyped(evt);
            }
        });

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel2.setText("Timbrado");

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("Vencimiento");

        txtSucursal.setEditable(false);
        txtSucursal.setBackground(new java.awt.Color(255, 255, 255));
        txtSucursal.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtSucursalFocusLost(evt);
            }
        });

        txtCaja.setEditable(false);
        txtCaja.setBackground(new java.awt.Color(255, 255, 255));
        txtCaja.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCajaFocusLost(evt);
            }
        });

        txtNroTrans.setEditable(false);
        txtNroTrans.setBackground(new java.awt.Color(204, 204, 204));
        txtNroTrans.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        txtNroTrans.setEnabled(false);

        txtDescSucursal.setEditable(false);
        txtDescSucursal.setBackground(new java.awt.Color(204, 204, 204));

        txtDescCaja.setEditable(false);
        txtDescCaja.setBackground(new java.awt.Color(204, 204, 204));

        txtVencimiento.setEditable(false);
        txtVencimiento.setBackground(new java.awt.Color(255, 255, 255));

        cboTipo.setEditable(true);
        cboTipo.setToolTipText("Tipo de Comprobante");
        cboTipo.setEnabled(false);
        cboTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboTipoActionPerformed(evt);
            }
        });

        jLabel4.setText("Tipo");

        jLabel5.setText("Sucursal");

        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, false)
                                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 57,
                                                Short.MAX_VALUE)
                                        .addComponent(
                                                jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout
                                                .createSequentialGroup()
                                                .addComponent(cboTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 140,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(82, 82, 82))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout
                                                .createSequentialGroup()
                                                .addComponent(txtSucursal, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(0, 0, 0).addComponent(txtDescSucursal,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 170,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 66,
                                                Short.MAX_VALUE))
                                .addGap(4, 4, 4)
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout
                                                .createSequentialGroup()
                                                .addComponent(txtCaja, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(0, 0, 0)
                                                .addComponent(txtDescCaja, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        180, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(txtNroTrans, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        10, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel5Layout.createSequentialGroup()
                                                .addComponent(txtTimbrado, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 80,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(10, 10, 10)
                                                .addComponent(txtVencimiento,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 80,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(14, 14, 14)))
                                .addContainerGap()));
        jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel5Layout.createSequentialGroup().addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtCaja, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel5Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(txtDescCaja, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(txtNroTrans, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        25, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(
                                                jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(jPanel5Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel4)
                                                .addGroup(jPanel5Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addGroup(jPanel5Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                        false)
                                                                .addComponent(txtVencimiento,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(jLabel8,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addGroup(jPanel5Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.BASELINE)
                                                                .addComponent(txtTimbrado,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(jLabel2))))
                                        .addGap(13, 13, 13))
                                .addGroup(jPanel5Layout.createSequentialGroup().addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(
                                                txtSucursal, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel5Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(txtDescSucursal,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGap(18, 18, 18).addComponent(cboTipo).addContainerGap()))));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addComponent(jSeparator1))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(cmdCerrar).addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(10, 10, 10)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(cmdCerrar)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

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

    private void cmdNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdNuevoActionPerformed
        Permisos per = new Permisos();
        Boolean inserto = per.PuedeInsertar(usuario, formulario);
        if (!inserto) {
            JOptionPane.showMessageDialog(null,
                    "El usuario " + usuario + " no tiene permiso para insertar" + " en el formulario " + formulario,
                    "Permisos", JOptionPane.INFORMATION_MESSAGE);
        } else {
            origen = "Nuevo";
            habilitarComponentes();
            arranque();
            inicializarCampos();
        }
    }//GEN-LAST:event_cmdNuevoActionPerformed

    private void cmdGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdGuardarActionPerformed
        guardar();
    }//GEN-LAST:event_cmdGuardarActionPerformed

    private void cmdEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdEditarActionPerformed
        Permisos per = new Permisos();
        Boolean edito = per.PuedeModificar(usuario, formulario);
        if (!edito) {
            JOptionPane.showMessageDialog(null,
                    "El usuario " + usuario + " no tiene permiso para editar" + " en el formulario " + formulario,
                    "Permisos", JOptionPane.INFORMATION_MESSAGE);
        } else {
            origen = "Editar";
            habilitarComponentes();
        }
    }//GEN-LAST:event_cmdEditarActionPerformed

    private void cmdBorrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdBorrarActionPerformed
        Permisos per = new Permisos();
        Boolean elimino = per.PuedeEliminar(usuario, formulario);
        if (!elimino) {
            JOptionPane.showMessageDialog(null,
                    "El usuario " + usuario + " no tiene permiso para eliminar" + " en el formulario " + formulario,
                    "Permisos", JOptionPane.INFORMATION_MESSAGE);
        } else {
            int showConfirmDialog = JOptionPane.showConfirmDialog(null, "Eliminacin de Registro",
                    "Desea eliminar este registro.", JOptionPane.YES_NO_OPTION);
            if (showConfirmDialog == 1) {
                JOptionPane.showMessageDialog(null, "Operacin cancelada.", "Mantenimiento de Comprobantes",
                        JOptionPane.INFORMATION_MESSAGE);
            } else {
                try {
                    st.beginTransaction();
                    int selectedRow = this.tabComprobantes.getSelectedRow();
                    Object valueAt = model.getValueAt(selectedRow, 11);
                    String nroTrans = valueAt.toString();
                    MtComprobantes registro = (MtComprobantes) st.load(MtComprobantes.class,
                            Integer.parseInt(nroTrans));
                    st.delete(registro);
                    st.getTransaction().commit();
                    JOptionPane.showMessageDialog(null, "Registro eliminado.", "Mantenimiento de Comprobantes",
                            JOptionPane.INFORMATION_MESSAGE);
                    arranque();
                } catch (HeadlessException | NumberFormatException | HibernateException ex) {
                    JOptionPane.showMessageDialog(null,
                            "Ocurri un error al eliminar el registro. " + ex.getMessage(),
                            "Mantenimiento de Comprobantes", JOptionPane.ERROR_MESSAGE);
                    st.getTransaction().rollback();
                }
            }
        }
    }//GEN-LAST:event_cmdBorrarActionPerformed

    private void cmdCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCancelarActionPerformed
        deshabilitarComponentes();
        arranque();
    }//GEN-LAST:event_cmdCancelarActionPerformed

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

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

    private void tabComprobantesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabComprobantesMouseClicked
        seleccionarItem();
    }//GEN-LAST:event_tabComprobantesMouseClicked

    private void cmdCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCerrarActionPerformed
        this.st.close();
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_cmdCerrarActionPerformed

    private void txtSucursalFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSucursalFocusLost
        desSucursal();
    }//GEN-LAST:event_txtSucursalFocusLost

    private void txtCajaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCajaFocusLost
        descCaja();
    }//GEN-LAST:event_txtCajaFocusLost

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

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

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

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

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

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

    private void cmdReporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdReporteActionPerformed
        informe();
    }//GEN-LAST:event_cmdReporteActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Comprobantes.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Comprobantes().setVisible(true);
            }
        });
    }

    private void hibernateSession() {
        this.st = HibernateUtil.getSessionFactory().openSession();
    }

    private void arranque() {
        tableModel();
        cargarTabla();
        cargarCombo();
    }

    public void tableModel() {
        model = (DefaultTableModel) this.tabComprobantes.getModel();
        model.setNumRows(0);
    }

    public void cargarTabla() {
        try {
            List<MtComprobantes> lista = (List<MtComprobantes>) st.createQuery("from MtComprobantes").list();
            for (MtComprobantes comList : lista) {
                model.addRow(new Object[] { comList.getMtSucursales().getCodSucursal(),
                        comList.getCaja().getCodCaja(), comList.getTipoDocum(), comList.getCodTribut(),
                        comList.getCodSucFac(), comList.getNroFactura(), comList.getInicioLote(),
                        comList.getFinLote(), comList.getTimbrado(), toString(comList.getVencimiento()),
                        comList.isEsActivo(), comList.getNroTrans() });
            }
        } catch (HibernateException ex) {
            JOptionPane.showMessageDialog(null, "Ocurrio un error al cargar la grilla. " + ex.getMessage(),
                    "Mantenimiento de Comprobantes_1", JOptionPane.ERROR_MESSAGE);
        }
    }

    public void guardar() {
        Date fechaMod = new Date();

        if ((this.cboTipo.getSelectedItem().toString().equals("FT")
                || this.cboTipo.getSelectedItem().toString().equals("NC"))
                && (this.txtTimbrado.getText().isEmpty() || this.txtVencimiento.getText().isEmpty())) {
            JOptionPane.showMessageDialog(null,
                    "Ingrese Timbrado y Fecha de Vencimiento para lote de comprobantes.",
                    "Mantenimiento de Comprobantes_1", JOptionPane.INFORMATION_MESSAGE);
            this.txtTimbrado.grabFocus();
        } else {
            if (this.txtSucursal.getText().isEmpty() || this.txtCaja.getText().isEmpty()) {
                JOptionPane.showMessageDialog(null, "Debe ingresar Sucursal y Caja.",
                        "Mantenimiento de Comprobantes", JOptionPane.INFORMATION_MESSAGE);
                this.txtSucursal.grabFocus();
            } else {
                if (this.txtFinLote.getText().isEmpty() || this.txtInicioLote.getText().isEmpty()
                        || this.txtNroDocum.getText().isEmpty() || this.txtSuc.getText().isEmpty()
                        || this.txtTribut.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(null,
                            "Verificar que todos los campos del Bloque Comprobantes contegan "
                                    + "valores y no espacios vacios.",
                            "Mantenimiento de Comprobantes", JOptionPane.INFORMATION_MESSAGE);
                    this.txtSucursal.grabFocus();
                } else {
                    // procede a la persistencia del registro.
                    if (this.origen.equals("Nuevo")) {
                        try {
                            st.beginTransaction();
                            MtComprobantes comp = new MtComprobantes();

                            comp.setNroTrans(obtenerNroTrans());
                            comp.setCodTribut(this.txtTribut.getText());
                            comp.setCodSucFac(this.txtSuc.getText());
                            comp.setNroFactura(Integer.parseInt(this.txtNroDocum.getText()));
                            comp.setCaja(obtenerCaja(this.txtCaja.getText()));
                            comp.setMtSucursales(obtenerSucursal(this.txtSucursal.getText()));
                            comp.setTimbrado(this.txtTimbrado.getText());
                            //comp.setVencimiento(toDate(this.txtVencimiento.getText().toString()));
                            try {
                                comp.setVencimiento(toDate(this.txtVencimiento.getText().toString()));
                            } catch (NullPointerException ex) {
                                comp.setVencimiento(null);
                            }
                            comp.setTipoDocum(this.cboTipo.getSelectedItem().toString());
                            comp.setEsActivo(this.chkEstado.isSelected());
                            comp.setInicioLote(Integer.parseInt(this.txtInicioLote.getText()));
                            comp.setFinLote(Integer.parseInt(this.txtFinLote.getText()));
                            comp.setFechaMod(fechaMod);
                            comp.setAccionMod(origen);
                            comp.setUsuarioMod(usuario);

                            st.save(comp);
                            st.getTransaction().commit();

                            JOptionPane.showMessageDialog(null, "El registro se guardo correctamente.",
                                    "Mantenimiento de Comprobantes", JOptionPane.INFORMATION_MESSAGE);
                            arranque();
                        } catch (HibernateException | NumberFormatException | HeadlessException ex) {
                            st.getTransaction().rollback();
                            JOptionPane.showMessageDialog(null, "Error al guardar registro. " + ex.getMessage(),
                                    "Mantenimiento de Comprobantes", JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        // procede a la persistencia del registro.
                        try {
                            st.beginTransaction();

                            FormatearFecha fecVenc = new FormatearFecha();
                            fecVenc.toDate(this.txtVencimiento.getText());

                            MtComprobantes comp = (MtComprobantes) st.load(MtComprobantes.class,
                                    Integer.parseInt(this.txtNroTrans.getText()));

                            comp.setCodTribut(this.txtTribut.getText());
                            comp.setCodSucFac(this.txtSuc.getText());
                            comp.setNroFactura(Integer.parseInt(this.txtNroDocum.getText()));
                            comp.setMtSucursales(obtenerSucursal(this.txtSucursal.getText()));
                            comp.setCaja(obtenerCaja(this.txtCaja.getText()));
                            comp.setTimbrado(this.txtTimbrado.getText());
                            //comp.setVencimiento(toDate(this.txtVencimiento.getText().toString()));
                            try {
                                comp.setVencimiento(toDate(this.txtVencimiento.getText().toString()));
                            } catch (NullPointerException ex) {
                                comp.setVencimiento(null);
                            }
                            comp.setTipoDocum(this.cboTipo.getSelectedItem().toString());
                            comp.setEsActivo(this.chkEstado.isSelected());
                            comp.setInicioLote(Integer.parseInt(this.txtInicioLote.getText()));
                            comp.setFinLote(Integer.parseInt(this.txtFinLote.getText()));
                            comp.setFechaMod(fechaMod);
                            comp.setAccionMod(origen);
                            comp.setUsuarioMod(usuario);

                            st.update(comp);
                            st.getTransaction().commit();
                            JOptionPane.showMessageDialog(null, "Artculo actualizado correctamente.",
                                    "Mantenimiento de Comprobantes", JOptionPane.INFORMATION_MESSAGE);
                            arranque();

                        } catch (HeadlessException | NumberFormatException | HibernateException ex) {
                            JOptionPane.showMessageDialog(null, "Error al guardar registro. " + ex.getMessage(),
                                    "Mantenimiento de Comprobantes", JOptionPane.INFORMATION_MESSAGE);
                            st.getTransaction().rollback();
                        }
                    }
                }
            }
        }
        deshabilitarComponentes();
    }

    private void seleccionarItem() {
        int selectedRow = this.tabComprobantes.getSelectedRow();
        Object tipo = model.getValueAt(selectedRow, 2);

        this.txtSucursal.setText(model.getValueAt(selectedRow, 0).toString());
        this.txtCaja.setText(model.getValueAt(selectedRow, 1).toString());
        cargarDesc();
        this.cboTipo.setSelectedItem(tipo.toString());
        this.txtTribut.setText(model.getValueAt(selectedRow, 3).toString());
        this.txtSuc.setText(model.getValueAt(selectedRow, 4).toString());
        this.txtNroDocum.setText(model.getValueAt(selectedRow, 5).toString());
        this.txtInicioLote.setText(model.getValueAt(selectedRow, 6).toString());
        this.txtFinLote.setText(model.getValueAt(selectedRow, 7).toString());
        try {
            this.txtTimbrado.setText(model.getValueAt(selectedRow, 8).toString());
        } catch (NullPointerException n) {
            this.txtTimbrado.setText("");
        }
        try {
            this.txtVencimiento.setText(model.getValueAt(selectedRow, 9).toString());
        } catch (NullPointerException ex) {
            this.txtVencimiento.setText("");
        }
        this.chkEstado.setSelected((boolean) model.getValueAt(selectedRow, 10));
        this.txtNroTrans.setText(model.getValueAt(selectedRow, 11).toString());
    }

    private int obtenerIndexTipo(String valor) {
        if (valor.equals("FT")) {
            return 0;
        }
        if (valor.equals("NC")) {
            return 1;
        }
        if (valor.equals("RE")) {
            return 2;
        }
        if (valor.equals("TK")) {
            return 3;
        }
        return 0;
    }

    public int obtenerNroTrans() {
        int cantidad = 0;
        try {
            Query query = st.createQuery("select max(d.nroTrans) from MtComprobantes d");
            cantidad = (int) query.uniqueResult();
        } catch (HibernateException ex) {
            JOptionPane.showMessageDialog(null, "Ocurrio un error al obtener el nro. trans. " + ex.getMessage(),
                    "Mantenimiento de Comprobantes", JOptionPane.ERROR_MESSAGE);
        }
        return (cantidad + 1);
    }

    public void cargarDesc() {
        desSucursal();
        descCaja();
    }

    public void descCaja() {
        try {
            Caja caja = (Caja) st.get(Caja.class, this.txtCaja.getText());
            if (caja == null) {
                JOptionPane.showMessageDialog(null, "Codigo de caja no existe.", "Mantenimiento de Comprobantes",
                        JOptionPane.INFORMATION_MESSAGE);
            } else {
                this.txtDescCaja.setText(caja.getNomCaja());
            }
        } catch (HibernateException ex) {
            JOptionPane.showMessageDialog(null,
                    "Ocurri un error al realizar consulta de Cajas." + ex.getMessage(),
                    "Mantenimiento de Comprobantes", JOptionPane.ERROR_MESSAGE);
        }
    }

    public void desSucursal() {
        try {
            MtSucursales sucursal = (MtSucursales) st.get(MtSucursales.class, this.txtSucursal.getText());
            if (sucursal == null) {
                JOptionPane.showMessageDialog(null, "Codigo de sucursal no existe.",
                        "Mantenimiento de Comprobantes", JOptionPane.INFORMATION_MESSAGE);
            } else {
                this.txtDescSucursal.setText(sucursal.getNomSucursal());
            }
        } catch (HibernateException ex) {
            JOptionPane.showMessageDialog(null,
                    "Ocurri un error realizar consulta de Sucursales. " + ex.getMessage(),
                    "Mantenimiento de Comprobantes", JOptionPane.ERROR_MESSAGE);
        }
    }

    public Caja obtenerCaja(String cod) {
        Caja caja = null;
        try {
            caja = (Caja) st.load(Caja.class, cod);
            if (caja == null) {
                JOptionPane.showMessageDialog(null, "Cdigo de caja buscado no existe. Intente de nuevo.",
                        "Mantenimiento de Cajeros", JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Ocurrio un error al realizar consulta. " + e.getMessage(),
                    "Mantenimiento de Cajeros", JOptionPane.ERROR_MESSAGE);
        }
        return caja;
    }

    public MtSucursales obtenerSucursal(String cod) {
        MtSucursales suc = null;
        try {
            suc = (MtSucursales) st.load(MtSucursales.class, cod);
            if (suc == null) {
                JOptionPane.showMessageDialog(null, "Cdigo de sucursal buscado no existe. Intente de nuevo.",
                        "Mantenimiento de Cajeros", JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Ocurrio un error al realizar consulta. " + e.getMessage(),
                    "Mantenimiento de Cajeros", JOptionPane.ERROR_MESSAGE);
        }
        return suc;
    }

    public void habilitarComponentes() {
        this.txtCaja.setEditable(true);
        this.txtFinLote.setEditable(true);
        this.txtInicioLote.setEditable(true);
        this.txtNroDocum.setEditable(true);
        this.txtSuc.setEditable(true);
        this.txtSucursal.setEditable(true);
        this.txtTimbrado.setEditable(true);
        this.txtTribut.setEditable(true);
        this.txtVencimiento.setEditable(true);

        this.cboTipo.setEnabled(true);
        this.tabComprobantes.setEnabled(false);

        this.cmdNuevo.setEnabled(false);
        this.cmdGuardar.setEnabled(true);
        this.cmdEditar.setEnabled(false);
        this.cmdCancelar.setEnabled(true);
        this.cmdBorrar.setEnabled(false);
    }

    public void deshabilitarComponentes() {
        this.txtCaja.setEditable(false);
        this.txtFinLote.setEditable(false);
        this.txtInicioLote.setEditable(false);
        this.txtNroDocum.setEditable(false);
        this.txtSuc.setEditable(false);
        this.txtSucursal.setEditable(false);
        this.txtTimbrado.setEditable(false);
        this.txtTribut.setEditable(false);
        this.txtVencimiento.setEditable(false);

        this.cboTipo.setEnabled(false);
        this.tabComprobantes.setEnabled(true);

        this.cmdNuevo.setEnabled(true);
        this.cmdGuardar.setEnabled(false);
        this.cmdEditar.setEnabled(true);
        this.cmdCancelar.setEnabled(false);
        this.cmdBorrar.setEnabled(true);
    }

    public void inicializarCampos() {
        this.txtSucursal.setText("");
        this.txtCaja.setText("");
        this.txtTimbrado.setText("");
        this.txtTribut.setText("");
        this.txtSuc.setText("");
        this.txtInicioLote.setText("");
        this.txtFinLote.setText("");
        this.txtNroDocum.setText("");
    }

    public Date toDate(String fechaStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

        Date date = new Date();
        try {
            //Hacemos la conversin con este procedimiento.
            if (fechaStr.equals("")) {
                date = null;
            } else {
                date = sdf.parse(fechaStr);
            }
        } catch (ParseException e) {
            JOptionPane.showMessageDialog(null, "Error de formato de fecha: " + e, "Conversion Fechas",
                    JOptionPane.ERROR_MESSAGE);
        }
        System.out.println("fecha convertida: " + date);
        return date;
    }

    public String toString(Date fechaDate) {
        String retorno = null;
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        try {
            if (fechaDate != null) {
                retorno = sdf.format(fechaDate);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Ocurrio un error al convertir fecha. " + ex.getMessage(),
                    "Conversion Fechas", JOptionPane.ERROR_MESSAGE);
        }
        return retorno;
    }

    public void informe() {
        try {
            Connection conexion;
            conexion = DriverManager.getConnection("jdbc:postgresql://localhost:5432/karu", "karu", "karu");

            JasperReport elReporte = (JasperReport) JRLoader
                    .loadObject(ClassLoader.getSystemResource("com/informes/Comprobantes_Lista.jasper"));
            JasperPrint imprimir = JasperFillManager.fillReport(elReporte, null, conexion);
            JasperViewer visor = new JasperViewer(imprimir, false);
            visor.setTitle("Listado de Comprobantes");
            visor.setVisible(true);
            conexion.close();
        } catch (SQLException | JRException e) {
            String mensajeEx = e.getMessage();
            JOptionPane.showMessageDialog(null, "Error al cargar reporte. " + mensajeEx);
        }
    }

    public void cargarCombo() {
        this.cboTipo.removeAllItems();
        List<MtTipoComprobantes> lista = (List<MtTipoComprobantes>) st.createQuery("From MtTipoComprobantes")
                .list();
        for (MtTipoComprobantes tipoList : lista) {
            this.cboTipo.addItem(tipoList.getCodComp());
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cboTipo;
    private javax.swing.JCheckBox chkEstado;
    private javax.swing.JButton cmdBorrar;
    private javax.swing.JButton cmdCancelar;
    private javax.swing.JButton cmdCerrar;
    private javax.swing.JButton cmdEditar;
    private javax.swing.JButton cmdGuardar;
    private javax.swing.JButton cmdNuevo;
    private javax.swing.JButton cmdReporte;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable tabComprobantes;
    private javax.swing.JTextField txtCaja;
    private javax.swing.JTextField txtDescCaja;
    private javax.swing.JTextField txtDescSucursal;
    private javax.swing.JTextField txtFinLote;
    private javax.swing.JTextField txtInicioLote;
    private javax.swing.JTextField txtNroDocum;
    private javax.swing.JTextField txtNroTrans;
    private javax.swing.JTextField txtSuc;
    private javax.swing.JTextField txtSucursal;
    private javax.swing.JTextField txtTimbrado;
    private javax.swing.JTextField txtTribut;
    private javax.swing.JTextField txtVencimiento;
    // End of variables declaration//GEN-END:variables
}