SUBROUTINE ORDER_RPT1_PRN( FromDate, ThruDate, OrderTable )
! 
* LIST ORDER JUSTLEN '8' ENTRY_DATE PO BREAK-ON CUST_CITY JUSTLEN '60' TOTAL TOTAL_AMOUNT JUSTLEN '15'  HEADING " Bookings by Company 'T' PAGE # 'PP''L' for Selected Dates From (01/01/95 ) Thru (12/01/95)"
! 
*PRINTER ON
declare function set_printer
* 
* HEADING/FOOTING
TheHeader = " Bookings by Company 'T' PAGE # 'P' for Selected Dates From (":oconv( FromDate, 'D2/' ):") Thru (":oconv( ThruDate, 'D2/' ):")"
ColHeader = "Key" : @vm : "Entry Date" : @vm : "PO #" : @vm : "Customer/City" : @vm : "Wafers": @vm:"Total Amount"
ColHeader<-1> = str( '-', 12 ):@vm:str( '-', 10 ):@vm:str( '-', 19 ):@vm:str( '-', 33 ):@vm:str( '-', 15):@vm:str( '-', 23 )
HeadPos   = '1,1.25,2,3,1,2'
convert ',' to @fm in HeadPos
*FOOTING ""
Void = set_printer( 'FONTHEADFOOT' )
Void = set_printer( 'HEADER', TheHeader, HeadPos, ColHeader )
* 
@RECCOUNT=0
FIRST.PASS=1
LAST.RECORD=0
READERR=0
* 
* OPEN DICT AND DATA FILES
* 
OPEN "DICT",OrderTable TO @DICT ELSE return
OPEN "",OrderTable TO FILE.IN ELSE return
* 
* MAKE COLUMN HEADING
* 
* ZERO ACCUMULATORS FOR EACH BREAK
* 
TOTALULQTY.CUSTULCITY.TOTAL=0
TOTALULQTY.CUSTULCITY.COUNT=0
TOTALULQTY.GRAND.TOTAL=0
TOTALULQTY.GRAND.COUNT=0

TOTALULAMOUNT.CUSTULCITY.TOTAL=0
TOTALULAMOUNT.CUSTULCITY.COUNT=0
TOTALULAMOUNT.GRAND.TOTAL=0
TOTALULAMOUNT.GRAND.COUNT=0
* 
* NULL PREVIOUS BREAK BUCKETS
* 
PREV.CUSTULCITY=''
LAST.CUSTULCITY.BREAK = 1
* 
! 
READRECORD:
! 
* 
* 
* ZERO BREAK FLAGS TO FALSE
* 
CUSTULCITY.BREAK=0
* 
* 
@FILE.ERROR.MODE=1
READNEXT @ID,WHICH.VALUE ELSE
@FILE.ERROR.MODE=0
IF STATUS() GT 0 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT', {RLIST_TEXT_5} )
return
END
IF @FILE.ERROR<1> EQ 421 THEN
Void = set_printer( 'TEXT', {RLIST_TEXT_6} )
GOTO READRECORD
END
IF @FILE.ERROR<1> NE 111 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT', {RLIST_TEXT_4} )
READERR+=1
GOTO READRECORD
END
LAST.RECORD=1
CUSTULCITY.BREAK=1
CUSTULCITY=PREV.CUSTULCITY
END
@FILE.ERROR.MODE=0
* 
S.ATID=@ID
* 
IF FIRST.PASS AND LAST.RECORD THEN
Void = set_printer( 'TEXT', {RLIST_TEXT_2} )
return
END
* 
IF LAST.RECORD THEN GOTO BREAKS
* 
IF @REDUCTION.DONE THEN
@FILE.ERROR.MODE=1
READO @RECORD FROM FILE.IN,@ID ELSE
@FILE.ERROR.MODE=0
IF STATUS() GT 0 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT', {RLIST_TEXT_5} )
return
END
IF @FILE.ERROR<1> NE 100 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT', {RLIST_TEXT_4} )
READERR+=1
END
GOTO READRECORD
END
@FILE.ERROR.MODE=0
END
* 
@RECCOUNT+=1
* 
* 
* CALCULATE VALUE(S) FOR COLUMN(S)
* 
S.ATID={@ID}
I.ATID=S.ATID
S.ENTRYULDATE={ENTRY_DATE}
I.ENTRYULDATE=S.ENTRYULDATE
S.TOTALULQTY={TOTAL_QTY}
I.TOTALULQTY=S.TOTALULQTY
S.PO={PO}
I.PO=S.PO
S.CUSTULCITY={CUST_CITY}
I.CUSTULCITY=S.CUSTULCITY
S.TOTALULAMOUNT={TOTAL_AMOUNT}
I.TOTALULAMOUNT=S.TOTALULAMOUNT
* 
* 
* TEST FOR CONTROL BREAK(S)
* 
IF (S.CUSTULCITY NE PREV.CUSTULCITY) OR CUSTULCITY.BREAK THEN
CUSTULCITY=PREV.CUSTULCITY
PREV.CUSTULCITY=S.CUSTULCITY
CUSTULCITY.BREAK+=1
END
* 
* 
IF FIRST.PASS THEN
FIRST.PASS=0
GOTO DETAIL
END
* 
* 
! 
BREAKS:
! 
* 
* PRINT BREAK TOTAL(S) AND ACCUMULATE TOTAL(S)
* 
* 
IF CUSTULCITY.BREAK THEN
Void = set_printer( 'TEXT', '' )
PRINTLINE = '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= "***":@vm
PRINTLINE:= OCONV(TOTALULQTY.CUSTULCITY.TOTAL ,"MD0,"):@vm
PRINTLINE:= OCONV(TOTALULAMOUNT.CUSTULCITY.TOTAL, "MD2,$")
TableColInfo = '>+1440':@vm:'<+1800':@vm:'<+2880':@vm:'<+4320':@vm:'>+1440':@vm:'>+2880'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

