Java tutorial
/* * 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 br.com.tcc.view; import Conexao.ConnectionFactory; import br.com.tcc.entity.Vendaregistro; import br.com.tcc.util.Data; import br.com.tcc.util.EntityManagerUtil; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; 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.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Leonardo P Souza */ public class FormaPagamentoView extends javax.swing.JFrame { public String mes, dia, ano, dia_semana, hora; public FormaPagamentoView() { initComponents(); int linha = tblRegistro.getRowCount() - 1; tblRegistro.setRowSelectionInterval(linha, linha); tblRegistro.scrollRectToVisible(tblRegistro.getCellRect(linha, 0, true)); } /** * 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() { bindingGroup = new org.jdesktop.beansbinding.BindingGroup(); entityManager = EntityManagerUtil.getEntityManager(); tipoPagamentoQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT tp FROM Tipopagamento tp"); tipoPagamentoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections .observableList(tipoPagamentoQuery.getResultList()); vendaRegistroQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT pr FROM Vendaregistro pr"); vendaRegistroList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections .observableList(vendaRegistroQuery.getResultList()); clienteQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT c FROM Cliente c"); clienteList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections .observableList(clienteQuery.getResultList()); funcionarioQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT f FROM Funcionario f"); funcionarioList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections .observableList(funcionarioQuery.getResultList()); vendaDetalheQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT pd FROM Vendadetalhe pd"); vendaDetalheList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections .observableList(vendaDetalheQuery.getResultList()); lblCodigo = new javax.swing.JLabel(); txtCodigo = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); cbxCliente = new javax.swing.JComboBox(); jLabel3 = new javax.swing.JLabel(); cbxFuncionario = new javax.swing.JComboBox(); jLabel7 = new javax.swing.JLabel(); cbxParcelas = new javax.swing.JComboBox(); jLabel8 = new javax.swing.JLabel(); txfVencimento = new javax.swing.JFormattedTextField(); jLabel1 = new javax.swing.JLabel(); cbxTipoPagamento = new javax.swing.JComboBox(); txtCompra = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); txtTotal = new javax.swing.JTextField(); txtDesconto = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); tblRegistro = new javax.swing.JTable(); btnConfirmarCompra = new javax.swing.JButton(); btnImprimir = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Confirmao de Pagamento"); lblCodigo.setText("Cdigo:"); txtCodigo.setEnabled(false); org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.id}"), txtCodigo, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel2.setText("Cliente:"); cbxCliente.setEnabled(false); org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings .createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, clienteList, cbxCliente); bindingGroup.addBinding(jComboBoxBinding); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idCliente}"), cbxCliente, org.jdesktop.beansbinding.BeanProperty.create("selectedItem")); bindingGroup.addBinding(binding); jLabel3.setText("Funcionrio:"); cbxFuncionario.setEnabled(false); jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, funcionarioList, cbxFuncionario); bindingGroup.addBinding(jComboBoxBinding); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idFuncionario}"), cbxFuncionario, org.jdesktop.beansbinding.BeanProperty.create("selectedItem")); bindingGroup.addBinding(binding); jLabel7.setText("Parcelas:"); cbxParcelas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6" })); cbxParcelas.setSelectedIndex(1); cbxParcelas.setToolTipText(""); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.parcela}"), cbxParcelas, org.jdesktop.beansbinding.BeanProperty.create("selectedItem")); bindingGroup.addBinding(binding); jLabel8.setText("1 Vencimento"); txfVencimento.setEnabled(false); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.vencimento}"), txfVencimento, org.jdesktop.beansbinding.BeanProperty.create("value")); bindingGroup.addBinding(binding); jLabel1.setText("Tipo de Pagamento:"); jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tipoPagamentoList, cbxTipoPagamento); bindingGroup.addBinding(jComboBoxBinding); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idTipoPagamento}"), cbxTipoPagamento, org.jdesktop.beansbinding.BeanProperty.create("selectedItem")); bindingGroup.addBinding(binding); cbxTipoPagamento.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { cbxTipoPagamentoFocusLost(evt); } }); cbxTipoPagamento.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbxTipoPagamentoActionPerformed(evt); } }); txtCompra.setEnabled(false); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.vlrSugerido}"), txtCompra, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); jLabel4.setText("Valor da Compra:"); jLabel5.setText("Desconto:"); jLabel6.setText("Valor Total:"); txtTotal.setEnabled(false); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.totalVenda}"), txtTotal, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); txtDesconto.setEnabled(false); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.desconto}"), txtDesconto, org.jdesktop.beansbinding.BeanProperty.create("text")); bindingGroup.addBinding(binding); org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings .createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vendaRegistroList, tblRegistro); org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}")); columnBinding.setColumnName("Cdigo"); columnBinding.setColumnClass(Integer.class); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idCliente.nome}")); columnBinding.setColumnName("Cliente"); columnBinding.setColumnClass(String.class); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idFuncionario.nome}")); columnBinding.setColumnName("Funcionario"); columnBinding.setColumnClass(String.class); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idTipoPagamento.descricao}")); columnBinding.setColumnName("Tipo Pagamento"); columnBinding.setColumnClass(String.class); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${parcela}")); columnBinding.setColumnName("Parcela"); columnBinding.setColumnClass(String.class); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${vencimento}")); columnBinding.setColumnName("Vencimento"); columnBinding.setColumnClass(java.util.Date.class); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dataVenda}")); columnBinding.setColumnName("Data"); columnBinding.setColumnClass(java.util.Date.class); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${vlrSugerido}")); columnBinding.setColumnName("Sugerido R$"); columnBinding.setColumnClass(Double.class); columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${desconto}")); columnBinding.setColumnName("Desconto R$"); columnBinding.setColumnClass(Double.class); columnBinding = jTableBinding .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${totalVenda}")); columnBinding.setColumnName("Total R$"); columnBinding.setColumnClass(Double.class); bindingGroup.addBinding(jTableBinding); jTableBinding.bind(); jScrollPane1.setViewportView(tblRegistro); btnConfirmarCompra.setText("Confirmar"); btnConfirmarCompra.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnConfirmarCompraActionPerformed(evt); } }); btnImprimir.setText("Imprimir"); btnImprimir.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnImprimirActionPerformed(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().addContainerGap().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblCodigo).addComponent(jLabel2)) .addGap(40, 40, 40) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(cbxCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel3).addGap(18, 18, 18).addComponent(cbxFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cbxTipoPagamento, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel7) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cbxParcelas, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel8) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txfVencimento, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnImprimir) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnConfirmarCompra)))) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4).addComponent(txtCompra, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(txtDesconto, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout .createSequentialGroup().addComponent(jLabel5).addGap(13, 13, 13))) .addGap(110, 110, 110) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(19, 19, 19) .addComponent(jLabel6)) .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(lblCodigo) .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(cbxCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3).addComponent(cbxFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(cbxTipoPagamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7) .addComponent(cbxParcelas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel8).addComponent(txfVencimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4).addComponent(jLabel5).addComponent(jLabel6)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtCompra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtDesconto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnConfirmarCompra).addComponent(btnImprimir)) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); bindingGroup.bind(); pack(); }// </editor-fold>//GEN-END:initComponents private void btnConfirmarCompraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConfirmarCompraActionPerformed int linhaClicada = tblRegistro.getSelectedRow(); Vendaregistro obj = vendaRegistroList.get(linhaClicada); if (cbxTipoPagamento.getSelectedItem().toString().equals(" vista") || cbxTipoPagamento.getSelectedItem().toString().equals("C. Debito")) { obj.setAtivo("Pago"); } else { obj.setAtivo("Pendente"); } obj.setRestante(obj.getTotalVenda()); obj.setDesconto(0.0); obj.setJuro(0.0); entityManager.getTransaction().begin(); entityManager.persist(obj); entityManager.getTransaction().commit(); dispose(); }//GEN-LAST:event_btnConfirmarCompraActionPerformed private void cbxTipoPagamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbxTipoPagamentoActionPerformed }//GEN-LAST:event_cbxTipoPagamentoActionPerformed private void cbxTipoPagamentoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cbxTipoPagamentoFocusLost int linhaClicada = tblRegistro.getSelectedRow(); Vendaregistro obj = vendaRegistroList.get(linhaClicada); if (cbxTipoPagamento.getSelectedItem().toString().equals(" vista") || cbxTipoPagamento.getSelectedItem().toString().equals("C. Debito")) { txtDesconto.setText("5%"); double desconto = (Double.parseDouble(txtCompra.getText()) * 5) / 100; obj.setTotalVenda(Double.parseDouble(txtCompra.getText()) - desconto); cbxParcelas.setFocusable(false); cbxParcelas.setEnabled(false); txtTotal.setText(obj.getTotalVenda().toString()); txfVencimento.setText(null); obj.setParcela("1"); obj.setVencimento(null); } if (cbxTipoPagamento.getSelectedItem().toString().equals("C. Credito") || cbxTipoPagamento.getSelectedItem().toString().equals("Boleto")) { txtDesconto.setText("0%"); // obj.setTotalVenda(obj.getVlrSugerido()); txtTotal.setText(obj.getVlrSugerido().toString()); cbxParcelas.setEnabled(true); Integer dias = 28; Date vencimento = new Date(); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(vencimento); gc.set(Calendar.DATE, gc.get(Calendar.DATE) + dias); vencimento = gc.getTime(); System.err.println("Data: " + vencimento.toString()); obj.setVencimento(vencimento); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); String result = sdf.format(vencimento); txfVencimento.setText(result); obj.setParcela(cbxParcelas.getSelectedItem().toString()); obj.setAtivo("Pendente"); } // if (cbxTipoPagamento.getSelectedItem().toString().equals("Boleto")) { // cbxParcelas.setEnabled(true); // txtDesconto.setText("0%"); // txtTotal.setText(obj.getVlrSugerido().toString()); // obj.setTotalVenda(obj.getVlrSugerido()); // Integer dias = 28; // Date vencimento = new Date(); // GregorianCalendar gc = new GregorianCalendar(); // gc.setTime(vencimento); // gc.set(Calendar.DATE, gc.get(Calendar.DATE) + dias); // vencimento = gc.getTime(); // System.err.println("Data: " + vencimento.toString()); // obj.setVencimento(vencimento); // SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); // String result = sdf.format(vencimento); // txfVencimento.setText(result); // obj.setParcela(cbxParcelas.getSelectedItem().toString()); // obj.setAtivo(null); // } }//GEN-LAST:event_cbxTipoPagamentoFocusLost private void btnImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirActionPerformed int row = tblRegistro.getSelectedRow(); int id = vendaRegistroList.get(row).getId(); Connection con = new ConnectionFactory().getConnection(); try { Statement stmt = con.createStatement(); ResultSet query = stmt.executeQuery( "SELECT produto.descricao, vendadetalhe.qtde, vendadetalhe.vlrUnitario, vendadetalhe.vlrTotal from vendadetalhe as vendadetalhe INNER JOIN produto as produto ON (vendadetalhe.idProduto = produto.ID) where idVendaRegistro = " + id); Document documento = new Document(); SimpleDateFormat horaformatada = new SimpleDateFormat("HH:mm:ss"); Date horaAtual = new Date(); hora = horaformatada.format(horaAtual); Date data = new Date(); // mes = ""+Data.getMonth();//0 a 11 dia = "" + data.getDate(); ano = "" + (1900 + data.getYear()); switch (data.getMonth()) { case 0: mes = "Janeiro"; break; case 1: mes = "Fevereiro"; break; case 2: mes = "Maro"; break; case 3: mes = "Abril"; break; case 4: mes = "Maio"; break; case 5: mes = "Junho"; break; case 6: mes = "Julho"; break; case 7: mes = "Agosto"; break; case 8: mes = "Setembro"; break; case 9: mes = "Outubro"; break; case 10: mes = "Novembro"; break; case 11: mes = "Dezembro"; break; } try { OutputStream outputStream = new FileOutputStream( "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Registro da venda " + txtCodigo.getText() + ".pdf"); PdfWriter.getInstance(documento, outputStream); documento.open(); Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 36, Font.BOLD); Font fonteItem = new Font(Font.FontFamily.COURIER, 28, Font.BOLD); Paragraph cabecalho = new Paragraph("AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n" + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n" + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n" + "CNPJ: 12.345.678/1011-12\n" + "-------------------------------------------\n" + dia + "/" + mes + "/" + ano + " " + hora + " COD: " + txtCodigo.getText()); cabecalho.setAlignment(Element.ALIGN_CENTER); documento.add(cabecalho); Paragraph paragrafo = new Paragraph("Relatrio da Venda", fonte); paragrafo.setAlignment(Element.ALIGN_CENTER); documento.add(paragrafo); Paragraph paragrafoCliente = new Paragraph("Cliente: " + cbxCliente.getSelectedItem().toString()); documento.add(paragrafoCliente); Paragraph paragrafoFuncionario = new Paragraph( "Funcionrio: " + cbxFuncionario.getSelectedItem().toString()); documento.add(paragrafoFuncionario); Paragraph paragrafoPagamento = new Paragraph( "Tipo de Pagamento: " + cbxTipoPagamento.getSelectedItem().toString()); documento.add(paragrafoPagamento); // Paragraph paragrafoParcela = new Paragraph("Parcelas: " + cbxParcelas.getSelectedItem().toString()); // documento.add(paragrafoParcela); // Paragraph paragrafoValor = new Paragraph("Valor R$: " + txtTotal.getText()); // documento.add(paragrafoValor); if (cbxTipoPagamento.getSelectedItem().toString().equals(" vista") || cbxTipoPagamento.getSelectedItem().toString().equals("C. Debito")) { Paragraph paragrafoValor = new Paragraph("Valor R$: " + txtCompra.getText()); documento.add(paragrafoValor); Paragraph paragrafoAVista = new Paragraph("Valor vista: " + txtTotal.getText()); documento.add(paragrafoAVista); } else { Paragraph paragrafoValor = new Paragraph("Valor R$: " + txtTotal.getText()); documento.add(paragrafoValor); int parcela = Integer.parseInt(cbxParcelas.getSelectedItem().toString()); double valorParcelas = Double.parseDouble(txtTotal.getText()); double total = valorParcelas / parcela; Paragraph paragrafoVezes = new Paragraph( cbxParcelas.getSelectedItem().toString() + " parcelas de R$: " + total); documento.add(paragrafoVezes); } Paragraph quebraLinha = new Paragraph("\n\n"); documento.add(quebraLinha); //we have two columns in our table PdfPTable LogTable = new PdfPTable(4); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Relatrio de Entrada de Estoque"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(4); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela Font fonte2 = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD, BaseColor.BLACK); Font fonteDados = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK); LogTable.addCell(header); LogTable.addCell(new Paragraph("Produto ", fonte2)); LogTable.addCell(new Paragraph("Quantidade", fonte2)); LogTable.addCell(new Paragraph("Valor Unitrio", fonte2)); LogTable.addCell(new Paragraph("Valor Total", fonte2)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("produto.descricao"); LogTable.addCell(new Paragraph(produto, fonteDados)); String quantidade = query.getString("qtde"); LogTable.addCell(new Paragraph(quantidade, fonteDados)); String vlrSugerido = query.getString("vlrUnitario"); LogTable.addCell(new Paragraph(vlrSugerido, fonteDados)); String vlrTotal = query.getString("vlrTotal"); LogTable.addCell(new Paragraph(vlrTotal, fonteDados)); } /* Attach report table to PDF */ documento.add(LogTable); // Paragraph paragrafoItemVenda = new Paragraph("Produtos da venda", fonteItem); // paragrafoItemVenda.setAlignment(Element.ALIGN_CENTER); // documento.add(paragrafoItemVenda); // Paragraph cabecalhoItemVenda = new Paragraph("Produto Qtde. Vlr Unit. Vlr Total"); // documento.add(cabecalhoItemVenda); // vendaDetalheQuery = entityManager.createQuery("from Vendadetalhe where idVendaRegistro=" + txtCodigo.getText()); // Paragraph paragrafoLista = new Paragraph(vendaDetalheQuery.getResultList().toString().substring(1, vendaDetalheQuery.getResultList().toString().length() - 1)); // documento.add(paragrafoLista); documento.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Registro da venda " + txtCodigo.getText() + ".pdf"; Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); } catch (FileNotFoundException ex) { Logger.getLogger(MovimentoVendaView.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(MovimentoVendaView.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(FormaPagamentoView.class.getName()).log(Level.SEVERE, null, ex); } } catch (SQLException ex) { Logger.getLogger(FormaPagamentoView.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_btnImprimirActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnConfirmarCompra; private javax.swing.JButton btnImprimir; private javax.swing.JComboBox cbxCliente; private javax.swing.JComboBox cbxFuncionario; private javax.swing.JComboBox cbxParcelas; private javax.swing.JComboBox cbxTipoPagamento; private java.util.List<br.com.tcc.entity.Cliente> clienteList; private javax.persistence.Query clienteQuery; private javax.persistence.EntityManager entityManager; private java.util.List<br.com.tcc.entity.Funcionario> funcionarioList; private javax.persistence.Query funcionarioQuery; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel lblCodigo; private javax.swing.JTable tblRegistro; private java.util.List<br.com.tcc.entity.Tipopagamento> tipoPagamentoList; private javax.persistence.Query tipoPagamentoQuery; private javax.swing.JFormattedTextField txfVencimento; private javax.swing.JTextField txtCodigo; private javax.swing.JTextField txtCompra; private javax.swing.JTextField txtDesconto; private javax.swing.JTextField txtTotal; private java.util.List<br.com.tcc.entity.Vendadetalhe> vendaDetalheList; private javax.persistence.Query vendaDetalheQuery; private java.util.List<br.com.tcc.entity.Vendaregistro> vendaRegistroList; private javax.persistence.Query vendaRegistroQuery; private org.jdesktop.beansbinding.BindingGroup bindingGroup; // End of variables declaration//GEN-END:variables }