/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* factura.java
*
* Created on 08-dic-2011, 3:58:24
*/
package GUI;
//import Examen.Controller.Conexion;
//import Examen.View.Interface;
import java.awt.Dialog.ModalityType;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import static java.awt.print.Printable.NO_SUCH_PAGE;
import static java.awt.print.Printable.PAGE_EXISTS;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.swing.JRViewer;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.api.SubstanceConstants;
import org.jvnet.substance.api.SubstanceSkin;
import org.jvnet.substance.skin.RavenGraphiteGlassSkin;
import org.jvnet.substance.watermark.SubstanceImageWatermark;
/**
*
* @author AkaMM, Javatlacati
*/
public class VentanaFactura extends javax.swing.JFrame implements Printable {
/**
* Creates new form factura
*/
public VentanaFactura() {
//TODO dejar listo porque este se entrega urgentemente
JFrame.setDefaultLookAndFeelDecorated(false);//evita que un look & feel lo haga decorado
initComponents();
ImageIcon qrimagen = new javax.swing.ImageIcon(getClass().getResource("/GUI/res/qrcode.png"));
Image img = qrimagen.getImage();
//BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
//Graphics g = bi.createGraphics();
//g.drawImage(img, 0, 0, codigoqr.getWidth(), codigoqr.getHeight(), null);
//ImageIcon newIcon = new ImageIcon(bi);
Image newimg = img.getScaledInstance(codigoqr.getWidth(), codigoqr.getHeight(), java.awt.Image.SCALE_SMOOTH);
ImageIcon newIcon = new ImageIcon(newimg);
codigoqr.setIcon(newIcon); // NOI18N
//TODO hacer ventana de administración de factura para eliminar facturas
}
@Override
public void setVisible(boolean b) {
super.setVisible(b);
try {
javax.swing.UIManager.setLookAndFeel(new NimbusLookAndFeel());
} catch (Exception ex) {
Logger.getLogger(VentanaFactura.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* 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() {
jPanel1 = new javax.swing.JPanel();
lblCPCliente = new javax.swing.JLabel();
lblNombreCliente = new javax.swing.JLabel();
lblDireccionCliente = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
lblRFCCliente = new javax.swing.JLabel();
jTnombrefac = new javax.swing.JTextField();
jTdireccionfac = new javax.swing.JTextField();
jTrfcfac = new javax.swing.JTextField();
jTrfcfac1 = new javax.swing.JTextField();
label1 = new java.awt.Label();
pnlDatosFactura = new javax.swing.JPanel();
lblFacturaNo = new javax.swing.JLabel();
jTnumfac = new javax.swing.JTextField();
lblFacturaNo1 = new javax.swing.JLabel();
jTnumfac1 = new javax.swing.JTextField();
lblFacturaNo2 = new javax.swing.JLabel();
jTnumfac2 = new javax.swing.JTextField();
lblFacturaNo3 = new javax.swing.JLabel();
jTnumfac3 = new javax.swing.JTextField();
lblFacturaNo4 = new javax.swing.JLabel();
jTnumfac4 = new javax.swing.JTextField();
pnlDatosFacturador = new javax.swing.JPanel();
lblNombre = new javax.swing.JLabel();
lblNombreDuenio = new javax.swing.JLabel();
lblRFC = new javax.swing.JLabel();
lblRFCduenio = new javax.swing.JLabel();
lblDireccion = new javax.swing.JLabel();
lblDireccionDuenio = new javax.swing.JLabel();
lblExpedicion = new javax.swing.JLabel();
lbLugarDuenio = new javax.swing.JLabel();
lblCP = new javax.swing.JLabel();
lbCPDuenio = new javax.swing.JLabel();
jPanel7 = new javax.swing.JPanel();
jTtotal = new javax.swing.JTextField();
jLabel18 = new javax.swing.JLabel();
lblTotal = new javax.swing.JLabel();
jBimprimirfac = new javax.swing.JButton();
txtIVA = new javax.swing.JTextField();
jLabel23 = new javax.swing.JLabel();
lblIVA = new javax.swing.JLabel();
txtSubtotal = new javax.swing.JTextField();
jLabel22 = new javax.swing.JLabel();
lblSubtotal = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
Tproductos = new javax.swing.JTable();
lblProductos = new javax.swing.JLabel();
codigoqr = new javax.swing.JLabel();
btnSalir = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
lblSello = new javax.swing.JLabel();
lblSell9oTexto = new javax.swing.JLabel();
lblSello1 = new javax.swing.JLabel();
lblSell9oTexto1 = new javax.swing.JLabel();
lblSello2 = new javax.swing.JLabel();
lblSell9oTexto2 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
lblSello3 = new javax.swing.JLabel();
lblSell9oTexto3 = new javax.swing.JLabel();
jPanel4 = new javax.swing.JPanel();
lblSello4 = new javax.swing.JLabel();
lblSell9oTexto4 = new javax.swing.JLabel();
jPanel5 = new javax.swing.JPanel();
lblSello5 = new javax.swing.JLabel();
lblSell9oTexto5 = new javax.swing.JLabel();
jPanel6 = new javax.swing.JPanel();
lblSello6 = new javax.swing.JLabel();
lblSell9oTexto6 = new javax.swing.JLabel();
lblSello7 = new javax.swing.JLabel();
lblSell9oTexto7 = new javax.swing.JLabel();
lblSello8 = new javax.swing.JLabel();
lblSell9oTexto8 = new javax.swing.JLabel();
setTitle("Factura");
setUndecorated(true);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
lblCPCliente.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblCPCliente.setText("CP:");
jPanel1.add(lblCPCliente, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 270, -1, -1));
lblNombreCliente.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblNombreCliente.setText("Nombre:");
jPanel1.add(lblNombreCliente, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 180, -1, -1));
lblDireccionCliente.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblDireccionCliente.setText("Dirección:");
jPanel1.add(lblDireccionCliente, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 210, -1, -1));
jLabel13.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
jLabel13.setForeground(new java.awt.Color(204, 204, 204));
jPanel1.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 69, 60, 30));
lblRFCCliente.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblRFCCliente.setText("RFC:");
jPanel1.add(lblRFCCliente, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 240, -1, -1));
jTnombrefac.setBorder(null);
jTnombrefac.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTnombrefacActionPerformed(evt);
}
});
jPanel1.add(jTnombrefac, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 180, 220, -1));
jTdireccionfac.setBorder(null);
jTdireccionfac.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTdireccionfacActionPerformed(evt);
}
});
jPanel1.add(jTdireccionfac, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 210, 220, -1));
jTrfcfac.setBorder(null);
jTrfcfac.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTrfcfacActionPerformed(evt);
}
});
jPanel1.add(jTrfcfac, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 270, 220, -1));
jTrfcfac1.setBorder(null);
jTrfcfac1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTrfcfac1ActionPerformed(evt);
}
});
jPanel1.add(jTrfcfac1, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 240, 220, -1));
label1.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
label1.setText("Ciao Bella, S.A. de C.V.");
jPanel1.add(label1, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 10, -1, -1));
pnlDatosFactura.setBorder(javax.swing.BorderFactory.createTitledBorder("Factura No. "));
pnlDatosFactura.setLayout(new java.awt.GridLayout(5, 2));
lblFacturaNo.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblFacturaNo.setText("Expedido en: ");
pnlDatosFactura.add(lblFacturaNo);
jTnumfac.setEditable(false);
jTnumfac.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
jTnumfac.setToolTipText("");
jTnumfac.setBorder(null);
pnlDatosFactura.add(jTnumfac);
lblFacturaNo1.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblFacturaNo1.setText("Fecha: ");
pnlDatosFactura.add(lblFacturaNo1);
jTnumfac1.setEditable(false);
jTnumfac1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
jTnumfac1.setToolTipText("");
jTnumfac1.setBorder(null);
pnlDatosFactura.add(jTnumfac1);
lblFacturaNo2.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblFacturaNo2.setText("Forma de Pago: ");
pnlDatosFactura.add(lblFacturaNo2);
jTnumfac2.setEditable(false);
jTnumfac2.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
jTnumfac2.setText("UNA SOLA EXIBICIÓN");
jTnumfac2.setToolTipText("");
jTnumfac2.setBorder(null);
pnlDatosFactura.add(jTnumfac2);
lblFacturaNo3.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblFacturaNo3.setText("Método de Pago: ");
pnlDatosFactura.add(lblFacturaNo3);
jTnumfac3.setEditable(false);
jTnumfac3.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
jTnumfac3.setText("EFECTIVO");
jTnumfac3.setToolTipText("");
jTnumfac3.setBorder(null);
pnlDatosFactura.add(jTnumfac3);
lblFacturaNo4.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblFacturaNo4.setText("Ref. Bancaria: ");
pnlDatosFactura.add(lblFacturaNo4);
jTnumfac4.setEditable(false);
jTnumfac4.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
jTnumfac4.setToolTipText("");
jTnumfac4.setBorder(null);
pnlDatosFactura.add(jTnumfac4);
jPanel1.add(pnlDatosFactura, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 50, 350, 120));
pnlDatosFacturador.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
pnlDatosFacturador.setOpaque(false);
pnlDatosFacturador.setLayout(new java.awt.GridLayout(5, 2));
lblNombre.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblNombre.setText("Nombre: ");
pnlDatosFacturador.add(lblNombre);
lblNombreDuenio.setText("JORGE ARTURO PEREZ TLAPALE");
pnlDatosFacturador.add(lblNombreDuenio);
lblRFC.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblRFC.setText("RFC:");
pnlDatosFacturador.add(lblRFC);
lblRFCduenio.setText("PETA611215AC4");
pnlDatosFacturador.add(lblRFCduenio);
lblDireccion.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblDireccion.setText("Direccion:");
pnlDatosFacturador.add(lblDireccion);
lblDireccionDuenio.setText("Plaza de la Constitución No. 16 Interior 202");
pnlDatosFacturador.add(lblDireccionDuenio);
lblExpedicion.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblExpedicion.setText("Lugar de Expedicion: ");
pnlDatosFacturador.add(lblExpedicion);
lbLugarDuenio.setText("Tlaxcala de Xicohténcatl, Tlaxcala");
pnlDatosFacturador.add(lbLugarDuenio);
lblCP.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblCP.setText("CP:");
pnlDatosFacturador.add(lblCP);
lbCPDuenio.setText("90000");
pnlDatosFacturador.add(lbCPDuenio);
jPanel1.add(pnlDatosFacturador, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, 440, 240));
jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel7.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jTtotal.setEditable(false);
jTtotal.setText("0.00");
jTtotal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTtotalActionPerformed(evt);
}
});
jPanel7.add(jTtotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 390, 229, 37));
jLabel18.setFont(new java.awt.Font("Tahoma", 1, 26)); // NOI18N
jLabel18.setText("$");
jPanel7.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 380, 20, 50));
lblTotal.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblTotal.setText("Total: ");
jPanel7.add(lblTotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 400, -1, -1));
jBimprimirfac.setText("Imprimir");
jBimprimirfac.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBimprimirfacActionPerformed(evt);
}
});
jPanel7.add(jBimprimirfac, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 300, 150, 53));
txtIVA.setEditable(false);
txtIVA.setText("0.00");
txtIVA.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtIVAActionPerformed(evt);
}
});
jPanel7.add(txtIVA, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 340, 229, 37));
jLabel23.setFont(new java.awt.Font("Tahoma", 1, 26)); // NOI18N
jLabel23.setText("$");
jPanel7.add(jLabel23, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 330, 20, 50));
lblIVA.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblIVA.setText("IVA:");
jPanel7.add(lblIVA, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 350, -1, -1));
txtSubtotal.setEditable(false);
txtSubtotal.setText("0.00");
txtSubtotal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtSubtotalActionPerformed(evt);
}
});
jPanel7.add(txtSubtotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 300, 229, 37));
jLabel22.setFont(new java.awt.Font("Tahoma", 1, 26)); // NOI18N
jLabel22.setText("$");
jPanel7.add(jLabel22, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 290, 20, 50));
lblSubtotal.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblSubtotal.setText("Subtotal: ");
jPanel7.add(lblSubtotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 320, -1, -1));
Tproductos.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Nombre del Producto", "Precio", "Cantidad"
}
) {
boolean[] canEdit = new boolean [] {
false, true, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
Tproductos.setOpaque(false);
jScrollPane1.setViewportView(Tproductos);
jPanel7.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(3, 20, 800, 207));
lblProductos.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblProductos.setText("Productos:");
jPanel7.add(lblProductos, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 0, -1, -1));
jPanel7.add(codigoqr, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 240, 220, 210));
btnSalir.setText("Salir");
btnSalir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSalirActionPerformed(evt);
}
});
jPanel7.add(btnSalir, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 370, 150, 60));
jPanel1.add(jPanel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 290, 810, 460));
getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, 830, 760));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel2.setLayout(new java.awt.GridLayout(7, 1));
lblSello.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblSello.setText("Sello Digital del CFDI");
jPanel2.add(lblSello);
lblSell9oTexto.setText("kasjdlkjsadlksdasbohsa jsad sad sad jp sadsDASDaikhsASDSADSDJaDS");
jPanel2.add(lblSell9oTexto);
lblSello1.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblSello1.setText("Sello del SAT");
jPanel2.add(lblSello1);
lblSell9oTexto1.setText("kasjdlkjsadlksdasbohsa jsad sad sad jp sadsDASDaikhsASDSADSDJaDS");
jPanel2.add(lblSell9oTexto1);
lblSello2.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblSello2.setText("Cadena Original del Complemento de certificación digital del SAT");
jPanel2.add(lblSello2);
lblSell9oTexto2.setText("||1.0|kasjdlkjsadlksdasbohsa jsad sad sad jp sadsDASDaikhsASDSADSDJaDS||");
jPanel2.add(lblSell9oTexto2);
jPanel3.setLayout(new java.awt.GridLayout(1, 2, 2, 0));
lblSello3.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblSello3.setText("No. Serie CERT. SAT");
jPanel3.add(lblSello3);
lblSell9oTexto3.setText("124648547649674");
jPanel3.add(lblSell9oTexto3);
jPanel2.add(jPanel3);
jPanel4.setLayout(new java.awt.GridLayout(1, 2, 2, 0));
lblSello4.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblSello4.setText("No. Serie CERT. Emisor");
jPanel4.add(lblSello4);
lblSell9oTexto4.setText("123484184964849687465465");
jPanel4.add(lblSell9oTexto4);
jPanel2.add(jPanel4);
lblSello5.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblSello5.setText("Fecha y Hora de Cert");
jPanel5.add(lblSello5);
lblSell9oTexto5.setText("2014-08-23T11:15:45");
jPanel5.add(lblSell9oTexto5);
jPanel2.add(jPanel5);
lblSello6.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblSello6.setText("Fecha de Elaboración");
jPanel6.add(lblSello6);
lblSell9oTexto6.setText("2014-08-23T11:15:42");
jPanel6.add(lblSell9oTexto6);
jPanel2.add(jPanel6);
lblSello7.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblSello7.setText("Folio Fiscal");
jPanel2.add(lblSello7);
lblSell9oTexto7.setText("||1.0|kasjdlkjsadlksdasbohsa jsad sad sad jp sadsDASDaikhsASDSADSDJaDS||");
jPanel2.add(lblSell9oTexto7);
lblSello8.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
lblSello8.setText("Regimen Fiscal");
jPanel2.add(lblSello8);
lblSell9oTexto8.setText("REGIMEN GENERAL DE LEY DE PERSONAS MORALES");
jPanel2.add(lblSell9oTexto8);
getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 770, 810, 280));
pack();
}// </editor-fold>//GEN-END:initComponents
private void jTtotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTtotalActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTtotalActionPerformed
private void jTnombrefacActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTnombrefacActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTnombrefacActionPerformed
private void jTdireccionfacActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTdireccionfacActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTdireccionfacActionPerformed
private void jTrfcfacActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTrfcfacActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTrfcfacActionPerformed
@Override
public int print(Graphics g, PageFormat pf, int page)
throws PrinterException {
if (page > 0) {
return NO_SUCH_PAGE;
}
//quitar las partes que no se quiere que se vean
// setVisible(false);
//removeNotify();
//setUndecorated(true);
//setVisible(true);
jBimprimirfac.setVisible(false);
btnSalir.setVisible(false);
// addNotify();
//TODO tal vez cambiar el color de fondo para la hora de imprimir
Graphics2D g2d = (Graphics2D) g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
g2d.scale(pf.getImageableWidth() / this.getWidth(), pf.getImageableHeight() / this.getHeight());
// Print the entire visible contents of a
// java.awt.Frame.
this.printAll(g2d);
//volver a hacer visible todo
// removeNotify();
// setVisible(false);
// setUndecorated(false);
// setVisible(true);
// addNotify();
jBimprimirfac.setVisible(true);
btnSalir.setVisible(true);
return PAGE_EXISTS;
}
private void jBimprimirfacActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBimprimirfacActionPerformed
// DefaultTableModel model = (DefaultTableModel) Tproductos.getModel();
// double total = 0;
// for (int i = 0; i < model.getRowCount(); i++) {
// total += (Double) model.getValueAt(i, 2);
// total += (Double) model.getValueAt(i, 3);
// }
// Object[] row = {"TOTAL", "", total};
// model.addRow(row);
// try {
// Tproductos.print();
// } catch (PrinterException ex) {
// Logger.getLogger(VentanaFactura.class.getName()).log(Level.SEVERE, null, ex);
// }
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
boolean doPrint = job.printDialog();
if (doPrint) {
try {
// job.setJobName("Ciao bella");
job.print();
} catch (PrinterException e) {
// The job did not successfully
// complete
}
}
// /**
// * *************************************
// */
// //con jasper reports
// Map parametros = new HashMap();
// parametros.put("cliente_nombre", jTnombrefac);//así apra todos
// //para jalar valores de jtable JRTableModelDataSource tabela = new JRTableModelDataSource(tabelaConsumo.getModel()); //aqui eu crio um datasource usando a propria jtable
// String archivo = "/reportes/factura.jasper";
// //java.io.InputStream file = getClass().getClassLoader().getResourceAsStream(archivo);
// java.io.InputStream file = getClass().getResourceAsStream(archivo);
// if (file == null) {
// System.err.println("Archivo factura.jasper no se encontró");
// }
// try {
// JasperPrint printer = JasperFillManager.fillReport(file, parametros, new JREmptyDataSource());
// JRViewer view = new JRViewer(printer);
// JDialog dialog = new JDialog();
// dialog.getContentPane().add(view);
// dialog.setSize(800, 600);
// dialog.setLocationRelativeTo(this);
// dialog.setModalityType(ModalityType.APPLICATION_MODAL);
// dialog.setModal(true);
// dialog.setVisible(true);
// //save
// OutputStream output = new FileOutputStream(new File("C:/output/JasperReport.pdf"));
// JasperExportManager.exportReportToPdfStream(printer, output);
// //TODO enviar por correo con JavaMail
// } catch (JRException ex) {
// Logger.getLogger(VentanaFactura.class.getName()).log(Level.SEVERE, null, ex);
// } catch (FileNotFoundException ex) {
// Logger.getLogger(VentanaFactura.class.getName()).log(Level.SEVERE, null, ex);
// }
// //TODO tal vez consultar los que falten de la BD
// /**
// * ************************************
// */
// int j;
//// Conexion con;
// ResultSet rs;
// String nomfac = jTnombrefac.getText();
// String rfcfac = jTrfcfac.getText();
// String direccionfac = jTdireccionfac.getText();
// String total = jTtotal.getText();
//
// Object producto;
// Object canti;
// String cadenita = "";
// String pro = "";
//
// if (!nomfac.equals("") || !rfcfac.equals("") || !direccionfac.equals("")) {
// if (JOptionPane.showConfirmDialog(rootPane, "Ya esta listo para imprimir la Factura?", "Imprimir Factura", 1) == 0) {
// String existe = null;
// int e;
// String ID = null;
// String ticket;
// String ss;
//
// try {
// //se crea la conexion y las consultas
//// con = new Conexion();
//
// //con.ejecutar("INSERT INTO `negocio`.`facturas` (`cantidad`, `nombre`, `direccion`, `rfc`) VALUES ('"+total+"', '"+nomfac+"', '"+direccionfac+"', '"+rfcfac+"');");
//// int to[] = new int[100];
//// float prec[] = new float[100];
// Object ex = null, precio = null;
// Object pros = null;
//
// // se crea la sentecia sql y se ejecuta para hacer la modificacion
//////// FileOutputStream os = null;
//////// try {
//////// os = new FileOutputStream("ticket.txt");
//////// } catch (FileNotFoundException ex1) {
//////// Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex1);
//////// }
//////// PrintStream ps = new PrintStream(os);
// //Interface row = new Interface();
// // int rowCount = row.getFactura();
// // vendedor vende = new vendedor();
// // int rc = vende.getFactura();
// Date fecha = new Date();
// String cadena = "Farmacia 'Las Lomas'\n----------------------\nRFC: TOSO850220GN9\nBaltazar N. 4 \nSan Antonio Coaxomulco, Tlaxcala\nFecha: " + fecha + "\n";
// String cade = "----------------------\n\n\t>>Datos del Comprador<<\n\nNumero de Factura: " + jTnumfac.getText() + "\nNombre: " + nomfac + "\nRFC: " + rfcfac + "\nDireccion: " + direccionfac;
// // System.out.println("Numero de Filas: "+rowCount);
// String enca = "\n----------------------\nProducto\tCant.\tPrecio\n";
//// for(int x=0;x<rowCount;x++){
////
//// producto = Tproductos.getValueAt(x,0);
//// pro = objectToString(producto);
////
//// precio = Tproductos.getValueAt(x,1);
//// // String pre = objectToString(prec);
////
//// canti = Tproductos.getValueAt(x,2);
//// // String c = objectToString(canti);
////
////
//// if(pro.length()<=8)
//// pro=pro+" ";
//// if(pro.length()>15)
//// pro = pro.substring(0, 15);
////
//// cadenita = cadenita+"\n"+pro+"\t"+canti+"\t"+precio+"";
////
//// }
//// for(int x=0;x<rc;x++){
////
//// producto = Tproductos.getValueAt(x,0);
//// pro = objectToString(producto);
////
//// precio = Tproductos.getValueAt(x,1);
//// // String pre = objectToString(prec);
////
//// canti = Tproductos.getValueAt(x,2);
//// // String c = objectToString(canti);
////
////
//// if(pro.length()<=8)
//// pro=pro+" ";
//// if(pro.length()>15)
//// pro = pro.substring(0, 15);
////
//// cadenita = cadenita+"\n"+pro+"\t"+canti+"\t"+precio+"";
////
//// }
// ticket = cadena + cade + enca + cadenita + "\n\nTotal: \t\t$" + jTtotal.getText() + "\n\n----------------------\n CON EL CORAZON EN LAS MANOS\n GRACIAS POR SU COMPRA.\n\n\n\n";
//
// //Cogemos el servicio de impresión por defecto (impresora por defecto)
// PrintService service = PrintServiceLookup.lookupDefaultPrintService();
////Le decimos el tipo de datos que vamos a enviar a la impresora
////Tipo: bytes Subtipo: autodetectado
// DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
////Creamos un trabajo de impresión
// DocPrintJob pj = service.createPrintJob();
////Nuestro trabajo de impresión envía una cadena de texto
// ss = new String(ticket);
// byte[] bytes;
////Transformamos el texto a bytes que es lo que soporta la impresora
// bytes = ss.getBytes();
////Creamos un documento (Como si fuese una hoja de Word para imprimir)
// Doc doc = new SimpleDoc(bytes, flavor, null);
//
////Obligado coger la excepción PrintException
// //Mandamos a impremir el documento
// pj.print(doc, null);
//
////// ps.println(ticket);
////// ps.close();
// String t = jTtotal.getText();
//// String id34=jTID.getText();
// ticket = "";
// //String venta = "INSERT INTO `ventas`(`total`, `id_usuario`) VALUES (,'"+t+"','"+id34+"')";
//// String venta = "INSERT INTO `negocio`.`ventas` (`id_ventas` ,`total` ,`fecha` ,`Id_usuario`)VALUES (NULL , '"+t+"', CURRENT_TIMESTAMP , '"+id34+"');";
//// con.ejecutar(venta);
//////////////////// for(int i=0;i<j;i++){
//////////////////// venta = "INSERT INTO `negocio`.`vendidos` (`id_vendido`, `producto`, `precio`, `cantidad`, `fecha`, `Id_usuario`) VALUES (NULL, '"+pro[i]+"', '"+prec[i]+"', '"+to[i]+"', CURRENT_TIMESTAMP, '"+id34+"');";
//////////////////// con.ejecutar(venta);
//////////////////// }
// JOptionPane.showMessageDialog(null, " Imprimiendo Factura");
// this.dispose();
//
// } catch (PrintException ex1) {
// Logger.getLogger(VentanaFactura.class.getName()).log(Level.SEVERE, null, ex1);
// }
// // Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
// // Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
//
// }
// } else {
// JOptionPane.showMessageDialog(rootPane, "Faltan Campos por Llenar");
// }
}//GEN-LAST:event_jBimprimirfacActionPerformed
private void jTrfcfac1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTrfcfac1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTrfcfac1ActionPerformed
private void txtSubtotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSubtotalActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtSubtotalActionPerformed
private void txtIVAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIVAActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtIVAActionPerformed
private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
dispose();
//System.exit(0);
}//GEN-LAST:event_btnSalirActionPerformed
/**
* @param args the command line arguments
*/
public void setTabla(JTable datos) {
this.Tproductos = datos;
}
public void setTotal(String total) {
jTtotal.setText(total);
}
public int getFactura(int filas) {
return filas;
}
public String objectToString(Object o) {
String st;
st = (String) o;
return st;
}
public JTable getTabla() {
return this.Tproductos;
}
public void setNum(int num) {
String x = String.valueOf(num);
jTnumfac.setText(x);
}
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(VentanaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(VentanaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(VentanaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(VentanaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
VentanaFactura fact = new VentanaFactura();
fact.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTable Tproductos;
private javax.swing.JButton btnSalir;
private javax.swing.JLabel codigoqr;
private javax.swing.JButton jBimprimirfac;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel22;
private javax.swing.JLabel jLabel23;
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.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTdireccionfac;
private javax.swing.JTextField jTnombrefac;
private javax.swing.JTextField jTnumfac;
private javax.swing.JTextField jTnumfac1;
private javax.swing.JTextField jTnumfac2;
private javax.swing.JTextField jTnumfac3;
private javax.swing.JTextField jTnumfac4;
private javax.swing.JTextField jTrfcfac;
private javax.swing.JTextField jTrfcfac1;
private javax.swing.JTextField jTtotal;
private java.awt.Label label1;
private javax.swing.JLabel lbCPDuenio;
private javax.swing.JLabel lbLugarDuenio;
private javax.swing.JLabel lblCP;
private javax.swing.JLabel lblCPCliente;
private javax.swing.JLabel lblDireccion;
private javax.swing.JLabel lblDireccionCliente;
private javax.swing.JLabel lblDireccionDuenio;
private javax.swing.JLabel lblExpedicion;
private javax.swing.JLabel lblFacturaNo;
private javax.swing.JLabel lblFacturaNo1;
private javax.swing.JLabel lblFacturaNo2;
private javax.swing.JLabel lblFacturaNo3;
private javax.swing.JLabel lblFacturaNo4;
private javax.swing.JLabel lblIVA;
private javax.swing.JLabel lblNombre;
private javax.swing.JLabel lblNombreCliente;
private javax.swing.JLabel lblNombreDuenio;
private javax.swing.JLabel lblProductos;
private javax.swing.JLabel lblRFC;
private javax.swing.JLabel lblRFCCliente;
private javax.swing.JLabel lblRFCduenio;
private javax.swing.JLabel lblSell9oTexto;
private javax.swing.JLabel lblSell9oTexto1;
private javax.swing.JLabel lblSell9oTexto2;
private javax.swing.JLabel lblSell9oTexto3;
private javax.swing.JLabel lblSell9oTexto4;
private javax.swing.JLabel lblSell9oTexto5;
private javax.swing.JLabel lblSell9oTexto6;
private javax.swing.JLabel lblSell9oTexto7;
private javax.swing.JLabel lblSell9oTexto8;
private javax.swing.JLabel lblSello;
private javax.swing.JLabel lblSello1;
private javax.swing.JLabel lblSello2;
private javax.swing.JLabel lblSello3;
private javax.swing.JLabel lblSello4;
private javax.swing.JLabel lblSello5;
private javax.swing.JLabel lblSello6;
private javax.swing.JLabel lblSello7;
private javax.swing.JLabel lblSello8;
private javax.swing.JLabel lblSubtotal;
private javax.swing.JLabel lblTotal;
private javax.swing.JPanel pnlDatosFactura;
private javax.swing.JPanel pnlDatosFacturador;
private javax.swing.JTextField txtIVA;
private javax.swing.JTextField txtSubtotal;
// End of variables declaration//GEN-END:variables
}