Void = set_printer( 'TEXT', '' )
* 
TOTALULQTY.GRAND.TOTAL+=TOTALULQTY.CUSTULCITY.TOTAL
TOTALULQTY.CUSTULCITY.TOTAL=0
TOTALULQTY.GRAND.COUNT+=TOTALULQTY.CUSTULCITY.COUNT
TOTALULQTY.CUSTULCITY.COUNT=0
TOTALULAMOUNT.GRAND.TOTAL+=TOTALULAMOUNT.CUSTULCITY.TOTAL
TOTALULAMOUNT.CUSTULCITY.TOTAL=0
TOTALULAMOUNT.GRAND.COUNT+=TOTALULAMOUNT.CUSTULCITY.COUNT
TOTALULAMOUNT.CUSTULCITY.COUNT=0
END
* 
* PERFORM LAST RECORD OUTPUT IF DONE
* 
IF LAST.RECORD THEN
Void = set_printer( 'TEXT', '' )
PRINTLINE = "***":@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= OCONV(TOTALULQTY.GRAND.TOTAL ,"MD0,"):@vm
PRINTLINE:= OCONV(TOTALULAMOUNT.GRAND.TOTAL ,"MD2,$")
TableColInfo = '>+1440':@vm:'<+1800':@vm:'<+2880':@vm:'<+4320':@vm:'>+1440':@vm:'>+2880'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

Void = set_printer( 'TEXT', '' )
* PRINT
* @ANS=@REC.COUNT
* PRINT {RLIST_TEXT_1}
IF READERR THEN
@ANS=READERR
Void = set_printer( 'TEXT', {RLIST_TEXT_3} )
END
return
END
* 
! 
DETAIL:
! 
* 
* DO CONVERSIONS IF ANY
* 
IF S.ENTRYULDATE NE "" THEN S.ENTRYULDATE=OCONV(S.ENTRYULDATE,"D2/")
IF S.TOTALULQTY NE "" THEN S.TOTALULQTY=OCONV(S.TOTALULQTY,"MD0,")
IF S.TOTALULAMOUNT NE "" THEN S.TOTALULAMOUNT=OCONV(S.TOTALULAMOUNT,"MD2,$")
* 
* ACCUMULATE TOTAL(S)
* 
IF NUM(I.TOTALULQTY) AND I.TOTALULQTY NE "" THEN
TOTALULQTY.CUSTULCITY.TOTAL+=I.TOTALULQTY
TOTALULQTY.CUSTULCITY.COUNT+=1
I.TOTALULQTY=''
END
IF NUM(I.TOTALULAMOUNT) AND I.TOTALULAMOUNT NE "" THEN
TOTALULAMOUNT.CUSTULCITY.TOTAL+=I.TOTALULAMOUNT
TOTALULAMOUNT.CUSTULCITY.COUNT+=1
I.TOTALULAMOUNT=''
END
* 
* PRINT DETAIL LINE
* 
PRINTLINE =  S.ATID:@vm
PRINTLINE:=  S.ENTRYULDATE:@vm
PRINTLINE:=  S.PO:@vm
PRINTLINE:=  S.CUSTULCITY:@vm
PRINTLINE:=  S.TOTALULQTY:@vm
PRINTLINE:=  S.TOTALULAMOUNT
TableColInfo = '>+1440':@vm:'<+1800':@vm:'<+2880':@vm:'<+4320':@vm:'>+1440':@vm:'>+2880'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

* 
* 
GOTO READRECORD
* 
END

