[#6441] Add a manual Contract#status
This commit is contained in:
@@ -6,6 +6,18 @@ module ContractsHelper
|
||||
deliverable
|
||||
end
|
||||
|
||||
def group_contracts_by_status(contracts)
|
||||
grouped_contracts = contracts.inject({}) do |grouped, contract|
|
||||
grouped[contract.status] ||= []
|
||||
grouped[contract.status] << contract
|
||||
grouped
|
||||
end
|
||||
grouped_contracts["open"] ||= []
|
||||
grouped_contracts["locked"] ||= []
|
||||
grouped_contracts["closed"] ||= []
|
||||
grouped_contracts
|
||||
end
|
||||
|
||||
# Simple helper to show the values of a field on an object in a standard format
|
||||
#
|
||||
# <p>
|
||||
|
||||
@@ -17,6 +17,7 @@ class Contract < ActiveRecord::Base
|
||||
validates_presence_of :start_date
|
||||
validates_presence_of :end_date
|
||||
validates_inclusion_of :discount_type, :in => %w($ %), :allow_blank => true, :allow_nil => true
|
||||
validates_inclusion_of :status, :in => ["open","locked","closed"], :allow_blank => true, :allow_nil => true
|
||||
validate :start_and_end_date_are_valid
|
||||
|
||||
# Accessors
|
||||
@@ -33,15 +34,20 @@ class Contract < ActiveRecord::Base
|
||||
attr_accessible :po_number
|
||||
attr_accessible :client_point_of_contact
|
||||
attr_accessible :details
|
||||
attr_accessible :status
|
||||
|
||||
named_scope :by_name, {:order => "#{Contract.table_name}.name ASC"}
|
||||
|
||||
[:status, :contract_type,
|
||||
[:contract_type,
|
||||
:discount_spent, :discount_budget
|
||||
].each do |mthd|
|
||||
define_method(mthd) { "TODO in later release" }
|
||||
end
|
||||
|
||||
def status
|
||||
read_attribute(:status) || "open"
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Labor Methods
|
||||
# ------------------------------------------------------------
|
||||
@@ -229,6 +235,7 @@ class Contract < ActiveRecord::Base
|
||||
|
||||
def after_initialize
|
||||
self.executed = false unless self.executed.present?
|
||||
self.status = "open" unless self.status.present?
|
||||
end
|
||||
|
||||
# Are the start_date and end_date valid?
|
||||
@@ -270,5 +277,5 @@ class Contract < ActiveRecord::Base
|
||||
def summarize_associated_values(records, value_method)
|
||||
records.inject(0) {|total, record| total += record.send(value_method)}
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<div class="box tabular">
|
||||
<% form.inputs :name => l(:text_general_legend) do %>
|
||||
<%= form.input :name, :required => true %>
|
||||
<%= form.input :status, :required => true, :collection => [["Open","open"],["Locked","locked"],["Closed","closed"]] %>
|
||||
<%= form.input :account_executive, :required => true, :collection => @project.users.sort %>
|
||||
<li class="boolean optional">
|
||||
<%= label('contract', 'executed') %>
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
|
||||
</div>
|
||||
|
||||
<% if collection.empty? %>
|
||||
<% if group_contracts_by_status(collection)["open"].empty? %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% else %>
|
||||
<table class="list" cellspacing="0" border="0" cellpadding="0" id="contracts">
|
||||
<table class="list open" cellspacing="0" border="0" cellpadding="0" id="contracts">
|
||||
<thead>
|
||||
<th><%= l(:field_id) %></th>
|
||||
<th><%= l(:field_name) %></th>
|
||||
@@ -26,11 +26,11 @@
|
||||
<th><%= l(:field_end_date) %></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% collection.each do |contract| %>
|
||||
<% group_contracts_by_status(collection)["open"].each do |contract| %>
|
||||
<% content_tag_for(:tr, contract, :class => cycle('','odd')) do %>
|
||||
<td class="id"><%= link_to(h(contract.id), contract_path(@project, contract)) %></td>
|
||||
<td class="name"><%= link_to(h(contract.name), contract_path(@project, contract)) %></td>
|
||||
<td><%= release(5, "Contract Status") %></td>
|
||||
<td class="status"><%= h(contract.status) %></td>
|
||||
<td><%= release(5, "Contract Type") %></td>
|
||||
<td class="account-executive"><%= h contract.account_executive.name %></td>
|
||||
<td class="total-budget"><%= h(format_value_field_for_contracts(contract.total_budget)) %></td>
|
||||
@@ -42,11 +42,71 @@
|
||||
<% end %>
|
||||
|
||||
<div class="title-bar">
|
||||
<h2>Inactive Contracts</h2>
|
||||
<h2>Locked Contracts</h2>
|
||||
</div>
|
||||
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<p><%= release(5, "Contract Status. Split contracts by active and inactive") %></p>
|
||||
<% if group_contracts_by_status(collection)["locked"].empty? %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% else %>
|
||||
<table class="list locked" cellspacing="0" border="0" cellpadding="0" id="contracts">
|
||||
<thead>
|
||||
<th><%= l(:field_id) %></th>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_status) %></th>
|
||||
<th><%= l(:field_type) %></th>
|
||||
<th><%= l(:field_account_executive_short) %></th>
|
||||
<th><%= l(:field_total_budget) %></th>
|
||||
<th><%= l(:field_end_date) %></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% group_contracts_by_status(collection)["locked"].each do |contract| %>
|
||||
<% content_tag_for(:tr, contract, :class => cycle('','odd')) do %>
|
||||
<td class="id"><%= link_to(h(contract.id), contract_path(@project, contract)) %></td>
|
||||
<td class="name"><%= link_to(h(contract.name), contract_path(@project, contract)) %></td>
|
||||
<td class="status"><%= h(contract.status) %></td>
|
||||
<td><%= release(5, "Contract Type") %></td>
|
||||
<td class="account-executive"><%= h contract.account_executive.name %></td>
|
||||
<td class="total-budget"><%= h(format_value_field_for_contracts(contract.total_budget)) %></td>
|
||||
<td class="end-date"><%= h format_date(contract.end_date) %></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
|
||||
<div class="title-bar">
|
||||
<h2>Closed Contracts</h2>
|
||||
</div>
|
||||
|
||||
<% if group_contracts_by_status(collection)["closed"].empty? %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% else %>
|
||||
<table class="list closed" cellspacing="0" border="0" cellpadding="0" id="contracts">
|
||||
<thead>
|
||||
<th><%= l(:field_id) %></th>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_status) %></th>
|
||||
<th><%= l(:field_type) %></th>
|
||||
<th><%= l(:field_account_executive_short) %></th>
|
||||
<th><%= l(:field_total_budget) %></th>
|
||||
<th><%= l(:field_end_date) %></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% group_contracts_by_status(collection)["closed"].each do |contract| %>
|
||||
<% content_tag_for(:tr, contract, :class => cycle('','odd')) do %>
|
||||
<td class="id"><%= link_to(h(contract.id), contract_path(@project, contract)) %></td>
|
||||
<td class="name"><%= link_to(h(contract.name), contract_path(@project, contract)) %></td>
|
||||
<td class="status"><%= h(contract.status) %></td>
|
||||
<td><%= release(5, "Contract Type") %></td>
|
||||
<td class="account-executive"><%= h contract.account_executive.name %></td>
|
||||
<td class="total-budget"><%= h(format_value_field_for_contracts(contract.total_budget)) %></td>
|
||||
<td class="end-date"><%= h format_date(contract.end_date) %></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -15,10 +15,7 @@
|
||||
|
||||
<div class="c_overview">
|
||||
<table class="left">
|
||||
<tr class="contract-status">
|
||||
<%# show_field(resource, :status, :html_options => {:class => 'contract-status'}) %>
|
||||
<td colspan="2"><%= release(5, "Contract status") %></td>
|
||||
</tr>
|
||||
<%= show_field(resource, :status, :html_options => {:class => 'contract-status'}) %>
|
||||
<%= show_field(resource, :account_executive, :html_options => {:class => 'contract-account-manager'}) %>
|
||||
<tr class="contract-type">
|
||||
<%# show_field(resource, :contract_type, :html_options => {:class => 'contract-type'}) %>
|
||||
|
||||
Reference in New Issue
Block a user