SELECT 'Unprocessed Shipping Transactions' trntype, org.organization_id,
org.organization_code, org.organization_name, COUNT (*) totaltrn,
tt.transaction_date, tt.expected_arrival_date, error_explanation,
ERROR_CODE, gp.period_code
FROM wsh_delivery_details wdd,
wsh_delivery_assignments wda,
wsh_new_deliveries wnd,
wsh_delivery_legs wdl,
wsh_trip_stops wts,
mtl_transactions_interface tt,
org_organization_definitions org,
gmf_period_statuses gp
WHERE wdd.source_code = 'OE'
AND wdd.released_status = 'C'
AND wdd.inv_interfaced_flag IN ('N', 'P')
AND wdd.organization_id = org.organization_id
AND wda.delivery_detail_id = wdd.delivery_detail_id
--- AND wnd.delivery_id = wda.delivery_id
--- AND wdd.organization_id = tt.organization_id(+)
AND wnd.status_code IN ('CL', 'IT')
AND wdl.delivery_id = wnd.delivery_id
AND wts.pending_interface_flag IN ('Y', 'P')
AND gp.period_code = gp.period_code
AND TRUNC (wts.actual_departure_date) >= TRUNC (gp.start_date)
AND TRUNC (wts.actual_departure_date) <= TRUNC (gp.end_date)
--AND TRUNC(WTS.ACTUAL_DEPARTURE_DATE) BETWEEN :P_FROM_DATE and :P_TO_DATE
---AND TRUNC(WTS.ACTUAL_DEPARTURE_DATE) BETWEEN TO_DATE('01-MAY-2018 00:00:00','DD-MON-YYYY HH24:MI:SS' ) AND
---TO_DATE('31-MAY-2018 23:59:59','DD-MON-YYYY HH24:MI:SS')
----AND wdl.pick_up_stop_id = wts.stop_id
GROUP BY org.organization_id,
org.organization_code,
org.organization_name,
error_explanation,
ERROR_CODE,
tt.transaction_date,
tt.expected_arrival_date,
gp.period_code
ORDER BY org.organization_name;