COMPILE SUBROUTINE TEST_REPORT_THRUPUT(dummy)

* General Manager Report - goes straight to Excel

* 9/23/2006 John C. Henry, J.C. Henry & Co., Inc.  Initial coding

DECLARE SUBROUTINE ErrMsg, Btree.Extract, Set_Status, SetInitDirOptions, ErrMsg
DECLARE FUNCTION Msg, Get_Status, obj_Calendar, Utility, SetInitDirOptions, Dialog_Box, obj_RDS_Test, Environment_Services

$INSERT RDS_EQU
$INSERT COMPANY_EQU
$INSERT REACTOR_EQUATES
$INSERT FISCAL_QTR_EQUATES
$INSERT MSG_EQUATES
$INSERT EXCEL_EQU


EQU ROW$TOT_OUT				TO 2
EQU ROW$TOT_CUST_SCRAP		TO 3
EQU ROW$TOT_EPI_SCRAP		TO 4
EQU ROW$TOT_OTHER			TO 5
EQU ROW$TOT_YIELD			TO 6
EQU ROW$TOT_SCRAP_RATE		TO 7
EQU ROW$TOT_PRIME_TW		TO 8
EQU ROW$TOT_RECLAIM_TW		TO 9


EQU COL$MON				TO 2
EQU COL$TUE				TO 3
EQU COL$WED				TO 4
EQU COL$THU				TO 5
EQU COL$FRI				TO 6
EQU COL$SAT				TO 7
EQU COL$SUN				TO 8
EQU COL$WTD_ACTUAL		TO 9
EQU COL$QTD_ACTUAL		TO 10
EQU COL$QTD_PPA_PLAN		TO 11
EQU COL$QTD_PPA_REMAIN		TO 12
EQU COL$ORG_PPA_DAILY_PLAN	TO 13
EQU COL$QTD_PPA_OVER_UNDER	TO 14
EQU COL$QTY_MRP_PLAN		TO 15
EQU COL$QTD_MRP_REMAIN		TO 16
EQU COL$MRP_DAILY_PLAN		TO 17
EQU COL$QTD_MRP_OVER_UNDER	TO 18

EQU COL$PERIOD			TO 20
EQU COL$PERIOD_VALUE	TO 21
EQU COL$PERIOD_START	TO 22
EQU COL$PERIOD_END		TO 23

EQU CRLF$ TO \0D0A\


eXcelCols = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,DD,EE,FF,GG,HH,II,JJ,KK,LL'
SWAP "','" WITH ',' IN eXcelCols
CONVERT ',' TO @VM IN eXcelCols

NoteText  = 'Select date in the Fiscal Week of interest.':CRLF$:CRLF$
NoteText := 'The report will calculate the Quarter and Week '
NoteText := 'beginning and ending dates and report on the QTD '
NoteText := 'and the full (Mon - Sun) week the date was in.'

DateLabel = 'Date in Fiscal Week:'

CutOffDt = Dialog_Box("DIALOG_DATE",@WINDOW,NoteText:@FM:DateLabel)
thisCutOffDt = ICONV(CutOffDt,'D4/')
IF thisCutOffDt = '' THEN
	ErrMsg('Invalid Date Entered.')
	RETURN
END

CutOffDt = OCONV(thisCutOffDt,'D4/')

IF CutOffDt = '' THEN RETURN

FiscalYear = obj_Calendar('IRFiscalYear',CutOffDt)

FWData = obj_Calendar('IRFiscalWeek',CutOffDt)

FiscalWeek	= FWData[1,@FM]
FWStartDt	= FWData[COL2()+1,@FM]
FWEndDt		= FWData[COL2()+1,@FM]

StartDt = ICONV(FWStartDt,'D')

WeekDates = ''
FOR I = StartDt TO StartDt + 6
	WeekDates<1,-1> = OCONV(I,'D4/')
NEXT I

FQData = obj_Calendar('IRFiscalQuarter',CutOffDt)

FiscalQuarter	= FQData<1>
FQStartDt		= FQData<2>
FQEndDt			= FQData<3>

DataArray = ''
DataArray<1,ROW$TOT_OUT>			= 'Total Out'
DataArray<1,ROW$TOT_CUST_SCRAP>		= '  Sup/Cust Scrap'
DataArray<1,ROW$TOT_EPI_SCRAP>		= '  IREP Scrap'
DataArray<1,ROW$TOT_OTHER>			= '  Prod Test'
DataArray<1,ROW$TOT_YIELD>			= '  Yield'
DataArray<1,ROW$TOT_SCRAP_RATE>		= '  Scrap/1k'
DataArray<1,ROW$TOT_PRIME_TW>		= '  Prime TW'
DataArray<1,ROW$TOT_RECLAIM_TW>		= '  Reclaim TW'


