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