COMPILE FUNCTION Batch_WO_Purge(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)

/*
	Commuter module for BATCH_WO_PURGE window (Purge groups of Work Orders and all affiliated data from the system)
	
	02/16/2016 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status,Print_React_Read_Worksheet
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, obj_AppWindow, 
DECLARE SUBROUTINE End_Window,obj_React_Reads

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Popup, Collect.Ixvals
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_WO_Log, WO_Purge, Set_Property


$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT POPUP_EQUATES


EQU CRLF$	TO \0D0A\
EQU TAB$	TO \09\


EQU COL$WO_NO		TO 1
EQU COL$CASS_CNT	TO 2
EQU COL$START		TO 3
EQU COL$STOP		TO 4
EQU COL$PER_BOX		TO 5

ErrTitle = 'Error in Batch_WO_Purge commuter module'
ErrorMsg = ''

Result = ''


BEGIN CASE

	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
		END CASE
	
	CASE EntID = @WINDOW:'.LU_WO' 			AND Event = 'CLICK'	; GOSUB LUWONo
	CASE EntID = @WINDOW:'.START_PURGE'		AND Event = 'CLICK'	; GOSUB StartPurge
	CASE EntID = @WINDOW:'.DONE'			AND Event = 'CLICK'	; GOSUB Close
	CASE EntID = @WINDOW:'.CLEAR'			AND Event = 'CLICK'	; GOSUB Clear
	
	CASE EntID = @WINDOW:'.WO_NO' AND Event = 'POSCHANGED'		; GOSUB WONoPC
	CASE EntID = @WINDOW:'.WO_NO' AND Event = 'CLICK'			; GOSUB WOClick
	CASE EntID = @WINDOW:'.WO_NO' AND Event = 'INSERTROW'		; GOSUB InsertRow
	CASE EntID = @WINDOW:'.WO_NO' AND Event = 'DELETEROW'		; GOSUB DeleteRow
	
	CASE 1
		ErrorMsg = 'Unknown Parameters ':EntID:' - ':Event:' passed to commuter'
		ErrMsg(ErrorMsg)
		
END CASE

IF ErrorMsg NE '' THEN
	ErrMsg(ErrTitle:@SVM:ErrorMsg)
END

RETURN Result






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


obj_Appwindow('Create',@WINDOW)


GOSUB Refresh

RETURN


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

End_Dialog(@WINDOW,'')

RETURN


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


RETURN


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


EmptyCol = STR(@VM,90)

Array = ''

Array<COL$WO_NO>	= EmptyCol
Array<COL$CASS_CNT> = EmptyCol
Array<COL$START>	= EmptyCol
Array<COL$STOP>		= EmptyCol
Array<COL$PER_BOX>	= EmptyCol


Set_Property(@WINDOW:'.WO_NO','DEFPROP',Array)


RETURN



* * * * * * *
LUWoNo:
* * * * * * *


Set_Status(0)

WOKeys = obj_WO_Log('Find')	

IF Get_Status(errCode) THEN ErrMsg(ErrCode)

IF WOKeys NE '' THEN
	TypeOver = ''
	TypeOver<PDISPLAY$> = WOKeys
	TypeOver<PMODE$> = 'K'

	WOKeys = Popup(@WINDOW,TypeOver,'WO_LOG_QUERY')
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
	
	IF WOKeys = '' THEN RETURN
	
	WOCnt = COUNT(WOKeys,@VM) + (WOKeys NE '')
	
	CassCnts = XLATE('WO_LOG',WOKeys,'WO_MAT_CNT','X')
	

	WOArray = ''
	WOArray<COL$WO_NO> 		= WOKeys:@VM
	WOArray<COL$CASS_CNT>	= CassCnts:@VM
	WOArray<COL$START>		= STR(@VM,WOCnt)
	WOArray<COL$STOP>		= STR(@VM,WOCnt)
	WOArray<COL$PER_BOX>	= STR(@VM,WOCnt)
	
	Set_Property(@WINDOW:'.WO_NO','DEFPROP',WOArray)
	
	
END
RETURN



* * * * * * *
WOClick:
* * * * * * *

RETURN


* * * * * * *
WONoPC:
* * * * * * *

GOSUB Refresh

RETURN


* * * * * * *
InsertRow:
* * * * * * *

DEBUG


RETURN


* * * * * * *
DeleteRow:
* * * * * * *

DEBUG


RETURN




* * * * * * *
StartPurge:
* * * * * * *


CtrlEntID = @WINDOW:'.WO_NO'

WOList = Get_Property(@WINDOW:'.WO_NO','LIST')

SelPositions = Get_Property(@WINDOW:'.WO_NO','SELPOS')	;* Returns list of selected row numbers
SelectedRows = SelPositions<2>

CONVERT @VM TO @FM in SelectedRows

SelCnt = COUNT(SelectedRows,@FM) + (SelectedRows NE '')

FOR I = 1 TO SelCnt

	SelectedRow = SelectedRows<I>
	WONo = WOList<SelectedRow,COL$WO_NO>
	
	
	StartTime = Time()
	
	void = WO_Purge(WONo)
	
	StopTime = Time()
	
	BoxCnt = WOList<SelectedRow,COL$CASS_CNT>
	
	IF StopTime = StartTime OR BoxCnt = 0 THEN
		PerBox = '-'
	END ELSE
		
		PerBox = OCONV(ICONV((StopTime - StartTime)/BoxCnt,'MD2'),'MD2')
		
	END
	
	
	Set_Property(CtrlEntID,'SELPOS',1:@FM:SelectedRow)		;* Clears selection in edit table line
	
	stat = Send_Message(CtrlEntID,'COLOR_BY_POS',0,SelectedRow,RED$)
	Set_Property(CtrlEntID,'CELLPOS',OCONV(StartTime,'MTS'),COL$START:@FM:SelectedRow)
	Set_Property(CtrlEntID,'CELLPOS',OCONV(StopTime,'MTS'),COL$STOP:@FM:SelectedRow)
	Set_Property(CtrlEntID,'CELLPOS',PerBox,COL$PER_BOX:@FM:SelectedRow)
	
NEXT I


RETURN





