SELECT TRUNC(DATE_CREATED) DATE_CREATED,
       CONTRACT Site,
       USERID as "User Id",
       NVL(COUNT(DISTINCT Handling_Unit_API.Get_Top_Parent_Handl_Unit_Id(HANDLING_UNIT_ID)),0)   + NVL(((SELECT COUNT(DISTINCT HANDLING_UNIT_ID )
                  FROM INVENTORY_TRANSACTION_HIST2 i
                 WHERE TRANSACTION_CODE = 'PICK-IN'
                   AND HANDLING_UNIT_ID > 0
                   AND (TRUNC(DATE_CREATED)=A.DATE_CREATED)
                   AND CONTRACT = A.CONTRACT
           AND USERID   = A.USERID
                   AND Handling_Unit_API.Get_Top_Parent_Handl_Unit_Id(HANDLING_UNIT_ID) IS NULL
                   group by TRUNC(DATE_CREATED), contract ,USERID)),0)                 as "No of Skids Picked",
                   
      -- COUNT(DISTINCT LOCATION_NO) as "Count of Shipments",
           NVL ( (SELECT COUNT( DISTINCT he.shipment_id) from HANDLING_UNIT_SHIPMENT he where he.handling_unit_id IN   
      ((SELECT HANDLING_UNIT_ID 
                  FROM INVENTORY_TRANSACTION_HIST2 i
                 WHERE TRANSACTION_CODE = 'PICK-IN'
                   AND HANDLING_UNIT_ID > 0
                   AND (TRUNC(DATE_CREATED)=A.DATE_CREATED)
                   AND CONTRACT = A.CONTRACT
                   AND USERID   = A.USERID
                   ))),0)    +   NVL (  (SELECT COUNT( DISTINCT he.shipment_id) from HANDLING_UNIT_HISTORY_SHPMNT he where he.handling_unit_id IN   
      ((SELECT HANDLING_UNIT_ID 
                  FROM INVENTORY_TRANSACTION_HIST2 i
                 WHERE TRANSACTION_CODE = 'PICK-IN'
                   AND HANDLING_UNIT_ID > 0
                   AND (TRUNC(DATE_CREATED)=A.DATE_CREATED)
                   AND CONTRACT = A.CONTRACT
                   AND USERID   = A.USERID
                   ))) ,0) as "Count of Shipments",
  



       COUNT(DISTINCT SOURCE_REF1) as "Count of Orders" 
          FROM INVENTORY_TRANSACTION_HIST2 A
         WHERE TRANSACTION_CODE = 'PICK-IN'
           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 NVL( '&Company', '%')  
  GROUP BY DATE_CREATED, CONTRACT, USERID
 ORDER BY DATE_CREATED, USERID