DataArray<COL$MON,1>				= 'Monday ':WeekDates<1,1>
DataArray<COL$TUE,1>				= 'Tuesday ':WeekDates<1,2>
DataArray<COL$WED,1>				= 'Wednesday ':WeekDates<1,3>
DataArray<COL$THU,1>				= 'Thursday ':WeekDates<1,4>
DataArray<COL$FRI,1>				= 'Friday ':WeekDates<1,5>
DataArray<COL$SAT,1>				= 'Saturday ':WeekDates<1,6>
DataArray<COL$SUN,1>				= 'Sunday ':WeekDates<1,7>
DataArray<COL$WTD_ACTUAL,1>			= 'WTD Actual'
DataArray<COL$QTD_ACTUAL,1>			= 'QTD Actual'
DataArray<COL$QTD_PPA_PLAN,1>		= 'QTD PPA Plan'
DataArray<COL$QTD_PPA_REMAIN,1>		= 'QTD PPA Remain'
DataArray<COL$ORG_PPA_DAILY_PLAN,1>	= 'Org PPA Daily Plan'
DataArray<COL$QTD_PPA_OVER_UNDER,1>	= 'QTD PPA +/-'
DataArray<COL$QTY_MRP_PLAN,1>		= 'QTY MRP Plan'
DataArray<COL$QTD_MRP_REMAIN,1>		= 'QTD MRP Remain'
DataArray<COL$MRP_DAILY_PLAN,1>		= 'MRP Daily Plan'
DataArray<COL$QTD_MRP_OVER_UNDER,1>	= 'QTD MRP +/-'

FQRec = XLATE('FISCAL_QTR',FiscalYear:'*':FiscalQuarter,'','X')

TargKeys = ''

FOR I = 1 TO COUNT(FQRec<FISCAL_QTR_THRU_GROUP$>,@VM) + (FQRec<FISCAL_QTR_THRU_GROUP$> NE '')
	TargKey		= FQRec<FISCAL_QTR_THRU_GROUP$,I>:'*':FQRec<FISCAL_QTR_THRU_TARGET$,I>
	TargQty		= OCONV(FQRec<FISCAL_QTR_THRU_QTY$,I>,'MD0,Z')
	TargPcnt	= OCONV(FQRec<FISCAL_QTR_THRU_PCNT$,I>, 'MD2%SZ')
	
 	BEGIN CASE
 		CASE TargKey = 'TOT*Total_Out'				; DataArray<COL$QTD_PPA_PLAN,ROW$TOT_OUT>			= TargQty
 		CASE TargKey = 'TOT*Total_MRP'				; DataArray<COL$QTY_MRP_PLAN,ROW$TOT_OUT>			= TargQty
 			
 		CASE TargKey = 'TOT*Sup/Cust_Scrap'			; DataArray<COL$QTD_PPA_PLAN,ROW$TOT_CUST_SCRAP>	= TargQty
 		CASE TargKey = 'TOT*IREP_Scrap'				; DataArray<COL$QTD_PPA_PLAN,ROW$TOT_EPI_SCRAP>		= TargQty
 		CASE TargKey = 'TOT*Prod_Test'				; DataArray<COL$QTD_PPA_PLAN,ROW$TOT_OTHER>			= TargQty
 		CASE TargKey = 'TOT*Yield'					; DataArray<COL$QTD_PPA_PLAN,ROW$TOT_YIELD>			= TargPcnt
 		
 		
 	END CASE
NEXT I


DataArray<COL$PERIOD,1>				= 'Fiscal Period'
DataArray<COL$PERIOD_VALUE,1>		= ''
DataArray<COL$PERIOD_START,1>		= 'Start Date'
DataArray<COL$PERIOD_END,1>			= 'End Date'

DataArray<COL$PERIOD,2>				= 'Week'
DataArray<COL$PERIOD_VALUE,2>		= FiscalWeek
DataArray<COL$PERIOD_START,2>		= FWStartDt
DataArray<COL$PERIOD_END,2>			= FWEndDt

