SELECT contract,
       EXTRACT(YEAR FROM DATE_CREATED) Year,
       EXTRACT(MONTH FROM DATE_CREATED) Period,
       IFSAPP.CUSTOMER_ORDER_API.Get_Customer_No(SOURCE_REF1) "Customer",
       IFSAPP.Cust_Ord_Customer_API.Get_Name(CUSTOMER_ORDER_API.Get_Customer_No(SOURCE_REF1)) "Customer Name",
       PART_NO,
       IFSAPP.Inventory_Part_API.Get_Description(CONTRACT, PART_NO) "Part Description",
       IFSAPP.INVENTORY_PART_API.Get_Part_Product_Family(CONTRACT, PART_NO) "Product Family",
       SUM(QUANTITY) as Quantity,
       COUNT(HANDLING_UNIT_ID) as Pallets
  FROM INVENTORY_TRANSACTION_HIST2
 WHERE
 TRANSACTION_CODE = 'OESHIP'
  AND   TRUNC(DATE_CREATED)   between  TO_DATE('&DATE_FROM','YYYY-MM-DD')    AND   TO_DATE ('&DATE_TO','YYYY-MM-DD')
   AND CONTRACT LIKE  NVL ('&Site' , '%' )
    AND PART_NO LIKE   nvl ( '&PartNo',  '%')
AND (IFSAPP.CUSTOMER_ORDER_API.Get_Customer_No(SOURCE_REF1) is null or IFSAPP.CUSTOMER_ORDER_API.Get_Customer_No(SOURCE_REF1) LIKE NVL ( '&CustomerNo' , '%') )
 AND (IFSAPP.INVENTORY_PART_API.Get_Part_Product_Family(CONTRACT, PART_NO) is null or IFSAPP.INVENTORY_PART_API.Get_Part_Product_Family(CONTRACT, PART_NO) LIKE  NVL ( '&PartProductFamily' , '%'))

 GROUP BY PART_NO,
          contract,
          EXTRACT(YEAR FROM DATE_CREATED),
          EXTRACT(MONTH FROM DATE_CREATED),
          IFSAPP.CUSTOMER_ORDER_API.Get_Customer_No(SOURCE_REF1),
          IFSAPP.Cust_Ord_Customer_API.Get_Name(CUSTOMER_ORDER_API.Get_Customer_No(SOURCE_REF1)),
          IFSAPP.Inventory_Part_API.Get_Description(CONTRACT, PART_NO),
          IFSAPP.INVENTORY_PART_API.Get_Part_Product_Family(CONTRACT,
                                                            PART_NO)
 ORDER BY EXTRACT(YEAR FROM DATE_CREATED),
          EXTRACT(MONTH FROM DATE_CREATED),
          PART_NO,
          CONTRACT