diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/version_reports_helper.rb | 67 |
1 files changed, 59 insertions, 8 deletions
diff --git a/app/helpers/version_reports_helper.rb b/app/helpers/version_reports_helper.rb index ced3d07..166d98a 100644 --- a/app/helpers/version_reports_helper.rb +++ b/app/helpers/version_reports_helper.rb @@ -9,23 +9,46 @@ module VersionReportsHelper link_to text, issue_path(issue) end - def hours_to_money(hours) - "$%i" % (hours*50) + def issue_time(issue) + l_hours(issue.total_spent_hours) if @show_time end - def hour_budget(issue) - v = issue.custom_field_values.detect {|value| - value.custom_field.name == 'Hour Budget' + def issue_money(issue, *options) + if @show_money + amount = custom_price(issue) || hours_to_money(@version, issue.total_spent_hours) + if options.include?(:format) + "$#{amount}" + else + amount + end + end + end + + def hours_to_money(version, hours) + @rate ||= (custom_field_value(version, :rate)||DEFAULT_REPORT_RATE).gsub(/[^0-9\.]/, '').to_f + (hours||0) * @rate + end + + # + # name is a key for REPORT_CUSTOM_FIELDS hash + # + def custom_field(object, name) + object.custom_field_values.detect {|value| + value.custom_field.name == REPORT_CUSTOM_FIELDS[name] } + end + + def custom_field_value(object, name) + v = custom_field(object, name) if v - v.value.to_i + v.value end end def hour_budget_error(issue) return unless @show_time - budget = hour_budget(issue) - if issue.total_spent_hours != budget + budget = (custom_field_value(issue, :hours) || 0).to_i + if issue.total_spent_hours.round != budget.round if issue.total_spent_hours < budget content_tag :div, :class => 'flash error' do "%s under budget!" % l_hours(budget - issue.total_spent_hours) @@ -38,4 +61,32 @@ module VersionReportsHelper end end + def custom_price(issue) + custom_field_value(issue, :price) + end + + def report_header(version) + url = custom_field_value(version, :header) + if !url.present? + url = DEFAULT_REPORT_HEADER + end + %(<img src="#{url}" style="max-width:100%"/>).html_safe + end + + # show_value requires CustomFieldsHelper + def report_summary(version) + show_value(custom_field(version, :summary)) + end + + def total_time(version, issues) + l_hours(issues.sum(&:total_spent_hours)) if @show_time + end + + def total_money(version, issues) + if @show_money + total = issues.sum {|issue| issue_money(issue)} + "$#{total}" + end + end + end |