Function SpecialVacationRequestMake (bIsInteractive As Integer, docRequest As NotesDocument, szErrorMessage As String) As Integer
'==================================================================================================================================
' Purpose: Sets the current Vacation request document into the workflow status WFSTATUS_REQUESTED.
'---------------------------------------------------------------------------------------------------------------------------------
' Arguments:
' bIsInteractive - True for frontend, False for backend
' docRequest - the request document to discard
' szErrorMessage - by reference store a possible error message
'---------------------------------------------------------------------------------------------------------------------------------
' Returns: True, if the action succeeded, False otherwise
'---------------------------------------------------------------------------------------------------------------------------------
' Created by: Bernhard Koehler on 29.08.2010 Modified by:
'---------------------------------------------------------------------------------------------------------------------------------
' Notes: ALL FIELDS MUST BE ALREADY VALIDATED! THIS ROUTINE IS ONLY USED FOR VACATION REQUESTS!
'---------------------------------------------------------------------------------------------------------------------------------
' Changes:
'==================================================================================================================================
Dim docContingent As NotesDocument
Dim docWFSetup As NotesDocument
Dim docSetup As NotesDocument
Dim szRequester As String
Dim szCurrentYear As String
Dim vRLDDates As Variant
Dim vRLDNames As Variant
Dim dblWorkingDaysNo As Double
Dim dblRemainingDays As Double
Dim dblTakenHolidays As Double
Dim dblPlannedHolidays As Double
Dim szTopLevelDecisionRule As String
On Error Goto ErrorRoutine
SpecialVacationRequestMake = False
szRequester = docRequest.Requester (0)
'For this action we need the contingent document for the current year:
szCurrentYear = Cstr (Year (docRequest.StartDate (0)))
'First, make a lookup for an proofed contingent document:
Set docContingent = GetContingentDocument (bIsInteractive, szRequester, szCurrentYear, szErrorMessage)
If docContingent Is Nothing Then
szErrorMessage = "No proofed contingent document found for " & ConvertNames (CN, szRequester) & " / " & szCurrentYear
If bIsInteractive = True Then
Messagebox szErrorMessage, MB_ICONINFORMATION, "Missing contingent"
End If 'of "bIsInteractive = True "
Exit Function
End If
'Is this a proofed contingent ?
If docContingent.Reviewed (0) <> "1" Then
szErrorMessage = "No proofed contingent document found for " & ConvertNames (CN, szRequester) & " / " & szCurrentYear
If bIsInteractive = True Then
Messagebox szErrorMessage, MB_ICONINFORMATION, "Missing contingent"
End If 'of "bIsInteractive = True "
Exit Function
End If
'Is the requested year already closed ?
If docContingent.YearClosed (0) = "1" Then
szErrorMessage = "The year " & szCurrentYear & " was already closed for " & ConvertNames (CN, szRequester) &_
" no request is possible for this year!"
If bIsInteractive = True Then
Messagebox szErrorMessage, MB_ICONINFORMATION, "Year closed"
End If 'of "bIsInteractive = True "
Exit Function
End If
'Read again necessary values from the contingent document:
docRequest.StaffNumber = docContingent.StaffNumber
docRequest.WorkingDays = docContingent.WorkingDays 'The list of weekdays this person has to work
'Check the WorkingDaysNo again:
dblWorkingDaysNo = GetWorkingAndRedLetterDays (docRequest.StartDate (0), docRequest.EndDate (0), docRequest.Region (0), _
docRequest.WorkingDays, vRLDDates, vRLDNames)
If dblWorkingDaysNo < -1 Then
szErrorMessage = "Error in calculating the working days!"
If bIsInteractive = True Then
Messagebox szErrorMessage, MB_ICONINFORMATION, "Error"
End If 'of "bIsInteractive = True "
Exit Function
Else
If dblWorkingDaysNo = 1 Then
'Check if there is a splitted working day:
If Isnumeric (docRequest.WorkingDaySplitted (0)) Then
dblWorkingDaysNo = dblWorkingDaysNo * Cdbl (docRequest.WorkingDaySplitted (0)) / 10
End If
End If
docRequest.WorkingDaysNo = dblWorkingDaysNo
docRequest.RLDDates = vRLDDates
docRequest.RLDNames = vRLDNames
End If
'Check if there are enough holidays left before this request can be made. We respect the following status:
' - Requested
' - Approved
' - Requested - cancelation
' - Cancelation rejected
If docRequest.Form (0) = "Vacation" Then 'Check only in case of holiday requests !
dblRemainingDays = CalculateRemainingHolidays (bIsInteractive, docRequest.Requester (0), Cstr (Year (docRequest.StartDate (0))), dblTakenHolidays, dblPlannedHolidays, szErrorMessage)
If dblRemainingDays - dblWorkingDaysNo < 0 Then
szErrorMessage = "This request can't be made - only " & Cstr (dblRemainingDays) & " vacation days are left."
If bIsInteractive = True Then
Messagebox szErrorMessage, MB_ICONEXCLAMATION, "Not enough remaining days"
End If
Exit Function
End If
End If 'of "If docRequest.Form = "RequestHoliday""
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'The following lines are normally done by "CommonRequestMake!"
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Get the workflow status document:
Set docWFSetup = GetWFSDocument (bIsInteractive, docRequest.ApplicationID (0), WFSTATUS_REQUESTED, szErrorMessage)
If docWFSetup Is Nothing Then Exit Function
Set docSetup = GetSetupDocument (bIsInteractive, "", szErrorMessage)
If docSetup Is Nothing Then Exit Function
'Get the TopLevelDecisonRule from the application global setup document:
szTopLevelDecisionRule = docSetup.TopLevelDecisionControl (0)
'Ensure the correct decision makers:
Call UpdateVacationDecisionWorkflow (docRequest)
docRequest.DecisionMakersRemaining = docRequest.DecisionMakersAll
If SetWorkflowStatus (bIsInteractive, docRequest, docWFSetup, szErrorMessage) = False Then
szErrorMessage = "Making of your request failed!"
If bIsInteractive = True Then
Messagebox szErrorMessage & MSG_INFORM_ADMIN, MB_ICONEXCLAMATION, "Error"
End If
Exit Function
End If
docRequest.RequestDate = Now
Call AddSpecialReaders (docRequest)
'If we reach this position the action succeeded:
SpecialVacationRequestMake = True
Exit Function
ErrorRoutine:
Call ErrorHandler ("SpecialVacationRequestMake")
Exit Function
End Function