/*****************************************************************************
*
* Filename         - $Workfile:   lba_info_triggers.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         -  Live Schema: triggers for lba_info table
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1999
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   lba_info_triggers.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/triggers/lba_info_triggers.svl  $
* 
*    Rev 1.2   21 Jun 2001 15:04:26   tagtrak
* OR:
* CR:
* Re-baseline version 4.0.0 to include patches.
* 
*    Rev 1.1   31 Jan 2000 15:06:36   tagtrak
* OR:
* CR: 14402
* REV: 
* San Francisco Core Product Merge
* Neil Hilier
* 
*    Rev 1.0   07 May 1999 15:05:32   tagtrak
* OR:
* CR: 13934
* REV:
* Oracle 8.
* FASL gate width change to Oracle char(5).
* LBA interface (excluding archive and backup).
* Clean build fixes from DB v1.0.0 (arch schema onward_flight &flight_dests).
* Change of expected FASL flight_no format.
* 
* Peter Dawson, 7th May 1999
* 
* 
*
****************************************************************************/


create or replace trigger ti_lba_info
before insert on lba_info
for each row
declare
	incoming lba_info%rowtype ;
begin

	:new.error_id := 0 ;   /* Initialise */

	/* 
	* use sequence lbainfo_id to define the primary key (transaction_id)
	*/
	if (:new.transaction_id is null or :new.transaction_id = 0 ) then  /* { */
		select
			lbainfoid_gen.nextval
		into
			:new.transaction_id
		from
			dual;
	end if;      /* } */

	/*
	* set the insert_date
	*/
	:new.insert_date := sysdate;

	if ( :new.error_id = 0 ) then    /* { */
		incoming.transaction_id := :new.transaction_id;
		incoming.flight_no      := :new.flight_no;
		incoming.std_date       := :new.std_date;
		incoming.transaction    := :new.transaction;
		incoming.seq_no         := nvl(:new.seq_no, -1) ;
		incoming.seat           := nvl(:new.seat, '-') ;
		incoming.pax_name       := :new.pax_name;
		incoming.flight_id      := -1 ;

		lba_pkg.handle_lba_info_inserts( incoming, :new.error_id ) ;

		/* Procedure returns the flight_id */

		if (incoming.flight_id >= 0 ) then
			:new.flight_id := incoming.flight_id ;
		end if ;

	end if ;                          /* } */

end;
/

create or replace trigger tu_lba_info
before update on lba_info
for each row
begin

	:new.update_date := sysdate;

end;
/
