/*****************************************************************************
*
* Filename         - $Workfile:   flight_close.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:   flight_close.sql  $  $Revision:   1.5  $
*
* 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/flight_close.sqv  $
* 
*    Rev 1.5   02 Apr 1998 19:33:08   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.4   15 Jan 1998 12:11:54   tagtrak
* OR: OR11101, TN13, TN15
* CR:
* REV:
* Phase 2C to Phase 3 upgrade plus code review actions and resolving some technical isses.
* 
*    Rev 1.3   24 Oct 1997 11:04:44   tagtrak
* Added PVCS header information
*
****************************************************************************/

PROMPT create or replace procedure flight_close

create or replace procedure flight_close (
	fno in  char,
	fdate in  char,
  siteid in number,
	retval out  number
) 
as 

	fid number(10); 
	fc  char(20);
begin

	/*
	 * - Initialise variables
	 * - Call the flight_id stored procedure
	 * - If the fid variable is equal to 0 then
	 *   return value = -139
	 * - else
	 *   select the db_value from the db_config table where the db_item =
	 *    'status_closed'.  If no data is found, then return value = -1016
	 * - if fc equals '-' then
	 *   return value = -1016
	 * - else
	 *   update the flight table and set the flight_status to the first 2
	 *    characters of the fc variable where the flight_id is equal to the
	 *    flight_id passed in as a parameter.
	 */


	fid    := 0;
	fc     := '-';
	retval := 0;

	flight_id (fno, fdate, siteid, fid);

	if (fid = 0) then 
		retval := -139;
	else 
		begin
			select 
				db_value 
			into
				fc 
			from
				db_config
			where
				db_item = 'status_closed'; 

			exception
				when NO_DATA_FOUND then
					retval := -1016;
		end;

		if (fc = '-') then 
			retval := -1016;
		else 
			update
				flight
			set 
				flight_status =  SUBSTR(fc, 1, 2)
			where
				flight_id     =  fid;
		end if;
	end if;
	 
end flight_close;
/