DataArray<COL$PERIOD,3>				= 'Quarter'
DataArray<COL$PERIOD_VALUE,3>		= FiscalQuarter
DataArray<COL$PERIOD_START,3>		= FQStartDt
DataArray<COL$PERIOD_END,3>			= FQEndDt

DataArray<COL$PERIOD,5>				= 'Ran At'
DataArray<COL$PERIOD_VALUE,5>		= ''
DataArray<COL$PERIOD_START,5>		= OCONV(Date(),'D4/')
DataArray<COL$PERIOD_END,5>			= OCONV(Time(),'MTH')


FQRec			= XLATE('FISCAL_QTR',FiscalYear:'*':FiscalQuarter,'','X')
QtrStartDt 		= FQRec<FISCAL_QTR_START_DT$>
QtrEndDt 		= FQRec<FISCAL_QTR_END_DT$>
PlanIdleDts		= FQRec<FISCAL_QTR_PLAN_IDLE_DTS$>


IF QtrStartDt = '' THEN
	ErrMsg('Fiscal Quarter ':FiscalYear:'*':FiscalQuarter:' is missing the start date.')
	RETURN
END

IF QtrEndDt = '' THEN
	ErrMsg('Fiscal Quarter ':FiscalYear:'*':FiscalQuarter:' is missing the end date.')
	RETURN
END

IF QtrStartDt >= QtrEndDt THEN
	ErrMsg('Fiscal Quarter ':FiscalYear:'*':FiscalQuarter:' has incorrect Start and/or End dates.')
	RETURN
END


TotQtrDays		= QtrEndDt - QtrStartDt + 1
QtrDaysRem		= QtrEndDt - thisCutOffDt
PlanIdleDaysRem = 0

PlanDtCnt = COUNT(PlanIdleDts,@VM) + (PlanIdleDts NE '')
FOR I = 1 TO PlanDtCnt
   PlanIdleDt = PlanIdleDts<1,I>
    IF PlanIdleDt >= thisCutOffDt THEN PlanIdleDaysRem += 1
NEXT I

PlanIdleDays	= PlanDtCnt

PlanWorkingDays	= TotQtrDays - PlanIdleDays

IF PlanWorkingDays < 0 THEN PlanWorkingDays = 0

PlanDaysRem = QtrDaysRem - PlanIdleDaysRem
IF PlanDaysRem < 0 THEN PlanDaysRem = 0


BEGIN CASE
	CASE QtrDaysRem = ''
		CalDaysDelta = ICONV(FWEndDt,'D') - ICONV(FQStartDt,'D')
		DaysWorked = INT((CalDaysDelta/TotQtrDays) * PlanWorkingDays)
		
	CASE PlanWorkingDays > PlanDaysRem
		DaysWorked = PlanWorkingDays - PlanDaysRem
		
	CASE 1
		DaysWorked = 0
		
END CASE


DataArray<COL$PERIOD,10>	= 'Actual Quarter Days'			;	DataArray<COL$PERIOD_VALUE,10> = TotQtrDays
DataArray<COL$PERIOD,11>	= 'Planned Working Days'		;	DataArray<COL$PERIOD_VALUE,11> = PlanWorkingDays
DataArray<COL$PERIOD,12>	= 'Actual Days Left'			;	DataArray<COL$PERIOD_VALUE,12> = QtrDaysRem
DataArray<COL$PERIOD,13>	= 'Total Idle Days'				;   DataArray<COL$PERIOD_VALUE,13> = PlanIdleDays
DataArray<COL$PERIOD,14>	= 'Idle Days Left'				;	DataArray<COL$PERIOD_VALUE,14> = PlanIdleDaysRem
DataArray<COL$PERIOD,15>	= 'Planned Days Left'			;	DataArray<COL$PERIOD_VALUE,15> = PlanDaysRem


* * * * * Process the REACT_RUN Table * * * * * *

OPEN 'DICT.REACT_RUN' TO @DICT ELSE
	ErrMsg('Unable to open "DICT.REACT_RUN" for index lookup')
	RETURN
END

OPEN 'REACT_RUN' TO ReactRunTable ELSE
	ErrMsg('Unable to open "DICT.REACT_RUN" for index lookup')
	RETURN
END

* Fudge the dates - '~' is not inclusive of the end dates


StartDt = ICONV(FQStartDt,'D') - 1
EndDt 	= ICONV(FWEndDt,'D') + 1

SearchString = 'UNLOAD_DT':@VM:OConv(StartDt, 'D4/'):'~':OConv(EndDt, 'D4/'):@FM

