Sie sind auf Seite 1von 16

File Laporan_voucher.java import java.sql.*; import javax.swing.*; import java.awt.event.*; import java.text.*; import java.util.

*;;

166
public class laporan_voucher extends javax.swing.JInternalFrame { //=================================BATAS EDIT============================= // manggil prosedur koneksiDatabase pada class koneksi_database pada file koneksi_database.java Connection kon = new koneksi_database().koneksiDatabase(); // BUAT JUDUL HEADER TABEL_1.... javax.swing.table.DefaultTableModel tabLapVoucher = new javax.swing.table.DefaultTableModel(null, new String[]{"No Faktur","Nama Barang"," Jumlah "," Harga Beli "," Harga Jual "," Total Detail","Nama Petugas","Tanggal"}) { public boolean isCellEditable(int iRows, int iCols) { return false; } }; public void hapustabel() { int row = tabLapVoucher.getRowCount(); for (int k=0; k < row ; k++ ) { tabLapVoucher.removeRow(0); } } public void tampilkandataketabel() { long tb = 0; long tj = 0; NumberFormat nf = NumberFormat.getNumberInstance(); hapustabel(); try { String sql = "select b.no_faktur,c.nama,b.jumlah,b.harga_beli,b.harga_jual,b.total_detail,d.nama,a.tanggal from tb_jual a, tb_detail_jual b, tb_barang c, tb_petugas d where a.no_faktur = b.no_faktur and c.id_barang =b.id_barang and d.id_petugas=a.id_petugas order by no_faktur,c.nama DESC;"; Statement stat = kon.createStatement(); ResultSet rs = stat.executeQuery(sql); while (rs.next()) { String faktur = rs.getString(1); String brg = rs.getString(2); String jum = rs.getString(3); String hb= rs.getString(4); String hj= rs.getString(5); String tot = rs.getString(6); String nama = rs.getString(7); String tgl = rs.getString(8); int hb1 = Integer.parseInt(hb) *Integer.parseInt(jum); int hj1 = Integer.parseInt(hj) *Integer.parseInt(jum);

tb += hb1; tj += hj1;

167
String[] data = {faktur ,brg , nf.format(Integer.parseInt(jum)),nf.format(Integer.parseInt(hb)),nf.format(Integer.parseInt(hj)),tot,nama , tgl}; tabLapVoucher.addRow(data); } this.jLabel9.setText("Rp " + nf.format(tj)); this.jLabel7.setText("Rp " + nf.format(tb)); this.jLabel5.setText("Rp " + nf.format(tj-tb)); } catch (Exception e) { System.out.println("Error Tampilkan data ke tabel : " + e); } } public void idpeg() { try { String sql = "select distinct nama from tb_petugas order by nama"; Statement stat = kon.createStatement(); ResultSet rs = stat.executeQuery(sql); this.jComboBox1.removeAllItems(); this.jComboBox1.addItem("Pilih"); while (rs.next()) { String peg = rs.getString(1); this.jComboBox1.addItem(peg); } } catch (Exception e) { System.out.println("Error Tampilkan data petugas : " + e); } } public String getIdPeg(String nama) { String id=""; try { String sql = "select id_petugas from tb_petugas where nama = '" + nama + "'"; Statement stat = kon.createStatement(); ResultSet rs = stat.executeQuery(sql); rs.last(); if(rs.getRow()>0) { rs.first(); id = rs.getString(1); } } catch (Exception e) { System.out.println("Error getIdPeg : " + e + "\n"); }

return id;

168
} //=================================BATAS EDIT============================= /** Creates new form laporan_voucher */ public laporan_voucher() { String tgl; initComponents(); tampilkandataketabel(); idpeg(); this.jButton1.setVisible(false); this.jComboBox2.removeAllItems(); this.jComboBox3.removeAllItems(); this.jComboBox4.removeAllItems(); this.jComboBox5.removeAllItems(); this.jComboBox2.addItem("Pilih"); this.jComboBox2.addItem("Harian"); this.jComboBox2.addItem("Bulanan"); this.jComboBox2.addItem("Tahunan"); this.jComboBox1.setEnabled(false); this.jComboBox2.setEnabled(false); this.jComboBox3.setEnabled(false); this.jComboBox4.setEnabled(false); this.jComboBox5.setEnabled(false); this.jComboBox3.addItem("Pilih"); for(int t = 1; t<=31; t++) { tgl = ""; tgl = Integer.toString(t); if(tgl.length()==1) { tgl = "0" + tgl; } this.jComboBox3.addItem(tgl); } this.jComboBox4.addItem("Pilih"); this.jComboBox4.addItem("Januari"); this.jComboBox4.addItem("Februari"); this.jComboBox4.addItem("Maret"); this.jComboBox4.addItem("April"); this.jComboBox4.addItem("Mei"); this.jComboBox4.addItem("Juni"); this.jComboBox4.addItem("Juli"); this.jComboBox4.addItem("Agustus"); this.jComboBox4.addItem("September"); this.jComboBox4.addItem("Oktober"); this.jComboBox4.addItem("November"); this.jComboBox4.addItem("Desember"); //MEMBUAT DATE Calendar dt = Calendar.getInstance();

