/*****************************************************************************
*
* Filename         - $Workfile:   set_location.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:   set_location.sql  $  $Revision:   1.2  $
*
* 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/set_location.svl  $
* 
*    Rev 1.2   20 Sep 1999 14:42:06   tagtrak
*  
* 
*    Rev 1.1   02 Apr 1998 19:38:02   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.0   26 Feb 1998 10:22:18   tagtrak
* OR:
* CR:
* REV:
* Initial core product version
* 
****************************************************************************/
PROMPT create or replace procedure set_location

create or replace procedure set_location (
	p_kit_id        in      kit.id%TYPE,
	p_location_code in      kit.location_code%TYPE,
        psiteid         in      location.site_id%type,
	ret_status      in out  number
) 
as
	count_locations         number;
        depcode site_info.airport_code%type;
begin
  depcode := multi_site.get_airport_code(psiteid); 

	ret_status      := 0;
	count_locations := 0;

	begin
		select
			count(*)
		into
			count_locations
		from
			location
		where
			location_code = p_location_code
                  AND   site_id   = psiteid;

		exception
			when NO_DATA_FOUND then
				/* UNKNOWN_LOCN */
				ret_status := -101;
				return;
	end;

	if (count_locations < 1) then
		/* UNKNOWN_LOCN */
		ret_status := -101;
		return;
	end if;
	
  /* Also set the global location_code */
  user_login_pkg.g_location_code := p_location_code;
  
	update
		kit
	set
		location_code = p_location_code,
                airport_code  = depcode
	where
		id            = p_kit_id;

  
	if (SQL%NOTFOUND) then
		/* UNKNOWN_KIT */
		ret_status := -1034;
	end if;

end set_location;
/
