COMPILE SUBROUTINE Print_Cass_Out( WMOutKeys, PrintOnly, PrintPath, PDFFileName, PrinterInitialized, HideUI)

$insert LOGICAL
$INSERT MSG_EQUATES
$INSERT RDS_EQU
$INSERT RDS_LAYER_INFO_EQU
$INSERT PROD_SPEC_EQU
$INSERT OIPRINT_EQUATES
$INSERT NCR_EQU
$INSERT POPUP_EQUATES
$INSERT COA

$INSERT RDS_TEST_EQUATES
$INSERT RDS_LAYER_EQUATES
$INSERT WO_LOG_EQUATES
$INSERT WO_STEP_EQU
$INSERT WO_MAT_EQUATES
$INSERT WM_OUT_EQUATES
$INSERT SURFACE_SCAN_EQUATES
$INSERT CUST_EPI_PART_EQUATES

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

EQU LTGREY$	TO 229 + (229*256) + (229*65536)

DECLARE FUNCTION FieldCount, Msg, Set_Printer, Get_Printer, obj_RDS_Test
DECLARE FUNCTION Printer_Select, obj_Install, obj_RDS
DECLARE SUBROUTINE extract_si_keys, record_lock, Btree.Extract

IF NOT(ASSIGNED(PrintPath))				THEN PrintPath = ''
IF NOT(ASSIGNED(PDFFileName))			THEN PDFFileName = ''
IF NOT(ASSIGNED(PrinterInitialized))	THEN PrinterInitialized = 0

If Assigned(HideUI) else HideUI = False$
If HideUI NE True$ then HideUI = False$

CassCnt = COUNT(WMOutKeys,@FM) + (WMOutKeys NE '')

WOStepKey	= FIELD(WMOutKeys<1,1>,'*',1,2)

WONo		= WOStepKey[1,'*']
WORec		= XLATE('WO_LOG',WONo,'','X')

CustNo		= WORec<WO_LOG_CUST_NO$>
CustName	= XLATE('COMPANY',CustNo,4,'X')

EpiPartNo	= WORec<WO_LOG_EPI_PART_NO$>

CleanRoomPaper = XLATE('CUST_EPI_PART',CustNo:'*':EpiPartNo,CUST_EPI_PART_CUST_RDS_CLEANROOM_PAPER$,'X')


PSNo = XLATE('WO_STEP',WOStepKey,WO_STEP_PROD_SPEC_ID$,'X')


IF CleanRoomPaper THEN
   MsgInfo = ''
   Mtext = "This customer's specification requires cleanroom paper RDSs":CrLf$:'Please place ':CassCnt:' piece(s) of cleanroom paper in the printer and then click OK'
   MsgInfo<mtext$> = Mtext
   MsgInfo<micon$> = '!'
   If HideUI EQ False$ then Void = msg( '', MsgInfo )
END


* * *   PRINT SETUP   * * *


FileName 	= 'Print Cassette Data Sheet'
Title		= 'Print Cassette Data Sheet'

PageInfo	= ''				; * Default is .5 inch margins and 8.5 x 11 paper
PageInfo<PI$LEFT>	= 0.5
PageInfo<PI$TOP>	= 1.5
PageInfo<PI$RIGHT>	= 0.5
PageInfo<PI$BOTTOM>	= 0.5
PageInfo<PI$SIZE>	= LETTER

MaxPrintLength = 11 - PageInfo<PI$TOP> - PageInfo<PI$BOTTOM>

PageSetup	= 0					;* 1 = Landscape mode
PrintSetup	= 0					;* 0 = No Preview, 2 = Preview

