/*****************************************************************************
*
* Filename         - $Workfile:   add_flt_access.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         - add_flt_access stored procedure
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1998
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   add_flt_access.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/add_flt_access.svl  $
* 
*    Rev 1.3   21 Jun 2001 14:38:04   tagtrak
* OR:
* CR:
* Re-baseline version 4.0.0 to include patches.
* 
*    Rev 1.2   20 Sep 1999 14:39:52   tagtrak
*  
* 
*    Rev 1.1   02 Apr 1998 19:31:14   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.0   26 Feb 1998 10:18:00   tagtrak
* OR:
* CR:
* REV:
* Initial core product version
*
****************************************************************************/

/*
 * add_flt_access - add a flight_access record.
 * This procedure will check for existance of the required
 * record, and if it doesnt already exist will create it.
 */
PROMPT create or replace procedure add_flt_access

create or replace procedure add_flt_access (
	flt_id     in   flight.flight_id%type,
	agent      in   agents.agent_code%type,
	fpriv_id   in   flight_privileges.id%type
)
as

	counter number;

begin

	counter := 0;

	/*
	 * We won't attempt to insert a record if an
	 * identical one exists.
	 */
	select
		count(1)
	into
		counter
	from
		flight_access
	where
		flight_id = flt_id and
		nvl(flight_priv_id,0) = nvl(fpriv_id,0) and
		agent_code = agent;

	if ( counter = 0 ) then
		insert into flight_access
			(flight_id, agent_code, flight_priv_id)
		values
			(flt_id, agent, fpriv_id);
	end if;

end add_flt_access;
/
