Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix visibility scope of labor items #15479

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<div class="grid-content medium-6">
<h4><%= t(:caption_labor_costs) %></h4>
<div>
<div class="generic-table--container -with-footer">
<div class="generic-table--results-container">
<table class="generic-table labor_budget_items">
<colgroup>
<col opHighlightCol>
<col opHighlightCol>
<col opHighlightCol>
<col opHighlightCol>
</colgroup>
<thead>
<tr>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<span>
<%= TimeEntry.human_attribute_name(:work_package) %>
</span>
</div>
</div>
</th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<span>
<%= TimeEntry.human_attribute_name(:hours) %>
</span>
</div>
</div>
</th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<span>
<%= TimeEntry.human_attribute_name(:user) %>
</span>
</div>
</div>
</th>
<th class="currency">
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<span>
<%= TimeEntry.human_attribute_name(:costs) %>
</span>
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<% by_work_package_and_time_entry do |work_package, entry| %>
<tr>
<td class="subject"><%= entry_work_package(work_package) %></td>
<td class="hours"><%= entry_hours(work_package, entry) %></td>
<td><%= entry_user(entry) %></td>
<td class="currency"><%= entry_costs(entry) %></td>
</tr>
<% end %>
</tbody>
<% if view_rates_allowed? %>
<tfoot>
<tr>
<td colspan="3"></td>
<td class="currency">
<div class="generic-table--footer-outer">
<strong><%= spent_sum %></strong>
</div>
</td>
</tr>
</tfoot>
<% end %>
</table>

<div class="generic-table--footer-background"></div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# frozen_string_literal: true

# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2010-2024 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
# ++

class Budgets::ActualLaborBudgetItemsComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
options :budget, :project

def by_work_package_and_time_entry
budget
.time_entries
.not_ongoing
.visible(User.current)
.group_by(&:work_package)
.each do |work_package, time_entries|
consolidate_time_entries(time_entries).each do |t|
yield work_package, t
end
end
end

def entry_work_package(work_package)
helpers.link_to_work_package work_package
end

def entry_hours(work_package, entry)
link_to helpers.l_hours(entry.hours),
cost_reports_path(work_package.project_id,
"fields[]": "WorkPackageId",
"operators[WorkPackageId]": "=",
"values[WorkPackageId]": work_package.id,
set_filter: 1)
end

def entry_user(entry)
entry.user.name
end

def entry_costs(entry)
entry.costs_visible_by?(User.current) ? number_to_currency(entry.real_costs) : ""
end

def spent_sum
number_to_currency(budget.spent_labor)
end

def view_rates_allowed?
User.current.allowed_in_project?(:view_hourly_rates,
project) ||
User.current.allowed_in_project?(:view_own_hourly_rate,
project)
end

private

def consolidate_time_entries(time_entries)
time_entries.inject(Hash.new) do |results, entry|
result ||= results[entry.user.id.to_s] = empty_time_entry(entry)

result.overridden_costs += entry.real_costs
result.hours += entry.hours
results
end.values
end

def empty_time_entry(entry)
result = TimeEntry.new(user: entry.user, overridden_costs: 0, project:)
result.hours = 0
result
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<div class="grid-content medium-6">
<h4><%= t(:caption_material_costs) %></h4>
<div>
<div class="generic-table--container -with-footer">
<div class="generic-table--results-container">
<table class="generic-table material_budget_items">
<colgroup>
<col opHighlightCol>
<col opHighlightCol>
<col opHighlightCol>
<col opHighlightCol>
</colgroup>
<thead>
<tr>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<span>
<%= MaterialBudgetItem.human_attribute_name(:work_package)%>
</span>
</div>
</div>
</th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<span>
<%= MaterialBudgetItem.human_attribute_name(:units) %>
</span>
</div>
</div>
</th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<span>
<%= MaterialBudgetItem.human_attribute_name(:cost_type) %>
</span>
</div>
</div>
</th>
<th class="currency">
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<span>
<%= MaterialBudgetItem.human_attribute_name(:costs) %>
</span>
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<% by_work_package_and_cost_entry do |work_package, cost_entry| %>
<tr>
<td class="subject"><%= entry_work_package(work_package) %></td>
<td><%= entry_hours(work_package, cost_entry) %></td>
<td><%= entry_type(cost_entry) %></td>
<td class="currency"><%= entry_costs(cost_entry) %></td>
</tr>
<% end %>
</tbody>
<% if view_rates_allowed? %>
<tfoot>
<tr>
<td colspan="3"></td>
<td class="currency">
<div class="generic-table--footer-outer">
<strong><%= spent_sum %></strong>
</div>
</td>
</tr>
</tfoot>
<% end %>
</table>

<div class="generic-table--footer-background"></div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# frozen_string_literal: true

# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2010-2024 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
# ++

class Budgets::ActualMaterialBudgetItemsComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
options :budget, :project

def by_work_package_and_cost_entry
budget
.cost_entries
.visible(User.current)
.includes(:cost_type)
.group_by(&:work_package)
.each do |work_package, cost_entries|
consolidate_cost_entries(cost_entries).each do |c|
yield work_package, c
end
end
end

def entry_work_package(work_package)
helpers.link_to_work_package work_package
end

def entry_hours(work_package, entry)
link_to helpers.localized_float(entry.units),
cost_reports_path(work_package.project_id,
"fields[]": "WorkPackageId",
"operators[WorkPackageId]": "=",
"values[WorkPackageId]": work_package.id,
unit: entry.cost_type_id,
set_filter: 1)
end

def entry_type(entry)
entry.cost_type
end

def entry_costs(entry)
entry.costs_visible_by?(User.current) ? number_to_currency(entry.real_costs) : ""
end

def spent_sum
number_to_currency(budget.spent_material)
end

def view_rates_allowed?
User.current.allowed_in_project?(:view_cost_rates, project)
end

private

def consolidate_cost_entries(cost_entries)
cost_entries.inject(Hash.new) do |results, entry|
result ||= results[entry.cost_type.id.to_s] = empty_cost_entry(entry)

result.overridden_costs += entry.real_costs
result.units += entry.units
results
end.values
end

def empty_cost_entry(entry)
CostEntry.new(cost_type: entry.cost_type, project:, overridden_costs: 0.0, units: 0)
end
end
Loading
Loading