TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER `BeforeAdd_DetBeli` BEFORE INSERT ON `tr_beli_d` FOR EACH ROW BEGIN\n  DECLARE vSatuan VARCHAR(255);\n DECLARE vSatuan1 VARCHAR(255);\n DECLARE vSatuan2 VARCHAR(255);\n   DECLARE vSatuan3 VARCHAR(255);\n  DECLARE vKonv1 DOUBLE;\n  DECLARE vKonv2 DOUBLE;\n  DECLARE vKonv3 DOUBLE;\n select satuan,satuan1,satuan2,satuan3,konv1,konv2,konv3 into vSatuan,vSatuan1,vSatuan2,vSatuan3,vKonv1,vKonv2,vKonv3 from tm_barang where kodebrg=new.kodebrg;\nif new.satuan = vSatuan then\n   set new.konv=1;\nend if;\nif new.satuan = vSatuan1 then\n  set new.konv=vKonv1;\nend if;\nif new.satuan =vSatuan2 then\n  set new.konv=vKonv2;\nend if;\nif new.satuan = vSatuan3 then\n  set new.konv = vKonv3;\nend if;\nEND' 'CREATE DEFINER=`root`@`localhost` TRIGGER `DetBeliAdd` AFTER INSERT ON `tr_beli_d` FOR EACH ROW BEGIN\nDECLARE HargaLama DOUBLE;\nDECLARE StockLama DOUBLE;\nDECLARE HitungLama DOUBLE;\nDECLARE HargaBaru, HargaBaruPPN DOUBLE;\nDECLARE JumlahBaru DOUBLE;\nDECLARE HitungBaru DOUBLE;\nDECLARE StockHasil DOUBLE;\nDECLARE HitungHasil DOUBLE;\nDECLARE HargaHasil DOUBLE;\nDECLARE HargaDisc, hppdisc DOUBLE;\nDECLARE NilaiPPN DOUBLE;\nDECLARE vTemp DOUBLE;\nSET StockLama=(SELECT ifnull(StockAkhir,0) FROM tm_StockBrg WHERE KodeBrg=new.KodeBrg and KodeGD=new.KodeGD );\nIF StockLama is NULL THEN \n   SET StockLama=0;\nEND IF;\nIF StockLama < 0 THEN \n   SET StockLama=0;\nEND IF;\nSET HargaLama=(SELECT ifnull(HargaAvg,0) FROM tm_barang WHERE KodeBrg=new.KodeBrg);\nIF HargaLama is NULL THEN \n   SET HargaLama=0;\nEND IF;\nSET HitungLama=HargaLama * StockLama;\nSET hppdisc = (ifnull(new.Harga,0) * (ifnull(new.disc,0)/100)); \nSET Hargadisc =(ifnull(new.Harga,0) * (ifnull(new.disc,0)/100)); \nSET HargaBaru=(ifnull(new.Harga,0)- ifnull(Hargadisc,0)) /ifnull(new.konv,1);\nSET HargaBaruPPN= HargaBaru +(ifnull(hargaBaru,0)*(ifnull(new.PPN,0)/100));\nSET JumlahBaru=ifnull(new.Jml,0) *ifnull( new.Konv,1);\nSET HitungBaru=HargaBaruPPN * JumlahBaru;\nSET StockHasil=StockLama + JumlahBaru;\nSET HitungHasil=HitungLama + HitungBaru;\nSET HargaHasil= HitungHasil / StockHasil;\nSet NilaiPPN = HargaHasil;\nSELECT COUNT(*) into vTemp FROM tm_stockbrg WHERE kodebrg=new.kodebrg and kodeGd=new.KodeGD ;\n    \nIF vTemp <=0 THEN\n    INSERT INTO tm_stockbrg(kodebrg,namabrg, kodegd, stockakhir,ukuran) VALUES(new.kodebrg,new.namabrg,new.kodegd,JumlahBaru,new.ukuran);\nEND IF;\nIF new.NoPO <> \'\' then\n    UPDATE tr_pobeli_d SET SdhTerima=IFNULL(SdhTerima,0) + new.Jml WHERE NoPO=new.NoPO AND ItemPO=new.ItemPO AND KodeBrg=new.KodeBrg;\nEND IF;\nEND' 'CREATE DEFINER=`root`@`localhost` TRIGGER `BeforeUpd_DetBeli` BEFORE UPDATE ON `tr_beli_d` FOR EACH ROW BEGIN\n  DECLARE vSatuan VARCHAR(255);\n DECLARE vSatuan1 VARCHAR(255);\n DECLARE vSatuan2 VARCHAR(255);\n   DECLARE vSatuan3 VARCHAR(255);\n  DECLARE vKonv1 DOUBLE;\n  DECLARE vKonv2 DOUBLE;\n  DECLARE vKonv3 DOUBLE;\n select satuan,satuan1,satuan2,satuan3,konv1,konv2,konv3 into vSatuan,vSatuan1,vSatuan2,vSatuan3,vKonv1,vKonv2,vKonv3 from tm_barang where kodebrg=new.kodebrg;\nif new.satuan = vSatuan then\n set new.konv=1;\nend if;\nif new.satuan = vSatuan1 then\n  set new.konv=vKonv1;\nend if;\nif new.satuan =vSatuan2 then\n  set new.konv=vKonv2;\nend if;\nif new.satuan = vSatuan3 then\n  set new.konv = vKonv3; \nend if;\nEND' 'CREATE DEFINER=`root`@`localhost` TRIGGER `DetBeliUpdate` AFTER UPDATE ON `tr_beli_d` FOR EACH ROW BEGIN\nDECLARE HargaBaru DOUBLE;\nDECLARE HargaDisc, hppdisc DOUBLE;\nDECLARE NilaiPPN DOUBLE;\nSET Hargadisc =(ifnull(new.Harga,0) * (ifnull(new.disc,0)/100)); \nSET HargaBaru=(ifnull(new.Harga,0)- ifnull(Hargadisc,0)) /ifnull(new.konv,1);\nSet NilaiPPN = HargaBaru +(ifnull(hargaBaru,0)*(ifnull(new.PPN,0)/100));\nIF old.NoPO <> \'\' then\n    UPDATE tr_pobeli_d SET SdhTerima=IFNULL(SdhTerima,0) - old.Jml WHERE NoPO=old.NoPO AND ItemPO=old.ItemPO AND KodeBrg=old.KodeBrg;\nEND IF;\nIF new.NoPO <> \'\' then\n    UPDATE tr_pobeli_d SET SdhTerima=IFNULL(SdhTerima,0) + new.Jml WHERE NoPO=new.NoPO AND ItemPO=new.ItemPO AND KodeBrg=new.KodeBrg;\nEND IF;\nend' 'CREATE DEFINER=`root`@`localhost` TRIGGER `DetBeliDelete` AFTER DELETE ON `tr_beli_d` FOR EACH ROW BEGIN\n  \nIF old.NoPO <> \'\' then\n    UPDATE tr_pobeli_d SET SdhTerima=IFNULL(SdhTerima,0) - old.Jml WHERE NoPO=old.NoPO AND ItemPO=old.ItemPO AND KodeBrg=old.KodeBrg;\nEND IF;\nend'
sql_modes=524288 524288 524288 524288 524288
definers='root@localhost' 'root@localhost' 'root@localhost' 'root@localhost' 'root@localhost'
