COMPILE SUBROUTINE Print_GaN_Scribe_Labels(WONo, CassNos, Recipient, Sender)


$INSERT LOGICAL
$INSERT MSG_EQUATES
$INSERT OIPRINT_EQUATES
$INSERT POPUP_EQUATES
$INSERT PROD_SPEC_EQUATES
$INSERT QUOTE_SPEC_EQU
$INSERT WO_LOG_EQUATES
$INSERT WO_STEP_EQU
$INSERT WO_MAT_EQUATES
$INSERT ORDER_EQU
$INSERT ORDER_DET_EQU
$INSERT EPI_PART_EQUATES
$INSERT CUST_EPI_PART_EQUATES
$INSERT PRS_STAGE_EQUATES

DECLARE FUNCTION Msg, Get_Printer, Set_Printer, Utility, obj_Install, Printer_Select, FieldCount, Popup
DECLARE FUNCTION MemberOf, Direct_Print, Environment_Services, Database_Services
DECLARE SUBROUTINE Btree.Extract, ErrMsg


* 8/23/2006 - Cloned from Print_WMO_Labels

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

IF NOT(ASSIGNED(WONo))		THEN RETURN
IF NOT(ASSIGNED(CassNos))	THEN CassNos = ''
IF WONo = '' 				THEN RETURN


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

BEGIN CASE
	CASE CassCnt = 0
		WOMatKeys = XLATE('WO_LOG',WONo,WO_LOG_WO_MAT_KEY$,'X')
		
	CASE CassCnt = 1
		WOMatKeys = WONo:'*':CassNos
		
	CASE 1
	
		SWAP @VM WITH @VM:WONo:'*' IN CassNos
		WOMatKeys = WONo:'*':CassNos
				
				
		TypeOver = ''
		TypeOver<PDISPLAY$> = WOMatKeys
		TypeOver<PTITLE$>	= 'GaN - Outbound Cassettes'

		WOMatKeys = Popup(@WINDOW,TypeOver,'PRINT_GAN_LABELS')
		CONVERT '.' TO '*' IN WOMatKeys


		
END CASE
		

IF WOMatKeys = '' THEN RETURN


IF NOT(ASSIGNED(WOStep)) THEN WOStep = 1

FileName 	= "Printing Label"
Title		= "Printing Label"

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	= ''			;* Preview
PrinterID = ''
PrintPath	= Printer_Select(PrinterID)		;* Popup is skipped IF Printer ID is passed

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 GOTO OIPrint_Error

CLOrientation = '' ;* used for printing on cleanroom labels

Void = Utility( 'CURSOR', 'H' )

WOStepKeys = XLATE('WO_LOG',WONo,WO_LOG_WO_STEP_KEY$,'X')

IF INDEX(WOStepKeys,@VM,1) THEN
	PrintWONo = WONo:'.':WOStep
END ELSE
	PrintWONo = WONo
END

WORec     = Database_Services('ReadDataRow', 'WO_LOG', WONo)

WMOBoxCnt = COUNT( WOMatKeys, @VM ) + (WOMatKeys NE '')

GOSUB PrintCleanRoomLabels

   
Void = UTILITY( 'CURSOR', 'A' )            


* * * * * *
OIPrint_Error:
* * * * * *

If Environment_Services('GetLabelPrintMethod') _EQC 'OIPI' then
    stat = Set_Printer("TERM")
end else
    stat = Direct_Print('STOP')
end

RETURN



