Function Import_6in_Retained_Wafers_Date()
#pragma precomp SRP_PreCompiler

Declare subroutine Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, Send_Message, Logging_Services
Declare subroutine Btree.Extract, Send_Event, Security_Err_Msg, Forward_Event, End_Window, Start_Window, FTP_Services
Declare subroutine EditCell, obj_NCR, obj_Notes, Post_Event, obj_WO_Mat, obj_WO_Mat_Log, obj_WO_Wfr, obj_Tables, obj_RDS
Declare subroutine Error_Services, RDS_Services, Dialog_Box, Insert, Unlock, QA_Services, Validate, Development_Services
Declare subroutine Update_Index, Database_Services, Obj_WO_Mat_QA, Fmt, Yield, WinYield, Sleepery, Qa_Services, Reactor_Services
Declare subroutine Obj_Post_Log, GaN_Services, Excel_Services, obj_WO_React, Activate_Save_Select, Reduce, FSMsg
Declare subroutine SRP_Stopwatch
Declare function Get_Property, Get_Status, Popup, Send_Message, Msg, Security_Check, Dialog_Box, RowExists, Utility
Declare function Dialog_Box, obj_WO_Log, obj_NCR, Check_Notes, obj_MUWafers, obj_WO_Mat, Error_Services, RDS_Services
Declare function MemberOf, obj_Tables, obj_RDS, Environment_Services, Logging_Services, Material_Services, ErrMsg
Declare function Work_Order_Services, RetStack, Min, Max, Obj_Prod_Spec, Insert, SRP_Trim, Xlate, Obj_Wo_Mat
Declare function Security_Services, QA_Services, Database_Services, RowExists, Rti_Lh_Info, UNICODE_ANSI, UNICODE_UTF8
Declare function index, Httpclient_Services, SRP_Encode, SRP_Decode, DirList, Obj_Rds_Test, Tool_Parms_Services
Declare function SQL_Services, RDS_Services, Obj_WM_out, Schedule_Services, Obj_Tool, SRP_Sort_Array, ICONV
Declare function Development_Services, Obj_WO_Mat_QA, SRP_Join_Arrays, NextKey, Obj_Prod_Spec, FTP_Services, SQL_Format
Declare Function DateTime, GaN_Services, SRP_Array, Excel_Services, EpiPro_Services, Repository

Declare subroutine SRP_Stopwatch, Btree.Extract


$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT WM_IN_EQUATES
$Insert WM_OUT_EQUATES
$INSERT WO_LOG_EQU
$INSERT WO_STEP_EQU
$INSERT WO_MAT_EQUATES
$INSERT ORDER_EQU
$INSERT RDS_EQUATES
$INSERT PROD_SPEC_EQU
$INSERT NOTIFICATION_EQU
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT RTI_LH_INFO_EQUATES
$INSERT WO_MAT_QA_EQUATES
$INSERT CUST_EPI_PART_EQUATES
$INSERT PRS_STAGE_EQUATES
$Insert RLIST_EQUATES
$Insert CLEAN_INSP_EQUATES
$Insert TOOL_PARMS_EQUATES
$Insert SCHEDULE_EQU
$Insert SCHED_DET_EQUATES
$Insert SCHEDULER_EQUATES
$Insert NCR_EQUATES
$Insert REACT_RUN_EQUATES
$Insert TOOL_EQUATES
$Insert TOOL_LOG_EQUATES
$Insert PM_EQUATES
$Insert WO_WFR_EQUATES

// Reduce modes (for Select statement)
Equ NEW_EXIST$ To 0 
Equ NEXT_CUR$  To 1
Equ ADD_EXIST$ To 2   

EQU COL$QA_MET_PHASE_MIN TO 17

Equ Tab$                    to \09\
Equ CRLF$                   to \0D0A\
Equ LF$                     to \0A\
Equ Comma$                  to ','

Main:

    // Import 6 inch Excel spreadsheet
    If @User4 EQ 'DAN_CR' then debug
    RetainFilepath    = 'D:\Apps\Temp\6in-IFEPI GaN Retain Inventory.xlsx'
    RetainExcelHandle = Excel_Services('OpenDocument', RetainFilepath)
    RetainWorksheet   = 'Sheet1'
    NumExcelRows      = Excel_Services('GetNumRows', RetainExcelHandle, RetainWorksheet)
    
    Open 'DICT.REACT_RUN' to @DICT then
        For ExcelRow = 2 to NumExcelRows
            RunID        = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'A', ExcelRow) )
            Convert @Upper.Case to @Lower.Case in RunID
            RDSNo        = ''
            Column       = 'GAN_RUN_ID'
            SearchString = Column:@VM:RunID:@FM
            Btree.Extract(SearchString, 'REACT_RUN', @DICT, RDSNo)
            If RDSNo NE '' then
                ReactRunRec = Database_Services('ReadDataRow', 'REACT_RUN', RDSNo)
                If Error_Services('NoError') then
                    RRRecipe  = ReactRunRec<REACT_RUN_GAN_RECIPE$>
                    RRPart    = Xlate('REACT_RUN', RDSNo, 'EPI_PART_NO', 'X')
                    RRScribes = Xlate('REACT_RUN', RDSNo, 'WFR_SCRIBES', 'X')
                    InWfrIDs  = ReactRunRec<REACT_RUN_IN_WFR_ID$>

                    * Read the data from the Excel retain spreadsheet *                 
                    Pocket     = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'C', ExcelRow) )
                    If Pocket _NEC 'ref' then
                                       
                        RetainDTM  = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'K', ExcelRow) )
                        // Truncate DTM to just the date, then convert to internal format
                        RetainDate = RetainDTM[1, 'F ']
                        RetainDate = IConv(RetainDate, 'D')

                        // Format the Pocket                    
                        If Pocket[1, 1] NE '0' then Pocket = '0':Pocket
                       
                        * Write the data to the WO_WFR record *
                        WfrIndex = Pocket + 0 ; // Convert string to integer and trim 0 padding                       
                        RRScribe = RRScribes<0, WfrIndex>  
                        WfrID    = InWfrIDs<0, WfrIndex>
                        WOWfrRec = Database_Services('ReadDataRow', 'WO_WFR', WfrID)
                        If Error_Services('NoError') then
                            WOWfrRec<WO_WFR_RETAIN_DT$> = RetainDate
                            Database_Services('WriteDataRow', 'WO_WFR', WfrID, WOWfrRec, True$, False$, True$)
                        end                
                    end
                end
            end
        Next ExcelRow
    end 
    Excel_Services('CloseDocument', RetainExcelHandle)

return 

