/*****************************************************************************
*
* Filename         - $Workfile:   mba_new_warns.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 Stored Procedure
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   mba_new_warns.sql  $  $Revision:   1.4  $
*
* 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:   /shared/pvcs/tagtarch/db_ora/db/source/live/procedures/mba_new_warns.sqv  $
* 
*    Rev 1.4   02 Apr 1998 19:37:06   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.3   15 Jan 1998 12:13:38   tagtrak
* OR: OR11101, TN13, TN15
* CR:
* REV:
* Phase 2C to Phase 3 upgrade plus code review actions and resolving some technical isses.
* 
*    Rev 1.2   24 Oct 1997 11:17:06   tagtrak
* Added PVCS header information
*
****************************************************************************/


PROMPT create or replace procedure mba_new_warns

create or replace procedure mba_new_warns (
	ltime in out  char,
	etime in out  char
) 
as
  
begin

	/*
	 * - Insert a record into the bag_alert table where flights in mba_flights
	 *    that were checked in warning period (default 15 mins) ago and were
	 *    not in the last mba loop and are not loaded.
	 * - Insert another record in the bag_alert table for bags just unloaded
	 */

	/* bags for 'old' flights in mba_flights that were checked in
	warning period (default 15 mins) ago and were not in the last
	mba loop and are not loaded */

	insert into
		bag_alert (
			pax_id,
			no_warnings,
			bag_tag2b,
			bag_tag3,
			last_time_stamp,
			alert_on_action,
			bag_tag,
			bag_tag2a,
			bag_tag1,
			flight_id
		)
		select
			b.pax_id,
			1,
			b.bag_tag2b,
			b.bag_tag3,
			SYSDATE,
			'LOAD',
			b.bag_tag,
			b.bag_tag2a,
			b.bag_tag1,
			p.flight_id
		from
			bag b,
			pax p,
			mba_flights m
		where
			m.flight_id        = p.flight_id    and
			m.first_time       = 0              and
			m.delete_marker    = 0              and
			b.delete_marker    = 0              and
			b.loaded_status   != 'Y'            and
			p.pax_id           = b.pax_id       and
			b.time_bag_stored <= to_date(ltime) and
			time_bag_stored    > to_date(etime); 

	/* check also for bags just unloaded */
	insert into
		bag_alert (
			pax_id,
			no_warnings,
			bag_tag2b,
			bag_tag3,
			last_time_stamp,
			alert_on_action,
			bag_tag,
			bag_tag2a,
			bag_tag1,
			flight_id
		)
		select
			b.pax_id,
			1,
			b.bag_tag2b,
			b.bag_tag3,
			SYSDATE,
			'LOAD',
			b.bag_tag,
			b.bag_tag2a,
			b.bag_tag1,
			p.flight_id
		from
			bag b,
			pax p,
			mba_flights m
		where
			m.flight_id     = p.flight_id    and
			m.first_time    = 0              and
			m.delete_marker = 0              and
			b.delete_marker = 0              and
			b.loaded_status = 'U'            and
			p.pax_id        = b.pax_id       and
			b.time_loaded  <= to_date(ltime) and
			time_loaded     > to_date(etime);

end mba_new_warns;
/
