[#4420] Display per period Retainer values on the Contract details page.

This commit is contained in:
Eric Davis
2010-09-09 14:56:20 -07:00
parent 0a1bb9169d
commit 5ef7d0271d
8 changed files with 47 additions and 20 deletions

View File

@@ -28,7 +28,7 @@ class DeliverablesController < InheritedResources::Base
def show
if show_partial?
@period = params[:period]
@period = extract_period(params[:period])
render :partial => 'deliverables/details_row', :locals => {:contract => @contract, :deliverable => @contract.deliverables.find(params[:id]), :period => @period}
else
redirect_to contract_url(@project, @contract)
@@ -57,4 +57,13 @@ class DeliverablesController < InheritedResources::Base
@project = @contract.project
end
def extract_period(param)
period = nil
if param.present? && param.match(/\A\d{4}-\d{2}\z/) # "YYYY-MM"
year, month = param.split('-')
period = Date.new(year.to_i, month.to_i, 1)
end
period
end
end

View File

@@ -86,12 +86,18 @@ module ContractsHelper
number_with_precision(value, :precision => Contract::ViewPrecision, :delimiter => ',')
end
def retainer_period_options(deliverable)
def retainer_period_options(deliverable, method_options={})
selected = method_options[:selected]
if selected && selected.is_a?(Date)
selected = selected.strftime("%Y-%m")
end
options = []
options << content_tag(:option, l(:label_all).capitalize, :value => '')
deliverable.months.collect do |month|
options << content_tag(:option, month.strftime("%B %Y"), :value => month.strftime("%Y-%m"))
value = month.strftime("%Y-%m")
options << content_tag(:option, month.strftime("%B %Y"), :value => value, :selected => (selected == value) ? 'selected' : nil)
end
options

View File

@@ -38,6 +38,11 @@ class Deliverable < ActiveRecord::Base
''
end
# Deliverable's aren't dated. Subclasses may override this for period behavior.
def current_date
nil
end
def to_s
title
end

View File

@@ -29,8 +29,8 @@ class FixedDeliverable < Deliverable
# The amount of money remaining after expenses have been taken out
# Profit left = Total - Labor spent - Overhead spent
def profit_left
total_spent - labor_budget_spent - overhead_spent
def profit_left(date=nil)
total_spent(date) - labor_budget_spent(date) - overhead_spent(date)
end
# Hardcoded value used as a wrapper for the old Budget plugin API.

View File

@@ -19,8 +19,12 @@ class RetainerDeliverable < HourlyDeliverable
'R'
end
def current_date
Date.today
end
def current_period
Date.today.strftime("%B %Y")
current_date.strftime("%B %Y")
end
def beginning_date
@@ -32,7 +36,11 @@ class RetainerDeliverable < HourlyDeliverable
end
def date_range
(beginning_date..ending_date)
if beginning_date && ending_date && beginning_date <= ending_date
(beginning_date..ending_date)
else
[]
end
end
def within_date_range?(date)

View File

@@ -108,7 +108,7 @@
<% end %>
<tr id="deliverable_details_<%= h(deliverable.id) %>" class="ign">
<%= render :partial => 'deliverables/details_row', :locals => {:deliverable => deliverable, :contract => resource} %>
<%= render :partial => 'deliverables/details_row', :locals => {:deliverable => deliverable, :contract => resource, :period => deliverable.current_date} %>
</tr>
<% end %>
</tbody>

View File

@@ -1,4 +1,4 @@
<% period ||= '' %>
<% period ||= nil %>
<td colspan="11" class="deliverable_details_outer_wrapper_<%= h(deliverable.id) %>">
@@ -16,7 +16,7 @@
<form method="get" action="<%= contract_deliverable_path(@project, contract, deliverable, :format => 'js', :as => 'deliverable_details_row') %>">
<fieldset>
<select name="period" id="retainer_period_change_<%= h(deliverable.id) %>" class="retainer_period_change">
<%= retainer_period_options(deliverable) %>
<%= retainer_period_options(deliverable, :selected => period) %>
</select>
</fieldset>
</form>
@@ -52,28 +52,28 @@
<tbody>
<tr>
<td class="l"><a href="#"><strong>Labor</strong></a></td>
<td class="labor_budget_spent"><%= h(format_value_field_for_contracts(deliverable.labor_budget_spent)) %></td>
<td class="labor_budget_total"><%= h(format_value_field_for_contracts(deliverable.labor_budget_total)) %></td>
<td class="labor_budget_spent"><%= h(format_value_field_for_contracts(deliverable.labor_budget_spent(period))) %></td>
<td class="labor_budget_total"><%= h(format_value_field_for_contracts(deliverable.labor_budget_total(period))) %></td>
<td> TODO: Release 2 / TODO hrs </td>
</tr>
<tr>
<td class="l"><a href="#"><strong>Overhead</strong></a></td>
<td class="overhead_budget_spent"><%= h(format_value_field_for_contracts(deliverable.overhead_spent)) %></td>
<td class="overhead_budget_total"><%= h(format_value_field_for_contracts(deliverable.overhead_budget_total)) %></td>
<td class="overhead_budget_spent"><%= h(format_value_field_for_contracts(deliverable.overhead_spent(period))) %></td>
<td class="overhead_budget_total"><%= h(format_value_field_for_contracts(deliverable.overhead_budget_total(period))) %></td>
<td> TODO: Release 2 / TODO hrs </td>
</tr>
<%# TODO: Release 2, Fixed %>
<%# TODO: Release 2, Markup %>
<tr>
<td class="l">Profit</td>
<td><%= h(format_value_field_for_contracts(deliverable.profit_left)) %></td>
<td><%= h(format_value_field_for_contracts(deliverable.profit_budget)) %></td>
<td><%= h(format_value_field_for_contracts(deliverable.profit_left(period))) %></td>
<td><%= h(format_value_field_for_contracts(deliverable.profit_budget(period))) %></td>
<td></td>
</tr>
<tr class="total">
<td class="l"><strong>Total:</strong></td>
<td class="total_spent"><strong><%= h(format_value_field_for_contracts(deliverable.total_spent)) %></strong></td>
<td class="total"><strong><%= h(format_value_field_for_contracts(deliverable.total)) %></strong></td>
<td class="total_spent"><strong><%= h(format_value_field_for_contracts(deliverable.total_spent(period))) %></strong></td>
<td class="total"><strong><%= h(format_value_field_for_contracts(deliverable.total(period))) %></strong></td>
<td><strong>TODO: Release 2</strong></td>
</tr>
</tbody>

View File

@@ -32,7 +32,6 @@ class DeliverableDetailsShowTest < ActionController::IntegrationTest
visit "/projects/#{@project.id}/contracts/#{@contract.id}/deliverables/#{@deliverable1.id}", :get, {:format => 'js', :as => 'deliverable_details_row', :period => '2010-02'}
puts response.body
assert_response :success
assert_select ".deliverable_details_outer_wrapper_#{@deliverable1.id}" do
assert_select "td.labor_budget_total", '100'
@@ -40,7 +39,7 @@ class DeliverableDetailsShowTest < ActionController::IntegrationTest
assert_select "td.total", '100'
assert_select "select.retainer_period_change" do
assert_select "option[selected=selected]", "Feburary 2010"
assert_select "option[selected=selected]", "February 2010"
end
end