You are on page 1of 1

create procedure trans(pel varchar(50),bar varchar(50), jum int,kary varchar(50) ) begin declare idpel char(4); declare idbar char(4);

declare idkar char(4); declare stc int; declare kode int; declare id char(4); declare ultah date; declare disc double; select id_pelanggan into idpel from pelanggan where nama= pel; select id_barang into idbar from barang where nama= bar; select id_karyawan into idkar from karyawan where nama= kary; select tgl_lahir into ultah from pelanggan where nama = pel; select pel'Nama Pelanggan',nama'nama barang',stok,jum'Jumlah yang di bel i', if(stok < jum,'Stok barang tidak cukup',jum*harga)'Keterangan', if(right(ultah,5)=right(curdate(),5),(jum*harga*0.2),'Tidak ada Diskon') 'Diskon', if(right(ultah,5)=right(curdate(),5),(Jum*harga)-(jum*harga*0.2),(jum*ha rga))'Jumlah yang di bayar' from barang where nama = bar; select stok into stc from barang where nama = bar; if stc > jum then select count(kode_transaksi) into kode from transaksi t; set kode = kode+1; if kode<10 then set id = concat('J00',kode); elseif kode<100 then set id = concat('J0',kode); elseif kode>100 then set id = concat('J',kode); end if; insert into transaksi set kode_transaksi = id , tgl_transaksi = now() , id_pelanggan = idpel , id_karyawan = idkar; insert into detail_transaksi set kode_transaksi = id , id_barang=idbar,j umlah=jum; update barang set stok = stok - jum where nama = bar; end if; end

You might also like