COMPILE SUBROUTINE Print_Ship_Notice(dummy)


DECLARE FUNCTION Set_Printer, Get_Printer, Dialog_Box, obj_Install, Printer_Select, obj_WM_Out
DECLARE SUBROUTINE Btree.Extract, ErrMsg


$INSERT COC_EQUATES
$INSERT RDS_EQU
$INSERT COMPANY_EQU
$INSERT WO_LOG_EQU
$INSERT WO_STEP_EQU
$INSERT WO_MAT_EQUATES
$INSERT WM_OUT_EQUATES
$INSERT OIPRINT_EQUATES
$INSERT APPCOLORS

* Initialize Common Printer parms

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

Parms = Dialog_Box('INVOICE_RPT6', @WINDOW,'*CENTER')	;* Original Dialog box used for now 10/18/2005 JCH - J.C. Henry & Co., Inc.

IF Parms = 'CANCEL' THEN RETURN

WOCustNos	= Parms<1>
StartShipDt = Parms<2>
EndShipDt	= Parms<3>

OPEN 'COC' TO COCTable ELSE
	ErrMsg('Unable to open COC table in routine.')
	RETURN
END

OPEN 'DICT.COC' TO @DICT ELSE
	ErrMsg('Unable to open DICT.COC in routine')
	RETURN
END

* Initialize Common Printer parms

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

PageSetup	= '0' 				;* Portrait

PDFParms = 'Printing PDF Document':@FM: '' :@FM:'':@FM: ''
	
PrintSetup	= ''
PrintSetup<1,1>	= '2'	;* Preview Normal
PrintSetup<1,2> = '5'	;* Display all buttons except Printer Setup
PrintSetup<1,3>	= '0'	;* Display Printing Window
PrintSetup<1,6> = '7'	;* Preview window - keyboard and mouse support

stat = Set_Printer("INIT",PDFParms,'Shipment Notification',PageInfo,PageSetup,PrintSetup)

FirstLine = 1

