compile SUBROUTINE Print_CoC_Invoice( ShipNo )

DECLARE FUNCTION security_check, set_printer, get_printer, msg, fieldcount, entid, repository, Printer_Select
DECLARE FUNCTION obj_Install
DECLARE SUBROUTINE security_err_msg

$insert security_rights_equ
$insert oiprint_equates
$insert msg_equates
$insert prod_spec_equ
$insert rds_equ
$insert quote_equ
$insert order_equ
$INSERT ORDER_DET_EQU

$INSERT COC_EQU
$INSERT WO_LOG_EQU
$INSERT APPCOLORS

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(ShipNo)) THEN RETURN

IF Security_Check( 'COC', Print$ ) ELSE
   Security_Err_Msg( 'COC', Print$ )
END

* * *   PRINT SETUP   * * *

PageInfo			= ''
PageInfo<PI$LEFT>	= 0.5		;* Margins
PageInfo<PI$TOP>	= 1.35
PageInfo<PI$RIGHT>	= 0.5
PageInfo<PI$BOTTOM>	= 0.25

PageSetup	= 0					;* 1 = Landscape mode
PrintSetup	= 2 				;* 0 = Print to printer without Preview

stat = Set_Printer("INIT",'Printing','COC Invoice',PageInfo,PageSetup,PrintSetup)


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 = -.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('TEXTXY','Shipment No: ':ShipNo,3.0:@FM:-0.325,font,1)


font	= 'Arial'
font<2>	= '18'		;* Big type
font<4>	= 1			;* Bold on
font<5> = 1			;* Italics
stat = Set_Printer('TEXTXY','CoC - Invoice Entry',2.5:@FM:-0.80,font,0)


ShipRec 	= XLATE('COC',ShipNo,'','X')
ShipRDSNos	= ShipRec<COC_RDS_NO$>
EntryDate	= ShipRec<COC_ENTRY_DATE$>


WONo		= ShipRec<COC_WO$>
WORec		= XLATE('WO_LOG',WONo,'','X')

OrdNo		= WORec<WO_LOG_ORDER_NO$>
OrdItem		= WORec<WO_LOG_ORDER_ITEM$>

OrderRec 	= XLATE('ORDER',OrdNo,'','X')

CustNo		= OrderRec<ORDER_CUST_NO$>
PONo		= OrderRec<ORDER_PO_NO$>
CustName	= XLATE('ORDER',OrdNo,'CUST_NAME','X')
Division	= XLATE('ORDER',OrdNo,'DIVISION','X')

LotNos		= ''
LotQtys 	= ''
LotRejects	= ''
LotPNs		= ''
LotPrices	= ''
LotAmts		= ''
LotLineNos	= ''

FOR I = 1 TO COUNT(ShipRDSNos,@VM) + (ShipRDSNos NE '')
	ShipRDSNo = ShipRDSNos<1,I>
	ShipRDSRec = XLATE('RDS',ShipRDSNo,'','X')
	
	WfrsOut = XLATE('RDS',ShipRDSNo,'WFRS_OUT','X')
	WfrsRej = XLATE('RDS',ShipRDSNo,'TOT_REJ','X')
	PartNo	= ShipRDSRec<RDS_PART_NUM$>
	LotNo	= ShipRDSRec<RDS_LOT_NUM$>
	*SchedNo = ShipRDSRec<RDS_SCHEDULE_NO$>
	*LineNo	= XLATE('SCHEDULE',SchedNo,8,'X')
	LineNo	= XLATE('RDS',ShipRDSNo,RDS_ORDER_ITEM$,'X')
	
	*Price = OrderRec<ORDER_PRICE$,LineNo>
	Price = XLATE('ORDER_DET',OrdNo:'*':LineNo,ORDER_DET_UNIT_PRICE$,'X')
	
	LOCATE LineNo IN LotLineNos BY 'AR' USING @VM SETTING POS THEN
		LotQtys<1,POS> 			= LotQtys<1,POS> + WfrsOut
		LotRejects<1,POS>		= LotRejects<1,POS> + WfrsRej
	END ELSE
		LotNos		= INSERT(LotNos,0,POS,0,LotNo)
		LotQtys		= INSERT(LotQtys,0,POS,0,WfrsOut)
		LotRejects	= INSERT(LotRejects,0,POS,0,WfrsRej)
		LotPNs		= INSERT(LotPNs,0,POS,0,PartNo)
		LotPrices	= INSERT(LotPrices,0,POS,0,Price)
		LotLineNos	= INSERT(LotLineNos,0,POS,0,LineNo)
	END
	
NEXT I


TotalWafers = SUM(LotQtys)
TotalRejects = SUM(LotRejects)


Font = "Courier New,12,L,1"
convert ',' to @fm in Font
Hf = Font
Stat = set_printer( 'FONT', Font )

stat = Set_Printer('TEXT','Shipment No: ':ShipNo)
stat = Set_Printer('TEXT','Entry Date:  ':OCONV(EntryDate,'D4/'))
stat = Set_Printer('TEXT','Cust No:     ':CustNo:' - ':CustName)
stat = Set_Printer('TEXT','Entry Date:  ':OCONV(EntryDate,'D4/'))
stat = Set_Printer('TEXT','Division:    ':Division)
stat = Set_Printer('TEXT','PO No:       ':PONo)
stat = Set_Printer('TEXT','Order No:    ':OrdNo:'  Item No: ':OrdItem)
stat = Set_Printer('TEXT','WO No:       ':WONo)

stat = Set_Printer('TEXT')

Font<2> = 9
Font<4> = 0
Void = set_printer( 'FONT', Font )

Void = set_printer( 'TEXT', '' )
   
colHeader	= 'Line No'						; colFormat	= '^720'
colHeader<1,2>	= 'Lot No'					; colFormat<1,2> = '^2880'
colHeader<1,3>	= 'Part No'					; colFormat<1,3> = '^2880'
colHeader<1,4> 	= 'Wafers'					; colFormat<1,4> = '^1440'
colHeader<1,5> 	= 'Rejects'					; colFormat<1,5> = '^1440'
colHeader<1,6> 	= 'Price'					; colFormat<1,6> = '^1440'


colData = ''
FOR I = 1 TO COUNT(LotLineNos,@VM) + (LotLineNos NE '')
	colData<I,1> = LotLineNos<1,I>
	colData<I,2> = LotNos<1,I>
	colData<I,3> = LotPNs<1,I>
	colData<I,4> = LotQtys<1,I>
	colData<I,5> = LotRejects<1,I>
	colData<I,6> = OCONV(LotPrices<1,I>,'MD2,')
NEXT I

colData<I+1,3> = 'Totals:'
colData<I+1,4> = TotalWafers
colData<I+1,5> = TotalRejects


font<2> = 10
font<4> = 1		;* Bold on
stat = Set_Printer('FONT',font)

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


stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',0,TB_ALL)
Stat = Set_Printer( 'TERM' )
RETURN 

