COMPILE FUNCTION Comm_Order_Change(Instruction, Parm1,Parm2)

/*
	Commuter module for ORDER_CHANGE (Order Change Log) window
	
	06/28/2004 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event, Set_List_Box_Data
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow, Make.List, Print_Order
DECLARE SUBROUTINE obj_Notes, Security_Err_Msg, End_Window, Forward_Event, Start_Window, obj_Order_Det, Create_Note
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Center_Window, Popup, Collect.Ixvals
DECLARE FUNCTION Send_Message, Msg, Security_Check, RowExists, obj_Order, NextKey, obj_WO_Log

$INSERT POPUP_EQUATES
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT QUOTE_SIGS_EQU
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT COMPANY_EQU
$INSERT QUOTE_EQU
$INSERT ORDER_EQU
$INSERT ORDER_DET_EQU
$INSERT NOTIFICATION_EQU

EQU CRLF$	TO \0D0A\

EQU COL$TABLE		TO 1
EQU COL$RECORD_KEY	TO 2
EQU COL$COLUMN		TO 3
EQU COL$VALUE		TO 4
EQU COL$OLD_VALUE	TO 5
EQU COL$NEW_VALUE	TO 6


EQU COL$ITEM_NO		TO 1		;* Equates for ORDER_DET (line item) edit table.
EQU COL$QUOTE_NO	TO 2
EQU COL$EPI_PN		TO 3
EQU COL$CUST_PN		TO 4
EQU COL$WO_NO		TO 5
EQU COL$ITEM_DESC	TO 6
EQU COL$ITEM_QTY	TO 7
EQU COL$UNIT_PRICE	TO 8
EQU COL$ITEM_AMT	TO 9

ErrTitle = 'Error in Comm_Order'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Instruction = 'Create' 		; GOSUB Create
	CASE Instruction = 'Refresh'		; GOSUB Refresh
	CASE Instruction = 'Read'			; GOSUB Read
	CASE Instruction = 'Write'			; GOSUB Write
	CASE Instruction = 'Clear'			; GOSUB Clear
	CASE Instruction = 'Delete'			; GOSUB Delete
	CASE Instruction = 'Page'			; GOSUB Page
	CASE Instruction = 'Close'			; GOSUB Close
	CASE Instruction = 'LUOrderChange'	; GOSUB LUOrderChange
	

	
	CASE 1
		ErrorMsg = 'Unknown Instruction ':QUOTE(Instruction):' passed to routine.'
		ErrMsg(ErrorMsg)
END CASE

RETURN Result



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

obj_Appwindow('Create',@WINDOW)

GOSUB Refresh

RETURN


* * * * * * *
Clear:
* * * * * * *

Send_Event(@WINDOW,'PAGE',1)

obj_AppWindow('ReadOnly',@RM:1)		;* Reenables data bound controls


* * * * * * *
Refresh:
* * * * * * *

IF Security_Check('Order',EDIT$) THEN
	obj_AppWindow('ReadOnly',@WINDOW:@RM:1)		;* enable all database controls
END ELSE
	obj_AppWindow('ReadOnly',@WINDOW)			;* disable all database controls
END


TableArray = Get_Property(@WINDOW:'.TABLE','DEFPROP')

Columns = TableArray<COL$COLUMN>
OldValues = TableArray<COL$OLD_VALUE>
NewValues = TableArray<COL$NEW_VALUE>

FOR I = 1 TO COUNT(Columns,@VM) + (Columns NE '')
	ColName = Columns<1,I>
	IF INDEX(ColName,'_DT',1) THEN
		OldValue = OCONV(OldValues<1,I>,'D4/')
		NewValue = OCONV(NewValues<1,I>,'D4/')
		Set_Property(@WINDOW:'.TABLE', 'CELLPOS', OldValue, COL$OLD_VALUE:@FM:I)
		Set_Property(@WINDOW:'.TABLE', 'CELLPOS', NewValue, COL$NEW_VALUE:@FM:I)
	END

NEXT I


* QBF buttons

Ctrls  = @WINDOW:'.QBF_FIRST_FIX':@RM		; Props  = 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_PREV_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_ABS_FIX':@RM			; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_NEXT_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_LAST_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_STOP_FIX'			; Props := 'ENABLED'

IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
	Vals = 0:@RM:0:@RM:0:@RM:0:@RM:0:@RM:0
END ELSE
	Vals = 1:@RM:1:@RM:1:@RM:1:@RM:1:@RM:1
END

Set_Property(Ctrls,Props,Vals)

* Turn edit table symbolic column backgrounds to green

ETSymbolics = Get_Property(@WINDOW,'@ET_SYMBOLICS')		;* Loaded during 'Create' in obj_Appwindow

ETCtrls	= ETSymbolics<1>
ETCols	= ETSymbolics<2>

FOR I = 1 TO COUNT(ETCtrls,@VM) + (ETCtrls NE '')
	ETCtrl	= ETCtrls<1,I>
	ETList = Get_Property(ETCtrl,'LIST')
	FOR Line = 1 TO COUNT(ETList,@FM) + (ETList NE '')
		IF ETList<Line,1> NE '' THEN
			FOR N = 1 TO COUNT(ETCols<1,I>,@SVM) + (ETCols<1,I> NE '')
				stat = Send_Message(ETCtrl,'COLOR_BY_POS',ETCols<1,I,N>,Line,GREEN$)
			NEXT N
		END
	NEXT I
NEXT I

RETURN


* * * * * * *
Page:
* * * * * * *

obj_Appwindow('Page')
GOSUB Refresh

RETURN


* * * * * * *
Read:
* * * * * * *

GOSUB Refresh

RETURN


* * * * * * *
Write:
* * * * * * *

OrderNo = Get_Property(@WINDOW:'.ORD_NO','TEXT')

* Change SentTO to a comma delimited list of user ID's

Message = ''
IF RowExists('ORDER',OrderNo) THEN
	Message = 'New Order ':QUOTE(OrderNo):' entered into system.'
END ELSE
	IF Get_Property(@WINDOW,'SAVEWARN') THEN
		Message = 'Order No. ':OrderNo:' has been changed.'
	END
END

IF Message NE '' THEN
   	
	Recipients		= XLATE('NOTIFICATION','ORDER_ENTRY',NOTIFICATION_USER_ID$,'X')
	SentFrom		= @USER4
	Subject			= 'New/Update Order':OrderNo
	AttachWindow	= 'ORDER2'
	AttachKey		= OrderNo   
	SendToGroup		= ''   

	Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
	*obj_Notes('Create',Parms)																				;* Per request of Customer Service 

	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
 
END

RETURN


* * * * * * *
Delete:
* * * * * * *

Result = 0		;* Stop event chain


RETURN

* * * * * * *
LUOrderChange:
* * * * * * * 

IF NOT(ASSIGNED(Parm1)) THEN FocusControl = ''	ELSE FocusControl = Parm1
IF NOT(ASSIGNED(Parm2)) THEN FocusPos = ''		ELSE FocusPos = Parm2

Set_Status(0)

OrderKeys = Popup(@WINDOW,TypeOver,'ORDER_CHANGE_LOG')

CONVERT @VM TO @FM IN OrderKeys

IF INDEX(OrderKeys,@FM,1) THEN
	Send_Event(@WINDOW,'QBFINIT')
	Set_Property(@WINDOW,'QBFLIST',OrderKeys)
	GOSUB Refresh
	Send_Event(@WINDOW,'QBFIRST')
END ELSE
	obj_Appwindow('LoadFormKeys',@WINDOW:@RM:OrderKeys)
END

RETURN


* * * * * * *
Close:
* * * * * * *

obj_Appwindow('DetailReturn')

RETURN

