Compile function Archive_Services(@Service, @Params)
#pragma precomp SRP_PreCompiler
$insert LOGICAL
$insert APP_INSERTS
EQU COMMA$ To ','

Declare subroutine Change_Log_Services, Logging_Services
Declare function SRP_Datetime, Logging_Services, Environment_Services, Datetime

LogPath     = Environment_Services('GetApplicationRootPath') : '\LogFiles\Archive'
LogDate     = Oconv(Date(), 'D4/')
LogTime     = Oconv(Time(), 'MTS')
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' ArchiveService.csv'
Headers     = 'Logging DTM' : @FM : 'Message' : @FM : 'Cutoff Date'
objLogArchiveService      = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, Comma$, Headers, '', False$, False$)
LoggingDTM  = LogDate : ' ' : LogTime   ; // Logging DTM

GoToService

Return Response or ""

//-----------------------------------------------------------------------------
// SERVICES
//-----------------------------------------------------------------------------

Service ArchiveRecords()
	Errors = ''
	StatusMessage = 'Starting Archive Script.'
    LogData    = ''
	LogData<1> = LoggingDTM
	LogData<2> = StatusMessage
	Logging_Services('AppendLog', objLogArchiveService, LogData, @RM, @FM)
    
    //Archive Change Log Records
    GoSub ChangeLogArchive
    
    //Finish
    Locate True$ in Errors using @FM setting ePos then
    	StatusMessage = 'Archive script complete. Errors detected. Check individual archive logs for more info.'
		LogData    = ''
		LogData<1> = LoggingDTM
		LogData<2> = StatusMessage
		Logging_Services('AppendLog', objLogArchiveService, LogData, @RM, @FM)
    end else
    	StatusMessage = 'Archive script complete. No errors detected.'
		LogData    = ''
		LogData<1> = LoggingDTM
		LogData<2> = StatusMessage
		Logging_Services('AppendLog', objLogArchiveService, LogData, @RM, @FM)
    end
    
End Service

Service DearchiveRecord(Table, ID)
	
end service

ChangeLogArchive:
	StatusMessage = 'Starting Change_Log Archive Script.'
    LogData    = ''
	LogData<1> = LoggingDTM
	LogData<2> = StatusMessage
	Logging_Services('AppendLog', objLogArchiveService, LogData, @RM, @FM)
    ChangeLogArchiveDate = SRP_Datetime('AddYears', Datetime(), -1)
    Change_Log_Services('ArchiveChangeLogRecByDate', ChangeLogArchiveDate)
    If Error_Services('NoError') then
    	StatusMessage = 'Starting Change_Log Archive Script.'
		LogData    = ''
		LogData<1> = LoggingDTM
		LogData<2> = StatusMessage
		Logging_Services('AppendLog', objLogArchiveService, LogData, @RM, @FM)
    end else
    	StatusMessage = 'Error in Change_Log Archive Script.'
		LogData    = ''
		LogData<1> = LoggingDTM
		LogData<2> = StatusMessage
		Logging_Services('AppendLog', objLogArchiveService, LogData, @RM, @FM)
		Errors<-1> = True$
    end
return





