COMPILE FUNCTION Comm_WO_Log_Tables(Instruction, Parm1,Parm2)

/*
	Commuter module for WO_Log2 (Work Order Log) window edit table functions
	
	08/16/2004 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, obj_Notes, obj_WO_Step, Start_Window
DECLARE SUBROUTINE Btree.Extract, Send_Event, Forward_Event, End_Window,Comm_WO_Log, Popup, obj_Tables
DECLARE FUNCTION Get_Property, Get_Status, Popup, Send_Message, Msg, Security_Check, Dialog_Box, RowExists
DECLARE FUNCTION Dialog_Box, obj_RDS


$INSERT POPUP_EQUATES
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT WO_LOG_EQU
$INSERT ORDER_EQU
$INSERT ORDER_DET_EQU
$INSERT SCHEDULE_EQU
$INSERT RDS_EQU
$INSERT PROD_SPEC_EQU


EQU CRLF$	TO \0D0A\

EQU COL$QUOTE_DESC		TO 1
EQU COL$SETUP_CHG		TO 4
EQU COL$SRP_CHG			TO 5
EQU COL$WAFER_PRICE		TO 6

EQU COL$ADD_DESC			TO 1
EQU COL$ADD_AMT				TO 2


EQU COL$CASS_NO				TO 1
EQU COL$LOT_NO				TO 2
EQU COL$QTY					TO 3
EQU COL$SUB_PART_NO			TO 4
EQU COL$VEND_CD				TO 5
EQU COL$EPI_PART_NO			TO 6
EQU COL$RX_DTM				TO 7
EQU COL$REL_DTM				TO 8
EQU COL$CURR_STATUS			TO 9
EQU COL$SAP_TX_DTM			TO 10
EQU COL$SAP_BATCH_NO		TO 11
EQU COL$CASS_ID_SAP			TO 12
EQU COL$SAP_YIELD			TO 13
EQU COL$SAP_CONFIRM_SCRAP	TO 14
EQU COL$SAP_GR_QTY			TO 15
EQU COL$SAP_RAW_SCRAP_QTY	TO 16
EQU COL$SAP_PROD_TEST_QTY	TO 17
EQU COL$SAP_MU_QTY			TO 18



EQU COL$STEP			TO 1
EQU COL$PSN				TO 2
EQU COL$DOPANT			TO 3
EQU COL$THICK			TO 4
EQU COL$THICK_UNITS		TO 5
EQU COL$RESIST			TO 6
EQU COL$RESIST_UNITS	TO 7
EQU COL$DESC			TO 8
EQU COL$STEP_STATUS		TO 9
EQU COL$STEP_SCHED		TO 10
EQU COL$STEP_SCHED_DTM	TO 11



ErrTitle = 'Error in Comm_WO_Log_Tables'
ErrorMsg = ''

Result = ''

BEGIN CASE
	
	CASE Instruction = 'QuotePriceDC'	; GOSUB QuotePriceDC
	CASE Instruction = 'PSPartDC'		; GOSUB PSPartDC
	CASE Instruction = 'ShipDC'			; GOSUB ShipDC
	CASE Instruction = 'ProcStepDC'		; GOSUB ProcStepDC
	CASE Instruction = 'WOStepDC'		; GOSUB WOStepDC
	CASE Instruction = 'PartStepDC'		; GOSUB WOStepDC
	CASE Instruction = 'Reorder'		; GOSUB Reorder
	CASE Instruction = 'CassDC'			; GOSUB CassDC
	CASE Instruction = 'CassInsert'		; GOSUB CassInsert
	CASE Instruction = 'CassDelete'		; GOSUB CassDelete


	CASE 1
		ErrorMsg = 'Unknown Instruction passed to routine'
END CASE

RETURN Result


* * * * * * *
QuotePriceDC:
* * * * * * *

* DoubleClick event handler for the Quotes Table

CtrlEntId = @WINDOW:'.QUOTE_PRICING'

CurrPos = Get_Property(CtrlEntId,'SELPOS')
RowData = Get_Property(CtrlEntId,'ROWDATA')
ColData = Get_Property(CtrlEntId,'ARRAY')

CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

IF CurrCol = COL$SETUP_CHG AND RowData<CurrCol> NE '' THEN
	NewDesc = RowData<COL$QUOTE_DESC>
	NewAddChg = RowData<COL$SETUP_CHG>
	
	AddChgDescs = Get_Property(@WINDOW:'.ADD_CHG','ARRAY')<1>	;* 1st column in edit table

	LineCnt = 0
	FOR I = 1 TO COUNT(AddChgDescs,@VM) + (AddChgDescs NE '')
	UNTIL AddChgDescs<1,I> = ''
		LineCnt += 1
	NEXT I
	
	Set_Property(@WINDOW:'.ADD_CHG','CELLPOS',NewDesc,COL$ADD_DESC:@FM:LineCnt+1)
	Set_Property(@WINDOW:'.ADD_CHG','CELLPOS',NewAddChg,COL$ADD_AMT:@FM:LineCnt+1)
END	;* End of check for Setup Charge column

IF CurrCol = COL$SRP_CHG AND RowData<CurrCol> NE '' THEN
	NewDesc = RowData<COL$QUOTE_DESC>
	NewAddChg = RowData<COL$SRP_CHG>
	
	AddChgDescs = Get_Property(@WINDOW:'.ADD_CHG','ARRAY')<1>	;* 1st column in edit table

	LineCnt = 0
	FOR I = 1 TO COUNT(AddChgDescs,@VM) + (AddChgDescs NE '')
	UNTIL AddChgDescs<1,I> = ''
		LineCnt += 1
	NEXT I
	
	Set_Property(@WINDOW:'.ADD_CHG','CELLPOS',NewDesc,COL$ADD_DESC:@FM:LineCnt+1)
	Set_Property(@WINDOW:'.ADD_CHG','CELLPOS',NewAddChg,COL$ADD_AMT:@FM:LineCnt+1)
END	;* End of check for SRP Charge column


IF CurrCol = COL$WAFER_PRICE AND RowData<CurrCol> NE '' THEN

	NewWaferPrice = RowData<COL$WAFER_PRICE>
	
	Set_Property(@WINDOW:'.UNIT_PRICE','DEFPROP',NewWaferPrice)
	
END	;* End of check for SRP Charge column

Comm_WO_Log('Refresh')

RETURN


* * * * * * *
PSPartDC:
* * * * * * *

RETURN			; ******** 7/23/2014 Control no longer in the window jch

CtrlEntID = @WINDOW:'.PS_PARTS'

CurrPartPos = Get_Property(CtrlEntID,'SELPOS')
PartNo = Get_Property(CtrlEntID,'CELLPOS',CurrPartPos)

CurrArray = Get_Property(@WINDOW:'.SCHED_IDS','ARRAY')

PartNos = CurrArray<COL$PART_NO>

CurrPos = Get_Property(@WINDOW:'.SCHED_IDS','SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

IF Get_Property(@WINDOW:'.SCHED_IDS','CELLPOS',COL$PART_NO:@FM:CurrRow) = '' THEN
	Set_Property(@WINDOW:'.SCHED_IDS','CELLPOS',PartNo,COL$PART_NO:@FM:CurrRow)
END

RETURN


* * * * * * *
ProcStepDC:
* * * * * * * 


RETURN


* * * * * * *
WOStepDC:
* * * * * * *
IF @USER4 EQ 'JONATHAN_O' then debug
CtrlEntID = Get_Property(@WINDOW,'FOCUS')

WONo = Get_Property(@WINDOW : '.EDL_WO_NO', 'DEFPROP')

CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>


StepNo		= Get_Property(CtrlEntID,'CELLPOS',COL$STEP:@FM:CurrRow)
PSNo		= Get_Property(CtrlEntId,'CELLPOS',COL$PSN:@FM:CurrRow)
ReactorType = XLATE('PROD_SPEC',PSNo,PROD_SPEC_REACTOR_TYPE$,'X')		;* Not used in program 8/28/2014 JCH


BEGIN CASE
	CASE CurrCol = COL$STEP

		IF WONo NE '' AND StepNo NE '' THEN

			WOStepKey = WONo:'*':StepNo

			IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
				Send_Event(@WINDOW,'WRITE')
			END
			
			*IF ReactorType = 'P' THEN
			*	DetWindow = 'WO_PROD_EPI'
			*END ELSE
				DetWindow	= 'WO_STEP'
			*END
			
			DetKeys		= WONo:'*':StepNo
			DefaultRec	= ''
			RetKey		= WONo
			RetPage		= 1
			RetCtrl		= CtrlEntID
			RetPos		= CurrPos
			
			oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

			obj_AppWindow('ViewNewDetail',oAParms)
			IF Get_Status(errCode) THEN
				ErrMsg(errCode)
			END
			
		END
		
	CASE CurrCol = COL$PSN
	
		IF PSNo NE '' THEN
		
			* Display the Prod Spec Window
			
			obj_AppWindow('ViewRelated','PROD_SPEC':@RM:PSNo)
			IF Get_Status(errCode) THEN
				ErrMsg(errCode)
			END
		
		END
	
	
	CASE 1
	
		NULL
		
END CASE
	
RETURN




* * * * * * *
ShipDC:
* * * * * * *

CtrlEntID = @WINDOW:'.SHIPMENTS'

WONo = Get_Property(@WINDOW,'ID')

CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

ShipNo = Get_Property(CtrlEntID,'CELLPOS',1:@FM:CurrRow)

IF WONo NE '' AND ShipNo NE '' THEN
	IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
		Send_Event(@WINDOW,'WRITE')
	END
	
	DetWindow	= 'COC'
	DetKeys		= ShipNo
	DefaultRec	= ''
	RetKey		= WONo
	RetPage		= 4
	RetCtrl		= CtrlEntID
	RetPos		= CurrPos
	
	oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

	obj_AppWindow('ViewNewDetail',oAParms)
	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
	
END

RETURN

* * * * * * *
Reorder:
* * * * * * *

CtrlEntID = @WINDOW:'.CASS_NO'

RelStamp = Get_Property(@WINDOW:'.REL_STAMP','TEXT')

IF RelStamp NE '' THEN
	Message = 'Work order has been released to production.||Cassettes may only be renumbered prior to release'
	ErrMsg('Cassette Reorder Process':@SVM:Message)
	RETURN
END

OrgCassList = Get_Property(CtrlEntId,'LIST')

IF OrgCassList<1,1> = '' THEN RETURN

BlankLineCnt = 0
LOOP
	LastLine = OrgCassList[-1,'B':@FM]			;* [] Operation sets COL1() and COL2()
UNTIL LastLine<1,1> NE '' OR LastLine = ''
	OrgCassList[COL1(),COL2()] = ''				;* Strip trailing blank lines from edit table controls
	BlankLineCnt += 1
REPEAT

ListCnt = COUNT(OrgCassList,@FM) + (OrgCassList NE '')

CONVERT @VM TO @SVM IN OrgCassList
CONVERT @FM TO @VM IN OrgCassList

TypeOver = ''
TypeOver<PDISPLAY$> = OrgCassList

ReSelect:

SortedCassList = Popup(@WINDOW,TypeOver,'WO_CASSETTE_SORT')
IF SortedCassList = '' OR SortedCassList = CHAR(27) THEN RETURN

IF Get_Status(errCode) THEN ErrMsg(errCode)

ResultCnt = COUNT(SortedCassList,@FM) + (SortedCassList NE '')

IF ResultCnt NE ListCnt THEN
	Message = 'All cassettes must be selected in the order they are to be processed.'
	ErrMsg('Cassette Reorder Process':@SVM:Message)
	GOTO ReSelect
END

FOR I = 1 TO ResultCnt
	SortedCassList<I,1> = I
NEXT I

BlankLines = STR(STR(@VM,6):@FM,BlankLineCnt)
SortedCassList<-1> = BlankLines

SortedCassList[-1,1] = ''	;* Trailing @FM

Set_Property(CtrlEntID,'LIST',SortedCassList)

Comm_WO_Log('Refresh')

RETURN


* * * * * * *
CassDC:
* * * * * * *

CtrlEntID = @WINDOW:'.CASS_NO'

WONo = Get_Property(@WINDOW,'ID')

IF WONo = '' THEN RETURN

CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>


BEGIN CASE
	CASE CurrCol = COL$CASS_ID_SAP
		CassID = Get_Property(CtrlEntID,'CELLPOS',COL$CASS_ID_SAP:@FM:CurrRow)
		
		BEGIN CASE
		
			CASE CassID = '' ; RETURN
			
			CASE INDEX(CassID,'.',1)
			
				WMOutKey = CassID[1,'.']:'*1*':CassID[COL2()+1,'.']
				
				DetWindow	= 'WM_OUT'
				DetKeys		= WMOutKey
				DefaultRec	= ''
				RetKey		= WONo
				RetPage		= 2
				RetCtrl		= CtrlEntID
				RetPos		= CurrPos
				
				oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

				obj_AppWindow('ViewNewDetail',oAParms)
				IF Get_Status(errCode) THEN
					ErrMsg(errCode)
				END
			
			CASE NUM(CassID)
				RDSNo = CassID

				IF RDSNo NE '' THEN

					Set_Property(@WINDOW,'@RETURN_FROM_RDS',WONo)		;* Bullshit lashup to work with multiple RDS windows

					thisFormName = 'RDS'
					
					thisFormWindowUp = Get_Property(thisFormName,'VISIBLE')	;* Returns 0 = hidden, 1 = visible, 2 = minimized, 3 = maximized 

					IF thisFormWindowUp = ''	THEN
                        If Get_Property('NDW_MAIN', 'VISIBLE') then
                            AppMain = 'NDW_MAIN'
                        end else
                            AppMain = 'LSL_MAIN2'
                        end
						Start_Window(thisFormName,AppMain,RDSNo:'*CENTER', '', '')	;* Put up the card window
						
						RETURN
					END
					
					IF thisFormWindowUp = 2		THEN Set_Property(thisFormName,'VISIBLE',9)	;* Restore the window if minimized

					IF Get_Property(thisFormName,'SAVEWARN') THEN
						Send_Event(thisFormName,'CLEAR')					;* Clear anything existing (prompts for save first)
					END
					
				END
			
			
			

		END CASE
		
			
	CASE 1
		CassNo = Get_Property(CtrlEntID,'CELLPOS',COL$CASS_NO:@FM:CurrRow)
		IF CassNo = '' THEN RETURN
		
		WOMatKey = WONo:'*':CassNo

		IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
			Send_Event(@WINDOW,'WRITE')
		END
		
		DetWindow	= 'WO_MAT'
		DetKeys		= WONo:'*':CassNo
		DefaultRec	= ''
		RetKey		= WONo
		RetPage		= 2
		RetCtrl		= CtrlEntID
		RetPos		= CurrPos
		
		oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

		obj_AppWindow('ViewNewDetail',oAParms)
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END
		

END CASE


RETURN


* * * * * * *
CassInsert:
* * * * * * * 

CtrlName = @WINDOW:'.CASS_NO'

RowNo = Parm1

Void = Send_Message(CtrlName,'DELETE',RowNo)

RETURN



* * * * * * *
CassDelete:
* * * * * * *

CtrlName = @WINDOW:'.CASS_NO'

RowNo	= Parm1
RowData	= Parm2

Dummy = Send_Message(CtrlName, 'INSERT', RowNo, RowData)


RETURN















