|
|
@ -46,6 +46,10 @@ class WorkPackage |
|
|
|
raise NotImplementedError, "subclass responsiblity" |
|
|
|
raise NotImplementedError, "subclass responsiblity" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def costs_sum_alias |
|
|
|
|
|
|
|
raise NotImplementedError, "subclass responsiblity" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
private |
|
|
|
private |
|
|
|
|
|
|
|
|
|
|
|
def work_package_ids(work_packages) |
|
|
|
def work_package_ids(work_packages) |
|
|
@ -65,22 +69,9 @@ class WorkPackage |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def add_costs_to(scope) |
|
|
|
def add_costs_to(scope) |
|
|
|
query = costs.to_sql |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scope |
|
|
|
scope |
|
|
|
.joins( |
|
|
|
|
|
|
|
"LEFT JOIN (#{query}) as #{table_alias} ON #{table_alias}.wp_id = #{wp_table.name}.id") |
|
|
|
|
|
|
|
.select("#{table_alias}.#{costs_table_name}_sum") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def costs |
|
|
|
|
|
|
|
filter_authorized all_costs |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def all_costs |
|
|
|
|
|
|
|
WorkPackage |
|
|
|
|
|
|
|
.joins(sum_arel.join_sources) |
|
|
|
.joins(sum_arel.join_sources) |
|
|
|
.select("work_packages.id as wp_id, #{costs_sum} as #{costs_table_name}_sum") |
|
|
|
.select("#{costs_sum} AS #{costs_sum_alias}") |
|
|
|
.group(wp_table[:id]) |
|
|
|
.group(wp_table[:id]) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -103,9 +94,7 @@ class WorkPackage |
|
|
|
|
|
|
|
|
|
|
|
def sum_arel |
|
|
|
def sum_arel |
|
|
|
wp_table |
|
|
|
wp_table |
|
|
|
.from(wp_table) |
|
|
|
.outer_join(ce_table).on(ce_table_join_condition) |
|
|
|
.join(ce_table, Arel::Nodes::OuterJoin).on(ce_table[:work_package_id].eq(wp_table[:id])) |
|
|
|
|
|
|
|
.join(projects_table).on(projects_table[:id].eq(wp_table[:project_id])) |
|
|
|
|
|
|
|
.group(wp_table[:id]) |
|
|
|
.group(wp_table[:id]) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -117,6 +106,13 @@ class WorkPackage |
|
|
|
costs_model.arel_table |
|
|
|
costs_model.arel_table |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ce_table_join_condition |
|
|
|
|
|
|
|
authorization_scope = filter_authorized costs_model.all |
|
|
|
|
|
|
|
authorization_where = authorization_scope.ast.cores.last.wheres.last |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ce_table[:work_package_id].eq(wp_table[:id]).and(authorization_where) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def projects_table |
|
|
|
def projects_table |
|
|
|
Project.arel_table |
|
|
|
Project.arel_table |
|
|
|
end |
|
|
|
end |
|
|
|