COMPILE FUNCTION obj_Vision(Method,Parms)

/*
	Methods for Interfacing with Vision via the IFS
    
	05/12/2005 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    GetOrder()						;* GetOrder from buffer
    
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, Dialog_Box, obj_WO_Log, NextKey, obj_Shipment
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, ErrMsg, Set_Property, obj_Order, Yield, Clear_Table
DECLARE SUBROUTINE obj_Order_Recon,Send_Info, Send_Event, Post_Event, obj_Notes


$INSERT MSG_EQUATES
$INSERT ORDER_EQU
$INSERT ORDER_DET_EQU
$INSERT WO_LOG_EQU
$INSERT WO_STEP_EQU
$INSERT XO_EQUATES
$INSERT QUOTE_SIGS_EQU
$INSERT RDS_EQU
$INSERT COMPANY_EQU
$INSERT COC_EQU
$INSERT NOTIFICATION_EQU

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

EQU ORDIN$ORDER_NO				TO 1
EQU ORDIN$ORD_ITEM_NO			TO 2
EQU ORDIN$ORD_ITEM_STATUS		TO 3
EQU ORDIN$BILL_TO_CUST_NO		TO 4
EQU ORDIN$SHIP_TO_CUST_NO		TO 5
EQU ORDIN$CUST_PO_NO			TO 6
EQU ORDIN$EPI_PART_NO			TO 7
EQU ORDIN$PART_TYPE				TO 8
EQU ORDIN$CUST_PART_NO			TO 9
EQU ORDIN$ORD_ITEM_QTY			TO 10
EQU ORDIN$ORD_ITEM_SHIP_QTY		TO 11
EQU ORDIN$ORD_ITEM_NET_QTY		TO 12
EQU ORDIN$ORD_ITEM_UNIT_PRICE	TO 13
EQU ORDIN$ORD_ITEM_EXT_PRICE	TO 14
EQU ORDIN$ORD_ITEM_PROMISE_DT	TO 15
EQU ORDIN$ORD_ITEM_REQ_SHIP_DT	TO 16
EQU ORDIN$ORD_ITEM_CALC_SWO_DT	TO 17
EQU ORDIN$ORD_ITEM_CUST_REQ_DT	TO 18
EQU ORDIN$ORD_ITEM_ATP			TO 19
EQU ORDIN$INV_NO				TO 20
EQU ORDIN$INV_LINE				TO 21
EQU ORDIN$CUST_SHIP_TO_NAME		TO 22

ErrTitle = 'Error in Stored Procedure "obj_Vision"'
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 = 'GetInbound'		; GOSUB GetInbound
	CASE Method = 'AddTransaction'	; GOSUB AddTransaction
	CASE Method = 'SendOutbound'	; GOSUB SendOutbound
	CASE Method = 'CustOnHold'		; GOSUB CustOnHold
	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


* * * * * * *
AddTransaction:
* * * * * * * 

TransAction 	= Parms[1,@RM]

IF TransAction = '' 	THEN RETURN

IF TransAction = 'PROMISE_DT' THEN
	VisionOrderNo	= Parms[COL2()+1,@RM]
	VisionLineNos	= Parms[COL2()+1,@RM]
	NewPromiseDt	= Parms[COL2()+1,@RM]

	IF VisionOrderNo = ''	THEN RETURN
	IF VisionLineNos = ''	THEN RETURN
	IF NewPromiseDt = ''	THEN RETURN


	thisNewPromiseDt = ICONV(NewPromiseDt,'D')
	IF thisNewPromiseDt = '' THEN
		ErrorMsg = 'Invalid parameter "NewPromiseDt" ':QUOTE(NewPromiseDt):' passed to routine. (':Method:')'
		RETURN
	END
	
	TransRec = TransAction:@FM:VisionOrderNo:@FM:VisionLineNos:@FM:thisNewPromiseDt
	
END

IF TransAction = 'SHIPMENT' THEN
	ShipScript = Parms[COL2()+1,@RM]
	IF ShipScript = '' THEN RETURN
	
	TransRec = Transaction:@FM:ShipScript
	
END

NextTransNo = NextKey('VISION_COMM')

oTParms = 'VISION_COMM':@RM:NextTransNo:@RM:@RM:TransRec
obj_Tables('WriteRec',OtParms)

RETURN


* * * * * * *
GetInbound:
* * * * * * *

* Check directory for presence of tables.

FileNames = ''

Path = 'Z:\'
InitDir Path:'*.*'

LOOP
  List = DirList()
UNTIL List = ""
	LOOP
		FileName = List[1,@FM]
		List[1,Col2()] = ""
		IF FileName[1,3] = 'ME1' THEN
			LOCATE FileName IN FileNames BY 'AR' USING @FM SETTING Pos ELSE
				FileNames = INSERT(FileNames,Pos,0,0,FileName)
			END
		END
	UNTIL List = ""
	REPEAT
REPEAT

IF FileNames[-1,1] = @FM THEN FileNames[-1,1] = ''
Test = ''
FileCnt = COUNT(FileNames,@FM) + (FileNames NE '')


FOR I = 1 TO FileCnt
	Send_Info('Processing ':I:' of ':FileCnt)
	FileName = FileNames<I>
	StartTime = Time()
	OSREAD FileIn FROM Path:FileName THEN
	
		SWAP TAB$ WITH @VM IN FileIn
		SWAP CRLF$ WITH @FM IN FileIn
		
		IF FileName[-1,1] = 'R' THEN
			
			Clear_Table('ORDER_RECON')
			TimeStamp = ICONV(OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTHS'),'DT')
			
			LineCnt = COUNT(FileIn,@FM) + (FileIn NE '')
			FOR N = 1 TO LineCnt
				Set_Property('VISION_COMM.STATUSLINE_FIX','TEXT','Processing File ':I:' of ':FileCnt:' Line ':N)
				LineIn = FileIn<N>
				
				GOSUB ParseOrderLine
				
				Parms  = TimeStamp:@RM
				Parms := VisionOrderNo:@RM
				Parms := VisionItemNo:@RM
				Parms := ItemStatus:@RM
				Parms := BillToCustNo:@RM
				Parms := ShipToCustNo:@RM
				Parms := CustPONo:@RM
				Parms := EpiPartNo:@RM
				Parms := PartType:@RM
				Parms := CustPartNo:@RM
				Parms := ItemQty:@RM
				Parms := ItemShipQty:@RM	
				Parms := ItemNetQty:@RM					;* Not used
				Parms := ItemUnitPrice:@RM
				Parms := ItemExtPrice:@RM				;* Not used
				Parms := OCONV(ItemPromiseDt,'D'):@RM
				Parms := OCONV(ItemReqShipDt,'D'):@RM
				Parms := OCONV(ItemCalcSWODt,'D'):@RM
				Parms := OCONV(ItemCRD,'D'):@RM			
				Parms := ItemQuoteNo:@RM
				Parms := CustName:@RM
				Parms := VisionInvoiceNo:@RM
				Parms := VisionInvoiceItem
				
				obj_Order_Recon('ReconOrder',Parms)
			
			NEXT N
			
			Recipients		= XLATE('NOTIFICATION','ORDER_ENTRY',NOTIFICATION_USER_ID$,'X')
			SentFrom		= "obj_Vision"
			Subject			= 'Reconciliation Report Received '
			Message			= 'Daily Reconciliation Download Received from Vision at ':OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTHS')
			AttachWindow	= ''
			AttachKey		= ''
			SendToGroup		= ''   

			Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
			obj_Notes('Create',Parms)
			
		END ELSE
		
			LineIn = FileIn
			
			Set_Property('VISION_COMM.STATUSLINE_FIX','TEXT','Processing File ':I:' of ':FileCnt)
			
			GOSUB ParseOrderLine
			
			Parms  = VisionOrderNo:@RM
			Parms := VisionItemNo:@RM
			Parms := ItemStatus:@RM
			Parms := BillToCustNo:@RM
			Parms := ShipToCustNo:@RM
			Parms := CustPONo:@RM
			Parms := EpiPartNo:@RM
			Parms := PartType:@RM
			Parms := CustPartNo:@RM
			Parms := ItemQty:@RM
			Parms := ItemShipQty:@RM	
			Parms := ItemNetQty:@RM					;* Not used
			Parms := ItemUnitPrice:@RM
			Parms := ItemExtPrice:@RM				;* Not used
			Parms := OCONV(ItemPromiseDt,'D'):@RM
			Parms := OCONV(ItemReqShipDt,'D'):@RM
			Parms := OCONV(ItemCalcSWODt,'D'):@RM
			Parms := OCONV(ItemCRD,'D'):@RM			
			Parms := ItemQuoteNo:@RM
			Parms := CustName:@RM
			Parms := VisionInvoiceNo:@RM
			Parms := VisionInvoiceItem
			
			obj_Order('PostVision',Parms)
			
		END
		
		OSDELETE Path:FileName
	
		ErrCode = Status()
		IF ErrCode = 2 THEN
			Set_Property('VISION_COMM', "TIMER", '0')
			Send_Event('VISION_COMM.START_STOP_BUTTON','CLICK')
			ErrorMsg  = 'Vision Communications has failed.||'
			ErrorMsg := 'Delete the':Path:FileName:' file and|'
			ErrorMsg := 'then restart the communications server.' 
			ErrMsg(ErrorMsg)
			Post_Event('VISION_COMM','CLOSE')
			RETURN
		END 
		
		
	END ELSE
		NULL
	END
NEXT I

Set_Property('VISION_COMM.STATUSLINE_FIX','TEXT','')
RETURN


* * * * * * *
SendOutbound:
* * * * * * *

OPEN 'VISION_COMM' TO Buffer THEN
	SELECT Buffer
	Done = 0
	LOOP
		READNEXT SeqNo ELSE Done = 1
	UNTIL Done
		READ Transaction FROM Buffer,SeqNo THEN
			TransType = Transaction<1>
			Transaction = DELETE(Transaction,1,0,0)
			
			BEGIN CASE
				CASE TransType = 'PROMISE_DT'
					GOSUB PromiseDt
				
				CASE TransType = 'SHIPMENT'
					Send_Info('VISION_COMM Record: ':SeqNo)
					GOSUB Shipment
				
				CASE TransType = 'ORDER_QTY'
					* Future
				CASE 1
			END CASE
			
			IF ClearFlag = 1 THEN
				DELETE Buffer,SeqNo ELSE Null
			END
		END
		
	REPEAT
END ELSE
	ErrorMsg = 'Unable to open "VISION_COMM" for transmission'
	RETURN
END

RETURN



* * * * * * *
PromiseDt:
* * * * * * *

VisionOrderNo = Transaction[1,@FM]
VisionLineNos = Transaction[COL2()+1,@FM]
NewPromiseDt  = Transaction[COL2()+1,@FM]

IF VisionOrderNo = ''	THEN ErrorMsg = 'Null parameter "VisionOrderNo" passed to routine. (':Method:')'
IF VisionLineNos = ''	THEN ErrorMsg = 'Null parameter "VisionLineNos" passed to routine. (':Method:')'
IF NewPromiseDt = '' 	THEN ErrorMsg = 'Null parameter "NewPromiseDt" passed to routine. (':Method:')'


IF ErrorMsg NE '' THEN RETURN

ClearFlag = 1

* Open up the connection and dataset to Vision

Set_Status(0)

hXO = XOInstance('VISION_TEST','ODBC','EPIDWNLD','EPIDWNLD','','','')

IF NOT(hXO) THEN
	ErrorMsg = 'Unable to Get Vision Connection Object Handle.'
	stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
	ClearFlag = 0
	RETURN
END
	
SendScript = ''
FOR I = 1 TO COUNT(VisionLineNos,@VM) + (VisionLineNos NE '')
	VisionLineNo = VisionLineNos<1,I>
	hQry = QryInstance(hXO)
	
	IF NOT(hQRY) THEN
		ErrorMsg = 'Unable to Get Vision Connection Object Handle.'
		stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
		ClearFlag = 0
		GOTO CloseConnection
	END

	SelectScript  = 'select '
	SelectScript := 'SLCO, SLWHS, SLSRCO, SLSRWH, SLONO, SLRLNO, SLLNNO, SLPTNO, SLSTCN, SLORQY, SLCRDT, SLRVDT, SLPRDT'

	SelectScript := " from VUSPD.OPI100L1"
	SelectScript := " where SLLNST <> 'C'"
	SelectScript := " and SLONO = '":VisionOrderNo:"'"
	SelectScript := " and SLLNNO = '":VisionLineNo:"'"

		
	RowData = ''

	flag = QryMethod(hQry,QRY_EXECUTE$,SelectScript)
	flag = QryMethod(hQry,QRY_GETERROR$,'','','','',ErrText)

	IF flag THEN
		ErrorMsg = 'Unable to Execute QRY_EXECUTE$.':CRLF$:ErrText
		stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
		ClearFlag = 0
		GOTO CloseConnection
		
	END

	LOOP

		flag = QryMethod(hQry,QRY_GETROW$, RowData)
		flag = QryMethod(hQry,QRY_GETERROR$,'','','','',ErrText)

		IF flag THEN
			SWAP @SVM WITH '-' IN ErrText
			ErrorMsg = 'Unable to Execute QRY_GETROW$.':CRLF$:ErrText
			stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
			stat = QryMethod(hQry,QRY_DESTROY$)
			ClearFlag = 0
			GOTO CloseConnection
			
		END
		
	UNTIL RowData = ''
		
		SBCO	= RowData<1>
		SBWHS	= RowData<2>
		SBSRCO	= RowData<3>
		SBSRWH	= RowData<4>
		SBORNO	= RowData<5>
		SBRLNO	= RowData<6>
		SBLNNO	= RowData<7>
		SBPTNO	= RowData<8>
		SBCSTN	= RowData<9>
		SBQDUE	= RowData<10>
		SBORDT	= RowData<11>
		SBSWOD	= RowData<12>
		SBOPSD	= RowData<13>		;* Old Promise Ship Date
		SPNPSD	= RowData<14>		;* New Promise Ship Date
		
		thisNewPromiseDt = OCONV(NewPromiseDt,'D4/')
		
		Month	= thisNewPromiseDt[1,'/']
		Day		= thisNewPromiseDt[COL2()+1,'/']
		Year	= (thisNewPromiseDt[COL2()+1,'/']) - 28		;* The - 28 adjust the date for the AS400/vision dates
		Year	= Year[-2,2]								;* Take the last two characters of the year
		
 		SPNPSD = Year:Month:Day
 		SBFL1  = '  '
 		
 		ScriptLine	= "insert into VUS1CNV.OPI300UF VALUES( ' ', "
		ScriptLine := "'":SBCO:"', "
		ScriptLine := "'":SBWHS:"', "
		ScriptLine := "'":SBSRCO:"', "
		ScriptLine := "'":SBSRWH:"', "
		ScriptLine := "'":SBORNO:"', "
		ScriptLine := SBRLNO:", "
		ScriptLine := SBLNNO:", "
		ScriptLine := "'":SBPTNO:"', "
		ScriptLine := "'":SBCSTN:"', "
		ScriptLine := SBQDUE:", "
		ScriptLine := SBORDT:", "
		ScriptLine := SBSWOD:", "
		ScriptLine := SBOPSD:", "		;* Old Promise Ship Date
		ScriptLine := SPNPSD:", "		;* New Promise Ship Date
 		ScriptLine := "'":SBFL1:"')"	;* Reason Code
 		
  		SendScript<-1> = ScriptLine
 				
		
	REPEAT
	stat = QryMethod(hQry,QRY_DESTROY$)
	
NEXT I	;* End of Vision Line number processing

FOR I = 1 TO COUNT(SendScript,@FM) + (SendScript NE '')

	ScriptLine = SendScript<I>
	
	hQry = QryInstance(hXO)
	
	IF NOT(hQRY) THEN
		ErrorMsg = 'Unable to Get Vision Connection Object Handle.'
		stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
		ClearFlag = 0
		GOTO CloseConnection
		RETURN
	END

	flag = QryMethod(hQry,QRY_EXECUTE$,ScriptLine)
	flag = QryMethod(hQry,QRY_GETERROR$,'','','','',ErrText)
	
	IF flag THEN
		SWAP @SVM WITH '-' IN ErrText
		ErrorMsg = 'Unable to Execute QRY_EXECUTE$.':CRLF$:ErrText
		stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
	END
	
	stat = QryMethod(hQry,QRY_DESTROY$)
NEXT I


* * * *
CloseConnection:
* * * * 

stat = XOMethod(hXO,XO_DESTROY$)


RETURN



* * * * * * *
Shipment:
* * * * * * *

SendScripts	= Transaction

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

IF ErrorMsg NE '' THEN RETURN

ClearFlag = 1									;* This will clear the VISION_COMM record if everything completes OK.

Set_Status(0)

*hXO = XOInstance('VISION_TEST','ODBC','USTEST','USTEST','','','')
hXO = XOInstance('VISION_TEST','ODBC','EPIDWNLD','EPIDWNLD','','','')

IF NOT(hXO) THEN
	ErrorMsg = 'Unable to Get Vision Connection Object Handle.'
	stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
	ClearFlag = 0
	RETURN
END

LOOP
	SendScript = SendScripts<1,1>	
	
	hQry = QryInstance(hXO)
	
	IF NOT(hQRY) THEN
		ErrorMsg = 'Unable to Get Vision Connection Object Handle.'
		stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
		ClearFlag = 0
		GOSUB CloseConnection
		RETURN
	END

	flag = QryMethod(hQry,QRY_EXECUTE$,SendScript)
	flag = QryMethod(hQry,QRY_GETERROR$,'','','','',ErrText)
	
	IF flag THEN
		Values	= FIELD(SendScript,'(',2)
		ShipNo	= TRIM(FIELD(Values,',',3))
		OrderNo	= TRIM(FIELD(Values,',',4))
		LineNo	= TRIM(FIELD(Values,',',5))
		
		SWAP @SVM WITH '-' IN ErrText
		
		ErrRecord = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS'):' Shipment: ':ShipNo:'  Order: ':OrderNo:' Line No: ':LineNo:'  ':ErrText
				
		GOSUB LogAS400Error
		
		stat = QryMethod(hQry,QRY_DESTROY$)
		
		GOSUB CloseConnection
		
		RETURN
	END
	SendScripts = DELETE(SendScripts,1,1,0)			;* Delete the first row
	
	stat = QryMethod(hQry,QRY_DESTROY$)
	
UNTIL SendScripts = ''
REPEAT

GOSUB CloseConnection

RETURN


* * * * * * *
CheckPartial:
* * * * * * *

*DEAD
RETURN

IF SendScripts = '' THEN
	ClearFlag = 1
END ELSE
	OPEN 'VISION_COMM' TO FileOut THEN
		SendScripts = 'SHIPMENT':@FM:SendScripts
		WRITE SendScripts ON FileOut,SeqNo ELSE Null		;* Place the remaining unsent items back into the buffer
	END
	ClearFlag = 0
END
GOSUB CloseConnection

RETURN


* * * * * * *
CustOnHold:
* * * * * * *


RETURN
* Not yet in production

VisionCustNo	= Parms[1,@RM]
VisionOrderNo	= Parms[COL2()+1,@RM]
VisionLineNos	= Parms[COL2()+1,@RM]


IF VisionCustNo = '' 	THEN ErrorMsg = 'Null parameter "VisionCustNo" passed to routine. (':Method:')'
IF VisionOrderNo = ''	THEN ErrorMsg = 'Null parameter "VisionOrderNo" passed to routine. (':Method:')'
IF VisionLineNos = ''	THEN ErrorMsg = 'Null parameter "VisionLineNos" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN

* Open up the connection and dataset to Vision

Set_Status(0)

hXO = XOInstance('VISION_TEST','ODBC','ERPTEST','ERPTEST','','','')

IF NOT(hXO) THEN
	ErrorMsg = 'Unable to Get Vision Connection Object Handle.'
	stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
	RETURN
END

hQry = QryInstance(hXO)

IF NOT(hQRY) THEN
	ErrorMsg = 'Unable to Get Vision Connection Object Handle.'
	stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
	GOTO CloseConnection
END

SelectScript  = "select GHCROP from VUSDD.OP31PF where GHSTCN = '":VisionCustNo:"'"

flag = QryMethod(hQry,QRY_EXECUTE$,SelectScript,'',ResultsAvail)
flag = QryMethod(hQry,QRY_GETERROR$,'','','','',ErrText)

IF flag THEN
	ErrorMsg = 'Unable to Execute QRY_EXECUTE$.':CRLF$:ErrText
	stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
	stat = QryMethod(hQry,QRY_DESTROY$)
	GOTO CloseConnection
END

flag = QryMethod(hQry,QRY_GETROW$, RowData)
flag = QryMethod(hQry,QRY_GETERROR$,'','','','',ErrText)

IF flag THEN
	ErrorMsg = 'Unable to Execute QRY_GETROW$.':CRLF$:ErrText
	stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
	stat = QryMethod(hQry,QRY_DESTROY$)
	GOTO CloseConnection
END

stat = QryMethod(hQry,QRY_DESTROY$)	;* Done with this query

IF RowData NE '' THEN

	* Customer is on Hold, now check for line level exceptions
	
	Result = 1
	
	FOR I = 1 TO COUNT(VisionLineNos,@VM) + (VisionLineNos NE '')
		
		VisionLineNo = VisionLineNos<1,I>
		
		hQry = QryInstance(hXO)
		
		IF NOT(hQRY) THEN
			ErrorMsg = 'Unable to Get Vision Connection Object Handle.'
			stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
			GOTO CloseConnection
		END
		
		SelectScript  = "select EOLNNO from VUSDD.OP32TF where EOCO = '001' and EOWHS = 'ES1' and EOONO = '":VisionOrderNo:"' and EOLNNO = ":VisionLineNo

		flag = QryMethod(hQry,QRY_EXECUTE$,SelectScript,'',ResultsAvail)
		flag = QryMethod(hQry,QRY_GETERROR$,'','','','',ErrText)
		
		IF flag THEN
			ErrorMsg = 'Unable to Execute QRY_EXECUTE$.':CRLF$:ErrText
			stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
			stat = QryMethod(hQry,QRY_DESTROY$)
			GOTO CloseConnection
		END
						
		flag = QryMethod(hQry,QRY_GETROW$, RowData)
		flag = QryMethod(hQry,QRY_GETERROR$,'','','','',ErrText)

		IF flag THEN
			ErrorMsg = 'Unable to Execute QRY_GETROW$.':CRLF$:ErrText
			stat = Set_Status(1,'STPROC',ErrTitle:@SVM:ErrorMsg)
			stat = QryMethod(hQry,QRY_DESTROY$)
			GOTO CloseConnection
		END
		
		IF RowData NE '' THEN
		
			* Customer is on hold AND there is an exception in one of the lines passed in
			Result = ''
			stat = QryMethod(hQry,QRY_DESTROY$)
			GOTO CloseConnection
		END
		
	NEXT I
	
	stat = QryMethod(hQry,QRY_DESTROY$)
		
END	;* End of Check for customer on hold
	
GOTO CloseConnection
RETURN


* * * * * * * * * * * * * * * * * * * * * * *
* Private Methods
* * * * * * * * * * * * * * * * * * * * * * *

* * * * * * *
ParseOrderLine:
* * * * * * *

VisionOrderNo		= LineIn<1,ORDIN$ORDER_NO>
VisionItemNo		= LineIn<1,ORDIN$ORD_ITEM_NO>
ItemStatus			= LineIn<1,ORDIN$ORD_ITEM_STATUS>
BillToCustNo		= LineIn<1,ORDIN$BILL_TO_CUST_NO>
ShipToCustNo		= LineIn<1,ORDIN$SHIP_TO_CUST_NO>
CustPONo			= LineIn<1,ORDIN$CUST_PO_NO>
EpiPartNo			= LineIn<1,ORDIN$EPI_PART_NO>
PartType			= LineIn<1,ORDIN$PART_TYPE>
CustPartNo			= LineIn<1,ORDIN$CUST_PART_NO>
ItemQty				= LineIn<1,ORDIN$ORD_ITEM_QTY>
ItemShipQty			= LineIn<1,ORDIN$ORD_ITEM_SHIP_QTY>
ItemNetQty			= LineIn<1,ORDIN$ORD_ITEM_NET_QTY>
ItemUnitPrice		= OCONV(ICONV(LineIn<1,ORDIN$ORD_ITEM_UNIT_PRICE>,'MD2'),'MD2')
ItemExtPrice		= LineIn<1,ORDIN$ORD_ITEM_EXT_PRICE>
ItemPromiseDt		= ICONV(LineIn<1,ORDIN$ORD_ITEM_PROMISE_DT>,'[VISION_DT_FORMAT]')		;* Now in internal OI format
ItemReqShipDt		= ICONV(LineIn<1,ORDIN$ORD_ITEM_REQ_SHIP_DT>,'[VISION_DT_FORMAT]')		;* Now in internal OI format
ItemCalcSWODt		= ICONV(LineIn<1,ORDIN$ORD_ITEM_CALC_SWO_DT>,'[VISION_DT_FORMAT]')		;* Now in internal OI format
ItemCRD				= ICONV(LineIn<1,ORDIN$ORD_ITEM_CUST_REQ_DT>,'[VISION_DT_FORMAT]')		;* Now in internal OI format

*ItemQuoteNo			= LineIn<1,ORDIN$ORD_ITEM_ATP>

TestQuoteNo = EpiPartNo[4,'-']
	
IF NUM(TestQuoteNo) THEN
	ItemQuoteNo		= ABS(TestQuoteNo)					;* Epi part Nos look like EPI1234 or EPI1234-SRP or EPI1234-MISC
END ELSE
	ItemQuoteNo		= ''
END	

VisionInvoiceNo		= LineIn<1,ORDIN$INV_NO>
VisionInvoiceItem	= LineIn<1,ORDIN$INV_LINE>
CustName			= LineIn<1,ORDIN$CUST_SHIP_TO_NAME>

RETURN


* * * * * * *
LogAS400Error:
* * * * * * *

OPEN 'SYSLISTS' TO ListsFile THEN
	READ ErrFile FROM ListsFile,'VISION_COMM_ERROR' ELSE ErrFile = ''
	
	NewLineCnt = COUNT(ErrRecord,@FM) + (ErrRecord NE '')
	
	FileLineCnt = COUNT(ErrFile,@FM) + (ErrFile NE '')
	IF FileLineCnt > 500 THEN
		FOR I = FileLineCnt TO (FileLineCnt - NewLineCnt) STEP -1
			ErrFile = DELETE(ErrFile,1,I,0)
		NEXT I
	END
	
	ErrFile = INSERT(ErrFile,1,1,0,ErrRecord)
	WRITE ErrFile ON ListsFile,'VISION_COMM_ERROR' ELSE NULL
	ErrRecord = ''
END

RETURN
