erp_base_erp_svcs 4.0.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v1/base_controller.rb +17 -0
  3. data/app/controllers/api/v1/categories_controller.rb +165 -0
  4. data/app/controllers/api/v1/contact_purposes_controller.rb +24 -0
  5. data/app/controllers/api/v1/geo_zones_controller.rb +25 -0
  6. data/app/controllers/api/v1/note_types_controller.rb +27 -0
  7. data/app/controllers/api/v1/parties_controller.rb +182 -0
  8. data/app/controllers/api/v1/role_types_controller.rb +146 -0
  9. data/app/controllers/api/v1/status_applications_controller.rb +40 -0
  10. data/app/controllers/api/v1/tracked_status_types_controller.rb +146 -0
  11. data/app/controllers/api/v1/unit_of_measurements_controller.rb +16 -0
  12. data/app/models/category.rb +116 -4
  13. data/app/models/contact.rb +16 -2
  14. data/app/models/contact_purpose.rb +13 -0
  15. data/app/models/descriptive_asset.rb +17 -0
  16. data/app/models/email_address.rb +21 -3
  17. data/app/models/entity_party_role.rb +8 -0
  18. data/app/models/fixed_asset.rb +2 -0
  19. data/app/models/fixed_asset_type.rb +1 -0
  20. data/app/models/generated_item.rb +17 -0
  21. data/app/models/geo_country.rb +12 -1
  22. data/app/models/individual.rb +11 -20
  23. data/app/models/note.rb +9 -0
  24. data/app/models/note_type.rb +2 -0
  25. data/app/models/organization.rb +19 -16
  26. data/app/models/party.rb +134 -229
  27. data/app/models/party_unit_of_measurement.rb +17 -1
  28. data/app/models/phone_number.rb +32 -12
  29. data/app/models/postal_address.rb +42 -11
  30. data/app/models/relationship_type.rb +28 -1
  31. data/app/models/role_type.rb +25 -2
  32. data/app/models/status_application.rb +40 -0
  33. data/app/models/tracked_status_type.rb +12 -0
  34. data/app/models/unit_of_measurement.rb +46 -7
  35. data/app/models/view_type.rb +14 -0
  36. data/config/routes.rb +24 -0
  37. data/db/data_migrations/20110913145838_setup_compass_ae_instance.rb +22 -9
  38. data/db/migrate/20080805000020_base_erp_services.rb +235 -6
  39. data/db/migrate/20130713171653_create_party_unit_of_measurements.rb +28 -0
  40. data/db/migrate/20150716201200_add_record_to_contact.rb +42 -0
  41. data/db/migrate/20150814202823_add_party_id_to_status_application.rb +10 -0
  42. data/db/migrate/20160310163040_add_created_by_updated_by_to_erp_base_erp_svcs.rb +44 -0
  43. data/lib/erp_base_erp_svcs.rb +1 -0
  44. data/lib/erp_base_erp_svcs/config.rb +3 -2
  45. data/lib/erp_base_erp_svcs/engine.rb +8 -1
  46. data/lib/erp_base_erp_svcs/extensions.rb +7 -1
  47. data/lib/erp_base_erp_svcs/extensions/active_record/acts_as_category.rb +5 -4
  48. data/lib/erp_base_erp_svcs/extensions/active_record/acts_as_erp_type.rb +48 -9
  49. data/lib/erp_base_erp_svcs/extensions/active_record/can_be_generated.rb +54 -0
  50. data/lib/erp_base_erp_svcs/extensions/active_record/has_contacts.rb +383 -0
  51. data/lib/erp_base_erp_svcs/extensions/active_record/has_notes.rb +15 -4
  52. data/lib/erp_base_erp_svcs/extensions/active_record/has_party_roles.rb +94 -0
  53. data/lib/erp_base_erp_svcs/extensions/active_record/has_tracked_status.rb +118 -35
  54. data/lib/erp_base_erp_svcs/extensions/active_record/is_contact_mechanism.rb +94 -0
  55. data/lib/erp_base_erp_svcs/extensions/active_record/is_describable.rb +46 -42
  56. data/lib/erp_base_erp_svcs/extensions/active_record/is_tenantable.rb +40 -0
  57. data/lib/erp_base_erp_svcs/extensions/active_record/tracks_created_by_updated_by.rb +39 -0
  58. data/lib/erp_base_erp_svcs/extensions/core/numbers.rb +29 -18
  59. data/lib/erp_base_erp_svcs/extensions/core/object.rb +5 -0
  60. data/lib/erp_base_erp_svcs/extensions/core/string.rb +53 -0
  61. data/lib/erp_base_erp_svcs/non_escape_json_string.rb +1 -1
  62. data/lib/erp_base_erp_svcs/time_zone_helper.rb +57 -0
  63. data/lib/erp_base_erp_svcs/version.rb +1 -1
  64. data/lib/tasks/erp_base_erp_svcs_tasks.rake +20 -23
  65. data/spec/dummy/log/development.log +3 -0
  66. metadata +29 -22
  67. data/db/data_migrations/20110525001935_add_usd_currency.rb +0 -11
  68. data/db/data_migrations/20110609150135_add_iso_codes.rb +0 -18
  69. data/db/data_migrations/20130211555555_upgrade_compass_ae_instances_data.rb +0 -18
  70. data/db/data_migrations/20130404201756_add_guid_to_instances.rb +0 -9
  71. data/db/migrate/20120606183856_add_txn_status.rb +0 -36
  72. data/db/migrate/20130211444444_upgrade_compass_ae_instances.rb +0 -33
  73. data/db/migrate/20130404171435_add_uuid_compass_ae_instance.rb +0 -16
  74. data/db/migrate/20130411125210_add_long_lat_to_address.rb +0 -15
  75. data/db/migrate/20130522125404_create_facilities.rb +0 -114
  76. data/db/migrate/20130621182047_create_unit_of_measurements.rb +0 -18
  77. data/db/migrate/20130909163912_add_iid_index_to_role_types.rb +0 -9
  78. data/db/migrate/20130926023541_add_domain_to_unit_of_measure.rb +0 -13
  79. data/db/migrate/20130929025342_add_type_semantics_to_uom.rb +0 -54
  80. data/db/migrate/20131112013047_add_primary_to_contacts.rb +0 -13
  81. data/db/migrate/20131112013048_add_erp_base_erp_svcs_missing_indexes.rb +0 -33
  82. data/db/migrate/20131211180831_add_postal_address_to_facility.rb +0 -5
  83. data/db/migrate/20140102154311_create_fixed_asset_party_roles.rb +0 -12
  84. data/db/migrate/20140401072612_add_custom_fields_to_party.rb +0 -12
  85. data/lib/erp_base_erp_svcs/extensions/active_record/has_contact.rb +0 -69
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd247b66200f776ec62392398963b75b67626880
4
- data.tar.gz: 176c47d90d2e3a9eb81c55f38b3a8846123eb394
3
+ metadata.gz: af53376eaee3b03867d4eac5c86bbf465b87eb6a
4
+ data.tar.gz: 666166674fc07591baedd90f54d468c81a0fecfd
5
5
  SHA512:
