summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-06-09 14:43:40 -0700
committerelijah <elijah@riseup.net>2015-06-09 14:43:40 -0700
commit79d0f9b58bde08d3bc16ff143e2d1adba7b83e17 (patch)
treebb65466bebb99d4cdd968d81a32df76636fe4be5
parent7133631f32cb7d179cac65fb4a94a7dec44c9246 (diff)
added support for budgeted cost field, in addition to the budgeted hours field.
-rw-r--r--README.md12
-rw-r--r--app/helpers/version_reports_helper.rb48
-rw-r--r--init.rb5
3 files changed, 45 insertions, 20 deletions
diff --git a/README.md b/README.md
index 8d0e4a3..d62979a 100644
--- a/README.md
+++ b/README.md
@@ -22,13 +22,17 @@ Configuration:
Custom fields:
* Issues
- * "Hour Budget": an integer field for 'deliverable' issues.
- * "Price": an string field for 'deliverable' issues
- (used to override the money amount displayed, if present).
+ * "Budgeted Hours": an integer field for 'deliverable' issues (hours).
+ If set, then a warning will be shown if the total hours is less.
+ * "Budgeted Cost": an text field for 'deliverable' issues (e.g. "$1000").
+ If set, then a warning will be shown if the total cost is less
+ (and "Budgeted Hours" is empty).
+ * "Fixed Cost": a text field for 'deliverable' issues. Fixed price for
+ deliverable, irrespective of labor (e.g. ignores the "Budgeted" fields).
* Versions
* "Header URL": an string field for target versions.
If present, the image will be added to the report at the top.
- * "Summary": a text field for Textile formatted summary
+ * "Summary": a long text field for Textile formatted summary
to appear at the top of a report ('description' is used for the heading).
* "Rate": a text field for the hourly rate, including currency ("$50").
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
diff --git a/init.rb b/init.rb
index 7b38d51..1e3bcdb 100644
--- a/init.rb
+++ b/init.rb
@@ -4,8 +4,9 @@ require_dependency 'version_report/hooks'
# The name of custom fields
#
REPORT_CUSTOM_FIELDS = {
- :hours => 'Hour Budget',
- :price => 'Price',
+ :hours => 'Budgeted Hours',
+ :money => 'Budgeted Cost',
+ :price => 'Fixed Cost',
:header => 'Header URL',
:summary => 'Summary',
:rate => 'Rate'