ReactRunKeys = ''
Option = ''
Flag = ''

Def = ""
Def<MTEXT$> = "Selecting Reactor Run records..."
Def<MTYPE$> = "U"
MsgUp = Msg(@window, Def)   ;* display the processing message

Set_Status(0)
Btree.Extract(SearchString, 'REACT_RUN', @DICT, ReactRunKeys, Option, Flag)

Msg(@WINDOW, MsgUp)

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	RETURN
END

IF ReactRunKeys = '' THEN
	ErrMsg('No RDS Records found for the current quarter!')
	RETURN
END


RDSCnt	= COUNT(ReactRunKeys,@VM) + (ReactRunKeys NE '')
LoopCnt	= 0
LastCheck = 0

Def = ""
Def<MCAPTION$>		= "Building Report..."
Def<MTYPE$>			= "GC"
Def<MEXTENT$>		= RDSCnt
Def<MTEXTWIDTH$>	= 600


AArray = ''
AATot = 0

MsgUp = Msg(@WINDOW, Def)

LOOP
	@ID = ReactRunKeys[1,@VM]
	ReactRunKeys[1,COL2()] = ''
	LoopCnt += 1
	
	READ @RECORD FROM ReactRunTable,@ID THEN
	
		WafersOut = {WFRS_OUT_NOMU}
		AATot = AATot + WafersOut
		
		AArray<LoopCnt,1> = @ID
		AArray<LoopCnt,2> = AATot
		AArray<LoopCnt,3> = WafersOut
		
		
		NCRKeys = @RECORD<RDS_NCR_KEYS$>
		CustScrap	= {CUST_TOT_REJ}
		IREpiScrap	= {LSL_TOT_REJ}
		PrimeTW		= {TW_PRIME}
		ReclaimTW	= {TW_RECLAIM}
		
		TestKeys = XLATE('RDS_LAYER',@RECORD<RDS_RDS_LAYER_KEYS$>,3,'X')
		TWProd = obj_RDS_Test('ProdTestCount',TestKeys)

		SRPBillable = @RECORD<RDS_RESEARCH_SRP_BILLABLE$>
		
		OtherWafers = TWProd + SRPBillable
		
		Reactor = @RECORD<RDS_REACTOR$>
		ReactorType = XLATE('REACTOR',Reactor,REACTOR_REACT_TYPE$ ,'X')
		
						
		CustNo = @RECORD<RDS_CUST_NO$>
		
		Captive = {CUST_CAPTIVE}
		CustReportExclude = XLATE('COMPANY',CustNo,COMPANY_REPORT_EXCLUDE$,'X')
		
		Product = {PRODUCT}
		DateOut = {DATE_OUT}
		Day = MOD(DateOut,7)
		
		
		BEGIN CASE
		  CASE Day = 0 ; DayCol = COL$SUN
		  CASE Day = 1 ; DayCol = COL$MON
		  CASE Day = 2 ; DayCol = COL$TUE
		  CASE Day = 3 ; DayCol = COL$WED
		  CASE Day = 4 ; DayCol = COL$THU
		  CASE Day = 5 ; DayCol = COL$FRI
		  CASE Day = 6 ; DayCol = COL$SAT
		END CASE
		
		DateOut = OCONV(DateOut,'D4/')
		
		RDSFiscalWeek = obj_Calendar('IRFiscalWeek',DateOut)<1>	;* 2nd and 3rd fields are the start and end dates of the week
		
		IF NOT(CustReportExclude) THEN
			
									
			DataArray<COL$QTD_ACTUAL,ROW$TOT_OUT>			= DataArray<COL$QTD_ACTUAL,ROW$TOT_OUT> + WafersOut
			
			DataArray<COL$QTD_ACTUAL,ROW$TOT_CUST_SCRAP>	= DataArray<COL$QTD_ACTUAL,ROW$TOT_CUST_SCRAP> + CustScrap
			DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>		= DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> + IREpiScrap
			DataArray<COL$QTD_ACTUAL,ROW$TOT_OTHER>			= DataArray<COL$QTD_ACTUAL,ROW$TOT_OTHER> + OtherWafers
			DataArray<COL$QTD_ACTUAL,ROW$TOT_PRIME_TW>		= DataArray<COL$QTD_ACTUAL,ROW$TOT_PRIME_TW> + PrimeTW
			DataArray<COL$QTD_ACTUAL,ROW$TOT_RECLAIM_TW>	= DataArray<COL$QTD_ACTUAL,ROW$TOT_RECLAIM_TW> + ReclaimTW
			
			Yield = DataArray<COL$QTD_ACTUAL,ROW$TOT_OUT>/(DataArray<COL$QTD_ACTUAL,ROW$TOT_OUT> + DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>)
			
			DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD>	= OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
			
			* * *  IREP Scrap Rate Row  * * * * *
				
			IF DataArray<COL$QTD_ACTUAL,ROW$TOT_OUT> > 0 THEN
				ScrapRate = (DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>/DataArray<COL$QTD_ACTUAL,ROW$TOT_OUT>)*1000
			END ELSE
				ScrapRate = 0
			END
			
			DataArray<COL$QTD_ACTUAL,ROW$TOT_SCRAP_RATE> = OCONV(ICONV(ScrapRate,'MD2'),'MD2')
			
			* Planning Calcs
			
			QTDRem = (ICONV(DataArray<COL$QTD_PPA_PLAN,ROW$TOT_EPI_SCRAP>,'MD0') - ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>,'MD0'))
			
			DataArray<COL$QTD_PPA_REMAIN,ROW$TOT_EPI_SCRAP> = OCONV(QTDRem,'MD0,')
			
			IF PlanWorkingDays = 0 THEN
				OrgDailyPlan = 0
			END ELSE
				OrgDailyPlan = ICONV(DataArray<COL$QTD_PPA_PLAN,ROW$TOT_EPI_SCRAP>,'MD0')/PlanWorkingDays
			END
			
			DataArray<COL$ORG_PPA_DAILY_PLAN,ROW$TOT_EPI_SCRAP> = OCONV(ICONV(OrgDailyPlan,'MD0'),'MD0')
			
			IF OrgDailyPlan NE 0 THEN
				QTDOverUnder = ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> - (DataArray<COL$ORG_PPA_DAILY_PLAN,ROW$TOT_EPI_SCRAP>*DaysWorked),'MD0')	;* <- 1/15/2008 JCH
				DataArray<COL$QTD_PPA_OVER_UNDER,ROW$TOT_EPI_SCRAP> = OCONV(QTDOverUnder,'MD0,')															;* <- 1/15/2008 JCH
			END
			
			* * *  Total Out Row  * * * * * *
			
			QTDRem = (ICONV(DataArray<COL$QTD_PPA_PLAN,ROW$TOT_OUT>,'MD0') - ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_OUT>,'MD0'))
			MRPRem = (ICONV(DataArray<COL$QTY_MRP_PLAN,ROW$TOT_OUT>,'MD0') - ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_OUT>,'MD0'))
			
			IF PlanDaysRem = 0 THEN MRPDailyPlan = 0 ELSE MRPDailyPlan = MRPRem/PlanDaysRem
			
			
			IF PlanWorkingDays = 0 THEN
				OrgDailyPlan = 0
				QtyMrpPlan = 0
			END ELSE
				OrgDailyPlan = ICONV(DataArray<COL$QTD_PPA_PLAN,ROW$TOT_OUT>,'MD0')/PlanWorkingDays
				QtyMrpPlan = ICONV(DataArray<COL$QTY_MRP_PLAN,ROW$TOT_OUT>,'MD0')/PlanWorkingDays
			END
			
			DataArray<COL$QTD_PPA_REMAIN,ROW$TOT_OUT> = OCONV(QTDRem,'MD0,')
			DataArray<COL$QTD_MRP_REMAIN,ROW$TOT_OUT> = OCONV(MRPRem,'MD0,')
			
			DataArray<COL$MRP_DAILY_PLAN,ROW$TOT_OUT> = OCONV(ICONV(MRPDailyPlan,'MD0'),'MD0')
			DataArray<COL$ORG_PPA_DAILY_PLAN,ROW$TOT_OUT> = OCONV(ICONV(OrgDailyPlan,'MD0'),'MD0')
			
			IF OrgDailyPlan NE 0 THEN
				QTDOverUnder = ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_OUT> - (DataArray<COL$ORG_PPA_DAILY_PLAN,ROW$TOT_OUT>*DaysWorked),'MD0')	;* <- 1/15/2008 JCH
				DataArray<COL$QTD_PPA_OVER_UNDER,ROW$TOT_OUT> = OCONV(QTDOverUnder,'MD0,')														;* <- 1/15/2008 JCH
			END
			
			IF QtyMrpPlan NE 0 THEN
				MRPOverUnder = ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_OUT> - (QtyMrpPlan*DaysWorked),'MD0')										;* <- 1/15/2008 JCH
				DataArray<COL$QTD_MRP_OVER_UNDER,ROW$TOT_OUT> = OCONV(MRPOverUnder,'MD0,')														;* <- 1/15/2008 JCH
			END
			
			
			* End of Planning Calcs
			
			IF RDSFiscalWeek = FiscalWeek THEN
				
				IF DayCol NE '' THEN
					DataArray<DayCol,ROW$TOT_OUT>			= DataArray<DayCol,ROW$TOT_OUT> + WafersOut
					DataArray<DayCol,ROW$TOT_CUST_SCRAP>	= DataArray<DayCol,ROW$TOT_CUST_SCRAP> + CustScrap
					DataArray<DayCol,ROW$TOT_EPI_SCRAP>		= DataArray<DayCol,ROW$TOT_EPI_SCRAP> + IREpiScrap
					DataArray<DayCol,ROW$TOT_OTHER>			= DataArray<DayCol,ROW$TOT_OTHER> + OtherWafers
					DataArray<DayCol,ROW$TOT_PRIME_TW>		= DataArray<DayCol,ROW$TOT_PRIME_TW> + PrimeTW
					DataArray<DayCol,ROW$TOT_RECLAIM_TW>	= DataArray<DayCol,ROW$TOT_RECLAIM_TW> + ReclaimTW
					
					IF DataArray<DayCol,ROW$TOT_OUT> > 0 THEN
						Yield = DataArray<DayCol,ROW$TOT_OUT>/(DataArray<DayCol,ROW$TOT_OUT> + DataArray<DayCol,ROW$TOT_EPI_SCRAP>)
					END ELSE
						Yield = 0
					END
					
					DataArray<DayCol,ROW$TOT_YIELD>	= OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
				END
					
				DataArray<COL$WTD_ACTUAL,ROW$TOT_OUT>			= DataArray<COL$WTD_ACTUAL,ROW$TOT_OUT> + WafersOut
				DataArray<COL$WTD_ACTUAL,ROW$TOT_CUST_SCRAP>	= DataArray<COL$WTD_ACTUAL,ROW$TOT_CUST_SCRAP> + CustScrap
				DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>		= DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP> + IREpiScrap
				DataArray<COL$WTD_ACTUAL,ROW$TOT_OTHER>			= DataArray<COL$WTD_ACTUAL,ROW$TOT_OTHER> + OtherWafers
				DataArray<COL$WTD_ACTUAL,ROW$TOT_PRIME_TW>		= DataArray<COL$WTD_ACTUAL,ROW$TOT_PRIME_TW> + PrimeTW
				DataArray<COL$WTD_ACTUAL,ROW$TOT_RECLAIM_TW>	= DataArray<COL$WTD_ACTUAL,ROW$TOT_RECLAIM_TW> + ReclaimTW
				
				IF DataArray<COL$WTD_ACTUAL,ROW$TOT_OUT> > 0 THEN
					Yield = DataArray<COL$WTD_ACTUAL,ROW$TOT_OUT>/(DataArray<COL$WTD_ACTUAL,ROW$TOT_OUT> + DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>)
				END ELSE
					Yield = 0
				END
				
				DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD>	= OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
				
				* Scrap Rate
				
				IF DataArray<COL$WTD_ACTUAL,ROW$TOT_OUT> > 0 THEN
					ScrapRate = (DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>/DataArray<COL$WTD_ACTUAL,ROW$TOT_OUT>)*1000
				END ELSE
					ScrapRate = 0
				END
				
				DataArray<COL$WTD_ACTUAL,ROW$TOT_SCRAP_RATE> = OCONV(ICONV(ScrapRate,'MD2'),'MD2')
															
			END		;*	End of check for current fiscal week
			
		END		;* End of check for Customer exclusion

	END	;* End of RDS Record read
	
	Running = Msg(@WINDOW, MsgUp, LoopCnt, MSGINSTUPDATE$) 
	
	
