select 7 as SOURCETYPE, PREPAYMENTTO.ITSID as SOURCEID, PREPAYMENTTO.ITSDATE, 'PrepaymentsTo' as ACCDEBIT,
2004 as SUBACCDEBITTYPE, DEBTORCREDITOR.ITSID as SUBACCDEBITID, DEBTORCREDITOR.ITSNAME as SUBACCDEBIT, PREPAYMENTTO.ITSTOTAL as DEBIT,
PREPAYMENTTO.ACCCASH as ACCCREDIT, SUBACCCASHTYPE  as SUBACCCREDITTYPE, SUBACCCASHID  as SUBACCCREDITID, SUBACCCASH as SUBACCCREDIT, PREPAYMENTTO.ITSTOTAL as CREDIT
from PREPAYMENTTO
join DEBTORCREDITOR on DEBTORCREDITOR.ITSID = PREPAYMENTTO.VENDOR
where PREPAYMENTTO.REVERSEDID is null and HASMADEACCENTRIES = 0 :WHEREADD
