select 4 as SOURCETYPE, MANUFACTURINGPROCESS.ITSID as SOURCEID, MANUFACTURINGPROCESS.ITSDATE,
'Inventory' as ACCDEBIT, 2001 as SUBACCDEBITTYPE, INVITEMCATEGORYPR.ITSID as SUBACCDEBITID, INVITEMCATEGORYPR.ITSNAME as SUBACCDEBIT, sum(ADDITIONCOSTLINE.ITSTOTAL) as DEBIT,
ACCEXPENSE  as ACCCREDIT, SUBACCEXPENSETYPE  as SUBACCCREDITTYPE, SUBACCEXPENSEID  as SUBACCCREDITID, SUBACCEXPENSE  as SUBACCCREDIT, sum(ADDITIONCOSTLINE.ITSTOTAL) as CREDIT
from ADDITIONCOSTLINE
join MANUFACTURINGPROCESS on MANUFACTURINGPROCESS.ITSID = ADDITIONCOSTLINE.ITSOWNER
join INVITEM as INVITEMPR on INVITEMPR.ITSID = MANUFACTURINGPROCESS.INVITEM
join INVITEMCATEGORY as INVITEMCATEGORYPR on INVITEMCATEGORYPR.ITSID = INVITEMPR.ITSCATEGORY
where MANUFACTURINGPROCESS.REVERSEDID is null and HASMADEACCENTRIES = 0 :WHEREADD
group by SOURCETYPE, SOURCEID, MANUFACTURINGPROCESS.ITSDATE, ACCDEBIT, SUBACCDEBITTYPE, SUBACCDEBITID, SUBACCDEBIT, ACCCREDIT, SUBACCCREDITTYPE, SUBACCCREDITID, SUBACCCREDIT
