compile function INVOICE_RPT6() 
begin condition
pre:
post:
end condition
declare function msg, set_property, send_event, dialog_box, utility, get_property
declare function set_printer, fieldcount, obj_Install, Printer_Select, Get_Status
declare subroutine rlist, or_view, activate_save_select, yield, extract_si_keys, ErrMsg
declare subroutine btree.extract
$insert logical
$insert rlist_equates
$insert msg_equates
$insert coc_equ
$insert order_equ
$insert company_equ

$insert oiprint_equates

Params = dialog_box( 'INVOICE_RPT6', @window, '*CENTER' )
if Params = 'CANCEL' or Params = '' then
   return 0
end

open 'DICT.COC' to DictCOCTable else
   MsgInfo = ''
   MsgInfo<mcol$> = -2
   MsgInfo<mrow$> = -2
   MsgInfo<mtext$> = 'Unable to open DICT.COC table...' 
   Void = msg( '', MsgInfo )
   return 0
end 
Stat = utility( 'CURSOR', 'H' )

CustIds			= Params<1>
ShipDateFrom	= Params<2>
ShipDateThru	= Params<3>

* initialize the printer and set the headings

* New Style PDF printing (OI7.1) added 1/29/04 John C. Henry, J.C. Henry & Co.

FileNameParms = 'Printing Shipping Notice':@FM: '' :@FM: 6 :@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', FileNameParms, 'Shipping Notice','','' , PrintSetup)
	

Font = 'Times New Roman,14,L,1'	;* 14 point, Left just, Bold
convert ',' to @fm in Font


Void = set_printer( 'FONT', Font )
*


