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


/*
 * add_stats_access - add a stats_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_stats_access

create or replace procedure add_stats_access (
	cont_agent  in   agents.agent_code%type,
	del_agent   in   agents.agent_code%type,
	flt_no      in   flight.flight_no%type,
	flt_dt      in   flight.flight_date%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
		stats_access
	where
		contracted_agent = cont_agent                  and
		nvl(delegated_agent,'-') = nvl(del_agent,'-')  and
		flight_no = flt_no                             and
		flight_date = flt_dt;

	if ( counter = 0 ) then
		insert into stats_access (
			contracted_agent,
			delegated_agent,
			flight_no,
			flight_date,
      airport_code,
			timestamp
		) values (
			cont_agent,
			del_agent,
			flt_no,
			flt_dt,
      multi_site.get_agent_loc(cont_agent),
			SYSDATE
		);
	end if;

end add_stats_access;
/