UNTIL ReactRunKeys = '' OR NOT(Running)
REPEAT


FOR I = ROW$TOT_OUT TO ROW$TOT_OTHER
	FOR J = COL$MON TO COL$QTD_ACTUAL
		DataArray<J,I> = OCONV(DataArray<J,I>,'MD0,Z')
	NEXT J
NEXT I

Msg(@WINDOW,MsgUp)

xlApp = OleCreateInstance("excel.Application")								;* Create instance of Excel
OlePutProperty(XlApp, 'Visible', xlSheetVisible)
if OleStatus() then Goto HadError

xlWorkBooks =OleGetProperty(xlApp, "Workbooks")								;* Create workbook
xlWkb = OleCallMethod(xlWorkbooks,"Add")
if OleStatus() then Goto HadError

xlSht = OleGetProperty(xlWkb, "Worksheets",1)								;* Select worksheet 1
if OleStatus() then Goto HadError

xlPageSetup = OleGetProperty(xlSht,"PageSetup")								;* Get PageSetup object for Page/Printing stuff
if OleStatus() then GOTO HadError

OlePutProperty( xlPageSetup , 'PrintGridLines', xlTrue )										;* Print Gridlines on
OlePutProperty( xlPageSetup , 'Orientation' , xlLandscape )										;* Orientation to Landscape
OlePutProperty( xlPageSetup , 'HeaderMargin', '20')												;* HeaderMargin to 20pts

