-
Notifications
You must be signed in to change notification settings - Fork 79
/
007_create_wk_crm.rb
107 lines (98 loc) · 4.27 KB
/
007_create_wk_crm.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/env ruby
# encoding: utf-8
class CreateWkCrm < ActiveRecord::Migration[4.2]
def change
create_table :wk_crm_enumerations do |t|
t.string :name
t.string :position
t.boolean :is_default
t.boolean :active
t.string :enum_type, :null => false
t.timestamps null: false
end
create_table :wk_crm_activities do |t|
t.string :name
t.string :status, :null => false, :limit => 3
t.string :description
t.datetime :start_date
t.datetime :end_date
t.datetime :status_update_on
t.string :activity_type, :null => false, :limit => 3
t.string :direction, :limit => 3
t.integer :duration
t.string :location
t.references :parent, polymorphic: true, index: true
t.references :assigned_user, :class => "User", :null => true
t.references :created_by_user, :class => "User"
t.references :updated_by_user, :class => "User"
t.timestamps null: false
end
create_table :wk_crm_contacts do |t|
t.string :first_name
t.string :last_name
t.references :address, :class => "wk_addresses", :null => true
t.string :title
t.string :department
t.references :assigned_user, :class => "User", :null => true
t.string :salutation
t.string :description
#t.references :parent, polymorphic: true, index: true
t.references :account, :class => "wk_accounts", :null => true
t.references :created_by_user, :class => "User"
t.references :updated_by_user, :class => "User"
t.timestamps null: false
end
add_index :wk_crm_contacts, :address_id
create_table :wk_leads do |t|
t.string :status, :null => false, :limit => 3
t.datetime :status_update_on
t.decimal :opportunity_amount
t.references :lead_source, :class => "wk_crm_enumerations"
t.string :referred_by
t.references :account, :class => "wk_accounts", :null => true
t.references :contact, :class => "wk_crm_contacts", :null => true
t.references :created_by_user, :class => "User"
t.references :updated_by_user, :class => "User"
t.timestamps null: false
end
create_table :wk_opportunities do |t|
t.string :name
t.column :currency, :string, :limit => 5, :default => '$'
t.datetime :close_date, :null => false
t.decimal :amount, :null => false
t.references :parent, polymorphic: true, index: true
t.references :assigned_user, :class => "User", :null => true
t.references :opportunity_type, :class => "wk_crm_enumerations", :null => true
t.references :sales_stage, :class => "wk_crm_enumerations", :null => false
t.references :lead_source, :class => "wk_crm_enumerations"
t.string :probability
t.string :next_step
t.string :description
t.references :created_by_user, :class => "User"
t.references :updated_by_user, :class => "User"
t.timestamps null: false
end
#add column in wk_address table
add_column :wk_addresses, :department, :string
add_column :wk_addresses, :website, :string
#add column in wk_accounts table
add_reference :wk_accounts, :activity, :class => "wk_crm_activites", :null => true, index: true
add_column :wk_accounts, :account_category, :string
add_column :wk_accounts, :industry, :string
add_column :wk_accounts, :annual_revenue, :float
add_column :wk_accounts, :description, :string
add_reference :wk_accounts, :assigned_user, :class => "User"
add_reference :wk_accounts, :created_by_user, :class => "User"
add_reference :wk_accounts, :updated_by_user, :class => "User"
enumValues = Hash.new
enumValues["LS"] = ['Cold Call', 'Existing Customer', 'Self Generated', 'Employee', 'Partner', 'Public Relations', 'Direct Mail', 'Conference', 'Trade Show', 'Web Site', 'Word Of Mouth', 'Email', 'Other']
enumValues["SS"] = ['Prospecting', 'Qualification', 'Needs Analysis', 'Value Proposition', 'Id.Decision Makers', 'Perception Analysis', 'Proposal/Price Quote', 'Negotiation/Review', 'Closed Won', 'Closed Lost']
enumValues["OT"] = ['New Business', 'Existing Business']
enumValues["AC"] = ['Analyst', 'Competitor', 'Customer', 'Integrator', 'Investor', 'Partner', 'Press', 'Prospect', 'Reseller', 'Other']
enumValues.each do |enumType, values|
values.each_with_index do |val, index|
WkCrmEnumeration.create :name => val, :position => index+1, :is_default => index == 0, :active => true, :enum_type => enumType
end
end
end
end