169
int th = dt.get(dt.YEAR); this.jComboBox5.addItem("Pilih"); for (int j = 2007; j<=th; j++) {

String tahun = Integer.toString(j); this.jComboBox5.addItem(tahun); } } /** 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"> private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jPanel1 = new javax.swing.JPanel(); jCheckBox1 = new javax.swing.JCheckBox(); jLabel1 = new javax.swing.JLabel(); jComboBox1 = new javax.swing.JComboBox(); jCheckBox2 = new javax.swing.JCheckBox(); jLabel2 = new javax.swing.JLabel(); jComboBox2 = new javax.swing.JComboBox(); jLabel3 = new javax.swing.JLabel(); jComboBox3 = new javax.swing.JComboBox(); jComboBox4 = new javax.swing.JComboBox(); jComboBox5 = new javax.swing.JComboBox(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jButton4 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); getContentPane().setLayout(null); 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" } )); this.jTable1.setModel(tabLapVoucher);

170
jScrollPane1.setViewportView(jTable1); getContentPane().add(jScrollPane1); jScrollPane1.setBounds(20, 20, 950, 450); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("")); jPanel1.setLayout(null); jCheckBox1.setText("Berdasarkan Petugas"); jCheckBox1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) { jCheckBox1ActionPerformed(evt); } }); jPanel1.add(jCheckBox1); jCheckBox1.setBounds(10, 10, 160, 23); jLabel1.setText("Nama Petugas :"); jPanel1.add(jLabel1); jLabel1.setBounds(70, 30, 110, 20); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); jPanel1.add(jComboBox1); jComboBox1.setBounds(190, 30, 150, 20); jCheckBox2.setText("Berdasarkan Waktu"); jCheckBox2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jCheckBox2ActionPerformed(evt); } }); jPanel1.add(jCheckBox2); jCheckBox2.setBounds(10, 60, 150, 23); jLabel2.setText("Jenis Laporan :"); jPanel1.add(jLabel2); jLabel2.setBounds(70, 90, 100, 20); jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); jComboBox2.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { jComboBox2ItemStateChanged(evt); } }); jPanel1.add(jComboBox2); jComboBox2.setBounds(190, 90, 150, 20); jLabel3.setText("Tanggal :"); jPanel1.add(jLabel3); jLabel3.setBounds(70, 120, 60, 20); jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); jPanel1.add(jComboBox3);

171
jComboBox3.setBounds(130, 120, 50, 20); jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); jPanel1.add(jComboBox4); jComboBox4.setBounds(190, 120, 150, 20); jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); jPanel1.add(jComboBox5); jComboBox5.setBounds(350, 120, 80, 20); getContentPane().add(jPanel1); jPanel1.setBounds(30, 490, 440, 160); jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel4.setText("Total Pendapatan :"); getContentPane().add(jLabel4); jLabel4.setBounds(640, 570, 150, 30);

jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel5.setText("0"); getContentPane().add(jLabel5); jLabel5.setBounds(800, 570, 150, 30); jButton4.setText("Keluar"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); getContentPane().add(jButton4); jButton4.setBounds(840, 620, 90, 30); jButton3.setText("Refresh"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); getContentPane().add(jButton3); jButton3.setBounds(740, 620, 100, 30); jButton2.setText("Lihat"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); getContentPane().add(jButton2); jButton2.setBounds(660, 620, 80, 30); jButton1.setText("Cetak"); getContentPane().add(jButton1);

172
jButton1.setBounds(570, 620, 90, 30); jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel6.setText("Total Pembelian :"); getContentPane().add(jLabel6); jLabel6.setBounds(640, 530, 150, 30); jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel7.setText("0"); getContentPane().add(jLabel7); jLabel7.setBounds(800, 530, 150, 30); jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel8.setText("Total Penjualan :"); getContentPane().add(jLabel8); jLabel8.setBounds(640, 490, 150, 30); jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jLabel9.setText("0"); getContentPane().add(jLabel9); jLabel9.setBounds(800, 490, 150, 30); pack(); }// </editor-fold> private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {

// berdasarkan ptugas if(this.jCheckBox1.isSelected()==true) { this.jComboBox1.setSelectedIndex(0); this.jComboBox1.setEnabled(true); this.jComboBox1.requestFocus(); } else if(this.jCheckBox2.isSelected()==false) { this.jComboBox1.setSelectedIndex(0); this.jComboBox1.setEnabled(false); this.jButton3.requestFocus(); } } private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) { // BERDASARKAN WAKTU if(this.jCheckBox2.isSelected()==true) { this.jComboBox2.setSelectedItem("Pilih"); this.jComboBox3.setSelectedItem("Pilih"); this.jComboBox4.setSelectedItem("Pilih"); this.jComboBox5.setSelectedItem("Pilih"); this.jComboBox2.setEnabled(true); this.jComboBox3.setEnabled(true); this.jComboBox4.setEnabled(true);

173
this.jComboBox5.setEnabled(true); this.jComboBox2.requestFocus(); } else if(this.jCheckBox2.isSelected()==false) { this.jComboBox2.setSelectedItem("Pilih"); this.jComboBox3.setSelectedItem("Pilih"); this.jComboBox4.setSelectedItem("Pilih"); this.jComboBox5.setSelectedItem("Pilih"); this.jComboBox2.setEnabled(false); this.jComboBox3.setEnabled(false); this.jComboBox4.setEnabled(false); this.jComboBox5.setEnabled(false); this.jButton3.requestFocus(); } } private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) { //LAPORAN TANGGAL String lap = ""; lap = (String) this.jComboBox2.getSelectedItem(); if(lap != null) { if(lap.equals("Harian")) { this.jComboBox3.setEnabled(true); this.jComboBox4.setEnabled(true); this.jComboBox5.setEnabled(true); this.jComboBox3.setSelectedItem("Pilih"); this.jComboBox4.setSelectedItem("Pilih"); this.jComboBox5.setSelectedItem("Pilih");

this.jComboBox3.requestFocus(); } else if(lap.equals("Bulanan")) { this.jComboBox3.setEnabled(false); this.jComboBox4.setEnabled(true); this.jComboBox5.setEnabled(true); this.jComboBox3.setSelectedItem("Pilih"); this.jComboBox4.setSelectedItem("Pilih"); this.jComboBox5.setSelectedItem("Pilih"); this.jComboBox4.requestFocus(); } else if(lap.equals("Tahunan")) { this.jComboBox3.setEnabled(false); this.jComboBox4.setEnabled(false); this.jComboBox5.setEnabled(true); this.jComboBox3.setSelectedItem("Pilih"); this.jComboBox4.setSelectedItem("Pilih"); this.jComboBox5.setSelectedItem("Pilih"); this.jComboBox5.requestFocus(); } else if(lap.equals("Pilih")) { this.jComboBox3.setEnabled(false);

174
this.jComboBox4.setEnabled(false); this.jComboBox5.setEnabled(false); this.jComboBox3.setSelectedItem("Pilih"); this.jComboBox4.setSelectedItem("Pilih"); this.jComboBox5.setSelectedItem("Pilih"); this.jComboBox2.requestFocus(); } } } private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { // keluar dispose(); } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TOMBOL REFRESH tampilkandataketabel(); this.jComboBox2.setSelectedIndex(0); this.jComboBox3.setSelectedIndex(0); this.jComboBox4.setSelectedIndex(0); this.jComboBox5.setSelectedIndex(0); this.jComboBox1.setSelectedIndex(0); this.jComboBox1.setEnabled(false); this.jComboBox2.setEnabled(false); this.jComboBox3.setEnabled(false); this.jComboBox4.setEnabled(false); this.jComboBox5.setEnabled(false); this.jCheckBox1.setSelected(false); this.jCheckBox2.setSelected(false); this.jButton3.requestFocus(); }

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TOMBOL LIHAT if(this.jCheckBox1.isSelected()==true && this.jCheckBox2.isSelected()==false) { long tb = 0; long tj = 0; hapustabel(); NumberFormat nf = NumberFormat.getNumberInstance(); try { String sql = "select b.no_faktur,c.nama,b.jumlah,b.harga_beli,b.harga_jual,b.total_detail,d.nama,a.tanggal from tb_jual a, tb_detail_jual b, tb_barang c, tb_petugas d where a.no_faktur = b.no_faktur and c.id_barang =b.id_barang and d.id_petugas=a.id_petugas and d.id_petugas = '" + getIdPeg(this.jComboBox1.getSelectedItem().toString()) + "' order by no_faktur DESC"; Statement stat = kon.createStatement(); ResultSet rs = stat.executeQuery(sql); while (rs.next()) { String faktur = rs.getString(1); String brg = rs.getString(2); String jum = rs.getString(3); String hb= rs.getString(4);

175
String hj= rs.getString(5); String tot = rs.getString(6); String nama = rs.getString(7); String tgl = rs.getString(8); int hb1 = Integer.parseInt(hb) *Integer.parseInt(jum); int hj1 = Integer.parseInt(hj) *Integer.parseInt(jum); tb += hb1; tj += hj1; String[] data = {faktur ,brg , nf.format(Integer.parseInt(jum)),nf.format(Integer.parseInt(hb)),nf.format(Integer.parseInt(hj)),tot,nama , tgl}; tabLapVoucher.addRow(data); } this.jLabel9.setText("Rp " + nf.format(tj)); this.jLabel7.setText("Rp " + nf.format(tb)); this.jLabel5.setText("Rp " + nf.format(tj-tb)); rs.last(); if(rs.getRow()==0) { this.jLabel5.setText("Rp 0"); this.jLabel7.setText("Rp 0"); this.jLabel9.setText("Rp 0"); } } catch (Exception e) { System.out.println("Error Cari data berdasarkan nama pegawai : " + e); } } else if(this.jCheckBox2.isSelected()==true && this.jCheckBox1.isSelected()==false) {

String tg = (String) this.jComboBox2.getSelectedItem(); String hr = (String) this.jComboBox3.getSelectedItem(); String bln = (String) this.jComboBox4.getSelectedItem(); String thn = (String) this.jComboBox5.getSelectedItem(); String kondisi = ""; long tb = 0; long tj = 0; if(tg.equals("Harian")) { hapustabel(); NumberFormat nf = NumberFormat.getNumberInstance(); kondisi = hr + " " + bln + " " + thn; try { String sql = "select b.no_faktur,c.nama,b.jumlah,b.harga_beli,b.harga_jual,b.total_detail,d.nama,a.tanggal from tb_jual a, tb_detail_jual b, tb_barang c, tb_petugas d where a.no_faktur = b.no_faktur and c.id_barang =b.id_barang and d.id_petugas=a.id_petugas and tanggal like '" + kondisi + "' order by no_faktur DESC"; Statement stat = kon.createStatement(); ResultSet rs = stat.executeQuery(sql); while (rs.next())

176
{ String faktur = rs.getString(1); String brg = rs.getString(2); String jum = rs.getString(3); String hb= rs.getString(4); String hj= rs.getString(5); String tot = rs.getString(6); String nama = rs.getString(7); String tgl = rs.getString(8); int hb1 = Integer.parseInt(hb) *Integer.parseInt(jum); int hj1 = Integer.parseInt(hj) *Integer.parseInt(jum); tb += hb1; tj += hj1; String[] data = {faktur ,brg , nf.format(Integer.parseInt(jum)),nf.format(Integer.parseInt(hb)),nf.format(Integer.parseInt(hj)),tot,nama , tgl}; tabLapVoucher.addRow(data); } this.jLabel9.setText("Rp " + nf.format(tj)); this.jLabel7.setText("Rp " + nf.format(tb)); this.jLabel5.setText("Rp " + nf.format(tj-tb)); rs.last(); if(rs.getRow()==0) { this.jLabel5.setText("Rp 0"); this.jLabel7.setText("Rp 0"); this.jLabel9.setText("Rp 0"); } } catch (Exception e) { System.out.println("Error Cari data berdasarkan Hari : " + e); }

} else if(tg.equals("Bulanan")) { hapustabel(); NumberFormat nf = NumberFormat.getNumberInstance(); kondisi = bln + " " + thn; try { String sql = "select b.no_faktur,c.nama,b.jumlah,b.harga_beli,b.harga_jual,b.total_detail,d.nama,a.tanggal from tb_jual a, tb_detail_jual b, tb_barang c, tb_petugas d where a.no_faktur = b.no_faktur and c.id_barang =b.id_barang and d.id_petugas=a.id_petugas and tanggal like '%" + kondisi + "' order by no_faktur DESC"; Statement stat = kon.createStatement(); ResultSet rs = stat.executeQuery(sql); while (rs.next()) { String faktur = rs.getString(1); String brg = rs.getString(2); String jum = rs.getString(3); String hb= rs.getString(4); String hj= rs.getString(5);

177
String tot = rs.getString(6); String nama = rs.getString(7); String tgl = rs.getString(8); int hb1 = Integer.parseInt(hb) *Integer.parseInt(jum); int hj1 = Integer.parseInt(hj) *Integer.parseInt(jum); tb += hb1; tj += hj1; String[] data = {faktur ,brg , nf.format(Integer.parseInt(jum)),nf.format(Integer.parseInt(hb)),nf.format(Integer.parseInt(hj)),tot,nama , tgl}; tabLapVoucher.addRow(data); } this.jLabel9.setText("Rp " + nf.format(tj)); this.jLabel7.setText("Rp " + nf.format(tb)); this.jLabel5.setText("Rp " + nf.format(tj-tb)); rs.last(); if(rs.getRow()==0) { this.jLabel5.setText("Rp 0"); this.jLabel7.setText("Rp 0"); this.jLabel9.setText("Rp 0"); } } catch (Exception e) { System.out.println("Error Cari data berdasarkan Bulan : " + e); } } else if(tg.equals("Tahunan")) { hapustabel(); NumberFormat nf = NumberFormat.getNumberInstance(); kondisi = thn;

try { String sql = "select b.no_faktur,c.nama,b.jumlah,b.harga_beli,b.harga_jual,b.total_detail,d.nama,a.tanggal from tb_jual a, tb_detail_jual b, tb_barang c, tb_petugas d where a.no_faktur = b.no_faktur and c.id_barang =b.id_barang and d.id_petugas=a.id_petugas and tanggal like '%" + kondisi + "' order by no_faktur DESC"; Statement stat = kon.createStatement(); ResultSet rs = stat.executeQuery(sql); while (rs.next()) { String faktur = rs.getString(1); String brg = rs.getString(2); String jum = rs.getString(3); String hb= rs.getString(4); String hj= rs.getString(5); String tot = rs.getString(6); String nama = rs.getString(7); String tgl = rs.getString(8); int hb1 = Integer.parseInt(hb) *Integer.parseInt(jum); int hj1 = Integer.parseInt(hj) *Integer.parseInt(jum);

178
tb += hb1; tj += hj1; String[] data = {faktur ,brg , nf.format(Integer.parseInt(jum)),nf.format(Integer.parseInt(hb)),nf.format(Integer.parseInt(hj)),tot,nama , tgl}; tabLapVoucher.addRow(data); } this.jLabel9.setText("Rp " + nf.format(tj)); this.jLabel7.setText("Rp " + nf.format(tb)); this.jLabel5.setText("Rp " + nf.format(tj-tb)); rs.last(); if(rs.getRow()==0) { this.jLabel5.setText("Rp 0"); this.jLabel7.setText("Rp 0"); this.jLabel9.setText("Rp 0"); } } catch (Exception e) { System.out.println("Error Cari data berdasarkan Tahun : " + e); } } } else if(this.jCheckBox2.isSelected()==true && this.jCheckBox1.isSelected()==true) { String tg = (String) this.jComboBox2.getSelectedItem(); String hr = (String) this.jComboBox3.getSelectedItem(); String bln = (String) this.jComboBox4.getSelectedItem(); String thn = (String) this.jComboBox5.getSelectedItem(); String kondisi = ""; long tb = 0; long tj = 0; if(tg.equals("Harian"))

{ hapustabel(); NumberFormat nf = NumberFormat.getNumberInstance(); kondisi = hr + " " + bln + " " + thn; try { String sql = "select b.no_faktur,c.nama,b.jumlah,b.harga_beli,b.harga_jual,b.total_detail,d.nama,a.tanggal from tb_jual a, tb_detail_jual b, tb_barang c, tb_petugas d where a.no_faktur = b.no_faktur and c.id_barang =b.id_barang and d.id_petugas=a.id_petugas and tanggal like '" + kondisi + "' and d.id_petugas = '" + getIdPeg(this.jComboBox1.getSelectedItem().toString()) + "' order by no_faktur DESC"; Statement stat = kon.createStatement(); ResultSet rs = stat.executeQuery(sql); while (rs.next()) { String faktur = rs.getString(1); String brg = rs.getString(2); String jum = rs.getString(3); String hb= rs.getString(4);

179
String hj= rs.getString(5); String tot = rs.getString(6); String nama = rs.getString(7); String tgl = rs.getString(8); int hb1 = Integer.parseInt(hb) *Integer.parseInt(jum); int hj1 = Integer.parseInt(hj) *Integer.parseInt(jum); tb += hb1; tj += hj1; String[] data = {faktur ,brg , nf.format(Integer.parseInt(jum)),nf.format(Integer.parseInt(hb)),nf.format(Integer.parseInt(hj)),tot,nama , tgl}; tabLapVoucher.addRow(data); } this.jLabel9.setText("Rp " + nf.format(tj)); this.jLabel7.setText("Rp " + nf.format(tb)); this.jLabel5.setText("Rp " + nf.format(tj-tb)); rs.last(); if(rs.getRow()==0) { this.jLabel5.setText("Rp 0"); this.jLabel7.setText("Rp 0"); this.jLabel9.setText("Rp 0"); } } catch (Exception e) { System.out.println("Error Cari data berdasarkan Hari : " + e); } } else if(tg.equals("Bulanan")) { hapustabel(); NumberFormat nf = NumberFormat.getNumberInstance(); kondisi = bln + " " + thn; try

{ String sql = "select b.no_faktur,c.nama,b.jumlah,b.harga_beli,b.harga_jual,b.total_detail,d.nama,a.tanggal from tb_jual a, tb_detail_jual b, tb_barang c, tb_petugas d where a.no_faktur = b.no_faktur and c.id_barang =b.id_barang and d.id_petugas=a.id_petugas and tanggal like '%" + kondisi + "' and d.id_petugas = '" + getIdPeg(this.jComboBox1.getSelectedItem().toString()) + "' order by no_faktur DESC"; Statement stat = kon.createStatement(); ResultSet rs = stat.executeQuery(sql); while (rs.next()) { String faktur = rs.getString(1); String brg = rs.getString(2); String jum = rs.getString(3); String hb= rs.getString(4); String hj= rs.getString(5); String tot = rs.getString(6); String nama = rs.getString(7); String tgl = rs.getString(8);

180
int hb1 = Integer.parseInt(hb) *Integer.parseInt(jum); int hj1 = Integer.parseInt(hj) *Integer.parseInt(jum); tb += hb1; tj += hj1; String[] data = {faktur ,brg , nf.format(Integer.parseInt(jum)),nf.format(Integer.parseInt(hb)),nf.format(Integer.parseInt(hj)),tot,nama , tgl}; tabLapVoucher.addRow(data); } this.jLabel9.setText("Rp " + nf.format(tj)); this.jLabel7.setText("Rp " + nf.format(tb)); this.jLabel5.setText("Rp " + nf.format(tj-tb)); rs.last(); if(rs.getRow()==0) { this.jLabel5.setText("Rp 0"); this.jLabel7.setText("Rp 0"); this.jLabel9.setText("Rp 0"); } } catch (Exception e) { System.out.println("Error Cari data berdasarkan Bulan : " + e); } } else if(tg.equals("Tahunan")) { hapustabel(); NumberFormat nf = NumberFormat.getNumberInstance(); kondisi = thn; try { String sql = "select b.no_faktur,c.nama,b.jumlah,b.harga_beli,b.harga_jual,b.total_detail,d.nama,a.tanggal from tb_jual a, tb_detail_jual b, tb_barang c, tb_petugas d where a.no_faktur = b.no_faktur and c.id_barang =b.id_barang

and d.id_petugas=a.id_petugas and tanggal like '%" + kondisi + "' and d.id_petugas = '" + getIdPeg(this.jComboBox1.getSelectedItem().toString()) + "' order by no_faktur DESC"; Statement stat = kon.createStatement(); ResultSet rs = stat.executeQuery(sql); while (rs.next()) { String faktur = rs.getString(1); String brg = rs.getString(2); String jum = rs.getString(3); String hb= rs.getString(4); String hj= rs.getString(5); String tot = rs.getString(6); String nama = rs.getString(7); String tgl = rs.getString(8); int hb1 = Integer.parseInt(hb) *Integer.parseInt(jum); int hj1 = Integer.parseInt(hj) *Integer.parseInt(jum); tb += hb1; tj += hj1;

181
String[] data = {faktur ,brg , nf.format(Integer.parseInt(jum)),nf.format(Integer.parseInt(hb)),nf.format(Integer.parseInt(hj)),tot,nama , tgl}; tabLapVoucher.addRow(data); } this.jLabel9.setText("Rp " + nf.format(tj)); this.jLabel7.setText("Rp " + nf.format(tb)); this.jLabel5.setText("Rp " + nf.format(tj-tb)); rs.last(); if(rs.getRow()==0) { this.jLabel5.setText("Rp 0"); this.jLabel7.setText("Rp 0"); this.jLabel9.setText("Rp 0"); } } catch (Exception e) { System.out.println("Error Cari data berdasarkan Tahun : " + e); } } } } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JCheckBox jCheckBox1; private javax.swing.JCheckBox jCheckBox2; private javax.swing.JComboBox jComboBox1; private javax.swing.JComboBox jComboBox2; private javax.swing.JComboBox jComboBox3; private javax.swing.JComboBox jComboBox4; private javax.swing.JComboBox jComboBox5; 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.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; }

Das könnte Ihnen auch gefallen