COMPILE FUNCTION obj_Order_Change(Method,Parms)
/*
	Methods for the Order_Change Window
    
	06/05/2005 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    Create(TableName,RecordKey,Column,OldValue,NewValue,Reason)
   
	
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, NextKey, Popup
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, Send_Dyn, Btree.Extract, ErrMsg, Send_Dyn, RList

$INSERT MSG_EQUATES
$INSERT ORDER_CHANGE_EQU
$INSERT WO_LOG_EQU
$INSERT ORDER_DET_EQU
$INSERT RDS_EQU

EQU TARGET_ACTIVELIST$ TO 5


ErrTitle = 'Error in Stored Procedure "obj_Order_Change"'
ErrorMsg = ''

IF NOT(ASSIGNED(Method))	THEN ErrorMsg = 'Unassigned parameter "Method" passed to subroutine'
IF NOT(ASSIGNED(Parms))		THEN Parms = ''

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

Result = ''

BEGIN CASE
	CASE Method = 'Create'		; GOSUB Create
	
	CASE 1
		ErrorMsg = 'Unknown Method ':QUOTE(Method):' passed to routine.'

END CASE

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

RETURN Result



* * * * * * *
Create:
* * * * * * *

OrderNo			= Parms[1,@RM]
TableName		= Parms[COL2()+1,@RM]
RecordKey		= Parms[COL2()+1,@RM]
Column			= Parms[COL2()+1,@RM]
Value			= Parms[COL2()+1,@RM]
OldValue		= Parms[COL2()+1,@RM]
NewValue		= Parms[COL2()+1,@RM]
Reason			= Parms[COL2()+1,@RM]
UserName		= Parms[COL2()+1,@RM]

IF OrderNo	 	= '' THEN ErrorMsg = 'Null parameter "OrderNo" passed to routine. (':Method:')'
IF Reason		= '' THEN ErrorMsg = 'Null parameter "Reason" passed to routine. (':Method:')'

IF UserName = '' THEN UserName = @USER4

IF ErrorMsg NE '' THEN RETURN

OCNo = NextKey('ORDER_CHANGE')

OCRec = ''
OCRec<ORDER_CHANGE_ORDER_NO$>	= OrderNo
OCRec<ORDER_CHANGE_TABLE$>		= TableName
OCRec<ORDER_CHANGE_RECORD_KEY$>	= RecordKey
OCRec<ORDER_CHANGE_COLUMN$>		= Column
OCRec<ORDER_CHANGE_VALUE$>		= Value
OCRec<ORDER_CHANGE_OLD_VALUE$>	= OldValue
OCRec<ORDER_CHANGE_NEW_VALUE$>	= NewValue
OCRec<ORDER_CHANGE_REASON$>		= Reason
OCRec<ORDER_CHANGE_TIMESTAMP$>	= ICONV(OCONV(Date(),'D4'):' ':OCONV(Time(),'MT'),'DTM')
OCRec<ORDER_CHANGE_USER_NAME$>	= UserName
OCRec<ORDER_CHANGE_STATION_ID$>	= @STATION

obj_Tables('WriteRec','ORDER_CHANGE':@RM:OCNo:@RM:@RM:OCRec)


RETURN