6
- metadata.gz: 2472e8d50fda6d0985bda2a6667084c279aeb0c7e107f653741b3b063a69a64f70c3afd3bda3941ed042d964aa9335be6cfd8918bf7d03facad8b5f155bb2f18
7
- data.tar.gz: a98dfed15080b6c737197eec3eae14fd7620a853a2fe1eb4e360a2fabdfc40d5fa23fd8a6591d0cd5fd177e42f5d0cc64a83c6e17e165f47c2c77a28da46e68b
6
+ metadata.gz: 0ffbbe9793ecbac77eb21be8f4cd9cccbc8a9a0310196eb7a7fcfbb7d8ded667cc592f70704e007a31446b2823ff2cd99db0c440bf6222610798e33e2b8c52f4
7
+ data.tar.gz: 66218fbfddb1eaf2fc5f05d3dfd7c486121641ed06f30c0449f565dc24db23cb06d1d8925b69cc5f6ae26feb393c7917a8b82939f0bfdde3510eb3b82cddd86d
@@ -0,0 +1,17 @@
1
+ module Api
2
+ module V1
3
+ class BaseController < ActionController::Base
4
+
5
+ before_filter :require_login
6
+ layout false
7
+
8
+ protected
9
+
10
+ def not_authenticated
11
+ render json: {success: false, message: 'Not Authenticated'}
12
+ end
13
+
14
+ end
15
+ end # V1
16
+ end # Api
17
+
@@ -0,0 +1,165 @@
1
+ module Api
2
+ module V1
3
+ class CategoriesController < BaseController
4
+
5
+ def index
6
+ sort = nil
7
+ dir = nil
8
+ limit = nil
9
+ start = nil
10
+
11
+ unless params[:sort].blank?
12
+ sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
13
+ sort = sort_hash[:property] || 'description'
14
+ dir = sort_hash[:direction] || 'ASC'
15
+ limit = params[:limit] || 25
16
+ start = params[:start] || 0
17
+ end
18
+
19
+ query_filter = params[:query_filter].blank? ? {} : JSON.parse(params[:query_filter]).symbolize_keys
20
+
21
+ # hook method to apply any scopes passed via parameters to this api
22
+ categories = Category.apply_filters(query_filter)
23
+
24
+ # scope by dba_organizations if there are no parties passed as filters
25
+ dba_organizations = [current_user.party.dba_organization]
26
+ dba_organizations = dba_organizations.concat(current_user.party.dba_organization.child_dba_organizations)
27
+ categories = categories.scope_by_dba_organization(dba_organizations)
28
+
29
+ respond_to do |format|
30
+ format.json do
31
+
32
+ if sort and dir
33
+ categories = categories.order("#{sort} #{dir}")
34
+ end
35
+
36
+ total_count = categories.count
37
+
38
+ if start and limit
39
+ categories = categories.offset(start).limit(limit)
40
+ end
41
+
42
+ render :json => {success: true,
43
+ total_count: total_count,
44
+ categories: categories.collect { |item| item.to_data_hash }}
45
+ end
46
+ format.tree do
47
+ if params[:parent_id]
48
+ render :json => {success: true,
49
+ categories: Category.find(params[:parent_id]).children_to_tree_hash}
50
+ else
51
+ nodes = [].tap do |nodes|
52
+ categories.roots.each do |root|
53
+ nodes.push(root.to_tree_hash)
54
+ end
55
+ end
56
+
57
+ render :json => {success: true,
58
+ categories: nodes}
59
+ end
60
+
61
+ end
62
+ format.all_representation do
63
+ if params[:parent_id].present?
64
+ render :json => {success: true,
65
+ categories: BizTxnAcctRoot.to_all_representation(Category.find(params[:parent_id]))}
66
+ else
67
+
68
+
69
+ render :json => {success: true,
70
+ categories: BizTxnAcctRoot.to_all_representation(nil, [], 0, categories.roots)}
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ def show
77
+ category = Category.find(params[:id])
78
+
79
+ render json: {category: category.to_data_hash}
80
+ end
81
+
82
+ def create
83
+ parent_id = params[:parent_id]
84
+
85
+ begin
86
+ ActiveRecord::Base.transaction do
87
+ category = Category.new(
88
+ description: params[:description].strip
89
+
90
+ )
91
+
92
+ if params[:internal_identifier].present?
93
+ category.internal_identifier = params[:internal_identifier].strip
94
+ else
95
+ category.internal_identifier = Category.generate_unique_iid(params[:description].strip)
96
+ end
97
+
98
+ category.save!
99
+
100
+ if parent_id and parent_id != 'No Parent'
101
+ parent = Category.find(parent_id)
102
+ if parent
103
+ category.move_to_child_of(parent)
104
+ end
105
+ end
106
+
107
+ EntityPartyRole.create(party: current_user.party.dba_organization,
108
+ role_type: RoleType.iid('dba_org'),
109
+ entity_record: category)
110
+
111
+ render json: {success: true, category: category.to_data_hash}
112
+ end
113
+ rescue ActiveRecord::RecordInvalid => invalid
114
+ Rails.logger.error invalid.record.errors.full_messages
115
+
116
+ render json: {:success => false, :message => invalid.record.errors.full_messages.join('</br>')}
117
+ rescue => ex
118
+ Rails.logger.error ex.message
119
+ Rails.logger.error ex.backtrace.join("\n")
120
+
121
+ ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
122
+
123
+ render json: {:success => false, :message => "Error creating record"}
124
+ end
125
+ end
126
+
127
+ def update
128
+ category = Category.find(params[:id])
129
+
130
+ begin
131
+ ActiveRecord::Base.transaction do
132
+ if params[:description].present?
133
+ category.description = params[:description].strip
134
+ end
135
+
136
+ if params[:internal_identifier].present?
137
+ category.internal_identifier = params[:internal_identifier].strip
138
+ end
139
+
140
+ category.save!
141
+
142
+ render json: {success: true, category: category.to_data_hash}
143
+ end
144
+ rescue => ex
145
+ Rails.logger.error ex.message
146
+ Rails.logger.error ex.backtrace.join("\n")
147
+
148
+ # email error
149
+ ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
150
+
151
+ render json: {success: false, message: 'Application Error'}
152
+ end
153
+ end
154
+
155
+ def destroy
156
+ category = Category.find(params[:id])
157
+
158
+ category.destroy
159
+
160
+ render json: {success: true}
161
+ end
162
+
163
+ end # CategoriesController
164
+ end # V1
165
+ end # Api
@@ -0,0 +1,24 @@
1
+ module Api
2
+ module V1
3
+ class ContactPurposesController < BaseController
4
+
5
+ def index
6
+ contact_purposes = if params[:ids].present?
7
+ [ContactPurpose.where(id: params[:ids])]
8
+ else
9
+ ContactPurpose.all
10
+ end
11
+
12
+ render json: {success: true,
13
+ contact_purposes: contact_purposes.collect(&:to_data_hash)}
14
+ end
15
+
16
+ def show
17
+ contact_purpose = ContactPurpose.find(params[:id])
18
+
19
+ render json: {success: true, contact_purpose: contact_purpose.to_data_hash}
20
+ end
21
+
22
+ end # ContactPurposesController
23
+ end # V1
24
+ end # Api
@@ -0,0 +1,25 @@
1
+ module Api
2
+ module V1
3
+ class GeoZonesController < BaseController
4
+
5
+ skip_before_filter :require_login, :only => :index
6
+
7
+ def index
8
+ GeoZone.include_root_in_json = false
9
+
10
+ if params[:geo_country_iso_code_2].present?
11
+ geo_country = GeoCountry.find_by_iso_code_2(params[:geo_country_iso_code_2])
12
+ if geo_country
13
+ render json: {success: true, geo_zones: GeoZone.where('geo_country_id = ?', geo_country.id).all}
14
+ else
15
+ render json: {success: false, message: 'Invalid Geo Country'}
16
+ end
17
+
18
+ else
19
+ render json: {success: true, geo_zones: GeoZone.all}
20
+ end
21
+ end
22
+
23
+ end # GeoZonesController
24
+ end # V1
25
+ end # Api
@@ -0,0 +1,27 @@
1
+ module Api
2
+ module V1
3
+ class NoteTypesController < BaseController
4
+
5
+ def index
6
+ NoteType.include_root_in_json = false
7
+
8
+ if params[:ids]
9
+
10
+ render json: {note_types: NoteType.where(id: params[:ids].split(',')).all}
11
+ else
12
+
13
+ render json: {success: true, note_types: NoteType.all}
14
+ end
15
+ end
16
+
17
+ def show
18
+ NoteType.include_root_in_json = false
19
+
20
+ note_type = NoteType.find(params[:id])
21
+
22
+ render json: {success: true, note_type: note_type}
23
+ end
24
+
25
+ end # NoteTypesController
26
+ end # V1
27
+ end # Api
@@ -0,0 +1,182 @@
1
+ module Api
2
+ module V1
3
+ class PartiesController < BaseController
4
+
5
+ def index
6
+ query = params[:query]
7
+ sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
8
+ sort = sort_hash[:property] || 'description'
9
+ dir = sort_hash[:direction] || 'ASC'
10
+ limit = params[:limit] || 25
11
+ start = params[:start] || 0
12
+ role_types = params[:role_types]
13
+
14
+ parties = Party
15
+
16
+ unless query.blank?
17
+ parties_tbl = Party.arel_table
18
+
19
+ where_clause = nil
20
+ # if the query has commas split on the commas and treat them as separate search terms
21
+ query.split(',').each do |query_part|
22
+ if where_clause.nil?
23
+ where_clause = parties_tbl[:description].matches(query_part.strip + '%')
24
+ else
25
+ where_clause = where_clause.or(parties_tbl[:description].matches(query_part.strip + '%'))
26
+ end
27
+ end
28
+
29
+ parties = parties.where(where_clause)
30
+ end
31
+
32
+ unless params[:id].blank?
33
+ parties = parties.where(id: params[:id].split(','))
34
+ end
35
+
36
+ unless role_types.blank?
37
+ if params[:include_child_roles]
38
+ role_types = RoleType.find_child_role_types(role_types.split(',')).collect{|role_type| role_type.internal_identifier}
39
+ else
40
+ role_types = role_types.split(',')
41
+ end
42
+
43
+ parties = parties.joins(party_roles: :role_type).where('role_types.internal_identifier' => role_types)
44
+ end
45
+
46
+ # scope by dba organization
47
+ if params[:include_descendants].present? and params[:include_descendants].to_bool
48
+ dba_organization = [current_user.party.dba_organization]
49
+ dba_organization.concat(current_user.party.dba_organization.child_dba_organizations)
50
+
51
+ parties = parties.scope_by_dba_organization(dba_organization)
52
+ else
53
+ parties = parties.scope_by_dba_organization(current_user.party.dba_organization)
54
+ end
55
+
56
+ parties = parties.uniq.order("#{sort} #{dir}")
57
+
58
+ total_count = parties.count
59
+ parties = parties.offset(start).limit(limit)
60
+
61
+ render :json => {total_count: total_count, parties: parties.collect(&:to_data_hash)}
62
+ end
63
+
64
+ def create
65
+ begin
66
+ ActiveRecord::Base.transaction do
67
+ role_type_iids = params[:role_types].present? ? params[:role_types].split(',') : []
68
+ business_party_klass = params[:business_party]
69
+
70
+ business_party = business_party_klass.constantize.new
71
+ if business_party_klass == 'Organization'
72
+ business_party.description = params[:description].strip
73
+ else
74
+ business_party.current_first_name = params[:first_name].strip
75
+ business_party.current_last_name = params[:last_name].strip
76
+ end
77
+
78
+ business_party.save!
79
+
80
+ dba_organization = current_user.party.dba_organization
81
+ role_type_iids.each do |role_type_iid|
82
+ role_type = RoleType.iid(role_type_iid)
83
+
84
+ PartyRole.create(party: business_party.party, role_type: role_type)
85
+
86
+ # associate to dba_org
87
+ relationship_type = RelationshipType.find_or_create(RoleType.iid('dba_org'), role_type)
88
+
89
+ business_party.party.create_relationship(relationship_type.description,
90
+ dba_organization.id,
91
+ relationship_type)
92
+ end
93
+
94
+ business_party.party.created_by_party = current_user.party
95
+ business_party.party.save!
96
+
97
+ render :json => {success: true, party: business_party.party.to_data_hash}
98
+ end
99
+ rescue ActiveRecord::RecordInvalid => invalid
100
+
101
+ render :json => {success: false, message: invalid.record.errors.messages}
102
+ rescue => ex
103
+ Rails.logger.error ex.message
104
+ Rails.logger.error ex.backtrace.join("\n")
105
+
106
+ # email error
107
+ ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
108
+
109
+ render :json => {success: false, message: 'Application Error'}
110
+ end
111
+ end
112
+
113
+ def show
114
+ party = Party.find(params[:id])
115
+
116
+ data = party.to_data_hash
117
+
118
+ if params[:include_email]
119
+ if params[:email_purposes].present?
120
+ contact_purposes = params[:email_purposes].split(',')
121
+ data[:email_addresses] = party.email_addresses_to_hash(contact_purposes)
122
+ else
123
+ data[:email_addresses] = party.email_addresses_to_hash
124
+ end
125
+ end
126
+
127
+ if params[:include_phone_number]
128
+ if params[:phone_number_purposes].present?
129
+ contact_purposes = params[:phone_number_purposes].split(',')
130
+ data[:phone_numbers] = party.phone_numbers_to_hash(contact_purposes)
131
+ else
132
+ data[:phone_numbers] = party.phone_numbers_to_hash
133
+ end
134
+ end
135
+
136
+ if params[:include_postal_address]
137
+ if params[:postal_address_purposes].present?
138
+ contact_purposes = params[:postal_address_purposes].split(',')
139
+ data[:postal_addresses] = party.postal_addresses_to_hash(contact_purposes)
140
+ else
141
+ data[:postal_addresses] = party.postal_addresses_to_hash
142
+ end
143
+ end
144
+
145
+ data[:custom_fields] = party.custom_fields
146
+
147
+ render :json => {success: true, party: data}
148
+ end
149
+
150
+ def update_roles
151
+ ActiveRecord::Base.transaction do
152
+ begin
153
+ party = Party.find(params[:id])
154
+ role_type_iids = params[:role_type_iids].split(',')
155
+
156
+ # remove current party roles
157
+ party.party_roles.destroy_all
158
+
159
+ # assign new roles
160
+ role_type_iids.each do |role_type_iid|
161
+ role_type = RoleType.iid(role_type_iid)
162
+
163
+ PartyRole.create(party: party, role_type: role_type)
164
+ end
165
+
166
+ party.updated_by_party = current_user.party
167
+ party.save!
168
+
169
+ render :json => {success: true}
170
+
171
+ rescue Exception => ex
172
+ Rails.logger.error(e.message)
173
+ Rails.logger.error(e.backtrace.join("\n"))
174
+
175
+ render :json => {success: false}
176
+ end # begin
177
+ end # transaction
178
+ end
179
+
180
+ end # PartiesController
181
+ end # V1
182
+ end # Api