select WE.WIP_ENTITY_NAME 任务号,
MFG_LOOKUPS_WJS.MEANING 作业状态,
WDJ.CLASS_CODE 任务类型,
MSI1.SEGMENT1 装配编码,
Msi1.Description 装配描述,
WDJ.SCHEDULED_START_DATE 计划完成日期,
WDJ.SCHEDULED_COMPLETION_DATE 计划完成日期,
nvl(WDJ.START_QUANTITY, 0) 计划数量,
nvl(WDJ.QUANTITY_COMPLETED, 0) 完成数量,
MSI2.SEGMENT1 物料编码,
CIC.ITEM_COST 成本,
Msi2.Description 物料描述,
nvl(WRO.REQUIRED_QUANTITY, 0) 需求数量,
nvl(WRO.QUANTITY_ISSUED, 0) 发送数量,
nvl(WRO.REQUIRED_QUANTITY, 0) - nvl(WRO.QUANTITY_ISSUED, 0) 未发,
wro.supply_subinventory 供应子库,
ML.MEANING 供应类型
from WIP.WIP_DISCRETE_JOBS WDJ,
WIP.WIP_REQUIREMENT_OPERATIONS WRO,
INV.Mtl_System_Items_B MSI1,
INV.Mtl_System_Items_B MSI2,
WIP.WIP_ENTITIES we,
BOM.CST_ITEM_COSTS CIC,
applsys.fnd_LOOKUP_values ML,
applsys.fnd_LOOKUP_values
MFG_LOOKUPS_WJS
where WE.ORGANIZATION_ID = X
and WDJ.WIP_ENTITY_ID(+) = WE.WIP_ENTITY_ID
and WDJ.ORGANIZATION_ID = WE.ORGANIZATION_ID
and Msi1.INVENTORY_ITEM_ID(+) = We.PRIMARY_ITEM_ID
and Msi1.ORGANIZATION_ID = We.ORGANIZATION_ID
and WRO.WIP_ENTITY_ID(+) = WDJ.WIP_ENTITY_ID
and WRO.ORGANIZATION_ID = WDJ.ORGANIZATION_ID
and MSI2.INVENTORY_ITEM_ID(+) = WRO.INVENTORY_ITEM_ID
and MSI2.ORGANIZATION_ID = WRO.ORGANIZATION_ID
and ML.LOOKUP_TYPE = 'WIP_SUPPLY'
and ML.LOOKUP_CODE = WRO.WIP_SUPPLY_TYPE
and (MFG_LOOKUPS_WJS.LOOKUP_TYPE = 'WIP_JOB_STATUS')
and (wdj.STATUS_TYPE = MFG_LOOKUPS_WJS.LOOKUP_CODE)
and CIC.INVENTORY_ITEM_ID = MSI2.INVENTORY_ITEM_ID
and CIC.ORGANIZATION_ID = MSI2.ORGANIZATION_ID
and CIC.COST_TYPE_ID = 1
and MFG_LOOKUPS_WJS.MEANING<>'已关闭'
--and trunc(WDJ.SCHEDULED_COMPLETION_DATE) between to_date('20**/01/01','yyyy-mm-dd') and to_date('20**/01/31','yyyy-mm-dd')
and MFG_LOOKUPS_WJS.Language='ZHS'
and ML.Language='ZHS'
and nvl(WRO.REQUIRED_QUANTITY, 0) - nvl(WRO.QUANTITY_ISSUED, 0)>0
-- and WRO.REQUIRED_QUANTITY < WRO.QUANTITY_ISSUED
-- and nvl(WDJ.START_QUANTITY, 0)< nvl(WDJ.QUANTITY_COMPLETED, 0)
and MFG_LOOKUPS_WJS.MEANING = '完成'
and nvl(WDJ.START_QUANTITY, 0)=nvl(WDJ.QUANTITY_COMPLETED, 0)
and WRO.WIP_SUPPLY_TYPE <> 6