/*****************************************************************************
*
* Filename         - $Workfile:   onward_bag_v2.sql  $
*
*                     Name              Date      Version     CR Number
* Author           - See revision history below.
* Last Update      - See revision history below.
*
* Project Name     - TAGTRAK(Oracle Database)
*
* Source Code
* Identifier       - 0/3/300/8010/112
*
* Design Spec
* Section          -
*
* Contents         - Create Live Schema Views
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   onward_bag_v2.sql  $  $Revision:   1.2  $
*
* Revision History
*
* Note that user tagtrak is many users. For these users the user
* name is entered as the last line in the change description.
*
* $Log:   /pvcsarch/db_ora/db/source/live/views/onward_bag_v2.svl  $
* 
*    Rev 1.2   21 Jun 2001 15:37:38   tagtrak
* OR:
* CR:
* Re-baseline version 4.0.0 to include patches.
* 
*    Rev 1.1   20 Sep 1999 15:17:46   tagtrak
*  
*
*  This view was intended to show all onward_dests for a bag
*  but nul pax and tag for subsequent dests
*  this was temp restricted to the first dest
*/

PROMPT Creating view   onward_bag_v2   ;

CREATE OR REPLACE FORCE VIEW   onward_bag_v2   (
FLIGHT_ID , 
flight_no,
flight_date,
FLIGHT_DESTINATION,
DEST_ORDER,
uld_no ,
location_code,
uld_category,
uld_type,
ULD_HOLD_NO,
ULD_CLASS_LIST,
bag_tag,
bag_tag1,
bag_tag2a,
bag_tag2b,
bag_tag3,
bag_tag_text,
BAG_SEQUENCE_NO,
pax_id,
pax_surname,
PAX_INITIALS,
onwrd_flight_no, 
onwrd_dest,
onwrd_dest_order,
onwrd_class,
all_onward_dests
)
as
select  
--distinct
f.FLIGHT_ID , 
f.flight_no,
f.flight_date,
decode(nvl(ff.dest_order,1),1,p.PAX_DESTINATION, ' '),
1, --  destination order NOT set
u.uld_no ,
u.location_code,
u.uld_category,
u.uld_type,
u.ULD_HOLD_NO,
ud.ULD_CLASS_LIST,
b.bag_tag,
b.bag_tag1,
b.bag_tag2a,
b.bag_tag2b,
LTRIM(TO_CHAR(b.bag_tag3, '000000')),
decode(nvl(ff.dest_order,1),1,b.bag_tag, ' '),
decode(nvl(ff.dest_order,1),1,to_char(b.BAG_SEQUENCE_NO),' '),
p.pax_id,
decode(nvl(ff.dest_order,1),1,p.pax_surname,' '),
decode(nvl(ff.dest_order,1),1,p.PAX_INITIALS,' '),
ff.no||ff.odate ,
ff.dest,
ff.dest_order,
ff.class,
Onward_Reports.Get_Destinations(p.pax_id)
from  flight f, onward_flight ff, ulds  u, uld_dests ud, pax p, bag b
where 
    f.flight_id = u.flight_id 
and u.uld_no = ud.uld_no 
and u.flight_id = ud.flight_id 
and p.pax_DESTination = ud.ULD_DESTINATION
and f.flight_id = p.flight_id
and p.pax_id = b.pax_id        
and b.uld_no = u.uld_no 
and ff.pax_id = p.pax_id
and b.LOADED_STATUS = 'Y'
and b.delete_marker = 0
and ff.dest_order = 1
/

