SELECT MAIN_Q.INVENTORY_ITEM_ID,
MAIN_Q.ORGANIZATION_ID,
MAIN_Q.ITEM_CODE,
MAIN_Q.ITEM_DESC,
MAIN_Q.UOM,
MAIN_Q.PACK_SIZE,
MAIN_Q.BATCH_SIZE,
MAIN_Q.CURRENT_FORECAST_QUANTITY,
MAIN_Q.PLAN_QTY,
MAIN_Q.ACTUAL_QTY,
ROUND(((MAIN_Q.ACTUAL_QTY/MAIN_Q.CURRENT_FORECAST_QUANTITY)*100),2) PERCENT_AGAINST_FORECAST,
ROUND(((MAIN_Q.ACTUAL_QTY/MAIN_Q.PLAN_QTY)*100),2) PERCENT_AGAINST_PLANNED,
TO_CHAR(TO_DATE('01'||'-'||:P_PERIOD),'DD-MON-YYYY') FROM_DATE,
TO_CHAR(LAST_DAY (TO_DATE('01'||'-'||:P_PERIOD)),'DD-MON-YYYY') TODATE,
--TO_CHAR(GET_TAX_YEAR_END_FUNC (TO_DATE('01'||'-'||:P_PERIOD)),'DD-MON-YYYY') TODATE,
MAIN_Q.ORGANIZATION_CODE,
MAIN_Q.ORGANIZATION_NAME
FROM (
SELECT --MFD.FORECAST_DESIGNATOR,
MSI1.INVENTORY_ITEM_ID ,
MSI1.ORGANIZATION_ID,
MSI1.SEGMENT1 ITEM_CODE,
MSI1.DESCRIPTION ITEM_DESC,
MSI1.PRIMARY_UNIT_OF_MEASURE UOM,
MSI1.ATTRIBUTE11 PACK_SIZE,
--MSI1.FIXED_ORDER_QUANTITY BATCH_SIZE,
(SELECT SUM(PLAN_QTY)
FROM GME_BATCH_HEADER GBH,
GME_MATERIAL_DETAILS GMD,
MTL_SYSTEM_ITEMS_B MSI
WHERE 1=1
AND GBH.BATCH_ID = GMD.BATCH_ID
AND GBH.ORGANIZATION_ID = GMD.ORGANIZATION_ID
AND GBH.BATCH_STATUS <> -1 --Means -1 = Cancelled
AND GMD.LINE_TYPE = 1 -- PRODUCT
AND MSI.INVENTORY_ITEM_ID = GMD.INVENTORY_ITEM_ID
AND MSI.ORGANIZATION_ID = GBH.ORGANIZATION_ID
---- PARAMETERS -----------------
-- AND GBH.BATCH_NO = NVL(:P_BATCH_NO,GBH.BATCH_NO)
AND GBH.ORGANIZATION_ID = MSI1.ORGANIZATION_ID
-- AND MSI.SEGMENT1 = :P_ITEM_CODE
AND MSI.INVENTORY_ITEM_ID = MSI1.INVENTORY_ITEM_ID
AND TRUNC (GBH.ACTUAL_START_DATE) BETWEEN TO_DATE('01'||'-'||:P_PERIOD) and LAST_DAY(TO_DATE('01'||'-'||:P_PERIOD))--GET_TAX_YEAR_END_FUNC (TO_DATE('01'||'-'||:P_PERIOD))
)BATCH_SIZE,
SUM(CURRENT_FORECAST_QUANTITY) CURRENT_FORECAST_QUANTITY,
(SELECT SUM(PLAN_QTY)
/* GMD.INVENTORY_ITEM_ID,
GMD.ORGANIZATION_ID,
GBH.BATCH_ID,
GBH.BATCH_STATUS,
--MSI.INVENTORY_ITEM_ID,
--MSI.ORGANIZATION_ID,
GBH.BATCH_NO,
MSI.ATTRIBUTE15 PRODUCT_CODE,
MSI.SEGMENT1 ITEM_CODE,
MSI.DESCRIPTION ITEM_DESCRIPTION,
MSI.ATTRIBUTE11 PACK_SIZE,
MSI.FIXED_ORDER_QUANTITY BATCH_SIZE,
GBH.ACTUAL_START_DATE,
GMD.PLAN_QTY,
GMD.ACTUAL_QTY */
FROM GME_BATCH_HEADER GBH,
GME_MATERIAL_DETAILS GMD,
MTL_SYSTEM_ITEMS_B MSI
WHERE 1=1
AND GBH.BATCH_ID = GMD.BATCH_ID
AND GBH.ORGANIZATION_ID = GMD.ORGANIZATION_ID
AND GBH.BATCH_STATUS <> -1 --Means -1 = Cancelled
AND GMD.LINE_TYPE = 1 -- PRODUCT
AND MSI.INVENTORY_ITEM_ID = GMD.INVENTORY_ITEM_ID
AND MSI.ORGANIZATION_ID = GBH.ORGANIZATION_ID
---- PARAMETERS -----------------
-- AND GBH.BATCH_NO = NVL(:P_BATCH_NO,GBH.BATCH_NO)
AND GBH.ORGANIZATION_ID = MSI1.ORGANIZATION_ID
-- AND MSI.SEGMENT1 = :P_ITEM_CODE
AND MSI.INVENTORY_ITEM_ID = MSI1.INVENTORY_ITEM_ID
AND TRUNC (GBH.ACTUAL_START_DATE) BETWEEN TO_DATE('01'||'-'||:P_PERIOD) and LAST_DAY(TO_DATE('01'||'-'||:P_PERIOD))--GET_TAX_YEAR_END_FUNC (TO_DATE('01'||'-'||:P_PERIOD))
)PLAN_QTY,
(SELECT SUM(ACTUAL_QTY)
/* GMD.INVENTORY_ITEM_ID,
GMD.ORGANIZATION_ID,
GBH.BATCH_ID,
GBH.BATCH_STATUS,
--MSI.INVENTORY_ITEM_ID,
--MSI.ORGANIZATION_ID,
GBH.BATCH_NO,
MSI.ATTRIBUTE15 PRODUCT_CODE,
MSI.SEGMENT1 ITEM_CODE,
MSI.DESCRIPTION ITEM_DESCRIPTION,
MSI.ATTRIBUTE11 PACK_SIZE,
MSI.FIXED_ORDER_QUANTITY BATCH_SIZE,
GBH.ACTUAL_START_DATE,
GMD.PLAN_QTY,
GMD.ACTUAL_QTY */
FROM GME_BATCH_HEADER GBH,
GME_MATERIAL_DETAILS GMD,
MTL_SYSTEM_ITEMS_B MSI
WHERE 1=1
AND GBH.BATCH_ID = GMD.BATCH_ID
AND GBH.ORGANIZATION_ID = GMD.ORGANIZATION_ID
AND GBH.BATCH_STATUS <> -1 --Means -1 = Cancelled
AND GMD.LINE_TYPE = 1 -- PRODUCT
AND MSI.INVENTORY_ITEM_ID = GMD.INVENTORY_ITEM_ID
AND MSI.ORGANIZATION_ID = GBH.ORGANIZATION_ID
---- PARAMETERS -----------------
-- AND GBH.BATCH_NO = NVL(:P_BATCH_NO,GBH.BATCH_NO)
AND GBH.ORGANIZATION_ID = MSI1.ORGANIZATION_ID
-- AND MSI.SEGMENT1 = :P_ITEM_CODE
AND MSI.INVENTORY_ITEM_ID = MSI1.INVENTORY_ITEM_ID
AND TRUNC (GBH.ACTUAL_START_DATE) BETWEEN TO_DATE('01'||'-'||:P_PERIOD) and LAST_DAY(TO_DATE('01'||'-'||:P_PERIOD))--GET_TAX_YEAR_END_FUNC (TO_DATE('01'||'-'||:P_PERIOD))
)ACTUAL_QTY,
OOD.ORGANIZATION_CODE,
OOD.ORGANIZATION_NAME
FROM MRP_FORECAST_DESIGNATORS MFD,
MRP_FORECAST_ITEMS MFI,
MTL_SYSTEM_ITEMS_B MSI1,
MRP_FORECAST_DATES MFDT,
ORG_ORGANIZATION_DEFINITIONS OOD
WHERE 1=1
AND MFD.ATTRIBUTE_CATEGORY = 'Forecast Type'
AND MFD.ATTRIBUTE1 = 'ROFO'
AND MFD.FORECAST_DESIGNATOR = MFI.FORECAST_DESIGNATOR
AND MFD.ORGANIZATION_ID = MFI.ORGANIZATION_ID
AND MFI.INVENTORY_ITEM_ID = MSI1.INVENTORY_ITEM_ID
AND MFI.ORGANIZATION_ID = MSI1.ORGANIZATION_ID
AND MFI.FORECAST_DESIGNATOR = MFDT.FORECAST_DESIGNATOR
AND MFI.INVENTORY_ITEM_ID = MFDT.INVENTORY_ITEM_ID
AND MFI.ORGANIZATION_ID = MFDT.ORGANIZATION_ID
AND MSI1.ORGANIZATION_ID = :P_ORGANIZATION_ID
AND MSI1.ORGANIZATION_ID = OOD.ORGANIZATION_ID
AND MFDT.FORECAST_DATE BETWEEN TO_DATE('01'||'-'||:P_PERIOD) and LAST_DAY(TO_DATE('01'||'-'||:P_PERIOD)) --GET_TAX_YEAR_END_FUNC (TO_DATE('01'||'-'||:P_PERIOD))--('01-SEP-2019') AND ('30-JUN-2020')
AND MFD.FORECAST_DESIGNATOR = :P_ROFO_FORECAST_NAME --'FCROFOOSD1'
GROUP BY
MSI1.INVENTORY_ITEM_ID ,
MSI1.ORGANIZATION_ID,
MSI1.SEGMENT1,
MSI1.DESCRIPTION,
MSI1.PRIMARY_UNIT_OF_MEASURE,
MSI1.ATTRIBUTE11,
MSI1.FIXED_ORDER_QUANTITY,
OOD.ORGANIZATION_CODE,
OOD.ORGANIZATION_NAME
) MAIN_Q
No comments:
Post a Comment