Sabtu, 20 November 2010

Membuat Aplikasi pembelian dengan Visual FoxPro

     Untuk membuat program pembelian, hal ini adalah hal yang biasa dan sering banyak dibahas di banyak artikel. Tapi untuk kali ini, tetap membahas pembelian tapi dengan cara yang berbeda.

     Pengertian Pembelian :
     Pembelian dapat diartikan sebagai urutan kerja atau salah satu proses yang berkaitan dengan pengadaan barang dagangan.


 Persiapan untuk membuat program transaksi pembelian sbb :
1.  Buat project : PjPembelian
2.  Dabatase :dbPembelian
3.  Buat beberapa tabel, berikut struktur sbb:
Tabel Souvenir
kdbrg : Primary key







Isi record pada tabel souvenir sbb :













Tabel Supplier
kdsup : Primary key 







Tabel Pembelian
nofak : Primary Key
kdbrg : Foreign Key (Regular)









Tabel dtBeli
nofak : Foreign Key (Regular)
kdbrg : Foreign Key (Regular)









Design Form pembelian : 




     

Keterangan :
1,2,4,5, 11  : textbox
9                : Listbox
6,7,12        :  CommandButton

1  :  txtNoFak
2  :  txtTglFak
3  :  Combo1
4  :  txtNmSup
5  :  txtQty
6  :  CInput
7  :  cmdFirst, cmdBack, cmdNext, cmdLast
8  :  Text1
9  :  List1
10 : Grid1
11 : txtTotal, txtUbay, txtKembali
12 : cTambah, cSimpan, cKeluar



Untuk setiap textbox yang menampilkan angka, maka akan diubah tipe datanya menjadi numerik melalui builder











Untuk combobox
Klik kanan pada combo
Pilih Builder, lalu masukkan kdsup ke “selected field”






Untuk ListBox, sama seperti combo
KLik kanan pada List
Pilih Builder, lalu masukkan semua field ke "Selected Field"










:: Listing :: 


Form  Aktif
thisform.combo1.Enabled= .T.
thisform.txtNmsup.Enabled= .T.
thisform.text1.Enabled= .T.
thisform.list1.Enabled= .T.
thisform.txtQty.Enabled= .T.
thisform.cinput.Enabled= .T.
thisform.cmdfirst.Enabled= .T.
thisform.cmdback.Enabled= .T.
thisform.cmdnext.Enabled= .T.
thisform.cmdlast.Enabled= .T.


Form  Aturgrid
SELECT Tmpbeli
thisform.grid1.Enabled= .F.
thisform.grid1.RecordSource='Tmpbeli'
thisform.grid1.RecordSourceType= 1
*Atur Grid   
thisform.grid1.column1.Width=85
thisform.grid1.column2.Width=160
thisform.grid1.column3.Width=70
thisform.grid1.column4.Width=50
thisform.grid1.column5.Width=70
           
thisform.grid1.column1.header1.Caption="Kode Barang"
thisform.grid1.column2.header1.Caption="Nama Barang"
thisform.grid1.column3.header1.Caption="Harga"
thisform.grid1.column4.header1.Caption="Qty"
thisform.grid1.column5.header1.Caption="Subtotal"

     
Form  Auto
SELECT pembelian

IF  RECCOUNT() = 0
      no="001"
ELSE
      GO BOTTOM 
      urut=VAL(RIGHT(nofak,3))+1
      DO CASE
      CASE urut > 10
            no="00"+(LTRIM(STR(urut,1)))
      CASE urut > 100
            no="0"+(LTRIM(STR(urut,2)))
      OTHERWISE 
            no=LTRIM(STR(urut,3))
      ENDCASE          
ENDIF

*Menghitung bulan
bl=LTRIM(STR(MONTH(DATE())))
IF VAL(bl) > 10
      bulan="0"+bl
ELSE
      bulan=bl
ENDIF

*Menghitung tahun
th=RIGHT(STR(YEAR(DATE())),2)

*menghitung tanggal
tgl=LEFT(DTOC(DATE()),2)

thisform.txtNoFak.Value="NF"+th+bulan+tgl+no
thisform.Refresh()


Form  Awal
thisform.combo1.Enabled= .F.
thisform.list1.Enabled= .F.
thisform.txtQty.Enabled= .F.
thisform.cinput.Enabled= .F.
thisform.cmdfirst.Enabled= .F.
thisform.cmdback.Enabled= .F.
thisform.cmdnext.Enabled= .F.
thisform.cmdlast.Enabled= .F.
thisform.SetAll("Enabled",.F.,"TextBox")
thisform.SetAll("Value",0,"TextBox")
thisform.text1.Value=""
thisform.txtnmsup.Value=""
thisform.txttotal.Value=0
thisform.txtNmsup.Value=""
thisform.aturgrid()
thisform.ctambah.Enabled= .T.
thisform.csimpan.Caption="Simpan"
thisform.ckeluar.Caption= "Keluar"



Form  Load
CLOSE TABLES ALL
SET DEFAULT TO "C:\Materi_VFP\PraUAS" 
USE pembelian EXCLUSIVE IN 0
USE dtbeli EXCLUSIVE IN 0
USE souvenir EXCLUSIVE IN 0
USE supplier EXCLUSIVE IN 0

CREATE TABLE Tmpbeli(kodebrg char(9),namabrg char(20),;
                   hrg numeric, Tqty byte, Tsubtotal numeric);
        
SELECT Tmpbeli
USE Tmpbeli


Form  Unload
IF USED("pembelian")
      USE IN pembelian
ENDIF

IF USED("dtbeli")
      USE IN dtbeli
ENDIF

IF USED("souvenir")
      USE IN souvenir
ENDIF

IF USED("supplier")
      USE IN supplier
ENDIF


DROP TABLE Tmpbeli



Form  Activate
thisform.awal()


Ctambah     Click
thisform.auto()
thisform.aktif()
thisform.ckeluar.caption= "Batal"
thisform.csimpan.Caption="Hapus Item"
thisform.ctambah.Enabled= .F.




Combo1               Click
SELECT supplier
SET ORDER TO kdsup

IF SEEK(thisform.combo1.Value)
      thisform.txtnmsup.Value=nmsup
      thisform.text1.SetFocus()
ENDIF


Text1        InterActiveChange
cari=TRIM(thisform.text1.Value) + ' % '
thisform.list1.RowSource=''
     
SELECT kdbrg,nmbrg,harga,stok ORDER BY kdbrg;
FROM Souvenir WHERE nmbrg LIKE ?cari INTO CURSOR tmpCari
     
thisform.list1.RowSource='tmpCari'
thisform.Refresh()


List1  dblClick
SELECT Tmpbeli
APPEND BLANK
thisform.grid1.Enabled= .T.
thisform.grid1.RecordSource='Tmpbeli'
thisform.grid1.RecordSourceType= 1

SELECT souvenir
SET ORDER TO TAG kdbrg
SEEK(TRIM(this.Value))
IF FOUND()
      thisform.grid1.column1.text1.Value=souvenir-> kdbrg
      thisform.grid1.column2.text1.Value=souvenir-> nmbrg
      thisform.grid1.column3.text1.Value=souvenir-> harga
      thisform.text1.Value=""
      thisform.list1.Refresh()
      thisform.txtQty.SetFocus()
ENDIF
thisform.list1.RowSource="souvenir"


List1 GotFocus
thisform.list1.ListIndex=1
txtQty      Lostfocus
SELECT Tmpbeli
thisform.grid1.RecordSource='Tmpbeli'
thisform.grid1.RecordSourceType= 1

thisform.grid1.column4.text1.Value=thisform.txtqty.Value
thisform.grid1.column5.text1.Value=thisform.grid1.column4.text1.Value*thisform.grid1.column3.text1.Value
thisform.txttotal.Value=thisform.txttotal.Value+ thisform.grid1.column5.text1.Value

*menambah stok barang

SELECT souvenir
SET ORDER TO kdbrg
LOCATE FOR kdbrg=ALLTRIM(thisform.grid1.column1.text1.Value )
IF FOUND()
      REPLACE stok WITH stok+thisform.txtQty.Value
      thisform.list1.Refresh()
ENDIF
thisform.txtqty.Value =0


Tombol Navigasi
Cmdfirst    Click
SELECT Tmpbeli
GO TOP
thisform.grid1.Refresh()
thisform.grid1.SetFocus


cdmback      Click
SELECT Tmpbeli
SKIP -1
thisform.grid1.SetFocus
IF BOF()
      GO TOP
      thisform.grid1.Refresh()
     
ENDIF


Cmdback     click
SELECT Tmpbeli
SKIP -1
thisform.grid1.SetFocus
IF BOF()
      GO TOP
      thisform.grid1.Refresh()     
