/*****************************************************************************
*
* Filename         - $Workfile:   agents_triggers.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         - Triggers for agents table.
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1998
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   agents_triggers.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/triggers/agents_triggers.svl  $
* 
*    Rev 1.2   21 Jun 2001 15:03:38   tagtrak
* OR:
* CR:
* Re-baseline version 4.0.0 to include patches.
* 
*    Rev 1.1   02 Apr 1998 19:45:46   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.0   26 Feb 1998 11:52:30   tagtrak
* OR:
* CR:
* REV:
* Initial core product version
*
****************************************************************************/

/*
 * After insert trigger on agents
 * Log an audit record.
 */
create or replace trigger ti_agents
after insert on agents
for each row
begin

	/*
	 * Maintain audit trail.
	 */
	add_log_rec( 'AGENTS',
		'insert: Agent Code: '||rtrim(:new.agent_code)||
		'. Description: '||rtrim(nvl(:new.description,'blank'))||
		'. Archive Flag: '||:new.archive_flag||'. Internal User: '||USER,
		:new.last_user );

end;
/

/*
 * After update trigger on agents
 * Log an audit record.
 */
create or replace trigger tu_agents
after update on agents
for each row
begin

	/*
	 * Maintain audit trail.
	 */
	add_log_rec( 'AGENTS',
		'update: (old values): Agent Code: '||rtrim(:old.agent_code)||
		'. Description: '||rtrim(nvl(:old.description,'blank'))||
		'. Archive Flag: '||:old.archive_flag||'. Last user: '||:old.last_user||
		'. (new values): Agent Code: '||rtrim(:new.agent_code)||
		'. Description: '||rtrim(nvl(:new.description,'blank'))||
		'. Archive Flag: '||:new.archive_flag||'. Internal User: '||USER,
		:new.last_user );

end;
/

/*
 * After delete trigger on agents
 * Log an audit record.
 */
create or replace trigger td_agents
after delete on agents
for each row
begin

	/*
	 * Maintain audit trail. The user is unknown in this context.
	 */
	add_log_rec( 'AGENTS',
		'delete: Agent Code: '||rtrim(:old.agent_code)||
		'. Description: '||rtrim(nvl(:old.description,'blank'))||
		'. Archive Flag: '||:old.archive_flag||'. Last user: '||:old.last_user||
		'. Internal User: '||USER,
		NULL );

end;
/
