ts_addrs

Upload: nikhilk62

Post on 15-Jul-2015

19 views

Category:

Documents


0 download

TRANSCRIPT

function CF_trip_stop_address1Formula return Char is cursor trip_stop_from_dlvy(p_delivery_id NUMBER) is select loc.address1, loc.address2, loc.address3, loc.address4, loc.city DECODE(loc.city, NULL, '', ', ') NVL(loc.state,loc. province) DECODE(loc.postal_code, NULL, '', ' ' loc.postal_code) DECODE(NVL(loc.state,NVL(loc.province, loc.postal_code)), NULL, '', ', ') loc.country from wsh_trip_stops wts, wsh_delivery_legs wdl, wsh_locations loc where wdl.delivery_id = p_delivery_id and wdl.pick_up_stop_id=wts.stop_id and wts.stop_location_id = loc.wsh_location_id; cursor trip_stop_from_ps(x_ps_number NUMBER) is select loc.address1, loc.address2, loc.address3, loc.address4, loc.city DECODE(loc.city, NULL, '', ', ') NVL(loc.state,loc. province) DECODE(loc.postal_code, NULL, '', ' ' loc.postal_code) DECODE(NVL(loc.state,NVL(loc.province, loc.postal_code)), NULL, '', ', ') loc.country FROM WSH_TRIP_STOPS WTS, WSH_DELIVERY_LEGS WDL, WSH_DELIVERY_ASSIGNMENTS_V WDA, -- Changed to view for MDC impact WSH_DELIVERY_DETAILS WDD, mtl_material_transactions_temp mmtt, WSH_LOCATIONS LOC WHERE mmtt.PICK_SLIP_NUMBER = x_ps_number AND mmtt.MOVE_ORDER_LINE_ID = WDD.MOVE_ORDER_LINE_ID AND mmtt.pick_slip_number IS NOT NULL AND abs(nvl(mmtt.transaction_quantity,0)) > 0 AND WDD.DELIVERY_DETAIL_ID = WDA.DELIVERY_DETAIL_ID AND WDA.DELIVERY_ID = WDL.DELIVERY_ID AND WDL.PICK_UP_STOP_ID = WTS.STOP_ID AND WTS.STOP_LOCATION_ID = LOC.WSH_LOCATION_ID AND nvl(WDD.line_direction, 'O') IN ('O', 'IO') AND WDD.container_flag IN ('N', 'Y') -- Added for MDC impact UNION ALL select loc.address1, loc.address2, loc.address3, loc.address4, loc.city DECODE(loc.city, NULL, '', ', ')

NVL(loc.state,loc. province) DECODE(loc.postal_code, NULL, '', ' ' loc.postal_code) DECODE(NVL(loc.state,NVL(loc.province, loc.postal_code)), NULL, '', ', ') loc.country FROM WSH_TRIP_STOPS WTS, WSH_DELIVERY_LEGS WDL, WSH_DELIVERY_ASSIGNMENTS_V WDA, -- Changed to view for MDC impact WSH_DELIVERY_DETAILS WDD, mtl_material_transactions mmt, WSH_LOCATIONS LOC WHERE mmt.PICK_SLIP_NUMBER = x_ps_number AND mmt.MOVE_ORDER_LINE_ID = WDD.MOVE_ORDER_LINE_ID AND mmt.pick_slip_number IS NOT NULL AND nvl(mmt.transaction_quantity,0) < 0 AND WDD.DELIVERY_DETAIL_ID = WDA.DELIVERY_DETAIL_ID AND WDA.DELIVERY_ID = WDL.DELIVERY_ID AND WDL.PICK_UP_STOP_ID = WTS.STOP_ID AND WTS.STOP_LOCATION_ID = LOC.WSH_LOCATION_ID AND nvl(WDD.line_direction, 'O') IN ('O', 'IO') AND WDD.container_flag IN ('N', 'Y') -- Added for MDC impact UNION ALL select loc.address1, loc.address2, loc.address3, loc.address4, loc.city DECODE(loc.city, NULL, '', ', ') NVL(loc.state,loc. province) DECODE(loc.postal_code, NULL, '', ' ' loc.postal_code) DECODE(NVL(loc.state,NVL(loc.province, loc.postal_code)), NULL, '', ', ') loc.country FROM WSH_TRIP_STOPS WTS, WSH_DELIVERY_LEGS WDL, WSH_DELIVERY_ASSIGNMENTS_V WDA, -- Changed to view for MDC impact WSH_DELIVERY_DETAILS WDD, mtl_txn_request_lines mtrl , WSH_LOCATIONS LOC WHERE mtrl.PICK_SLIP_NUMBER = x_ps_number AND mtrl.LINE_ID = WDD.MOVE_ORDER_LINE_ID AND mtrl.pick_slip_number IS NOT NULL AND WDD.DELIVERY_DETAIL_ID = WDA.DELIVERY_DETAIL_ID AND WDA.DELIVERY_ID = WDL.DELIVERY_ID AND WDL.PICK_UP_STOP_ID = WTS.STOP_ID AND WTS.STOP_LOCATION_ID = LOC.WSH_LOCATION_ID AND nvl(WDD.line_direction, 'O') IN ('O', 'IO') AND WDD.container_flag IN ('N', 'Y'); -- Added for MDC impact