FOR CustSeq = 1 TO COUNT(WOCustNos,@VM) + (WOCustNOs NE '')
	
	WOCustNo = WOCustNos<1,CustSeq>
	Captive = XLATE('COMPANY',WOCustNO,COMPANY_CAPTIVE$,'X')
	
	SearchString = ''
	
	BEGIN CASE
	
		CASE StartShipDt NE '' AND EndShipDt NE ''
			SelStartShipDt = OCONV((ICONV(StartShipDt,'D')-1),'D4/')
			SelEndShipDt = OCONV((ICONV(EndShipDt,'D')+1),'D4/')
			SearchString := 'SHIP_DT':@VM:SelStartShipDt:'~':SelEndShipDt:@FM
			
		CASE StartShipDt NE '' AND EndShipDt = ''
			SearchString := 'SHIP_DT':@VM:'>=':StartShipDt:@FM
			
		CASE StartShipDt = '' AND EndShipDt NE ''
			SearchString := 'SHIP_DT':@VM:'<=':EndShipDt:@FM
			
	END CASE
		

	IF WOCustNos NE '' THEN
		SearchString := 'WO_CUST_NO':@VM:WOCustNo:@FM
	END

	IF SearchString = '' THEN RETURN						;* No parameters -> bail

	Option = ''
	Flag = ''

	Btree.Extract(SearchString, 'COC', @DICT, ShipNos, Option, Flag)

	IF Get_Status(errCode) THEN 
		ErrMsg(errCode)
		RETURN
	END
	
	IF ShipNos = '' THEN
		ErrMsg('No shipments on file for Customer No: ':WOCustNo)
		GOTO SkipCustomer
	END

	IF CustSeq > 1 THEN
		stat = Set_Printer('PAGEBREAK')
	END

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

	stat = Set_Printer('FONTHEADFOOT', font)


	stat = Set_Printer('FOOTER',"Page 'P'":@VM:'Customer No: ':WOCustNo:@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  * * * *

/*
	bfont	= 'Arial'
	bfont<2> = 12		;* font size
	bfont<4> = 1		;* Bold on
	bfont<5> = 0		;* Italics off

	stat = Set_Printer('TEXTXY',obj_Install('Get_Prop','Company'),5.75:@FM:-1.15,bfont,1)

	cfont = 'Arial'
	cfont<2> = 10	;* 10 point font size
	cfont<4> = 0		;* Bold off

	stat = Set_Printer('TEXTXY',obj_Install('Get_Prop','Address'),5.75:@fm:-0.925,cfont,1)
	stat = Set_Printer('TEXTXY',obj_Install('Get_Prop','CSZC'),5.75:@fm:-0.775,cfont,1)
	stat = Set_Printer('TEXTXY','Phone:  888 575-3741',5.75:@fm:-0.625,cfont,1)							;* Look at getting this toll free number into obj_Install
	stat = Set_Printer('TEXTXY','Phone:  ':obj_Install('Get_Prop','Phone'),5.75:@fm:-0.475,cfont,1)
	stat = Set_Printer('TEXTXY','FAX:     ':obj_Install('Get_Prop','FAX'),5.75:@fm:-0.325,cfont,1)
	*stat = Set_Printer('TEXTXY','Web:    ':obj_Install('Get_Prop','WebSite'),5.75:@fm:-0.325,cfont,1)

*/


	
	dfont	= 'Arial'
	dfont<2>	= '18'		;* Big type
	dfont<4>	= 1			;* Bold on
	dfont<5> = 1			;* Italics
	stat = Set_Printer('TEXTXY','Shipment Notice',2.6:@FM:-0.80,dfont,1)

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

	stat = Set_Printer( 'FONT', font )
	
	TotWaferQtyGrand = 0
	ShipCnt = COUNT(ShipNos,@VM) + (ShipNos NE '')



	FOR I = 1 TO ShipCnt
		ShipNo = ShipNos<1,I>
		@ID = ShipNo
		
		
		
		READ @RECORD FROM COCTable,@ID THEN
		
			PONo			= {PO_NO_FULL}
			
			WOCustNo		= {WO_CUST_NO}
			SAPDelNo		= @RECORD<COC_SAP_DEL_NO$>
			
			ShipToCustNo	= WOCustNo
			BillToCustNo	= XLATE('COMPANY',ShipToCustNo,COMPANY_BILL_TO_CUST_NO$,'X')
			
			ShipToInfo = XLATE('COMPANY',ShipToCustNo,'SHIP_TO_INFO','X')
			
			IF BillToCustNo = '' THEN
				BillToInfo	= XLATE('COMPANY',ShipToCustNo,'BILL_TO_INFO','X')
			END ELSE
				BillToInfo	= XLATE('COMPANY',BillToCustNo,'BILL_TO_INFO','X')
			END
			
			
			WONo			= {WO}
			ShipVia			= {SHIP_VIA}
				
			SWAP @VM WITH CRLF$ IN ShipToInfo
			SWAP @VM WITH CRLF$ IN BillToInfo
				
			ShipDt = OCONV({SHIP_DT},'D4/')	
			TrackingNos = {TRACKING_NOS}
			SWAP @VM WITH CRLF$ IN TrackingNos
			
			OItems			= {RDS_ORDER_LINE}
			OPartNos		= {CASS_CUST_PART_NO}
			ORDSNos			= {RDS_NO}
			OSuppliedBys 	= {CASS_SUB_SUPPLIED_BY}
			OLotNos			= {RDS_LOT_NO}
			OWaferQtys		= OCONV({CASS_WAFER_CNT},'MD0')
			ORejects		= {CASS_WAFER_REJ}
			OProdTest		= {CASS_WAFER_PROD}
			TotWaferQty 	= {TOT_QTY}
			TotRejQty		= {TOT_REJ}
			TotProdQty		= {TOT_PROD}
			
			WOStepNos 		= @RECORD<COC_WO_STEP$>
			CassNos			= @RECORD<COC_CASS_NO$>
			
			WOStepKey		= WONo:'*':WOStepNos<1,1>
			
			PSNo			= XLATE('WO_STEP',WOStepKey,WO_STEP_PROD_SPEC_ID$,'X')
			ReactorType		= XLATE('PROD_SPEC',PSNo,80,'X')
			
			WMOutKeys = ''
				
			IF ORDSNos<1,1> = '' THEN
			
				FOR S = 1 TO COUNT(WOStepNos,@VM) + (WOStepNos NE '')
					WMOutKeys<1,S> = WONo:'*':WOStepNos<1,S>:'*':CassNos<1,S>
				NEXT S
				
				WMOPartNoQtys = obj_WM_Out('GetPartNoQtys',WMOutKeys)
			
				WMOutRec = XLATE('WM_OUT',WMOutKeys<1,1>,'','X')
				
				CassNo = CassNos<1,1>
				
				SubPartNo = XLATE('WO_MAT',WONo:'*':CassNo,WO_MAT_SUB_PART_NO$,'X')
				
				SuppCd = SubPartNo[-1,'B-']
				IF LEN(SuppCd) NE '2' THEN SuppCd =''
			END ELSE
				WMOPartNoQtys = ''

				SubPartNum = XLATE( 'RDS', ORDSNos<1,1>, 'SUB_PART_NO', 'X' )

				SuppCd = SubPartNum[-1,'B-']
				IF LEN(SuppCd) NE '2' THEN SuppCd =''
			END

			TotWaferQtyGrand += TotWaferQty
			
			Captive = XLATE('COMPANY',{WO_CUST_NO},64,'X')
			
			
			colHead1 = 'Ship Date'							; colFormat1 = '^1440'
			colHead1<1,2> = 'Shipment':CRLF$:'Pack List'	; colFormat1<1,2> = '^1220'
			colHead1<1,3> = 'SAP Del No'					; colFormat1<1,3> = '^1220'
			colHead1<1,4> = 'Ship Via'						; colFormat1<1,4> = '<2160'
			colHead1<1,5> = 'Tracking No'					; colFormat1<1,5> = '^2160'
			colHead1<1,6> = 'Purchase Order'				; colFormat1<1,6> = '^2600'
			
			colData1 = ShipDt
			colData1<1,2> = ShipNo
			colData1<1,3> = SAPDelNo
			colData1<1,4> = ShipVia
			colData1<1,5> = TrackingNos
			colData1<1,6> = PONo

			colHead2 = ''	; colFormat2 = '<10800'	; colData2 = ' '		;* Blank line 'in' the table
			
			ItemTable = ''
			
			OCnt = COUNT(OItems,@VM) + (OItems NE '')

			colHead3 = 'Ship To: ':ShipToCustNo					; colFormat3 = '<5400'
			colHead3<1,2> = 'Bill To: ':BillToCustNo			; colFormat3<1,2> = '<5400'
			
			colData3 = ShipToInfo
			colData3<1,2> = BillToInfo
			
			colHead4 = ''	; colFormat4 = '<10800'	; colData4 = ' '		;* Blank line 'in' the table
			
			IF Captive OR ReactorType = 'EPP' THEN
				
				IF WMOPartNoQtys NE '' THEN
					
					PartNos = WMOPartNoQtys<1>
					WMOQtys = WMOPartNoQtys<2>
					FOR L = 1 TO COUNT(PartNos,@VM) + (PartNos NE '')
						ItemTable<L,1> = PartNos<1,L>
						ItemTable<L,2> = WMOQtys<1,L>
						ItemTable<L,3> = WONo
						ItemTable<L,4> = SuppCd
					NEXT L
					OCnt = L
				END ELSE
					FOR L = 1 TO OCnt
						OPartNo = OPartNos<1,L>
						LOCATE OPartNo IN ItemTable<1> USING @VM SETTING Pos THEN
							ItemTable<Pos,2> = ItemTable<Pos,2> + OWaferQtys<1,L>
						END ELSE
							ItemTable = INSERT(ItemTable,Pos,1,0,OPartNo)
							ItemTable = INSERT(ItemTable,Pos,2,0,OWaferQtys<1,L>)
							ItemTable = INSERT(ItemTable,Pos,3,0,WONo)
							
							IF SuppCd NE '' THEN
								ItemTable = INSERT(ItemTable,Pos,4,0,SuppCd)
							END
						END
					NEXT L
				END
				
				IF I = ShipCnt THEN
					ItemTable<-1> = @VM:@VM
					ItemTable<-1> = 'Report Total:':@VM:OCONV(TotWaferQtyGrand,'MD0,'):@VM
				END
				
				colHead5 = 'Cust Part No'						; colFormat5 = '<2160'
				colHead5<1,2> = 'Shipped'						; colFormat5<1,2> = '>1440'
				colHead5<1,3> = 'Work Order'					; colFormat5<1,3> = '^1440'
				
				IF SuppCd NE '' THEN
					colHead5<1,4> = 'Substrate Supplier Code'	; colFormat5<1,4> = '^2880'
				END
				
			END ELSE
			
				
				SuppliedBy = ''
				FOR L = 1 TO OCnt
					SuppliedBy = OSuppliedBys<1,L>
					IF SuppliedBy = 'L' THEN
					   ItemTable<L> = OItems<1,L>:@VM:OPartNos<1,L>:@VM:ORDSNos<1,L>:@VM:OLotNos<1,L>:@VM:OWaferQtys<1,L>:@VM:WONo
					END ELSE
					    ItemTable<L> = OItems<1,L>:@VM:OPartNos<1,L>:@VM:ORDSNos<1,L>:@VM:OLotNos<1,L>:@VM:OWaferQtys<1,L>:@VM:OProdTest<1,L>:@VM:ORejects<1,L>:@VM:WONo
					END
				NEXT L
				
						
				IF SuppliedBy = 'L' THEN
					ItemTable<L+1> = '':@VM:'':@VM:'':@VM:'Shipment Total:':@VM:TotWaferQty:@VM
				END ELSE
					ItemTable<L+1> = '':@VM:'':@VM:'':@VM:'Shipment Totals:':@VM:TotWaferQty:@VM:TotProdQty:@VM:TotRejQty:@VM
				END
				 	
				IF I = ShipCnt THEN
					ItemTable<L+3> = '':@VM:'':@VM:'':@VM:'Report Total:':@VM:TotWaferQtyGrand:@VM
				END		
				
				
				IF SuppliedBy = 'L' THEN
					* Substrate supplied by EPI Services (Was Lawrence Labs)
					colHead5 = 'Item'				; colFormat5 = '^720'
					colHead5<1,2> = 'Cust Part No'	; colFormat5<1,2> = '<2160'
					colHead5<1,3> = 'RDS No'		; colFormat5<1,3> = '^1080'
					colHead5<1,4> = 'Lot No'		; colFormat5<1,4> = '<2160'
					colHead5<1,5> = 'Shipped'		; colFormat5<1,5> = '>1440'
					colHead5<1,6> = 'Work Order'	; colFormat5<1,6> = '^1440'
				END ELSE
					colHead5 = 'Item'				; colFormat5 = '^720'
					colHead5<1,2> = 'Cust Part No'	; colFormat5<1,2> = '<2160'
					colHead5<1,3> = 'RDS No'		; colFormat5<1,3> = '^1080'
					colHead5<1,4> = 'Lot No'		; colFormat5<1,4> = '<2160'
					colHead5<1,5> = 'Shipped'		; colFormat5<1,5> = '>1080'
					colHead5<1,6> = 'Prod Test'		; colFormat5<1,6> = '>1080'
					colHead5<1,7> = 'Rejects'		; colFormat5<1,7> = '>1080'
					colHead5<1,8> = 'Work Order'	; colFormat5<1,8> = '^1440'
				END
			END	;* End of check for Captive Order
			
			colData5 = ItemTable
			
		END
		
		
		stat = Set_Printer('CALCTABLE',colFormat1:@FM:colData1)
		Table1Size = Get_Printer('CALCTABLE')
		
		stat = Set_Printer('CALCTABLE',colFormat2:@FM:colData2)
		Table2Size = Get_Printer('CALCTABLE')
		
		stat = Set_Printer('CALCTABLE',colFormat3:@FM:colData3)
		Table3Size = Get_Printer('CALCTABLE')
		
		stat = Set_Printer('CALCTABLE',colFormat4:@FM:colData4)
		Table4Size = Get_Printer('CALCTABLE')
		
		stat = Set_Printer('CALCTABLE',colFormat5:@FM:colData5)
		Table5Size = Get_Printer('CALCTABLE')
		
		TableHeight 	= Table1Size<2> + Table2Size<2> + Table3Size<2> + Table4Size<2> + Table5Size<2> 
		CurrVertPos 	= Get_Printer('POS')<2>
		PageHeight		= Get_Printer('PAGESIZE')<2>
		TopMargin		= Get_Printer('MARGIN')<2>
		BottomMargin	= Get_Printer('MARGIN')<4>
		
		MarginFudge		= 0.125
		
		IF CurrVertPos + TableHeight > (PageHeight - TopMargin - BottomMargin - MarginFudge) OR FirstLine THEN
			IF NOT(FirstLine) THEN
				stat = Set_Printer('PAGEBREAK')
			END
			FirstLine = 0			
		END
		
		stat = Set_Printer('ADDTABLE',colFormat1,colHead1,colData1,LTGREY$,'',0,TB_ALL)
		stat = Set_Printer('ADDTABLE',colFormat2,colHead2,colData2,'','',0,TB_ALL)
		stat = Set_Printer('ADDTABLE',colFormat3,colHead3,colData3,'','',0,TB_ALL)
		stat = Set_Printer('ADDTABLE',colFormat4,colHead4,colData4,'','',0,TB_ALL)
		stat = Set_Printer('ADDTABLE',colFormat5,colHead5,colData5,'','',0,TB_BOX)
		
		stat = Set_Printer('TEXT')
		stat = Set_Printer('TEXT')
		
	NEXT I
	

* * * * * * *
SkipCustomer:
* * * * * * *

NEXT CustSeq


stat = Set_Printer('TERM')




RETURN