OlePutProperty( xlPageSetup , 'CenterHeader' , '&14Epi SERVICES - Thruput Report - w/o Makeup Activity' )		;* Set Center Header
OlePutProperty( xlPageSetup , 'LeftHeader' , '&G' )												;* Set graphic in Left Header

graphic = OleGetProperty( xlPageSetup , 'LeftHeaderPicture' )									;* Get graphic object for Left Header Picture
OlePutProperty( graphic , 'FileName' , 'R:\Oinsight\BMPS\EpiSvcs.png' )							;* Set filename for graphic
OlePutProperty( graphic , 'Height' , '51.75' )													;* Scale graphic to fit header		
OlePutProperty( graphic , 'Width' , '81')

OlePutProperty( xlPageSetup , 'RightHeader' , 'Page &P' )					;* Set Right Header to show current page number

ColCnt = COUNT(DataArray,@FM) + (DataArray NE '')
LineCnt = COUNT(DataArray<1>,@VM) + (DataArray<1> NE '')
FOR LineNo = 1 TO LineCnt
	FOR Column = 1 to ColCnt
		RangeColumn = eXcelCols<1,Column>
		range = OleGetProperty( xlSht, 'Range',RangeColumn:LineNo)
		OlePutProperty(range, 'Value', DataArray<Column,LineNo>)			;* Load report array into spreadsheet cells
		IF OleStatus() THEN GOTO HadError
	NEXT Column
