select a.iseq30,a.viseq,
      to_char(a.adat,'yyyy/mm/dd') adat,
      a.vseq,a.vlin,a.tcls,a.amt,a.txt2,
			e.chgnm chgcdnm,
      to_char(a.idat, 'yyyy/mm/dd hh24:mi:ss') idat,
      f.chgnm upchgnm,
			decode(a.tcls,'91','現金','92','手形','93','相殺','94','消費税','95','小切手','96','振込') tclsnm,
			case when a.udat=a.idat then null else to_char(a.udat, 'yyyy/mm/dd hh24:mi:ss') end udat,
	  a.vlin orgvlin,
	  a.tcls orgtcls,
	  a.txt2 orgtxt2,
	  a.amt  orgamt
from axm99 h,afm08 f,afm08 e,aur32 a
where a.ktktcd=:ktktcd
	and a.cucd=:cucd
	and nvl(a.cuscd,'null')=nvl(:cuscd,'null')
	and a.vseq=:vseq
	and a.dcls='2'
	and a.nbil=0
	and a.sts=0
	and a.viseq=:viseq
	and a.ktktcd=h.ktktcd
	and ((:sts='3') or (:sts<>'3' and a.sbat2>=h.sbat2))	/* 2008.02.05 se-322 請求訂正の考慮を追加 */
	and (a.sbat>=:sbat or a.sbat=-999)
	and a.chgcd=e.chgcd(+)
	and a.upchg=f.chgcd(+)
order by a.vlin
