-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathorder_services_helper.rb
91 lines (80 loc) · 2.96 KB
/
order_services_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
66
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
# frozen_string_literal: true
# Copyright (c) 2006-2017, Puzzle ITC GmbH. This file is part of
# PuzzleTime and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/puzzle/puzzletime.
module OrderServicesHelper
def summed_worktimes_table(entries, options = {})
options[:footer] = checkable_worktimes_footer(entries)
checkable_worktimes_table(entries, options)
end
private
def checkable_worktimes_table(entries, options)
plain_table_or_message(entries, data: checkable_worktimes_data) do |t|
t.row_attrs { |e| { data: { no_link: cannot?(:update, e) } } }
worktimes_checkbox_column(t, options)
t.attr(:work_date)
t.attr(:employee_id) do |e|
e.employee.to_s
end
t.attr(:hours)
t.attr(:amount, currency, class: 'right')
t.attr(:work_item_id) do |e|
e.work_item.to_s
end
t.attr(:ticket)
t.attr(:description, nil, class: 'truncated', style: 'max-width: 250px;') do |w|
content_tag(:span, w.description.to_s, title: w.description)
end
t.attr(:internal_description, nil, class: 'truncated', style: 'max-width: 150px;') do |w|
content_tag(:span, w.internal_description.to_s, title: w.internal_description)
end
t.attrs(:billable, :meal_compensation, :invoice_id)
t.foot { options[:footer] } if options[:footer]
end
end
def checkable_worktimes_data
data = {}
data[:row_link] = edit_ordertime_path(':id', back_url: url_for(returning: true)) if can?(:update, @order)
data
end
def checkable_worktimes_footer(entries)
return if entries.blank?
footer = summed_worktimes_row(entries)
if entries.size == OrderServicesController::MAX_ENTRIES
too_many_entries_row
else
footer
end
end
def worktimes_checkbox_column(t, options)
check_all = check_box_tag(:all_worktimes, true, false, data: { check: 'worktime_ids[]' })
t.col(check_all, class: 'no-link') do |e|
required_perm = options[:checkbox_requires_permission]
check_box_tag('worktime_ids[]', e.id) if required_perm.nil? || can?(required_perm, e)
end
end
def summed_worktimes_row(entries)
content_tag(:tr, class: 'times_total_sum') do
summed_worktimes_cells(entries)
end
end
def summed_worktimes_cells(entries)
content_tag(:td) +
content_tag(:td, 'Total') +
content_tag(:td) +
content_tag(:td, f(entries.to_a.sum(&:hours)), class: 'right') +
content_tag(:td, f(entries.to_a.sum(&:amount)), class: 'right') +
content_tag(:td) +
content_tag(:td) +
content_tag(:td) +
content_tag(:td) +
content_tag(:td)
end
def too_many_entries_row
content_tag(:tr, class: 'center') do
content_tag(:td, 'Weitere Einträge werden nicht angezeigt. Bitte passen Sie die Filterkriterien an, um die ' \
'Anzahl Einträge zu reduzieren.', colspan: 10)
end
end
end