ENDIF


Cmdnext     Click
SELECT Tmpbeli
SKIP 1
thisform.grid1.SetFocus
IF EOF()
      GO BOTTOM
      thisform.grid1.Refresh()     
ENDIF


Cmdlast     Click
GO BOTTOM
thisform.grid1.Refresh()
thisform.grid1.SetFocus


cInput      Click
thisform.txtubay.Enabled= .T.
thisform.txtubay.SetFocus()
thisform.csimpan.Caption="Simpan"




txtUbay     KeyPres
LPARAMETERS nKeyCode, nShiftAltCtrl
IF nkeycode=13
      t=thisform.txttotal.Value
      b=thisform.txtubay.Value
      IF bTHEN
            MESSAGEBOX("Uang Bayar kurang!!",48,"Kesalahan")
            b=""
            RETURN
      ELSE
            thisform.txtkembali.Value=b-t
            thisform.csimpan.Caption="Simpan"          
      ENDIF
ENDIF


Csimpan     Click
SELECT pembelian
SET ORDER TO nofak
IF thisform.csimpan.Caption="Hapus Item"
      SELECT Tmpbeli
      SET DELETED ON
      DELETE 
      PACK
      thisform.aturgrid()
ELSE

      SELECT Tmpbeli
      SCAN
      SELECT dtbeli
      APPEND BLANK
      REPLACE nofak WITH thisform.txtnofak.Value
      REPLACE kdbrg WITH Tmpbeli.kodebrg
      REPLACE qty WITH Tmpbeli.Tqty
      REPLACE subtotal WITH Tmpbeli.Tsubtotal
      ENDSCAN

      SELECT pembelian
      SET ORDER TO nofak     
      APPEND BLANK
      REPLACE nofak WITH thisform.txtnofak.Value
      REPLACE tglfak WITH DATE()
      REPLACE kdsup WITH thisform.Combo1.Value
      REPLACE total WITH thisform.txtTotal.Value
      REPLACE ubay WITH thisform.txtUbay.Value
      REPLACE kembali WITH thisform.txtKembali.Value

      SELECT Tmpbeli
      DELETE ALL
      PACK
      thisform.awal()
      thisform.Refresh()
ENDIF




Ckeluar     Click
IF thisform.ckeluar.Caption="Batal"
      thisform.ckeluar.Caption="Keluar"
     
      SELECT Tmpbeli
      IF RECCOUNT() <> 0 THEN
            SELECT souvenir
            SET ORDER TO kdbrg
            LOCATE FOR kdbrg=ALLTRIM(thisform.grid1.column1.text1.Value )
            IF FOUND()
                  REPLACE stok WITH stok-(Tmpbeli.Tqty)
                  thisform.list1.Refresh()
            ENDIF 
          
            SELECT Tmpbeli
            DELETE ALL
            PACK 
            thisform.awal()
      ELSE
            thisform.awal()
      ENDIF
ELSE
IF thisform.ckeluar.Caption="Keluar"
      thisform.Release
ENDIF
ENDIF


Timer1      Timer
*Menghitung tahun
th=LTRIM(STR(YEAR(DATE())))

*Menghitung bulan
bl=CMONTH(DATE())

*menghitung tanggal
tgl=LEFT(DTOC(DATE()),2)

thisform.txttglfak.Value=tgl+"  "+bl+" "+th

7 komentar:

ilham aditya mengatakan...

ths banyak.......................

Thank you for ur comment... by Razbie
InspirasiQ mengatakan...

sangat membantu...
terima kasih... ^_^

Thank you for ur comment... by Razbie
Wearnes mengatakan...

kalau skrip fasilitas frint nya gimana mbaaa

Thank you for ur comment... by Razbie
BLOG INSPIRASI mengatakan...

om tolong kasih tau relasinya donk soalnya "kdbrg" untuk tabel pembelian gak ada.... pliss donk om kasih tau...

Thank you for ur comment... by Razbie
Apenta mengatakan...

Terima kasih atas sharing program nya. Kalo bisa, ditambahkan file untuk di download.

Thank you for ur comment... by Razbie
Anonim mengatakan...

gan, yang tmpbeli kok ga ada ya?
mohon petunjuknya..
tq..

Thank you for ur comment... by Razbie
yune_yuliana mengatakan...

Cara membuat 2 master ka

Thank you for ur comment... by Razbie

Poskan Komentar