/*****************************************************************************
*
* Filename         - $Workfile:   check_unload_alert.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 - check_unload_alert
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   check_unload_alert.sql  $  $Revision:   1.3  $
*
* 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/procedures/check_unload_alert.svl  $
* 
*    Rev 1.3   21 Jun 2001 14:42:12   tagtrak
* OR:
* CR:
* Re-baseline version 4.0.0 to include patches.
* 
*    Rev 1.2   20 Sep 1999 14:40:20   tagtrak
*  
* 
*    Rev 1.1   02 Apr 1998 19:22:16   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.0   15 Jan 1998 12:15:58   tagtrak
* OR: OR11101, TN13, TN15
* CR:
* REV:
* Phase 2C to Phase 3 upgrade plus code review actions and resolving some technical isses.
*
****************************************************************************/

PROMPT create or replace procedure check_unload_alert

create or replace procedure check_unload_alert (
	dm            in       number,
	atl1          in       char,
	atl2          in       char,
	dest          in       char,
	uno           in       char,
	fid           in       number,
	ldd_sts       in       char,
	clear_alert   in out   number
) as

	numrows number;

begin

	/*
	 * This procedure is called by the trigger TU_BAG to indicate whether
	 * UNLOAD alerts should be cleared.
	 * An UNLOAD alert should be cleared if;
	 *    the bag is not deleted (dm = 0) AND
	 *    authorised to load (atl1 = 'Y' AND atl2 = 'Y') AND
	 *    if loaded, new destination is OK for this ULD
	 * Returns clear_alert = 1 to clear the alert, else 0.
	 */

	/*
	 * See if the destination is one that can go into this
	 * ULD, if it is numrows will be > 0.
	 */

	if (ldd_sts = 'Y') then
			select
				count(uld_no)
			into
				numrows
			from
				uld_dests
			where
				uld_no = uno and
				flight_id = fid and
					(uld_destination = dest
					or uld_destination = '*');

	else
		/*
		 * Put in dummy value for next bit of code, though
		 * we would not expect to be called AND would not expect
		 * an UNLOAD alert IF the bag was not loaded
		 */

		numrows := 1;
	end if;
 
	if ( dm = 0 and atl1 = 'Y' and
		atl2 = 'Y' and numrows > 0) then
		clear_alert := 1;
	else
		clear_alert := 0;
	end if;

end check_unload_alert;
/
