-- File renamed from fasl_triggers.sql - Dave Banks - FALCP/CA/1771 - 8th March 2006

create or replace trigger ti_fasl_flight_info
before insert on fasl_flight_info
for each row
begin

	if (:new.id is null or :new.id = 0 ) then
		select
			flight_info_id.nextval
		into
			:new.id
		from
			dual;
	end if;

	:new.timestamp := sysdate;

	if ( :new.direction is null ) then
		:new.direction := 'DEP';
	end if;

end;
/

create or replace trigger tu_fasl_flight_info
before update on fasl_flight_info
for each row
begin

	:new.timestamp := sysdate;

end;
/



create or replace trigger tia_fasl_flight_info
after insert on fasl_flight_info
for each row
declare
	incoming fasl_flight_info%rowtype;
begin

	incoming.id             := :new.id;
	incoming.timestamp      := :new.timestamp;
	incoming.direction      := :new.direction;
	incoming.flight_carrier := :new.flight_carrier;
	incoming.flight_number  := :new.flight_number;
	incoming.flight_suffix  := :new.flight_suffix;
	incoming.flight_date    := :new.flight_date;
	incoming.gate           := :new.gate;
	incoming.std            := :new.std;
	incoming.destination    := :new.destination;

	fasl_fids.handle_flight_info( flightinfo.fasl_interface, incoming);

end;
/

create or replace trigger tua_fasl_flight_info
after update on fasl_flight_info
for each row
declare
	incoming fasl_flight_info%rowtype;
begin

	incoming.id             := :new.id;
	incoming.timestamp      := :new.timestamp;
	incoming.direction      := :new.direction;
	incoming.flight_carrier := :new.flight_carrier;
	incoming.flight_number  := :new.flight_number;
	incoming.flight_suffix  := :new.flight_suffix;
	incoming.flight_date    := :new.flight_date;
	incoming.gate           := :new.gate;
	incoming.std            := :new.std;
	incoming.destination    := :new.destination;

	fasl_fids.handle_flight_info( flightinfo.fasl_interface, incoming);

end;
/
