Public Class frmJual
Dim SQL As String
Dim Proses As New ClsKoneksi
Dim tblJual As DataTable
Dim tblBarang As DataTable
Public MyListItem As ListViewItem
Dim stk As Integer
Sub HeaderJual()
lstJual.Columns.Add("NO", 30, HorizontalAlignment.Right)
lstJual.Columns.Add("Kode", 60, HorizontalAlignment.Center)
lstJual.Columns.Add("Nama Barang", 170, HorizontalAlignment.Left)
lstJual.Columns.Add("Harga", 60, HorizontalAlignment.Right)
lstJual.Columns.Add("Jumlah", 50, HorizontalAlignment.Center)
lstJual.Columns.Add("Total", 60, HorizontalAlignment.Right)
End Sub
Sub Tampil()
Dim i As Integer
Dim urut As Integer
Dim ttl, gttl As Double
urut = 1
'jml = 0
Try
If lstJual.Items.Count > 0 Then
lstJual.Clear()
End If
lstJual.View = View.Details
Call HeaderJual()
tblJual = Proses.ExecuteQuery("SELECT dbojual.kode, dbobarang.nabar, dbobarang.stok, dbobarang.hrg_jual, dbojual.jumlah FROM dbobarang, dbojual WHERE dbobarang.kode=dbojual.kode AND nofak='" & txtNofak.Text & "'order by dbobarang.nabar asc")
For i = 0 To tblJual.Rows.Count - 1
With tblJual.Rows(i)
MyListItem = lstJual.Items.Add(urut)
MyListItem.SubItems.Add(.Item("kode").ToString)
MyListItem.SubItems.Add(.Item("nabar").ToString)
MyListItem.SubItems.Add(.Item("hrg_jual").ToString)
MyListItem.SubItems.Add(.Item("jumlah").ToString)
ttl = .Item("hrg_jual") * .Item("jumlah")
gttl = gttl + ttl
MyListItem.SubItems.Add(ttl.ToString)
End With
urut = urut + 1
Next
Catch Exp As Exception
MsgBox("Program error" & vbCrLf & Err.Description)
End Try
txtTTL.Text = gttl
End Sub
Private Sub txtKode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtKode.KeyPress
If (e.KeyChar = Chr(13) And txtQTY.Text <> "") Then
txtBayar.Focus()
ElseIf (e.KeyChar = Chr(13) And txtQTY.Text = "") Then
MsgBox("Maaf belum ada transaksi !")
End If
End Sub
Private Sub txtKode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtKode.TextChanged
Dim stkmin As Integer
stkmin = 0
If Len(txtKode.Text) < 6 Then Exit Sub
tblBarang = Proses.ExecuteQuery("Select * From dbobarang Where kode='" & txtKode.Text & "'")
If tblBarang.Rows.Count > 0 Then
With tblBarang.Rows(0)
txtNabar.Text = .Item("nabar")
txtHarga.Text = .Item("hrg_jual")
stk = .Item("stok")
stkmin = .Item("stok_min")
If stk = stkmin Then
MsgBox("Maaf stok barang habis !")
Exit Sub
End If
End With
txtQTY.Focus()
'btnSimpan.Enabled = False : btnKeluar.Enabled = True
'btnUpdate.Enabled = True : btnHapus.Enabled = True : btnBatal.Enabled = True
Else
MsgBox("Kode tidak dikenal !")
End If
End Sub
Sub Kode_Otomatis()
tblJual = Proses.ExecuteQuery("Select * From dbojual order by nofak desc")
If tblJual.Rows.Count = 0 Then
txtNofak.Text = "TR-001"
Else
With tblJual.Rows(0)
txtNofak.Text = .Item("nofak")
End With
txtNofak.Text = Val(Microsoft.VisualBasic.Mid(txtNofak.Text, 4, 3)) + 1
If Len(txtNofak.Text) = 1 Then
txtNofak.Text = "TR-00" & txtNofak.Text & ""
ElseIf Len(txtNofak.Text) = 2 Then
txtNofak.Text = "TR-0" & txtNofak.Text & ""
ElseIf Len(txtNofak.Text) = 3 Then
txtNofak.Text = "TR-" & txtNofak.Text & ""
End If
End If
End Sub
Sub SimpanTransaksi()
Dim tglm As Date
tglm = Now()
SQL = "Insert Into dbojual Values ('" & txtNofak.Text & "','" & txtKode.Text & "','" & Format(tglm, "yyyy/MM/dd") & "' ,'" & txtQTY.Text & "','KS001' )"
Proses.ExecuteNonQuery(SQL)
MessageBox.Show("Data Baru telah disimpan..!!", "Penyimpanan Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information)
Call Tampil()
'Call bersih()
End Sub
Sub UpdateTransaksi()
Dim jmlstk As Integer
jmlstk = stk - Val(txtQTY.Text)
SQL = "Update dbobarang Set stok = '" & jmlstk & "' where kode = '" & txtKode.Text & "'"
Proses.ExecuteNonQuery(SQL)
'MessageBox.Show("Data telah diubah..!!", "Perubahan Data Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information)
'Call bersih()
End Sub
Private Sub frmJual_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Kode_Otomatis()
txtNabar.Enabled = False
txtHarga.Enabled = False
txtNofak.Enabled = False
txtQTY.Enabled = True
txtKembali.Enabled = False
End Sub
Private Sub txtQTY_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQTY.KeyPress
If e.KeyChar = Chr(13) Then
Call SimpanTransaksi()
Call UpdateTransaksi()
Call Bersih()
txtKode.Focus()
End If
End Sub
Sub Bersih()
txtKode.Text = ""
txtNabar.Text = ""
txtHarga.Text = ""
txtQTY.Text = ""
End Sub
Private Sub txtBayar_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBayar.TextChanged
txtKembali.Text = Val(txtBayar.Text) - Val(txtTTL.Text)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lbNama.Text = Microsoft.VisualBasic.Right(lbNama.Text, 1) + Microsoft.VisualBasic.Left(lbNama.Text, Len(lbNama.Text) - 1)
End Sub
Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label10.Click
Cetak_Jual.ShowDialog()
End Sub
End Class