if @CreatedBy = '2db2d235-0f60-494a-b434-e17652f94d40'
select
OIC.SequenceNo
,TA.SequenceNo PACSequenceNo
,po_nbr
,pod_line
,po_ord_date
,ISNULL(TA.ACNum,'未验收')ACNum
,PRM.PRM_CapexNumber
,PRM.CreatedBy
,ur.name PRCreator
,PRM.CreatedTime
,PRM.CreatedByParentId
,(select CG.DisplayName from OT_OrganizationUnit OU,OT_CATEGORY CG where OU.ObjectID =PRM.CreatedByParentId AND OU.CategoryID = CG.ObjectID)ApplyDeptName
,PRD.PRD_ItemCode
,PRD.PRD_ItemDesc
,PRM.PRM_UserDept
,(SELECT MAX(OF_DEPTNAME) OF_DEPTNAME FROM R_ORGANIZATIONFINDEPT where OF_DEPTCODE =PRM.PRM_UserDept)UserDeptname
,PRM.PRM_ReqDeliveryDate
,PRM.PRM_BuyerUser
,(SELECT Name FROM OT_user WHERE ObjectID = PRM.PRM_BuyerUser)BuyerUser
,PRM.PRM_OutProcessType
,(SELECT TypeDesc FROM R_OutProcessType WHERE TypeID = PRM.PRM_OutProcessType)OutProcessType
,PRM_Type
,(SELECT EnumValue FROM OT_EnumerableMetadata WHERE [Category] = '请购类型' AND CODE = PRM.PRM_Type)EnumValue
,PRM.PRM_ApplyScene
,PRM_AssetType
,ISNULL((SELECT EnumValue FROM OT_EnumerableMetadata WHERE [Category] = '资产类别' AND CODE = PRM.PRM_AssetType),'')AssetType
,PRM.PRM_ProcessProject
,PRM.PRM_ImplementaryContent
,PRD.PRD_Qty
,PRD.PRD_Unit
,PRD.PRD_Price
,PRM.PRM_Total
,PRD.PRD_VendorCode
,PRD.PRD_VendorName
from v_mfg_podata LEFT OUTER JOIN (SELECT PRAC.PAC_PONUM ,IC.SequenceNo,(case when ISNULL(COUNT(*),0) = 0 then '未验收' when ISNULL(COUNT(*),0) > 0 then '已验收' else '' end)ACNum
FROM I_PRAcceptanceCheck PRAC,OT_InstanceContext IC WHERE PRAC.ObjectID = IC.BizObjectId GROUP BY PRAC.PAC_PONUM,IC.SequenceNo) TA ON TA.PAC_PONUM = po_nbr
,I_PROrderMsr PRM,I_PROrderDtl PRD,OT_INSTANCECONTEXT OIC,ot_organizationunit D,ot_user ur
where PRM.ObjectID = PRD.ParentObjectID and PRM.Objectid=OIC.BizObjectId AND (PRM.PRM_Type = 5 OR PRM.PRM_Type = 6 OR PRM.PRM_Type = 7) AND D.ObjectID = PRM.CreatedByParentId
and pod__chr01 = OIC.SequenceNo and po_nbr = PRD.PRD_PONumber and pod_line = PRD.PRD_POLine
and ur.ObjectID = PRM.CreatedBy
and ((TA.ACNum is null and @ACNum = '未验收' and not exists (select PAC_PONUM from I_PRAcceptanceCheck PRAC1 where PRAC1.PAC_PONUM = po_nbr )) or (TA.ACNum is not null and @ACNum = '已验收' and exists(select PAC_PONUM from I_PRAcceptanceCheck PRAC1 where PRAC1.PAC_PONUM = po_nbr)))
and OIC.SequenceNo not in ('PR2016120050',
'PR2016120153',
'PR2016120076',
'PR2016120062',
'PR2016120154',
'PR2016120292',
'PR2016120324',
'PR2016120133',
'PR2016120262',
'PR2016120052',
'PR2016120340',
'PR2016120307',
'PR2016120328',
'PR2016120417',
'PR2016120332',
'PR2016120302',
'PR2017010041',
'PR2017010028',
'PR2016120369',
'PR2016120018',
'PR2017010009',
'PR2016120013',
'PR2017010145',
'PR2017010166',
'PR2017010099',
'PR2017010093',
'PR2016120378',
'PR2016120343',
'PR2017010072',
'PR2017010032',
'PR2017010071',
'PR2016120402',
'PR2016120279',
'PR2017020029',
'PR2017020017',
'PR2017020008',
'PR2017020009',
'PR2017020010',
'PR2017020012',
'PR2017020013',
'PR2017020014',
'PR2017020015',
'PR2017020016',
'PR2017010229',
'PR2017010097',
'PR2017010103',
'PR2017010039',
'PR2017010038',
'PR2017010037',
'PR2017010096',
'PR2017010232',
'PR2016120396',
'PR2016120273',
'PR2017010201',
'PR2016120287',
'PR2017010173',
'PR2017010231',
'PR2016120239',
'PR2017020183',
'PR2017020281',
'PR2017020231',
'PR2017020227',
'PR2017010155',
'PR2017010217',
'PR2017030023',
'PR2017020130',
'PR2017010081',
'PR2016120395',
'PR2017020275',
'PR2017030026',
'PR2017020243',
'PR2017020099',
'PR2017030108',
'PR2017030109',
'PR2017030013',
'PR2017010075',
'PR2017020180',
'PR2017030118',
'PR2017020196',
'PR2017020280',
'PR2017010027',
'PR2017010227',
'PR2016120258',
'PR2016120192',
'PR2016120403',
'PR2017010015',
'PR2016120257',
'PR2016120312',
'PR2017030216',
'PR2016120344',
'PR2017010182',
'PR2016120361',
'PR2017040014',
'PR2017030003',
'PR2017030068',
'PR2017040031',
'PR2017030078',
'PR2016120210',
'PR2017040063',
'PR2017030055',
'PR2017030091',
'PR2016120045',
'PR2017020218',
'PR2017030374',
'PR2017030066',
'PR2017030055',
'PR2017040058',
'PR2017020163',
'PR2017030224',
'PR2017030054',
'PR2017030053',
'PR2017040151',
'PR2017040083',
'PR2017040126',
'PR2016120238',
'PR2017030386',
'PR2017040138',
'PR2017040085',
'PR2016120039',
'PR2016120078',
'PR2017040167',
'PR2017040168',
'PR2017040250',
'PR2017040073',
'PR2017030311',
'PR2017040128',
'PR2017030130',
'PR2017040234',
'PR2017040327',
'PR2017050080',
'PR2017040334',
'PR2017030096',
'PR2017030251',
'PR2017030395',
'PR2017040180',
'PR2017020131',
'PR2017030160',
'PR2016120294',
'PR2017020041',
'PR2016120406',
'PR2016120350',
'PR2016120321',
'PR2017050151',
'PR2017050010',
'PR2017040236',
'PR2017050089',
'PR2017040133',
'PR2017050260',
'PR2017050245',
'PR2017050115',
'PR2017050085',
'PR2017050118',
'PR2017030122',
'PR2017020214',
'PR2017050152',
'PR2017040245',
'PR2017020109',
'PR2016120202',
'PR2017050196',
'PR2017050376',
'PR2016120376',
'PR2017010107',
'PR2016120379',
'PR2016120380',
'PR2017010136',
'PR2017020146',
'PR2017030129',
'PR2017030182',
'PR2017040071',
'PR2017030297',
'PR2017040007',
'PR2017050252',
'PR2017050040',
'PR2017050039',
'PR2017020143',
'PR2017010233',
'PR2017050133',
'PR2017050137',
'PR2017010210',
'PR2017050359',
'PR2017030347',
'PR2017030396',
'PR2017040006',
'PR2017050079',
'PR2017010223',
'PR2017050176',
'PR2017060012',
'PR2017050249',
'PR2017050092',
'PR2017050025',
'PR2017030315',
'PR2017060022',
'PR2017020173',
'PR2016120240',
'PR2017030322',
'PR2017050073',
'PR2017040103',
'PR2017020122',
'PR2017060054',
'PR2016120280',
'PR2017020240',
'PR2017030205',
'PR2017010080',
'PR2017030187',
'PR2017050327',
'PR2017060034',
'PR2017060056',
'PR2017060038',
'PR2017060052',
'PR2017050054',
'PR2017060125',
'PR2017050189',
'PR2017040113',
'PR2017060198',
'PR2017060201',
'PR2017060200',
'PR2017060199',
'PR2017060197',
'PR2017060196',
'PR2017060195',
'PR2017060194',
'PR2017050101',
'PR2017060096',
'PR2017050086',
'PR2017040314',
'PR2017040157',
'PR2017040224',
'PR2017040320',
'PR2017020133',
'PR2017030085',
'PR2017040005',
'PR2016120228',
'PR2017060055',
'PR2017050328',
'PR2017060106',
'PR2017020100',
'PR2017040280',
'PR2017050206',
'PR2017030234',
'PR2017030225',
'PR2017050205',
'PR2017050323',
'PR2017040279',
'PR2017020189',
'PR2017020119',
'PR2017060151',
'PR2017060163',
'PR2017040329',
'PR2017060089',
'PR2017060164',
'PR2017050091',
'PR2017050259',
'PR2016120054',
'PR2017040048',
'PR2017060306',
'PR2017060336',
'PR2017030185',
'PR2017060362'
) AND (po_nbr like '%' + isnull(@po_nbr,'') + '%') AND (OIC.SequenceNo like '%' + isnull(@SequenceNo,'') + '%') and (ur.name like '%' + isnull(@PRCreator,'') + '%')
ORDER BY po_nbr desc, po_ord_date desc
else
select
OIC.SequenceNo
,TA.SequenceNo PACSequenceNo
,po_nbr
,pod_line
,po_ord_date
,ISNULL(TA.ACNum,'未验收')ACNum
,PRM.PRM_CapexNumber
,PRM.CreatedBy
,ur.name PRCreator
,PRM.CreatedTime
,PRM.CreatedByParentId
,(select CG.DisplayName from OT_OrganizationUnit OU,OT_CATEGORY CG where OU.ObjectID =PRM.CreatedByParentId AND OU.CategoryID = CG.ObjectID)ApplyDeptName
,PRD.PRD_ItemCode
,PRD.PRD_ItemDesc
,PRM.PRM_UserDept
,(SELECT MAX(OF_DEPTNAME) OF_DEPTNAME FROM R_ORGANIZATIONFINDEPT where OF_DEPTCODE =PRM.PRM_UserDept)UserDeptname
,PRM.PRM_ReqDeliveryDate
,PRM.PRM_BuyerUser
,(SELECT Name FROM OT_user WHERE ObjectID = PRM.PRM_BuyerUser)BuyerUser
,PRM.PRM_OutProcessType
,(SELECT TypeDesc FROM R_OutProcessType WHERE TypeID = PRM.PRM_OutProcessType)OutProcessType
,PRM_Type
,(SELECT EnumValue FROM OT_EnumerableMetadata WHERE [Category] = '请购类型' AND CODE = PRM.PRM_Type)EnumValue
,PRM.PRM_ApplyScene
,PRM_AssetType
,ISNULL((SELECT EnumValue FROM OT_EnumerableMetadata WHERE [Category] = '资产类别' AND CODE = PRM.PRM_AssetType),'')AssetType
,PRM.PRM_ProcessProject
,PRM.PRM_ImplementaryContent
,PRD.PRD_Qty
,PRD.PRD_Unit
,PRD.PRD_Price
,PRM.PRM_Total
,PRD.PRD_VendorCode
,PRD.PRD_VendorName
from v_mfg_podata LEFT OUTER JOIN (SELECT PRAC.PAC_PONUM ,IC.SequenceNo,(case when ISNULL(COUNT(*),0) = 0 then '未验收' when ISNULL(COUNT(*),0) > 0 then '已验收' else '' end)ACNum
FROM I_PRAcceptanceCheck PRAC,OT_InstanceContext IC WHERE PRAC.ObjectID = IC.BizObjectId GROUP BY PRAC.PAC_PONUM,IC.SequenceNo) TA ON TA.PAC_PONUM = po_nbr
,I_PROrderMsr PRM,I_PROrderDtl PRD,OT_INSTANCECONTEXT OIC,ot_organizationunit D,ot_user ur
where PRM.ObjectID = PRD.ParentObjectID and PRM.Objectid=OIC.BizObjectId AND (PRM.PRM_Type = 5 OR PRM.PRM_Type = 6 OR PRM.PRM_Type = 7) AND D.ObjectID = PRM.CreatedByParentId
and ur.ObjectID = PRM.CreatedBy and ((TA.ACNum is null and @ACNum = '未验收' and not exists (select PAC_PONUM from I_PRAcceptanceCheck PRAC1 where PRAC1.PAC_PONUM = po_nbr )) or (TA.ACNum is not null and @ACNum = '已验收' and exists(select PAC_PONUM from I_PRAcceptanceCheck PRAC1 where PRAC1.PAC_PONUM = po_nbr)))
and pod__chr01 = OIC.SequenceNo and po_nbr = PRD.PRD_PONumber and pod_line = PRD.PRD_POLine and OIC.SequenceNo not in ('PR2016120050',
'PR2016120153',
'PR2016120076',
'PR2016120062',
'PR2016120154',
'PR2016120292',
'PR2016120324',
'PR2016120133',
'PR2016120262',
'PR2016120052',
'PR2016120340',
'PR2016120307',
'PR2016120328',
'PR2016120417',
'PR2016120332',
'PR2016120302',
'PR2017010041',
'PR2017010028',
'PR2016120369',
'PR2016120018',
'PR2017010009',
'PR2016120013',
'PR2017010145',
'PR2017010166',
'PR2017010099',
'PR2017010093',
'PR2016120378',
'PR2016120343',
'PR2017010072',
'PR2017010032',
'PR2017010071',
'PR2016120402',
'PR2016120279',
'PR2017020029',
'PR2017020017',
'PR2017020008',
'PR2017020009',
'PR2017020010',
'PR2017020012',
'PR2017020013',
'PR2017020014',
'PR2017020015',
'PR2017020016',
'PR2017010229',
'PR2017010097',
'PR2017010103',
'PR2017010039',
'PR2017010038',
'PR2017010037',
'PR2017010096',
'PR2017010232',
'PR2016120396',
'PR2016120273',
'PR2017010201',
'PR2016120287',
'PR2017010173',
'PR2017010231',
'PR2016120239',
'PR2017020183',
'PR2017020281',
'PR2017020231',
'PR2017020227',
'PR2017010155',
'PR2017010217',
'PR2017030023',
'PR2017020130',
'PR2017010081',
'PR2016120395',
'PR2017020275',
'PR2017030026',
'PR2017020243',
'PR2017020099',
'PR2017030108',
'PR2017030109',
'PR2017030013',
'PR2017010075',
'PR2017020180',
'PR2017030118',
'PR2017020196',
'PR2017020280',
'PR2017010027',
'PR2017010227',
'PR2016120258',
'PR2016120192',
'PR2016120403',
'PR2017010015',
'PR2016120257',
'PR2016120312',
'PR2017030216',
'PR2016120344',
'PR2017010182',
'PR2016120361',
'PR2017040014',
'PR2017030003',
'PR2017030068',
'PR2017040031',
'PR2017030078',
'PR2016120210',
'PR2017040063',
'PR2017030055',
'PR2017030091',
'PR2016120045',
'PR2017020218',
'PR2017030374',
'PR2017030066',
'PR2017030055',
'PR2017040058',
'PR2017020163',
'PR2017030224',
'PR2017030054',
'PR2017030053',
'PR2017040151',
'PR2017040083',
'PR2017040126',
'PR2016120238',
'PR2017030386',
'PR2017040138',
'PR2017040085',
'PR2016120039',
'PR2016120078',
'PR2017040167',
'PR2017040168',
'PR2017040250',
'PR2017040073',
'PR2017030311',
'PR2017040128',
'PR2017030130',
'PR2017040234',
'PR2017040327',
'PR2017050080',
'PR2017040334',
'PR2017030096',
'PR2017030251',
'PR2017030395',
'PR2017040180',
'PR2017020131',
'PR2017030160',
'PR2016120294',
'PR2017020041',
'PR2016120406',
'PR2016120350',
'PR2016120321',
'PR2017050151',
'PR2017050010',
'PR2017040236',
'PR2017050089',
'PR2017040133',
'PR2017050260',
'PR2017050245',
'PR2017050115',
'PR2017050085',
'PR2017050118',
'PR2017030122',
'PR2017020214',
'PR2017050152',
'PR2017040245',
'PR2017020109',
'PR2016120202',
'PR2017050196',
'PR2017050376',
'PR2016120376',
'PR2017010107',
'PR2016120379',
'PR2016120380',
'PR2017010136',
'PR2017020146',
'PR2017030129',
'PR2017030182',
'PR2017040071',
'PR2017030297',
'PR2017040007',
'PR2017050252',
'PR2017050040',
'PR2017050039',
'PR2017020143',
'PR2017010233',
'PR2017050133',
'PR2017050137',
'PR2017010210',
'PR2017050359',
'PR2017030347',
'PR2017030396',
'PR2017040006',
'PR2017050079',
'PR2017010223',
'PR2017050176',
'PR2017060012',
'PR2017050249',
'PR2017050092',
'PR2017050025',
'PR2017030315',
'PR2017060022',
'PR2017020173',
'PR2016120240',
'PR2017030322',
'PR2017050073',
'PR2017040103',
'PR2017020122',
'PR2017060054',
'PR2016120280',
'PR2017020240',
'PR2017030205',
'PR2017010080',
'PR2017030187',
'PR2017050327',
'PR2017060034',
'PR2017060056',
'PR2017060038',
'PR2017060052',
'PR2017050054',
'PR2017060125',
'PR2017050189',
'PR2017040113',
'PR2017060198',
'PR2017060201',
'PR2017060200',
'PR2017060199',
'PR2017060197',
'PR2017060196',
'PR2017060195',
'PR2017060194',
'PR2017050101',
'PR2017060096',
'PR2017050086',
'PR2017040314',
'PR2017040157',
'PR2017040224',
'PR2017040320',
'PR2017020133',
'PR2017030085',
'PR2017040005',
'PR2016120228',
'PR2017060055',
'PR2017050328',
'PR2017060106',
'PR2017020100',
'PR2017040280',
'PR2017050206',
'PR2017030234',
'PR2017030225',
'PR2017050205',
'PR2017050323',
'PR2017040279',
'PR2017020189',
'PR2017020119',
'PR2017060151',
'PR2017060163',
'PR2017040329',
'PR2017060089',
'PR2017060164',
'PR2017050091',
'PR2017050259',
'PR2016120054',
'PR2017040048',
'PR2017060306',
'PR2017060336',
'PR2017030185',
'PR2017060362'
) AND (po_nbr like '%' + isnull(@po_nbr,'') + '%') AND (OIC.SequenceNo like '%' + isnull(@SequenceNo,'') + '%') and D.CategoryID = @CreatedBy
and (ur.name like '%' + isnull(@PRCreator,'') + '%')
ORDER BY po_nbr desc, po_ord_date desc |