Function SRP_Import_Old_Schedule(void)
/******************************************************************************************************** 

    This program is proprietary and is not to be used by or disclosed to others, nor is it to
    be copied without written permission from SRP Computer Solutions, Inc.

    Name        :   Import Old Schedule

    Description :   Imports the old schedule (CONFIG, WO_MAST_SCHED) into the new WO_MAST_SCHED table

    Tags    	:   [SRP]

    Parameters  :

    History (Date, Initials, Notes)
        09/17/08    fjt     Initial development
        09/18/17    dmb     Re-purpose to import from SCHED_DET into SCHEDULER.

********************************************************************************************************/
#pragma precomp SRP_PreCompiler

$insert SRP_APP_INSERTS
$insert SCHED_DET_EQUATES
$insert SCHEDULER_EQUATES
$insert WO_SCHEDULE_EQUATES

Equ SECONDS_PER_DAY$        to 86400
Equ MIDNIGHT_AM$            to 0        ; // Midnight represented as the beginning of the day.
Equ MIDNIGHT_PM$            to 86400    ; // Midnight represented as the end of the day.
Equ SIX_AM$                 to 21600
Equ NOON$                   to 43200
Equ SIX_PM$                 to 64800

Declare function    Database_Services, Memory_Services, Schedule_Services
Declare subroutine  Database_Services, Memory_Services
Debug
SchedDetKeyIDs  = Database_Services('SearchIndex', 'SCHED_DET', 'SCHED_DT', '>01/01/2017', True$)
For Each SchedDetKeyID in SchedDetKeyIDs
    ReactorNo       = SchedDetKeyID[1, '*']
    ScheduleDate    = SchedDetKeyID[Col2() + 1, '*']
    SequenceNo      = SchedDetKeyID[Col2() + 1, '*']
    SchedDetRow     = Schedule_Services('GetScheduleDetail', SchedDetKeyID)
    WorkOrderNo     = SchedDetRow<SCHED_DET_WO_NO$>
    If WorkOrderNo NE '' then
        If Memory_Services('GetValue', ReactorNo : '*' : WorkOrderNo) NE True$ then
            WOScheduleRow   = Database_Services('ReadDataRow', 'WO_SCHEDULE', WorkOrderNo)
            WorkOrderKeys   = WOScheduleRow<WO_SCHEDULE_SCHED_DET_KEY_IDS$>
            Convert @VM to @FM in WorkOrderKeys
            ReactorKeys     = ''
            For Each WorkOrderKey in WorkOrderKeys using @FM
                thisReactorNo   = WorkOrderKey[1, '*']
                If thisReactorNo EQ ReactorNo then
                    ReactorKeys    := WorkOrderKey : @FM
                end
            Next WorkOrderKey
            ReactorKeys[-1, 1]  = ''
            If ReactorKeys NE '' then
                FirstScheduleDate   = Field(ReactorKeys<1>, '*', 2)
                If FirstScheduleDate EQ ScheduleDate then
                    SchedulerRow                            = ''
                    NumDays                                 = DCount(ReactorKeys, @FM)
                    SchedulerRow<SCHEDULER.END_DATE$>       = ScheduleDate + (NumDays - 1)
                    SchedulerRow<SCHEDULER.WO_STEP$>        = SchedDetRow<SCHED_DET_WO_STEP$>
                    SchedulerRow<SCHEDULER.CASSETTE_NO$>    = SchedDetRow<SCHED_DET_CASS_NO$>
                    SchedulerRow<SCHEDULER.DESCRIPTION$>    = SchedDetRow<SCHED_DET_DESC$>
                    SchedulerRow<SCHEDULER.MODIFIED$>       = SchedDetRow<SCHED_DET_MODIFIED$>
                    SchedulerRow<SCHEDULER.BLOCK_OUT$>      = SchedDetRow<SCHED_DET_BLOCK_OUT$>
                    SchedulerRow<SCHEDULER.BLOCK_OUT_TYPE$> = SchedDetRow<SCHED_DET_BLOCK_OUT_TYPE$>
                    SchedulerRow<SCHEDULER.BACKCOLOR$>      = SchedDetRow<SCHED_DET_BACKCOLOR$>
                    SchedulerRow<SCHEDULER.FORECOLOR$>      = SchedDetRow<SCHED_DET_FORECOLOR$>
                    SchedulerRow<SCHEDULER.START_TIME$>     = MIDNIGHT_AM$
                    SchedulerRow<SCHEDULER.END_TIME$>       = MIDNIGHT_PM$
                    SchedulerRow<SCHEDULER.WAFER_COUNT$>    = ''
                    SchedulerKeyID                          = ReactorNo : '*' : ScheduleDate : '*' : WorkOrderNo
                    Database_Services('WriteDataRow', 'SCHEDULER', SchedulerKeyID, SchedulerRow, True$)
                    Memory_Services('SetValue', ReactorNo : '*' : WorkOrderNo, True$)
                end
            end
        end
    end
Next SchedDetKeyID

Return Ans OR ''
