SELECT DATE_CREATED,
       Site,
       Parts as Count_of_Parts,
       Quantity as Quantity_Shipped,
       (NVL((SELECT COUNT(DISTINCT HANDLING_UNIT_ID)
              FROM INVENTORY_TRANSACTION_HIST2 i
             WHERE TRANSACTION_CODE = 'OESHIP'
               AND HANDLING_UNIT_ID > 0
               AND (TRUNC(DATE_CREATED) = A.DATE_CREATED)
               AND CONTRACT = A.site
               AND Handling_Unit_API.Get_Top_Parent_Handl_Unit_Id(HANDLING_UNIT_ID) IS NULL
             group by TRUNC(DATE_CREATED), contract),
            0) + (NVL(Parent_Skids, 0))) Skids,
       
       ifsapp.Ipl_Label_Util_API.Get_Value_Ship_Per_Day(DATE_CREATED, site) as Value,
       Count_of_Orders as No_of_Customer_Orders_Shipped
  FROM (select TRUNC(DATE_CREATED) DATE_CREATED,
               contract as Site,
               COUNT(DISTINCT PART_NO) as Parts,
               COUNT(DISTINCT
                     Handling_Unit_API.Get_Top_Parent_Handl_Unit_Id(HANDLING_UNIT_ID)) as Parent_Skids,
               COUNT(DISTINCT SOURCE_REF1) as Count_of_Orders,
               SUM(QUANTITY) as Quantity
          FROM INVENTORY_TRANSACTION_HIST2 i
         WHERE TRANSACTION_CODE = 'OESHIP'
           AND HANDLING_UNIT_ID > 0
           AND (TRUNC(DATE_CREATED) >= TO_DATE('&Valid_From', 'MM/DD/YYYY') AND
               TRUNC(DATE_CREATED) <= TO_DATE('&Valid_To', 'MM/DD/YYYY'))
           AND CONTRACT LIKE '%&CONTRACT%'
         group by TRUNC(DATE_CREATED), contract
         ORDER BY DATE_CREATED, CONTRACT) A