SELECT a.business_unit , sec.oprid , a.voucher_id , MAX(d.pymnt_cnt) FROM PS_VOUCHER a , ps_vendor b , ps_sec_bu_opr sec , ps_pymnt_vchr_xref d , ps_pymt_trms_hdr t WHERE sec.business_unit = a.business_unit AND a.vendor_setid = b.setid AND a.vendor_id = b.vendor_id AND a.business_unit = d.business_unit AND a.voucher_id = d.voucher_id AND t.setid = ( SELECT SETID FROM PS_SET_CNTRL_REC WHERE REC_GROUP_ID = 'FS_14' AND RECNAME = 'PYMT_TRMS_HDR' AND SETCNTRLVALUE = a.business_unit) AND a.pymnt_terms_cd = t.pymnt_terms_cd AND ((a.process_man_close = 'N' OR a.close_status <> 'C') OR (a.process_man_close <> 'N' AND d.pymnt_selct_status = 'E')) AND a.entry_status <> 'X' AND d.pymnt_type <> 'W' AND d.pymnt_selct_status <> 'X' AND ((a.VOUCHER_STYLE='PPAY' AND d.PREPAID_STATUS='P' ) OR a.VOUCHER_STYLE<>'PPAY') AND d.due_dt IS NOT NULL GROUP BY a.business_unit , sec.oprid , a.voucher_id
|