/*****************************************************************************
*
* Filename         - $Workfile:   delete_all_bags.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:   delete_all_bags.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/delete_all_bags.sqv  $
* 
*    Rev 1.5   25 Sep 1998 10:03:10   tagtrak
* OR: 12484
* CR: 12484
* REV:
* Merged Vienna (0.3.1E) and Core Product (0.2.5E) -
* branch ATS revision moved to trunk.
* Andrew Walker
* 
*    Rev 1.4.2.0   18 Aug 1998 09:34:58   tagtrak
* OR: 12484
* CR: 12484
* REV:
* Merging Vienna (0.3.1E) and Core Product (0.2.5E).
* Andrew Walker
* 
*    Rev 1.4.1.0   04 Jun 1998 15:32:06   tagtrak
* OR:
* CR: 12098
* REV:
* Vienna Modifications
* Andrew Walker
* 
*    Rev 1.4   02 Apr 1998 19:32:44   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.3   15 Jan 1998 12:11:38   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 11:03:20   tagtrak
* Added PVCS header information
*
****************************************************************************/

PROMPT create or replace procedure delete_all_bags

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

as 

	fid		number(10); 
	pid		number(10);

	cursor c1 is 
	select
		pax_id 
	from
		pax
	where
		booked_flight_id =  fid;

begin

	/*
	 * - Initialise Variables
	 * - Call the flight_id stored procedure
	 * - If the fid (obtained from the call to flight_id) equals 0 then
	 *   return value = -139
	 * - else
	 *   loop around the c1_rec cursor
	 *     pid = cursor.pax_id
	 *     update the bag table, and set the delete marker to 1 where
	 *      the pax_id = pid
	 *   end loop
	 *   update the bag table, and set the delete marker to 1 where
	 *    the flight_id = fid
	 */

	fid    := 0;
	retval := 0;
 
	flight_id (fno, fdate, siteid, fid);
 
	if (fid = 0) then 
		retval := -139;
	else 
		/* For Statement */
		for c1_rec in c1 loop 
			pid := c1_rec.pax_id;

			update
				bag
			set 
				delete_marker = 1
			where
				pax_id        =  pid;

		end loop;

		update
			pax
		set 
			delete_marker = 1
		where
			booked_flight_id     = fid;

	end if;
 
end delete_all_bags;
/
