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.
# File lib/TimeSheetSummary.rb, line 26 26: def initialize 27: super('tj3ts_summary', 'summary') 28: 29: # This is a LogicalExpression string that controls what resources should 30: # not be considered in the summary. 31: @hideResource = '0' 32: # The base directory of the time sheet templates. 33: @templateDir = 'TimeSheetTemplates' 34: # The base directory of the submitted time sheets 35: @sheetDir = 'TimeSheets' 36: # The log file 37: @logFile = 'timesheets.log' 38: # A list of email addresses to send the individual sheets. The sender 39: # will be the sheet submitter. 40: @sheetRecipients = [] 41: # A list of email addresses to send the summary to 42: @digestRecipients = [] 43: 44: @resourceIntro = "== Weekly Report from <nowiki>%s</nowiki> ==\n" 45: @resourceSheetSubject = "Weekly report %s" 46: @summarySubject = "Weekly staff reports %s" 47: @reminderSubject = "Your time sheet for the period ending %s is overdue!" 48: @reminderText = The deadline for your time sheet submission has passed but we haven't receivedit yet. Please submit your time sheet immediately so the content can still beincluded in the management reports. Please send a copy of your submissionnotification email to your manager. If possible, your manager will still tryto include your report data in his/her report.Please be aware that post deadline submissions must be processed manually andcreate an additional load for your manager and/or project manager. Please tryto submit in time in the future.Thanks for your cooperation! 49: @defaulterHeader = "The following %d person(s) have not yet submitted " + 50: "their time sheets:\n\n" 51: end
# File lib/TimeSheetSummary.rb, line 66 66: def sendSummary(resourceIds) 67: setWorkingDir 68: 69: summary = '' 70: defaulterList = [] 71: getResourceList.each do |resource| 72: resourceId = resource[0] 73: resourceName = resource[1] 74: resourceEmail = resource[2] 75: next if !resourceIds.empty? && !resourceIds.include?(resourceId) 76: 77: templateFile = "#{@templateDir}/#{@date}/#{resourceId}_#{@date}.tji" 78: sheetFile = "#{@sheetDir}/#{@date}/#{resourceId}_#{@date}.tji" 79: if File.exist?(templateFile) 80: if File.exists?(sheetFile) 81: # If there are no recipients specified, we don't need to compile 82: # the summary. 83: unless @digestRecipients.empty? && @sheetRecipients.empty? 84: # Resource has submitted a time sheet 85: sheet = getResourceJournal(sheetFile) 86: summary += sprintf(@resourceIntro, resourceName) 87: summary += sheet + "\n----\n" 88: info("Adding report from #{resourceName} to summary") 89: 90: @sheetRecipients.each do |to| 91: sendRichTextEmail(to, sprintf(@resourceSheetSubject, @date), 92: sheet, nil, 93: "#{resourceName} <#{resourceEmail}>") 94: end 95: end 96: else 97: defaulterList << resource 98: # Resource did not submit a time sheet 99: info("Report from #{resourceId} is missing") 100: end 101: end 102: end 103: 104: unless defaulterList.empty? 105: # Prepend the defaulter list to the summary. 106: text = sprintf(@defaulterHeader, defaulterList.length) 107: defaulterList.each do |resource| 108: text += "* <nowiki>#{resource[1]}</nowiki>\n" 109: end 110: text += "\n----\n" 111: summary = text + summary 112: 113: # Create a file with the IDs of the resources who's reports are 114: # missing. 115: missingFile = "#{@sheetDir}/#{@date}/missing-reports" 116: begin 117: File.open(missingFile, 'w') do |f| 118: defaulterList.each { |resource| f.puts resource[0] } 119: end 120: rescue 121: error("Cannot write file with missing reports (#missingFile): #{$!}") 122: end 123: end 124: 125: # Send out the summary text to the list of digest recipients. 126: @digestRecipients.each do |to| 127: sendRichTextEmail(to, sprintf(@summarySubject, @date), summary) 128: end 129: 130: # If there is a reminder text defined, resend the template to those 131: # individuals that have not yet submitted their report yet. 132: if @reminderText && !@reminderText.empty? 133: defaulterList.each do |resource| 134: sendReminder(resource[0], resource[1], resource[2]) 135: end 136: end 137: end
# File lib/TimeSheetSummary.rb, line 153 153: def getResourceJournal(sheetFile) 154: err = '' 155: status = nil 156: report = nil 157: warnings = nil 158: begin 159: # Save a copy of the sheet for debugging purposes. 160: command = "tj3client --silent check-ts #{@projectId} #{sheetFile}" 161: status = Open4.popen4(command) do |pid, stdin, stdout, stderr| 162: # Send the report to the tj3client process via stdin. 163: report = stdout.read 164: warnings = stderr.read 165: end 166: rescue 167: fatal("Cannot summarize sheet: #{$!}") 168: end 169: 170: report 171: end
# File lib/TimeSheetSummary.rb, line 141 141: def sendReminder(id, name, email) 142: attachment = "#{@templateDir}/#{@date}/#{id}_#{@date}.tji" 143: unless File.exist?(attachment) 144: error("sendReportTemplates: " + 145: "#{@sheetType} sheet #{attachment} for #{name} not found") 146: end 147: 148: message = "Hello #{name}!\n\n#{@reminderText}" + File.read(attachment) 149: 150: sendEmail(email, sprintf(@reminderSubject, @date), message, attachment) 151: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.