function CountStaffOnLeave($roleID, $date)
{
    //Assume no staff on leave to begin with.
    $countOfStaffOnLeave = 0;
    //Retrieve the date record from the database.
    $dateRecord = RetrieveDateRecordByDate($date);
    if ($dateRecord != NULL) {
        //Retrieve all approved absence bookings for this date.
        $dateID = $dateRecord[DATE_TABLE_DATE_ID];
        $filter[APPR_ABS_BOOK_DATE_DATE_ID] = $dateID;
        $bookingsForDate = RetrieveApprovedAbsenceBookingDates($filter);
        if ($bookingsForDate != NULL) {
            //One or more bookings exist. itterate through them.
            foreach ($bookingsForDate as $bookingDate) {
                //Using the absence booking record, obtain the employee
                //record from the database
                $absenceBooking = RetrieveApprovedAbsenceBookingByID($bookingDate[APPR_ABS_BOOK_DATE_ABS_BOOK_ID]);
                if ($absenceBooking != NULL) {
                    $staffMember = RetrieveEmployeeByID($absenceBooking[APPR_ABS_EMPLOYEE_ID]);
                    //-----------------------------------------------------
                    // Check to see if this member of staff performs the
                    // same role as the role of the employee requesting this
                    // leave. If so, add one to the count of staff on leave.
                    //-----------------------------------------------------
                    if ($staffMember[EMP_COMPANY_ROLE] == $roleID) {
                        $countOfStaffOnLeave = $countOfStaffOnLeave + 1;
                    }
                } else {
                    error_log("Unknown absence booking id of " . $bookingDate[APPR_ABS_BOOK_DATE_ABS_BOOK_ID]);
                }
            }
        }
    } else {
        error_log("Unknown date of {$date}");
    }
    return $countOfStaffOnLeave;
}
function RetrieveDateIDByDate($date)
{
    $result = NULL;
    $record = RetrieveDateRecordByDate($date);
    if ($record) {
        $result = $record[DATE_TABLE_DATE_ID];
    }
    return $result;
}