FOR BoxNo = 1 TO CassCnt
	WMOutKey = WMOutKeys<BoxNo>
	WMOutRec = XLATE('WM_OUT',WMOutKey,'','X')
	IF WMOutRec NE '' THEN

		IF NOT(PrinterInitialized) THEN

			PrintSetup	= ''
			PrintSetup<1,1>	= '2'	;* Specific Location
			PrintSetup<1,2> = '5'	;* Show Print and PDF, hide Print Setup
			PrintSetup<1,3>	= '0'	;* Show the printing window
			PDFParms = 'Printing PDF Document':@FM: '' :@FM:'':@FM: ''

			stat = Set_Printer( 'INIT', PDFParms, 'Run Data Sheet',PageInfo,PageSetup , PrintSetup)
			
		END ELSE
			stat = Set_Printer('PAGEBREAK')
		END

		GOSUB PrintSheet

		IF NOT(PrinterInitialized) THEN
			stat = Set_Printer( 'TERM' )
		END
	END
NEXT BoxNo

RETURN

* * * * * *
PrintSheet:
* * * * * *

font = 'Arial'		;* Font basics
font<2> = 10
font<4> = 0

stat = Set_Printer('FONTHEADFOOT', font)

font	= 'Arial'
font<2>	= '18'		;* Big type
font<4>	= 1			;* Bold on
font<5> = 1			;* Italics

stat = Set_Printer('TEXTXY','Cassette Data Sheet',2.20:@FM:-0.80,font,0)

font<2> = 12	;* Drop the font size
font<5> = 0		;* Italics off

IF NOT(PrinterInitialized) THEN
	stat = Set_Printer('FOOTER',"Page 'P'":@VM:@VM:"'T' 'D'")

	stat = Set_Printer('LINESTYLE', PS_SOLID:@FM:2)
	stat = Set_Printer('LINE', -0.1:@FM:-1.2:@FM:7.5:@FM:-1.2, 1)
	stat = Set_Printer('LINE', -0.1:@FM:-0.1:@FM:7.5:@FM:-0.1, 1)
	 
	location = -0.15:@fm:-1.150:@fm:1.57:@fm:1
	stat = Set_Printer('BMP',obj_Install('Get_Prop','ColorBMP'),location, 0,1)

	* * * *  Added 10/8/2015 JCH - Updated 'CONFIG','COMPANY'  * * * *

	InstDat		= obj_Install('Get_Prop','Company':@FM:'Division')
	Company		= InstDat<1>
	Division	= InstDat<2>
		
	font	= 'Arial'
	font<2>	= '12'		;* Big type
	font<4>	= 1			;* Bold on
	font<5> = 0			;* Italics

	stat = Set_Printer('TEXTXY',Company,5.7:@FM:-1.15,font,1)
	stat = Set_Printer('TEXTXY',Division,5.7:@FM:-0.970,font,1)

	font<2> = 10	;* 10 point font
	font<4> = 0		;* Bold off
	font<5> = 0		;* Italics Off

	stat = Set_Printer('TEXTXY',obj_Install('Get_Prop','Address'), 5.7:@fm:-0.775, font,1)
	stat = Set_Printer('TEXTXY',obj_Install('Get_Prop','CSZC'), 5.7:@fm:-0.625, font,1)
	stat = Set_Printer('TEXTXY','Tel:      ':obj_Install('Get_Prop','Phone'), 5.7:@fm:-0.475, font, 1)
	stat = Set_Printer('TEXTXY','FAX:    ':obj_Install('Get_Prop','FAX'), 5.7:@fm:-0.325, font, 1)

	* * * *  End of changes 10/8/2015 JCH  * * * *

	stat = Set_Printer('TEXT')

END


colHeader = 'Cassette ID'						; colFormat = '^1440'
colHeader<1,2> = 'WO No'						; colFormat<1,2> = '^1440'
colHeader<1,3> = 'WO Step'						; colFormat<1,3> = '^1440' 
colHeader<1,4> = 'Cass No'						; colFormat<1,4> = '^1440'
colHeader<1,5> = 'Customer'						; colFormat<1,5> = '<5040'


CassID = WMOutKey
CONVERT '*' TO '.' IN CassID

WONo	= WMOutKey[1,'*']
WOStep	= WMOutKey[COL2()+1,'*']
CassNo	= WMOutKey[COL2()+1,'*']

colData	= CassID
colData<1,2> = WONo
colData<1,3> = WOStep
colData<1,4> = CassNo
colData<1,5> = CustName


font<2> = 10
font<4> = 1		;* Bold on
stat = Set_Printer('FONT',font)
stat = Set_Printer('ADDTABLE',colFormat,colHeader,'',LTGREY$,'',0,TB_ALL)


font<2> = 10
font<4> = 0
stat = Set_Printer('FONT',font)

stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_ALL)

stat = Set_Printer('TEXT')


colHeader = ''							; colFormat = '^720'
colHeader<1,2> = 'Reactor'				; colFormat<1,2> = '^3240'
colHeader<1,3> = ''						; colFormat<1,3> = '^2700'
colHeader<1,4> = ''						; colFormat<1,4> = '^2700'
colHeader<1,5> = 'Material In'			; colFormat<1,5> = '^1440'

font<2> = 8
font<4> = 1		;* Bold on
stat = Set_Printer('FONT',font)
stat = Set_Printer('ADDTABLE',colFormat,colHeader,'',LTGREY$,'',0,TB_ALL)

colHeader = 'Slot'						; colFormat = '^720'
colHeader<1,2> = 'RDS'					; colFormat<1,2> = '^1080'
colHeader<1,3> = 'Pocket'				; colFormat<1,3> = '^1080'
colHeader<1,4> = 'Zone'					; colFormat<1,4> = '^1080'
colHeader<1,5> = 'Lot No'				; colFormat<1,5> = '^2700'
colHeader<1,6> = 'Part No'				; colFormat<1,6> = '^2700'
colHeader<1,7> = 'Cass'					; colFormat<1,7> = '^720'
colHeader<1,8> = 'Slot'					; colFormat<1,8> = '^720'


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

CassLoadQty = WORec<WO_LOG_OUT_CASS_LOAD_QTY$>
IF CassLoadQty = '' THEN CassLoadQty = 25

RDSNos			= WMOutRec<WM_OUT_RDS$>
ReactPockets	= WMOutRec<WM_OUT_POCKET$>
ReactZones		= WMOutRec<WM_OUT_ZONE$>
InCassNos		= WMOutRec<WM_OUT_IN_CASS_NO$>
InSlotNos		= WMOutRec<WM_OUT_IN_SLOT_NO$>
OutSlotNos		= WMOutRec<WM_OUT_SLOT_NO$>

LineCnt = 1
colData = ''

FOR I = 1 TO CassLoadQty

	InCassNo = InCassNos<1,I>
	WOMatRec = XLATE('WO_MAT',WONo:'*':InCassNo,'','X')		;* Changed from WO_Rec to WO_MAT 1/16/2008 JCH
	
	colData<I,1> = OutSlotNos<1,I>
	colData<I,2> = RDSNos<1,I>
	colData<I,3> = ReactPockets<1,I>
	colData<I,4> = ReactZones<1,I>
	colData<I,5> = WOMatRec<WO_MAT_LOT_NO$>
	colData<I,6> = WOMatRec<WO_MAT_CUST_PART_NO$>
	colData<I,7> = InCassNo
	colData<I,8> = InSlotNos<1,I>

NEXT I

stat = Set_Printer('ADDTABLE',colFormat,colHeader,'',LTGREY$,'',0,TB_ALL)

font<2> = 8
font<4> = 0		;* Bold off
stat = Set_Printer('FONT',font)
stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_ALL)
	

MakeupWaferFlag = 0

/*
*IF XLATE('RDS',RdsId,'MU_WFRS_ADDED','X') > 0 THEN
IF 1 = 0 THEN
	colData<3,4> = 0		;* Makeup wafers added
	MakeupWaferFlag = 1
END ELSE
	colData<3,4> = xlate( 'RDS', RdsId, 'TOT_REJ', 'X' )
	MakeupWaferFlag = 0
END

*/

