COMPILE SUBROUTINE Print_SAP_Cass_Ship_Label( WONo,WOSteps,CassNos,RDSNos,RDSType )
#pragma precomp SRP_PreCompiler

/*
Complete Rewrite SAP changes 7/26/2011 by John C. Henry, J.C. Henry & Co., Inc.
DPC 12/5/19 - removed thickness and resistivity from SAP shipping label per Matt T.
DPC 3/11/21 - changed RevLvl to pull from CUST_EPI_PART instead of PROD_SPEC
DPC 1/12/22 - with help of Daniel at SRP, changed some print functions to allow defaulting printer
*/

$INSERT LOGICAL
$INSERT MSG_EQUATES
$INSERT RDS_EQU

$INSERT PROD_VER_EQUATES
$INSERT OIPRINT_EQUATES
$INSERT PROD_SPEC_EQU
$INSERT PRS_LAYER_EQU
$INSERT WO_LOG_EQUATES
$INSERT WO_STEP_EQU
$INSERT WO_MAT_EQUATES
$INSERT WM_OUT_EQUATES
$INSERT ORDER_EQU
$INSERT ORDER_DET_EQU
$INSERT REACTOR_EQUATES
$INSERT REACT_RUN_EQUATES
$INSERT COMPANY_EQUATES
$INSERT CUST_EPI_PART_EQUATES
$Insert EPI_PART_EQUATES

DECLARE FUNCTION	Msg, Get_Printer, Set_Printer, obj_Prod_Spec, obj_Vendor_Code, Logging_Services, Unassigned, Obj_Wo_Mat	
DECLARE FUNCTION	Get_Status, Utility, Printer_Select, obj_Install, Environment_Services, Direct_Print
Declare function    GaN_Services, Error_Services
DECLARE SUBROUTINE	Set_Status, Msg, errMsg, obj_Zebra105SL, Logging_Services, Direct_Print, Sap_Services

EQU PI$LEFT		TO	1
EQU PI$TOP		TO  2
EQU PI$RIGHT	TO	3
EQU PI$BOTTOM	TO	4
EQU PI$WIDTH	TO 	5
EQU PI$HEIGHT	TO	6
EQU PI$SIZE		TO	7

