select 5 as SOURCETYPE, MANUFACTURE.ITSID as SOURCEID, MANUFACTURE.ITSDATE,
'Inventory' as ACCDEBIT, 2001 as SUBACCDEBITTYPE, INVITEMCATEGORYM.ITSID as SUBACCDEBITID, INVITEMCATEGORYM.ITSNAME as SUBACCDEBIT, sum(MANUFACTURE.ITSTOTAL) as DEBIT,
'Inventory' as ACCCREDIT, 2001 as SUBACCCREDITTYPE, INVITEMCATEGORYMP.ITSID as SUBACCCREDITID, INVITEMCATEGORYMP.ITSNAME as SUBACCCREDIT, sum(MANUFACTURE.ITSTOTAL) as CREDIT
from MANUFACTURE
join INVITEM as INVITEMM on INVITEMM.ITSID = MANUFACTURE.INVITEM
join INVITEMCATEGORY as INVITEMCATEGORYM on INVITEMCATEGORYM.ITSID = INVITEMM.ITSCATEGORY
join MANUFACTURINGPROCESS on MANUFACTURINGPROCESS.ITSID = MANUFACTURE.MANUFACTURINGPROCESS 
join INVITEM as INVITEMMP on INVITEMMP.ITSID = MANUFACTURINGPROCESS.INVITEM
join INVITEMCATEGORY as INVITEMCATEGORYMP on INVITEMCATEGORYMP.ITSID = INVITEMMP.ITSCATEGORY
where MANUFACTURE.REVERSEDID is null  and MANUFACTURE.HASMADEACCENTRIES = 0 :WHEREADD
group by SOURCETYPE, SOURCEID, MANUFACTURE.ITSDATE, ACCDEBIT, SUBACCDEBITTYPE, SUBACCDEBITID, SUBACCDEBIT, ACCCREDIT, SUBACCCREDITTYPE, SUBACCCREDITID, SUBACCCREDIT