stat = Set_Printer('TEXT')

SSTablesPos = Get_Printer('POS')
SSTablesY = SSTablesPos<2>

colHeader = 'Post Clean':CRLF$:'Light Point Defects'
colFormat = '^2160'
colData 	= WMOutRec<WM_OUT_LPD_POSTCLEAN$>

font<2> = 10
font<4> = 1		;* Bold on
stat = Set_Printer('FONT',font)
stat = Set_Printer('ADDTABLE',colFormat,colHeader,'',LTGREY$,'',0,TB_ALL)

font<4> = 0 	;* Bold Off
stat = Set_Printer('FONT',font)

stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_ALL)

font<1> = 'Arial'		;* Reset font to normal

stat = Set_Printer('FONT',font)

* Check for Surfscan results

SurfScanKey = WMOutKey:'*PC'		;* Only Post Clean Surface scans on WM_OUT cassettes
SurfScanRec = XLATE('SURFACE_SCAN',SurfScanKey,'','X')

IF SurfScanRec NE '' THEN
	stat = Set_Printer('POS',SSTablesPos)
	
	PSRec = XLATE('PROD_SPEC',PSNo,'','X')

	HazeSpec	= PSRec<105>
	DefectSpec	= PSRec<104>

	Stage = 'PC'

	PopupData = XLATE('SYSREPOSPOPUPS','LSL2**STAGE',8,'X')
	StageDesc = ''
	FOR I = 1 TO COUNT(PopupData,@VM) + (PopupData NE '')
	    PopCode = PopupData<1,I,1>
	    IF PopCode = Stage THEN  StageDesc =  PopupData<1,I,2>
	UNTIL PopupData<1,I,1> = Stage
	NEXT I

	Tool = SurfScanRec<SURFACE_SCAN_SCAN_TOOL$>		

	colHeader	= StageDesc:' - ':Tool:CRLF$:'Surface Scan Results'			; colFormat = '<2880'
	colHeader<1,2>	= 'Spec'												; colFormat<1,2> = '>900'
	colHeader<1,3>	= 'Min'													; colFormat<1,3> = '>900'
	colHeader<1,4>	= 'Max'													; colFormat<1,4> = '>900'
	colHeader<1,5>	= 'Avg'													; colFormat<1,5> = '>900'
			
	colData = ''
	IF CustNo = '6872' THEN
		colData<1,1> = 'Sum of Defects > .02':CHAR(230):'m'
	END ELSE
		colData<1,1> = 'Sum of Defects'
	END
	colData<1,2> = DefectSpec
	colData<1,3> = SurfScanRec<SURFACE_SCAN_SUM_OF_DEF_MIN$>
	colData<1,4> = SurfScanRec<SURFACE_SCAN_SUM_OF_DEF_MAX$>
	colData<1,5> = OCONV(SurfScanRec<SURFACE_SCAN_SUM_OF_DEF_AVG$>,'MD3')

	colData<2,1> = 'Surface Haze Avg (ppm)'
	colData<2,2> = HazeSpec
	colData<2,3> = SurfScanRec<SURFACE_SCAN_HAZE_AVG_MIN$>
	colData<2,4> = SurfScanRec<SURFACE_SCAN_HAZE_AVG_MAX$>
	colData<2,5> = OCONV(SurfScanRec<SURFACE_SCAN_HAZE_AVG_AVG$>,'MD3')
	
	font<2> = 10
	font<4> = 1		;* Bold on
	stat = Set_Printer('FONT',font)
	stat = Set_Printer('ADDTABLE',colFormat,colHeader,'',LTGREY$,'',0,TB_ALL:@FM:3.0)

	font<1> = 'MS LineDraw'		;* This font contains the omega symbol
	font<4> = 0					;* Bold off
	stat = Set_Printer('FONT',font)

	stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_ALL:@FM:3.0)

	font<1> = 'Arial'		;* Reset font to normal

	stat = Set_Printer('FONT',font)
	
END



RETURN




