Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <% @punches_days.sort.each do |day, punches|%>
  2.  
  3. <h3><%= day.strftime('%A %D') %></h3>
  4. <table>
  5. <tr>
  6.  
  7. <th>Status</th>
  8. <th>Comment</th>
  9. <th>Time</th>
  10. <th></th>
  11. <th></th>
  12. </tr>
  13.  
  14. <% for punch in punches %>
  15. <tr>
  16.  
  17. <td><%= punch.status %></td>
  18. <td><%= punch.comment %></td>
  19. <td><%= punch.created_at.in_time_zone(punch.user.time_zone)%></td>
  20. <td><%= link_to 'Show', punch %></td>
  21. <td><%= link_to 'Edit', edit_punch_path(punch) %></td>
  22. <td><%= link_to 'Destroy', punch, :confirm => 'Are you sure?', :method => :delete %></td>
  23. </tr>
  24. <% end %>
  25. </table>
  26.  
  27.  
  28. <% end %>
  29.  
  30. Sunday 11/06/11
  31.  
  32. Status Comment Time
  33. In 2011-11-06 08:00:00 -0500 Show Edit Destroy
  34. Lunch 2011-11-06 12:00:00 -0500 Show Edit Destroy
  35. In 2011-11-06 13:00:00 -0500 Show Edit Destroy
  36. Out 2011-11-06 16:00:00 -0500 Show Edit Destroy
  37.  
  38. Tuesday 11/08/11
  39.  
  40. Status Comment Time
  41. In 2011-11-08 08:00:00 -0500 Show Edit Destroy
  42. Lunch 2011-11-08 12:15:00 -0500 Show Edit Destroy
  43. In 2011-11-08 13:00:00 -0500 Show Edit Destroy
  44. Out 2011-11-08 16:41:00 -0500 Show Edit Destroy
  45.  
  46. def timecard
  47. @punches = Punch.timecard(params[:user])
  48. @punches_days = @punches.group_by { |t| t.created_at.beginning_of_day}
  49. @in_out_lengths = @punches.each_slice(2).map { |a| a[1].created_at - a[0].created_at }
  50. @total = ((@in_out_lengths.inject(:+))/1.hour).round
  51.  
  52.  
  53. respond_to do |format|
  54. format.html # timecard.html.erb
  55. format.json { render :json => @punches }
  56. end
  57. end
  58.  
  59. in_out_lengths = punches.each_slice(2).map { |a| a[1].created_at - a[0].created_at }
  60. total = in_out_lengths.inject(:+)
  61.  
  62. punches.each_slice(2).map { |a| a.last.created_at - a.first.created_at }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement