Wednesday, April 25, 2007

Listing Program Transaksi Stok Barang

Form1 ------------------------ Init
SET DATE BRITISH
thisform.isian_tidak_aktif

PUBLIC koneksi,tombol
sambung='Driver={MySQL ODBC 3.51 Driver};Server=192.168.10.253;Database='+'setyo;uid='+'setyo'
koneksi=SQLSTRINGCONNECT(sambung)

iF koneksi >=0
MESSAGEBOX('koneksi ke server berhasil',0+64,'info')
ELSE
MESSAGEBOX('koneksi ke server gagal',1,'info')
ENDIF

SQLEXEC(koneksi,'select * from barang',"tb_barang")
thisform.cbobrg.RowSource="tb_barang"
thisform.cbobrg.RowSourceType= 6
thisform.cbobrg.ColumnCount=3
SQLEXEC(koneksi,'select * from supplier',"tb_supplier")
thisform.cbosup.RowSource="tb_supplier"
thisform.cbosup.RowSourceType= 6
thisform.cbosup.ColumnCount=3
thisform.no_otomatis
thisform.txttgl.SetFocus

Form1-------------------- atur_listbox
*prosedur untuk mengatur isian di listbox
thisform.list1.RowSourceType= 0
thisform.list1.ColumnCount=5
thisform.list1.AddListItem("",1,1)
thisform.list1.AddListItem("",1,2)
thisform.list1.AddListItem("",1,3)
thisform.list1.AddListItem("",1,4)
thisform.list1.AddListItem("",1,5)

Form1 ----------------------------------hitung_total
PARAMETERS tno_faktur
SQLEXEC(koneksi,'select sum(sub_total) as total from tdafbeli where no_faktur=?tno_faktur','total_beli')
thisform.txttotal.Value = total_beli.total

Form1 isian_tidak_aktif
* prosedur untuk menokaktifkan object inputan
thisform.setall('Enabled',.f.,'Textbox')
thisform.SetAll('enabled',.F.,'ComboBox')

Form1 ---------------------------------------kosong_isian
-------------------------------------------------
* prosedur untuk mengosongkan tempat isian
thisform.txtnofaktur.Value =""
thisform.txttgl.Value=CTOD(" / / ")
thisform.cbosup.Value =""
thisform.txtnmsup.Value =""
thisform.cbobrg.Value=""
thisform.txtnmbrg.Value= ""
thisform.txtjmlbeli.Value =0
thisform.txthrgbeli.Value=0
thisform.txtsubtotal.Value =0
thisform.txttotal.Value=0


Form1 ----------------------------------------list_beli
-------------------------------------------------
* Prosedur untuk menampilkan data transaksi di listbox
PARAMETERS tno_faktur
SQLEXEC(koneksi,'select a.kode_barang,b.nama_barang,b.harga_beli,a.jumlah_beli,a.sub_total from tdafbeli a, barang b where a.kode_barang=b.kode_barang and a.no_faktur=?tno_faktur','daftar_beli')

thisform.list1.RowSource="daftar_beli"
thisform.list1.RowSourceType = 2
thisform.list1.SetFocus()

Form1--------------------------------------------- nomor_otomatis
* Prosedur untuk menampilkan no_faktur otomatis
SQLEXEC(koneksi,'select * from beli',"tb_beli")
GO bottom
IF BOF()
xno='00001'
ELSE
no=VAL(tb_beli.no_faktur)
no=no+1
sno=ALLTRIM(STR(no,5,0))
xno=SUBSTR('00000',1,5-LEN(sno))+sno
ENDIF
thisform.txtnofaktur.Value = xno

Form1 --------------------------------------------------------------- tampil_barang
* Prosedur untuk menampilkan data barang di combo box
SQLEXEC(koneksi,'select * from barang',"tb_barang")
thisform.cbobrg.RowSource="tb_barang"
thisform.cbobrg.RowSourceType= 6
thisform.cbobrg.ColumnCount=3

form1 ----------------------------------------------------------------tampil_data
* Prosedur untuk menampilkan data beli
SQLEXEC(koneksi,'select * from beli',"tb_beli")
thisform.txtnofaktur.Value=no_faktur
thisform.Txttgl.Value =tanggal
thisform.cbosup.Value =kode_supplier
thisform.txttotal.Value=total_bayar

SQLEXEC(koneksi,'select * from supplier',"tb_supplier")
SELECT tb_supplier
thisform.txtnmsup.Value=nama_supplier


SQLEXEC(koneksi,'select * from tdafbeli',"tb_tdafbeli")
SELECT tb_tdafbeli
thisform.cbobrg.Value =kode_barang
thisform.txtjmlbeli.Value=jumlah_beli
thisform.txthrgbeli.Value=harga_beli
thisform.txtsubtotal.Value=sub_total

SQLEXEC(koneksi,'select * from barang',"tb_barang")
select tb_barang
thisform.txtnmbrg.Value=nama_barang

txttgl ------------------------------------------------------------------lostfocus
thisform.txttgl.Enabled= .T.
thisform.cbosup.Enabled = .T.
thisform.cbosup.SetFocus
thisform.cbobrg.Enabled= .T.
thisform.txtjmlbeli.Enabled= .T.


txtjml-------------------------------------------------------beli lostfocus
a1 = ALLTRIM(thisform.txtnofaktur.Value)
a2 = ALLTRIM(thisform.cbobrg.Value)
a3 = thisform.txtjmlbeli.Value
a4 = thisform.txtsubtotal.Value

SQLEXEC(koneksi,'insert into tdafbeli values (?a1,?a2,?a3,?a4)')

thisform.list_beli(a1)
thisform.hitung_total(a1)

SQLEXEC(koneksi,'select * from barang',"tb_barang")
SELECT tb_barang

xstok=stok
x1 = ALLTRIM(thisform.cbobrg.Value)
xstok=stok+VAL(thisform.txtjmlbeli.Text )
SQLEXEC(koneksi,"update barang set stok=?xstok where kode_barang=?x1")
*thisform.txtsubtotal.Value=thisform.txtjmlbeli.Value * thisform.txthrgbeli.Value

x=MESSAGEBOX("Ada barang lain ",4+32,"Pembelian")
IF x=6 THEN
thisform.Refresh
thisform.cbobrg.SetFocus
ELSE
thisform.Refresh
thisform.cmdsave.SetFocus
ENDIF
thisform.tampil_barang


txtjmlbeli -----------------------------------------------------Interactivechange
thisform.txtsubtotal.Value = thisform.txthrgbeli.Value * thisform.txtjmlbeli.Value

cmdadd ----------------------------------------------------------- Clik
tombol=1
thisform.kosong_isian
thisform.atur_listbox
thisform.no_otomatis
thisform.txttgl.Enabled= .T.
thisform.txttgl.SetFocus()

cmdsave -------------------------------------------------------------- Clik
a1=ALLTRIM(thisform.txtnofaktur.Value)
a2=thisform.txttgl.Value
a3=thisform.cbosup.Value
a4=thisform.txttotal.Value

IF tombol=1
SQLEXEC(koneksi,'insert into beli values (?a1,?a2,?a3,?a4)')
ELSE
SQLEXEC(koneksi,'update beli set no_faktur=a1,tanggal=a2,kode_supplier=a3,total_bayar=a4 where no_faktur=a1')
ENDIF
MESSAGEBOX('data saved',16)
thisform.Refresh

cmdexit ------------------------------------------------------------------ Clik
pesan=MESSAGEBOX('Yakin keluar',4+32,' Exit')
IF pesan=6
USE
thisform.Release
Endif