select (sum(debet) - sum(kredit)) saldoakhir from ( select 'AD' Urut, 'JUAL GROSIR' Kode,mst.tgljual as Tanggal, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*0 as Kredit, concat(mst.transjual,'-',mst.nojual) nobukti, concat(mst.transjual,'-',mst.nojual) ref, ifnull(Nilai,0)*0 as Saldo from Tr_Jual_M Mst where 1=1 and kodeCust=&kodeCust1 union all select 'AXK' Urut, 'BATAL JUAL GROSIR' Kode,mst.tglbatal, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*0 as Debet, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, concat(mst.transjual,'-',mst.nojual) nobukti, concat(mst.transjual,'-',mst.nojual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_Jual_M Mst where 1=1 and ifnull(tglbatal,'')<>'' and kodeCust=&kodeCust1 union all select 'BK' Urut, 'RETJUAL GROSIR' Kode,mst.tglretj as Tanggal,ifnull(nilai,0)*0 as Debet, ifnull(nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, concat(mst.transretj,'-',mst.noretj) nobukti,concat(mst.transjual,'-',mst.nojual) ref, ifnull(Nilai,0)*0 as Saldo from Tr_RetJual_M Mst where 1=1 and kodeCust=&KodeCust1 union all select 'BXD' Urut, 'BATAL RETJUAL GROS' Kode,mst.tglbatal,ifnull(nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(nilai,0)*0 as Kredit, concat(mst.transretj,'-',mst.noRetj) nobukti,concat(mst.transJual,'-',mst.noJual) ref, ifnull(Nilai,0)*0 as Saldo from Tr_RetJual_M Mst where 1=1 and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 union all select 'CD' Urut, 'JUAL RKT' Kode,mst.tgljual as Tanggal, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*0 as Kredit,concat(mst.transjual,'-',mst.nojual) nobukti, concat(mst.transjual,'-',mst.nojual) ref, ifnull(Nilai,0)*0 as Saldo from Tr_JualRakitan_M Mst where 1=1 and kodeCust=&KodeCust1 union all select 'CXK' Urut,'BATAL JUAL RKT' Kode,mst.tglbatal, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*0 as Debet, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, concat(mst.transjual,'-',mst.nojual) nobukti,concat(mst.transjual,'-',mst.nojual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_JualRakitan_M Mst where 1=1 and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 union all select 'DK' Urut, 'RETJUAL RKT' Kode,mst.tglretj as Tanggal,ifnull(nilai,0)*0 as Debet, ifnull(nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, concat(mst.transretj,'-',mst.noretj) nobukti,concat(mst.transjual,'-',mst.nojual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_RetJualRakitan_M Mst where 1=1 and kodeCust=&KodeCust1 union all select 'DXD' Urut,'BATAL RETJUAL RKT' Kode, mst.tglbatal,ifnull(nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(nilai,0)*0 as Kredit, concat(mst.transretj,'-',mst.noRetj) nobukti,concat(mst.transJual,'-',mst.noJual) ref, ifnull(Nilai,0)*0 as Saldo from Tr_RetJualRakitan_M Mst where 1=1 and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 union all select 'F1K' Urut, 'BAYAR JUAL GROSIR' Kode,mst.tglBayarJ as Tanggal,ifnull(nilai,0)*0 as Debet, ifnull(nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, concat(dets.transJual,'-',dets.noJual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_ScrBayarJual dets where mst.nobayarj=dets.nobayarj and kodeCust=&KodeCust1 union all select 'FX1D' Urut,'BATAL BYR J.GROS' Kode,mst.tglbatal, ifnull(nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(nilai,0)*0 as Kredit,mst.noBayarJ nobukti, concat(dets.transJual,'-',dets.noJual) ref, ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_ScrBayarJual dets where mst.nobayarJ=dets.nobayarJ and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 union all select 'F1K' Urut, 'BAYAR JUAL RKT' Kode,mst.tglBayarJ as Tanggal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, concat(dets.transJual,'-',dets.noJual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJualRakitan_M Mst,Tr_ScrBayarJualRakitan dets where mst.nobayarj=dets.nobayarj and kodeCust=&KodeCust1 union all select 'FX1D' Urut,'BATAL BYR JUAL RKT' Kode,mst.tglbatal, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit,mst.noBayarJ nobukti, concat(dets.transJual,'-',dets.noJual) ref, ifnull(Nilai,0)*0 as Saldo from Tr_BayarJualRakitan_M Mst,Tr_ScrBayarJualRakitan dets where mst.nobayarJ=dets.nobayarJ and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 union all select 'F2D' Urut, 'DGN BG' Kode,mst.tglBayarJ as Tanggal, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit, mst.noBayarJ nobukti,dets.noBG ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='BG' and kodeCust=&KodeCust1 union all select 'FX2K' Urut,'BATAL DGN BG' Kode,mst.tglbatal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, dets.noBG ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='BG' and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 union all select 'F3D' Urut, 'DGN CN' Kode,mst.tglBayarJ as Tanggal, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit, mst.noBayarJ nobukti,dets.nobukti ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='CRNota' and kodeCust=&KodeCust1 union all select 'FX3K' Urut,'BATAL DGN CN' Kode,mst.tglbatal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, dets.nobukti ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='CRNota' and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 union all select 'F4D' Urut, 'DGN DN' Kode,mst.tglBayarJ as Tanggal, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit, mst.noBayarJ nobukti,dets.nobukti ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='DBNota' and kodeCust=&KodeCust1 union all select 'FX4K' Urut,'BATAL DGN DN' Kode,mst.tglbatal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, dets.nobukti ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='DBNota' and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 union all select 'F5D' Urut, 'DGN RETJ' Kode,mst.tglBayarJ as Tanggal, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit, mst.noBayarJ nobukti, concat(dets.trans,'-',dets.nobukti) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='Retur' and kodeCust=&KodeCust1 union all select 'FX5K' Urut,'BATAL DGN RETJ' Kode,mst.tglbatal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, concat(dets.trans,'-',dets.nobukti) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='Retur' and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 union all select 'F6D' Urut, 'DGN TITIP' Kode,mst.tglBayarJ as Tanggal, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit, mst.noBayarJ nobukti, concat(dets.trans,'-',dets.nobukti) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='Titipan' and kodeCust=&KodeCust1 union all select 'FX6K' Urut,'BATAL DGN TITIP' Kode,mst.tglbatal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, concat(dets.trans,'-',dets.nobukti) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='Titipan' and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 union all select 'AX' Urut,'SALDO AWAL' Kode,cast('1999-12-31' as datetime) tgl, 0,0,'','',sum(debet)-sum(kredit) from ( select 'AD' Urut, 'JUAL' Kode,mst.tgljual as Tanggal, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*0 as Kredit,concat(mst.transjual,'-',mst.nojual) nobukti, concat(mst.transjual,'-',mst.nojual) ref, ifnull(Nilai,0)*0 as Saldo from Tr_Jual_M Mst where 1=1 and kodeCust=&KodeCust1 and tgljual < '2000-01-01' union all select 'AXK' Urut,'BATAL JUAL' Kode,mst.tglbatal, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*0 as Debet, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, concat(mst.transjual,'-',mst.nojual) nobukti, concat(mst.transjual,'-',mst.nojual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_Jual_M Mst where 1=1 and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 and tglbatal < '2000-01-01' union all select 'BK' Urut, 'Tr_RetJual_M' Kode,mst.tglretj as Tanggal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit,concat(mst.transretj,'-',mst.noretj) nobukti, concat(mst.transjual,'-',mst.nojual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_RetJual_M Mst where 1=1 and kodeCust=&KodeCust1 and tglretj < '2000-01-01' union all select 'BXD' Urut,'BATAL Tr_RetJual_M' Kode,mst.tglbatal,ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit,concat(mst.transretj,'-',mst.noRetj) nobukti, concat(mst.transJual,'-',mst.noJual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_RetJual_M Mst where 1=1 and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 and tglbatal < '2000-01-01' union all select 'AD' Urut, 'JUAL RKT' Kode,mst.tgljual as Tanggal, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*0 as Kredit,concat(mst.transjual,'-',mst.nojual) nobukti, concat(mst.transjual,'-',mst.nojual) ref, ifnull(Nilai,0)*0 as Saldo from Tr_JualRakitan_M Mst where 1=1 and kodeCust=&KodeCust1 and tgljual < '2000-01-01' union all select 'AXK' Urut,'BATAL JUAL RKT' Kode,mst.tglbatal, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*0 as Debet, ifnull(nilai-bayartunai-bayarcard-bayarvoucher,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, concat(mst.transjual,'-',mst.nojual) nobukti, concat(mst.transjual,'-',mst.nojual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_JualRakitan_M Mst where 1=1 and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 and tglbatal < '2000-01-01' union all select 'BK' Urut, 'RETJUAL RKT' Kode,mst.tglretj as Tanggal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit,concat(mst.transretj,'-',mst.noretj) nobukti, concat(mst.transjual,'-',mst.nojual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_RetJualRakitan_M Mst where 1=1 and kodeCust=&KodeCust1 and tglretj < '2000-01-01' union all select 'BXD' Urut,'BATAL RETJUAL RKT' Kode, mst.tglbatal,ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit, concat(mst.transretj,'-',mst.noRetj) nobukti, concat(mst.transJual,'-',mst.noJual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_RetJualRakitan_M Mst where 1=1 and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 and tglbatal < '2000-01-01' union all select 'F1K' Urut, 'BAYAR JUAL GROS' Kode,mst.tglBayarJ as Tanggal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, concat(dets.transJual,'-',dets.noJual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_ScrBayarJual dets where mst.nobayarj=dets.nobayarj and kodeCust=&KodeCust1 and TglBayarj < '2000-01-01' union all select 'FX1D' Urut,'BATAL BYR J.GROS' Kode,mst.tglbatal,ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit,mst.noBayarJ nobukti, concat(dets.transJual,'-',dets.noJual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_ScrBayarJual dets where mst.nobayarJ=dets.nobayarJ and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 and tglbatal < '2000-01-01' union all select 'F1K' Urut, 'BYR JUAL RKT' Kode,mst.tglBayarJ as Tanggal, ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, concat(dets.transJual,'-',dets.noJual) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJualRakitan_M Mst, Tr_ScrBayarJualRakitan dets where mst.nobayarj=dets.nobayarj and kodeCust=&KodeCust1 and TglBayarj < '2000-01-01' union all select 'FX1D' Urut,'BATAL BYR J.RKT' Kode,mst.tglbatal,ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit,mst.noBayarJ nobukti, concat(dets.transJual,'-',dets.noJual) ref, ifnull(Nilai,0)*0 as Saldo from Tr_BayarJualRakitan_M Mst,Tr_ScrBayarJualRakitan dets where mst.nobayarJ=dets.nobayarJ and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 and tglbatal < '2000-01-01' union all select 'F2D' Urut, 'DGN BG' Kode,mst.tglBayarJ as Tanggal, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit, mst.noBayarJ nobukti,dets.noBG ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='BG' and kodeCust=&KodeCust1 and TglBayarj < '2000-01-01' union all select 'FX2K' Urut,'BATAL DGN BG' Kode,mst.tglbatal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, dets.noBG ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='BG' and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 and tglbatal < '2000-01-01' union all select 'F3D' Urut, 'DGN CN' Kode,mst.tglBayarJ as Tanggal, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit, mst.noBayarJ nobukti,dets.nobukti ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='CRNota' and kodeCust=&KodeCust1 and TglBayarj < '2000-01-01' union all select 'FX3K' Urut,'BATAL DGN CN' Kode,mst.tglbatal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, dets.nobukti ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='CRNota' and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 and tglbatal < '2000-01-01' union all select 'F4D' Urut, 'DGN DN' Kode,mst.tglBayarJ as Tanggal, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit, mst.noBayarJ nobukti,dets.nobukti ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='DBNota' and kodeCust=&KodeCust1 and TglBayarj < '2000-01-01' union all select 'FX4K' Urut,'BATAL DGN DN' Kode,mst.tglbatal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, dets.nobukti ref, ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='DBNota' and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 and tglbatal < '2000-01-01' union all select 'F5D' Urut, 'DGN RETJ' Kode,mst.tglBayarJ as Tanggal, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit, mst.noBayarJ nobukti, concat(dets.trans,'-',dets.nobukti) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='Retur' and kodeCust=&KodeCust1 and TglBayarj < '2000-01-01' union all select 'FX5K' Urut,'BATAL DGN RETJ' Kode,mst.tglbatal,ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, concat(dets.trans,'-',dets.nobukti) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='Retur' and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 and tglbatal < '2000-01-01' union all select 'F6D' Urut, 'DGN TITIP' Kode,mst.tglBayarJ as Tanggal, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Debet, ifnull(Nilai,0)*0 as Kredit, mst.noBayarJ nobukti, concat(dets.trans,'-',dets.nobukti) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='Titipan' and kodeCust=&KodeCust1 and TglBayarj < '2000-01-01' union all select 'FX6K' Urut,'BATAL DGN TITIP' Kode,mst.tglbatal, ifnull(Nilai,0)*0 as Debet, ifnull(Nilai,0)*case when ifnull(ExRate,1)=0 then 1 else ifnull(ExRate,1) end Kredit, mst.noBayarJ nobukti, concat(dets.trans,'-',dets.nobukti) ref,ifnull(Nilai,0)*0 as Saldo from Tr_BayarJual_M Mst,Tr_BayarJual_D dets where mst.nobayarJ=dets.nobayarJ and dets.kodebyr='Titipan' and ifnull(tglbatal,'')<>'' and kodeCust=&KodeCust1 and tglbatal < '2000-01-01' ) nn ) xx order by Tanggal,urut,nobukti