NEXT LineCnt

LastColumn = eXcelCols<1,ColCnt>
range = OleGetProperty( xlSht, 'Range','B1:':LastColumn:'1')				;* Turn on word wrap in columns from B through end
OlePutProperty( range, 'WrapText', xlTrue)
IF OleStatus() THEN GOTO HadError

RangeColumn = eXcelCols<1,ColCnt>
range = OleGetProperty( xlSht, 'Range','A1:':RangeColumn:LineCnt)

Void = OleCallMethod( range, 'AutoFormat', xlRangeAutoFormatClassic1 )		;* Turn on autoformat (FormatClassic1)
IF OleStatus() THEN GOTO HadError


FOR I = COL$MON TO COL$SUN
	eXcelCol = eXcelCols<1,I>
	column = OleGetProperty( xlSht, 'Range' , eXcelCol:':':exCelCol )		;* Set the day columns to a standard width
	OlePutProperty( column , 'ColumnWidth' , '10.3' )
	a = OleStatus()
NEXT I


EdgeList = xlDiagonalDown:@VM:xlDiagonalup:@VM:xlEdgeLeft:@VM:xlEdgeTop:@VM:xlEdgeRight:@VM:xlInsideVertical

* Put border on the BOTTOM of this row

range = OleGetProperty( xlSht, 'Range', 'A':ROW$TOT_RECLAIM_TW:':':RangeColumn:ROW$TOT_OUT)

FOR I = 1 TO COUNT(EdgeList,@VM) + (EdgeList NE '')
	edge = OleGetProperty( range, 'Borders' , EdgeList<1,I> )
	OlePutProperty( edge , 'LineStyle' , xlLineStyleNone )					;* Clear border segments EXCEPT bottom
	IF OleStatus() THEN debug
NEXT I

