summaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/version_reports_helper.rb48
1 files changed, 34 insertions, 14 deletions
diff --git a/app/helpers/version_reports_helper.rb b/app/helpers/version_reports_helper.rb
index bb6eda6..930ac3d 100644
--- a/app/helpers/version_reports_helper.rb
+++ b/app/helpers/version_reports_helper.rb
@@ -17,7 +17,7 @@ module VersionReportsHelper
def issue_money(issue, *options)
if @show_money
- amount = custom_price(issue) || hours_to_money(@version, issue.total_spent_hours)
+ amount = custom_price(issue) || hours_to_money(issue.total_spent_hours)
amount = amount.round
if options.include?(:format)
number_to_currency amount, :precision => 0
@@ -27,9 +27,12 @@ module VersionReportsHelper
end
end
- def hours_to_money(version, hours)
- @rate ||= to_float( custom_field_value(version, :rate) || DEFAULT_REPORT_RATE )
- (hours||0) * @rate
+ def hourly_rate
+ @rate ||= to_float( custom_field_value(@version, :rate) || DEFAULT_REPORT_RATE )
+ end
+
+ def hours_to_money(hours)
+ (hours||0) * hourly_rate
end
#
@@ -49,23 +52,40 @@ module VersionReportsHelper
end
def hour_budget_error(issue)
- return unless @show_time
- 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)
+ return unless @show_time || @show_money
+ time_budget = (custom_field_value(issue, :hours) || 0).to_i
+ money_budget = (custom_field_value(issue, :money) || 0).to_i
+ if time_budget != 0
+ if issue.total_spent_hours.round != time_budget
+ if issue.total_spent_hours < time_budget
+ content_tag :div, :class => 'flash error' do
+ "%s under budget!" % l_hours(time_budget - issue.total_spent_hours)
+ end
+ elsif issue.total_spent_hours > time_budget
+ content_tag :div, :class => 'flash warning' do
+ "%s over budget!" % l_hours(issue.total_spent_hours - time_budget)
+ end
end
- elsif issue.total_spent_hours > budget
- content_tag :div, :class => 'flash warning' do
- "%s over budget!" % l_hours(issue.total_spent_hours - budget)
+ end
+ elsif money_budget != 0
+ actual_money = issue_money(issue).round
+ if actual_money != money_budget
+ if actual_money < money_budget
+ content_tag :div, :class => 'flash error' do
+ "%s under budget!" % l_hours((money_budget - actual_money) / hourly_rate)
+ end
+ elsif actual_money > money_budget
+ content_tag :div, :class => 'flash warning' do
+ "%s over budget!" % l_hours((actual_money - money_budget) / hourly_rate)
+ end
end
end
end
end
def custom_price(issue)
- if value = custom_field_value(issue, :price)
+ value = custom_field_value(issue, :price)
+ if value.present? && value != "0"
to_float(value)
end
end