Hello all. I’ve wrote the below class and it works as expected with the exception of passing the date of 12/31/2007. This returns a Pay Period of 0, but all the other dates I’ve tried worked fine. Can someone help me figure out why 12/31/2007 fails? I apologize for putting all the code in here but I figured that would result in the most understanding. But the property that’s failing is the PayPeriod property. I call it like so:Dim adminPerson As AdminPerson
Set adminPerson = New AdminPerson(s.UserName)
pp = adminPerson.PayPeriod(“12/31/2007”)
this returns 0
Here is the class, hopefully it’s readable once I post this.
Public Class AdminSuite
Private dbList List As Variant
Private extDbProDoc As NotesDocument
Private thisServer As String
Private thisDB As NotesDatabase
Private FiscalYr As Double
Private PP As Integer
'********************************* C O N S T R U C T O R S *******************************
'/**
' * Contructor for the AdminSuite class. This assumes that there is a profile document named
' * "External DB Profile"
' */
Public Sub New
Dim s As New NotesSession
Set thisDB = s.CurrentDatabase
Set Me.extDBProDoc = thisDB.GetProfileDocument("External DB Profile")
Me.thisServer = thisDB.Server
PP = 0
FiscalYr = 0
End Sub
'****************************** E N D C O N S T R U C T O R S ***************************
'********************************* P R O P E R T I E S *******************************
'/**
' * The Exernal DB Profile document
' * @return NotesDocument of the "External DB Profile"
' */
Public Property Get extProDoc As NotesDocument
Set extProDoc = extDbProDoc
End Property
'*****************************************
'/**
' * A list of external databases that this application accesses
' * @return Variant which contains a list of NotesDatabase objects
' */
Public Property Get extDBList As Variant
Dim extDb As NotesDatabase
If Me.extProDoc Is Nothing Then
Print "No Profile Doc defined!"
Exit Property
Else
Forall i In extProDoc.Items
If Instr(i.Name,"$") Or i.Name = "extPeoplePlus" Or i.Name = "Form" Then
Print "Skipping field " + i.Name
Else
If i.Values(0) <> "" Then
Set extDb = New NotesDatabase(thisServer,i.Values(0))
Set dbList(Lcase(extDb.FileName)) = extDB
End If
End If
End Forall
Set dbList(Lcase(Me.thisDB.FileName)) = Me.thisDB
End If
extDBList = dbList
End Property
'*****************************************
'/**
' * The current fiscal year based on today
' * @return Double as the year
' */
Public Property Get FiscalYear(lookupDate As String) As Double
Dim lookupNotesDate As NotesDateTime
If lookupDate = "" Then
Set lookupNotesDate = New NotesDateTime(Cstr(Today))
Else
Set lookupNotesDate = New NotesDateTime(lookupDate)
End If
FiscalYr = Me.getFiscalYear(lookupNotesDate)
FiscalYear = FiscalYr
End Property
'*****************************************
'/**
' * Get the pay period for the passed date. It must be within this fiscal year
' * @param lookupDate as String - A string representation of a date (i.e. "01/01/2008")
' * @return Integer representing the pay period for the requested date
' */
Public Property Get PayPeriod(lookupDate As String) As Integer
Dim lookupNotesDate As NotesDateTime
If lookupDate = "" Then
Set lookupNotesDate = New NotesDateTime(Cstr(Today))
Else
Set lookupNotesDate = New NotesDateTime(lookupDate)
End If
PP = Me.getPayPeriod(lookupNotesDate)
PayPeriod = PP
End Property
'***************************** E N D P R O P E R T I E S ***************************
'************************************** M E T H O D S ********************************
'/**
' * Calculate the fiscal year for the date passed
' * @param lookupDate as NotesDateTime - A NotesDateTime for the date you want to figure out the fiscal year for
' * @return Double as the Fiscal Year for the date passed
' */
Public Function getFiscalYear(lookupDate As NotesDateTime) As Double
If Month(lookupDate.DateOnly) < 10 Then
getFiscalYear = Cdbl(Year(lookupDate.DateOnly))
Else
getFiscalYear = Cdbl(Year(lookupDate.DateOnly) + 1)
End If
End Function
'*****************************************
'/**
' * Calculate the current Pay Period
' * @param lookupDate as NotesDateTime. This is the date we want to return the pay period for, it must be this fiscal year
' * @return Integer of the current pay period
' */
Private Function getPayPeriod(lookupDate As NotesDateTime) As Integer
Dim weekDy As Integer
Dim startDat As NotesDateTime
Dim endDat As NotesDateTime
Dim fy As Double
Dim payPeriods(1 To 27) As String
Dim count As Integer, i As Integer
Dim payPeriodRange As String
'The starting date of the fiscal year will always be the fiscal year minus 1
fy = Me.FiscalYear(Cstr(lookupDate.DateOnly)) - 1
' Figure out the starting date of the fiscal year. Will be the last sunday in September
Set startDat = New NotesDateTime("9/30/" + Cstr(fy))
weekDy = Weekday(startDat.DateOnly)
If weekDy > 1 Then
weekDy = weekDy - 1
Call startDat.AdjustDay(-weekDy)
End If
'populate the payPeriodRange with the start date
'Increment the start date by 13 days
'populate the payPeriodRange with the start date adjusted 13 days. This is the end date for the pay period
'Populate the payPeriods array
'Do this until we have 27 values in the array
count = 1
Do Until count = 28
payPeriodRange = Cstr(startDat.DateOnly) + "-"
Call startDat.AdjustDay(13)
payPeriodRange = payPeriodRange + Cstr(startDat.DateOnly)
payPeriods(count) = payPeriodRange
Call startDat.AdjustDay(1)
count = count + 1
Loop
'loop through all date ranges and if the passed date is greater than the start date AND
'less than the end date see what element we're in and that's the pay period
For i = 1 To Ubound(payPeriods)
Set startDat = New NotesDateTime(Strleft(payPeriods(i),"-"))
Set endDat = New NotesDateTime(Strright(payPeriods(i),"-"))
If lookupDate.DateOnly >= startDat.DateOnly And lookupDate.DateOnly <= endDat.DateOnly Then
getPayPeriod = i
Exit For
End If
Next
End Function
'*****************************************
'*********************************** E N D M E T H O D S ***************************
End Class
'######################################################################################
'######################################################################################
Public Class AdminPerson As AdminSuite
Private perNotesName As NotesName
'********************************* C O N S T R U C T O R S *******************************
'/**
' * Constructor for a person within AdminSuite
' * @param perName as String - This is the person's Notes Name as a string
' */
Public Sub New (perName As String)
Set perNotesName = New NotesName(perName)
End Sub
'****************************** E N D C O N S T R U C T O R S ***************************
'********************************* P R O P E R T I E S *******************************
'/**
' * Get the name of the person
' * @return NotesName
' */
Public Property Get perName As NotesName
Set perName = perNotesName
End Property
'*****************************************
'/**
' * Get the PP timesheet for the date passed for this person
' * @param - lookupDate as String - A string representation of a date
' * @return NotesDocument - Current timesheet for this person
' */
Public Property Get timeSheet(lookupDate As String) As NotesDocument
Dim view As NotesView
Dim doc As NotesDocument
Dim lookupNotesDate As NotesDateTime
If lookupDate = "" Then
Set lookupNotesDate = New NotesDateTime(Cstr(Today))
Else
Set lookupNotesDate = New NotesDateTime(lookupDate)
End If
If Iselement(Me.extDbList("ged_timekeeping_database.nsf")) Then
Set view = Me.extDbList("ged_timekeeping_database.nsf").GetView("(luTimeSheetsPersonPP)")
Set doc = view.GetDocumentByKey(Me.perName.Common + "-" +_
Cstr(Me.FiscalYear(lookupNotesDate.DateOnly)) + "-" +_
Cstr(Me.PayPeriod(lookupNotesDate.DateOnly)))
If Not doc Is Nothing Then
Set Me.timeSheet = doc
Else
Msgbox "No timesheet found for " + Me.perName.Common + " for Pay Period " +_
Cstr(Me.PayPeriod(lookupNotesDate.DateOnly)) + " and Fiscal Year " +_
Cstr(Me.FiscalYear(lookupNotesDate.DateOnly)),0,"ERROR"
Exit Property
End If
Else
Msgbox "The Timesheet database isn't listed in the External DB Profile document!" + Chr(10) +_
"Please ensure the Timesheet database is properly defined in the External DB Profile document.",0,"E R R O R"
End If
End Property
'*****************************************
'/**
' * Get the
'***************************** E N D P R O P E R T I E S ***************************
End Class