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
@@ -0,0 +1,146 @@
1
+ module Api
2
+ module V1
3
+ class RoleTypesController < BaseController
4
+
5
+ def index
6
+ if params[:party_id]
7
+ party = Party.find(params[:party_id])
8
+
9
+ render :json => {success: true, role_types: party.role_types.collect{|role_type| role_type.to_data_hash}}
10
+
11
+ elsif params[:parent]
12
+ parent = nil
13
+ # create parent if it doesn't exist
14
+ # if the parent param is a comma seperated string then
15
+ # the parent is nested from left to right
16
+ params[:parent].split(',').each do |parent_iid|
17
+ if parent
18
+ parent = RoleType.find_or_create(parent_iid, parent_iid.humanize, parent)
19
+ else
20
+ parent = RoleType.find_or_create(parent_iid, parent_iid.humanize)
21
+ end
22
+ end
23
+
24
+ respond_to do |format|
25
+ format.tree do
26
+ render :json => {success: true, role_types: parent.children_to_tree_hash}
27
+ end
28
+ format.json do
29
+ render :json => {success: true, role_types: RoleType.to_all_representation(parent)}
30
+ end
31
+ end
32
+
33
+ # if ids are passed look up on the Role Types with the ids passed
34
+ elsif params[:ids]
35
+ ids = params[:ids].split(',').compact
36
+
37
+ role_types = []
38
+
39
+ ids.each do |id|
40
+ # check if id is a integer if so fine by id
41
+ if id.is_integer?
42
+ role_type = RoleType.find(id)
43
+ else
44
+ role_type = RoleType.iid(id)
45
+ end
46
+
47
+ if role_type
48
+ respond_to do |format|
49
+ format.tree do
50
+ data = role_type.to_hash({
51
+ only: [:id, :parent_id, :internal_identifier],
52
+ leaf: role_type.leaf?,
53
+ text: role_type.to_label,
54
+ children: []
55
+ })
56
+
57
+ parent = nil
58
+ role_types.each do |role_type_hash|
59
+ if role_type_hash[:id] == data[:parent_id]
60
+ parent = role_type_hash
61
+ end
62
+ end
63
+
64
+ if parent
65
+ parent[:children].push(data)
66
+ else
67
+ role_types.push(data)
68
+ end
69
+ end
70
+ format.json do
71
+ role_types.push(role_type.to_hash(only: [:id, :description, :internal_identifier]))
72
+ end
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ render :json => {success: true, role_types: role_types}
79
+
80
+ # get all role types
81
+ else
82
+ respond_to do |format|
83
+ format.tree do
84
+ nodes = [].tap do |nodes|
85
+ RoleType.roots.each do |root|
86
+ nodes.push(root.to_tree_hash)
87
+ end
88
+ end
89
+
90
+ render :json => {success: true, role_types: nodes}
91
+ end
92
+ format.json do
93
+ render :json => {success: true, role_types: RoleType.to_all_representation}
94
+ end
95
+ end
96
+
97
+ end
98
+ end
99
+
100
+ def show
101
+ id = params[:id]
102
+
103
+ # check if id is a integer if so fine by id
104
+ if id.is_integer?
105
+ role_type = RoleType.find(id)
106
+ else
107
+ role_type = RoleType.iid(id)
108
+ end
109
+
110
+ respond_to do |format|
111
+ format.tree do
112
+ render :json => {success: true, role_type: role_type.to_tree_hash}
113
+ end
114
+ format.json do
115
+ render :json => {success: true, role_type: role_type.to_hash(only: [:id, :description, :internal_identifier])}
116
+ end
117
+ end
118
+ end
119
+
120
+ def create
121
+ description = params[:description].strip
122
+
123
+ begin
124
+ ActiveRecord::Base.transaction do
125
+ role_type = RoleType.create!(description: description, internal_identifier: description.to_iid)
126
+
127
+ if params[:parent] != 'No Parent'
128
+ parent = RoleType.iid(params[:parent])
129
+ role_type.move_to_child_of(parent)
130
+ elsif params[:default_parent]
131
+ parent = RoleType.iid(params[:default_parent])
132
+ role_type.move_to_child_of(parent)
133
+ end
134
+
135
+ render :json => {success: true, role_type: role_type.to_hash(only: [:id, :description, :internal_identifier])}
136
+ end
137
+ rescue ActiveRecord::RecordInvalid => invalid
138
+ Rails.logger.error invalid.record.errors.full_messages
139
+
140
+ render :json => {:success => false, :message => invalid.record.errors.full_messages.join('</br>')}
141
+ end
142
+ end
143
+
144
+ end # RoleTypesController
145
+ end # V1
146
+ end # Api
@@ -0,0 +1,40 @@
1
+ module Api
2
+ module V1
3
+ class StatusApplicationsController < BaseController
4
+
5
+ def index
6
+ statuses = if params[:record_id].present? && params[:record_type].present?
7
+
8
+ # if the record acts as BizTxnEvent we need to use BizTxnEvent
9
+ record = params[:record_type].constantize.find(params[:record_id])
10
+ if record.respond_to?(:root_txn)
11
+ record_type = 'BizTxnEvent'
12
+ record_id = record.root_txn.id
13
+ else
14
+ record_type = params[:record_type]
15
+ record_id = params[:record_id]
16
+ end
17
+
18
+ StatusApplication.where('status_application_record_id = ? and status_application_record_type = ?',
19
+ record_id,
20
+ record_type)
21
+ .includes(:tracked_status_type).order('created_at desc').collect do |status|
22
+ status.to_data_hash
23
+ end
24
+
25
+ else
26
+ StatusApplication.all.collect { |status| status.to_data_hash }
27
+ end
28
+
29
+ render :json => {:success => true, :status_applications => statuses}
30
+ end
31
+
32
+ def show
33
+ status_application = StatusApplication.find(params[:id])
34
+
35
+ render :json => {:success => true, :status_application => status_application.to_data_hash}
36
+ end
37
+
38
+ end # StatusApplicationsController
39
+ end # V1
40
+ end # Api
@@ -0,0 +1,146 @@
1
+ module Api
2
+ module V1
3
+ class TrackedStatusTypesController < BaseController
4
+
5
+ def index
6
+ # look up parent by internal identifier
7
+ if params[:parent].present?
8
+ parent = nil
9
+ # create parent if it doesn't exist
10
+ # if the parent param is a comma separated string then
11
+ # the parent is nested from left to right
12
+ params[:parent].split(',').each do |parent_iid|
13
+ if parent
14
+ parent = TrackedStatusType.find_or_create(parent_iid, parent_iid.humanize, parent)
15
+ else
16
+ parent = TrackedStatusType.find_or_create(parent_iid, parent_iid.humanize)
17
+ end
18
+ end
19
+
20
+ respond_to do |format|
21
+ format.tree do
22
+ render :json => {success: true, tracked_status_types: parent.children_to_tree_hash}
23
+ end
24
+ format.json do
25
+ render :json => {success: true, tracked_status_types: parent.children.all.collect{|item| item.to_data_hash}}
26
+ end
27
+ end
28
+
29
+ # if parent id is passed find parent and get its children
30
+ elsif params[:parent_id].present?
31
+ parent = TrackedStatusType.find(params[:parent_id])
32
+
33
+ respond_to do |format|
34
+ format.tree do
35
+ render :json => {success: true, tracked_status_types: parent.children_to_tree_hash}
36
+ end
37
+ format.json do
38
+ render :json => {success: true, tracked_status_types: parent.children.all.collect{|item| item.to_data_hash}}
39
+ end
40
+ end
41
+ # if ids are passed look up on the Tracked Status Types with the ids passed
42
+ elsif params[:ids].present?
43
+ ids = params[:ids].split(',').compact
44
+
45
+ tracked_status_types = []
46
+
47
+ ids.each do |id|
48
+ # check if id is a integer if so fine by id
49
+ if id.is_integer?
50
+ tracked_status_type = TrackedStatusType.find(id)
51
+ else
52
+ tracked_status_type = TrackedStatusType.iid(id)
53
+ end
54
+
55
+ respond_to do |format|
56
+ format.tree do
57
+ data = tracked_status_type.to_hash({
58
+ only: [:id, :parent_id, :internal_identifier],
59
+ leaf: tracked_status_type.leaf?,
60
+ text: tracked_status_type.to_label,
61
+ children: []
62
+ })
63
+
64
+ parent = nil
65
+ tracked_status_types.each do |tracked_status_type_hash|
66
+ if tracked_status_type_hash[:id] == data[:parent_id]
67
+ parent = tracked_status_type_hash
68
+ end
69
+ end
70
+
71
+ if parent
72
+ parent[:children].push(data)
73
+ else
74
+ tracked_status_types.push(data)
75
+ end
76
+ end
77
+ format.json do
78
+ tracked_status_types.push(tracked_status_type.to_data_hash)
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ render :json => {success: true, tracked_status_types: role_types}
85
+
86
+ # get all role types
87
+ else
88
+ respond_to do |format|
89
+ format.tree do
90
+ nodes = [].tap do |nodes|
91
+ TrackedStatusType.roots.each do |root|
92
+ nodes.push(root.to_tree_hash)
93
+ end
94
+ end
95
+
96
+ render :json => {success: true, tracked_status_types: nodes}
97
+ end
98
+ format.json do
99
+ render :json => {success: true, tracked_status_types: TrackedStatusType.where('parent_id is null').all.collect{|item| item.to_data_hash}}
100
+ end
101
+ end
102
+
103
+ end
104
+ end
105
+
106
+ def show
107
+ id = params[:id]
108
+
109
+ # check if id is a integer if so fine by id
110
+ if id.is_integer?
111
+ tracked_status_type = TrackedStatusType.find(id)
112
+ else
113
+ tracked_status_type = TrackedStatusType.iid(id)
114
+ end
115
+
116
+ respond_to do |format|
117
+ format.tree do
118
+ render :json => {success: true, tracked_status_type: tracked_status_type.to_tree_hash}
119
+ end
120
+ format.json do
121
+ render :json => {success: true, tracked_status_type: tracked_status_type.to_data_hash}
122
+ end
123
+ end
124
+ end
125
+
126
+ def create
127
+ description = params[:description].strip
128
+
129
+ ActiveRecord::Base.transaction do
130
+ tracked_status_type = TrackedStatusType.create(description: description, internal_identifier: description.to_iid)
131
+
132
+ if params[:parent] != 'No Parent'
133
+ parent = TrackedStatusType.iid(params[:parent])
134
+ tracked_status_type.move_to_child_of(parent)
135
+ elsif params[:default_parent]
136
+ parent = TrackedStatusType.iid(params[:default_parent])
137
+ tracked_status_type.move_to_child_of(parent)
138
+ end
139
+
140
+ render :json => {success: true, tracked_status_type: tracked_status_type.to_data_hash}
141
+ end
142
+ end
143
+
144
+ end # TrackedStatusTypesController
145
+ end # V1
146
+ end # Api
@@ -0,0 +1,16 @@
1
+ module Api
2
+ module V1
3
+ class UnitOfMeasurementsController < BaseController
4
+
5
+ def index
6
+ render json: {
7
+ unit_of_measurements:
8
+ UnitOfMeasurement.scope_by_dba_organization(current_user.party.dba_organization).collect do |uom|
9
+ uom.to_data_hash
10
+ end
11
+ }
12
+ end
13
+
14
+ end # UnitOfMeasurementsController
15
+ end # V1
16
+ end # Api
@@ -1,13 +1,125 @@
1
+ # unless table_exists?(:categories)
2
+ # create_table :categories do |t|
3
+ # t.string :description
4
+ # t.string :external_identifier
5
+ # t.datetime :from_date
6
+ # t.datetime :to_date
7
+ # t.string :internal_identifier
8
+ #
9
+ # # polymorphic assns
10
+ # t.integer :category_record_id
11
+ # t.string :category_record_type
12
+ #
13
+ # # nested set cols
14
+ # t.integer :parent_id
15
+ # t.integer :lft
16
+ # t.integer :rgt
17
+ #
18
+ # t.timestamps
19
+ # end
20
+ # add_index :categories, [:category_record_id, :category_record_type], :name => "category_polymorphic"
21
+ # add_index :categories, :internal_identifier, :name => 'categories_internal_identifier_idx'
22
+ # add_index :categories, :parent_id, :name => 'categories_parent_id_idx'
23
+ # add_index :categories, :lft, :name => 'categories_lft_idx'
24
+ # add_index :categories, :rgt, :name => 'categories_rgt_idx'
25
+ # end
26
+
27
+
1
28
  class Category < ActiveRecord::Base
