Sub hapus_grid()
dtsem.RecordSource = "select*from tmptrans"
dtsem.Refresh
If Not dtsem.Recordset.RecordCount = 0 Then
dtsem.Recordset.MoveFirst
Do While Not dtsem.Recordset.EOF
dtsem.Recordset.Delete
dtsem.Refresh
dtsem.Recordset.MoveNext
Loop
End If
dtsem.Refresh
End Sub
Private Sub CmdTambah_Click()
aktif
bersih
Txttgl.Text = Date
Txtkdbrg.SetFocus
dtfak.RecordSource = "select * from faktur"
dtfak.Refresh
With dtfak.Recordset
If .EOF Then
Txtnostruk.Text = "S" + Format(Date, "yyyy") & Format(Date, "mm") & "001"
Else
.MoveLast
Txtnostruk.Text = "S" + Format(Date, "yyyy") & Format(Date, "mm") & Right(Str(Val(Right(!nostruk, 3)) + 1001), 3)
End If
End With
dtfak.Refresh
End Sub
Sub bersih()
For Each X In Me
If TypeOf X Is TextBox Then
X.Text = ""
End If
Next
End Sub
Sub nonaktif()
For Each X In Me
If TypeOf X Is TextBox Then
X.Enabled = False
End If
Next
End Sub
Sub aktif()
Txtkdbrg.Enabled = True
Txtqty.Enabled = True
Txtubay.Enabled = True
End Sub
Private Sub CmdSimpan_Click()
dtfak.RecordSource = "select * from faktur"
dtfak.Refresh
With dtfak.Recordset
.AddNew
.Fields("nofak") = Txtnostruk.Text
.Fields("tgl") = Date
.Fields("total") = Val(Txttobay.Text)
.Fields("iduser") = DataCombo1.text
.Update
End With
dtsem.RecordSource = "select * from tmptrans"
dtsem.Refresh
detail.RecordSource = "select * from tddtfak"
detail.Refresh
dtsem.Recordset.MoveFirst
n = 1
While Not dtsem.Recordset.EOF
detail.Recordset.AddNew
detail.Recordset.Fields("nofak") = Txtnostruk.Text
detail.Recordset.Fields("kdbrg") = dtsem.Recordset.Fields("kdbrg")
detail.Recordset.Fields("qty") = dtsem.Recordset.Fields("qty")
detail.Recordset.Fields("subtotal") = dtsem.Recordset.Fields("subtotal")
detail.Recordset.Update
dtsem.Recordset.MoveNext
n = n + 1
Wend
MsgBox "Data telah tersimpan"
bersih
nonaktif
hapus_grid
dtsem.RecordSource = "select * from tmptrans"
dtsem.Refresh
End Sub
Private Sub CmdBatal_Click()
If Txtstok <> "" Then
dtbarang.Recordset.Fields("stok") = dtbarang.Recordset.Fields("stok") + Val(Txtqty.Text)
dtbarang.Recordset.Update
End If
nonaktif
bersih
hapus_grid
dtsem.RecordSource = "select * from tmptrans"
dtsem.Refresh
End Sub
Private Sub CmdKeluar_Click()
If Txtstok <> "" Then
dtbarang.Recordset.Fields("stok") = dtbarang.Recordset.Fields("stok") + Val(Txtqty.Text)
dtbarang.Recordset.Update
End If
nonaktif
bersih
hapus_grid
dtsem.RecordSource = "select * from tmptrans"
dtsem.Refresh
Unload Me
End Sub
Private Sub Form_Activate()
nonaktif
bersih
Txttgl.Text = Date
End Sub
Private Sub TxtUbay_Change()
Txtukem.Text = Val(Txtubay.Text) - Val(Txttobay.Text)
End Sub
Private Sub Txtkdbrg_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
dtbarang.RecordSource = "select * from barang where kdbrg='" & Txtkdbrg & "'"
dtbarang.Refresh
If KeyAscii = 13 Then
With barang.Recordset
If .BOF And .EOF Then
MsgBox "Kode tidak ada "
Txtkdbrg.Enabled = True
Txtkdbrg = ""
Txtkdbrg.SetFocus
Else
Txtnmbrg.Text = .Fields("nmbrg")
Txthrgjual.Text = .Fields("hrgjual")
Txtstok.Text = .Fields("stok")
Txtqty.SetFocus
End If
End With
End If
End Sub
Private Sub TxtQty_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Val(Txtstok.Text) < Val(Txtqty.Text) Then
MsgBox "stok barang tidak mencukupi"
Txtqty.Text = ""
Txtqty.SetFocus
Else
dtsem.RecordSource = "select * from tmptrans"
dtsem.Refresh
dtbarang.RecordSource = "select * from barang where kdbrg='" & Txtkdbrg & "'"
dtbarang.Refresh
Txtsubtotal = Val(Txthrgjual.Text) * Val(Txtqty.Text)
Txttobay.Text = Val(Txttobay.Text) + Val(Txtsubtotal.Text)
l = MsgBox("Tambah barang?", 32 + 4, "Konfirmasi")
If l = vbYes Then 'tambah data barang
dtsem.RecordSource = "select * from tmptrans"
dtsem.Refresh
With dtsem.Recordset
.AddNew
.Fields("kdbrg") = Txtkdbrg.Text
.Fields("nmbrg") = Txtnmbrg.Text
.Fields("hrgjual") = Txthrgjual.Text
.Fields("qty") = Val(Txtqty.Text)
.Fields("subtotal") = Txtsubtotal.Text
.Update
End With
dtsem.RecordSource = "select * from tmptrans"
dtsem.Refresh
barang.Recordset.Fields("stok") = Val(Txtstok.Text) - Val(Txtqty.Text)
barang.Recordset.Update 'utk update stok barang
Txtkdbrg.Enabled = True
Txtkdbrg = ""
Txtkdbrg.SetFocus
Txtsubtotal = ""
Txtnmbrg = ""
Txthrgjual = ""
Txtstok = ""
Txtqty = ""
Else ' ga mo nambah (duitnya ga cukup)
With dtsem.Recordset
.AddNew
.Fields("kdbrg") = Txtkdbrg.Text
.Fields("nmbrg") = Txtnmbrg.Text
.Fields("hrgjual") = Txthrgjual.Text
.Fields("qty") = Val(Txtqty.Text)
.Fields("subtotal") = Txtsubtotal.Text
.Update
End With
dtsem.RecordSource = "select * from tmptrans"
dtsem.Refresh
barang.Recordset.Fields("stok") = Val(Txtstok.Text) - Val(Txtqty.Text)
barang.Recordset.Update
nonaktif
Txtkdbrg = ""
Txtsubtotal = ""
Txtnmbrg = ""
Txthrgjual = ""
Txtstok = ""
Txtqty = ""
Txtubay.Enabled = True
Txtubay.SetFocus
End If
dtsem.RecordSource = "select * from tmptrans"
dtsem.Refresh
End If
End If
End Sub
Private Sub dtcmbuser_Click(Area As Integer)
dtuser.RecordSource = "select * from Tuser"
dtuser.Recordset.MoveFirst
Do While Not dtuser.Recordset.EOF
If dtcmbuser.Text = dtuser.Recordset!userid Then
txtnama.Text = dtuser.Recordset!nmuser
Exit Sub
End If
dtuser.Recordset.MoveNext
Loop
End Sub