Pemanfaatan Database Server Open Source                       Oleh : Hendra, ST.Mengenal FirebirdFirebird adalah suatu dat...
Pemanfaatan Database Server Open Source                        Oleh : Hendra, ST.Perkembangan FirebirdPada tahun 2000, Bor...
Pemanfaatan Database Server Open Source                       Oleh : Hendra, ST.Klik pada I accept the agreement, dan klik...
Pemanfaatan Database Server Open Source                       Oleh : Hendra, ST.Mengaktifkan dan Mematikan Service pada Fi...
Pemanfaatan Database Server Open Source                     Oleh : Hendra, ST.Mengenal IBExpertIB Expert merupakan salah s...
Pemanfaatan Database Server Open Source           Oleh : Hendra, ST.Klik pada nextKlik Finishdan secara otomatis akan meng...
Pemanfaatan Database Server Open Source     Oleh : Hendra, ST.Proses Pembuatan DatabaseBuatlah sebuah folder baru c:firebi...
Pemanfaatan Database Server Open Source   Oleh : Hendra, ST.Klik pada Test ConnectIndoprog                                ...
Pemanfaatan Database Server Open Source                       Oleh : Hendra, ST.Dan Akhirnya klik pada registerDouble klik...
Pemanfaatan Database Server Open Source                  Oleh : Hendra, ST.Proses pembuatan Table :   1. Secara interaktif...
Pemanfaatan Database Server Open Source            Oleh : Hendra, ST.Klik pada    (ctrl+f9) mengkompilasi tabel anda.   2....
Pemanfaatan Database Server Open Source                   Oleh : Hendra, ST.Rincian script diatas :CREATE TABLE DATAPART (...
Pemanfaatan Database Server Open Source            Oleh : Hendra, ST.Pembuatan ViewKlik kanan pada View, dan pilih New Vie...
Pemanfaatan Database Server Open Source                      Oleh : Hendra, ST.dan klik pada   (ctrl+f9) untuk mengkompila...
Pemanfaatan Database Server Open Source         Oleh : Hendra, ST.Pembuatan ProcedureKlik kanan pada Procedure dan pilih N...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.RETURNS (    RESULT INTEGER)ASDECLARE VA...
Pemanfaatan Database Server Open Source                          Oleh : Hendra, ST.        update dataterima set status = ...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.  into :VJENIS,:VNOMOR, :VTANGGAL,:VPART...
Pemanfaatan Database Server Open Source   Oleh : Hendra, ST.Pembuatan TriggerPada Trigger klik kanan, dan pilih Newdan aka...
Pemanfaatan Database Server Open Source             Oleh : Hendra, ST.Rincian Script diatas :CREATE TRIGGER DATATERIMADETA...
Pemanfaatan Database Server Open Source                     Oleh : Hendra, ST.Pembuatan GeneratorGenerator merupakan auto ...
Pemanfaatan Database Server Open Source                Oleh : Hendra, ST.CREATE TRIGGER DATATERIMADETAIL_BI0ACTIVE BEFORE ...
Pemanfaatan Database Server Open Source                      Oleh : Hendra, ST.Konektivitas Visual Basic dengan FirebirdDe...
Pemanfaatan Database Server Open Source                   Oleh : Hendra, ST.Klik Next                                  Kli...
Pemanfaatan Database Server Open Source                  Oleh : Hendra, ST.Dim MyConn As New ConnectionMyConn.ConnectionSt...
Pemanfaatan Database Server Open Source                   Oleh : Hendra, ST.Konektivitas Crystal Report dengan FirebirdPil...
Pemanfaatan Database Server Open Source            Oleh : Hendra, ST.Pilih Microsoft OLE DB Provider for ODBC DriversIndop...
Pemanfaatan Database Server Open Source                        Oleh : Hendra, ST.Klik pada Use connection string, dan keti...
Pemanfaatan Database Server Open Source   Oleh : Hendra, ST.Indoprog                                                   29
Pemanfaatan Database Server Open Source                      Oleh : Hendra, ST.Menampilkan report dari Project Visual Basi...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.Lampiran Script Database untuk program S...
Pemanfaatan Database Server Open Source     Oleh : Hendra, ST.CREATE PROCEDURE CANCELDATAKELUAR (    NOKELUAR CHAR(10))RET...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.    TANGGAL DATE)RETURNS (    RESULT INT...
Pemanfaatan Database Server Open Source    Oleh : Hendra, ST.     EBY        VARCHAR(20),     ETIME      DATE,     POSTING...
Pemanfaatan Database Server Open Source     Oleh : Hendra, ST.CREATE TABLE DATAKARTUPARTLOKASI (    JENIS        CHAR(1), ...
Pemanfaatan Database Server Open Source           Oleh : Hendra, ST.     PARTNO          CHAR(25) NOT NULL,     PARTNAME  ...
Pemanfaatan Database Server Open Source   Oleh : Hendra, ST.     PODETAILID   INTEGER NOT NULL);CREATE TABLE DATARAK (    ...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.     DISC             NUMERIC(15,2),    ...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.       DataKeluar.tglkeluar,       DataK...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.   datakartupart.tanggal,   datakartupar...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.               dataterimadetail.jumlah*1...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.   as DPP,   case     when datasupplier....
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.          else                 datakelua...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.   datakeluardetail.partno,   datakeluar...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.   end   as jumlahfrom datakeluar inner ...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.                inner join datacustomer ...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST./* View: REKAPPENJUALANPART */CREATE VIE...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.REFERENCES DATAPART (PARTNO);ALTER TABLE...
Pemanfaatan Database Server Open Source                          Oleh : Hendra, ST./* Trigger: DATAADJUST_INSERT */CREATE ...
Pemanfaatan Database Server Open Source                              Oleh : Hendra, ST.begin  /*jenis 4 = penjualan,   5= ...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.ACTIVE AFTER DELETE POSITION 0ASbegin  U...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST./* Trigger: DATATERIMADETAIL_BI0 */CREAT...
Pemanfaatan Database Server Open Source                           Oleh : Hendra, ST.     begin     Update datapart Set   Q...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.         Update datasodetail Set QtySupp...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.  for select nopo from datapo where stat...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.DECLARE VARIABLE VJENIS INTEGER;DECLARE ...
Pemanfaatan Database Server Open Source                          Oleh : Hendra, ST./* untuk data keluar, 4 = Penjualan, 5 ...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.       begin       vtotalbaris = vtotalb...
Pemanfaatan Database Server Open Source                          Oleh : Hendra, ST.    RESULT INTEGER)ASDECLARE VARIABLE V...
Pemanfaatan Database Server Open Source                          Oleh : Hendra, ST.  for select datakeluar.jenis,         ...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.       update datapartlokasi set adjuste...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.    RESULT INTEGER)ASDECLARE VARIABLE VB...
Pemanfaatan Database Server Open Source                         Oleh : Hendra, ST.    if (VTOTALBELUMPOSTING= 0) then     ...
Pemanfaatan database server open source
Pemanfaatan database server open source
Upcoming SlideShare
Loading in …5
×

Pemanfaatan database server open source

954 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
954
On SlideShare
0
From Embeds
0
Number of Embeds
29
Actions
Shares
0
Downloads
89
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Pemanfaatan database server open source

  1. 1. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Mengenal FirebirdFirebird adalah suatu database relational yang menawarkan kemampuan kemampuanANSI SQL-99 yang dapat dijalankan pada Linux, Windows, dan varitas dari platformUnix.Firebird adalah database server yang sifatnya Open Source, dan dapat digunakan secarabebas untuk tujuan komersil ataupun tidak.Website : http://firebird.sourceforge.net/FAQ : http://firebird.sourceforge.net/index.php?op=faqCatatan :Berdasarkan pengalaman penulis Firebird SQL server merupakan database server yangringan dan berunjuk kerja tinggi dapat dijalankan pada lingkungan Windows 98/2000maupun XP.Penulisan telah memanfaatkannya untuk pengembangan program database yang seriusdiperusahaan 1 tahun terakhir dan tidak ada masalah serius yang pernah ditimbulkannya.Kemudian firebird mendukung fasilitas Primarykey, Foreignkey, View, Storeprocedure,Trigger.Juga tersedia ODBC provider untuk ADO maupun ADO.NetDokumentasi tentang perbandingan dan Migrasi dari MSDE/SQL Server ke Firebirdhttp://firebird.sourceforge.net/manual/migration-mssql.html#migration-mssql-introIndoprog 1
  2. 2. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Perkembangan FirebirdPada tahun 2000, Borland memutuskan untuk melepaskan InterBase 6.0 sebagai OpenSource. Firebird adalah suatu pengembangan terpisah yang dimulai dari source codetersebut, yang dikendalikan oleh suatu Open Source Community.Dimana kita dapat mendownload FirebirdUntuk mendownload Firebird Server, kunjungihttp://firebird.sourceforge.net/index.php?op=files&id=engineProses Instalasi Firebird SQL 1.5Klik pada next, Klik pada nextIndoprog 2
  3. 3. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Klik pada I accept the agreement, dan klik Klik pada nextnextKlik pada next Klik pada nextKlik pada FinishIndoprog 3
  4. 4. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Mengaktifkan dan Mematikan Service pada FirebirdPada Start, Klik Setting, Klik Control Panel, dan klik padaLakukan setting firebird sebagai berikut :Klik pada stop, dan start kembali.Indoprog 4
  5. 5. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Mengenal IBExpertIB Expert merupakan salah satu tools untuk pembuatan dan manipulasi database padaFirebird SQL Server (seperti SQL Enterprised Manager pada SQL Server)Mendownload IBExpert Free Personal EditionUntuk mendownload IBExpert anda dapat mengunjungi http://www.ibexpert.comInstalasi IBExpertKlik Next Klik NextKlik yes Klik NextIndoprog 5
  6. 6. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Klik pada nextKlik Finishdan secara otomatis akan mengaktifkan IBExpert.Indoprog 6
  7. 7. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Proses Pembuatan DatabaseBuatlah sebuah folder baru c:firebirddbKemudian klik pada OkPerbedaan dialect pada Database Firebird.Indoprog 7
  8. 8. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Klik pada Test ConnectIndoprog 8
  9. 9. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Dan Akhirnya klik pada registerDouble klik pada C:FirebirdDBfbindoprog.fdbSejauh ini berarti anda telah berhasil membuat database dan membuat koneksi.Indoprog 9
  10. 10. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Proses pembuatan Table : 1. Secara interaktif melalui designer pada IBExpertKemudian akan muncul jendela tabel designerIsikan nama Tabel dan struktur database andaIndoprog 10
  11. 11. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Klik pada (ctrl+f9) mengkompilasi tabel anda. 2. Melalui SQL EditorKetik SQL Script andaIndoprog 11
  12. 12. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Rincian script diatas :CREATE TABLE DATAPART ( PARTNO CHAR(25) NOT NULL, PARTNAME VARCHAR(50), TIPE VARCHAR(3), KATEGORI CHAR(1), QTYONHAND NUMERIC(10,2) DEFAULT 0, SATUAN CHAR(10), HET NUMERIC(15,2), PDISCHET NUMERIC(6,2), HMODAL NUMERIC(15,2), PDISCMODAL NUMERIC(6,2), QTYONSO NUMERIC(10,2) DEFAULT 0, QTYONPO NUMERIC(10,2) DEFAULT 0, BBALANCEHPP NUMERIC(15,2) DEFAULT 0, BBALANCE NUMERIC(10,2) DEFAULT 0, MUTASIMASUK NUMERIC(10,2) DEFAULT 0, MUTASIKELUAR NUMERIC(10,2) DEFAULT 0, ADJUSTED NUMERIC(15,2) DEFAULT 0, BBALANCEHPP0 NUMERIC(15,2) DEFAULT 0, BBALANCE0 NUMERIC(10,2) DEFAULT 0, MUTASIMASUK0 NUMERIC(10,2) DEFAULT 0, MUTASIKELUAR0 NUMERIC(10,2) DEFAULT 0, ADJUSTED0 NUMERIC(15,2) DEFAULT 0, NMAX NUMERIC(10,2) DEFAULT 0, NMIN NUMERIC(10,2) DEFAULT 0, NORAK CHAR(11), EBY VARCHAR(20), ETIME DATE);Klik pada (f9) untuk menjalankan script anda.Indoprog 12
  13. 13. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Pembuatan ViewKlik kanan pada View, dan pilih New ViewSelanjutnya akan tampil jendela New ViewRincian Script diatasCREATE VIEW REKAPPENJUALANPART( JENIS, TGLKELUAR, NOHARI, PARTNAME, QTYSUPPLY)ASselect datakeluar.JENIS, datakeluar.tGLKELUAR, extract(day from datakeluar.tGLKELUAR) as NoHari, datakeluarDetail.PARTNO || || datakeluarDetail.PARTNAME, datakeluarDetail.QTYSUPPLYfrom datakeluar inner join datakeluardetail on datakeluar.nokeluar =datakeluardetail.nokeluarwhere datakeluar.status <> "C";Ketikan script anda :Indoprog 13
  14. 14. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.dan klik pada (ctrl+f9) untuk mengkompilasi script anda.Indoprog 14
  15. 15. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Pembuatan ProcedureKlik kanan pada Procedure dan pilih NewSelanjutnya akan tampil jendela New ProcedureDan ketikan script untuk procedure anda :Rincian Script diatas :CRETE PROCEDURE POSTINGKARTUPART ( TANGGAL DATE)Indoprog 15
  16. 16. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.RETURNS ( RESULT INTEGER)ASDECLARE VARIABLE VJENIS INTEGER;DECLARE VARIABLE VNOMOR CHAR(10);DECLARE VARIABLE VTANGGAL DATE;DECLARE VARIABLE VPARTNO CHAR(25);DECLARE VARIABLE VKODELOKASI CHAR(10);DECLARE VARIABLE VPARTNAME VARCHAR(50);DECLARE VARIABLE VQTY NUMERIC(10,2);DECLARE VARIABLE VHARGA NUMERIC(10,2);DECLARE VARIABLE VDETAILID INTEGER;DECLARE VARIABLE VTOTALBARIS INTEGER;DECLARE VARIABLE VID INTEGER;DECLARE VARIABLE VIDHPP INTEGER;DECLARE VARIABLE VQTYKELUAR NUMERIC(15,2);DECLARE VARIABLE VQTYALLREMAIN NUMERIC(15,2);DECLARE VARIABLE VQTYREMAIN NUMERIC(15,2);DECLARE VARIABLE VHPP NUMERIC(15,2);DECLARE VARIABLE VTOTALHPP NUMERIC(15,2);DECLARE VARIABLE VBARIS INTEGER;begin vtotalbaris = 0;/* untuk data terima, 1 = Pembelian, 2 = Ret. Pembelian, mutasi tidak ikut */ for select dataterima.jenis, dataterima.noterima, dataterima.tglterima, dataterimadetail.partno, dataterimadetail.kodelokasi0, dataterimadetail.partname, dataterimadetail.qtysupply, (dataterimadetail.harga-dataterimadetail.disc), dataterimadetail.terimadetailid from dataterima inner join dataterimadetail ondataterima.noterima=dataterimadetail.noterima where (dataterima.jenis ="1" or dataterima.jenis = "2") anddataterima.tglterima = :tanggal and dataterima.posting is null into :VJENIS,:VNOMOR, :VTANGGAL,:VPARTNO, :VKODELOKASI, :VPARTNAME ,:VQTY,:VHARGA,:VDETAILID do begin vtotalbaris = vtotalbaris + 1; /*jenis 1 = pembelian, 2= ret. pembelian*/ if (vjenis="1" ) then begin /*sisip data ke table datakartupart */ insert into datakartupart(jenis,nomor,tanggal,partno,kodelokasi,partname,qty,qtyout,harga,hpp,carihpp, sourceid)values (:vjenis,:VNOMOR, :VTANGGAL,:VPARTNO, :VKODELOKASI, :VPARTNAME ,:VQTY,0,:VHARGA,0,0,:VDETAILID); /*update ke mutasi masuk ditabel datapart */ update datapart set mutasimasuk = mutasimasuk + :VQTY where partno = :VPARTNO; end else begin /*sisip data ke table datakartupart */ insert into datakartupart(jenis,nomor,tanggal,partno,kodelokasi,partname,qty,qtyout,harga,hpp,carihpp, sourceid)values (:vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VKODELOKASI, :VPARTNAME ,-:VQTY,0,:vharga,0,0, :vdetailid); /*update ke mutasi masuk ditabel datapart */ update datapart set mutasimasuk = mutasimasuk -:VQTY where partno = :VPARTNO; end /*update flag posting */ update dataterimadetail set posting = "P" where dataterimadetail.terimadetailid =:vdetailid;Indoprog 16
  17. 17. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. update dataterima set status = "P", posting = "P" where dataterima.noterima =:vnomor; end/* untuk data keluar, 4 = Penjualan, 5 = Ret. Penjualan, mutasi tidak ikut */ for select datakeluar.jenis, datakeluar.nokeluar, datakeluar.tglkeluar, datakeluardetail.partno, datakeluardetail.kodelokasi0, datakeluardetail.partname, datakeluardetail.qtysupply, (datakeluardetail.harga-datakeluardetail.disc), datakeluardetail.keluardetailid from datakeluar inner join datakeluardetail ondatakeluar.nokeluar=datakeluardetail.nokeluar where (datakeluar.jenis ="4" or datakeluar.jenis = "5") anddatakeluar.tglkeluar = :tanggal and datakeluar.posting is null into :VJENIS,:VNOMOR, :VTANGGAL,:VPARTNO, :VKODELOKASI, :VPARTNAME ,:VQTY,:VHARGA,:VDETAILID do begin vtotalbaris = vtotalbaris + 1; /*jenis 4 = penjualan, 5= ret. penjualan, 6 = mutasi keluar */ if (vjenis="4") then begin /*sisip data ke table datakartupart */ insert into datakartupart(jenis,nomor,tanggal,partno,kodelokasi,partname,qty,qtyout,harga,hpp,carihpp, sourceid)values (:vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VKODELOKASI, :VPARTNAME ,-:VQTY,0,:vharga,0,0, :vdetailid); /*update ke mutasi masuk ditabel datapart */ update datapart set mutasikeluar = mutasikeluar + :VQTY where partno =:VPARTNO; end else begin /*sisip data ke table datakartupart */ insert into datakartupart(jenis,nomor,tanggal,partno,kodelokasi,partname,qty,qtyout,harga,hpp,carihpp, sourceid)values (:vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VKODELOKASI,:VPARTNAME,:VQTY,0,:vharga,0,0, :vdetailid); /*update ke mutasi masuk ditabel datapart */ update datapart set mutasikeluar = mutasikeluar + :VQTY where partno =:VPARTNO; end /*update flag posting */ update datakeluardetail set posting = "P" where datakeluardetail.keluardetailid =:vdetailid; update datakeluar set status = "P", posting = "P" where datakeluar.nokeluar =:vnomor; end/* untuk data adjust */ for select dataadjust.jenis, dataadjust.noadjust, dataadjust.tgladjust, dataadjust.partno, dataadjust.kodelokasi, dataadjust.partname, dataadjust.qtyadjust, dataadjust.harga, dataadjust.adjustid from dataadjust where dataadjust.tgladjust = :tanggal and dataadjust.postingis nullIndoprog 17
  18. 18. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. into :VJENIS,:VNOMOR, :VTANGGAL,:VPARTNO, :VKODELOKASI, :VPARTNAME ,:VQTY,:VHARGA,:VDETAILID do begin vtotalbaris = vtotalbaris + 1; /*sisip data ke table datakartupart */ insert into datakartupart (jenis,nomor,tanggal,partno,kodelokasi,partname,qty,qtyout,harga,hpp,carihpp) values (:VJENIS,:VNOMOR, :VTANGGAL,:VPARTNO, :VKODELOKASI, :VPARTNAME ,:VQTY,0,:VHARGA,0,0); /*update ke adjusted ditabel datapart */ update datapart set adjusted = adjusted + :VQTY where partno = :VPARTNO; /*update flag posting */ update dataADJUST set status = "P", posting = "P" where dataADJUST.noadjust =:vnomor; end/* untuk HPP */ for select datakartupart.partno,datakartupart.qty, datakartupart.id from datakartupart where datakartupart.carihpp = 0 and qty < 0 order by id into :vpartno, :VQTY, :VID do begin vqtykeluar = -vqty; /*qty keluar negatif, jadi dibuat positif */ select sum(qty-qtyout) from datakartupart where datakartupart.partno = :vpartno and (datakartupart.qty-datakartupart.qtyout) > 0 into :vqtyallremain; if (vqtyallremain >= vqtykeluar) then begin vbaris = 0; vtotalhpp = 0; while (vqtykeluar > 0) do begin vbaris = vbaris + 1; select first 1 skip 0 (datakartupart.qty-datakartupart.qtyout), datakartupart.id, datakartupart.harga from datakartupart where datakartupart.partno = :vpartno and (qty-qtyout) > 0 order by idasc into :VQTYREMAIN, :vidhpp, :vhpp; if (vqtykeluar > vqtyremain) then begin insert into datahpp (id,idhpp,qty,hpp) values (:vid,:vidhpp, :vqtyremain, :vhpp); update datakartupart set qtyout=qtyout + :VQTYREMAIN where id =:vidhpp; vqtykeluar = vqtykeluar-vqtyremain; vtotalhpp = vtotalhpp + (vqtyremain*vhpp); end else begin insert into datahpp (id,idhpp,qty,hpp) values (:vid,:vidhpp, :vqtykeluar, :vhpp); update datakartupart set qtyout=qtyout + :VQTYkeluar where id = :vidhpp; vtotalhpp = vtotalhpp + (vqtykeluar*vhpp); vqtykeluar = 0; end end /*end of while*/ update datakartupart set hpp = :vtotalhpp, carihpp = :VBARIS where id = :vid; end /* end of if (vqtyallremain >= vqtykeluar) */ end result = vtotalbaris;endKlik pada untuk mengkompilasi script anda.Indoprog 18
  19. 19. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Pembuatan TriggerPada Trigger klik kanan, dan pilih Newdan akan tampil jendela new triggerKetikan script trigger anda :Indoprog 19
  20. 20. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Rincian Script diatas :CREATE TRIGGER DATATERIMADETAIL_INSERTACTIVE AFTER INSERT POSITION 0ASbegin /*jenis 1 = pembelian, 2= ret. pembelian, 3 = mutasi masuk */ if (new.jenis = 1 or new.jenis=3) then begin Update datapart Set QtyOnHand = QtyOnHand + New.qtysupply wherepartno = New.partno; Update datapodetail Set QtySupply = QtySupply + New.qtysupplyWhere PoDetailID = New.PoDetailID; end else begin Update datapart Set QtyOnHand = QtyOnHand - New.qtysupply wherepartno = New.partno; Update datapodetail Set QtySupply = QtySupply - New.qtysupplyWhere PoDetailID = New.PoDetailID; endendIndoprog 20
  21. 21. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Pembuatan GeneratorGenerator merupakan auto increment variable yang digunakan untuk pembuatan fieldidentity (dikombinasikan dengan pemakaian trigger)Selanjutnya akan ditampilkan jendela New GeneratorKetikan nama Generator dan nilai AwalnyaMengkombinasikan Generator dengan Trigger untuk membuat field identityIndoprog 21
  22. 22. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.CREATE TRIGGER DATATERIMADETAIL_BI0ACTIVE BEFORE INSERT POSITION 0ASbegin New.terimadetailid = Gen_Id(GenTerimaDetailID,1);endIndoprog 22
  23. 23. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Konektivitas Visual Basic dengan FirebirdDengan ODBCFirebird ODBC dapat di download dihttp://firebird.sourceforge.net/index.php?op=files&id=odbcKlik Next Klik NextKlik Next Klik NextIndoprog 23
  24. 24. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Klik Next Klik NextKlik Next Klik FinishKlik InstallConnection String pada ADOSetelah anda menginstalasi Firebird ODBC, maka koneksi ADO dapat dilakukan denganconnection string sebagai berikut :Indoprog 24
  25. 25. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Dim MyConn As New ConnectionMyConn.ConnectionString = "DRIVER=Firebird/InterBase(r) driver;UID=SYSDBA;PWD=MASTERKEY;DBNAME=c:firebirddbfbindoprog.fdb;"MyConn.OpenJika database berada pada komputer lain, misalnya DATASERVER dengan IP192.168.0.1, maka connection string menjadi sebagai berikut :Dim MyConn As New ConnectionMyConn.ConnectionString = "DRIVER=Firebird/InterBase(r)driver;UID=SYSDBA;PWD=MASTERKEY;DBNAME=DATASERVER:c:firebirddbfbindoprog.fdb;"MyConn.OpenatauDim MyConn As New ConnectionMyConn.ConnectionString = "DRIVER=Firebird/InterBase(r)driver;UID=SYSDBA;PWD=MASTERKEY;DBNAME=192.168.0.1:c:firebirddbfbindoprog.fdb;"MyConn.OpenMembuka RecordsetPembukaan recordset dapat dilakukan seperti biasanya :Set RsMaster = New RecordsetRsMaster.Open "DataPart", MyConn, adOpenDynamic, adLockOptimistic,adCmdTableMenjalankan StoreProcedureYang mengembalikan parameterDim MyComm As New CommandMyComm.ActiveConnection = MyConnMyComm.CommandText = "execute procedure postingkartupart(01-31-2005);"MyComm.Prepared = TrueMyComm.Parameters.RefreshMyComm.ExecuteResult = MyComm.Parameters("Result")Yang mengembalikan recordsetDim MyComm As New CommandDim MyRs As New RecordsetMyComm.ActiveConnection = MyConnMyComm.CommandText = "execute procedure kartupart(01-01-2005, 01-31-2005); "MyComm.Prepared = TrueMyComm.Parameters.RefreshSet MyRs = MyComm.ExecuteIndoprog 25
  26. 26. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Konektivitas Crystal Report dengan FirebirdPilih More Data Sources, dan DblKlik pada Make New ConnectionIndoprog 26
  27. 27. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Pilih Microsoft OLE DB Provider for ODBC DriversIndoprog 27
  28. 28. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Klik pada Use connection string, dan ketikan pada Connection string :DRIVER=Firebird/InterBase(r)driver;UID=SYSDBA;PWD=MASTERKEY;DBNAME=c:firebirddbfbindoprog.fdbIndoprog 28
  29. 29. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Indoprog 29
  30. 30. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Menampilkan report dari Project Visual BasicUntuk menampilkan Crystal Report ke project anda dapat dilakukan denganmenggunakan komponen “Crystal Report Viewer Control” melalui menu Project,Components, dan Reference ke “Crystal Report 8 Activex Designer runtime library”Dim xApp As New CRAXDRT.ApplicationDim xRpt As New CRAXDRT.ReportPrivate Sub Form_Load()Set xRpt = xApp.OpenReport("C:fbindoprog.rpt")xRpt.DiscardSavedDataxRpt.Database.LogOnServerEx "pdsoledb.dll", "OLE DB", "", "", "", "","DRIVER=Firebird/InterBase(r)driver;UID=SYSDBA;PWD=MASTERKEY;DBNAME=c:firebirddbfbindoprog.fdb"xRpt.Database.Tables(1).SetLogOnInfo "OLE DB","c:firebirddbfbindoprog.fdb", "SYSDBA", "MASTERKEY"CRViewer.ReportSource = xRptCRViewer.ViewReportEnd SubIndoprog 30
  31. 31. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.Lampiran Script Database untuk program Stock untuk dipelajari :/******************************************************************************//**** Generated by IBExpert 2004.04.01 31/8/2004 11:53:57 PM ****//******************************************************************************/SET NAMES NONE;/******************************************************************************//**** Domains ****//******************************************************************************/CREATE DOMAIN MONEY ASNUMERIC(15,2)DEFAULT 0;CREATE DOMAIN SALDOPART ASNUMERIC(10,2)DEFAULT 0;/******************************************************************************//**** Generators ****//******************************************************************************/CREATE GENERATOR GENADJUSTID;SET GENERATOR GENADJUSTID TO 21;CREATE GENERATOR GENAKSESID;SET GENERATOR GENAKSESID TO 55;CREATE GENERATOR GENKARTUPARTID;SET GENERATOR GENKARTUPARTID TO 99;CREATE GENERATOR GENKARTUPARTLOKASIID;SET GENERATOR GENKARTUPARTLOKASIID TO 0;CREATE GENERATOR GENKELUARDETAILID;SET GENERATOR GENKELUARDETAILID TO 18;CREATE GENERATOR GENPARTID;SET GENERATOR GENPARTID TO 0;CREATE GENERATOR GENPODETAILID;SET GENERATOR GENPODETAILID TO 50;CREATE GENERATOR GENSODETAILID;SET GENERATOR GENSODETAILID TO 9;CREATE GENERATOR GENTERIMADETAILID;SET GENERATOR GENTERIMADETAILID TO 61;SET TERM ^ ;/******************************************************************************//**** Stored Procedures ****//******************************************************************************/CREATE PROCEDURE CANCELDATAADJUST ( NOADJUST CHAR(10))RETURNS ( RESULT INTEGER)ASBEGIN EXIT;END^Indoprog 31
  32. 32. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.CREATE PROCEDURE CANCELDATAKELUAR ( NOKELUAR CHAR(10))RETURNS ( RESULT INTEGER)ASBEGIN EXIT;END^CREATE PROCEDURE CANCELDATATERIMA ( NOTERIMA CHAR(10))RETURNS ( RESULT INTEGER)ASBEGIN EXIT;END^CREATE PROCEDURE CLOSEPO ( TANGGAL INTEGER)RETURNS ( RESULT INTEGER)ASBEGIN EXIT;END^CREATE PROCEDURE CLOSESO ( TANGGAL INTEGER)RETURNS ( RESULT INTEGER)ASBEGIN EXIT;END^CREATE PROCEDURE POSTINGKARTUPART ( TANGGAL DATE)RETURNS ( RESULT INTEGER)ASBEGIN EXIT;END^CREATE PROCEDURE POSTINGKARTUPARTLOKASI ( TANGGAL DATE)RETURNS ( RESULT INTEGER)ASBEGIN EXIT;END^CREATE PROCEDURE PRINTDATAKELUAR ( VNOKELUAR CHAR(10))ASBEGIN EXIT;END^CREATE PROCEDURE TUTUPHARIAN (Indoprog 32
  33. 33. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. TANGGAL DATE)RETURNS ( RESULT INTEGER)ASBEGIN EXIT;END^CREATE PROCEDURE TUTUPPERIODE ( BULAN INTEGER, TAHUN INTEGER, BULAN1 INTEGER, TAHUN1 INTEGER)RETURNS ( RESULT INTEGER)ASBEGIN EXIT;END^CREATE PROCEDURE UPDATEPO ( TANGGAL INTEGER)RETURNS ( RESULT INTEGER)ASBEGIN EXIT;END^CREATE PROCEDURE UPDATESO ( TANGGAL INTEGER)RETURNS ( RESULT INTEGER)ASBEGIN EXIT;END^SET TERM ; ^/******************************************************************************//**** Tables ****//******************************************************************************/CREATE TABLE AKSES ( OPERATOR VARCHAR(50), NOMOR INTEGER, KETERANGAN VARCHAR(50), AKSES INTEGER, ID INTEGER NOT NULL);CREATE TABLE DATAADJUST ( JENIS CHAR(1), NOADJUST CHAR(10) NOT NULL, TGLADJUST DATE, PARTNO CHAR(25), KODELOKASI CHAR(10), PARTNAME VARCHAR(30), QTYADJUST NUMERIC(15,2), HARGA NUMERIC(15,2), KETERANGAN1 VARCHAR(50), KETERANGAN2 VARCHAR(50), STATUS CHAR(1) DEFAULT N, ADJUSTID INTEGER,Indoprog 33
  34. 34. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. EBY VARCHAR(20), ETIME DATE, POSTING CHAR(1));CREATE TABLE DATACOMPANY ( KODEPT CHAR(5) NOT NULL, NAMA VARCHAR(30) NOT NULL, ALAMAT VARCHAR(30), KOTA VARCHAR(20), KDKOTA VARCHAR(3), STATUS VARCHAR(2), TELEPON VARCHAR(10), PIMPINAN VARCHAR(20), PARTHOLDER VARCHAR(20), KASIR VARCHAR(20), FRONTDESK VARCHAR(20), DATAHDWS1 VARCHAR(20), DATAHDWS2 VARCHAR(20), DATAHDWS3 VARCHAR(20), BULAN INTEGER DEFAULT 0, TAHUN INTEGER DEFAULT 0, TERAKHIR DATE, EBY VARCHAR(20), ETIME DATE);CREATE TABLE DATACUSTOMER ( KODECUST VARCHAR(20) NOT NULL, NAMACUST VARCHAR(50), ALAMAT1 VARCHAR(50), ALAMAT2 VARCHAR(50), ALAMAT3 VARCHAR(50), TELP VARCHAR(20), HUB VARCHAR(50), NPWP VARCHAR(20), DISC NUMERIC(6,2) DEFAULT 0, JENIS CHAR(1), EBY VARCHAR(20), ETIME DATE);CREATE TABLE DATAHPP ( ID INTEGER, IDHPP INTEGER, QTY NUMERIC(15,2), HPP NUMERIC(15,2));CREATE TABLE DATAHPPLOKASI ( ID INTEGER, IDHPP INTEGER, QTY NUMERIC(15,2), HPP NUMERIC(15,2));CREATE TABLE DATAKARTUPART ( JENIS CHAR(1), NOMOR VARCHAR(10), TANGGAL DATE, PARTNO VARCHAR(20), PARTNAME VARCHAR(50), QTY NUMERIC(15,2), QTYOUT NUMERIC(15,2) DEFAULT 0, HARGA NUMERIC(15,2) DEFAULT 0, HPP NUMERIC(15,2) DEFAULT 0, CARIHPP SMALLINT DEFAULT 0, KODELOKASI CHAR(10), SOURCEID INTEGER, ID INTEGER NOT NULL);Indoprog 34
  35. 35. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.CREATE TABLE DATAKARTUPARTLOKASI ( JENIS CHAR(1), NOMOR VARCHAR(10), TANGGAL DATE, PARTNO VARCHAR(20), PARTNAME VARCHAR(50), QTY NUMERIC(15,2), QTYOUT NUMERIC(15,2) DEFAULT 0, HARGA NUMERIC(15,2) DEFAULT 0, HPP NUMERIC(15,2) DEFAULT 0, CARIHPP SMALLINT DEFAULT 0, KODELOKASI0 CHAR(10), KODELOKASI1 CHAR(10), SOURCEID INTEGER, ID INTEGER NOT NULL);CREATE TABLE DATAKELUAR ( JENIS CHAR(1), NOREGISTER CHAR(10) NOT NULL, NOKELUAR CHAR(10) NOT NULL, TGLKELUAR DATE, TGLJTEMPO DATE, KODELOKASI0 CHAR(10), KODELOKASI1 CHAR(10), KODECUST VARCHAR(20), NAMACUST VARCHAR(50), ALAMAT1 VARCHAR(50), ALAMAT2 VARCHAR(50), NOWO CHAR(10), DISC NUMERIC(6,2), NOSO CHAR(10), KETERANGAN1 VARCHAR(50), KETERANGAN2 VARCHAR(50), STATUS CHAR(1) DEFAULT N, EBY VARCHAR(20), ETIME DATE, POSTING CHAR(1));CREATE TABLE DATAKELUARDETAIL ( D SMALLINT, PARTNO CHAR(25), PARTNAME CHAR(50), QTYSUPPLY NUMERIC(15,2), HARGA NUMERIC(15,2), PDISC NUMERIC(6,2), DISC NUMERIC(15,2), JUMLAH NUMERIC(15,2), JENIS CHAR(1), NOKELUAR CHAR(10), ITEMSO INTEGER, SODETAILID INTEGER, KELUARDETAILID INTEGER NOT NULL, POSTING CHAR(1), KODELOKASI0 CHAR(10), KODELOKASI1 CHAR(10));CREATE TABLE DATALOKASI ( KODELOKASI CHAR(10) NOT NULL, KETERANGAN VARCHAR(50), ALAMAT1 VARCHAR(50), ALAMAT2 VARCHAR(50), ALAMAT3 VARCHAR(50), TELEPON VARCHAR(20), HUBUNGI VARCHAR(30));CREATE TABLE DATAPART (Indoprog 35
  36. 36. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. PARTNO CHAR(25) NOT NULL, PARTNAME VARCHAR(50), TIPE VARCHAR(3), KATEGORI CHAR(1), QTYONHAND NUMERIC(10,2) DEFAULT 0, SATUAN CHAR(10), HET NUMERIC(15,2), PDISCHET NUMERIC(6,2), HMODAL NUMERIC(15,2), PDISCMODAL NUMERIC(6,2), QTYONSO NUMERIC(10,2) DEFAULT 0, QTYONPO NUMERIC(10,2) DEFAULT 0, BBALANCEHPP NUMERIC(15,2) DEFAULT 0, BBALANCE NUMERIC(10,2) DEFAULT 0, MUTASIMASUK NUMERIC(10,2) DEFAULT 0, MUTASIKELUAR NUMERIC(10,2) DEFAULT 0, ADJUSTED NUMERIC(15,2) DEFAULT 0, BBALANCEHPP0 NUMERIC(15,2) DEFAULT 0, BBALANCE0 NUMERIC(10,2) DEFAULT 0, MUTASIMASUK0 NUMERIC(10,2) DEFAULT 0, MUTASIKELUAR0 NUMERIC(10,2) DEFAULT 0, ADJUSTED0 NUMERIC(15,2) DEFAULT 0, NMAX NUMERIC(10,2) DEFAULT 0, NMIN NUMERIC(10,2) DEFAULT 0, NORAK CHAR(11), EBY VARCHAR(20), ETIME DATE);CREATE TABLE DATAPARTLOKASI ( PARTNO CHAR(25), KODELOKASI CHAR(10), BBALANCEHPP MONEY, MUTASIMASUK SALDOPART, MUTASIKELUAR SALDOPART, ADJUSTED SALDOPART, BBALANCEHPP0 SALDOPART, MUTASIMASUK0 SALDOPART, MUTASIKELUAR0 SALDOPART, ADJUSTED0 SALDOPART, PARTID INTEGER NOT NULL);CREATE TABLE DATAPESAN ( PESAN1 VARCHAR(50) NOT NULL, PESAN2 VARCHAR(50), PESAN3 VARCHAR(50), PESAN4 VARCHAR(50));CREATE TABLE DATAPO ( NOPO CHAR(10) NOT NULL, TANGGALPO DATE, DELVDATE DATE, KODESUPP CHAR(10), STATUS CHAR(1) DEFAULT N, EBY VARCHAR(20), ETIME DATE);CREATE TABLE DATAPODETAIL ( D SMALLINT, C SMALLINT, PARTNO CHAR(25), PARTNAME VARCHAR(50), DELVDATE DATE, QTYORDER NUMERIC(15,2), QTYSUPPLY NUMERIC(15,2), ITEMPO INTEGER, STATUS CHAR(1), NOPO CHAR(10),Indoprog 36
  37. 37. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. PODETAILID INTEGER NOT NULL);CREATE TABLE DATARAK ( NORAK CHAR(11) NOT NULL, KETERANGAN VARCHAR(50));CREATE TABLE DATASO ( NOSO CHAR(10) NOT NULL, TANGGALSO DATE, DELVDATE DATE, KODECUST CHAR(10), NOWO CHAR(10), STATUS CHAR(1) DEFAULT N, EBY VARCHAR(20), ETIME DATE);CREATE TABLE DATASODETAIL ( D SMALLINT, C SMALLINT, PARTNO CHAR(25), PARTNAME VARCHAR(50), DELVDATE DATE, QTYORDER NUMERIC(15,2), QTYSUPPLY NUMERIC(15,2), ITEMSO INTEGER, STATUS CHAR(1), NOSO CHAR(10), SODETAILID INTEGER NOT NULL);CREATE TABLE DATASUPPLIER ( KODESUPP VARCHAR(20) NOT NULL, NAMASUPP VARCHAR(50), ALAMAT1 VARCHAR(50), ALAMAT2 VARCHAR(50), ALAMAT3 VARCHAR(50), TELP VARCHAR(20), HUB VARCHAR(50), NPWP VARCHAR(20), DISC NUMERIC(6,2) DEFAULT 0, EBY VARCHAR(20), ETIME DATE);CREATE TABLE DATATERIMA ( JENIS CHAR(1), NOTERIMA CHAR(10) NOT NULL, TGLTERIMA DATE, TGLJTEMPO DATE, KODELOKASI0 CHAR(10), KODELOKASI1 CHAR(10), KODESUPP VARCHAR(20), DISC NUMERIC(6,2), NOPO CHAR(10), KETERANGAN VARCHAR(50), STATUS CHAR(1) DEFAULT N, EBY VARCHAR(20), ETIME DATE, POSTING CHAR(1));CREATE TABLE DATATERIMADETAIL ( D SMALLINT, PARTNO CHAR(25), PARTNAME CHAR(50), QTYSUPPLY NUMERIC(15,2), HARGA NUMERIC(15,2), PDISC NUMERIC(6,2),Indoprog 37
  38. 38. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. DISC NUMERIC(15,2), JUMLAH NUMERIC(15,2), JENIS CHAR(1), NOTERIMA CHAR(10), ITEMPO INTEGER, PODETAILID INTEGER, TERIMADETAILID INTEGER NOT NULL, POSTING CHAR(1), KODELOKASI0 CHAR(10), KODELOKASI1 CHAR(10));CREATE TABLE DATATIPE ( TIPE CHAR(3) NOT NULL, KETERANGAN VARCHAR(30));CREATE TABLE FUNGSI ( AKSES INTEGER NOT NULL, KETERANGAN VARCHAR(50));CREATE TABLE MENUITEM ( NOMOR INTEGER NOT NULL, KETERANGAN VARCHAR(50), AKSES INTEGER);CREATE TABLE OPERATOR ( OPERATOR VARCHAR(50) NOT NULL, NAMA VARCHAR(50), PASSWORDI VARCHAR(50), LEVELI VARCHAR(50), EBY VARCHAR(50), ETIME DATE, LTIME DATE);/******************************************************************************//**** Views ****//******************************************************************************//* View: CETAKFAKTURKELUAR */CREATE VIEW CETAKFAKTURKELUAR( NOREGISTER, NOKELUAR, NOWO, KODECUST, NAMACUST, ALAMAT1, ALAMAT2, TGLKELUAR, ITEMSO, PARTNO, PARTNAME, QTYSUPPLY, DISC, JUMLAH)ASselect DataKeluar.noregister, DataKeluar.nokeluar, DataKeluar.nowo, DataKeluar.kodecust, DataKeluar.namacust, DataKeluar.alamat1, DataKeluar.alamat2,Indoprog 38
  39. 39. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. DataKeluar.tglkeluar, DataKeluarDetail.itemso, DataKeluarDetail.partno, DataKeluarDetail.partname, DataKeluarDetail.qtysupply, DataKeluarDetail.disc, DataKeluarDetail.jumlahfrom DataKeluar Inner Join DataKeluarDetail On DataKeluar.nokeluar =DataKeluarDetail.nokeluar;/* View: LAPORANDATAPART */CREATE VIEW LAPORANDATAPART( PARTNO, PARTNAME, TIPE, QTYONSO, QTYONPO, BBALANCE, MUTASIMASUK, MUTASIKELUAR, ADJUSTED, EBALANCE, NMAX, NMIN)ASselect datapart.partno, datapart.partname, datapart.tipe, datapart.qtyonso, datapart.qtyonpo, datapart.bbalance, datapart.mutasimasuk, datapart.mutasikeluar, datapart.adjusted, datapart.bbalance + datapart.mutasimasuk - datapart.mutasikeluar + datapart.adjustedas EBalance, datapart.nmax, datapart.nminfrom datapartwhere datapart.bbalance + datapart.mutasimasuk + datapart.mutasikeluar <> 0;/* View: LAPORANKARTUSTOCK */CREATE VIEW LAPORANKARTUSTOCK( PARTNO, PARTNAME, KATEGORI, BBALANCE, BBALANCEHPP, JENIS, NOMOR, TANGGAL, QTYHPPMASUK, HPPMASUK, QTYHPPKELUAR, HPPKELUAR)ASselect datapart.partno, datapart.partname, datapart.kategori, datapart.bbalance, datapart.bbalancehpp, datakartupart.jenis, datakartupart.nomor,Indoprog 39
  40. 40. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. datakartupart.tanggal, datakartupart.qty as qtyhppmasuk, datakartupart.harga as hppmasuk, datahpp.qty as qtyhppkeluar, datahpp.hpp as hppkeluarfrom datapart left join datakartupart on datapart.partno = datakartupart.partnoleft join datahpp on datakartupart.id = datahpp.id;/* View: LAPORANPEMBELIAN */CREATE VIEW LAPORANPEMBELIAN( JENIS, NOTERIMA, TGLTERIMA, TGLJTEMPO, KODESUPP, NAMASUPP, NPWP, DISC, NOPO, PARTNO, PARTNAME, QTYSUPPLY, HARGA, DISCOUNT, DPP, PPN, JUMLAH)ASselect dataterima.jenis, dataterima.noterima, dataterima.tglterima, dataterima.tgljtempo, dataterima.kodesupp, datasupplier.namasupp, datasupplier.npwp, dataterima.disc, dataterima.nopo, dataterimadetail.partno, dataterimadetail.partname, dataterimadetail.qtysupply, dataterimadetail.harga, dataterimadetail.qtysupply * dataterimadetail.disc as discount, case when datasupplier.npwp = "" then case when dataterima.jenis = 2 then -dataterimadetail.jumlah else dataterimadetail.jumlah end else case when dataterima.jenis = 2 then -dataterimadetail.jumlah*10/11 else dataterimadetail.jumlah*10/11 end end as DPP, case when datasupplier.npwp = "" then 0 else case when dataterima.jenis = 2 then -dataterimadetail.jumlah*1/11 elseIndoprog 40
  41. 41. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. dataterimadetail.jumlah*1/11 end end as PPN, case when dataterima.jenis = 2 then -dataterimadetail.jumlah else dataterimadetail.jumlah end as Jumlahfrom dataterima inner join dataterimadetail on dataterima.noterima =dataterimadetail.noterima inner join datasupplier on dataterima.kodesupp = datasupplier.kodesuppwhere not dataterimadetail.posting is null and dataterima.status <> "C";/* View: LAPORANPEMBELIANPREPOSTING */CREATE VIEW LAPORANPEMBELIANPREPOSTING( JENIS, NOTERIMA, TGLTERIMA, TGLJTEMPO, KODESUPP, NAMASUPP, NPWP, DISC, NOPO, PARTNO, PARTNAME, QTYSUPPLY, HARGA, DISCOUNT, DPP, PPN, JUMLAH)ASselect dataterima.jenis, dataterima.noterima, dataterima.tglterima, dataterima.tgljtempo, dataterima.kodesupp, datasupplier.namasupp, datasupplier.npwp, dataterima.disc, dataterima.nopo, dataterimadetail.partno, dataterimadetail.partname, dataterimadetail.qtysupply, dataterimadetail.harga, dataterimadetail.qtysupply * dataterimadetail.disc as discount, case when datasupplier.npwp = "" then case when dataterima.jenis = 2 then -dataterimadetail.jumlah else dataterimadetail.jumlah end else case when dataterima.jenis = 2 then -dataterimadetail.jumlah*10/11 else dataterimadetail.jumlah*10/11 end endIndoprog 41
  42. 42. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. as DPP, case when datasupplier.npwp = "" then 0 else case when dataterima.jenis = 2 then -dataterimadetail.jumlah*1/11 else dataterimadetail.jumlah*1/11 end end as PPN, dataterimadetail.jumlahfrom dataterima inner join dataterimadetail on dataterima.noterima =dataterimadetail.noterima inner join datasupplier on dataterima.kodesupp = datasupplier.kodesuppwhere dataterimadetail.posting is null and dataterima.status <> "C";/* View: LAPORANPENDAPATANPENJUALANPART */CREATE VIEW LAPORANPENDAPATANPENJUALANPART( JENIS, NOWO, STATUS, NOKELUAR, TGLKELUAR, JUMLAH, CASH, REGULAR, OLI, PPN)ASselect datakeluar.jenis, datakeluar.nowo, datakeluar.status, datakeluar.nokeluar, datakeluar.tglkeluar, sum( case when datakeluar.jenis = 5 then -datakeluardetail.jumlah else datakeluardetail.jumlah end ) As jumlah, sum( case when datacustomer.jenis = "C" then case when datakeluar.jenis = 5 then -datakeluardetail.jumlah else datakeluardetail.jumlah end else 0 end) as Cash, sum( case when datacustomer.jenis = "C" then 0 else case when datakeluar.jenis = 5 then -datakeluardetail.jumlahIndoprog 42
  43. 43. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. else datakeluardetail.jumlah end end) as Regular, sum( case when datapart.tipe = OLI then case when datakeluar.jenis = 5 then -datakeluardetail.jumlah else datakeluardetail.jumlah end else 0 end) as Oli, sum( case when datapart.tipe = OLI then 0 else case when datakeluar.jenis = 5 then -datakeluardetail.jumlah else datakeluardetail.jumlah end end) as ppnfrom datakeluar inner join datakeluardetail on datakeluar.nokeluar =datakeluardetail.nokeluar inner join datacustomer on datakeluar.kodecust = datacustomer.kodecust inner join datapart on datakeluardetail.partno = datapart.partnowhere datakeluar.jenis=4 or datakeluar.jenis=5Group By datakeluar.jenis, datakeluar.nowo, datakeluar.status, datakeluar.nokeluar, datakeluar.tglkeluar;/* View: LAPORANPENJUALAN */CREATE VIEW LAPORANPENJUALAN( JENIS, NOKELUAR, TGLKELUAR, TGLJTEMPO, KODECUST, NAMACUST, NPWP, DISC, NOSO, PARTNO, PARTNAME, QTYSUPPLY, HARGA, DISCOUNT, JUMLAH)ASselect datakeluar.jenis, datakeluar.nokeluar, datakeluar.tglkeluar, datakeluar.tgljtempo, datakeluar.kodecust, datacustomer.namacust , datacustomer.npwp, datakeluar.disc, datakeluar.noso,Indoprog 43
  44. 44. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. datakeluardetail.partno, datakeluardetail.partname, datakeluardetail.qtysupply, case when datakeluar.jenis = 5 then -datakeluardetail.harga else datakeluardetail.harga end as harga, datakeluardetail.qtysupply * datakeluardetail.disc as discount, case when datakeluar.jenis = 5 then -datakeluardetail.jumlah else datakeluardetail.jumlah end as jumlahfrom datakeluar inner join datakeluardetail on datakeluar.nokeluar =datakeluardetail.nokeluar inner join datacustomer on datakeluar.kodecust = datacustomer.kodecustwhere not datakeluardetail.posting is null and datakeluar.status <> "C";/* View: LAPORANPENJUALANPREPOSTING */CREATE VIEW LAPORANPENJUALANPREPOSTING( JENIS, NOKELUAR, TGLKELUAR, TGLJTEMPO, KODECUST, NAMACUST, NPWP, DISC, NOSO, PARTNO, PARTNAME, QTYSUPPLY, HARGA, DISCOUNT, JUMLAH)ASselect datakeluar.jenis, datakeluar.nokeluar, datakeluar.tglkeluar, datakeluar.tgljtempo, datakeluar.kodecust, datacustomer.namacust , datacustomer.npwp, datakeluar.disc, datakeluar.noso, datakeluardetail.partno, datakeluardetail.partname, datakeluardetail.qtysupply, case when datakeluar.jenis = 5 then -datakeluardetail.harga else datakeluardetail.harga end as harga, datakeluardetail.qtysupply * datakeluardetail.disc as discount, case when datakeluar.jenis = 5 then -datakeluardetail.jumlah else datakeluardetail.jumlahIndoprog 44
  45. 45. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. end as jumlahfrom datakeluar inner join datakeluardetail on datakeluar.nokeluar =datakeluardetail.nokeluar inner join datacustomer on datakeluar.kodecust = datacustomer.kodecustwhere datakeluardetail.posting is null and datakeluar.status <> "C";/* View: LAPORANSUMMARYPENJUALAN */CREATE VIEW LAPORANSUMMARYPENJUALAN( JENIS, NOKELUAR, TGLKELUAR, KODECUST, NAMACUST, SBLMPPN, PPNOLI, PPNPART, TOTAL)ASselect datakeluar.jenis, datakeluar.nokeluar, datakeluar.tglkeluar, datakeluar.kodecust, datacustomer.namacust , sum( case when datakeluar.jenis = 5 then -datakeluardetail.jumlah * 10/11 else datakeluardetail.jumlah * 10/11 end )as sblmppn, sum( case when datapart.tipe = OLI then case when datakeluar.jenis = 5 then -datakeluardetail.jumlah * 1/11 else datakeluardetail.jumlah * 1/11 end else 0 end) as ppnoli, sum( case when datapart.tipe = OLI then 0 else case when datakeluar.jenis = 5 then -datakeluardetail.jumlah * 1/11 else datakeluardetail.jumlah * 1/11 end end) as ppnpart, sum( case when datakeluar.jenis = 5 then -datakeluardetail.jumlah else datakeluardetail.jumlah end ) as totalfrom datakeluar inner join datakeluardetail on datakeluar.nokeluar =datakeluardetail.nokeluarIndoprog 45
  46. 46. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. inner join datacustomer on datakeluar.kodecust = datacustomer.kodecust inner join datapart on datakeluardetail.partno = datapart.partnowhere not datakeluardetail.posting is null and datakeluar.status <> "C"group by datakeluar.jenis, datakeluar.nokeluar, datakeluar.tglkeluar, datakeluar.kodecust, datacustomer.namacust;/* View: REKAPMUTASIPERSEDIAAN */CREATE VIEW REKAPMUTASIPERSEDIAAN( PARTNO, PARTNAME, KATEGORI, BBALANCE, BBALANCEHPP, QTYMASUK, QTYKELUAR, HPPMASUK, HPPKELUAR)ASselect datapart.partno, datapart.partname, datapart.kategori, datapart.bbalance, datapart.bbalancehpp, sum( case when datakartupart.qty > 0 then datakartupart.qty else 0 end) as qtymasuk, sum( case when datakartupart.qty > 0 then 0 else -datakartupart.qty end) as qtykeluar, sum( case when datakartupart.qty > 0 then datakartupart.hpp else 0 end) as hppmasuk, sum( case when datakartupart.qty > 0 then 0 else datakartupart.hpp end) as hppkeluarfrom datapart left join datakartupart on datapart.partno = datakartupart.partnogroup by datapart.partno, datapart.partname, datapart.kategori, datapart.bbalance, datapart.bbalancehpp;Indoprog 46
  47. 47. Pemanfaatan Database Server Open Source Oleh : Hendra, ST./* View: REKAPPENJUALANPART */CREATE VIEW REKAPPENJUALANPART( JENIS, TGLKELUAR, NOHARI, PARTNAME, QTYSUPPLY)ASselect datakeluar.JENIS, datakeluar.tGLKELUAR, extract(day from datakeluar.tGLKELUAR) as NoHari, datakeluarDetail.PARTNO || || datakeluarDetail.PARTNAME, datakeluarDetail.QTYSUPPLYfrom datakeluar inner join datakeluardetail on datakeluar.nokeluar =datakeluardetail.nokeluarwhere datakeluar.status <> "C";/******************************************************************************//**** Unique Constraints ****//******************************************************************************/ALTER TABLE DATAPARTLOKASI ADD CONSTRAINT UNQ_DATAPARTLOKASI UNIQUE (PARTNO, KODELOKASI);/******************************************************************************//**** Primary Keys ****//******************************************************************************/ALTER TABLE AKSES ADD CONSTRAINT PK_AKSES PRIMARY KEY (ID);ALTER TABLE DATAADJUST ADD PRIMARY KEY (NOADJUST);ALTER TABLE DATACOMPANY ADD PRIMARY KEY (KODEPT);ALTER TABLE DATACUSTOMER ADD CONSTRAINT PK_DATACUSTOMER PRIMARY KEY (KODECUST);ALTER TABLE DATAKARTUPART ADD CONSTRAINT PK_DATAKARTUPART PRIMARY KEY (ID);ALTER TABLE DATAKARTUPARTLOKASI ADD CONSTRAINT PK_DATAKARTUPARTLOKASI PRIMARY KEY (ID);ALTER TABLE DATAKELUAR ADD CONSTRAINT PK_DATAKELUAR PRIMARY KEY (NOKELUAR);ALTER TABLE DATAKELUARDETAIL ADD CONSTRAINT PK_DATAKELUARDETAIL PRIMARY KEY(KELUARDETAILID);ALTER TABLE DATALOKASI ADD CONSTRAINT PK_DATALOKASI PRIMARY KEY (KODELOKASI);ALTER TABLE DATAPART ADD PRIMARY KEY (PARTNO);ALTER TABLE DATAPARTLOKASI ADD CONSTRAINT PK_DATAPARTLOKASI PRIMARY KEY (PARTID);ALTER TABLE DATAPESAN ADD CONSTRAINT PK_DATAPESAN PRIMARY KEY (PESAN1);ALTER TABLE DATAPO ADD CONSTRAINT PK_DATAPO PRIMARY KEY (NOPO);ALTER TABLE DATAPODETAIL ADD CONSTRAINT PK_DATAPODETAIL PRIMARY KEY (PODETAILID);ALTER TABLE DATARAK ADD CONSTRAINT PK_DATARAK PRIMARY KEY (NORAK);ALTER TABLE DATASO ADD CONSTRAINT PK_DATASO PRIMARY KEY (NOSO);ALTER TABLE DATASODETAIL ADD CONSTRAINT PK_DATASODETAIL PRIMARY KEY (SODETAILID);ALTER TABLE DATASUPPLIER ADD CONSTRAINT PK_DATASUPPLIER PRIMARY KEY (KODESUPP);ALTER TABLE DATATERIMA ADD CONSTRAINT PK_DATATERIMA PRIMARY KEY (NOTERIMA);ALTER TABLE DATATERIMADETAIL ADD CONSTRAINT PK_DATATERIMADETAIL PRIMARY KEY(TERIMADETAILID);ALTER TABLE DATATIPE ADD CONSTRAINT PK_DATATIPE PRIMARY KEY (TIPE);ALTER TABLE FUNGSI ADD CONSTRAINT PK_FUNGSI PRIMARY KEY (AKSES);ALTER TABLE MENUITEM ADD CONSTRAINT PK_MENUITEM PRIMARY KEY (NOMOR);ALTER TABLE OPERATOR ADD CONSTRAINT PK_OPERATOR PRIMARY KEY (OPERATOR);/******************************************************************************//**** Foreign Keys ****//******************************************************************************/ALTER TABLE DATAADJUST ADD CONSTRAINT FK_DATAADJUSTPARTNO FOREIGN KEY (PARTNO) REFERENCESDATAPART (PARTNO);ALTER TABLE DATAKARTUPART ADD CONSTRAINT FK_DATAKARTUPARTPARTNO FOREIGN KEY (PARTNO)Indoprog 47
  48. 48. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.REFERENCES DATAPART (PARTNO);ALTER TABLE DATAKARTUPARTLOKASI ADD CONSTRAINT FK_DATAKARTUPARTLOKASI FOREIGN KEY(PARTNO) REFERENCES DATAPART (PARTNO);ALTER TABLE DATAKELUAR ADD CONSTRAINT FK_DATAKELUARKODECUST FOREIGN KEY (KODECUST)REFERENCES DATACUSTOMER (KODECUST);ALTER TABLE DATAKELUARDETAIL ADD CONSTRAINT FK_DATAKELUARDETAILNOKELUAR FOREIGN KEY(NOKELUAR) REFERENCES DATAKELUAR (NOKELUAR);ALTER TABLE DATAKELUARDETAIL ADD CONSTRAINT FK_DATAKELUARDETAILPARTNO FOREIGN KEY(PARTNO) REFERENCES DATAPART (PARTNO);ALTER TABLE DATAKELUARDETAIL ADD CONSTRAINT FK_DATAKELUARDETAILSODETAIL FOREIGN KEY(SODETAILID) REFERENCES DATASODETAIL (SODETAILID);ALTER TABLE DATAPART ADD CONSTRAINT FK_DATAPARTNORAK FOREIGN KEY (NORAK) REFERENCESDATARAK (NORAK) ON UPDATE CASCADE USING INDEX FK_DATAPART;ALTER TABLE DATAPART ADD CONSTRAINT FK_DATAPARTTIPE FOREIGN KEY (TIPE) REFERENCESDATATIPE (TIPE) ON UPDATE CASCADE;ALTER TABLE DATAPARTLOKASI ADD CONSTRAINT FK_DATAPARTLOKASIKODELOKASI FOREIGN KEY(KODELOKASI) REFERENCES DATALOKASI (KODELOKASI);ALTER TABLE DATAPARTLOKASI ADD CONSTRAINT FK_DATAPARTLOKASIPARTNO FOREIGN KEY (PARTNO)REFERENCES DATAPART (PARTNO) USING INDEX FK_DATAPARTLOKASI;ALTER TABLE DATAPO ADD CONSTRAINT FK_DATAPO FOREIGN KEY (KODESUPP) REFERENCESDATASUPPLIER (KODESUPP) ON UPDATE CASCADE;ALTER TABLE DATAPODETAIL ADD CONSTRAINT FK_DATAPODETAILNOPO FOREIGN KEY (NOPO) REFERENCESDATAPO (NOPO);ALTER TABLE DATAPODETAIL ADD CONSTRAINT FK_DATAPODETAILPARTNO FOREIGN KEY (PARTNO)REFERENCES DATAPART (PARTNO);ALTER TABLE DATASO ADD CONSTRAINT FK_DATASOKODECUST FOREIGN KEY (KODECUST) REFERENCESDATACUSTOMER (KODECUST);ALTER TABLE DATASODETAIL ADD CONSTRAINT FK_DATASODETAILNOSO FOREIGN KEY (NOSO) REFERENCESDATASO (NOSO);ALTER TABLE DATASODETAIL ADD CONSTRAINT FK_DATASODETAILPARTNO FOREIGN KEY (PARTNO)REFERENCES DATAPART (PARTNO);ALTER TABLE DATATERIMA ADD CONSTRAINT FK_DATATERIMAKODESUPP FOREIGN KEY (KODESUPP)REFERENCES DATASUPPLIER (KODESUPP);ALTER TABLE DATATERIMADETAIL ADD CONSTRAINT FK_DATATERIMADETAILNOTERIMA FOREIGN KEY(NOTERIMA) REFERENCES DATATERIMA (NOTERIMA);ALTER TABLE DATATERIMADETAIL ADD CONSTRAINT FK_DATATERIMADETAILPARTNO FOREIGN KEY(PARTNO) REFERENCES DATAPART (PARTNO);ALTER TABLE DATATERIMADETAIL ADD CONSTRAINT FK_DATATERIMADETAILPODETAIL FOREIGN KEY(PODETAILID) REFERENCES DATAPODETAIL (PODETAILID);/******************************************************************************//**** Triggers ****//******************************************************************************/SET TERM ^ ;/* Trigger: AKSES_BI0 */CREATE TRIGGER AKSES_BI0 FOR AKSESACTIVE BEFORE INSERT POSITION 0ASbegin New.id = Gen_Id(GenAksesID,1);end^/* Trigger: DATAADJUST_DELETE */CREATE TRIGGER DATAADJUST_DELETE FOR DATAADJUSTACTIVE AFTER DELETE POSITION 0ASbeginUpdate datapart Set QtyOnHand = QtyOnHand - Old.qtyadjust Where partno = Old.partno;end^Indoprog 48
  49. 49. Pemanfaatan Database Server Open Source Oleh : Hendra, ST./* Trigger: DATAADJUST_INSERT */CREATE TRIGGER DATAADJUST_INSERT FOR DATAADJUSTACTIVE AFTER INSERT POSITION 0ASbeginUpdate datapart Set QtyOnHand = QtyOnHand + New.qtyadjust Where partno = New.partno;end^/* Trigger: DATAADJUST_UPDATE */CREATE TRIGGER DATAADJUST_UPDATE FOR DATAADJUSTACTIVE AFTER UPDATE POSITION 0ASbeginUpdate datapart Set QtyOnHand = QtyOnHand - Old.qtyadjust Where partno = Old.partno;Update datapart Set QtyOnHand = QtyOnHand + New.qtyadjust Where partno = New.partno;end^/* Trigger: DATAKARTUPARTLOKASI_BI0 */CREATE TRIGGER DATAKARTUPARTLOKASI_BI0 FOR DATAKARTUPARTLOKASIACTIVE BEFORE INSERT POSITION 0ASbegin New.id = Gen_Id(GenKartuPartLokasiID,1);end^/* Trigger: DATAKARTUPART_BI0 */CREATE TRIGGER DATAKARTUPART_BI0 FOR DATAKARTUPARTACTIVE BEFORE INSERT POSITION 0ASbegin New.id = Gen_Id(GenKartuPartID,1);end^/* Trigger: DATAKELUARDETAIL_BI0 */CREATE TRIGGER DATAKELUARDETAIL_BI0 FOR DATAKELUARDETAILACTIVE BEFORE INSERT POSITION 0ASbegin New.keluardetailid = Gen_Id(GenKeluarDetailID,1);end^/* Trigger: DATAKELUARDETAIL_DELETE */CREATE TRIGGER DATAKELUARDETAIL_DELETE FOR DATAKELUARDETAILACTIVE AFTER DELETE POSITION 0ASbegin /*jenis 4 = penjualan, 5= ret. penjualan, 6 = mutasi keluar */ if (old.jenis = 4 or old.jenis=6) then begin Update datapart Set QtyOnHand = QtyOnHand + old.qtysupply where partno = old.partno; Update datasodetail Set QtySupply = QtySupply - Old.qtysupply Where SoDetailID =Old.SoDetailID; end else begin Update datapart Set QtyOnHand = QtyOnHand - old.qtysupply where partno = old.partno; Update datasodetail Set QtySupply = QtySupply + Old.qtysupply Where SoDetailID =Old.SoDetailID; endend^/* Trigger: DATAKELUARDETAIL_INSERT */CREATE TRIGGER DATAKELUARDETAIL_INSERT FOR DATAKELUARDETAILACTIVE AFTER INSERT POSITION 0ASIndoprog 49
  50. 50. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.begin /*jenis 4 = penjualan, 5= ret. penjualan, 6 = mutasi keluar */ if (new.jenis = 4 or new.jenis=6) then begin Update datapart Set QtyOnHand = QtyOnHand - New.qtysupply where partno = New.partno; Update datasodetail Set QtySupply = QtySupply + New.qtysupply Where SoDetailID =New.SoDetailID; end else begin Update datapart Set QtyOnHand = QtyOnHand + New.qtysupply where partno = New.partno; Update datasodetail Set QtySupply = QtySupply - New.qtysupply Where SoDetailID =New.SoDetailID; endend^/* Trigger: DATAKELUARDETAIL_UPDATE */CREATE TRIGGER DATAKELUARDETAIL_UPDATE FOR DATAKELUARDETAILACTIVE AFTER UPDATE POSITION 0ASbegin /*jenis 4 = penjualan, 5= ret. penjualan, 6 = mutasi keluar */ if (old.jenis = 4 or old.jenis=6) then begin Update datapart Set QtyOnHand = QtyOnHand + old.qtysupply where partno = old.partno; Update datasodetail Set QtySupply = QtySupply - old.qtysupply Where SoDetailID =old.SoDetailID; end else begin Update datapart Set QtyOnHand = QtyOnHand - old.qtysupply where partno = old.partno; Update datasodetail Set QtySupply = QtySupply + old.qtysupply Where SoDetailID =old.SoDetailID; end /*jenis 4 = penjualan, 5= ret. penjualan, 6 = mutasi keluar */ if (new.jenis = 4 or new.jenis=6) then begin Update datapart Set QtyOnHand = QtyOnHand - New.qtysupply where partno = New.partno; Update datasodetail Set QtySupply = QtySupply + new.qtysupply Where SoDetailID =new.SoDetailID; end else begin Update datapart Set QtyOnHand = QtyOnHand + New.qtysupply where partno = New.partno; Update datasodetail Set QtySupply = QtySupply - new.qtysupply Where SoDetailID =new.SoDetailID; endend^/* Trigger: DATAPARTLOKASI_BI0 */CREATE TRIGGER DATAPARTLOKASI_BI0 FOR DATAPARTLOKASIACTIVE BEFORE INSERT POSITION 0ASbegin new.partid = gen_id(genpartid,1);end^/* Trigger: DATAPODETAIL_BI0 */CREATE TRIGGER DATAPODETAIL_BI0 FOR DATAPODETAILACTIVE BEFORE INSERT POSITION 0ASbegin New.podetailid = gen_id(genpodetailid,1);end^/* Trigger: DATAPODETAIL_DELETE */CREATE TRIGGER DATAPODETAIL_DELETE FOR DATAPODETAILIndoprog 50
  51. 51. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.ACTIVE AFTER DELETE POSITION 0ASbegin Update DataPart Set QtyOnPO = QtyOnPO - (Old.qtyorder-Old.qtysupply) Where PartNo =Old.PartNo;end^/* Trigger: DATAPODETAIL_INSERT */CREATE TRIGGER DATAPODETAIL_INSERT FOR DATAPODETAILACTIVE AFTER INSERT POSITION 0ASbegin Update datapart set QtyOnPO = QtyOnPO + (New.qtyorder-New.qtySupply) Where PartNo =New.PartNo;end^/* Trigger: DATAPODETAIL_UPDATE */CREATE TRIGGER DATAPODETAIL_UPDATE FOR DATAPODETAILACTIVE AFTER UPDATE POSITION 0ASbegin Update DataPart Set QtyOnPO = QtyOnPO - (Old.qtyorder-Old.qtySupply) Where PartNo =Old.PartNo; Update DataPart Set QtyOnPO = QtyOnPO + (new.qtyorder-New.qtySupply) Where PartNo =New.PartNo;end^/* Trigger: DATASODETAIL_BI0 */CREATE TRIGGER DATASODETAIL_BI0 FOR DATASODETAILACTIVE BEFORE INSERT POSITION 0ASbegin New.sodetailid = gen_id(gensodetailid,1);end^/* Trigger: DATASODETAIL_DELETE */CREATE TRIGGER DATASODETAIL_DELETE FOR DATASODETAILACTIVE AFTER DELETE POSITION 0ASbegin Update DataPart Set QtyOnSO = QtyOnSO - (Old.qtyorder-old.qtysupply) Where PartNo =Old.PartNo;end^/* Trigger: DATASODETAIL_INSERT */CREATE TRIGGER DATASODETAIL_INSERT FOR DATASODETAILACTIVE AFTER INSERT POSITION 0ASbegin Update datapart set QtyOnSO = QtyOnSO + (New.qtyorder-new.qtysupply) Where PartNo =New.PartNo;end^/* Trigger: DATASODETAIL_UPDATE */CREATE TRIGGER DATASODETAIL_UPDATE FOR DATASODETAILACTIVE AFTER UPDATE POSITION 0ASbegin Update DataPart Set QtyOnSO = QtyOnSO - (Old.qtyorder-old.qtysupply) Where PartNo =Old.PartNo; Update DataPart Set QtyOnSO = QtyOnSO + (New.qtyorder-new.qtysupply) Where PartNo =New.PartNo;end^Indoprog 51
  52. 52. Pemanfaatan Database Server Open Source Oleh : Hendra, ST./* Trigger: DATATERIMADETAIL_BI0 */CREATE TRIGGER DATATERIMADETAIL_BI0 FOR DATATERIMADETAILACTIVE BEFORE INSERT POSITION 0ASbegin New.terimadetailid = Gen_Id(GenTerimaDetailID,1);end^/* Trigger: DATATERIMADETAIL_DELETE */CREATE TRIGGER DATATERIMADETAIL_DELETE FOR DATATERIMADETAILACTIVE AFTER DELETE POSITION 0ASbegin /*jenis 1 = pembelian, 2= ret. pembelian, 3 = mutasi masuk */ if (old.jenis = 1 or old.jenis=3) then begin Update datapart Set QtyOnHand = QtyOnHand - old.qtysupply where partno = old.partno; Update datapodetail Set QtySupply = QtySupply - Old.qtysupply Where PoDetailID =Old.PoDetailID; end else begin Update datapart Set QtyOnHand = QtyOnHand + old.qtysupply where partno = old.partno; Update datapodetail Set QtySupply = QtySupply + Old.qtysupply Where PoDetailID =Old.PoDetailID; endend^/* Trigger: DATATERIMADETAIL_INSERT */CREATE TRIGGER DATATERIMADETAIL_INSERT FOR DATATERIMADETAILACTIVE AFTER INSERT POSITION 0ASbegin /*jenis 1 = pembelian, 2= ret. pembelian, 3 = mutasi masuk */ if (new.jenis = 1 or new.jenis=3) then begin Update datapart Set QtyOnHand = QtyOnHand + New.qtysupply where partno = New.partno; Update datapodetail Set QtySupply = QtySupply + New.qtysupply Where PoDetailID =New.PoDetailID; end else begin Update datapart Set QtyOnHand = QtyOnHand - New.qtysupply where partno = New.partno; Update datapodetail Set QtySupply = QtySupply - New.qtysupply Where PoDetailID =New.PoDetailID; endend^/* Trigger: DATATERIMADETAIL_UPDATE */CREATE TRIGGER DATATERIMADETAIL_UPDATE FOR DATATERIMADETAILACTIVE AFTER UPDATE POSITION 0ASbegin /*jenis 1 = pembelian, 2= ret. pembelian, 3 = mutasi masuk */ if (old.jenis = 1 or old.jenis=3) then begin Update datapart Set QtyOnHand = QtyOnHand - old.qtysupply where partno = old.partno; Update datapodetail Set QtySupply = QtySupply - old.qtysupply Where PoDetailID =old.PoDetailID; end else begin Update datapart Set QtyOnHand = QtyOnHand + old.qtysupply where partno = old.partno; Update datapodetail Set QtySupply = QtySupply + old.qtysupply Where PoDetailID =old.PoDetailID; end /*jenis 1 = pembelian, 2= ret. pembelian, 3 = mutasi masuk */ if (new.jenis = 1 or new.jenis=3) thenIndoprog 52
  53. 53. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. begin Update datapart Set QtyOnHand = QtyOnHand + New.qtysupply where partno = New.partno; Update datapodetail Set QtySupply = QtySupply + new.qtysupply Where PoDetailID =new.PoDetailID; end else begin Update datapart Set QtyOnHand = QtyOnHand - New.qtysupply where partno = New.partno; Update datapodetail Set QtySupply = QtySupply - new.qtysupply Where PoDetailID =new.PoDetailID; endend^SET TERM ; ^/******************************************************************************//**** Stored Procedures ****//******************************************************************************/SET TERM ^ ;ALTER PROCEDURE CANCELDATAADJUST ( NOADJUST CHAR(10))RETURNS ( RESULT INTEGER)ASDECLARE VARIABLE VPARTNO CHAR(25);DECLARE VARIABLE VQTYADJUST NUMERIC(15,2);DECLARE VARIABLE VTOTALBARIS Integer;begin VTOTALBARIS = 0; For Select partno, qtyadjust From dataadjust where noadjust = :noadjust and posting isnull Into :vpartno, :vqtyadjust do Begin VTOTALBARIS = VTOTALBARIS+1; Update datapart Set QtyOnHand = QtyOnHand - :VQTYADJUST Where PartNo = :vPartno; Update dataadjust Set Status = "C", Posting = "C" Where noadjust = :noadjust; End Result = VTOTALBARIS;end^ALTER PROCEDURE CANCELDATAKELUAR ( NOKELUAR CHAR(10))RETURNS ( RESULT INTEGER)ASDECLARE VARIABLE VJENIS CHAR(1);DECLARE VARIABLE VPARTNO CHAR(25);DECLARE VARIABLE VQTYSUPPLY NUMERIC(15,2);DECLARE VARIABLE VSODETAILID INTEGER;DECLARE VARIABLE VKELUARDETAILID INTEGER;DECLARE VARIABLE VTOTALBARIS INTEGER;begin VTOTALBARIS = 0; For Select jenis, partno, qtysupply, sodetailid, keluardetailid From datakeluardetailwhere Nokeluar = :nokeluar and posting is null Into :vjenis, :vpartno, :vqtysupply, :vsodetailid, :vkeluardetailid do Begin VTOTALBARIS = VTOTALBARIS+1; /*jenis 4 = penjualan, 5= ret. penjualan, 6 = mutasi keluar */ if (vjenis="4" or vjenis="6") then begin Update datapart Set QtyOnHand = QtyOnHand + :VQTYSUPPLY Where PartNo = :vPartno;Indoprog 53
  54. 54. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. Update datasodetail Set QtySupply = QtySupply + :VQTYSUPPLY Where sodetailid =:vsodetailid; end else begin Update datapart Set QtyOnHand = QtyOnHand - :VQTYSUPPLY Where PartNo = :vPartno; Update datasodetail Set QtySupply = QtySupply - :VQTYSUPPLY Where sodetailid =:vsodetailid; end Update datakeluardetail Set Posting = "C" Where keluardetailid = :VkeluarDETAILID; End Update datakeluar Set Status = "C", Posting = "C" Where Nokeluar = :Nokeluar AndPosting is null; Result = VTOTALBARIS;end^ALTER PROCEDURE CANCELDATATERIMA ( NOTERIMA CHAR(10))RETURNS ( RESULT INTEGER)ASDECLARE VARIABLE VJENIS CHAR(1);DECLARE VARIABLE VPARTNO CHAR(25);DECLARE VARIABLE VQTYSUPPLY NUMERIC(15,2);DECLARE VARIABLE VPODETAILID INTEGER;DECLARE VARIABLE VTERIMADETAILID INTEGER;DECLARE VARIABLE VTOTALBARIS INTEGER;begin VTOTALBARIS = 0; For Select jenis, partno, qtysupply, podetailid, terimadetailid From dataterimadetailwhere NoTerima = :noterima and posting is null Into :vjenis, :vpartno, :vqtysupply, :vpodetailid, :vterimadetailid do Begin VTOTALBARIS = VTOTALBARIS+1; /*jenis 1 = pembelian, 2= ret. pembelian, 3 = mutasi masuk */ if (vjenis="1" or vjenis="3") then begin Update datapart Set QtyOnHand = QtyOnHand - :VQTYSUPPLY Where PartNo = :vPartno; Update datapodetail Set QtySupply = QtySupply - :VQTYSUPPLY Where PoDetailId =:vPODetailId; end else begin Update datapart Set QtyOnHand = QtyOnHand + :VQTYSUPPLY Where PartNo = :vPartno; Update datapodetail Set QtySupply = QtySupply +:VQTYSUPPLY Where PoDetailId =:vPODetailId; end Update dataterimadetail Set Posting = "C" Where terimadetailid = :VTERIMADETAILID; End Update dataterima Set Status = "C", Posting = "C" Where NoTerima = :NoTerima AndPosting is null; Result = VTOTALBARIS;end^ALTER PROCEDURE CLOSEPO ( TANGGAL INTEGER)RETURNS ( RESULT INTEGER)ASDECLARE VARIABLE VQTYORDER NUMERIC(15,2);DECLARE VARIABLE VQTYSUPPLY NUMERIC(15,2);DECLARE VARIABLE VNOPO CHAR(10);DECLARE VARIABLE VPODETAILID INTEGER;DECLARE VARIABLE VCLOSEBARIS INTEGER;DECLARE VARIABLE VPARTNO CHAR(25);DECLARE VARIABLE VBARIS INTEGER;begin VBaris = 0;Indoprog 54
  55. 55. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. for select nopo from datapo where status=N or status=P and TanggalPO <= :tanggal into :VNOPO do begin VCloseBaris = 0; for select podetailid, partno, qtyorder, qtysupply from datapodetail where nopo =:VNOPO into :VPODETAILID, :VPARTNO, :VQTYORDER , :VQTYSUPPLY do begin if (VQTYORDER > VQTYSUPPLY) then begin update datapart set qtyonpo = qtyonpo - (:VQTYORDER-:VQTYSUPPLY) wherepartno = :vpartno; update datapodetail set status = O where podetailid = :VPODETAILID; VCloseBaris = VCloseBaris + 1; VBaris = VBaris + 1; end end if (VCloseBaris > 0) then begin update datapo set status = O where nopo = :VNOPO; end endResult = VBaris;end^ALTER PROCEDURE CLOSESO ( TANGGAL INTEGER)RETURNS ( RESULT INTEGER)ASDECLARE VARIABLE VQTYORDER NUMERIC(15,2);DECLARE VARIABLE VQTYSUPPLY NUMERIC(15,2);DECLARE VARIABLE VNOSO CHAR(10);DECLARE VARIABLE VSODETAILID INTEGER;DECLARE VARIABLE VCLOSEBARIS INTEGER;DECLARE VARIABLE VPARTNO CHAR(25);DECLARE VARIABLE VBARIS INTEGER;begin VBaris = 0; for select noSO from dataSO where status=N or status=P and TanggalSO <= :tanggal into :VNOSO do begin VCloseBaris = 0; for select SOdetailid, partno, qtyorder, qtysupply from dataSOdetail where noSO =:VNOSO into :VSODETAILID, :VPARTNO, :VQTYORDER , :VQTYSUPPLY do begin if (VQTYORDER > VQTYSUPPLY) then begin update datapart set qtyonSO = qtyonSO - (:VQTYORDER-:VQTYSUPPLY) wherepartno = :vpartno; update dataSOdetail set status = O where SOdetailid = :VSODETAILID; VCloseBaris = VCloseBaris + 1; VBaris = VBaris + 1; end end if (VCloseBaris > 0) then begin update dataSO set status = O where noSO = :VNOSO; end endResult = VBaris;end^ALTER PROCEDURE POSTINGKARTUPART ( TANGGAL DATE)RETURNS ( RESULT INTEGER)ASIndoprog 55
  56. 56. Pemanfaatan Database Server Open Source Oleh : Hendra, ST.DECLARE VARIABLE VJENIS INTEGER;DECLARE VARIABLE VNOMOR CHAR(10);DECLARE VARIABLE VTANGGAL DATE;DECLARE VARIABLE VPARTNO CHAR(25);DECLARE VARIABLE VKODELOKASI CHAR(10);DECLARE VARIABLE VPARTNAME VARCHAR(50);DECLARE VARIABLE VQTY NUMERIC(10,2);DECLARE VARIABLE VHARGA NUMERIC(10,2);DECLARE VARIABLE VDETAILID INTEGER;DECLARE VARIABLE VTOTALBARIS INTEGER;DECLARE VARIABLE VID INTEGER;DECLARE VARIABLE VIDHPP INTEGER;DECLARE VARIABLE VQTYKELUAR NUMERIC(15,2);DECLARE VARIABLE VQTYALLREMAIN NUMERIC(15,2);DECLARE VARIABLE VQTYREMAIN NUMERIC(15,2);DECLARE VARIABLE VHPP NUMERIC(15,2);DECLARE VARIABLE VTOTALHPP NUMERIC(15,2);DECLARE VARIABLE VBARIS INTEGER;begin vtotalbaris = 0;/* untuk data terima, 1 = Pembelian, 2 = Ret. Pembelian, mutasi tidak ikut */ for select dataterima.jenis, dataterima.noterima, dataterima.tglterima, dataterimadetail.partno, dataterimadetail.kodelokasi0, dataterimadetail.partname, dataterimadetail.qtysupply, (dataterimadetail.harga-dataterimadetail.disc), dataterimadetail.terimadetailid from dataterima inner join dataterimadetail ondataterima.noterima=dataterimadetail.noterima where (dataterima.jenis ="1" or dataterima.jenis = "2") anddataterima.tglterima = :tanggal and dataterima.posting is null into :VJENIS,:VNOMOR, :VTANGGAL,:VPARTNO, :VKODELOKASI, :VPARTNAME ,:VQTY,:VHARGA,:VDETAILID do begin vtotalbaris = vtotalbaris + 1; /*jenis 1 = pembelian, 2= ret. pembelian*/ if (vjenis="1" ) then begin /*sisip data ke table datakartupart */ insert into datakartupart(jenis,nomor,tanggal,partno,kodelokasi,partname,qty,qtyout,harga,hpp,carihpp, sourceid)values (:vjenis,:VNOMOR, :VTANGGAL,:VPARTNO, :VKODELOKASI, :VPARTNAME ,:VQTY,0,:VHARGA,0,0,:VDETAILID); /*update ke mutasi masuk ditabel datapart */ update datapart set mutasimasuk = mutasimasuk + :VQTY where partno = :VPARTNO; end else begin /*sisip data ke table datakartupart */ insert into datakartupart(jenis,nomor,tanggal,partno,kodelokasi,partname,qty,qtyout,harga,hpp,carihpp, sourceid)values (:vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VKODELOKASI, :VPARTNAME ,-:VQTY,0,:vharga,0,0, :vdetailid); /*update ke mutasi masuk ditabel datapart */ update datapart set mutasimasuk = mutasimasuk -:VQTY where partno = :VPARTNO; end /*update flag posting */ update dataterimadetail set posting = "P" where dataterimadetail.terimadetailid =:vdetailid; update dataterima set status = "P", posting = "P" where dataterima.noterima =:vnomor; endIndoprog 56
  57. 57. Pemanfaatan Database Server Open Source Oleh : Hendra, ST./* untuk data keluar, 4 = Penjualan, 5 = Ret. Penjualan, mutasi tidak ikut */ for select datakeluar.jenis, datakeluar.nokeluar, datakeluar.tglkeluar, datakeluardetail.partno, datakeluardetail.kodelokasi0, datakeluardetail.partname, datakeluardetail.qtysupply, (datakeluardetail.harga-datakeluardetail.disc), datakeluardetail.keluardetailid from datakeluar inner join datakeluardetail ondatakeluar.nokeluar=datakeluardetail.nokeluar where (datakeluar.jenis ="4" or datakeluar.jenis = "5") anddatakeluar.tglkeluar = :tanggal and datakeluar.posting is null into :VJENIS,:VNOMOR, :VTANGGAL,:VPARTNO, :VKODELOKASI, :VPARTNAME ,:VQTY,:VHARGA,:VDETAILID do begin vtotalbaris = vtotalbaris + 1; /*jenis 4 = penjualan, 5= ret. penjualan, 6 = mutasi keluar */ if (vjenis="4") then begin /*sisip data ke table datakartupart */ insert into datakartupart(jenis,nomor,tanggal,partno,kodelokasi,partname,qty,qtyout,harga,hpp,carihpp, sourceid)values (:vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VKODELOKASI, :VPARTNAME ,-:VQTY,0,:vharga,0,0, :vdetailid); /*update ke mutasi masuk ditabel datapart */ update datapart set mutasikeluar = mutasikeluar + :VQTY where partno =:VPARTNO; end else begin /*sisip data ke table datakartupart */ insert into datakartupart(jenis,nomor,tanggal,partno,kodelokasi,partname,qty,qtyout,harga,hpp,carihpp, sourceid)values (:vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VKODELOKASI,:VPARTNAME,:VQTY,0,:vharga,0,0, :vdetailid); /*update ke mutasi masuk ditabel datapart */ update datapart set mutasikeluar = mutasikeluar + :VQTY where partno =:VPARTNO; end /*update flag posting */ update datakeluardetail set posting = "P" where datakeluardetail.keluardetailid =:vdetailid; update datakeluar set status = "P", posting = "P" where datakeluar.nokeluar =:vnomor; end/* untuk data adjust */ for select dataadjust.jenis, dataadjust.noadjust, dataadjust.tgladjust, dataadjust.partno, dataadjust.kodelokasi, dataadjust.partname, dataadjust.qtyadjust, dataadjust.harga, dataadjust.adjustid from dataadjust where dataadjust.tgladjust = :tanggal and dataadjust.postingis null into :VJENIS,:VNOMOR, :VTANGGAL,:VPARTNO, :VKODELOKASI, :VPARTNAME ,:VQTY,:VHARGA,:VDETAILID doIndoprog 57
  58. 58. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. begin vtotalbaris = vtotalbaris + 1; /*sisip data ke table datakartupart */ insert into datakartupart (jenis,nomor,tanggal,partno,kodelokasi,partname,qty,qtyout,harga,hpp,carihpp) values (:VJENIS,:VNOMOR, :VTANGGAL,:VPARTNO, :VKODELOKASI, :VPARTNAME ,:VQTY,0,:VHARGA,0,0); /*update ke adjusted ditabel datapart */ update datapart set adjusted = adjusted + :VQTY where partno = :VPARTNO; /*update flag posting */ update dataADJUST set status = "P", posting = "P" where dataADJUST.noadjust =:vnomor; end/* untuk HPP */ for select datakartupart.partno,datakartupart.qty, datakartupart.id from datakartupart where datakartupart.carihpp = 0 and qty < 0 order by id into :vpartno, :VQTY, :VID do begin vqtykeluar = -vqty; /*qty keluar negatif, jadi dibuat positif */ select sum(qty-qtyout) from datakartupart where datakartupart.partno = :vpartno and (datakartupart.qty-datakartupart.qtyout) > 0 into :vqtyallremain; if (vqtyallremain >= vqtykeluar) then begin vbaris = 0; vtotalhpp = 0; while (vqtykeluar > 0) do begin vbaris = vbaris + 1; select first 1 skip 0 (datakartupart.qty-datakartupart.qtyout), datakartupart.id, datakartupart.harga from datakartupart where datakartupart.partno = :vpartno and (qty-qtyout) > 0 order by idasc into :VQTYREMAIN, :vidhpp, :vhpp; if (vqtykeluar > vqtyremain) then begin insert into datahpp (id,idhpp,qty,hpp) values (:vid,:vidhpp, :vqtyremain, :vhpp); update datakartupart set qtyout=qtyout + :VQTYREMAIN where id =:vidhpp; vqtykeluar = vqtykeluar-vqtyremain; vtotalhpp = vtotalhpp + (vqtyremain*vhpp); end else begin insert into datahpp (id,idhpp,qty,hpp) values (:vid,:vidhpp, :vqtykeluar, :vhpp); update datakartupart set qtyout=qtyout + :VQTYkeluar where id = :vidhpp; vtotalhpp = vtotalhpp + (vqtykeluar*vhpp); vqtykeluar = 0; end end /*end of while*/ update datakartupart set hpp = :vtotalhpp, carihpp = :VBARIS where id = :vid; end /* end of if (vqtyallremain >= vqtykeluar) */ end result = vtotalbaris;end^ALTER PROCEDURE POSTINGKARTUPARTLOKASI ( TANGGAL DATE)RETURNS (Indoprog 58
  59. 59. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. RESULT INTEGER)ASDECLARE VARIABLE VJENIS INTEGER;DECLARE VARIABLE VNOMOR CHAR(10);DECLARE VARIABLE VTANGGAL DATE;DECLARE VARIABLE VPARTNO CHAR(25);DECLARE VARIABLE VPARTNAME VARCHAR(50);DECLARE VARIABLE VQTY NUMERIC(10,2);DECLARE VARIABLE VHARGA NUMERIC(10,2);DECLARE VARIABLE VDETAILID INTEGER;DECLARE VARIABLE VTOTALBARIS INTEGER;DECLARE VARIABLE VID INTEGER;DECLARE VARIABLE VIDHPP INTEGER;DECLARE VARIABLE VQTYKELUAR NUMERIC(15,2);DECLARE VARIABLE VQTYALLREMAIN NUMERIC(15,2);DECLARE VARIABLE VQTYREMAIN NUMERIC(15,2);DECLARE VARIABLE VHPP NUMERIC(15,2);DECLARE VARIABLE VTOTALHPP NUMERIC(15,2);DECLARE VARIABLE VBARIS INTEGER;begin vtotalbaris = 0;/* untuk data terima */ for select dataterima.jenis, dataterima.noterima, dataterima.tglterima, dataterimadetail.partno, dataterimadetail.partname, dataterimadetail.qtysupply, (dataterimadetail.harga-dataterimadetail.disc), dataterimadetail.terimadetailid from dataterima inner join dataterimadetail ondataterima.noterima=dataterimadetail.noterima where dataterima.tglterima = :tanggal and dataterima.posting is null into :vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VPARTNAME ,:VQTY ,:vharga,:vdetailid do begin vtotalbaris = vtotalbaris + 1; /*jenis 1 = pembelian, 2= ret. pembelian, 3 = mutasi masuk */ if (vjenis="1" or vjenis="3") then begin /*sisip data ke table datakartupartlokasi */ insert into datakartupartlokasi(jenis,nomor,tanggal,partno,partname,qty,qtyout,harga,hpp,carihpp, sourceid) values (:vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VPARTNAME ,:VQTY,0,:vharga,0,0,:vdetailid); /*update ke mutasi masuk ditabel datapartlokasi */ update datapartlokasi set mutasimasuk = mutasimasuk + :VQTY where partno =:VPARTNO; end else begin /*sisip data ke table datakartupartlokasi */ insert into datakartupartlokasi(jenis,nomor,tanggal,partno,partname,qty,qtyout,harga,hpp,carihpp, sourceid) values (:vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VPARTNAME ,-:VQTY ,0,:vharga,0,0,:vdetailid); /*update ke mutasi masuk ditabel datapartlokasi */ update datapartlokasi set mutasimasuk = mutasimasuk -:VQTY where partno =:VPARTNO; end /*update flag posting */ update dataterimadetail set posting = "P" where dataterimadetail.terimadetailid =:vdetailid; update dataterima set status = "P", posting = "P" where dataterima.noterima =:vnomor; end/* untuk data keluar */Indoprog 59
  60. 60. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. for select datakeluar.jenis, datakeluar.nokeluar, datakeluar.tglkeluar, datakeluardetail.partno, datakeluardetail.partname, datakeluardetail.qtysupply, (datakeluardetail.harga-datakeluardetail.disc), datakeluardetail.keluardetailid from datakeluar inner join datakeluardetail ondatakeluar.nokeluar=datakeluardetail.nokeluar where datakeluar.tglkeluar = :tanggal and datakeluar.posting is null into :vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VPARTNAME ,:VQTY ,:vharga,:vdetailid do begin vtotalbaris = vtotalbaris + 1; /*jenis 4 = penjualan, 5= ret. penjualan, 6 = mutasi keluar */ if (vjenis="4" or vjenis="6") then begin /*sisip data ke table datakartupartlokasi */ insert into datakartupartlokasi(jenis,nomor,tanggal,partno,partname,qty,qtyout,harga,hpp,carihpp, sourceid) values (:vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VPARTNAME ,-:VQTY ,0,:vharga,0,0,:vdetailid); /*update ke mutasi masuk ditabel datapartlokasi */ update datapartlokasi set mutasikeluar = mutasikeluar + :VQTY where partno =:VPARTNO; end else begin /*sisip data ke table datakartupartlokasi */ insert into datakartupartlokasi(jenis,nomor,tanggal,partno,partname,qty,qtyout,harga,hpp,carihpp, sourceid) values (:vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VPARTNAME ,:VQTY ,0,:vharga,0,0,:vdetailid); /*update ke mutasi masuk ditabel datapartlokasi */ update datapartlokasi set mutasikeluar = mutasikeluar + :VQTY where partno =:VPARTNO; end /*update flag posting */ update datakeluardetail set posting = "P" where datakeluardetail.keluardetailid =:vdetailid; update datakeluar set status = "P", posting = "P" where datakeluar.nokeluar =:vnomor; end/* untuk data adjust */ for select dataadjust.jenis, dataadjust.noadjust, dataadjust.tgladjust, dataadjust.partno, dataadjust.partname, dataadjust.qtyadjust, dataadjust.harga, dataadjust.adjustid from dataadjust where dataadjust.tgladjust = :tanggal and dataadjust.postingis null into :vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VPARTNAME ,:VQTY ,:vharga,:vdetailid do begin vtotalbaris = vtotalbaris + 1; /*sisip data ke table datakartupartlokasi */ insert into datakartupartlokasi(jenis,nomor,tanggal,partno,partname,qty,qtyout,harga,hpp,carihpp) values (:vjenis,:VNOmor, :Vtanggal,:VPARTNO, :VPARTNAME ,:VQTY ,0,:vharga,0,0); /*update ke adjusted ditabel datapartlokasi */Indoprog 60
  61. 61. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. update datapartlokasi set adjusted = adjusted + :VQTY where partno = :VPARTNO; /*update flag posting */ update dataADJUST set status = "P", posting = "P" where dataADJUST.noadjust =:vnomor; end/* untuk HPP */ for select datakartupartlokasi.partno,datakartupartlokasi.qty, datakartupartlokasi.idfrom datakartupartlokasi where datakartupartlokasi.carihpp = 0 and qty < 0 order by id into :vpartno, :VQTY, :VID do begin vqtykeluar = -vqty; /*qty keluar negatif, jadi dibuat positif */ select sum(qty-qtyout) from datakartupartlokasi where datakartupartlokasi.partno = :vpartno and (datakartupartlokasi.qty-datakartupartlokasi.qtyout) > 0 into :vqtyallremain; if (vqtyallremain >= vqtykeluar) then begin vbaris = 0; vtotalhpp = 0; while (vqtykeluar > 0) do begin vbaris = vbaris + 1; select first 1 skip 0 (datakartupartlokasi.qty-datakartupartlokasi.qtyout), datakartupartlokasi.id, datakartupartlokasi.harga from datakartupartlokasi where datakartupartlokasi.partno = :vpartno and (qty-qtyout) > 0 orderby id asc into :VQTYREMAIN, :vidhpp, :vhpp; if (vqtykeluar > vqtyremain) then begin insert into datahpplokasi (id,idhpp,qty,hpp) values (:vid,:vidhpp, :vqtyremain, :vhpp); update datakartupartlokasi set qtyout=qtyout + :VQTYREMAIN where id =:vidhpp; vqtykeluar = vqtykeluar-vqtyremain; vtotalhpp = vtotalhpp + (vqtyremain*vhpp); end else begin insert into datahpplokasi (id,idhpp,qty,hpp) values (:vid,:vidhpp, :vqtykeluar, :vhpp); update datakartupartlokasi set qtyout=qtyout + :VQTYkeluar where id = :vidhpp; vtotalhpp = vtotalhpp + (vqtykeluar*vhpp); vqtykeluar = 0; end end /*end of while*/ update datakartupartlokasi set hpp = :vtotalhpp, carihpp = :VBARIS where id = :vid; end /* end of if (vqtyallremain >= vqtykeluar) */ end result = vtotalbaris;end^ALTER PROCEDURE PRINTDATAKELUAR ( VNOKELUAR CHAR(10))ASbegin update datakeluar set status = L Where Nokeluar = :VNOKELUAR;end^ALTER PROCEDURE TUTUPHARIAN ( TANGGAL DATE)RETURNS (Indoprog 61
  62. 62. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. RESULT INTEGER)ASDECLARE VARIABLE VBELUMPOSTINGKELUAR INTEGER;DECLARE VARIABLE VBELUMPOSTINGTERIMA INTEGER;DECLARE VARIABLE VBELUMPOSTINGADJUST INTEGER;DECLARE VARIABLE VTOTALBELUMPOSTING INTEGER;begin select count(*) From datakeluar where posting is null and tglkeluar = :tanggal into :VBELUMPOSTINGKELUAR; select count(*) From dataterima where posting is null and tglterima = :tanggal into :VBELUMPOSTINGTERIMA; select count(*) From dataadjust where posting is null and tgladjust = :tanggal into :VBELUMPOSTINGADJUST; VTOTALBELUMPOSTING = VBELUMPOSTINGKELUAR+VBELUMPOSTINGTERIMA+VBELUMPOSTINGADJUST; if (VTOTALBELUMPOSTING = 0) then begin Update DataCompany Set Terakhir = :tanggal; Result = 0; end else begin Result = VTOTALBELUMPOSTING; endend^ALTER PROCEDURE TUTUPPERIODE ( BULAN INTEGER, TAHUN INTEGER, BULAN1 INTEGER, TAHUN1 INTEGER)RETURNS ( RESULT INTEGER)ASDECLARE VARIABLE VBULAN INTEGER;DECLARE VARIABLE VTAHUN INTEGER;DECLARE VARIABLE VBELUMPOSTINGKELUAR INTEGER;DECLARE VARIABLE VBELUMPOSTINGTERIMA INTEGER;DECLARE VARIABLE VBELUMPOSTINGADJUST INTEGER;DECLARE VARIABLE VTOTALBELUMPOSTING INTEGER;begin select bulan,tahun from datacompany into :VBULAN, :VTAHUN; if (Bulan = VBULAN and Tahun = VTAHUN ) then begin select count(*) From datakeluar where posting is null and (Extract(month from tglkeluar) = :bulan) and (Extract(year from tglkeluar)=:tahun) into :VBELUMPOSTINGKELUAR; select count(*) From dataterima where posting is null and (Extract(month from tglterima) = :bulan) and (Extract(year from tglterima)=:tahun) into :VBELUMPOSTINGTERIMA; select count(*) From dataadjust where posting is null and (Extract(month from tgladjust) = :bulan) and (Extract(year from tgladjust)=:tahun) into :VBELUMPOSTINGADJUST; VTOTALBELUMPOSTING = VBELUMPOSTINGKELUAR+VBELUMPOSTINGTERIMA+VBELUMPOSTINGADJUST;Indoprog 62
  63. 63. Pemanfaatan Database Server Open Source Oleh : Hendra, ST. if (VTOTALBELUMPOSTING= 0) then Begin Update DataPart Set BBalanceHPP0 = BBalanceHPP, BBalance0 = BBalance, MutasiKeluar0 = MutasiKeluar, MutasiMasuk0 = MutasiMasuk, Adjusted0 = Adjusted; Update DataPart Set BBalance = BBalance0-MutasiKeluar0+MutasiMasuk0+Adjusted0, MutasiKeluar = 0, MutasiMasuk = 0, Adjusted = 0; /*Menghitung nilai BBalanceHPP */ Update DataPart Set BBalanceHPP = (select sum((qty-qtyout)*hpp) from datakartupart where partno =datapart.partno and qty > 0); Update DataCompany Set Bulan=:Bulan1, Tahun=:Tahun1; Result = 0; End else Begin Result = VTOTALBELUMPOSTING; End end else begin Result = -1; endend^ALTER PROCEDURE UPDATEPO ( TANGGAL INTEGER)RETURNS ( RESULT INTEGER)ASDECLARE VARIABLE VQTYORDER NUMERIC(15,2);DECLARE VARIABLE VQTYSUPPLY NUMERIC(15,2);DECLARE VARIABLE VNOPO CHAR(10);DECLARE VARIABLE VPODETAILID INTEGER;DECLARE VARIABLE VPARTNO CHAR(25);DECLARE VARIABLE VBARIS INTEGER;DECLARE VARIABLE VBARISA INTEGER;DECLARE VARIABLE VBARISF INTEGER;DECLARE VARIABLE VBARISP INTEGER;DECLARE VARIABLE VBARISN INTEGER;begin VBaris = 0; for select noPO from dataPO where status=N or status=P and TanggalPO <= :tanggal into :VNOPO do begin VBARISA = 0; VBARISF = 0; VBARISP = 0; VBARISN = 0; for select POdetailid, partno, qtyorder, qtysupply from dataPOdetail where noPO =:VNOPO into :VPODETAILID, :VPARTNO, :VQTYORDER , :VQTYSUPPLY do begin if (VQTYORDER <= VQTYSUPPLY) then begin update dataPOdetail set status = F where POdetailid = :VPODETAILID; VBARISF = VBARISF + 1; end else if (VQTYSUPPLY > 0) then begin update dataPOdetail set status = P where POdetailid = :VPODETAILID; VBARISP = VBARISP + 1; end elseIndoprog 63

×