/*****************************************************************************
*
* Filename         - $Workfile:   is_uld_shipside.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:   is_uld_shipside.sql  $  $Revision:   1.7  $
*
* 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/is_uld_shipside.sqv  $
* 
*    Rev 1.7   02 Apr 1998 19:36:42   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.6   15 Jan 1998 12:13:18   tagtrak
* OR: OR11101, TN13, TN15
* CR:
* REV:
* Phase 2C to Phase 3 upgrade plus code review actions and resolving some technical isses.
* 
*    Rev 1.5   24 Oct 1997 11:14:32   tagtrak
* Added PVCS header information
*
****************************************************************************/


PROMPT create or replace procedure is_uld_shipside

create or replace procedure is_uld_shipside (
	uno         in     char,
	fno         in     char,
	fid         in     number,
	is_shipside in out char
)
as 

	cv_locn get_latest_uld_trace_pkg.cursor_type;
	locn    char(8);
	flno    char(8);
	fldt    char(5);

begin

	/*
	 * - Initialise variable
	 * - Select uld_loaded_status from the ulds table where the uld_no is
	 *   equal to the uno parameter and the flight_id is equal to the
	 *   fid parameter
	 * - If it is not shipside then
	 *   call the get_latest_uld_trace procedure
	 *   loop
	 *     fetch cursor and exit when no more data is found
	 *     If fno = '-' then
	 *       Call the flight_no procedure to obtain the flight_no
	 *     else
	 *       Assign fno to the flno variable
	 *     IF locn = flno then
	 *       Assign shipside to 'Y'
	 *     ELSE
	 *       Assign shipside to 'N'
	 *   End Loop
	 *   Close Cursor
	 * - If no data found then
	 *   Assign shipside to 'N'
	 */

	is_shipside := 'N';

	select
		uld_loaded_status
	into
		is_shipside
	from
		ulds
	where
		uld_no    = uno and
		flight_id = fid;

	if (is_shipside = 'N') then 
		/* may have been logged at plane side, but not loaded into plane */
		get_latest_uld_trace_pkg.get_latest_uld_trace (
			fid,
			uno,
			cv_locn
		);

		loop
			fetch cv_locn into locn;
			exit when cv_locn%notfound;

			if (fno = '-') then
				flight_no (fid, flno, fldt);
			else
				flno := fno;
			end if;

			if (locn = flno) then
				is_shipside := 'Y'; /* it is ship-side */ 
			else
				is_shipside := 'N';
			end if;
		end loop;
		close cv_locn;
	end if;

	exception when NO_DATA_FOUND then
		is_shipside := 'N';

end is_uld_shipside;
/