CustCnt = fieldcount( CustIds, @vm )
for i = 1 to CustCnt
	TotQtyShip   = 0
	TotRejCnt    = 0
   ThisCustId = CustIds<1,i>
   SearchStr = ''
   if CustIds then
      SearchStr<-1> = 'WO_CUST_NO':@vm:ThisCustId
   end
   if ShipDateFrom and ShipDateThru then
      SearchStr<-1> = 'SHIP_DT':@vm:ShipDateFrom:'...':ShipDateThru
   end else
		if ShipDateFrom then
		    SearchStr<-1> = 'SHIP_DT':@vm:'>=':ShipDateFrom
		end
		if ShipDateThru then
		    SearchStr<-1> = 'SHIP_DT':@vm:'<=':ShipDateThru
		end
   end
   SearchStr := @fm
   Void = utility( 'CURSOR', 'H' )
   * do a btree.extract
   btree.extract( SearchStr, 'COC', DictCOCTable, Keys, '', Flag )
   IF Get_Status(errCode) THEN ErrMsg(errCode)
   if Flag <> 0 then
      MsgInfo = ''
      MsgInfo<mcol$>  = -2
      MsgInfo<mrow$>  = -2
      MsgInfo<mtext$> = 'Error while extracting COC records...' 
      Void = msg( '', MsgInfo )
      return 0
   end
   if Keys then
      convert @vm to @fm in Keys
      
      *Keys = key_sort( Keys, 'COC', 'CUST_NAME':@fm:'#ENTRY_DATE':@fm:'PO', 1 )
      
      ThisCOCRec = xlate( 'COC', Keys<1>, '', 'X' )
      
      * use the first COC for customer shipping specific information
      Font<2> = 14
      Font<3> = 'C'
      Font<4> = 0 ;* not bold
      Void = set_printer( 'FONT', Font )      
      Void = set_printer( 'TEXT', obj_Install('Get_Prop','Company' ))
      Font<4> = 1 ;* bold
      Void = set_printer( 'FONT', Font )
      Void = set_printer( 'TEXT', obj_Install('Get_Prop','Division' ))
      Font<2> = 12
      Font<4> = 0
      Void = set_printer( 'FONT', Font )            
      *Void = set_printer( 'TEXT', 'Epitaxial Services' )
      Void = set_printer( 'TEXT', obj_Install('Get_Prop','Address'))
      Void = set_printer( 'TEXT', obj_Install('Get_Prop','CSZ'))
      Void = set_printer( 'TEXT', 'Phone 1-888-575-3741' )
      Void = set_printer( 'TEXT', 'Phone 480-668-4033' )
      Void = set_printer( 'TEXT', 'Fax 480-668-4021' )
      Void = set_printer( 'TEXT', '' )
      Void = set_printer( 'TEXT', '' )
      Font<2> = 14
      Font<4> = 1
      Void = set_printer( 'FONT', Font )                  
      Void = set_printer( 'TEXT', 'SHIPMENT NOTICE' )
      Font<4> = 0 ;* remove bolding
      Font<2> = 10
      Void = set_printer( 'FONT', Font )                  
      Void = set_printer( 'TEXT', '' )
      Void = set_printer( 'TEXT', '' )
      
      * Ship To Info	;* Changed ship to to point to order instead of company
      					;* 9/18/2003 John C. Henry, J.C. Henry & Co., Inc.
     
		*OrderNo	 	= ThisCOCRec<COC_ORDER_NO$,1>			;* This is multivalued
		OrderNo		= XLATE('COC',Keys<1>,'RDS_ORDER_NO','X')	;* Changed to symbolic 2/23/2005 jch
		
		OrderRec	= XLATE('ORDER',OrderNo,'','X')
		ShipToName	= OrderRec<ORDER_SHIP_TO_COMPANY$>
		ShipToAddr	= OrderRec<ORDER_SHIP_TO_ADDRESS$>		; * This is MV's needs work
		ShipToCity	= OrderRec<ORDER_SHIP_TO_CITY$>
		ShipToST	= OrderRec<ORDER_SHIP_TO_STATE$>
		ShipToZIP	= OrderRec<ORDER_SHIP_TO_ZIP$>
      
      
      CustRec = xlate( 'COMPANY', ThisCOCRec<coc_cust_no$>, '', 'X' )
	   Table = ''
	   Table<-1> = '':@vm:'Shipping to:':@vm:ShipToName	;* JCH
	   *Address = xlate( 'COMPANY', ThisCOCRec<coc_cust_no$>, company_address$, 'X' )
	   Acnt = fieldcount( ShipToAddr, @vm )			;* JCH
	   for j = 1 to Acnt
   	   Table<-1> = '':@vm:'':@vm:ShipToAddr<1,j>	;* JCH
      next j
      Table<-1> = '':@vm:'':@vm:ShipToCity:', ':ShipToST:' ':ShipToZIP
      TableColInfo = '<+1440':@vm:'<+1440':@vm:'<+3600'
      x = Set_Printer("ADDTABLE", TableColInfo, '', Table, '', '', 1, TB_NONE)
      Void = set_printer( 'TEXT', '' )
      COCCnt = fieldcount( Keys, @fm )
      for k = 1 to COCCnt
         ThisCOCID = Keys<k>
         ThisCOCRec = xlate( 'COC', ThisCOCID, '', 'X' )
         PONo = XLATE( 'COC', ThisCOCID, 'PO_NO', 'X' )
         POLine = XLATE('COC',ThisCOCID, 'PO_LINE','X')
         PORel	= XLATE('COC',ThisCOCID, 'PO_REL','X')
         
         IF POLine NE '' THEN PONo := ' Line ':POLine
         IF PORel NE '' THEN PONo := ' Rel ':PORel
         * 
		Table = ''
		TableColInfo = '<+1440':@vm:'<+2160':@vm:'<+2880':@vm:'<+1440':@vm:'<+2160' 
		Table<-1> = '':@vm:'Purchase Order#:':@vm:PONo:@vm:'Ship Date':@vm:oconv( ThisCOCRec<coc_ship_dt$>, 'D2/' )
		
		x = Set_Printer("ADDTABLE", TableColInfo, '', Table, '', '', 1, TB_NONE)
		
		Table = ''
		ShipVia = ThisCOCRec<coc_ship_via$>
		x = Set_Printer("ADDTABLE", TableColInfo, '', Table, '', '', 1, TB_NONE)
		
		TableColInfo = '6640>+':@vm:'<+2000'
		Font<4> = 1
		Void = set_printer( 'FONT', Font )
		TTable = '':@vm:'Tracking Number(s)'
		x = Set_Printer("ADDTABLE", TableColInfo, '', TTable, '', '', 1, TB_NONE)
		
		Font<4> = 0
		Void = set_printer( 'FONT', Font )
								
		TrackingNos = ThisCOCRec<coc_tracking_nos$>
		TableColInfo = '6640>+':@vm:'<+2000'
		convert @vm to @fm in TrackingNos
		Tcnt = fieldcount( TrackingNos, @fm )
		for l = 1 to Tcnt 
		   Table<-1> = '':@vm:TrackingNos<l>
		next l
		x = Set_Printer("ADDTABLE", TableColInfo, '', Table, '', '', 1, TB_NONE)
        
        			
		Table = ''
		Font<6> = 1 ;* underline
		Void = set_printer( 'FONT', Font )
		Table<-1> = 'Item':@vm:'Part#':@vm:'Lot#':@vm:'Qty Ship':@vm:'Rejects':@VM:'Work Order'
		TableColInfo = '>+720':@vm:'<+2160':@vm:'<+1440':@vm:'>+720':@vm:'>+720':@VM:'>1440'
  			x = Set_Printer("ADDTABLE", TableColInfo, '', Table, '', '', 1, TB_NONE)
		Font<6> = 0 ;* no more underline
		Void = set_printer( 'FONT', Font )
		
  		Table = ''
  		
		*OItems 	= ThisCOCRec<coc_order_line$>
		OItems		= XLATE('COC',ThisCOCID,'RDS_ORDER_LINE','X')	;* Changed to symbolic 2/23/2005 JCH
		OPartNos	= XLATE('COC',ThisCOCID,'RDS_PART_NO','X')		;* Changed to symbolic 2/23/2005 JCH
		OLotNos		= XLATE('COC',ThisCOCID,'RDS_LOT_NO','X')		;* Changed to symbolic 2/23/2005 JCH
		OWaferQtys	= XLATE('COC',ThisCOCID,'RDS_WAFER_QTY','X')	;* Changed to symbolic 2/23/2005 JCH
		ORejects	= XLATE('COC',ThisCOCID,'RDS_REJECTS','X')		;* Changed to symbolic 2/23/2005 JCH
	
		OCnt = fieldcount( OItems, @vm )
		QtyShip   = 0
		RejCnt    = 0
		for l = 1 to OCnt
			Table<-1> = OItems<1,l>:@vm:OPartNos<1,l>:@vm:OLotNos<1,l>:@vm:OWaferQtys<1,l>:@vm:ORejects<1,l>:@VM:ThisCOCRec<coc_wo$>
			QtyShip   += OWaferQtys<1,l>
			RejCnt    += ORejects<1,l>
	   	next l
	   	
	   	TableColInfo = '>+720':@vm:'<+2160':@vm:'<+1440':@vm:'>+720':@vm:'>+720':@VM:'>1440'
   		x = Set_Printer("ADDTABLE", TableColInfo, '', Table, '', '', 1, TB_NONE)
	   	Font<4> = 1
	   	Void = set_printer( 'FONT', Font )
	   	Table = ''
	   	Table<-1> = 'Total shipment for packing list ':ThisCOCId:':':@vm:QtyShip:@vm:RejCnt
	   	TableColInfo = '^+4320':@vm:'>+720':@vm:'>+720'
	   	x = Set_Printer("ADDTABLE", TableColInfo, '', Table, '', '', 1, TB_NONE)
			TotQtyShip   += QtyShip
			TotRejCnt    += RejCnt
			Void = set_printer( 'TEXT', str( '*', 101 ) )
	   	Font<4> = 0
	   	Void = set_printer( 'FONT', Font )
	   	Void = set_printer( 'TEXT', '' )
	   	Void = set_printer( 'TEXT', '' )
      next k
    	Font<4> = 1
	  	Void = set_printer( 'FONT', Font )
     	Table = ''
	   TableColInfo = '^+3600':@vm:'>+720':@vm:'>+720'
   	Table<-1> = 'Total shipment for all packing lists:':@vm:TotQtyShip:@vm:TotRejCnt
	   	x = Set_Printer("ADDTABLE", TableColInfo, '', Table, '', '', 1, TB_NONE)
    	Font<4> = 0
	  	Void = set_printer( 'FONT', Font )
   end else
      MsgInfo = ''
      MsgInfo<mcol$>  = -2
      MsgInfo<mrow$>  = -2
      MsgInfo<mtext$> = 'No records found meeting your criteria for ':oconv( ThisCustId, '[XLATE_CONV,COMPANY*CO_NAME]' ):'...' 
      MsgInfo<micon$> = '!'
      Void = msg( '', MsgInfo )
   end
   if i = CustCnt else
      * not on the last one do a page break
      Void = set_printer( 'PAGEBREAK' )
   end
next i
Void = set_printer( 'TERM', 1 ) 
Stat = utility( 'CURSOR', 'A' )
return 0
*================================================================================================*

   * initialize the printer and set the headings
   if DirToPrinter = 'Yes' then
      OutputParam = 0
   end else
      OutputParam = 3 ;* maximized print preview
   end 
   
   PrintPath = Printer_Select('',1)	;* Get default printer path
   
   Void = set_printer( 'INIT', '', '', '', '', OutputParam , PrintPath)
	Font = 'Times New Roman,14,L,1'	;* 14 point, Left just, Bold
	convert ',' to @fm in Font
return

*================================================================================================*

