Class TaskJuggler::TimeSheet
In: lib/taskjuggler/TimeSheets.rb
Parent: Object

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.

Methods

Attributes

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

Public Class methods

[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

Add a new TimeSheetRecord to the list.

[Source]

# 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

Perform all kinds of consitency checks.

[Source]

# 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

[Source]

# File lib/taskjuggler/TimeSheets.rb, line 360
    def daysToSlots(days)
      ((days * 60 * 60 * @resource.project.dailyWorkingHours) /
       @resource.project['scheduleGranularity']).to_i
    end

[Source]

# File lib/taskjuggler/TimeSheets.rb, line 365
    def error(id, text, sourceFileInfo = nil)
      @messageHandler.error(id, text, sourceFileInfo || @sourceFileInfo,
                            nil, @resource)
    end

Converts allocation percentage into time slots.

[Source]

# File lib/taskjuggler/TimeSheets.rb, line 344
    def percentToSlots(value)
      @percentageUsed = true
      (totalGrossWorkingSlots * value).to_i
    end

[Source]

# File lib/taskjuggler/TimeSheets.rb, line 355
    def slotsToDays(slots)
      slots * @resource.project['scheduleGranularity'] /
        (60 * 60 * @resource.project.dailyWorkingHours)
    end

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

[Source]

# File lib/taskjuggler/TimeSheets.rb, line 351
    def slotsToPercent(slots)
      slots.to_f / totalGrossWorkingSlots
    end

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

[Source]

# 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) / (60 * 60 * 24 * 7)

      daysToSlots(project.weeklyWorkingDays * weeksToReport)
    end

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

[Source]

# File lib/taskjuggler/TimeSheets.rb, line 335
    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

[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

[Source]

# File lib/taskjuggler/TimeSheets.rb, line 370
    def warning(id, text, sourceFileInfo = nil)
      @messageHandler.warning(id, text, sourceFileInfo, nil, @resource)
    end

[Validate]