/*****************************************************************************
*
* Filename         - $Workfile:   add_loadall_pax.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:   add_loadall_pax.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/aisarch/db_ora/db/source/live/procedures/add_loadall_pax.sqv  $
*
*    Rev 1.5   01 Aug 2002 14:07:50   yomi
* DESC: Timezone change
* CR:   15508
*
*    Rev 1.4   02 Apr 1998 19:31:26   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
*
*    Rev 1.3   15 Jan 1998 12:10:52   tagtrak
* OR: OR11101, TN13, TN15
* CR:
* REV:
* Phase 2C to Phase 3 upgrade plus code review actions and resolving some technical isses.
*
*    Rev 1.2   24 Oct 1997 10:59:20   tagtrak
* Added PVCS header information
*
****************************************************************************/


PROMPT create or replace procedure add_loadall_pax

create or replace procedure add_loadall_pax (
	fid   in   number,
	nbags in   number,
	pdest in   char,
	pcls  in   char,
	pid   out  number
)
as
begin

	/*
	 * - Declare a pax_exists exception
	 * - Insert a record into the pax table using the parameters supplied
	 * - Select pax_id from the pax table for the pax just inserted
	 * - If the pax exists, then pid = 0
	 */

	/* now get the new pax_id */
	pid := -1;

	declare
		pax_exists exception;
		pragma exception_init(PAX_EXISTS, -20027);
    v_pid    pax.pax_id%type;
    depair   pax.departure_airport_code%type := null;

	begin
    depair := get_offset.find_airport_code(fid, v_pid);
		insert into pax (
			flight_id,
			pax_initials,
			pax_surname,
			time_pax_stored,
			no_of_bags,
			pax_sequence_no,
			pax_status,
			no_same_surname,
			pax_destination,
			pax_class,
      pax_bags_class,
			authority_to_load_dcs,
			pax_full_inits,
			onward_transfer
		) values (
			fid,
			'LAP',
			'LoadAll Pax',
			SYSDATE + get_offset.airport_code(depair),
			nbags,
			'-1',
			'C',
			0,
			pdest,
			pcls,
      pcls,
			'Y',
			'LAP',
			0
		);

		select
			pax_id
		into
			pid
		from
			pax
		where
			flight_id =  fid and
			pax_sequence_no = '-1';

	exception
		when PAX_EXISTS then
			pid := 0;

	end;
end add_loadall_pax;
/
