Class: TaskJuggler::TimeSheetSummary

Inherits:
SheetReceiver show all
Defined in:
lib/taskjuggler/TimeSheetSummary.rb

Overview

The TimeSheetSender class generates time sheet templates for the current week and sends them out to the project contributors. For this to work, the resources must provide the ‘Email’ custom attribute with their email address. The actual project data is accessed via tj3client on a tj3 server process.

Instance Attribute Summary collapse

Attributes inherited from SheetHandlerBase

#dryRun, #workingDir

Instance Method Summary collapse

Methods inherited from SheetReceiver

#processEmail

Methods included from StdIoWrapper

#stdIoWrapper

Methods inherited from SheetHandlerBase

#addToScm, #cutOut, #error, #htmlMailBody, #info, #log, #sendEmail, #sendRichTextEmail, #setWorkingDir, #warning

Constructor Details

#initializeTimeSheetSummary

Returns a new instance of TimeSheetSummary.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/taskjuggler/TimeSheetSummary.rb', line 27

def initialize
  super('tj3ts_summary', 'summary')

  # This is a LogicalExpression string that controls what resources should
  # not be considered in the summary.
  @hideResource = '0'
  # The base directory of the time sheet templates.
  @templateDir = 'TimeSheetTemplates'
  # The base directory of the submitted time sheets
  @sheetDir = 'TimeSheets'
  # The log file
  @logFile = 'timesheets.log'
  # A list of email addresses to send the individual sheets. The sender
  # will be the sheet submitter.
  @sheetRecipients = []
  # A list of email addresses to send the summary to
  @digestRecipients = []

  @resourceIntro = "== Weekly Report from <nowiki>%s</nowiki> ==\n"
  @resourceSheetSubject = "Weekly report %s"
  @summarySubject = "Weekly staff reports %s"
  @reminderSubject = "Your time sheet for the period ending %s is overdue!"
  @reminderText = "The deadline for your time sheet submission has passed but we haven't received\nit yet. Please submit your time sheet immediately so the content can still be\nincluded in the management reports. Please send a copy of your submission\nnotification email to your manager. If possible, your manager will still try\nto include your report data in his/her report.\n\nPlease be aware that post deadline submissions must be processed manually and\ncreate an additional load for your manager and/or project manager.  Please try\nto submit in time in the future.\n\nThanks for your cooperation!\n\n"
  @defaulterHeader = "The following %d person(s) have not yet submitted " +
                     "their time sheets:\n\n"
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



25
26
27
# File 'lib/taskjuggler/TimeSheetSummary.rb', line 25

def date
  @date
end

#digestRecipientsObject

Returns the value of attribute digestRecipients.



25
26
27
# File 'lib/taskjuggler/TimeSheetSummary.rb', line 25

def digestRecipients
  @digestRecipients
end

#sheetRecipientsObject

Returns the value of attribute sheetRecipients.



25
26
27
# File 'lib/taskjuggler/TimeSheetSummary.rb', line 25

def sheetRecipients
  @sheetRecipients
end

Instance Method Details

#sendSummary(resourceIds) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/taskjuggler/TimeSheetSummary.rb', line 67

def sendSummary(resourceIds)
  setWorkingDir

  summary = ''
  defaulterList = []
  getResourceList.each do |resource|
    resourceId = resource[0]
    resourceName = resource[1]
    resourceEmail = resource[2]
    next if !resourceIds.empty? && !resourceIds.include?(resourceId)

    templateFile = "#{@templateDir}/#{@date}/#{resourceId}_#{@date}.tji"
    sheetFile = "#{@sheetDir}/#{@date}/#{resourceId}_#{@date}.tji"
    if File.exist?(templateFile)
      if File.exist?(sheetFile)
        # If there are no recipients specified, we don't need to compile
        # the summary.
        unless @digestRecipients.empty? && @sheetRecipients.empty?
          # Resource has submitted a time sheet
          sheet = getResourceJournal(sheetFile)
          summary += sprintf(@resourceIntro, resourceName)
          summary += sheet + "\n----\n"
          info("Adding report from #{resourceName} to summary")

          @sheetRecipients.each do |to|
            sendRichTextEmail(to, sprintf(@resourceSheetSubject, @date),
                              sheet, nil,
                              "#{resourceName} <#{resourceEmail}>")
          end
        end
      else
        defaulterList << resource
        # Resource did not submit a time sheet
        info("Report from #{resourceId} is missing")
      end
    end
  end

  unless defaulterList.empty?
    # Prepend the defaulter list to the summary.
    text = sprintf(@defaulterHeader, defaulterList.length)
    defaulterList.each do |resource|
      text += "* <nowiki>#{resource[1]}</nowiki>\n"
    end
    text += "\n----\n"
    summary = text + summary

    # Create a file with the IDs of the resources who's reports are
    # missing.
    missingFile = "#{@sheetDir}/#{@date}/missing-reports"
    begin
      File.open(missingFile, 'w') do |f|
        defaulterList.each { |resource| f.puts resource[0] }
      end
    rescue
      error("Cannot write file with missing reports (#missingFile): #{$!}")
    end
  end

  # Send out the summary text to the list of digest recipients.
  @digestRecipients.each do |to|
    sendRichTextEmail(to, sprintf(@summarySubject, @date), summary)
  end

  # If there is a reminder text defined, resend the template to those
  # individuals that have not yet submitted their report yet.
  if @reminderText && !@reminderText.empty?
    defaulterList.each do |resource|
      sendReminder(resource[0], resource[1], resource[2])
    end
  end
end