18 |
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
19 |
|
20 |
20 |
class IssueQuery < Query
|
21 |
|
class EstimatedRemainingHoursColumn < QueryColumn
|
22 |
|
COLUMN_SQL = Arel.sql("COALESCE(#{Issue.table_name}.estimated_hours, 0) * (100 - COALESCE(#{Issue.table_name}.done_ratio, 0)) / 100")
|
23 |
|
|
24 |
|
def initialize
|
25 |
|
super(:estimated_remaining_hours, totalable: true, sortable: COLUMN_SQL)
|
26 |
|
end
|
27 |
|
|
28 |
|
def value(object)
|
29 |
|
(object.estimated_hours || 0) * (100 - (object.done_ratio || 0)) / 100
|
30 |
|
end
|
31 |
|
|
32 |
|
def value_object(object)
|
33 |
|
value(object)
|
34 |
|
end
|
35 |
|
end
|
36 |
|
|
37 |
21 |
self.queried_class = Issue
|
38 |
22 |
self.view_permission = :view_issues
|
39 |
23 |
|
|
24 |
ESTIMATED_REMAINING_HOURS_SQL = Arel.sql("COALESCE(#{Issue.table_name}.estimated_hours, 0) * (100 - COALESCE(#{Issue.table_name}.done_ratio, 0)) / 100")
|
40 |
25 |
self.available_columns = [
|
41 |
26 |
QueryColumn.new(:id, :sortable => "#{Issue.table_name}.id",
|
42 |
27 |
:default_order => 'desc', :caption => '#', :frozen => true),
|
... | ... | |
66 |
51 |
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date", :groupable => true),
|
67 |
52 |
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours",
|
68 |
53 |
:totalable => true),
|
69 |
|
EstimatedRemainingHoursColumn.new,
|
|
54 |
QueryColumn.new(:estimated_remaining_hours,
|
|
55 |
:sortable => ESTIMATED_REMAINING_HOURS_SQL,
|
|
56 |
:totalable => true),
|
70 |
57 |
QueryColumn.new(
|
71 |
58 |
:total_estimated_hours,
|
72 |
59 |
:sortable =>
|
... | ... | |
390 |
377 |
end
|
391 |
378 |
|
392 |
379 |
def total_for_estimated_remaining_hours(scope)
|
393 |
|
map_total(scope.sum(EstimatedRemainingHoursColumn::COLUMN_SQL)) {|t| t.to_f.round(2)}
|
|
380 |
map_total(scope.sum(ESTIMATED_REMAINING_HOURS_SQL)) {|t| t.to_f.round(2)}
|
394 |
381 |
end
|
395 |
382 |
|
396 |
383 |
# Returns sum of all the issue's time entries hours
|