erp_work_effort 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/GPL-3-LICENSE +674 -0
  2. data/README.rdoc +1 -0
  3. data/Rakefile +31 -0
  4. data/app/assets/javascripts/erp_work_effort/application.js +9 -0
  5. data/app/assets/stylesheets/erp_work_effort/application.css +7 -0
  6. data/app/controllers/erp_work_effort/application_controller.rb +4 -0
  7. data/app/helpers/erp_work_effort/application_helper.rb +4 -0
  8. data/app/models/cost.rb +3 -0
  9. data/app/models/extensions/party.rb +3 -0
  10. data/app/models/party_resource_availability.rb +5 -0
  11. data/app/models/party_resource_availability_type.rb +7 -0
  12. data/app/models/project_effort.rb +2 -0
  13. data/app/models/project_requirement.rb +2 -0
  14. data/app/models/support_effort.rb +2 -0
  15. data/app/models/support_requirement.rb +2 -0
  16. data/app/models/valid_work_assignment.rb +8 -0
  17. data/app/models/valid_work_assignment_attribute.rb +3 -0
  18. data/app/models/work_effort.rb +135 -0
  19. data/app/models/work_effort_assignment.rb +15 -0
  20. data/app/models/work_effort_status.rb +4 -0
  21. data/app/models/work_effort_status_type.rb +13 -0
  22. data/app/models/work_requirement.rb +76 -0
  23. data/app/models/work_requirement_work_effort_status_type.rb +4 -0
  24. data/app/views/layouts/erp_work_effort/application.html.erb +14 -0
  25. data/config/routes.rb +2 -0
  26. data/db/migrate/20100220000000_base_work_efforts.rb +208 -0
  27. data/lib/erp_work_effort.rb +5 -0
  28. data/lib/erp_work_effort/engine.rb +13 -0
  29. data/lib/erp_work_effort/extensions.rb +4 -0
  30. data/lib/erp_work_effort/extensions/active_record/acts_as_project_effort.rb +66 -0
  31. data/lib/erp_work_effort/extensions/active_record/acts_as_project_requirement.rb +64 -0
  32. data/lib/erp_work_effort/extensions/active_record/acts_as_support_effort.rb +61 -0
  33. data/lib/erp_work_effort/extensions/active_record/acts_as_support_requirement.rb +68 -0
  34. data/lib/erp_work_effort/version.rb +3 -0
  35. data/lib/tasks/erp_work_effort_tasks.rake +4 -0
  36. data/spec/dummy/Rakefile +7 -0
  37. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  38. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  39. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  40. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  41. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  42. data/spec/dummy/config.ru +4 -0
  43. data/spec/dummy/config/application.rb +43 -0
  44. data/spec/dummy/config/boot.rb +10 -0
  45. data/spec/dummy/config/database.yml +8 -0
  46. data/spec/dummy/config/environment.rb +5 -0
  47. data/spec/dummy/config/environments/spec.rb +27 -0
  48. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/spec/dummy/config/initializers/inflections.rb +10 -0
  50. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  51. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  52. data/spec/dummy/config/initializers/session_store.rb +8 -0
  53. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  54. data/spec/dummy/config/locales/en.yml +5 -0
  55. data/spec/dummy/config/routes.rb +3 -0
  56. data/spec/dummy/public/404.html +26 -0
  57. data/spec/dummy/public/422.html +26 -0
  58. data/spec/dummy/public/500.html +26 -0
  59. data/spec/dummy/public/favicon.ico +0 -0
  60. data/spec/dummy/script/rails +6 -0
  61. data/spec/models/cost_spec.rb +11 -0
  62. data/spec/models/party_resource_availability_spec.rb +11 -0
  63. data/spec/models/party_resource_availability_type_spec.rb +11 -0
  64. data/spec/models/project_effort_spec.rb +11 -0
  65. data/spec/models/project_requirement_spec.rb +11 -0
  66. data/spec/models/support_effort_spec.rb +11 -0
  67. data/spec/models/support_requirement_spec.rb +11 -0
  68. data/spec/models/valid_work_assignment_attribute_spec.rb +11 -0
  69. data/spec/models/valid_work_assignment_spec.rb +11 -0
  70. data/spec/models/work_effort_assignment_spec.rb +13 -0
  71. data/spec/models/work_effort_spec.rb +11 -0
  72. data/spec/models/work_effort_status_spec.rb +11 -0
  73. data/spec/models/work_effort_status_type_spec.rb +11 -0
  74. data/spec/models/work_requirement_spec.rb +11 -0
  75. data/spec/models/work_requirement_work_effort_status_type._spec.rb +11 -0
  76. data/spec/spec_helper.rb +60 -0
  77. metadata +195 -0
