Skip to content

Commit

Permalink
round timesheet totals to the nearest integer if the difference to th…
Browse files Browse the repository at this point in the history
…e nearest integer is less than 0.05. sometimes users enter spent_time of 20 minutes, which is 0.33 hours and 3 times 0.33 otherwise sums to 0.99. also improved the summation algorithm by first collecting numbers in an array and using enumerable.sum. fix allowed projects nil error when deleting timesheet entry by adding return after redirect. reformat print style css
  • Loading branch information
jkalbhenn committed Dec 11, 2018
1 parent 12da78a commit 1175dd7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
23 changes: 15 additions & 8 deletions app/controllers/timesheet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def report
@timesheet = Timesheet.new(params[:timesheet])
else
redirect_to :action => 'index'
return
end

@timesheet.allowed_projects = allowed_projects
Expand All @@ -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? }
Expand Down
42 changes: 21 additions & 21 deletions assets/stylesheets/timesheet-print.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
}

0 comments on commit 1175dd7

Please sign in to comment.