class TaskJuggler::TimeSheet

The TimeSheet class stores the work related bits of a time sheet. For each task it holds a TimeSheetRecord object. A time sheet is always bound to an existing Resource.

Attributes

interval[R]
resource[R]
scenarioIdx[R]
sourceFileInfo[RW]

Public Class Methods

new(resource, interval, scenarioIdx) click to toggle source
# File lib/taskjuggler/TimeSheets.rb, line 248
def initialize(resource, interval, scenarioIdx)
  raise "Illegal resource" unless resource.is_a?(Resource)
  @resource = resource
  raise "Interval undefined" if interval.nil?
  @interval = interval
  raise "Sceneario index undefined" if scenarioIdx.nil?
  @scenarioIdx = scenarioIdx
  @sourceFileInfo = nil
  # This flag is set to true if at least one record was reported as
  # percentage.
  @percentageUsed = false
  # The TimeSheetRecord list.
  @records = []
  @messageHandler = MessageHandlerInstance.instance
end

Public Instance Methods

<<(record) click to toggle source

Add a new TimeSheetRecord to the list.

# File lib/taskjuggler/TimeSheets.rb, line 265
def<<(record)
  @records.each do |r|
    if r.task == record.task
      error('ts_duplicate_task',
            "Duplicate records for task #{r.taskId}")
    end
  end
  @records << record
end
check() click to toggle source

Perform all kinds of consitency checks.

# File lib/taskjuggler/TimeSheets.rb, line 276
def check
  totalSlots = 0
  @records.each do |record|
    record.check
    totalSlots += record.work
  end

  unless (scenarioIdx = @resource.project['trackingScenarioIdx'])
    error('ts_no_tracking_scenario',
          'No trackingscenario has been defined.')
  end

  if @resource['efficiency', scenarioIdx] > 0.0
    targetSlots = totalNetWorkingSlots
    # This is the acceptable rounding error when checking the total
    # reported work.
    delta = 1
    if totalSlots < (targetSlots - delta)
      error('ts_work_too_low',
            "The total work to be reported for this time sheet " +
            "is #{workWithUnit(targetSlots)} but only " +
            "#{workWithUnit(totalSlots)} were reported.")
    end
    if totalSlots > (targetSlots + delta)
      error('ts_work_too_high',
            "The total work to be reported for this time sheet " +
            "is #{workWithUnit(targetSlots)} but " +
            "#{workWithUnit(totalSlots)} were reported.")
    end
  else
    if totalSlots > 0
      error('ts_work_not_null',
            "The reported work for non-working resources must be 0.")
    end
  end
end
daysToSlots(days) click to toggle source
# File lib/taskjuggler/TimeSheets.rb, line 361
def daysToSlots(days)
  ((days * 60 * 60 * @resource.project.dailyWorkingHours) /
   @resource.project['scheduleGranularity']).to_i
end
error(id, text, sourceFileInfo = nil) click to toggle source
# File lib/taskjuggler/TimeSheets.rb, line 366
def error(id, text, sourceFileInfo = nil)
  @messageHandler.error(id, text, sourceFileInfo || @sourceFileInfo,
                        nil, @resource)
end
percentToSlots(value) click to toggle source

Converts allocation percentage into time slots.

# File lib/taskjuggler/TimeSheets.rb, line 345
def percentToSlots(value)
  @percentageUsed = true
  (totalGrossWorkingSlots * value).to_i
end
slotsToDays(slots) click to toggle source
# File lib/taskjuggler/TimeSheets.rb, line 356
def slotsToDays(slots)
  slots * @resource.project['scheduleGranularity'] /
    (60 * 60 * @resource.project.dailyWorkingHours)
end
slotsToPercent(slots) click to toggle source

Computes how many percent the slots are of the total working slots in the report time frame.

# File lib/taskjuggler/TimeSheets.rb, line 352
def slotsToPercent(slots)
  slots.to_f / totalGrossWorkingSlots
end
totalGrossWorkingSlots() click to toggle source

Compute the total number of potential working time slots during the report period. This value is not resource specific.

# File lib/taskjuggler/TimeSheets.rb, line 325
def totalGrossWorkingSlots
  project = @resource.project
  # Calculate the number of weeks in the report
  weeksToReport = (@interval.end - @interval.start).to_f /
    (60 * 60 * 24 * 7)

  daysToSlots((project.weeklyWorkingDays * weeksToReport).to_i)
end
totalNetWorkingSlots() click to toggle source

Compute the total number of actual working time slots of the Resource. This is the sum of allocated, free time slots.

# File lib/taskjuggler/TimeSheets.rb, line 336
def totalNetWorkingSlots
  project = @resource.project
  startIdx = project.dateToIdx(@interval.start)
  endIdx = project.dateToIdx(@interval.end)
  @resource.getAllocatedSlots(@scenarioIdx, startIdx, endIdx, nil) +
    @resource.getFreeSlots(@scenarioIdx, startIdx, endIdx)
end
warnOnDelta() click to toggle source
# File lib/taskjuggler/TimeSheets.rb, line 313
def warnOnDelta
  project = @resource.project
  startIdx = project.dateToIdx(@interval.start)
  endIdx = project.dateToIdx(@interval.end)

  @records.each do |record|
    record.warnOnDelta(startIdx, endIdx)
  end
end
warning(id, text, sourceFileInfo = nil) click to toggle source
# File lib/taskjuggler/TimeSheets.rb, line 371
def warning(id, text, sourceFileInfo = nil)
  @messageHandler.warning(id, text, sourceFileInfo, nil, @resource)
end