Setelah kita membuat form pengadaan, langkah selanjutnya kita akan membuat Form Transaksi Penjualan.
Buat desain Form Transaksi Penjualan seperti gambar dibawah ini
Form ini juga memiliki persamaan dengan form transaksi pengadaan barang, yaitu membuat ID otomatis. Kalau pada form transaksi pengadaan membuat ID Pengadaan maka dalam form ini akan membuat ID Transaksi secara otomatis. Masih sama dengan sebelumnya menggunakan tanggal transaksi saat itu.
Ketika user menekan (meng-klik) button Transaksi Baru maka secara otomatis ID Transaksi akan muncul.
maka nama barang Buku Sidu 56 berkurang
jika mau membayar isikan nominal uang pada kolom bayar. lalu tekan enter maka hasil tampilannya seperti dibawah ini.
jika mau membayar isikan nominal uang pada kolom bayar. lalu tekan enter maka hasil tampilannya seperti dibawah ini.
Setelah membuat interface seperti di atas langkah selanjutnya membuat kunci koneksi dan mendeklarasikan kunci koneksi
sorce codenya pembuatan form penjualan :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package database;
import database_koneksi.koneksi;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
*
*/
public class penjualan extends javax.swing.JFrame {
koneksi k;
Statement statement;
ResultSet resultSet;
int count = 0;
double total =0;
boolean belumTrans = false;
/**
* Creates new form penjualan
*/
public penjualan() {
initComponents();
k = new koneksi();
ViewBarang();
ViewTrans();
KondisiAwal();
}
private void KondisiAwal() {
btnInsert.setEnabled(false);
btnDelete.setEnabled(false);
txtIDBarang.setEnabled(false);
txtBarang.setEnabled(false);
txtJumlah.setEditable(false);
tblBarang.setEnabled(false);
txtBayar.setEnabled(false);
Clear();
btnTransBaru.setEnabled(true);
//idPenjualan = "";
belumTrans = false;
jdate.setEnabled(false);
}
private void KondisiAktif() {
btnInsert.setEnabled(true);
btnDelete.setEnabled(true);
//txtIDBarang.setEnabled(true);
txtJumlah.setEditable(true);
tblPenjualan.setEnabled(true);
Clear();
tblBarang.setEnabled(true);
btnTransBaru.setEnabled(false);
txtBarang.setEnabled(true);
txtBayar.setEnabled(true);
belumTrans = true;
jdate.setEnabled(false);
}
public void Insert() {
int stok = 0;
String idPenjualan = txtNota.getText();
String idBarang = txtIDBarang.getText();
String jumlah = txtJumlah.getText();
double totalHarga = Double.parseDouble(txtJumlah.getText()) * Double.parseDouble(txtHarga.getText());
int temp = Integer.valueOf(txtJumlah.getText());
String query = "SELECT stok FROM barang WHERE id_barang='" + idBarang + "'";
try {
statement = k.connection.createStatement();
resultSet = statement.executeQuery(query);
while (resultSet.next()) {
stok = Integer.valueOf(resultSet.getString(1));
}
if (stok == 0) {
JOptionPane.showMessageDialog(null, "Maaf, jumlah stok saat ini tidak mencukupi!");
} else if (stok < temp) {
JOptionPane.showMessageDialog(null, "Maaf, jumlah stok saat ini tidak mencukupi!");
} else {
String sql = "INSERT INTO rel_penjualan_barang VALUES('" + idBarang + "','" + idPenjualan + "','" + jumlah + "','" + HitungLaba() + "','" + totalHarga + "')";
try {
statement = k.connection.createStatement();
statement.executeUpdate(sql);
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
Hitung();
}
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
}
private String AutoID() {
String idPenjualan = "";
try {
Date date= new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String tanggal = dateFormat.format(date);
jdate.setDate(date);
SimpleDateFormat dateFormat2 = new SimpleDateFormat("dd.MM.YYYY");
String tanggal2 = dateFormat2.format(date);
count = 100;
String sqlTanggal = "SELECT tanggal_penjualan,id_penjualan FROM penjualan";
resultSet = statement.executeQuery(sqlTanggal);
while (resultSet.next()) {
String data1 = resultSet.getString(1);
String data2 = resultSet.getString(2);
if (data1.equals(tanggal)) {
if (count == Integer.valueOf(data2.substring(14, 17))) {
count++;
}
}
}
idPenjualan = "TJ." + tanggal + "." + count;
String sql = "INSERT INTO penjualan VALUES('" + idPenjualan + "','fedra','" + tanggal + "',0)";
statement.executeUpdate(sql);
txtNota.setText(idPenjualan);
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
return idPenjualan;
}
public void ViewBarang() {
DefaultTableModel isitable = new DefaultTableModel();
isitable.addColumn("ID Barang");
isitable.addColumn("Nama Barang");
isitable.addColumn("Stok Barang");
isitable.addColumn("Harga Jual");
String sql = "SELECT id_barang,nama_barang,stok,hargajual FROM barang WHERE stok>0 ORDER BY id_barang ASC";
try {
statement = k.connection.createStatement();
resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
isitable.addRow(new Object[]{resultSet.getString(1), resultSet.getString(2), resultSet.getString(3), resultSet.getString(4)});
}
tblBarang.setModel(isitable);
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
}
public void ViewTrans() {
DefaultTableModel isitable = new DefaultTableModel();
isitable.addColumn("ID Penjualan");
isitable.addColumn("ID Barang");
isitable.addColumn("Nama Barang");
isitable.addColumn("Harga");
isitable.addColumn("Jumlah");
isitable.addColumn("Total Harga");
String idPenjualan = txtNota.getText();
double subTotal = Double.parseDouble(txtJumlah.getText()) * Double.parseDouble(txtHarga.getText());
String sql = "SELECT r.id_penjualan,r.id_barang,b.nama_barang,b.hargajual,r.jumlah,r.total_harga FROM rel_penjualan_barang r,barang b WHERE r.id_barang=b.id_barang AND r.id_penjualan='" + idPenjualan + "' ORDER BY id_barang ASC";
try {
statement = k.connection.createStatement();
resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
isitable.addRow(new Object[]{resultSet.getString(1), resultSet.getString(2), resultSet.getString(3), resultSet.getString(4), resultSet.getString(5), resultSet.getString(6)});
}
tblPenjualan.setModel(isitable);
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
}
public void UpdateStok() {
int stok = 0;
String idBarang = txtIDBarang.getText();
int jumlah = Integer.valueOf(txtJumlah.getText());
String query = "SELECT stok FROM barang WHERE id_barang='" + idBarang + "'";
try {
statement = k.connection.createStatement();
resultSet = statement.executeQuery(query);
while (resultSet.next()) {
stok = Integer.valueOf(resultSet.getString(1));
}
if (stok == 0) {
} else if (stok < jumlah) {
} else {
int updateStok = stok - jumlah;
String sql = "UPDATE barang SET stok='" + updateStok + "' WHERE id_barang='" + idBarang + "'";
try {
statement = k.connection.createStatement();
statement.executeUpdate(sql);
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
}
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
}
public void Hitung() {
String idPenjualan = txtNota.getText();
String sql = "SELECT SUM(total_harga) FROM rel_penjualan_barang WHERE id_penjualan='" + idPenjualan + "'";
try {
statement = k.connection.createStatement();
resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
txtTotal.setText(resultSet.getString(1));
}
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
}
private void UpdateTotal() {
String idPenjualan = txtNota.getText();
String total = txtTotal.getText();
String sql = "UPDATE penjualan SET total_penjualan='" + total + "' WHERE id_penjualan='" + idPenjualan + "'";
try {
statement = k.connection.createStatement();
statement.executeUpdate(sql);
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
}
private void Kembali() {
double total = Double.valueOf(txtTotal.getText());
double bayar = Double.valueOf(txtBayar.getText());
if (bayar < total) {
JOptionPane.showMessageDialog(null, "Maaf, uang yang Anda bayarkan tidak mencukupi!");
} else {
double kembali = Double.parseDouble(txtBayar.getText()) - Double.parseDouble(txtTotal.getText());
txtKembali.setText(Double.toString(kembali));
}
}
private double HitungLaba() {
Vector<String> vektorIdPengadaan = new Vector<>();
Vector<String> vektorIdBarang = new Vector<>();
Vector<Integer> jum = new Vector<>();
Vector<Double> hargaBeli = new Vector<>();
Vector<Double> hargaJual = new Vector<>();
double laba = 0;
try {
String namaBarang = txtIDBarang.getText();
String sql = "SELECT r.id_pengadaan,r.id_barang,r.harga_beli_satuan,b.hargajual,r.belum_terjual FROM rel_pengadaan_barang r,barang b WHERE r.id_barang=b.id_barang AND r.id_barang='" + namaBarang + "' AND r.belum_terjual>0";
resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
vektorIdPengadaan.addElement(resultSet.getString(1));
vektorIdBarang.addElement(resultSet.getString(2));
hargaBeli.addElement(resultSet.getDouble(3));
hargaJual.addElement(resultSet.getDouble(4));
jum.addElement(resultSet.getInt(5));
}
int jumlah;
int jumlahJual = Integer.valueOf(txtJumlah.getText());
for (int i = 0; i < vektorIdPengadaan.size(); i++) {
jumlah = jum.elementAt(i) - jumlahJual;
if (jumlah >= 0) {
try {
String query = "UPDATE rel_pengadaan_barang SET belum_terjual='" + jumlah + "' WHERE id_pengadaan='" + vektorIdPengadaan.elementAt(i) + "' AND id_barang='" + vektorIdBarang.elementAt(i) + "'";
statement.executeUpdate(query);
laba = laba + (hargaJual.elementAt(i) - hargaBeli.elementAt(i)) * jumlahJual;
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
break;
} else {
try {
String query1 = "UPDATE rel_pengadaan_barang SET belum_terjual='" + 0 + "' WHERE id_pengadaan='" + vektorIdPengadaan.elementAt(i) + "' AND id_barang='" + vektorIdBarang.elementAt(i) + "'";
statement.executeUpdate(query1);
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
laba = laba + (hargaJual.elementAt(i) - hargaBeli.elementAt(i)) * jum.elementAt(i);
jumlahJual = -1 * jumlah;
}
}
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
return laba;
}
private void Cari() {
DefaultTableModel isitable = new DefaultTableModel();
isitable.addColumn("ID Barang");
isitable.addColumn("Nama Barang");
isitable.addColumn("Stok Barang");
isitable.addColumn("Harga Jual");
String cari = txtBarang.getText();
String sql = "SELECT id_barang,nama_barang,stok,hargajual FROM barang WHERE id_barang LIKE '%" + cari + "%' OR nama_barang LIKE '%" + cari + "%' ORDER BY id_barang ASC";
try {
statement = k.connection.createStatement();
resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
isitable.addRow(new Object[]{resultSet.getString(1), resultSet.getString(2), resultSet.getString(3), resultSet.getString(4)});
}
tblBarang.setModel(isitable);
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
}
public void Transaksi() {
btnTransBaru.setEnabled(true);
String total = txtTotal.getText();
String bayar = txtBayar.getText();
String kembali = txtKembali.getText();
JOptionPane.showMessageDialog(null, "Total : Rp. " + total + "\nBayar : Rp. " + bayar + "\nKembali : Rp. " + kembali);
txtNota.setText("0");
txtTotal.setText("0");
txtBayar.setText("0");
txtKembali.setText("0");
tblPenjualan.removeAll();
ViewTrans();
}
private void DeleteData() {
int stokAsal = 0;
String idPenjualan = tblPenjualan.getValueAt(tblPenjualan.getSelectedRow(), 0).toString();
String idBarang = tblPenjualan.getValueAt(tblPenjualan.getSelectedRow(), 1).toString();
int stok = Integer.parseInt(txtJumlah.getText());
String sql = "DELETE FROM rel_penjualan_barang WHERE id_penjualan='" + idPenjualan + "' AND id_barang='" + idBarang + "'";
try {
statement = k.connection.createStatement();
statement.executeUpdate(sql);
txtTotal.setText(String.valueOf(Double.parseDouble(txtTotal.getText()) - Double.parseDouble(txtSubTotal.getText())));
String view = "SELECT stok_barang FROM barang WHERE id_barang='" + idBarang + "'";
statement = k.connection.createStatement();
resultSet = statement.executeQuery(view);
while (resultSet.next()) {
stokAsal = Integer.valueOf(resultSet.getString(1));
}
int updateStok = stokAsal + stok;
String query = "UPDATE barang SET stok='" + updateStok + "' WHERE id_penjualan='" + idPenjualan + "' AND id_barang='" + idBarang + "'";
try {
statement = k.connection.createStatement();
statement.executeUpdate(query);
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
String query2 = "UPDATE rel_pengadaan_barang SET belum_terjual='" + updateStok + "' WHERE id_penjualan='" + idPenjualan + "' AND id_barang='" + idBarang + "'";
try {
statement = k.connection.createStatement();
statement.executeUpdate(query2);
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
}
public void cancelTrans() {
String idTrans = txtNota.getText();
String sql = "DELETE FROM penjualan WHERE id_penjualan='" + idTrans + "'";
try {
statement = k.connection.createStatement();
statement.executeUpdate(sql);
} catch (Exception e) {
System.out.println("Terjadi kesalahan, karena " + e.getMessage());
JOptionPane.showMessageDialog(null, "Terjadi kesalahan, karena " + e.getMessage());
}
}
public void Clear() {
txtIDBarang.setText(null);
txtBarang.setText(null);
txtJumlah.setText("0");
txtHarga.setText("0");
}
/**
* 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() {
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtIDBarang = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
tblBarang = new javax.swing.JTable();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
txtJumlah = new javax.swing.JTextField();
txtHarga = new javax.swing.JTextField();
btnTransBaru = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
tblPenjualan = new javax.swing.JTable();
jLabel6 = new javax.swing.JLabel();
txtNota = new javax.swing.JLabel();
txtBarang = new javax.swing.JTextField();
txtSubTotal = new javax.swing.JTextField();
jdate = new com.toedter.calendar.JDateChooser();
jPanel4 = new javax.swing.JPanel();
lbTotal = new javax.swing.JLabel();
lbBayar = new javax.swing.JLabel();
txtTotal = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
txtBayar = new javax.swing.JTextField();
txtKembali = new javax.swing.JLabel();
lbKembali = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
btnCancel = new javax.swing.JButton();
btnDelete = new javax.swing.JButton();
btnInsert = new javax.swing.JButton();
btnCancel1 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel1.setText("Tanggal");
jLabel2.setText("ID Barang / Nama Barang");
txtIDBarang.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
txtIDBarangKeyPressed(evt);
}
});
tblBarang.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"
}
));
tblBarang.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tblBarangMouseClicked(evt);
}
});
jScrollPane1.setViewportView(tblBarang);
jLabel4.setText("Jumlah");
jLabel5.setText("Harga");
txtJumlah.setText("0");
txtJumlah.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
txtJumlahKeyPressed(evt);
}
});
txtHarga.setText("0");
txtHarga.setEnabled(false);
btnTransBaru.setText("Transaksi Baru");
btnTransBaru.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTransBaruActionPerformed(evt);
}
});
tblPenjualan.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"
}
));
tblPenjualan.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tblPenjualanMouseClicked(evt);
}
});
jScrollPane2.setViewportView(tblPenjualan);
jLabel6.setText("ID Penjualan");
txtNota.setText("0");
txtNota.setEnabled(false);
txtBarang.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txtBarangKeyTyped(evt);
}
public void keyPressed(java.awt.event.KeyEvent evt) {
txtBarangKeyPressed(evt);
}
});
txtSubTotal.setText("0");
txtSubTotal.setEnabled(false);
jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
lbTotal.setText("Total");
lbBayar.setText("Bayar");
txtTotal.setFont(new java.awt.Font("Tahoma", 1, 25)); // NOI18N
txtTotal.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
txtTotal.setText("0");
jLabel8.setText("Rp.");
jLabel10.setText("Rp.");
txtBayar.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
txtBayar.setText("0");
txtBayar.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
txtBayarKeyPressed(evt);
}
});
txtKembali.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
txtKembali.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
txtKembali.setText("0");
lbKembali.setText("Kembali");
jLabel13.setText("Rp.");
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addContainerGap(565, Short.MAX_VALUE)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbBayar)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbKembali)
.addComponent(lbTotal))
.addGap(50, 50, 50)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(jLabel10)
.addComponent(jLabel13))
.addGap(18, 18, 18)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtKembali, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
.addComponent(txtBayar))))
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbTotal)
.addComponent(txtTotal)
.addComponent(jLabel8))
.addGap(18, 18, 18)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbBayar)
.addComponent(jLabel10)
.addComponent(txtBayar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtKembali)
.addComponent(lbKembali)
.addComponent(jLabel13))
.addContainerGap(14, Short.MAX_VALUE))
);
jPanel3.setBackground(new java.awt.Color(204, 204, 204));
jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
btnCancel.setText("Cancel");
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelActionPerformed(evt);
}
});
btnDelete.setText("Delete");
btnDelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDeleteActionPerformed(evt);
}
});
btnInsert.setText("Insert");
btnInsert.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnInsertActionPerformed(evt);
}
});
btnCancel1.setText("Back");
btnCancel1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancel1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(btnCancel1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 640, Short.MAX_VALUE)
.addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btnInsert, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btnInsert, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
.addComponent(btnDelete, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnCancel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnCancel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(50, 50, 50)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(txtIDBarang, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtBarang, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jdate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel5))
.addGap(50, 50, 50)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtJumlah, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(txtHarga, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtSubTotal)))
.addGap(50, 50, 50))
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel6)
.addGap(18, 18, 18)
.addComponent(txtNota, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnTransBaru)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txtJumlah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(6, 6, 6)))
.addComponent(jdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtIDBarang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(txtHarga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtBarang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtSubTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnTransBaru)
.addComponent(jLabel6)
.addComponent(txtNota))
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(35, Short.MAX_VALUE))
);
jPanel1.setBackground(new java.awt.Color(204, 204, 204));
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText("FORM PENJUALAN BARANG");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(41, 41, 41))
);
pack();
}// </editor-fold>
private void txtIDBarangKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
}
private void tblBarangMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (belumTrans == false) {
JOptionPane.showMessageDialog(null, "Maaf, Anda belum membuat transaksi baru!");
} else {
txtIDBarang.setText(tblBarang.getValueAt(tblBarang.getSelectedRow(), 0).toString());
txtBarang.setText(tblBarang.getValueAt(tblBarang.getSelectedRow(), 1).toString());
txtHarga.setText(tblBarang.getValueAt(tblBarang.getSelectedRow(), 3).toString());
}
}
private void txtJumlahKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if (evt.getKeyChar() == '\n') {
if (txtIDBarang.getText().equals("") || txtBarang.getText().equals("") || txtJumlah.getText().equals("") || txtHarga.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Maaf, Data yang Anda masukkan kurang lengkap!");
} else {
Insert();
UpdateStok();
ViewTrans();
ViewBarang();
Clear();
btnCancel.setEnabled(false);
}
}
}
private void btnTransBaruActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
KondisiAktif();
AutoID();
txtJumlah.setText("0");
txtHarga.setText("0");
txtTotal.setText("0");
txtBayar.setText("0");
txtKembali.setText("0");
tblPenjualan.removeAll();
ViewTrans();
}
private void tblPenjualanMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
txtNota.setText(tblPenjualan.getValueAt(tblPenjualan.getSelectedRow(), 0).toString());
txtIDBarang.setText(tblPenjualan.getValueAt(tblPenjualan.getSelectedRow(), 1).toString());
txtBarang.setText(tblPenjualan.getValueAt(tblPenjualan.getSelectedRow(), 2).toString());
txtJumlah.setText(tblPenjualan.getValueAt(tblPenjualan.getSelectedRow(), 4).toString());
txtHarga.setText(tblPenjualan.getValueAt(tblPenjualan.getSelectedRow(), 3).toString());
txtSubTotal.setText(tblPenjualan.getValueAt(tblPenjualan.getSelectedRow(), 5).toString());
}
private void txtBarangKeyTyped(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
Cari();
}
private void txtBarangKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if (evt.getKeyChar() == '\n') {
if (txtBarang.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Maaf, Data yang Anda masukkan kurang lengkap!");
Cari();
Clear();
} else {
Cari();
Clear();
}
}
}
private void txtBayarKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if (evt.getKeyChar() == '\n') {
if (txtBayar.getText().equals("0")) {
JOptionPane.showMessageDialog(null, "Maaf, Data yang Anda masukkan kurang lengkap!");
UpdateTotal();
Clear();
} else {
UpdateTotal();
Kembali();
Clear();
Transaksi();
KondisiAwal();
btnCancel.setEnabled(true);
}
}
}
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
KondisiAwal();
cancelTrans();
UpdateTotal();
UpdateStok();
txtNota.setText("0");
}
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String idPenjualan = txtNota.getText();
String idBarang = txtIDBarang.getText();
int hasil = JOptionPane.showConfirmDialog(null, "Apakah Anda yakin akan menghapus data dengan id penjualan " + idPenjualan + " dan id barang " + idBarang, null, JOptionPane.YES_NO_OPTION);
if (hasil == JOptionPane.YES_OPTION) {
DeleteData();
ViewBarang();
ViewTrans();
txtSubTotal.setText("0");
Clear();
JOptionPane.showMessageDialog(null, "Data telah berhasil dihapus!");
} else if (hasil == JOptionPane.NO_OPTION) {
Clear();
}
}
private void btnInsertActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (txtIDBarang.getText().equals("") || txtBarang.getText().equals("") || txtJumlah.getText().equals("") || txtHarga.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Maaf, Data yang Anda masukkan kurang lengkap!");
} else {
Insert();
UpdateStok();
ViewTrans();
ViewBarang();
Clear();
//btnCancel.setEnabled(false);
}
}
private void btnCancel1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new Menu_Utama(Form_Login.kondisiLogin).setVisible(true);
this.dispose();
}
/**
* @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(penjualan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(penjualan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(penjualan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(penjualan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new penjualan().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnCancel1;
private javax.swing.JButton btnDelete;
private javax.swing.JButton btnInsert;
private javax.swing.JButton btnTransBaru;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private com.toedter.calendar.JDateChooser jdate;
private javax.swing.JLabel lbBayar;
private javax.swing.JLabel lbKembali;
private javax.swing.JLabel lbTotal;
private javax.swing.JTable tblBarang;
private javax.swing.JTable tblPenjualan;
private javax.swing.JTextField txtBarang;
private javax.swing.JTextField txtBayar;
private javax.swing.JTextField txtHarga;
private javax.swing.JTextField txtIDBarang;
private javax.swing.JTextField txtJumlah;
private javax.swing.JLabel txtKembali;
private javax.swing.JLabel txtNota;
private javax.swing.JTextField txtSubTotal;
private javax.swing.JLabel txtTotal;
// End of variables declaration
}
Tidak ada komentar:
Posting Komentar