Main:

	ErrorMsg = ''

	IF NOT(ASSIGNED(WONo))		THEN ErrorMsg = 'Unassigned parameter "WONo" passed to PRINT_CASS_SHIP_LABEL routine.'
	IF NOT(ASSIGNED(WOSteps))	THEN ErrorMsg = 'Unassigned parameter "WOSteps" passed to PRINT_CASS_SHIP_LABEL routine.'
	IF NOT(ASSIGNED(CassNos))	THEN ErrorMsg = 'Unassigned parameter "CassNos" passed to PRINT_CASS_SHIP_LABEL routine.'
	IF NOT(ASSIGNED(RDSNos))	THEN ErrorMsg = 'Unassigned parameter "RDSNos" passed to PRINT_CASS_SHIP_LABEL routine.'

	LogPath         = Environment_Services('GetApplicationRootPath') : '\LogFiles\Zebra'
	LogDate         = Oconv(Date(), 'D4/')
	LogTime         = Oconv(Time(), 'MTS')
	LogFileName     = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '.csv'
	Headers         = 'Logging DTM' : @FM : 'Description'
	ColumnWidths    = 20 : @FM : 300
	objLog          = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)

	LogPath        = Environment_Services('GetApplicationRootPath') : '\LogFiles\Spectrum'
	LogDate        = Oconv(Date(), 'D4/')
	LogTime        = Oconv(Time(), 'MTS')
	LogFileName    = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '.csv'
	Headers        = 'Logging DTM' : @FM : 'Description'
	ColumnWidths   = 20 : @FM : 300
	objSpectrumLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)

	LoggingDTM      = LogDate : ' ' : LogTime   ; // Logging DTM

	IF ErrorMsg NE '' THEN
		ErrMsg(ErrorMsg)
		RETURN
	END	

	PrinterID = ''
	
	* Initialize the printer
	FileName  = "Printing Label"
	Title     = "Printing Label"	;* Initialize Printing

	PageInfo			= ''
	PageInfo<PI$LEFT>	= 0.1
	PageInfo<PI$TOP>	= 0.1
	PageInfo<PI$RIGHT>	= 0.1
	PageInfo<PI$BOTTOM>	= 0.1

	PageSetup          = '1' 							;* Landscape
	PrintSetup         = '0'							;* Print to specific location
	PrintPath          = Printer_Select(PrinterID);* Select printer - Displays popup if PrinterPort not found
	PrintPathLog       = PrintPath

	Swap @FM with '@FM' in PrintPathLog
	Swap @VM with '@VM' in PrintPathLog
	Swap @SVM with '@SVM' in PrintPathLog
	Swap @TM with '@TM' in PrintPathLog
	Swap @STM with '@STM' in PrintPathLog
	Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @User4 : ' - PrintPath = ' : PrintPathLog, @RM, @FM)

	IF PrintPath = '' THEN
		Def = ""
		Def<MTYPE$> = "TA3"
		Def<MTEXT$> = 'Destination Printer not Selected..'
		Def<MCAPTION$> = ''
		Def<MICON$> = '*'
		Msg(@WINDOW, Def, '')
		RETURN
	END

	If Environment_Services('GetLabelPrintMethod') _EQC 'OIPI' then
		stat = Set_Printer("INIT",FileName,Title,PageInfo,PageSetup,PrintSetup,PrintPath)
	end else
		stat = Direct_Print('START', PrintPath<1>, '', '')
	end
	IF stat < 0 THEN GOSUB OIPrint_Err			;* Bail = couldn't initialize the printer

	If Unassigned(RDSType) then RDSType = ''

	IF RDSType EQ '' then
		ReactNos		= XLATE('REACT_RUN',RDSNos,REACT_RUN_REACTOR$,'X')										;* Added 12/16/2008 - JCH - Adding Reactor Type codes to cassette labels
		ReactTypes		= OCONV(XLATE('REACTOR',ReactNos,REACTOR_REACT_TYPE$,'X'),'[REACT_TYPE_CONV,OPSREF]')	;* Added 12/16/2008 - JCH - Adding Reactor Type codes to cassette labels
	end else
		ReactTypes		= RDSType
	end

	WORec			= XLATE('WO_LOG',WONo,'','X')

	WoLogReqShipDt	= OCONV( WORec<WO_LOG_PROMISE_SHIP_DT$>, 'D2/' )
	WoLogDMShipDt	= OCONV( WORec<WO_LOG_PROMISE_SHIP_DT$>, 'DE' )
	WoLogCustPONo	= WORec<WO_LOG_CUST_PO_NO$>
	WoLogEpiPartNo	= WORec<WO_LOG_EPI_PART_NO$>
	WoLogCustNo		= WORec<WO_LOG_CUST_NO$>

	ProdOrdNo		= WORec<WO_LOG_PROD_ORD_NO$>
	ProdVerNo		= WORec<WO_LOG_PROD_VER_NO$>
	ProdVerRec		= XLATE('PROD_VER',ProdVerNo,'','X')
		
	CompRec			= XLATE('COMPANY',WoLogCustNo,'','X')

	Captive			= CompRec<COMPANY_CAPTIVE$>
	VendCd			= CompRec<COMPANY_VEND_CD$>	
	CustName		= CompRec<COMPANY_CO_NAME$>

	IF ProdOrdNo NE '' THEN
		IF WoLogCustPONo = 'NA' OR WoLogCustPONo = '' THEN
			PONo = ProdOrdNo
		END ELSE
			PONo = WoLogCustPONo
		END
		OrderItems = ''
		VisionOrderNo = ''
		VisionLineNos = ''
	END

	CassCnt = COUNT(CassNos,@VM) + (CassNos NE '')

	FOR I = 1 TO CassCnt

		WOStep		= WOSteps<1,I>
		ProdSpecID	= XLATE('WO_STEP',WONo:'*':WOStep,WO_STEP_PROD_SPEC_ID$,'X')
		RevLvl		= XLATE('CUST_EPI_PART',WoLogCustNo:'*':WoLogEpiPartNo,CUST_EPI_PART_SPEC_REV$,'X')[-1,'B':@VM]	;* use rev from Cust Epi Part, not PSN
		CassNo		= CassNos<1,I>
		RDSNo		= RDSNos<1,I>
		ReactType	= Xlate('WO_MAT', WONo:'*':CassNo,'REACTOR_TYPE','X')
		WOMatRec	= XLATE('WO_MAT',WONo:'*':CassNo,'','X')
		ReShipCust  = WOMatRec<WO_MAT_RESHIP_CUST_NO$>
		If ReShipCust EQ '' then
			CustNo  = WoLogCustNo
		end else
			CustNo  = ReShipCust
		end
		CompRec		= XLATE('COMPANY',CustNo,'','X')
		Captive		= CompRec<COMPANY_CAPTIVE$>
		VendCd		= CompRec<COMPANY_VEND_CD$>
		CustName    = CompRec<COMPANY_CO_NAME$>
		ReShipDate  = WOMatRec<WO_MAT_RESHIP_DT$>
		If ReShipDate EQ '' then
			ReqShipDt	= OCONV( WORec<WO_LOG_PROMISE_SHIP_DT$>, 'D2/' )
			DMShipDt	= OCONV( WORec<WO_LOG_PROMISE_SHIP_DT$>, 'DE' )
		end else
			ReqShipDt	= OCONV( ReShipDate, 'D2/' )
			DMShipDt	= OCONV( ReShipDate, 'DE' )
		end
		ReShipCustEpiPartNo = WOMatRec<WO_MAT_RESHIP_CUST_EPI_PART_NO$>
		If ReShipCustEpiPartNo EQ '' then
			EpiPartNo   = WoLogEpiPartNo
		end else
			EpiPartNo   = ReShipCustEpiPartNo
		end
		ReShipCustPO    = WOMatRec<WO_MAT_RESHIP_CUST_PO$>
		If ReShipCustPO EQ '' then
			CustPONo    = WoLogCustPONo
		end else
			CustPONo    = ReShipCustPO
		end
		IF CustPONo = 'NA' OR CustPONo = '' THEN
			PONo = ProdOrdNo
		END ELSE
			PONo = CustPONo
		END
		ReShipEpiPartNo = WOMatRec<WO_MAT_RESHIP_CUST_EPI_PART_NO$>
		SAPBatchNo      = WOMatRec<WO_MAT_SAP_BATCH_NO$>
		
		SubSupplier	= obj_Vendor_Code('SemiToEpi',WOMatRec<WO_MAT_SUB_VEND_CD$>)
		
		IF VendCd NE '' THEN SubSupplier = VendCd		;* Override from Company Table.

		Begin Case
			Case (RDSNo NE '' AND RDSType EQ 'SIC') OR (RDSNo NE '' AND ReactType<1,I> NE 'EPP' AND ReactType<1,I> NE 'GAN') ;* regular Epi

				CassIDLabel = 'RDSNo:      '
				CassID		= RDSNo
				ReactType = ReactTypes<1,I>
				
				MakeupBox		= WOMatRec<WO_MAT_MAKEUP_BOX$>
				PartNo			= XLATE('WO_LOG',WONo,WO_LOG_EPI_PART_NO$,'X')
				If ReShipEpiPartNo NE '' then
					PartNo  = ReShipEpiPartNo
				end
				LotNo			= WOMatRec<WO_MAT_LOT_NO$>
				SubstrPartNo	= WOMatRec<WO_MAT_SUB_PART_NO$>
				
				IF SubstrPartNo[-2,2] _EQC '.S' THEN SubstrPartNo = ''
				
				CassOrderItem	= WOMatRec<WO_MAT_ORDER_ITEM$>	
				
				IF ProdVerNo = '' THEN
					CustPNDesc = XLATE( 'ORDER_DET',WONo:'*':CassOrderItem,'CUST_PN_DESC','X')
				END ELSE
					CustPNDesc = XLATE('PROD_VER',ProdVerNo,PROD_VER_CUST_PART_DESC$,'X')
				END
				
				SupVerify		= XLATE( 'RDS', RDSNo, 'SUP_VER_SIG_NAME', 'X' )
				SupVerifyDt		= OCONV(XLATE('WO_MAT',WONo:'*':CassNo,'SHIP_SUP_VER_SIG_DT','X'),'D2/')
				WfrsOut			= XLATE( 'RDS', RDSNo, 'WFRS_OUT', 'X' )
				MUWfrsRemQty	= XLATE( 'RDS', RDSNo, 'MU_WFRS_REMOVED','X' )
				MUWfrsAddQty	= XLATE( 'RDS', RDSNo, 'MU_WFRS_ADDED','X' )
				
				ResultThickL1   = OCONV( XLATE( 'REACT_RUN', RDSNo, 'TTHICK_AVG', 'X' ), 'MD2' )
				ResultThickL2	= OCONV( XLATE( 'REACT_RUN', RDSNo, 'TTHICK_AVG_L2', 'X' ), 'MD2' )
				ResultThickL3	= OCONV( XLATE( 'REACT_RUN', RDSNo, 'TTHICK_AVG_L3', 'X' ), 'MD2' )
				
				TargetThickL1	= OCONV( XLATE( 'REACT_RUN', RDSNo, 'THICK_TARGET', 'X' ), 'MD2' )
				TargetThickL2	= OCONV( XLATE( 'REACT_RUN', RDSNo, 'THICK_TARGET_L2', 'X' ), 'MD2' )
				TargetThickL3	= OCONV( XLATE( 'REACT_RUN', RDSNo, 'THICK_TARGET_L3', 'X' ), 'MD2' )
				
				IF ResultThickL1 = '' THEN ResultThickL1 = TargetThickL1
				IF ResultThickL2 = '' THEN ResultThickL2 = TargetThickL2
				IF ResultThickL3 = '' THEN ResultThickL3 = TargetThickL3		
						   
				ThickUnitsL1    = XLATE( 'REACT_RUN', RDSNo, 'THICK_UNITS', 'X' )
				ThickUnitsL2    = XLATE( 'REACT_RUN', RDSNo, 'THICK_UNITS_L2', 'X' )
				ThickUnitsL3    = XLATE( 'REACT_RUN', RDSNo, 'THICK_UNITS_L3', 'X' )
				
				ResultThick = ResultThickL1
				IF ResultThickL2 NE '' THEN ResultThick := '/':ResultThickL2
				IF ResultThickL3 NE '' THEN ResultThick := '/':ResultThickL3
				
				IF ResultThick NE '' THEN ResultThick := ThickUnitsL1
				
				ResultResL1		= XLATE( 'REACT_RUN', RDSNo, 'TRES_AVG', 'X' )
				ResultResL2		= XLATE( 'REACT_RUN', RDSNo, 'TRES_AVG_L2', 'X' )
				ResultResL3		= XLATE( 'REACT_RUN', RDSNo, 'TRES_AVG_L3', 'X' )
				
				TargetResL1		= OCONV( XLATE( 'REACT_RUN', RDSNo, 'RES_TARGET', 'X' ), 'MD3' )   
				TargetResL2		= OCONV( XLATE( 'REACT_RUN', RDSNo, 'RES_TARGET_L2', 'X' ), 'MD3' )
				TargetResL3		= OCONV( XLATE( 'REACT_RUN', RDSNo, 'RES_TARGET_L3', 'X' ), 'MD3' )

				IF ResultResL1	= '' THEN ResultResL1 = TargetResL1
				IF ResultResL2	= '' THEN ResultResL2 = TargetResL2
				IF ResultResL3	= '' THEN ResultResL3 = TargetResL3
				
				ResUnitsL1		= XLATE( 'REACT_RUN', RDSNo, 'RES_UNITS', 'X' )
				ResUnitsL2		= XLATE( 'REACT_RUN', RDSNo, 'RES_UNITS_L2', 'X' )
				ResUnitsL3		= XLATE( 'REACT_RUN', RDSNo, 'RES_UNITS_L3', 'X' )
				
				ResultRes = ResultResL1
				
				IF ResultResL2 NE '' THEN ResultRes := '/':ResultResL2
				IF ResultResL3 NE '' THEN ResultRes := '/':ResultResL3
				
				IF ResultRes NE '' THEN ResultRes := ResUnitsL1
				
				ResultResMin	= XLATE( 'REACT_RUN', RDSNo, 'TRES_MIN', 'X' )
				ResultResMax	= XLATE( 'REACT_RUN', RDSNo, 'TRES_MAX', 'X' )
				
				TargetConL1		= OCONV( XLATE( 'REACT_RUN', RDSNo, 'CON_TARGET', 'X' )<1,1>, 'MS21' )
				TargetConL2		= OCONV( XLATE( 'REACT_RUN', RDSNo, 'CON_TARGET_L2', 'X' ), 'MS21' )
				TargetConL3		= OCONV( XLATE( 'REACT_RUN', RDSNo, 'CON_TARGET_L3', 'X' ), 'MS21' )

				ConUnitsL1		= XLATE( 'REACT_RUN', RDSNo, 'CON_UNITS', 'X' )
				ConUnitsL2		= XLATE( 'REACT_RUN', RDSNo, 'CON_UNITS_L2', 'X' )
				ConUnitsL3		= XLATE( 'REACT_RUN', RDSNo, 'CON_UNITS_L3', 'X' )
				
				ResultCon = TargetConL1
				IF TargetConL2 NE '' THEN ResultCon := '/':TargetConL2
				IF TargetConL3 NE '' THEN ResultCon := '/':TargetConL3
				IF ResultCon NE '' THEN ResultCon := ConUnitsL1
				
			Case (ReactType EQ 'EPP') or (ReactType EQ 'P') ; * EpiPro

				WMOutKey = WONo:'*':WOStep:'*':CassNo
				WMOutRec = XLATE('WM_OUT',WMOutKey,'','X')
				
				MakeupBox = WMOutRec<WM_OUT_MAKEUP_BOX$>
				
				CassIDLabel = 'WMONo:      '
				CassID		= WMOutKey
				
				CONVERT '*' TO '.' IN CassID
				
				ReactType = 'EpiPro'										;* * * * 12/17/2008 Harded coded reactor type for EpiPro reactors
				
				SupVerify		= WMOutRec<WM_OUT_SUP_VER_SIG$>
				SupVerifyDt		= OCONV(XLATE('WO_MAT',WONo:'*':CassNo,'SHIP_SUP_VER_SIG_DT','X'),'D2/')
				
				InCassNo1		= ''
				InSlotNo1		= ''
				MUWoNo1			= ''
				MUCassNo1		= ''
				MUSlotNo1		= ''
				
				PartNo 			= ''
				LotNo			= ''
				SubstrPartNo	= ''
				CassOrderItem	= ''
				CustPNDesc		= ''
				
				Pointer = 1
				LOOP
					IF WMOutRec<WM_OUT_MU_WO_NO$,Pointer> = '' THEN
						InCassNo1	= WMOutRec<WM_OUT_IN_CASS_NO$,Pointer>
						InSlotNo1	= WMoutRec<WM_OUT_IN_SLOT_NO$,Pointer>
					END ELSE
						IF MUWoNo1 = '' THEN
							MUWoNo1		= WMOutRec<WM_OUT_MU_WO_NO$,Pointer>
							MUCassNo1	= WMOutRec<WM_OUT_MU_CASS_NO$,Pointer>
							MUSlotNo1	= WMOutRec<WM_OUT_MU_SLOT_NO$,Pointer>
						END
					END
					
				UNTIL InCassNo1 NE '' OR Pointer > 25
				
					Pointer += 1
				REPEAT
				
				IF InCassNo1 NE '' THEN
					WOMatRec        = XLATE('WO_MAT',WONo:'*':InCassNo1,'','X')
					PartNo			= XLATE('WO_LOG',WONo,WO_LOG_CUST_PART_NO$,'X')
					LotNo			= WOMatRec<WO_MAT_LOT_NO$>
					SubstrPartNo	= WOMatRec<WO_MAT_SUB_PART_NO$>
					
				END ELSE
					IF MUWoNo1 NE '' AND MUCassNo1 NE '' THEN
						MUWOMatRec      = XLATE('WO_MAT',MUWoNo1:'*':MUCassNo1,'','X')
						PartNo			= XLATE('WO_LOG',MUWoNo1,WO_LOG_CUST_PART_NO$,'X')
						LotNo			= MUWOMatRec<WO_MAT_LOT_NO$>
						SubstrPartNo	= MUWOMatRec<WO_MAT_SUB_PART_NO$>
						
					END
				END
				If ReShipEpiPartNo NE '' then
					PartNo  = ReShipEpiPartNo
				end
				WfrsOut			= XLATE('WM_OUT',WMOutKey,'WFRS_OUT','X')
				MUWfrsRemQty	= ''
				MUWfrsAddQty	= ''
			
				Specs = obj_Prod_Spec('GetLayerProp',ProdSpecID)
				
				ResultThick		= ''
				ResultRes		= ''
				ResultResMin	= ''
				ResultResMax	= ''
				ResultCon		= ''
				
				LayerCount = COUNT(Specs,@RM) + (Specs NE '')
				
				FOR Layer = 1 TO LayerCount
				
					LayerSpecs = FIELD(Specs,@RM,Layer)
					LayerSpecs = FIELD(LayerSpecs,@FM,2,99)			;* Pull of the layer set ID
					
					IF LayerSpecs<PRS_LAYER_THICK_TARGET$> NE '' THEN
						ResultThick := LayerSpecs<PRS_LAYER_THICK_TARGET$>
					END
					
					IF LayerSpecs<PRS_LAYER_RES_TARGET$> NE '' THEN
						ResultRes		:= LayerSpecs<PRS_LAYER_RES_TARGET$>
						ResultResMin	:= LayerSpecs<PRS_LAYER_RES_MIN$>
						ResultResMax	:= LayerSpecs<PRS_LAYER_RES_MAX$>
					END
					
					IF LayerSpecs<PRS_LAYER_CONC_TARGET$> NE '' THEN
						ResultCon	:= LayerSpecs<PRS_LAYER_CONC_TARGET$>
					END
					
					IF Layer < LayerCount THEN
						IF ResultThick NE ''	THEN ResultThick	:= '/'
						IF ResultRes NE ''		THEN ResultRes		:= '/'
						IF ResultResMin NE ''	THEN ResultResMin	:= '/'
						IF ResultResMax NE ''	THEN ResultResMax	:= '/'
						IF ResultCon NE ''		THEN ResultCon		:= '/'
					END ELSE
						IF ResultThick NE ''	THEN ResultThick	:= LayerSpecs<PRS_LAYER_THICK_UNITS$>
						IF ResultRes NE ''		THEN ResultRes		:= LayerSpecs<PRS_LAYER_RES_UNITS$>
						IF ResultResMin NE ''	THEN ResultResMin	:= LayerSpecs<PRS_LAYER_RES_UNITS$>
						IF ResultResMax NE ''	THEN ResultResMax	:= LayerSpecs<PRS_LAYER_RES_UNITS$>
						IF ResultCon NE ''		THEN ResultCon		:= LayerSpecs<PRS_LAYER_CONC_UNITS$>
					END
					
				NEXT Layer
			
			Case ReactType EQ 'GAN'
				
				WOMatKey = WONo:'*':CassNo
				MakeupBox = False$
				CassIDLabel = 'WOMatNo:      '
				CassID		= WOMatKey
				MUWfrsAddQty = 0
				
				SupVerify		= WOMatRec<WO_MAT_CASS_FINAL_SIG$>
				SupVerifyDt		= WOMatRec<WO_MAT_CASS_FINAL_SIG_DTM$>
				
				InCassNo1		= ''
				InSlotNo1		= ''
				MUWoNo1			= ''
				MUCassNo1		= ''
				MUSlotNo1		= ''
				
				PartNo 			= ''
				LotNo			= ''
				SubstrPartNo	= ''
				CassOrderItem	= ''
				CustPNDesc		= ''
									   
				IF InCassNo1 NE '' THEN
					WOMatRec        = XLATE('WO_MAT',WONo:'*':InCassNo1,'','X')
					PartNo			= XLATE('WO_LOG',WONo,WO_LOG_EPI_PART_NO$,'X')
					LotNo			= WOMatRec<WO_MAT_LOT_NO$>
					SubstrPartNo	= WOMatRec<WO_MAT_SUB_PART_NO$>
					
				END ELSE
					IF MUWoNo1 NE '' AND MUCassNo1 NE '' THEN
						MUWOMatRec      = XLATE('WO_MAT',MUWoNo1:'*':MUCassNo1,'','X')
						PartNo			= XLATE('WO_LOG',MUWoNo1,WO_LOG_EPI_PART_NO$,'X')
						LotNo			= MUWOMatRec<WO_MAT_LOT_NO$>
						SubstrPartNo	= MUWOMatRec<WO_MAT_SUB_PART_NO$>
						
					END
				END
				If ReShipEpiPartNo NE '' then
					PartNo  = ReShipEpiPartNo
				end
			   
				//WfrsOut = Count(Xlate('WO_MAT_WFR', WOMatKey, 'OUT_WFR_ID', 'X'), @VM)
				WfrsOut = obj_WO_Mat('CurrWaferCnt',WOMatKey)
		   
				Specs = obj_Prod_Spec('GetLayerProp',ProdSpecID)
				
				ResultThick		= ''
				ResultRes		= ''
				ResultResMin	= ''
				ResultResMax	= ''
				ResultCon		= ''
				
				LayerCount = COUNT(Specs,@RM) + (Specs NE '')
			  
				FOR Layer = 1 TO LayerCount
				
					LayerSpecs = FIELD(Specs,@RM,Layer)
					LayerSpecs = FIELD(LayerSpecs,@FM,2,99)			;* Pull of the layer set ID
					
					IF LayerSpecs<PRS_LAYER_THICK_TARGET$> NE '' THEN
						ResultThick := LayerSpecs<PRS_LAYER_THICK_TARGET$>
					END
					
					IF LayerSpecs<PRS_LAYER_RES_TARGET$> NE '' THEN
						ResultRes		:= LayerSpecs<PRS_LAYER_RES_TARGET$>
						ResultResMin	:= LayerSpecs<PRS_LAYER_RES_MIN$>
						ResultResMax	:= LayerSpecs<PRS_LAYER_RES_MAX$>
					END
					
					IF LayerSpecs<PRS_LAYER_CONC_TARGET$> NE '' THEN
						ResultCon	:= LayerSpecs<PRS_LAYER_CONC_TARGET$>
					END
					
					IF Layer < LayerCount THEN
						IF ResultThick NE ''	THEN ResultThick	:= '/'
						IF ResultRes NE ''		THEN ResultRes		:= '/'
						IF ResultResMin NE ''	THEN ResultResMin	:= '/'
						IF ResultResMax NE ''	THEN ResultResMax	:= '/'
						IF ResultCon NE ''		THEN ResultCon		:= '/'
					END ELSE
						IF ResultThick NE ''	THEN ResultThick	:= LayerSpecs<PRS_LAYER_THICK_UNITS$>
						IF ResultRes NE ''		THEN ResultRes		:= LayerSpecs<PRS_LAYER_RES_UNITS$>
						IF ResultResMin NE ''	THEN ResultResMin	:= LayerSpecs<PRS_LAYER_RES_UNITS$>
						IF ResultResMax NE ''	THEN ResultResMax	:= LayerSpecs<PRS_LAYER_RES_UNITS$>
						IF ResultCon NE ''		THEN ResultCon		:= LayerSpecs<PRS_LAYER_CONC_UNITS$>
					END
					
				NEXT Layer
		End Case
		
		IF ProdVerNo NE '' THEN
			// The CassIDLabel has already been determined at this point.  It can either be "RDSNo:" or "WMONo:".
			// However, for some reason, it has always been overridden to be "CassID:".
			// Except that QA is now requesting to not override the cassette label string for the NXP (7124) customer.
			If (CustNo NE '7124') then
				CassIDLabel = 'CassID:     '
			end
		END
		
		IF PartNo = '' THEN
			PartNo = EpiPartNO
		END

		GOSUB PrintLabel
		PrintSpectrumLabel    = False$
		EpiPartNo             = XLATE('WO_LOG', WONo, WO_LOG_EPI_PART_NO$, 'X')
		CustReshipPartNo      = XLATE('WO_MAT', WONo : '*' : CassNo, WO_MAT_RESHIP_CUST_EPI_PART_NO$, 'X')
		If CustReshipPartNo EQ '' then
			GenerateSpectrumLabel = XLATE('EPI_PART', EpiPartNo, EPI_PART_GENERATE_SPECTRUM_LABEL$, 'X')
		end else
			GenerateSpectrumLabel = XLATE('EPI_PART', CustReshipPartNo, EPI_PART_GENERATE_SPECTRUM_LABEL$, 'X')
		end
		PrintSpectrumLabel = GenerateSpectrumLabel AND (Indexc(PrintPath, 'MESZBRPRT011', 1) OR Indexc(PrintPath, 'MESZBRPRT004', 1))
		If PrintSpectrumLabel then
			Sap_Services('PrintSpectrumLabel', WONo, WOStep, CassNo)
			If Error_Services('NoError') then
				LogData       = ''
				LogData<1, 1> = LoggingDTM
				LogData<1, 2> = 'Successfully sent .sik file to Spectrum file share. WO#' : WONo : ', Cass# ' : CassNo
				Logging_Services('AppendLog', objSpectrumLog, LogData, @FM, @VM)
			end else
				ErrorMessage  = Error_Services('GetMessage')
				LogData       = ''
				LogData<1, 1> = LoggingDTM
				LogData<1, 2> = 'Failed to send .sik file to Spectrum file share. WO#' : WONo : ', Cass# ' : CassNo :'. ' : ErrorMessage
				Logging_Services('AppendLog', objSpectrumLog, LogData, @FM, @VM)
			end
		end
		
	NEXT I


