open-insight/LSL2/STPROC/SUPPLEMENT_SERVICES.txt

602 lines
24 KiB
Plaintext

Compile function Supplement_Services(@Service, @Params)
/***********************************************************************************************************************
Name : Supplement_Services
Description : Handler program for all Supplement services.
Notes : Application errors should be logged using the Error Services module. There are a few methodological
assumptions built into way errors are managed which are important to understand in order to properly
work with Error Services:
- The term 'top' refers to the originating procedure of a call stack and the term 'bottom' refers to
the last routine (or the current routine) within a call stack. Within the OpenInsight Debugger
this will appear backwards since the originating procedure always appears at the bottom of the
list and the current routine appears at the top of the list. We are using this orientation because
it is common to refer to the process of calling other procedures as 'drilling down'.
- The reason for defining the orientation of the call stack is because Error_Services allows for
multiple error conditions to be appended to an original error. In most cases this will happen when
a procedure at the bottom of the stack generates an error condition and then returns to its
calling procedure. This higher level procedure can optionally add more information relevant to
itself. This continues as the call stack 'bubbles' its way back to the top to where the
originating procedure is waiting.
- Native OpenInsight commands that handle errors (e.g., Set_Status, Set_FSError, Set_EventStatus)
preserve their error state until explicitly cleared. This can hinder the normal execution of code
since subsequent procedures (usually SSPs) will fail if a pre-existing error condition exists.
Our philosophy is that error conditions should automatically be cleared before a new procedure
is executed to avoid this problem. However, the nature of Basic+ does not make this easy to
automate for any given stored procedure. Therefore, if a stored procedure wants to conform to our
philosophy then it should include a call into the 'Clear' service request at the top of the
program. Alternatively this can be done through a common insert (see SERVICE_SETUP for example.)
- Service modules will use the SERVICE_SETUP insert and therefore automatically clear out any
error conditions that were set before.
Parameters :
Service [in] -- Name of the service being requested
Param1-10 [in/out] -- Additional request parameter holders
Response [out] -- Response to be sent back to the Controller (MCP) or requesting procedure
Metadata :
History : (Date, Initials, Notes)
3/20/24 djm Original programmer.
***********************************************************************************************************************/
#pragma precomp SRP_PreCompiler
$insert APP_INSERTS
$Insert SERVICE_SETUP
$Insert SUPPLEMENTS_EQUATES
Equ COMMA$ to ','
Declare function Database_Services, Supplement_Services, Rti_Createguid, SRP_Array, Datetime, Signature_Services
Declare function Environment_Services, Logging_Services, Select_Into
Declare subroutine Database_Services, RList, Rds_Services, Supplement_Services, Logging_Services, Set_Status, SRP_Stopwatch
GoToService else
Error_Services('Add', Service : ' is not a valid service request within the ' : ServiceModule : ' module.')
end
Return Response or ''
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Service Parameter Options
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Options LOTTYPES = 'RDS', 'WO_MAT'
Options STAGES = 'VER', 'PREC','PREI', 'PRES', 'LOAD', 'FWII', 'FWIS', 'UNLOAD', 'LWII', 'LWIS', 'PSTC', 'PSTI', 'PSTS', 'QA', 'POST'
//-----------------------------------------------------------------------------
// SERVICES
//-----------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
// CreateSupplement
//
// LotType - [Required]
// LotID - [Required]
// Stage - [Required]
// SupplText - [Required]
// EntryUser - [Required]
//
// Create a new Supplement Record.
//
//----------------------------------------------------------------------------------------------------------------------
Service CreateSupplement(LotType=LOTTYPES, LotID, Stage=STAGES, SupplText, EntryUser)
WriteNeeded = True$
Stages = Supplement_Services('GetStagesForLot', LotType, LotID)
If Stages NE False$ then
StageCheck = Count(Stages<1>, Stage)
If LotType NE '' AND LotID NE '' AND SupplText NE '' AND EntryUser NE '' then
Existing = Supplement_Services('GetSupplementsForLot', LotType, LotID, Stage)
If StageCheck NE 0 Then
If Existing EQ FALSE$ then
SupplID = Rti_Createguid()
end else
SupplID = Existing
OrigText = Xlate("SUPPLEMENTS", SupplID, SUPPLEMENTS_SUPPL_TEXT$, 'X', '')
If OrigText EQ SupplText then
WriteNeeded = FALSE$
Response = FALSE$
end
end
end
If WriteNeeded then
NewSupRec = ''
NewSupRec<SUPPLEMENTS_LOT_TYPE$> = LotType
NewSupRec<SUPPLEMENTS_LOT_ID$> = LotID
NewSupRec<SUPPLEMENTS_STAGE$> = Stage
NewSupRec<SUPPLEMENTS_SUPPL_TEXT$> = SupplText
NewSupRec<SUPPLEMENTS_ENTRY_USER$> = EntryUser
NewSupRec<SUPPLEMENTS_ENTRY_DATETIME$> = Datetime()
Database_Services('WriteDataRow', 'SUPPLEMENTS', SupplID, NewSupRec, True$, False$, False$)
If Error_Services('NoError') then
Response = SupplID
If Existing EQ FALSE$ then
Supplement_Services('LogSupplementChange', NewSupRec, 'Created', EntryUser)
end else
Supplement_Services('LogSupplementChange', NewSupRec, 'Edited', EntryUser)
end
end else
Response = FALSE$
Error_Services('Add', 'Error creating Supplement record.')
end
end
end else
Response = FALSE$
Error_Services('Add', 'LotType, LotID, Stage, SupplText or EntryUser was missing in the ' : Service : ' service.')
end
end else
Response = FALSE$
Error_Services('Add', 'Supplements can only be added to stages associated with the specified lot.')
end
End Service
//----------------------------------------------------------------------------------------------------------------------
// GetStagesWithSupplements
//
// LotType - [Required]
// LotID - [Required]
//
// Returns an array of stages with supplements associated for a given lot
//
//----------------------------------------------------------------------------------------------------------------------
Service GetStagesWithSupplements(LotType=LOTTYPES, LotID)
If LotType NE '' and LotID NE '' then
Statement = 'SELECT SUPPLEMENTS WITH LOT_TYPE EQ ' :Quote(LotType): ' AND WITH LOT_ID EQ ' :Quote(LotID)
ClearSelect
Rlist(Statement, 5, '', '', '')
If @RecCount NE 0 and @List_Active EQ 3 then
StageList = ''
Cursor = ''
Done = 0
Open 'SUPPLEMENTS' To FileVar then
Loop
ReadNext Key Using Cursor Else Done = True$
Until Done do
Read SuppRec from FileVar, Key then
StageList<-1> = SuppRec<SUPPLEMENTS_STAGE$>
end
Repeat
End
If StageList NE '' then
Response = StageList
end else
Response = False$
end
end else
Set_Status(0)
Response = FALSE$
end
end else
Response = FALSE$
Error_Services('Add', 'LotType or LotID was missing in the ' : Service : ' service.')
end
end service
//----------------------------------------------------------------------------------------------------------------------
// GetLotsWithSupplements
//
// LotType - [Required]
//
// Returns an array of lots with associated Supplements.
//
//----------------------------------------------------------------------------------------------------------------------
Service GetLotsWithSupplements(LotType)
ClearSelect
Statement = 'LIST SUPPLEMENTS WITH LOT_TYPE EQ ' :Quote(LotType): ' BY LOT_ID LOT_ID'
Lots = Select_Into(Statement, 'EDT')
If Lots NE '' then
FlipLots = SRP_Array('Rotate',Lots)
Lots = FlipLots<2>
Response = SRP_Array('Clean', Lots, "TrimAndMakeUnique", @VM)
end else
Response = FALSE$
Set_Status(0)
end
end service
//----------------------------------------------------------------------------------------------------------------------
// GetSupplementsForLot
//
// LotType - [Required]
// LotID - [Required]
// Stage = [Optional]
//
// Returns an array of Supplement IDs for a lot, or for the stage of a lot.
//
//----------------------------------------------------------------------------------------------------------------------
Service GetSupplementsForLot(LotType=LOTTYPES, LotID, Stage=STAGES)
If LotType NE '' and LotID NE '' then
If Stage EQ '' then
Statement = 'SELECT SUPPLEMENTS WITH LOT_TYPE EQ ' :Quote(LotType): ' AND WITH LOT_ID EQ ' :Quote(LotID)
ClearSelect
Rlist(Statement, 5, '', '', '')
If @RecCount NE 0 and @List_Active EQ 3 then
SupplementList = ''
Stages = Supplement_Services('GetStagesForLot', LotType, LotID)
StageCount = Dcount(Stages<1>, @VM)
For I = 1 to StageCount
SupplementStage = Supplement_Services('GetSupplementsForLot', LotType, LotID, Stages<1,I>)
If SupplementStage NE False$ then SupplementList<-1> = SupplementStage
Next I
If SupplementList NE '' then
Response = SupplementList
end else
Response = False$
end
end else
Set_Status(0)
Response = FALSE$
end
end else
StageSupplementList = ''
Statement = 'SELECT SUPPLEMENTS WITH LOT_TYPE EQ ' :Quote(LotType): ' AND WITH LOT_ID EQ ' :Quote(LotID)
Statement2 = 'SELECT SUPPLEMENTS WITH STAGE EQ ' :Quote(Stage)
ClearSelect
Rlist(Statement, 5, '', '', '')
Rlist(Statement2, 5, '', '', '')
If @RecCount NE 0 and @List_Active EQ 3 then
Cursor = ''
Done = 0
Open 'SUPPLEMENTS' To FileVar then
Loop
ReadNext Key Using Cursor Else Done = True$
Until Done
StageSupplementList<-1> = Key
Repeat
End
If StageSupplementList NE '' then
Response = StageSupplementList
end else
Response = False$
end
end else
Set_Status(0)
Response = FALSE$
end
end
end else
Response = FALSE$
Error_Services('Add', 'LotType or LotID was missing in the ' : Service : ' service.')
end
end service
//----------------------------------------------------------------------------------------------------------------------
// UpdateSupplementText
//
// SupplID - [Required]
// NewText - [Required]
// EntryUser - [Required]
//
// Modify the text of an existing Supplement.
//
//----------------------------------------------------------------------------------------------------------------------
Service UpdateSupplementText(SupplID, NewText, EntryUser)
If SupplID NE '' And NewText NE '' then
OldRec = Xlate('SUPPLEMENTS', SupplID, '', 'X', '')
If OldRec NE '' then
NewRec = OldRec
NewRec<SUPPLEMENTS_SUPPL_TEXT$> = NewText
NewRec<SUPPLEMENTS_ENTRY_USER$> = EntryUser
NewRec<SUPPLEMENTS_ENTRY_DATETIME$> = Datetime()
Database_Services('WriteDataRow', 'SUPPLEMENTS', SupplID, NewRec, True$, False$, False$)
If Error_Services('NoError') then
Response = SupplID
Supplement_Services('LogSupplementChange', OldRec, 'Edited', EntryUser)
end else
Response = FALSE$
Error_Services('Add', 'Error editing Supplement record.')
end
end else
Response = FALSE$
Error_Services('Add', 'Record does not exist.')
end
end else
Response = FALSE$
Error_Services('Add', 'SupplID or NewText was missing in the ' : Service : ' service.')
end
end service
//----------------------------------------------------------------------------------------------------------------------
// DeleteSupplementByByLotStage
//
// EntryUser - [Required]
// LotType - [Required]
// LotID - [Required]
// Stage = [Required]
//
// Delete an existing Supplement.
//
//----------------------------------------------------------------------------------------------------------------------
Service DeleteSupplementByLotStage(EntryUser, LotType=LOTTYPES, LotID, Stage=STAGES)
If LotType NE '' and LotID NE '' and Stage NE '' and EntryUser NE '' then
ExistingSupps = Supplement_Services('GetSupplementsForLot', LotType, LotID, Stage)
If ExistingSupps NE '' then
For Each SupplID in ExistingSupps using @VM
SupplRec = Xlate('SUPPLEMENTS', SupplID, '', 'X', '')
Database_Services('DeleteDataRow', 'SUPPLEMENTS', SupplID, True$, False$)
If Error_Services('NoError') then
Supplement_Services('LogSupplementChange', SupplRec, 'Deleted', EntryUser)
Response = TRUE$
end else
Response = FALSE$
Error_Services('Add', 'Error deleting Supplement record.')
end
Next SupplID
end else
Response = FALSE$
Error_Services('Add', 'Record does not exist.')
end
end else
Response = FALSE$
Error_Services('Add', 'SupplID was missing in the ' : Service : ' service.')
end
end service
//----------------------------------------------------------------------------------------------------------------------
// DeleteSupplementByID
//
// SupplID - [Required]
// EntryUser - [Required]
//
// Delete an existing Supplement.
//
//----------------------------------------------------------------------------------------------------------------------
Service DeleteSupplementByID(SupplID, EntryUser)
If SupplID NE '' then
TestRec = Xlate('SUPPLEMENTS', SupplID, '', 'X', '')
If TestRec NE '' then
Database_Services('DeleteDataRow', 'SUPPLEMENTS', SupplID, True$, False$)
If Error_Services('NoError') then
Supplement_Services('LogSupplementChange', TestRec, 'Deleted', EntryUser)
Response = TRUE$
end else
Response = FALSE$
Error_Services('Add', 'Error deleting Supplement record.')
end
end else
Response = FALSE$
Error_Services('Add', 'Record does not exist.')
end
end else
Response = FALSE$
Error_Services('Add', 'SupplID was missing in the ' : Service : ' service.')
end
end service
//----------------------------------------------------------------------------------------------------------------------
// GetStagesForLot
//
// LotType - [Required]
// LotID - [Required]
//
// Returns an array list of valid stages for validation.
//
//----------------------------------------------------------------------------------------------------------------------
Service GetStagesForLot(LotType=LOTTYPES, LotID)
If LotType NE '' AND LotID NE '' then
Stages = ''
Begin Case
Case LotType EQ 'WO_MAT'
WOMatKey = LotID
Case LotType EQ 'RDS'
RDSRow = Database_Services('ReadDataRow', 'RDS', LotID)
WOMatKey = Xlate('RDS', LotID, 'WO_MAT_KEY', 'X')
End Case
SigProf = Signature_Services('GetSigProfile', WOMatKey, False$, LotID)
Stages = SigProf<1>
Response = Supplement_Services('TranslateStages', Stages)
End else
Error_Services('Add', 'LotType or LotID was missing in the ' : Service : ' service.')
Response = False$
end
end service
//----------------------------------------------------------------------------------------------------------------------
// TranslateStages
//
// ValidStages - Required]
//
// Returns an array of internal and external stages for a lot. <1> = internal, <2> = external.
//
//----------------------------------------------------------------------------------------------------------------------
Service TranslateStages(ValidStages)
If ValidStages NE '' And ValidStages NE False$ And Error_Services('NoError') then
ValidStageArray = ''
ValidStageArray<1> = ValidStages
AllStages = XLATE('SYSREPOSPOPUPS','LSL2**SIG_PROF_KEYS',8,'X')
Swap @VM with @FM in AllStages
Swap @SVM with @VM in AllStages
FlipAllStages = SRP_Array('Rotate', AllStages)
StageCount = DCount(ValidStages, @VM)
For each Stage in ValidStages using @VM setting ValidPOS
Locate Stage in FlipAllStages<1> using @VM setting AllPOS then
ValidStageArray<2,ValidPOS> = FlipAllStages<2,AllPOS>
end
Next Stage
Response = ValidStageArray
End else
Error_Services('Add', 'ValidStages was missing in the ' : Service : ' service.')
Response = FALSE$
end
end service
//----------------------------------------------------------------------------------------------------------------------
// AcknowledgeSupplement
//
// SupplID - [Required]
// EntryUser - [Required]
//
// Acknowledge an existing Supplement.
//
//----------------------------------------------------------------------------------------------------------------------
Service AcknowledgeSupplement(SupplID, EntryUser)
If SupplID NE '' And EntryUser NE '' then
OldRec = Xlate('SUPPLEMENTS', SupplID, '', 'X', '')
If OldRec NE '' then
NewRec = OldRec
NewRec<SUPPLEMENTS_SUPPL_ACK$> = True$
NewRec<SUPPLEMENTS_ACK_USER$> = EntryUser
NewRec<SUPPLEMENTS_ACK_DTM$> = Datetime()
Database_Services('WriteDataRow', 'SUPPLEMENTS', SupplID, NewRec, True$, False$, False$)
If Error_Services('NoError') then
Response = SupplID
Supplement_Services('LogSupplementChange', NewRec, 'Acknowledged', EntryUser)
end else
Response = FALSE$
Error_Services('Add', 'Error editing Supplement record.')
end
end else
Response = FALSE$
Error_Services('Add', 'Record does not exist.')
end
end else
Response = FALSE$
Error_Services('Add', 'SupplID or EntryUser was missing in the ' : Service : ' service.')
end
end service
//----------------------------------------------------------------------------------------------------------------------
// UnacknowledgedSupplementCheck
//
// LotType - [Required]
// LotID - [Required]
// Stage = [Required]
//
// Returns true or false for whether or not there are unacknowledged supplements remaining for a stage.
//
//----------------------------------------------------------------------------------------------------------------------
Service UnacknowledgedSupplementCheck(LotType=LOTTYPES, LotID, Stage=STAGES)
If LotType NE '' and LotID NE '' and Stage NE '' then
Response = ''
Statement = 'SELECT SUPPLEMENTS WITH LOT_TYPE EQ ' :Quote(LotType): ' AND WITH LOT_ID EQ ' :Quote(LotID)
Statement2 = 'SELECT SUPPLEMENTS WITH STAGE EQ ' :Quote(Stage)
ClearSelect
Rlist(Statement, 5, '', '', '')
Rlist(Statement2, 5, '', '', '')
If @RecCount NE 0 and @List_Active EQ 3 then
Unacknowledged = False$
Cursor = ''
Done = 0
Open 'SUPPLEMENTS' To FileVar then
Loop
ReadNext Key Using Cursor Else Done = True$
Until Done
AckField = Xlate('SUPPLEMENTS', Key, 'SUPPL_ACK', 'X', '')
If AckField NE True$ then Unacknowledged = True$
If Unacknowledged EQ True$ then Response<-1> = Key
Repeat
If Response EQ '' then Response = FALSE$
End
end else
Response = FALSE$
Set_Status(0)
end
end else
Response = FALSE$
Error_Services('Add', 'LotType, LotID, or Stage was missing in the ' : Service : ' service.')
end
end service
//----------------------------------------------------------------------------------------------------------------------
// LogSupplementChange
//
// SupplementRec - [Required]
// EditEvent - [Required]
// EntryUser - [Required]
//
// Creates a comment in the lot record logging changes to supplements.
//
//----------------------------------------------------------------------------------------------------------------------
Service LogSupplementChange(SupplementRec, EditEvent, EntryUser)
If SupplementRec NE '' and EditEvent NE '' and EntryUser NE '' then
SupplementText = SupplementRec<SUPPLEMENTS_SUPPL_TEXT$>
LotType = SupplementRec<SUPPLEMENTS_LOT_TYPE$>
LotID = SupplementRec<SUPPLEMENTS_LOT_ID$>
Stage = SupplementRec<SUPPLEMENTS_STAGE$>
LogComment = Stage : ' Supplement ' : Quote(SupplementText) : ' for ' : LotType : ': ': LotID : ' has been ' : EditEvent : ' by User: ' : EntryUser
Begin Case
Case LotType EQ 'RDS'
Rds_Services('AddComment', LotID, LogComment)
Supplement_Services('FileLogSuccessfulSupp', LogComment, EntryUser, EditEvent)
End Case
end else
Error_Services('Add', 'LotType, LotID, or Stage was missing in the ' : Service : ' service.')
end
end service
//----------------------------------------------------------------------------------------------------------------------
// FileLogSuccessfulSupp
//
// LogText- [Required]
// EntryUser - [Required]
//
// Creates a comment in the lot record logging changes to supplements.
//
//----------------------------------------------------------------------------------------------------------------------
Service FileLogSuccessfulSupp(LogText, EntryUser, EditEvent)
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\Supplements'
LogDate = Oconv(Date(), 'D4/')
LogTime = Oconv(Time(), 'MTS')
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' Supplement Changes.csv'
Headers = 'Logging DTM' : @FM : 'User' :@FM: 'Event' : @FM : 'Notes'
objLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, Comma$, Headers, '', False$, False$)
LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
LogData = LoggingDTM :@VM: EntryUser :@VM: EditEvent :@VM: LogText
Logging_Services('AppendLog', objLog, LogData, @FM, @VM)
end service