COMPILE SUBROUTINE Print_Vend_CofA( CoaID , PrintPath, PDFFileName, PrinterInitialized, HideUI)

DECLARE FUNCTION Set_Printer, Get_Printer, Printer_Select, obj_Install

$Insert LOGICAL
$insert company_equ
$insert msg_equates

$insert popup_equates

$INSERT COA
$INSERT OIPRINT_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)

IF NOT(ASSIGNED(CoaID)) OR CoaID = ''	THEN RETURN	;* Nothing to do
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$

* * *   PRINT SETUP   * * *

FileName 	= 'Print Vendor Certificate of Analysis'
Title		= 'Print Vendor Certificate of Analysis'

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


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

PageSetup	= 0					;* 1 = Landscape mode
PrintSetup	= 0					;* 0 = No Preview, 2 = Preview
	
	
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 Document':@FM: '' :@FM:'':@FM: ''
			
	stat = Set_Printer( 'INIT', PDFParms, 'C of A',PageInfo,PageSetup , PrintSetup)
END ELSE
	stat = Set_Printer('PAGEBREAK')
END


CoaRec = XLATE('COA',CoaID,'','X')

CompNo	= FIELD(CoaID,'*',1)
LotNo	= FIELD(CoaID,'*',2)

LotDt			= OCONV(CoaRec<COA_LOT_DT$>,'D4/')
LotQty			= CoaRec<COA_LOT_QTY$>
Spec			= CoaRec<COA_SPEC$>
PartNo			= CoaRec<COA_PART_NO$>
PoNo			= CoaRec<COA_PO_NO$>
GrowthMethod	= CoaRec<COA_SUB_GROWTH_METHOD$>
Orientation		= CoaRec<COA_SUB_ORIENTATION$>
CondType		= CoaRec<COA_SUB_COND_TYPE$>
Dopant			= CoaRec<COA_SUB_DOPANT$>
Parameters		= CoaRec<COA_PARAMETER$>
ParmSpecs		= CoaRec<COA_PARM_SPEC$>
SampleSizes		= CoaRec<COA_SAMPLE_SIZE$>
Mins			= CoaRec<COA_MIN$>
Maxs			= CoaRec<COA_MAX$>
Means			= CoaRec<COA_MEAN$>
StdDevs			= CoaRec<COA_STD_DEV$>

CompanyRec = XLATE('COMPANY',CompNo,'','X')
CompName	= CompanyRec<COMPANY_CO_NAME$>
CompAddress = CompanyRec<COMPANY_ADDRESS$>
CompCity	= CompanyRec<COMPANY_CITY$>
CompST		= CompanyRec<COMPANY_STATE$>
CompZIP		= CompanyRec<COMPANY_ZIP$>

SWAP @VM WITH CRLF$ IN CompAddress

CompInfo = CompName:CRLF$:CompAddress

IF CompCity NE ''	THEN CompInfo := CRLF$:CompCity
IF CompSt NE ''		THEN CompInfo := ', ':CompSt
IF CompZip NE ''	THEN CompInfo := ' ':CompZIP

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

stat = Set_Printer('FONTHEADFOOT', font)

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)

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


stat = Set_Printer('TEXTXY','Vendor Certificate of Analysis',1.5:@FM:-0.80,font,0)

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

* * * *  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')

colHeader = 'Vendor'						; colFormat	= '<4320'
colHeader<1,2> = 'Specification'			; colFormat<1,2> = '<2880'
colHeader<1,3> = 'PO No'					; colFormat<1,3> = '<2880'

colData = CompInfo
colData<1,2> = Spec
colData<1,3> = PONo


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)

stat = Set_Printer('TEXT')

* Lot Info

colHeader = 'Vendor Lot No'			; colFormat = '<2880'
colHeader<1,2> = 'Lot Qty'			; colFormat<1,2> = '^1440'
colHeader<1,3> = 'Lot Date'			; colFormat<1,3> = '^2880'

colData = LotNo
colData<1,2> = LotQty
colData<1,3> = LotDt

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)

stat = Set_Printer('TEXT')


* Substrate Info

colHeader = 'Substrate':CRLF$:'Growth Method'				; colFormat = '^2700'
colHeader<1,2> = 'Substrate':CRLF$:'Orientation'			; colFormat<1,2> = '^2700'
colHeader<1,3> = 'Substrate':CRLF$:'Conductivity Type'		; colFormat<1,3> = '^2700'
colHeader<1,4> = 'Substrate':CRLF$:'Dopant'					; colFormat<1,4> = '^2700'

colData = GrowthMethod
colData<1,2> = Orientation
colData<1,3> = CondType
colData<1,4> = Dopant

font<2> = 8
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)

stat = Set_Printer('TEXT')



* Parameters

colHeader	= 'Parameter'						; colFormat	= '<2160'
colHeader<1,2>	= 'Specification'				; colFormat<1,2> = '<1440'
colHeader<1,3>	= 'Sample Size'					; colFormat<1,3> = '>1440'
colHeader<1,4> 	= 'Minimum'						; colFormat<1,4> = '>1440'
colHeader<1,5> 	= 'Maximum'						; colFormat<1,5> = '>1440'
colHeader<1,6> 	= 'Mean'						; colFormat<1,6> = '>1440'
colHeader<1,7> 	= 'Standard':CRLF$:'Deviation'	; colFormat<1,7> = '>1440'


colData = ''
FOR I = 1 TO COUNT(Parameters,@VM) + (Parameters NE '')
	colData<I,1> = Parameters<1,I>
	colData<I,2> = ParmSpecs<1,I>
	colData<I,3> = SampleSizes<1,I>
	colData<I,4> = Mins<1,I>
	colData<I,5> = Maxs<1,I>
	colData<I,6> = Means<1,I>
	colData<I,7> = StdDevs<1,I>
NEXT I

* Temporary until data is actually sent by Helitek

IF CompNo = '6771' THEN
	TempParms = 'Dopant':@FM:'Surface Orientation':@FM:'Primary Flat Location':@FM:'Round Edge Profile'
	I -= 2
	FOR  M = 1 TO 4
		colData<M+I,1> = TempParms<M>
		colData<M+I,2> = ''
		colData<M+I,3> = ''
		colData<M+I,4> = ''
		colData<M+I,5> = ''
		colData<M+I,6> = ''
		colData<M+I,7> = ''
	NEXT M
END

* End of Temporary

font<2> = 8
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)

stat = Set_Printer('TEXT')

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

RETURN