data/README.rdoc ADDED
@@ -0,0 +1 @@
1
+ = ErpWorkEffort
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ErpWorkEffort'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require "rspec/core/rake_task"
29
+ RSpec::Core::RakeTask.new(:spec)
30
+ task :default => :spec
31
+
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,4 @@
1
+ module ErpWorkEffort
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ErpWorkEffort
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ class Cost < ActiveRecord::Base
2
+ belongs_to :money
3
+ end
@@ -0,0 +1,3 @@
1
+ Party.class_eval do
2
+ has_many :resource_availabilities, :class_name => 'PartyResourceAvailability', :dependent => :destroy
3
+ end
@@ -0,0 +1,5 @@
1
+ class PartyResourceAvailability < ActiveRecord::Base
2
+ belongs_to :party
3
+ belongs_to :party_resource_availability_type, :foreign_key => 'pra_type_id', :class_name => 'PartyResourceAvailabilityType'
4
+
5
+ end
@@ -0,0 +1,7 @@
1
+ class PartyResourceAvailabilityType < ActiveRecord::Base
2
+ has_many :party_resource_availabilities
3
+
4
+ def self.iid(internal_identifier)
5
+ self.where('internal_identifier = ?', internal_identifier).first
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ class ProjectEffort < WorkEffort
2
+ end
@@ -0,0 +1,2 @@
1
+ class ProjectRequirement < WorkRequirement
2
+ end
@@ -0,0 +1,2 @@
1
+ class SupportEffort < WorkEffort
2
+ end
@@ -0,0 +1,2 @@
1
+ class SupportRequirement < WorkRequirement
2
+ end
@@ -0,0 +1,8 @@
1
+ class ValidWorkAssignment < ActiveRecord::Base
2
+ belongs_to :party
3
+ belongs_to :work_requirement
4
+ belongs_to :role_type
5
+ has_many :valid_work_assignment_attributes, :dependent => :destroy
6
+
7
+ alias :attributes :valid_work_assignment_attributes
8
+ end
@@ -0,0 +1,3 @@
1
+ class ValidWorkAssignmentAttribute < ActiveRecord::Base
2
+ belongs_to :valid_work_assignment
3
+ end
@@ -0,0 +1,135 @@
1
+ class WorkEffort < ActiveRecord::Base
2
+ acts_as_nested_set
3
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
4
+
5
+ belongs_to :work_effort_record, :polymorphic => true
6
+ belongs_to :facility, :polymorphic => true
7
+ belongs_to :work_effort_assignment
8
+ has_many :work_effort_statuses
9
+
10
+ belongs_to :projected_cost, :class_name => 'Cost', :foreign_key => 'projected_cost_id'
11
+ belongs_to :actual_cost, :class_name => 'Cost', :foreign_key => 'actual_cost_id'
12
+ #has_one :work_effort_deliverable
13
+
14
+ #get current status
15
+ def status
16
+ work_effort_status = self.descendants.flatten!.nil? ? self.get_current_status : self.descendants.flatten!.last.get_current_status
17
+ work_effort_status.work_effort_status_type.description
18
+ end
19
+
20
+ # return true if this effort has been started, false otherwise
21
+ def started?
22
+ get_current_status.nil? ? false : true
23
+ end
24
+
25
+ # return true if this effort has been completed, false otherwise
26
+ def completed?
27
+ finished_at.nil? ? false : true
28
+ end
29
+
30
+ #start initial work_status
31
+ def start(status_type)
32
+ effort = self
33
+ unless self.descendants.flatten!.nil?
34
+ children = self.descendants.flatten
35
+ effort = children.last
36
+ end
37
+
38
+ current_status = effort.get_current_status
39
+
40
+ if current_status.nil?
41
+ work_effort_status = WorkEffortStatus.create(:started_at => DateTime.now, :work_effort_status_type => status_type)
42
+ effort.work_effort_statuses << work_effort_status
43
+ effort.started_at = DateTime.now
44
+ effort.save
45
+ else
46
+ raise 'Effort Already Started'
47
+ end
48
+ end
49
+
50
+ # completes current status if current status is in progress
51
+ # start status passed in
52
+ # if status passed in is last status, starts parent status if status exists
53
+ def send_to_status(status_type, complete_effort=false, complete_status=false)
54
+ current_status = get_current_status
55
+
56
+ unless current_status.nil?
57
+ new_work_effort_status = WorkEffortStatus.new
58
+ new_work_effort_status.started_at = DateTime.now
59
+ new_work_effort_status.finished_at = new_work_effort_status.started_at if complete_status
60
+ new_work_effort_status.work_effort_status_type = status_type
61
+ new_work_effort_status.work_effort = self
62
+ new_work_effort_status.save
63
+ current_status.finished_at = DateTime.now
64
+ current_status.save
65
+ complete_work_effort if complete_effort
66
+ else
67
+ raise 'Effort Has Not Started'
68
+ end
69
+ end
70
+
71
+ #completes current status
72
+ #start next status if not last status
73
+ #starts parent status if parent exists
74
+ def send_to_next_status
75
+ current_status = get_current_status
76
+
77
+ unless current_status.nil?
78
+ next_status_type = current_status.work_effort_status_type.next_status_type
79
+
80
+ if next_status_type.nil?
81
+ complete_work_effort
82
+ else
83
+ new_work_effort_status = WorkEffortStatus.new
84
+ new_work_effort_status.started_at = DateTime.now
85
+ new_work_effort_status.work_effort_status_type = next_status_type
86
+ new_work_effort_status.work_effort = self
87
+ new_work_effort_status.save
88
+ end
89
+
90
+ current_status.finished_at = DateTime.now
91
+ current_status.save
92
+ else
93
+ raise 'Effort Has Not Started' if current_status.nil?
94
+ end
95
+ end
96
+
97
+ def send_to_previous_status
98
+ current_status = get_current_status
99
+
100
+ unless current_status.nil?
101
+ previous_status_type = current_status.work_effort_status_type.previous_status_type
102
+
103
+ if previous_status_type.nil?
104
+ raise 'Current status is initial status' if current_status.nil?
105
+ else
106
+ new_work_effort_status = WorkEffortStatus.new
107
+ new_work_effort_status.started_at = DateTime.now
108
+ new_work_effort_status.work_effort_status_type = previous_status_type
109
+ new_work_effort_status.work_effort = self
110
+ new_work_effort_status.save
111
+ end
112
+
113
+ current_status.finished_at = DateTime.now
114
+ current_status.save
115
+ else
116
+ raise 'Effort Has Not Started' if current_status.nil?
117
+ end
118
+ end
119
+
120
+ def complete_work_effort
121
+ self.finished_at = DateTime.now
122
+ self.actual_completion_time = time_diff_in_minutes(self.finished_at.to_time, self.started_at.to_time)
123
+ self.save
124
+ self.parent.start_effort unless self.parent.nil?
125
+ end
126
+
127
+ protected
128
+ def get_current_status
129
+ self.work_effort_statuses.find_by_finished_at(nil)
130
+ end
131
+
132
+ def time_diff_in_minutes (time_one, time_two)
133
+ (((time_one - time_two).round) / 60)
134
+ end
135
+ end
@@ -0,0 +1,15 @@
1
+ class WorkEffortAssignment < ActiveRecord::Base
2
+ has_one :work_effort
3
+ belongs_to :assigned_to, :polymorphic => true
4
+ belongs_to :assigned_by, :polymorphic => true
5
+
6
+ validates_presence_of :assigned_to, :work_effort, :assigned_by
7
+
8
+ def before_destroy
9
+ unless self.work_effort.nil?
10
+ self.work_effort.work_effort_assignment_id = nil
11
+ self.work_effort.save
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,4 @@
1
+ class WorkEffortStatus < ActiveRecord::Base
2
+ belongs_to :work_effort, :dependent => :destroy
3
+ belongs_to :work_effort_status_type
4
+ end
@@ -0,0 +1,13 @@
1
+ class WorkEffortStatusType < ActiveRecord::Base
2
+ has_many :work_effort_statuses
3
+ has_one :previous_status_type, :class_name => 'WorkEffortStatusType', :foreign_key => 'previous_status_id'
4
+ has_one :next_status_type, :class_name => 'WorkEffortStatusType', :foreign_key => 'next_status_id'
5
+
6
+ def status
7
+ description
8
+ end
9
+
10
+ def self.iid(internal_identifier)
11
+ self.where('internal_identifier = ?', internal_identifier).first
12
+ end
13
+ end
@@ -0,0 +1,76 @@
1
+ class WorkRequirement < ActiveRecord::Base
2
+ acts_as_nested_set
3
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
4
+
5
+ belongs_to :work_requirement_record, :polymorphic => true
6
+ belongs_to :facility, :polymorphic => true
7
+ has_many :valid_work_assignments
8
+ has_many :work_requirement_work_effort_status_types, :dependent => :destroy
9
+ has_many :work_effort_status_types, :through => :work_requirement_work_effort_status_types
10
+ belongs_to :projected_cost, :class_name => "Cost", :foreign_key => 'cost_id'
11
+
12
+ def set_status_type_as_initial_status(status_type)
13
+ changing_status_type = self.work_effort_status_types.find_by_internal_identifier(status_type.internal_identifier)
14
+ unless changing_status_type.nil?
15
+ clear_initial_status_type
16
+ changed_status_type = self.work_requirement_work_effort_status_types.find(:first, :conditions => ["work_effort_status_type_id = ?", changing_status_type.id])
17
+ changed_status_type.is_initial_status = true
18
+ changed_status_type.save
19
+ else
20
+ raise "Work Requirement Does Not Contain Work Effort Status Type"
21
+ end
22
+ end
23
+
24
+ def add_status_type(status_type, is_initial_status=false)
25
+ status_rel = WorkRequirementWorkEffortStatusType.new
26
+ status_rel.work_effort_status_type = status_type
27
+ if is_initial_status
28
+ clear_initial_status_type
29
+ status_rel.is_initial_status = is_initial_status
30
+ end
31
+ status_rel.work_requirement = self
32
+ status_rel.save
33
+ end
34
+
35
+ def initial_work_effort_status_type
36
+ status_rel = get_initial_status_type
37
+ status_rel.nil? ? (raise "No Initial Status Set For Requirement") : status_rel.work_effort_status_type
38
+ end
39
+
40
+ def create_work_efforts(effort_class, initial_status_type=nil)
41
+ parent_effort = create_effort(effort_class, self)
42
+ self.children.each{ |req_child|
43
+ child_effort = create_effort(effort_class, req_child)
44
+ child_effort.work_effort.move_to_child_of(parent_effort.work_effort)
45
+ child_effort.save!
46
+ }
47
+
48
+ initial_status_type.nil? ? parent_effort.start(initial_work_effort_status_type) : parent_effort.start(initial_status_type)
49
+ parent_effort
50
+ end
51
+
52
+ protected
53
+ def create_effort(effort_class, req)
54
+ effort = effort_class.new
55
+
56
+ effort.description = req.description
57
+ effort.projected_completion_time = req.projected_completion_time
58
+ effort.projected_cost = req.projected_cost
59
+ effort.facility = req.facility
60
+ effort.save!
61
+
62
+ effort
63
+ end
64
+
65
+ def clear_initial_status_type
66
+ initial_status_type = get_initial_status_type
67
+ unless initial_status_type.nil?
68
+ initial_status_type.is_initial_status = false
69
+ initial_status_type.save
70
+ end
71
+ end
72
+
73
+ def get_initial_status_type
74
+ work_requirement_work_effort_status_types.where('is_initial_status = 1').first
75
+ end
76
+ end
@@ -0,0 +1,4 @@
1
+ class WorkRequirementWorkEffortStatusType < ActiveRecord::Base
2
+ belongs_to :work_requirement, :foreign_key => 'work_requirement_id'
3
+ belongs_to :work_effort_status_type, :foreign_key => 'work_effort_status_type_id'
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>ErpWorkEffort</title>
5
+ <%= stylesheet_link_tag "erp_work_effort/application" %>
6
+ <%= javascript_include_tag "erp_work_effort/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ ErpWorkEffort::Engine.routes.draw do
2
+ end
@@ -0,0 +1,208 @@
1
+ class BaseWorkEfforts < ActiveRecord::Migration
2
+
3
+ def self.up
4
+
5
+ ## work_efforts
6
+ unless table_exists?(:work_efforts)
7
+ create_table :work_efforts do |t|
8
+ t.string :description
9
+ t.string :type
10
+ t.datetime :started_at
11
+ t.datetime :finished_at
12
+ t.integer :projected_completion_time
13
+ t.integer :actual_completion_time
14
+
15
+ t.timestamps
16
+
17
+ #polymorphic columns
18
+ t.integer :facility_id
19
+ t.string :facility_type
20
+ t.integer :work_effort_record_id
21
+ t.string :work_effort_record_type
22
+
23
+ #foreign keys
24
+ t.integer :work_effort_assignment_id
25
+ t.integer :projected_cost_id
26
+ t.integer :actual_cost_id
27
+
28
+ #better nested set columns
29
+ t.integer :parent_id
30
+ t.integer :lft
31
+ t.integer :rgt
32
+ end
33
+
34
+ add_index :work_efforts, [:work_effort_record_id, :work_effort_record_type], :name => "work_effort_record_id_type"
35
+ add_index :work_efforts, [:facility_type, :facility_id], :name => "facility"
36
+ add_index :work_efforts, :work_effort_assignment_id
37
+ add_index :work_efforts, :finished_at
38
+ end
39
+
40
+ ## work_requirements
41
+ unless table_exists?(:work_requirements)
42
+ create_table :work_requirements do |t|
43
+ t.string :description
44
+ t.string :type
45
+ t.integer :projected_completion_time
46
+ t.timestamps
47
+
48
+ #polymorphic columns
49
+ t.integer :work_requirement_record_id
50
+ t.string :work_requirement_record_type
51
+ t.integer :facility_id
52
+ t.string :facility_type
53
+
54
+ # foreign keys
55
+ t.integer :cost_id
56
+
57
+ #better nested set columns
58
+ t.integer :parent_id
59
+ t.integer :lft
60
+ t.integer :rgt
61
+ end
62
+ end
63
+
64
+ ## work_requirement_work_effort_status_types
65
+ unless table_exists?(:work_requirement_work_effort_status_types)
66
+ create_table :work_requirement_work_effort_status_types do |t|
67
+ t.timestamps
68
+
69
+ #foreign keys
70
+ t.integer :work_requirement_id
71
+ t.integer :work_effort_status_type_id
72
+ t.boolean :is_initial_status
73
+ end
74
+ end
75
+
76
+ ## work_effort_statuses
77
+ unless table_exists?(:work_effort_statuses)
78
+ create_table :work_effort_statuses do |t|
79
+ t.datetime :started_at
80
+ t.datetime :finished_at
81
+ t.integer :work_effort_id
82
+ t.integer :work_effort_status_type_id
83
+
84
+ t.timestamps
85
+ end
86
+
87
+ add_index :work_effort_statuses, :work_effort_status_type_id
88
+ add_index :work_effort_statuses, :work_effort_id
89
+ end
90
+
91
+ ## work_effort_status_types
92
+ unless table_exists?(:work_effort_status_types)
93
+ create_table :work_effort_status_types do |t|
94
+ t.string :internal_identifier
95
+ t.string :description
96
+ t.integer :next_status_id
97
+ t.integer :previous_status_id
98
+
99
+ t.timestamps
100
+ end
101
+
102
+ add_index :work_effort_status_types, :internal_identifier
103
+ add_index :work_effort_status_types, :description
104
+ end
105
+
106
+ ## work_effort_assignments
107
+ unless table_exists?(:work_effort_assignments)
108
+ create_table :work_effort_assignments do |t|
109
+ t.datetime :assigned_at
110
+ t.datetime :assigned_from
111
+ t.datetime :assigned_thru
112
+ t.datetime :unassigned_at
113
+
114
+ #Polymorphic Columns
115
+ t.integer :assigned_to_id
116
+ t.string :assigned_to_type
117
+ t.integer :assigned_by_id
118
+ t.string :assigned_by_type
119
+
120
+ t.timestamps
121
+ end
122
+
123
+ add_index :work_effort_assignments, [:assigned_to_id, :assigned_to_type], :name => "assigned_to"
124
+ add_index :work_effort_assignments, :assigned_from
125
+ add_index :work_effort_assignments, :assigned_thru
126
+ end
127
+
128
+ ## valid_work_assignments
129
+ unless table_exists?(:valid_work_assignments)
130
+ create_table :valid_work_assignments do |t|
131
+ t.integer :role_type_id
132
+ t.integer :work_requirement_id
133
+
134
+ t.timestamps
135
+ end
136
+
137
+ end
138
+
139
+ ## valid_work_assignment_attributes
140
+ unless table_exists?(:valid_work_assignment_attributes)
141
+ create_table :valid_work_assignment_attributes do |t|
142
+ t.integer :valid_work_assignment_id
143
+ t.string :name
144
+ t.string :type
145
+ t.string :value
146
+
147
+ t.timestamps
148
+ end
149
+ end
150
+
151
+ ## party_resource_availabilities
152
+ unless table_exists?(:party_resource_availabilities)
153
+ create_table :party_resource_availabilities do |t|
154
+ t.datetime :from_date
155
+ t.datetime :to_date
156
+ t.integer :party_id
157
+ t.integer :pra_type_id #:party_resource_availability_type_id is too long
158
+
159
+ t.timestamps
160
+ end
161
+
162
+ add_index :party_resource_availabilities, :from_date
163
+ add_index :party_resource_availabilities, :to_date
164
+ add_index :party_resource_availabilities, :pra_type_id
165
+ add_index :party_resource_availabilities, :party_id
166
+ end
167
+
168
+ unless table_exists?(:party_resource_availability_types)
169
+ create_table :party_resource_availability_types do |t|
170
+ t.string :description
171
+ t.string :internal_identifier
172
+
173
+ t.timestamps
174
+ end
175
+
176
+ add_index :party_resource_availability_types, :internal_identifier
177
+ add_index :party_resource_availability_types, :description
178
+ end
179
+
180
+ ## costs
181
+ unless table_exists?(:costs)
182
+ create_table :costs do |t|
183
+ t.integer :money_id
184
+ t.timestamps
185
+ end
186
+ end
187
+
188
+ end
189
+
190
+ def self.down
191
+ # Drop all tables, including those that were originally created then deleted
192
+ [
193
+ # Old tables deleted and no longer used
194
+ :work_requirement_assignabilities,
195
+ # Currently used tables
196
+ :category_classifications, :categories, :work_requirement_assignability_attributes,
197
+ :valid_work_assignments, :work_effort_assignments, :work_effort_status_types,
198
+ :work_effort_statuses, :work_requirement_work_effort_status_types,
199
+ :work_requirements, :work_efforts, :party_resource_availabilities, :party_resource_availability_types,
200
+ :costs
201
+ ].each do |tbl|
202
+ if table_exists?(tbl)
203
+ drop_table tbl
204
+ end
205
+ end
206
+
207
+ end
208
+ end