addr1 addr2 addr3 addr4 addr5

VARCHAR2(240) VARCHAR2(240) VARCHAR2(240) VARCHAR2(240) VARCHAR2(300)

:= := := := :=

' ' ' ' '

'; '; '; '; ';

begin SRW.reference(:ts_addr1); SRW.reference(:ts_addr2); SRW.reference(:ts_addr3); SRW.reference(:ts_addr4); SRW.reference(:ts_addr5); IF :trip_stop_flag = 'Y' THEN IF :delivery_flag = 'Y' THEN OPEN trip_stop_from_dlvy(:cf_delivery_id); FETCH trip_stop_from_dlvy into addr1,addr2,addr3,addr4,addr5; CLOSE trip_stop_from_dlvy ; ELSE OPEN trip_stop_from_ps(:pick_slip_number); FETCH trip_stop_from_ps into addr1,addr2,addr3,addr4,addr5; CLOSE trip_stop_from_ps ; END IF; -----------Trip Stop Address1 :ts_addr1 := addr1; -----------Trip Stop Address2 if (addr2 is not null) then :ts_addr2 := addr2; elsif (addr2 is null and addr3 is not null) then :ts_addr2 := addr3; elsif (addr2 is null and addr3 is null and addr4 is not null) then :ts_addr2 := addr4; elsif (addr2 is null and addr3 is null and addr4 is null) then :ts_addr2 := addr5; else :ts_addr2 := ' '; end if; -----------Trip Stop Address3 if (addr2 is not null and addr3 is not null) then :ts_addr3 := addr3; elsif (addr2 is not null and addr3 is null and addr4 is not null) then :ts_addr3 := addr4; elsif (addr2 is not null and addr3 is null and addr4 is null) then :ts_addr3 := addr5; elsif (addr2 is null and addr3 is not null and addr4 is not null) then :ts_addr3 := addr4; elsif (addr2 is null and addr3 is not null and addr4 is null) then :ts_addr3 := addr5; elsif (addr2 is null and addr3 is null and addr4 is not null) then :ts_addr3 := addr5; elsif (addr2 is null and addr3 is null and addr4 is null) then :ts_addr3 := ' '; end if; -----------Trip Stop Address4 if (addr2 is not null and addr3 is not null and addr4 is not null) then :ts_addr4 := addr4; elsif (addr2 is not null and addr3 is null and addr4 is null) then :ts_addr4 := ' '; elsif (addr2 is not null and addr3 is null and addr4 is not null) then :ts_addr4 := addr5; elsif (addr2 is null and addr3 is not null and addr4 is not null) then :ts_addr4 := addr5;

elsif (addr2 is not null and addr3 is not null and addr4 is null) then :ts_addr4 := addr5; elsif (addr2 is null and addr3 is not null and addr4 is null) then :ts_addr4 := ' '; elsif (addr2 is null and addr3 is null and addr4 is not null) then :ts_addr4 := ' '; elsif (addr2 is null and addr3 is null and addr4 is null) then :ts_addr4 := ' '; end if; -----------Trip Stop Address5 if ((addr2 is null) or (addr3 is null) or (addr4 is null)) then :ts_addr5 := ' '; else :ts_addr5 := addr5; end if; END IF; return ' '; exception WHEN OTHERS THEN return ' '; end;