class TaskJuggler::TimeSheetReport

This specialization of ReportBase implements a template generator for time sheets. The time sheet is structured using the TJP file syntax.

Public Class Methods

new(report) click to toggle source

Create a new object and set some default values.

Calls superclass method TaskJuggler::ReportBase::new
# File lib/taskjuggler/reports/TimeSheetReport.rb, line 53
def initialize(report)
  super(report)

  @current = []
  @future = []
end

Public Instance Methods

generateIntermediateFormat() click to toggle source

In the future we might want to generate other output than TJP synatx. So we generate an abstract version of the time sheet first. This abstract version has a TSResourceRecord for each resource and each of these records holds a TSTaskRecord for each assigned task.

# File lib/taskjuggler/reports/TimeSheetReport.rb, line 64
def generateIntermediateFormat
  super
  @current = collectRecords(a('start'), a('end'))
  newEnd = a('end') + (a('end').to_i - a('start').to_i)
  newEnd = @project['end'] if newEnd > @project['end']
  @future = collectRecords(a('end'), a('end') + (a('end') - a('start')))
end
to_tjp() click to toggle source

Generate a time sheet in TJP syntax format.

# File lib/taskjuggler/reports/TimeSheetReport.rb, line 73
    def to_tjp
      # This String will hold the result.
      @file = <<'EOT'
# The status headline should be no more than 60 characters and may
# not be empty! The status summary is optional and should be no
# longer than one or two sentences of plain text. The details section
# is also optional has no length limitation. You can use simple
# markup in this section.  It is recommended that you provide at
# least a summary or a details section.
# See http://www.taskjuggler.org/tj3/manual/timesheet.html for details.
#
# --------8<--------8<--------
EOT

      # Iterate over all the resources that we have TSResourceRecords for.
      @current.each do |rr|
        resource = rr.resource
        # Generate the time sheet header
        @file << "timesheet #{resource.fullId} " +
                 "#{a('start')} - #{a('end')} {\n\n"

        @file << "  # Vacation time: #{rr.vacationPercent}%\n\n"

        if rr.tasks.empty?
          # If there were no assignments, just write a comment.
          @file << "  # There were no planned tasks assignments for " +
                   "this period!\n\n"
        else
          rr.tasks.each do |tr|
            task = tr.task

            @file << "  # Task: #{task.name}\n"
            @file << "  task #{task.fullId} {\n"
            #@file << "    work #{tr.workDays *
            #                     @project['dailyworkinghours']}h\n"
            @file << "    work #{tr.workPercent}%\n"
            if tr.remaining
              @file << "    remaining #{tr.remaining}d\n"
            else
              @file << "    end #{tr.endDate}\n"
            end
            c = tr.workDays > 1.0 ? '' : '# '
            @file << "    #{c}status green \"Your headline here!\" {\n" +
                     "    #  summary -8<-\n" +
                     "    #  A summary text\n" +
                     "    #  ->8-\n" +
                     "    #  details -8<-\n" +
                     "    #  Some more details\n" +
                     "    #  ->8-\n" +
                     "    #  flags ...\n" +
                     "    #{c}}\n"
            @file << "  }\n\n"
          end
        end
        @file << <<'EOT'
  # If you had unplanned tasks, uncomment and fill out the
  # following lines:
  # newtask new.task.id "A task title" {
  #   work X%
  #   remaining Y.Yd
  #   status green "Your headline here!" {
  #     summary -8<-
  #     A summary text
  #     ->8-
  #     details -8<-
  #     Some more details
  #     ->8-
  #     flags ...
  #   }
  # }

  # You can use the following section to report personal notes.
  # status green "Your headline here!" {
  #   summary -8<-
  #   A summary text
  #   ->8-
  #   details -8<-
  #   Some more details
  #   ->8-
  # }
EOT
        future = @future[@future.index { |r| r.resource == resource }]
        if future && !future.tasks.empty?
          @file << <<'EOT'
  #
  # Your upcoming tasks for the next period
  # Please check them carefully and discuss any necessary
  # changes with your manager or project manager!
  #
EOT
          future.tasks.each do |taskRecord|
            @file << "  # #{taskRecord.task.name}: #{taskRecord.workPercent}%\n"
          end
          @file << "\n"
        else
          @file << "\n  # You have no future assignments for this project!\n"
        end
        @file << "}\n# -------->8-------->8--------\n\n"
      end
      @file
    end