diff --git a/app/controllers/timesheet_controller.rb b/app/controllers/timesheet_controller.rb index 5921cbc..500f34f 100644 --- a/app/controllers/timesheet_controller.rb +++ b/app/controllers/timesheet_controller.rb @@ -29,6 +29,7 @@ def report @timesheet = Timesheet.new(params[:timesheet]) else redirect_to :action => 'index' + return end @timesheet.allowed_projects = allowed_projects @@ -49,29 +50,35 @@ def report save_filters_to_session(@timesheet) @timesheet.fetch_time_entries - # Sums - @total = { } + # collect spent time per project + @total = {} unless @timesheet.sort == :issue - @timesheet.time_entries.each do |project,logs| - @total[project] = 0 + @timesheet.time_entries.each do |project, logs| + @total[project] = [] if logs[:logs] logs[:logs].each do |log| - @total[project] += log.hours + @total[project].push log.hours end end end else @timesheet.time_entries.each do |project, project_data| - @total[project] = 0 + @total[project] = [] if project_data[:issues] project_data[:issues].each do |issue, issue_data| - @total[project] += issue_data.collect(&:hours).sum + @total[project].push issue_data.collect(&:hours).sum end end end end - @grand_total = @total.collect{|k,v| v}.inject{|sum,n| sum + n} + # sum hours per project + @total.each do |project, hours| + sum = hours.sum + @total[project] = (sum.round - sum).abs < 0.05 ? sum.round : sum + end + + @grand_total = @total.collect{|k,v| v}.sum respond_to do |format| format.html { render :action => 'details', :layout => false if request.xhr? } diff --git a/assets/stylesheets/timesheet-print.css b/assets/stylesheets/timesheet-print.css index cd71527..d3e03d0 100644 --- a/assets/stylesheets/timesheet-print.css +++ b/assets/stylesheets/timesheet-print.css @@ -36,7 +36,7 @@ h2, /* hide version column */ #time_entries table td:nth-child(6), #time_entries table th:nth-child(6) { - display: none; + display: none; } tr.total td { @@ -46,56 +46,56 @@ tr.total td { } #time_entries a { - color: inherit; - text-decoration: none; + color: inherit; + text-decoration: none; } table td *, table th { - font-weight: normal; + font-weight: normal; } section { - page-break-before: always; + page-break-before: always; } section:first-of-type { - page-break-before: auto; + page-break-before: auto; } * { - border: 0 !important; - background-color: #fff !important; + border: 0 !important; + background-color: #fff !important; } table * { - text-align: left; + text-align: left; } /* right align hours column */ #time_entries td:nth-child(9), #time_entries th:nth-child(9) { - text-align: right; + text-align: right; } tr.total { - border-color: #ddd !important; - border-style: solid !important; - border-width: 0px !important; - border-top-width: 1px !important; - border-bottom-width: 1px; - height: 30px; - display: table-row; + border-color: #ddd !important; + border-style: solid !important; + border-width: 0px !important; + border-top-width: 1px !important; + border-bottom-width: 1px; + height: 30px; + display: table-row; border-top: 1px solid #ddd !important; } tr.week-number { - text-align: right; + text-align: right; padding-right: 5px; padding-bottom: 5px; padding-top: 10px; - display: table-row; + display: table-row; } tr.week-number, div.week-number { @@ -110,8 +110,8 @@ tr.week-number td { h3 + div.week-number { padding-bottom: 10px; - text-align: right; + text-align: right; margin-top: -33px; font-size: 16px; - display: block; + display: block; }