GUI.frameNewVentaKit.java Source code

Java tutorial

Introduction

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

import Clases.funciones;
import ObjetosDB.Cliente;
import ObjetosDB.Kitproductos;
import ObjetosDB.OrdenDeVenta;
import ObjetosDB.Productos;
import ObjetosDB.Promociones;
import ObjetosDB.VentaProducto;
import ObjetosDB.metodosDB;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.SwingWorker;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author tars
 */
public class frameNewVentaKit extends javax.swing.JFrame {
    private ArrayList<Productos> carroProductos = new ArrayList<ObjetosDB.Productos>();
    private ArrayList<Kitproductos> carroKits = new ArrayList<Kitproductos>();
    public Cliente cliente = null;
    public boolean clientesel = false;
    private javax.swing.JLabel jLabel20 = new JLabel();

    private ArrayList<Promociones> promos = null;
    public ArrayList<Productos> aux2a;
    DefaultTableModel modelo1 = new DefaultTableModel();
    String t3[] = { "ID", "PRODUCTO", "TALLA", "MARCA", "TIPO", "PROVEEDOR", "PRECIO VENTA", "COD." };
    private int montoDescuento = 0; //Poner descuento de la prmomocin aca porfavor.

    /**
     * Creates new form frameNewVenta
     */
    public frameNewVentaKit() throws SQLException {
        initComponents();
        jRadioButton1.setActionCommand("Tarjeta Dbito");
        jRadioButton2.setActionCommand("Efectivo");
        jRadioButton3.setActionCommand("Tarjeta Crdito");
        int cantidadpromos = 0;
        modelo1.setColumnIdentifiers(t3);
        jTable1.setModel(modelo1);
        this.getPromos();
        jLabel17.setText("-");
        jLabel20.setText("0");
        aux2a = new metodosDB().getProductos();
        final JPopupMenu popupMenu = new JPopupMenu();
        JMenuItem deleteItem = new JMenuItem("Informacin del Producto");

        deleteItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int id = -1;
                boolean error = false;
                try {
                    int s = jTable1.getSelectedRow();
                    id = (int) jTable1.getValueAt(s, 0);

                } catch (ArrayIndexOutOfBoundsException a) {
                    JOptionPane.showMessageDialog(rootPane, "Debe seleccionar un item de la tabla");
                    error = true;
                }
                if (error == false) {
                    try {
                        Productos p = new metodosDB().getProductoById(id);
                        frameDescripcionProducto freim = new frameDescripcionProducto(p);
                        freim.setVisible(true);
                    } catch (SQLException ex) {
                        JOptionPane.showMessageDialog(rootPane,
                                "Error en el producto / producto no existe en base de datos");
                    }
                }
            }

        });
        popupMenu.add(deleteItem);
        jTable1.setComponentPopupMenu(popupMenu);
    }

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

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jButton11 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton12 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel19 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton1 = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jButton9 = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Nueva Venta");
        setBackground(new java.awt.Color(0, 0, 0));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Kits / Productos",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP,
                new java.awt.Font("Tahoma", 0, 11), java.awt.Color.gray)); // NOI18N

        jButton11.setFont(new java.awt.Font("Arial Black", 0, 16)); // NOI18N
        jButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/search.png"))); // NOI18N
        jButton11.setText("Seleccionar Kit");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(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().addGap(30, 30, 30)
                                .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 225,
                                        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().addGap(60, 60, 60).addComponent(jButton11)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Resumen de Productos",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jTable1.setModel(
                new javax.swing.table.DefaultTableModel(
                        new Object[][] { { null, null, null, null }, { null, null, null, null },
                                { null, null, null, null }, { null, null, null, null } },
                        new String[] { "Title 1", "Title 2", "Title 3", "Title 4" }));
        jTable1.addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentAdded(java.awt.event.ContainerEvent evt) {
                jTable1ComponentAdded(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jButton12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/Transfer.png"))); // NOI18N
        jButton12.setText("Cambiar Kit");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE)
                .addGroup(jPanel3Layout
                        .createSequentialGroup().addContainerGap().addComponent(jButton12,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 137,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Resumen Caja",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION,
                new java.awt.Font("Tahoma", 0, 11), java.awt.Color.red)); // NOI18N

        jLabel3.setText("Total a Pagar ($):");

        jLabel4.setText("Monto Neto  Kit ($):");

        jLabel5.setText("I.V.A");

        jLabel6.setText("19%");

        jLabel7.setText("($):");

        jLabel19.setText("0");

        jLabel21.setText("0");

        jLabel22.setFont(new java.awt.Font("Droid Sans", 1, 24)); // NOI18N
        jLabel22.setText("0.-");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setSelected(true);
        jRadioButton2.setText("Efectivo");
        jRadioButton2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButton3);
        jRadioButton3.setText("Tarjeta Crdito");

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setText("Tarjeta Dbito");

        jLabel2.setText("Valor Sin Iva:");

        jLabel8.setText("0");

        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(37, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jRadioButton3)
                                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 193,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGroup(jPanel2Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel3).addComponent(jRadioButton2))
                                        .addGap(59, 59, 59).addComponent(jLabel22))
                                .addComponent(jRadioButton1)
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel2)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jLabel8))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout
                                                .createSequentialGroup().addComponent(jLabel5)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel6).addGap(18, 18, 18).addComponent(jLabel7)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jLabel21))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                jPanel2Layout.createSequentialGroup().addComponent(jLabel4)
                                                        .addGap(65, 65, 65).addComponent(jLabel19))))));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4).addComponent(jLabel19))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2).addComponent(jLabel8))
                        .addGap(22, 22, 22)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5).addComponent(jLabel6).addComponent(jLabel7)
                                .addComponent(jLabel21))
                        .addGap(2, 2, 2)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3).addComponent(jLabel22))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButton3)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jButton1.setBackground(new java.awt.Color(0, 255, 102));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/disk.png"))); // NOI18N
        jButton1.setText("Imprimir Boleta");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setBackground(new java.awt.Color(255, 51, 51));
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/delete.png"))); // NOI18N
        jButton3.setText("Cancelar Venta");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Identificacin del Cliente",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION,
                new java.awt.Font("Tahoma", 0, 11), java.awt.Color.blue)); // NOI18N

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/user_add.png.jpg"))); // NOI18N
        jButton7.setText("Registrar Cliente");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/user_green.png"))); // NOI18N
        jButton8.setText("Cargar Cliente");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jLabel9.setText("Nombre Cliente:");

        jLabel10.setText("Telefono:");

        jLabel11.setText("Email:");

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/zoom.png"))); // NOI18N
        jButton9.setText("Ver Historial de Compras");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jLabel13.setText("-");

        jLabel14.setText("-");

        jLabel15.setText("-");

        jLabel1.setText("ID:");

        jLabel17.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(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel5Layout.createSequentialGroup()
                                .addGroup(
                                        jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jButton7).addComponent(jLabel9).addComponent(jLabel10)
                                                .addComponent(jLabel11).addComponent(jLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel5Layout.createSequentialGroup().addGroup(jPanel5Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel13).addComponent(jLabel14)
                                                .addComponent(jLabel15)).addContainerGap(
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGroup(jPanel5Layout.createSequentialGroup().addGroup(jPanel5Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel17).addComponent(jButton8))
                                                .addGap(0, 0, Short.MAX_VALUE)))))));
        jPanel5Layout
                .setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel5Layout.createSequentialGroup()
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton8, 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.BASELINE)
                                        .addComponent(jLabel1).addComponent(jLabel17))
                                .addGap(3, 3, 3)
                                .addGroup(
                                        jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel13)
                                                .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(
                                        jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel10).addComponent(jLabel14))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(
                                        jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel11).addComponent(jLabel15))
                                .addGap(31, 31, 31).addComponent(jButton9)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/Export To Document.png"))); // NOI18N
        jButton2.setText("Cotizacin");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(39, 39, 39)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGap(18, 18, 18).addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createSequentialGroup().addGap(10, 10, 10)
                                                .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addGap(18, 18, 18).addComponent(jButton3)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 210,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addContainerGap(28, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(157, 157, 157)))));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton1).addComponent(jButton3).addComponent(jButton2,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

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

    public void calculaTotales(ArrayList<Productos> carroProductos) {
        int montoNeto = 0;
        int iva_pesos = 0;
        int iva_porcentaje = 19;
        int montoTotal = 0;
        int montosiniva = 0;
        for (int i = 0; i < carroProductos.size(); i++) {
            Productos producto = carroProductos.get(i);
            montoNeto += producto.getPrecioVenta();
            System.out.println(montoNeto + "\n");
        }
        montoDescuento = Integer.parseInt(jLabel20.getText());
        jLabel19.setText(Integer.toString(montoNeto));
        jLabel20.setText(Integer.toString(montoDescuento));
        int sumaPrevia = montoNeto - montoDescuento;
        iva_pesos = (sumaPrevia * iva_porcentaje) / 100;
        jLabel21.setText(Integer.toString(iva_pesos));
        montoTotal = montoNeto - montoDescuento;
        jLabel22.setText(Integer.toString(montoTotal));
        montosiniva = sumaPrevia - iva_pesos;
        jLabel8.setText(Integer.toString(montosiniva));
        System.out.println("ESTA ENTRANDO EL SIN IVA:");
        System.out.println(jLabel8.getText());

    }

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed

        frameNewCliente frameCliente = new frameNewCliente(jLabel15, jLabel13, jLabel14, jLabel17);
        frameCliente.setVisible(true);

    }//GEN-LAST:event_jButton7ActionPerformed

    private ArrayList<Promociones> getPromos() throws SQLException {

        metodosDB f = new metodosDB();
        promos = f.getPromociones();
        return promos;
    }

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        frameVentasHistoricasCliente historial = null;

        //SI NO HAY CLIENTE  seleccionado
        if (jLabel17.getText().equals("-")) {

            this.setCursor(Cursor.getDefaultCursor());
            int mnsj = JOptionPane.showConfirmDialog(null, "DEBE SELECCIONAR UN CLIENTE", "ERROR",
                    JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);
            return;
        } else {

            try {
                historial = new frameVentasHistoricasCliente(jLabel17.getText());
            } catch (SQLException ex) {
                Logger.getLogger(Framenewventa.class.getName()).log(Level.SEVERE, null, ex);
            }
            historial.setVisible(true);
        } //GEN-LAST:event_jButton9ActionPerformed
    }

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        cargarClientes cargarCliente = null;
        try {
            cargarCliente = new cargarClientes(jLabel13, jLabel14, jLabel15, null, jLabel17);
        } catch (SQLException ex) {
            Logger.getLogger(frameNewVentaKit.class.getName()).log(Level.SEVERE, null, ex);
        }
        cargarCliente.setVisible(true);
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jTable1ComponentAdded(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_jTable1ComponentAdded

        calculaTotales(this.carroProductos);
    }//GEN-LAST:event_jTable1ComponentAdded

    private String getFecha() {
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        Calendar cal = Calendar.getInstance();
        String FechaHoy = dateFormat.format(cal.getTime());
        return FechaHoy;
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        int idordenventa = 0;
        int montosiniva = 0;
        String FechaHoy = getFecha();
        int montoNeto = -1, iva = -1, totalPagar = -1, descuentoTotal = -1;
        boolean error = false;

        try {
            montoNeto = Integer.parseInt(jLabel19.getText());
            iva = Integer.parseInt(jLabel21.getText());
            ;
            descuentoTotal = Integer.parseInt(jLabel20.getText());
            ;
            totalPagar = Integer.parseInt(jLabel22.getText());
            montosiniva = totalPagar - iva;
            jLabel8.setText(Integer.toString(montosiniva));
            System.out.println("ESTA ENTRANDO EL SIN IVA:");
            System.out.println(jLabel8.getText());
        } catch (NumberFormatException a) {
            JOptionPane.showMessageDialog(rootPane, "Error Calculando Precios");
            error = true;
        }
        String nombre, codigo_barra, ordenVenta;
        int cantidad_vendida, precio_unitario_neto, precio_total_neto, descuento;
        float precio_unitario_final, precio_total_final;
        int numeroBoleta = -1, montoTotal = 0;
        String medio_pago = buttonGroup1.getSelection().getActionCommand();
        int estadoPresupuesto = 0; // 1-> venta, 0 -> presupuesto;
        ArrayList<VentaProducto> carroVentas;
        if (carroProductos.size() > 0) //si hay cosas para vender, vendemos
        {
            try {
                if (jLabel17.getText().equals("-"))
                    error = true;

                if (error == false)
                    this.cliente = new metodosDB().getClienteById(Integer.parseInt(jLabel17.getText()));

                if (this.cliente == null) {
                    jframe1 a = new jframe1();
                    JOptionPane.showMessageDialog(a, "Debe seleccionar un cliente".toUpperCase());
                    error = true;
                    return;
                }

                if (error == false) {

                    //obtenemos datos de clioente
                    String nombrec = this.cliente.getNombre();
                    String telefono = this.cliente.getTelefono();
                    String email = this.cliente.getEmail();
                    int rut = this.cliente.getIdCliente();
                    //datos de orden venta
                    numeroBoleta = new metodosDB().getLastId("Ordendeventa") + 1;
                    System.out.println("\n numero Boleta" + numeroBoleta);
                    //comprimimos array de carropdocutos
                    empaquetaProductos(this.carroProductos);
                    System.out.println("paqueteado");

                    //creamos array de ventas productos
                    carroVentas = creaVentaProducto(carroProductos, "producto", numeroBoleta);
                    System.out.println("carorventascreado");
                    //creamos orden de venta
                    OrdenDeVenta orden = new OrdenDeVenta(new metodosDB().getLastId("Ordendeventa"), getFecha(),
                            Integer.toString(totalPagar), numeroBoleta, medio_pago, estadoPresupuesto, cliente,
                            carroVentas);
                    System.out.println("cordenventacreado");
                    //Descontamos productos del inventario;
                    if (guardaVenta(orden) == false)
                        error = true;
                    if (error == false) {
                        JOptionPane.showMessageDialog(rootPane,
                                "Venta Generada Exitosamente, productos descontados de inventario");
                        descuentaInventario(carroProductos);
                        this.dispose();

                    } else {
                        JOptionPane.showMessageDialog(rootPane, "Ha ocurrido un error en la venta");
                    }

                } else {
                    JOptionPane.showMessageDialog(rootPane, "Debe seleccionar Cliente!");
                }

            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(rootPane, "Ha ocurrido un error en la base de datos");
            }
        } else {
            JOptionPane.showMessageDialog(rootPane, "No hay productos en el carrito!");

        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        if (jLabel17.getText().toString().equals("-")) {
            JOptionPane.showMessageDialog(rootPane, "DEBE SELECCIONAR UN CLIENTE");
        } else {

            try {
                setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

                funciones f = new funciones();
                String dia = (Calendar.getInstance().getTime().getDate() < 10)
                        ? "0" + Calendar.getInstance().getTime().getDate()
                        : Calendar.getInstance().getTime().getDate() + "";
                String mes = f.get_mesMay((Calendar.getInstance().getTime().getMonth() + 1));
                String anio = (Calendar.getInstance().getTime().getYear() + 1900) + "";

                String nombre = "COTIZACION TIENDA ULTIMO ROUND";
                String rut_socio = "";
                int mon = 0;
                String arch = Calendar.getInstance().getTimeInMillis() + "_" + nombre + ".pdf";
                DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
                Date date = new Date();
                String stringToEncrypt = nombre.trim() + dateFormat.format(date);

                int encryptedString = stringToEncrypt.trim().hashCode();
                String aRemplazar = Integer.toString(encryptedString);
                String remplazado = aRemplazar.replace("-", "");

                String url = f.getRutaCotizacion() + arch;
                FileOutputStream archivo = new FileOutputStream(url);

                int deuda = Integer.parseInt("1");

                String palabra = f.Convertir(deuda + "", false);

                palabra = palabra.substring(0, palabra.length() - 2);
                if (palabra.split(" ")[palabra.split(" ").length - 1].equals("millones")
                        | palabra.split(" ")[palabra.split(" ").length - 1].equals("milln")) {
                    palabra = palabra + "de pesos";
                } else {
                    palabra = palabra + "pesos";
                }

                Document documento = new Document(PageSize.LETTER);
                PdfWriter.getInstance(documento, archivo);
                documento.open();
                try {
                    Image im = Image.getInstance(f.getRutaCotizacion() + "headerword.png");
                    im.setAlignment(Image.ALIGN_CENTER);
                    im.scaleToFit(600, 400);
                    documento.add(im);
                } catch (Exception e) {
                    setCursor(Cursor.getDefaultCursor());

                    JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL ENCABEZADO.",
                            "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

                }

                int linea = 0;
                Font fuente = new Font();
                fuente.setStyle(Font.UNDERLINE | Font.BOLD);
                fuente.setSize(11);
                fuente.setColor(BaseColor.BLACK);
                documento.add(new Paragraph(" "));
                Paragraph fecha = new Paragraph(dia + " de " + mes.toLowerCase() + " de " + anio + "\n",
                        FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
                fecha.setAlignment(Paragraph.ALIGN_RIGHT);
                documento.add(fecha);
                Paragraph obp = new Paragraph("ULTIMO ROUND\n",
                        FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
                obp.setAlignment(Paragraph.ALIGN_RIGHT);
                documento.add(obp);
                Paragraph codigo = new Paragraph("COD." + remplazado,
                        FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
                codigo.setAlignment(Paragraph.ALIGN_RIGHT);
                documento.add(codigo);
                Paragraph space = new Paragraph("\n",
                        FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
                space.setAlignment(Paragraph.ALIGN_LEFT);
                documento.add(space);
                Paragraph origen = new Paragraph("ESTIMADO CLIENTE: " + jLabel13.getText() + "\n",
                        FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
                origen.setAlignment(Paragraph.ALIGN_LEFT);
                documento.add(origen);
                Paragraph origen2 = new Paragraph("EMAIL: " + jLabel15.getText() + "\n",
                        FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
                origen2.setAlignment(Paragraph.ALIGN_LEFT);
                documento.add(origen2);
                Paragraph a = new Paragraph(nombre,
                        FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
                a.setAlignment(Paragraph.ALIGN_LEFT);
                documento.add(a);
                Paragraph rut = new Paragraph(rut_socio,
                        FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
                rut.setAlignment(Paragraph.ALIGN_LEFT);
                documento.add(rut);
                Paragraph ref = new Paragraph("REF:COTIZACION POR PRODUCTOS TIENDA ULTIMO ROUND\n",
                        FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
                ref.setAlignment(Paragraph.ALIGN_RIGHT);
                documento.add(ref);

                documento.add(space);
                int numerocheque = 0;
                int montofinal = 0;
                String montostring = "";
                String detalle = "";
                String monto = jLabel22.getText();

                String montoaux = monto.replace(".", "");

                deuda = Integer.parseInt(montoaux);

                palabra = f.Convertir(deuda + "", false);
                System.out.println(palabra);
                palabra = palabra.replaceAll("0", "");
                System.out.println(palabra);
                Paragraph e = new Paragraph(
                        "Junto con saludarlo, adjunto la cotizacin detallada de los siguientes productos"
                                + " por el monto de $" + monto + ".- ( " + palabra
                                + "pesos IVA INCLUIDO) ,segn detalle:\n\n",
                        FontFactory.getFont("times new roman", 11, Font.NORMAL, BaseColor.BLACK));
                e.setAlignment(Paragraph.ALIGN_LEFT);
                documento.add(e);
                documento.add(new Paragraph(" "));
                // ACA DEBE IR LA TABLA
                //special font sizes
                Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0));
                Font bf10 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
                //specify column widths

                //create PDF table with the given widths

                documento.add(new Paragraph(" "));
                float[] colsWidth = { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f };
                PdfPTable tabla = new PdfPTable(5);
                tabla.setWidths(colsWidth);
                String[] titulos = { "PRODUCTO", "VALOR PRODUCTO", "TIPO", "MARCA", "TALLA" };

                tabla.setWidthPercentage(100);
                PdfPCell celda;
                for (int k = 0; k < titulos.length; k++) {
                    celda = new PdfPCell(new Paragraph(titulos[k],
                            FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);
                }
                int var = 0;
                int w = 0;
                for (w = 0; w < jTable1.getRowCount(); w++) {
                    celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 1).toString(), FontFactory
                            .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);
                    celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 7).toString(), FontFactory
                            .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);
                    celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 4).toString(), FontFactory
                            .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);
                    celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 3).toString(), FontFactory
                            .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);
                    celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 2).toString(), FontFactory
                            .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                    tabla.addCell(celda);

                }
                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

                celda = new PdfPCell(new Paragraph("MONTO NETO",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(monto,
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

                celda = new PdfPCell(new Paragraph("IVA TOTAL",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                double iva2 = Float.parseFloat(monto) * (0.19);
                iva2 = Math.round(iva2);

                celda = new PdfPCell(new Paragraph(Double.toString(iva2),
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph("",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

                celda = new PdfPCell(new Paragraph("VALOR TOTAL",
                        FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                int valortotal = Integer.parseInt(monto);

                celda = new PdfPCell(new Paragraph(Integer.toString(valortotal),
                        FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                documento.add(tabla);
                //FOOOTER
                documento.add(space);
                Paragraph despido = new Paragraph("Quedando a vuestra disposicin, saluda atentamente a Ud.,\n",
                        FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
                despido.setAlignment(Paragraph.ALIGN_LEFT);
                documento.add(despido);
                documento.add(space);

                Paragraph firma2 = new Paragraph("TIENDA ULTIMO ROUND\n",
                        FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
                firma2.setAlignment(Paragraph.ALIGN_RIGHT);
                documento.add(firma2);
                documento.add(space);
                documento.add(space);
                documento.add(space);
                Paragraph firma3 = new Paragraph("Cotizacin vlida por siete das\n",
                        FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
                firma3.setAlignment(Paragraph.ALIGN_CENTER);
                documento.add(firma3);
                documento.add(space);
                documento.add(space);
                try {
                    Image im = Image.getInstance(f.getRutaCotizacion() + "footerword.png");
                    im.setAlignment(Image.ALIGN_CENTER);
                    im.scaleToFit(600, 500);
                    documento.add(im);
                } catch (Exception ex) {
                    setCursor(Cursor.getDefaultCursor());

                    JOptionPane.showConfirmDialog(null,
                            "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL PIE DE PAGINA.", "ERROR",
                            JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

                }
                documento.close();

                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null, "REALIZADO CORRECTAMENTE", "INFORMACIN",
                        JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE);
            } catch (Exception ex) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null, "ERROR" + ex.getMessage(), "ERROR", JOptionPane.PLAIN_MESSAGE,
                        JOptionPane.ERROR_MESSAGE);
            }

        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        jButton11.setEnabled(false);
        // TODO add your handling code here:
        buscarKitinventario buscar = new buscarKitinventario(this.carroProductos, this.modelo1, this.jTable1,
                jLabel19, jLabel20, jLabel21, jLabel22, montoDescuento, aux2a, null, jLabel8);
        buscar.setVisible(true);
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
        int i = 0;
        boolean a = false;
        int size = carroProductos.size();
        int indice = -1;
        while (hasKits(carroProductos)) {
            if (carroProductos.get(i).getkit() == 1) {

                for (int k = 0; k < aux2a.size(); k++)
                    if (aux2a.get(k).getId_producto() == carroProductos.get(i).getId_producto())
                        indice = k;
                aux2a.get(indice).setCantidadp(aux2a.get(indice).getCantidadp() + 1);
                carroProductos.remove(i);
                modelo1.removeRow(i);
                a = true;
            }
            if (a == true)
                i = 0;
            else
                i++;
        }
        jLabel19.setText("0");
        jLabel20.setText("0");
        jLabel21.setText("0");
        jLabel22.setText("0");
        jLabel8.setText("0");
        System.out.println("ESTA ENTRANDO EL SIN IVA:");
        System.out.println(jLabel8.getText());
        calculaTotales(this.carroProductos);
        jButton11.setEnabled(true);
    }//GEN-LAST:event_jButton12ActionPerformed

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

    public boolean hasKits(ArrayList<Productos> pr) {
        for (Productos p : pr)
            if (p.getkit() == 1)
                return true;
        return false;
    }

    private void empaquetaProductos(ArrayList<Productos> carroProductos) {
        for (int i = 0; i < this.carroProductos.size(); i++) {
            Productos producto = this.carroProductos.get(i);
            int cv = (carroProductos.get(i).getCantidadDB() - carroProductos.get(i).getCantidadp());
            for (int j = 0; j < (cv - 1); j++) {
                int indice = this.carroProductos.indexOf(producto);
                this.carroProductos.remove(indice);

            }
        }
    }

    private ArrayList<VentaProducto> creaVentaProducto(ArrayList<Productos> carroProductos, String kit_or_product,
            int numeroBoleta) throws SQLException {
        ArrayList<VentaProducto> carroVentas = new ArrayList<VentaProducto>();
        int idVentaProducto = new metodosDB().getLastId("Ventaproducto");
        //    public VentaProducto(int idVentaProducto, String fecha, int precioUnitarioNeto, int cantidadProducto, int precioUnitarioFinal, int precioTotalNeto, int precioTotalFinal, int descuento, Kitproductos kit, Productos producto, int idOrdenDeVenta,String kit_or_product) { //Constructor
        int precio_unitario_neto, precio_total_neto, cantidad_vendida;
        int precio_unitario_final, precio_total_final;
        int id_orden_venta = numeroBoleta, descuento = 0;
        if (kit_or_product.equals("producto")) {

            for (Productos p : carroProductos) {
                cantidad_vendida = (p.getCantidadDB() - p.getCantidadp());
                precio_unitario_neto = p.getPrecioVenta();
                precio_unitario_final = (int) Math.round(precio_unitario_neto * 1.19);
                precio_total_neto = precio_unitario_neto * cantidad_vendida;
                precio_total_final = precio_unitario_final * cantidad_vendida;
                VentaProducto venta = new VentaProducto(idVentaProducto, getFecha(), precio_unitario_neto,
                        cantidad_vendida, precio_unitario_final, precio_total_neto, precio_total_final, descuento,
                        null, p, id_orden_venta, "producto");
                carroVentas.add(venta);
            }

        }
        return carroVentas;
    }

    private boolean guardaVenta(OrdenDeVenta orden) {
        try {
            //guardamos el objeto orden de venta.
            new metodosDB().addOrdenVenta(orden);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(rootPane, "Error almacenando venta en la bdd");
            return false;

        }
        return true;
    }

    private void descuentaInventario(ArrayList<Productos> carroProductos) throws SQLException {
        for (Productos p : carroProductos) {
            int cantidad_vendida = (p.getCantidadDB() - p.getCantidadp());
            p.setCantidadActual(p.getCantidadActual() - (1 * cantidad_vendida));
            new metodosDB().updateProductos(p);

        }
    }

    /**
     * @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 ex) {
            java.util.logging.Logger.getLogger(frameNewVentaKit.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frameNewVentaKit.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frameNewVentaKit.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frameNewVentaKit.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new frameNewVentaKit().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(frameNewVentaKit.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}