edge = OleGetProperty( range, 'Borders' , xlEdgeBottom )					;* Set border segment for bottom to medium weight line
olePutProperty( edge , 'LineStyle', xlContinuous )
olePutProperty( edge , 'Weight' , xlMedium )
olePutProperty( edge , 'ColorIndex', xlColorIndexAutomatic )

range = OleGetProperty( xlSht, 'Range', 'A':ROW$MER_RECLAIM_TW:':':RangeColumn:ROW$TOT_OUT)	;* Set border for range (underline entire row)

FOR I = 1 TO COUNT(EdgeList,@VM) + (EdgeList NE '')
	edge = OleGetProperty( range, 'Borders' , EdgeList<1,I> )				
	OlePutProperty( edge , 'LineStyle' , xlLineStyleNone )
NEXT I

edge = OleGetProperty( range, 'Borders' , xlEdgeBottom )
olePutProperty( edge , 'LineStyle', xlContinuous )
olePutProperty( edge , 'Weight' , xlMedium )
olePutProperty( edge , 'ColorIndex', xlColorIndexAutomatic )





* Void = OleCallMethod( xlWkb, 'SaveAs','C:\OIReports\ThruPut.xls', xlWorkbookNormal )		;* Save to local drive
Void = OleCallMethod( xlWkb, 'SaveAs',Environment_Services('GetReportsRootPath') : '\ThruPut.xls', xlWorkbookNormal )		;* Save to local drive

RETURN

* * * * * * *
HadError:
* * * * * * *

xlChart = ''
Charts = ''
range = ''
xlSht = ''
xlWkb=''
xlWorkBooks = ''
x = OleCallMethod(xlApp, 'Quit')

RETURN 

/* end of code */

*


/*
* Insert 4 blank rows at the top

range = OleGetProperty( xlSht, 'Range','1:1')
rows = OleGetProperty( range, 'Rows' )

void = OleCallMethod( rows, 'Insert', xlShiftDown )
void = OleCallMethod( rows, 'Insert', xlShiftDown )
void = OleCallMethod( rows, 'Insert', xlShiftDown )
void = OleCallMethod( rows, 'Insert', xlShiftDown )

* Merge the 4 rows and setup for header text

range = OleGetProperty( xlSht, 'Range','A1:':LastColumn:'4')
OlePutProperty( range , 'HorizontalAlignment' , xlCenter )
OlePutProperty( range , 'VerticalAlignment' , xlCenter )
OlePutProperty( range , 'WrapText' , xlFalse )
OlePutProperty( range , 'Orientation' , '0' )
OlePutProperty( range , 'AddIndent' , xlFalse )
OlePutProperty( range , 'IndentLevel' , '0' )
OlePutProperty( range , 'ShrinkToFit' , xlFalse )
OlePutProperty( range , 'ReadingOrder' , xlContext )
OlePutProperty( range , 'MergeCells' , xlTrue )

font = OleGetProperty( range , 'Font' )
OlePutProperty( font , 'Name' , 'Arial' )
OlePutProperty( font , 'FontStyle' , 'Bold' )
OlePutProperty( font , 'Size' , '12' )
OlePutProperty( font , 'Strikethrough' , xlFalse )
OlePutProperty( font , 'Superscript' , xlFalse )
OlePutProperty( font , 'Subscript' , xlFalse )
OlePutProperty( font , 'OutlineFont' , xlFalse )
OlePutProperty( font , 'Shadow' , xlFalse )
OlePutProperty( font , 'Underline' , xlUnderLineStyleNone )
OlePutProperty( font , 'ColorIndex' , xlAutomatic )


range = OleGetProperty( xlSht, 'Range','A1:':LastColumn:'4')
OlePutProperty(range, 'Value', 'Thruput Report - w/o Makeup Activity')							;* Put the title text in

pictures = OleGetProperty( xlSht , 'Pictures' )
void = OleCallMethod( pictures , 'Insert' , 'R:\Oinsight\BMPS\EpiSvcs.png' )					;* Insert graphic in u/l corner

shapes = OleGetProperty( xlSht , 'Shapes' )														;* This is a collection
shaperange = OleGetProperty( shapes , 'Range' , '1' )											;* This selects 1 or more of the collection to work with
void = OleCallMethod( shaperange , 'ScaleWidth' , '0.41' , msoFalse , msoScaleFromTopLeft )		;* Scale the graphic to fit in the 4 line header
void = OleCallMethod( shaperange , 'ScaleHeight' , '0.41' , msoFalse , msoScaleFromTopLeft )
*/