2
29
  acts_as_nested_set
30
+ has_party_roles
31
+
32
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
33
+ acts_as_erp_type
3
34
 
4
35
  attr_protected :created_at, :updated_at
5
36
 
37
+ validates :internal_identifier, uniqueness: {allow_nil: false}
38
+
6
39
  belongs_to :category_record, :polymorphic => true
7
40
  has_many :category_classifications, :dependent => :destroy
8
-
9
- def self.iid( internal_identifier_string )
10
- where("internal_identifier = ?",internal_identifier_string.to_s).first
41
+
42
+ class << self
43
+ # Filter records
44
+ #
45
+ # @param filters [Hash] a hash of filters to be applied,
46
+ # @param statement [ActiveRecord::Relation] the query being built
47
+ # @return [ActiveRecord::Relation] the query being built
48
+ def apply_filters(filters, statement=nil)
49
+ unless statement
50
+ statement = self
51
+ end
52
+
53
+ # filter by parent
54
+ if filters[:parent]
55
+ if filters[:parent].is_integer?
56
+ statement = statement.where(categories: {parent_id: filters[:parent]})
57
+ else
58
+ statement = statement.where(categories: {parent_id: Category.iid(filters[:parent])})
59
+ end
60
+ end
61
+
62
+ # filter by query which will filter on description
63
+ if filters[:query]
64
+ statement = statement.where('description like ?', "%#{filters[:query].strip}%")
65
+ end
66
+
67
+ statement
68
+ end
69
+
70
+ # scope by dba organization
71
+ #
72
+ # @param dba_organization [Party] dba organization to scope by
73
+ #
74
+ # @return [ActiveRecord::Relation]
75
+ def scope_by_dba_organization(dba_organization)
76
+ scope_by_party(dba_organization, {role_types: 'dba_org'})
77
+ end
78
+
79
+ alias scope_by_dba scope_by_dba_organization
80
+
81
+ # scope by party
82
+ #
83
+ # @param party [Integer | Party | Array] either a id of Party record, a Party record, an array of Party records
84
+ # or an array of Party ids
85
+ # @param options [Hash] options to apply to this scope
86
+ # @option options [String | Array] :role_types BizTxnAcctPtyRtype internal identifiers to include in the scope,
87
+ # comma separated or an Array
88
+ #
89
+ # @return [ActiveRecord::Relation]
90
+ def scope_by_party(party, options={})
91
+ statement = joins(:entity_party_roles)
92
+ .where(entity_party_roles: {party_id: party}).uniq
93
+
94
+ if options[:role_types]
95
+ role_types = options[:role_types]
96
+ unless role_types.is_a? Array
97
+ role_types = role_types.split(',')
98
+ end
99
+
100
+ statement = statement.joins(entity_party_roles: :role_type)
101
+ .where(role_types: {internal_identifier: role_types})
102
+ end
103
+
104
+ statement
105
+ end
106
+
107
+ def iid(internal_identifier)
108
+ where("internal_identifier = ?", internal_identifier).first
109
+ end
110
+ end
111
+
112
+ def to_data_hash
113
+ to_hash(
114
+ only: [
115
+ :id,
116
+ :description,
117
+ :internal_identifier,
118
+ :created_at,
119
+ :updated_at
120
+ ],
121
+ leaf: leaf?
122
+ )
11
123
  end
12
-
124
+
13
125
  end