kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.9 KiB
73 lines
2.9 KiB
11 years ago
|
#-- copyright
|
||
|
# OpenProject Costs Plugin
|
||
|
#
|
||
|
# Copyright (C) 2009 - 2014 the OpenProject Foundation (OPF)
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# version 3.
|
||
|
#
|
||
|
# 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.
|
||
|
#++
|
||
|
|
||
15 years ago
|
require 'csv'
|
||
|
|
||
|
module CostObjectsHelper
|
||
|
include ApplicationHelper
|
||
7 years ago
|
include ActionView::Helpers::NumberHelper
|
||
12 years ago
|
|
||
15 years ago
|
# Check if the current user is allowed to manage the budget. Based on Role
|
||
|
# permissions.
|
||
|
def allowed_management?
|
||
9 years ago
|
User.current.allowed_to?(:edit_cost_objects, @project)
|
||
15 years ago
|
end
|
||
12 years ago
|
|
||
12 years ago
|
def cost_objects_to_csv(cost_objects)
|
||
9 years ago
|
CSV.generate(col_sep: t(:general_csv_separator)) do |csv|
|
||
15 years ago
|
# csv header fields
|
||
9 years ago
|
headers = ['#',
|
||
|
Project.model_name.human,
|
||
|
CostObject.human_attribute_name(:subject),
|
||
|
CostObject.human_attribute_name(:author),
|
||
|
CostObject.human_attribute_name(:fixed_date),
|
||
|
VariableCostObject.human_attribute_name(:material_budget),
|
||
|
VariableCostObject.human_attribute_name(:labor_budget),
|
||
|
CostObject.human_attribute_name(:spent),
|
||
|
CostObject.human_attribute_name(:created_on),
|
||
|
CostObject.human_attribute_name(:updated_on),
|
||
|
CostObject.human_attribute_name(:description)
|
||
|
]
|
||
9 years ago
|
csv << headers.map { |c| begin; c.to_s.encode('UTF-8'); rescue; c.to_s; end }
|
||
15 years ago
|
# csv lines
|
||
|
cost_objects.each do |cost_object|
|
||
|
fields = [cost_object.id,
|
||
|
cost_object.project.name,
|
||
|
cost_object.subject,
|
||
|
cost_object.author.name,
|
||
|
format_date(cost_object.fixed_date),
|
||
9 years ago
|
cost_object.kind == 'VariableCostObject' ? number_to_currency(cost_object.material_budget) : '',
|
||
|
cost_object.kind == 'VariableCostObject' ? number_to_currency(cost_object.labor_budget) : '',
|
||
|
cost_object.kind == 'VariableCostObject' ? number_to_currency(cost_object.spent) : '',
|
||
12 years ago
|
format_time(cost_object.created_on),
|
||
15 years ago
|
format_time(cost_object.updated_on),
|
||
|
cost_object.description
|
||
9 years ago
|
]
|
||
9 years ago
|
csv << fields.map { |c| begin; c.to_s.encode('UTF-8'); rescue; c.to_s; end }
|
||
15 years ago
|
end
|
||
|
end
|
||
|
end
|
||
6 years ago
|
|
||
|
def budget_attachment_representer(message)
|
||
|
::API::V3::Budgets::BudgetRepresenter.new(message,
|
||
|
current_user: current_user,
|
||
|
embed_links: true)
|
||
|
end
|
||
12 years ago
|
end
|