* * * * * * * * * * * *`  L o c a l   S u b r o u t i n e s   * * * * * * * * * * * *

* * * * * * *
PrintCleanRoomLabels:
* * * * * * *
 
  
FOR I = 1 TO WMOBoxCnt

	WOMatKey       = WOMatKeys<1,I>
	MakeupBox      = ''
	PrintWOMatKey  = WOMatKey
	CONVERT '*' TO '.' IN PrintWOMatKey
	CassNo         = FIELD(WOMatKey,'*',2)
	LotNo          = 'Multiple'
	WfrQty         = XLATE('WO_MAT_WFR',WOMatKey,'OUT_WFR_QTY','X')
	WOMatKey       = WONo:'*':CassNo
	WOMatRec       = XLATE('WO_MAT',WOMatKey,'','X')
	SubPartNo      = WORec<WO_LOG_ORD_SUB_PART_NO$>
	CustPartNo     = WORec<WO_LOG_CUST_PART_NO$>
	EpiPartNo      = WORec<WO_LOG_EPI_PART_NO$>
	WOStepKey      = WONo:'*1'
	PSNo           = Xlate('WO_STEP', WOStepKey, 'PROD_SPEC_ID', 'X')
	TechType       = Xlate('PROD_SPEC', PSNo, 'TECH_TYPE', 'X')
	PartNo         = Xlate('WO_LOG', WONo, 'EPI_STRUCTURE', 'X')
	EpiPo          = XLATE('WO_LOG', WONo, 'EPI_PART_NO', 'X')
    WaferSize      = XLATE('EPI_PART', EpiPo, 'SUB_THICK' ,'X')
    WaferSize     := 'um'
    SubSuppCd	   = WORec<WO_LOG_EXP_VEND_CD$>
    SubSuppCd      = XLATE('SEMI_VEND_CODE',SubSuppCd,SEMI_VEND_CODE_EPI_VEND_CD$,'X')
	Begin Case
	    Case TechType EQ 'P'
	        TechType = 'Prod'
	    Case TechType EQ 'E'
	        TechType = 'Eng'
	End Case
	CustPartDesc  = XLATE('EPI_PART',EpiPartNo,EPI_PART_EPI_PART_DESC$,'X')
	PartNo        = CustPartNo				;* Temporary for 4x2 to 4x4 conversion
	PartDesc      = CustPartDesc			;* Temporary for 4x2 to 4x4 conversion
	SuppCd        = TRIM(SubPartNo[-1,'B-'])
	IF LEN(SuppCd) NE '2' THEN SuppCd =''
	
	GOSUB PrintLabel
	
NEXT I
  
RETURN


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

    ****** First Label ******
    Str  = '^XA'
    Str := '^LH0,0'
    Str := '^PR2'		;* Print speed 2 inches per second
    Str := '^LL406'		;* Label length @203 dpi
    Str := '^PW812'
    Str := '^MD15'		;* Media darkness
    Str := '^MMT'		;* Media mode t=tear off mode
*    Str := '^PQ2'		;* Print 2 labels for each pass through here
    Str := '^FWN':CRLF$ ;* Normal orientation
    
    Str := CRLF$
    Str := '^FO60,50^A0, 250^FDFragile^FS':CRLF$
    Str := '^FO140,310^A0, 70^FDHandle With Care!^FS':CRLF$
    Str := '^XZ':CRLF$:CRLF$
    
    ****** Second Label ******
    Str := '^XA'
    Str := '^LH0,0'
    Str := '^PR2'		;* Print speed 2 inches per second
    Str := '^LL406'		;* Label length @203 dpi
    Str := '^PW812'
    Str := '^MD15'		;* Media darkness
    Str := '^MMT'		;* Media mode t=tear off mode
*    Str := '^PQ2'		;* Print 2 labels for each pass through here
    Str := '^FWN':CRLF$ ;* Normal orientation
    
    Str := CRLF$
    Str := '^FO90,100^A0, 150^FD':PrintWOMatKey:'^FS':CRLF$
    Str := '^FO220,280^B3,,80,N^FD':'O':PrintWOMatKey:'^FS':CRLF$		;* Code 39 barcode
    Str := '^XZ':CRLF$:CRLF$
    
    ****** Third Label ******
    Str := '^XA'
    Str := '^LH0,0'
    Str := '^PR2'		;* Print speed 2 inches per second
    Str := '^LL406'		;* Label length @203 dpi
    Str := '^PW812'
    Str := '^MD15'		;* Media darkness
    Str := '^MMT'		;* Media mode t=tear off mode
*    Str := '^PQ2'		;* Print 2 labels for each pass through here
    Str := '^FWN':CRLF$ ;* Normal orientation
    
    Str := CRLF$
    Str := '^FO40,30^A0, 80^FDRecipient: ^FS':CRLF$
    Str := '^FO40,120^A0, 80^FD':Recipient:'^FS':CRLF$
    Str := '^FO40,220^A0, 80^FDSender: ^FS':CRLF$
    Str := '^FO40,310^A0, 80^FD':Sender:'^FS':CRLF$
    Str := '^XZ':CRLF$:CRLF$
    
    ****** Fourth Label ******
    Str := '^XA'
    Str := '^LH0,0'
    Str := '^PR2'		;* Print speed 2 inches per second
    Str := '^LL406'		;* Label length @203 dpi
    Str := '^PW812'
    Str := '^MD15'		;* Media darkness
    Str := '^MMT'		;* Media mode t=tear off mode
*    Str := '^PQ2'		;* Print 2 labels for each pass through here
    Str := '^FWB':CRLF$ ;* Print bottum-up 270 degrees, read from bottom up
    
    Str := '^FX Cell A1^FS':CRLF$
    Str := '^FO2,17':CRLF$
    Str := '^GB28,170,2^FS':CRLF$
    Str := '^FO8,220^A0,25^FD':PrintWOMatKey:'^FS':CRLF$

    Str := '^FX Cell B1^FS':CRLF$
    Str := '^FO2,185':CRLF$
    Str := '^GB28,180,2^FS':CRLF$
    Str := '^FO8,70^A0,25^FDBox 1^FS':CRLF$

    Str := '^FX Cell A2^FS':CRLF$
    Str := '^FO28,17':CRLF$
    Str := '^GB28,170,2^FS':CRLF$
    Str := '^FO34,250^A0,25^FD':TechType:'^FS':CRLF$

    Str := '^FX Cell B2^FS':CRLF$
    Str := '^FO28,185':CRLF$
    Str := '^GB28,180,2^FS':CRLF$
    Str := '^FO34,55^A0,25^FD':WfrQty:' Wafers^FS':CRLF$

    Str := '^FX Cell A3^FS':CRLF$
    Str := '^FO54,17':CRLF$
    Str := '^GB28,170,2^FS':CRLF$
    Str := '^FO60,250^A0,25^FD':PartNo:'^FS':CRLF$

    Str := '^FX Cell B3^FS':CRLF$
    Str := '^FO54,185':CRLF$
    Str := '^GB28,180,2^FS':CRLF$
    Str := '^FO60,70^A0,25^FD':WaferSize:'^FS':CRLF$

    Str := '^FX Cell A4^FS':CRLF$
    Str := '^FO88,367^A0,25^FDSlot^FS':CRLF$
    Str := '^FO80,17':CRLF$
    Str := '^GB28,170,2^FS':CRLF$
    Str := '^FO88,225^A0,25^FDWafer ID^FS':CRLF$

    Str := '^FX Cell B4^FS':CRLF$
    Str := '^FO80,185':CRLF$
    Str := '^GB28,180,2^FS':CRLF$
    Str := '^FO88,50^A0,25^FDLaser Mark^FS':CRLF$

    GaNWfrIDs = Xlate('WO_MAT', WOMatKey, 'OUT_GAN_WFR_ID', 'X')
    Scribes   = Xlate('WO_MAT', WOMatKey, 'OUT_SCRIBE', 'X')
    // Begin Wafer List
    For WaferIndex = 1 to 25
        GaNWfrID  = GaNWfrIDs<0, WaferIndex>
        Scribe    = Scribes<0, WaferIndex>
        Str      := '^FO':(88 + (26 * WaferIndex) ):',367^A0,25^FD':WaferIndex:'^FS':CRLF$
        Str      := '^FO':(80 + (26 * WaferIndex) ):',17':CRLF$
        Str      := '^GB28,170,2^FS':CRLF$
        Str      := '^FO':(88 + (26 * WaferIndex) ):',190^AJ,22^FD':GaNWfrID:'^FS':CRLF$
        Str      := '^FO':(80 + (26 * WaferIndex) ):',185':CRLF$
        Str      := '^GB28,180,2^FS':CRLF$
        Str      := '^FO':(88 + (26 * WaferIndex) ):',50^AJ,22^FD':Scribe:'^FS':CRLF$
    Next WaferIndex

    Str := '^XZ':CRLF$
    
    Str := '^FWN' ; // Reset orientation to "Normal"

    If Environment_Services('GetLabelPrintMethod') _EQC 'OIPI' then
        stat = Set_Printer('TEXT',Str)
    end else
        stat = Direct_Print('PRINT', Str)
    end

	
RETURN	