* * * * * * *
OIPrint_Err:
* * * * * * *

	* Local method to kill the OIPI engine
	If Environment_Services('GetLabelPrintMethod') _EQC 'OIPI' then
		stat = Set_Printer("TERM")
	end else
		stat = Direct_Print('STOP')
	end

RETURN


* * * * * * * *
PrintLabel:
* * * * * * * *

	Convert '*' to '.' in CassID

	MULabel = ''
	IF MakeupBox	= 1	THEN MULabel = '** Makeup Box **'
	IF MUWfrsAddQty > 0 THEN MULabel = 'Merged Lot'
	  
	SuppCd		= SubSupplier
	ErrorMsg	= ''

	IF LEN(PartNo) > 18		THEN ErrorMsg = 'CustPartNo parameter exceeds 18 characters.'
	IF LEN(RevLvl) > 3		THEN ErrorMsg = 'RevLvl parameter exceeds 3 characters.'
	IF LEN(WfrsOut) > 6		THEN ErrorMsg = 'PartQty parameter exceeds 6 characters.'
	IF NOT(NUM(WfrsOut))	THEN ErrorMsg = 'PartQty parameter is not a number.'

	IF ErrorMsg THEN
		ErrMsg(ErrorMsg)
	END ELSE
		* Good to go on the label print
		If Environment_Services('GetLabelPrintMethod') _EQC 'OIPI' then
			stat = Set_Printer('TEXT',ImageData)	;* Download bitmap image to the printer
		end else
			stat = Direct_Print('PRINT', ImageData)
		end
		* Label is 812 x 608 dots at 8dots/mm (203 dots/inch)
		* Leave periodic spaces in Label String - OIPrint interface wraps text on spaces and will cut off 
		* the LabelString if there aren't any spaces.  Printer Width needs to be set to 132 or greater

		LabelString  = '^XA'				;* Start of label format
		LabelString := '^LH15,50'			;* Label home offset (needed to get onto the label medium)
		LabelString := '^BY3'				;* Set narrow Bar Code line width to 3 dots
		LabelString := '^PR2'				;* Print speed = 2 IPS

		LabelString := '^FO0,156^GB809,0,3,B^FS':@FM	;* 'Top' of 4x3 Label
		LabelString := '^FO0,308^GB809,0,3,B^FS':@FM	;* 1st 'horizontal' line (bottom of 1st cell)
		LabelString := '^FO0,460^GB809,0,3,B^FS':@FM	;* 2nd 'horizontal' line (bottom of 2nd cell)

		* Block 1 Left (Cust Part)
		LabelString := '^FO0,10^A0,25^FDCust Part (P):^FS':CRLF$			;* Label Line 1
		LabelString := '^FO15,45^A0,50,40^FD':PartNo:'^FS':CRLF$			;* Readable
		LabelString := '^FO15,95^BY2^BC,60,N^FDP':PartNo:'^FS':CRLF$		;* Code 128
		LabelString := '^BY3,3.0':CRLF$

		* Block 1 Right (Rev Lvl)
		LabelString := '^FO508,0^BY2^B3,,60,N^FD2P':RevLvl:'^FS':CRLF$		;* Code 39
		LabelString := '^BY3,3.0':CRLF$
		LabelString := '^FO508,70^A0,25^FDRev.Level (2P):^FS':CRLF$			;* Label Line 1
		LabelString := '^FO680,70^A0,50,48^FD':RevLvl:'^FS':CRLF$			;* Readable

		* Block 2 Left (Quantity)
		LabelString := '^FO0,165^A0,25^FDQuantity (Q):^FS':CRLF$			;* Label Line 1
		LabelString := '^FO15,195^A0,50,40^FD':WfrsOut:'^FS':CRLF$			;* Readable
		LabelString := '^FO15,245^BY2^B3,,60,N^FDQ':WfrsOut:'^FS':CRLF$		;* Code 39
		LabelString := '^BY3,3.0':CRLF$

		LabelString := '^FO250,275^A0,25^FDReact Type:^FS':CRLF$				
		LabelString := '^FO380,275^A0,25^FD':ReactType:'^FS':CRLF$				
		
		LabelString := '^FO500,123^A0,25^FDReq Ship Dt:^FS':CRLF$				
		LabelString := '^FO635,123^A0,36^FD':ReqShipDt:'^FS':CRLF$				

		//Data Matrix Barcode Content
		IF CustNo = '7053' THEN
			* Tower Specific 
			//DPC - 2/10/20 - added '1B' prefix and SAPBatchNo per Matt T. request
			//DPC - 3/11/20 - replaced 1T LotNo with SAPBatchNo per Matt T. request
			BCContent  = 'P'	: PartNo			:';'		;* Cust Part No
			BCContent := '2T'	: CassID			:';'		;* CassID (Epi Lot Number)
			BCContent := '1B'	: SAPBatchNo		:';'		;* SAP Batch ID		
			BCContent := '1R'	: ResultResMin		:';'		;* Res Min
			BCContent := '2R'	: ResultResMax		:';'		;* Res Max
			BCContent := 'Q' 	: WfrsOut			:';'		;* Qty
			BCContent := '1V'	: 'IR'				:';'		;* Vendor Code
			BCContent := '6D'	: DMShipDt			:';'		;* Req Ship Date
			BCContent := '32T'	: EpiPartNo						;* EpiPartNo
		END ELSE
			* All other customers
			BCContent  = 'P'	: PartNo		:';'		;* Cust Part No
			BCContent := '2T'	: RevLvl		:';'		;* Rev Level
			BCContent := '1T'	: CassID		:';'		;* Cass ID (Lot Number)
			BCContent := '1R'	: ResultThick	:';'		;* Thk Avg
			BCContent := '2R'	: ResultRes		:';'		;* Res Avg
			BCContent := '3R'	: ResultCon		:';'		;* Conc
			BCContent := 'Q' 	: WfrsOut		:';'		;* Qty
			BCContent := '1V'	: SuppCD		:';'		;* Vendor Code
			BCContent := '6D'	: DMShipDt		:';'		;* Req Ship Date
			BCContent := '32T'	: CustName					;* Customer Name		
		END
		
		LabelString := '^FO600,178^BXN,3,200^FD':BCContent:'^FS'	;* Test Data Matrix bar code
			
		* Block 3 Left (Customer Lot)
		LabelString := '^FO0,315^A0,25^FDCustomer Lot :^FS':CRLF$				;* Label Line 1
		LabelString := '^FO15,350^A0,50,40^FD':LotNo:'^FS':CRLF$				;* Readable
		LabelString := '^FO15,400^BY2^B3,,60,N^FD':LotNo:'^FS':CRLF$			;* Code 39		
		LabelString := '^BY3,3.0':CRLF$

		* Block 3 Right (Supplier)
		LabelString := '^FO510,320^A0,,40^FDIFX Epi Services^FS':CRLF$			;* Added Text for 'IFX Epi Services * * * * * * * * * *
		
		IF SuppCd NE '' THEN
			
			LabelString := '^FO590,430^A0,25^FDSupp Cd (1V):^FS':CRLF$			;* Label Line - Added 8/17/2005 JCH Supplier Code Info
			LabelString := '^FO740,430^A0,36,40^FD':SuppCd:'^FS':CRLF$			;* Readable
			
			LabelString := '^FO590,370^BY2^B3,,50,N^FD1V':SuppCd:'^FS':CRLF$	;* Code 39 Supplier Code - This bar code is in line 1	;*Changed ^FD' to ^FD1V' - dkk 7/27/15
			LabelString := '^BY3,3.0':CRLF$
		END	
		
		* Block 4 1st Line Left
		LabelString := '^FO0,470^A0,25^FDCustomer:^FS':CRLF$					;* Label Line
		LabelString := '^FO120,470^A0,45,25^FD':CustName:'^FS':CRLF$			;* Readable
		
		* Block 4 1st Line Right
		IF MULabel NE '' THEN
			LabelString := '^FO550,470^A0,40^FD':MULabel:'^FS':CRLF$
		END
		
		* Block 4 2nd Line 
		If CustNo EQ '6874' then												;* for Newport, include the 1T prefix
			LabelString := '^FO0,515^A0,25^FD':'(1T)':CassIDLabel :'^FS':CRLF$	;* Label Line
			LabelString := '^FO130,515^A0,36,40^FD':CassID:'^FS':CRLF$			 
			LabelString := '^FO340,515^BY2^B3,,40,N^FD':'1T':CassID:'^FS':CRLF$	 
		end else
			LabelString := '^FO0,515^A0,25^FD':CassIDLabel :'^FS':CRLF$			;* Label Line
			LabelString := '^FO130,515^A0,36,40^FD':CassID:'^FS':CRLF$			;* Readable
			LabelString := '^FO340,515^BY2^B3,,40,N^FD':CassID:'^FS':CRLF$		;* Code 39 (This is the Cass ID)	;*Changed ^FD' to ^FD1T' - dkk 7/30/15
		end
		
		LabelString := '^BY3,3.0':CRLF$
		
		* Block 4 3rd Line
		IF ProdVerNo NE '' THEN
			* SAP 
			LabelString := '^FO0,570^A0,25^FDBatch:^FS':CRLF$					;* Label Line
			LabelString := '^FO130,570^A0,36^FD':SAPBatchNo:'^FS':CRLF$			;* Readable * SAP Batch No *
			LabelString := '^FO340,570^BY2^B3,,40,N^FD':SAPBatchNo:'^FS':CRLF$	;* Code 39 (This is the Cass ID)
			LabelString := '^BY3,3.0':CRLF$
			
		END
		
		* Block 4 5th Line
		LabelString := '^FO0,620^A0,25^FDPO No:^FS':CRLF$						;* Label Line	
					
		IF LEN(PONo) > 11 THEN
			LabelString := '^FO80,620^A0,25,20^FD':PONo:'^FS':CRLF$				;* Readable * Production Order *  Squeezed
		END ELSE
			LabelString := '^FO80,620^A0,25,40^FD':PONo:'^FS':CRLF$				;* Readable * Production Order *
		END

		LabelString := '^FO300,620^A0,25^FDWO No:^FS':CRLF$						;* Label Line
		LabelString := '^FO380,620^A0,25^FD':WONo:'^FS':CRLF$					;* Readable
		LabelString := '^FO490,620^A0,25^FDEPI Part:^FS':CRLF$					;* Label Line
		LabelString := '^FO590,620^A0,25^FD':EpiPartNo:'^FS':CRLF$	
		
		* Block 4
		IF SAPBatchNo = '' THEN
			ConcLabelString = FMT(EpiPartNo,"L#15"):FMT(CassID,"L#12"):FMT(WfrsOut,"R#6")
		END ELSE
			ConcLabelString = EpiPartNo:' ':SAPBatchNo:' ':WfrsOut
		END
		
		LabelString := '^FO0,650^BY2^BC,90,N^FD':ConcLabelString:'^FS':CRLF$			;* Code 128 - original
		LabelString := '^XZ'
			
		If Environment_Services('GetLabelPrintMethod') _EQC 'OIPI' then
			stat = Set_Printer('TEXT',LabelString)
		end else
			stat = Direct_Print('PRINT', LabelString)
		end
	END	;* End of Check for good label data

RETURN

