erp_orders 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/GPL-3-LICENSE +674 -0
  2. data/README.rdoc +2 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/javascripts/erp_orders/application.js +9 -0
  5. data/app/assets/stylesheets/erp_orders/application.css +7 -0
  6. data/app/controllers/erp_orders/erp_app/desktop/order_manager/base_controller.rb +147 -0
  7. data/app/controllers/erp_orders/erp_app/organizer/order_management/base_controller.rb +19 -0
  8. data/app/helpers/erp_orders/application_helper.rb +4 -0
  9. data/app/models/charge_line.rb +21 -0
  10. data/app/models/charge_line_payment_txn.rb +5 -0
  11. data/app/models/extensions/agreement.rb +6 -0
  12. data/app/models/extensions/money.rb +3 -0
  13. data/app/models/extensions/party.rb +3 -0
  14. data/app/models/extensions/product_instance.rb +3 -0
  15. data/app/models/extensions/product_type.rb +3 -0
  16. data/app/models/line_item_role_type.rb +4 -0
  17. data/app/models/order_line_item.rb +27 -0
  18. data/app/models/order_line_item_pty_role.rb +35 -0
  19. data/app/models/order_line_item_type.rb +4 -0
  20. data/app/models/order_txn.rb +381 -0
  21. data/app/models/order_txn_type.rb +4 -0
  22. data/app/views/layouts/erp_orders/application.html.erb +14 -0
  23. data/config/routes.rb +14 -0
  24. data/db/data_migrations/20110605231556_create_order_party_roles.rb +23 -0
  25. data/db/data_migrations/20110728201731_create_desktop_app_order_manager.rb +25 -0
  26. data/db/data_migrations/20110728201732_create_organizer_app_order_management.rb +14 -0
  27. data/db/migrate/20080805000060_base_orders.rb +175 -0
  28. data/db/migrate/20110602194707_update_order_txn_ship_to_bill_to.rb +25 -0
  29. data/lib/erp_orders/engine.rb +13 -0
  30. data/lib/erp_orders/extensions/active_record/acts_as_order_txn.rb +111 -0
  31. data/lib/erp_orders/extensions.rb +1 -0
  32. data/lib/erp_orders/version.rb +3 -0
  33. data/lib/erp_orders.rb +5 -0
  34. data/lib/tasks/erp_orders_tasks.rake +4 -0
  35. data/public/javascripts/erp_app/desktop/applications/order_manager/line_items_grid_panel.js +100 -0
  36. data/public/javascripts/erp_app/desktop/applications/order_manager/module.js +85 -0
  37. data/public/javascripts/erp_app/desktop/applications/order_manager/orders_grid_panel.js +163 -0
  38. data/public/javascripts/erp_app/desktop/applications/order_manager/payments_grid_panel.js +109 -0
  39. data/public/javascripts/erp_app/organizer/applications/order_management/base.js +127 -0
  40. data/public/javascripts/erp_app/organizer/applications/order_management/extensions.js +115 -0
  41. data/public/javascripts/erp_app/organizer/applications/order_management/line_items_grid_panel.js +99 -0
  42. data/public/javascripts/erp_app/organizer/applications/order_management/orders_grid_panel.js +205 -0
  43. data/public/javascripts/erp_app/organizer/applications/order_management/payments_grid_panel.js +93 -0
  44. data/spec/dummy/Rakefile +7 -0
  45. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  46. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  47. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  48. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  49. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  50. data/spec/dummy/config/application.rb +49 -0
  51. data/spec/dummy/config/boot.rb +10 -0
  52. data/spec/dummy/config/database.yml +8 -0
  53. data/spec/dummy/config/environment.rb +5 -0
  54. data/spec/dummy/config/environments/spec.rb +27 -0
  55. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  56. data/spec/dummy/config/initializers/inflections.rb +10 -0
  57. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  58. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  59. data/spec/dummy/config/initializers/session_store.rb +8 -0
  60. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  61. data/spec/dummy/config/locales/en.yml +5 -0
  62. data/spec/dummy/config/routes.rb +4 -0
  63. data/spec/dummy/config.ru +4 -0
  64. data/spec/dummy/public/404.html +26 -0
  65. data/spec/dummy/public/422.html +26 -0
  66. data/spec/dummy/public/500.html +26 -0
  67. data/spec/dummy/public/favicon.ico +0 -0
  68. data/spec/dummy/script/rails +6 -0
  69. data/spec/models/charge_line_payment_txn_spec.rb +11 -0
  70. data/spec/models/charge_line_spec.rb +11 -0
  71. data/spec/models/line_item_role_type_spec.rb +11 -0
  72. data/spec/models/order_line_item_pty_role_spec.rb +13 -0
  73. data/spec/models/order_line_item_spec.rb +12 -0
  74. data/spec/models/order_line_item_type_spec.rb +14 -0
  75. data/spec/models/order_txn_spec.rb +11 -0
  76. data/spec/models/order_txn_type_spec.rb +11 -0
  77. data/spec/spec_helper.rb +60 -0
  78. metadata +203 -0
@@ -0,0 +1,381 @@
1
+ class OrderTxn < ActiveRecord::Base
2
+ acts_as_biz_txn_event
3
+
4
+ belongs_to :order_txn_record, :polymorphic => true, :dependent => :destroy
5
+ has_many :order_line_items, :dependent => :destroy
6
+ has_many :charge_lines, :as => :charged_item
7
+
8
+ alias :line_items :order_line_items
9
+
10
+ # validation
11
+ validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :update, :allow_nil => true
12
+
13
+ #find a order by given biz txn party role iid and party
14
+ def self.find_by_party_role(biz_txn_party_role_type_iid, party)
15
+ biz_txn_party_roles = BizTxnPartyRole.find(
16
+ :all,
17
+ :conditions => ['party_id = ? and biz_txn_party_role_type_id = ?', party.id, BizTxnPartyRoleType.find_by_internal_identifier(biz_txn_party_role_type_iid).id])
18
+
19
+ biz_txn_party_roles.collect{|item| item.biz_txn_event.biz_txn_record}
20
+ end
21
+
22
+ # get the total charges for an order.
23
+ # The total will be returned as Money.
24
+ # There may be multiple Monies assocated with an order, such as points and
25
+ # dollars. To handle this, the method should return an array of Monies
26
+ #
27
+ def get_total_charges
28
+ # get all of the charge lines associated with the order and order_lines
29
+ total_hash = Hash.new
30
+ all_charges = get_all_charge_lines
31
+ # loop through all of the charges and combine charges for each money type
32
+ all_charges.each do |charge|
33
+ cur_money = charge.money
34
+ cur_total = total_hash[cur_money.currency.internal_identifier]
35
+ if (cur_total.nil?)
36
+ cur_total = cur_money.clone
37
+ else
38
+ cur_total.amount = 0 if cur_total.amount.nil?
39
+ cur_total.amount += cur_money.amount if !cur_money.amount.nil?
40
+ end
41
+ total_hash[cur_money.currency.internal_identifier] = cur_total
42
+ end
43
+ return total_hash.values
44
+ end
45
+
46
+ #get all charge lines on order and order line items
47
+ def get_all_charge_lines
48
+ all_charges = []
49
+ all_charges.concat(charge_lines)
50
+ order_line_items.each do |line_item|
51
+ all_charges.concat(line_item.charge_lines)
52
+ end
53
+ all_charges
54
+ end
55
+
56
+ def submit
57
+ #Template Method
58
+ end
59
+
60
+ #add product_type or product_instance line item
61
+ def add_line_item(object, reln_type = nil, to_role = nil, from_role = nil)
62
+ class_name = object.class.name
63
+ if object.is_a?(Array)
64
+ class_name = object.first.class.name
65
+ else
66
+ class_name = object.class.name
67
+ end
68
+
69
+ case class_name
70
+ when 'ProductType'
71
+ return add_product_type_line_item(object, reln_type, to_role, from_role)
72
+ when 'ProductInstance'
73
+ return add_product_instance_line_item(object, reln_type, to_role, from_role)
74
+ end
75
+ end
76
+
77
+ def add_product_type_line_item(product_type, reln_type = nil, to_role = nil, from_role = nil)
78
+
79
+ li = OrderLineItem.new
80
+
81
+ if(product_type.is_a?(Array))
82
+ if (product_type.size == 0)
83
+ return
84
+ elsif (product_type.size == 1)
85
+ product_type_for_line_item = product_type[0]
86
+ else # more than 1 in the array, so it's a package
87
+ product_type_for_line_item = ProductType.new
88
+ product_type_for_line_item.description = to_role.description
89
+
90
+ product_type.each do |product|
91
+ # make a product-type-reln
92
+ reln = ProdTypeReln.new
93
+ reln.prod_type_reln_type = reln_type
94
+ reln.role_type_id_from = from_role.id
95
+ reln.role_type_id_to = to_role.id
96
+
97
+ #associate package on the "to" side of reln
98
+ reln.prod_type_to = product_type_for_line_item
99
+
100
+ #assocation product_type on the "from" side of the reln
101
+ reln.prod_type_from = product
102
+ reln.save
103
+ end
104
+ end
105
+ else
106
+ product_type_for_line_item = product_type
107
+ end
108
+
109
+ li.product_type = product_type_for_line_item
110
+ self.line_items << li
111
+ li.save
112
+ return li
113
+ end
114
+
115
+ def add_product_instance_line_item(product_instance, reln_type = nil, to_role = nil, from_role = nil)
116
+
117
+ li = OrderLineItem.new
118
+
119
+ if(product_instance.is_a?(Array))
120
+ if (product_instance.size == 0)
121
+ return
122
+ elsif (product_instance.size == 1)
123
+ product_instance_for_line_item = product_instance[0]
124
+ else # more than 1 in the array, so it's a package
125
+ product_instance_for_line_item = ProductInstance.new
126
+ product_instance_for_line_item.description = to_role.description
127
+ product_instance_for_line_item.save
128
+
129
+ product_instance.each do |product|
130
+ # make a product-type-reln
131
+ reln = ProdInstanceReln.new
132
+ reln.prod_instance_reln_type = reln_type
133
+ reln.role_type_id_from = from_role.id
134
+ reln.role_type_id_to = to_role.id
135
+
136
+ #associate package on the "to" side of reln
137
+ reln.prod_instance_to = product_instance_for_line_item
138
+
139
+ #assocation product_instance on the "from" side of the reln
140
+ reln.prod_instance_from = product
141
+ reln.save
142
+ end
143
+ end
144
+ else
145
+ product_instance_for_line_item = product_instance
146
+ end
147
+
148
+ li.product_instance = product_instance_for_line_item
149
+ self.line_items << li
150
+ li.save
151
+ return li
152
+ end
153
+
154
+ def find_party_by_role(role_type_iid)
155
+ party = nil
156
+
157
+ tpr = self.root_txn.biz_txn_party_roles.find(:first, :include => :biz_txn_party_role_type, :conditions => ['biz_txn_party_role_types.internal_identifier = ?',role_type_iid])
158
+ party = tpr.party unless tpr.nil?
159
+
160
+ party
161
+ end
162
+
163
+ def set_shipping_info(party)
164
+ self.ship_to_first_name = party.business_party.current_first_name
165
+ self.ship_to_last_name = party.business_party.current_last_name
166
+ shipping_address = party.find_contact_with_purpose(PostalAddress, ContactPurpose.shipping) || party.find_contact_with_purpose(PostalAddress, ContactPurpose.default)
167
+ unless shipping_address.nil?
168
+ shipping_address = shipping_address.contact_mechanism
169
+ self.ship_to_address_line_1 = shipping_address.address_line_1
170
+ self.ship_to_address_line_2 = shipping_address.address_line_2
171
+ self.ship_to_city = shipping_address.city
172
+ self.ship_to_state = shipping_address.state
173
+ self.ship_to_postal_code = shipping_address.zip
174
+ #self.ship_to_country_name = shipping_address.country_name
175
+ #self.ship_to_country = shipping_address.country
176
+ end
177
+ end
178
+
179
+ def set_billing_info(party)
180
+ self.email = party.find_contact_mechanism_with_purpose(EmailAddress, ContactPurpose.billing).email_address unless party.find_contact_mechanism_with_purpose(EmailAddress, ContactPurpose.billing).nil?
181
+ self.phone_number = party.find_contact_mechanism_with_purpose(PhoneNumber, ContactPurpose.billing).phone_number unless party.find_contact_mechanism_with_purpose(PhoneNumber, ContactPurpose.billing).nil?
182
+
183
+ self.bill_to_first_name = party.business_party.current_first_name
184
+ self.bill_to_last_name = party.business_party.current_last_name
185
+ billing_address = party.find_contact_with_purpose(PostalAddress, ContactPurpose.billing) || party.find_contact_with_purpose(PostalAddress, ContactPurpose.default)
186
+ unless billing_address.nil?
187
+ billing_address = billing_address.contact_mechanism
188
+ self.bill_to_address_line_1 = billing_address.address_line_1
189
+ self.bill_to_address_line_2 = billing_address.address_line_2
190
+ self.bill_to_city = billing_address.city
191
+ self.bill_to_state = billing_address.state
192
+ self.bill_to_postal_code = billing_address.zip
193
+ #self.bill_to_country_name = billing_address.country_name
194
+ #self.bill_to_country = billing_address.country
195
+ end
196
+ end
197
+
198
+ def determine_txn_party_roles
199
+ #Template Method
200
+ end
201
+
202
+ def determine_charge_elements
203
+ #Template Method
204
+ end
205
+
206
+ def determine_charge_accounts
207
+ #Template Method
208
+ end
209
+
210
+ ###############################################################################
211
+ #BizTxnEvent Overrides
212
+ ###############################################################################
213
+ def create_dependent_txns
214
+ #Template Method
215
+ end
216
+
217
+ ################################################################
218
+ ################################################################
219
+ # Payment methods
220
+ # these methods are used to capture payments on orders
221
+ ################################################################
222
+ ################################################################
223
+
224
+ def authorize_payments(financial_txns, credit_card, gateway, gateway_options={}, use_delayed_jobs=true)
225
+ all_txns_authorized = true
226
+ authorized_txns = []
227
+ gateway_message = nil
228
+
229
+ #check if we are using delayed jobs or not
230
+ unless use_delayed_jobs
231
+ financial_txns.each do |financial_txn|
232
+ financial_txn.authorize(credit_card, gateway, gateway_options)
233
+ if financial_txn.payments.empty?
234
+ all_txns_authorized = false
235
+ gateway_message = 'Unknown Gateway Error'
236
+ break
237
+ elsif !financial_txn.payments.first.success
238
+ all_txns_authorized = false
239
+ gateway_message = financial_txn.payments.first.payment_gateways.first.response
240
+ break
241
+ else
242
+ authorized_txns << financial_txn
243
+ end
244
+ end
245
+ else
246
+ financial_txns.each do |financial_txn|
247
+ #push into delayed job so we can fire off more payments if needed
248
+ ErpTxnsAndAccts::DelayedJobs::PaymentGatewayJob.start(financial_txn, gateway, :authorize, gateway_options, credit_card)
249
+ end
250
+ #wait till all payments are complete
251
+ #wait a max of 120 seconds 2 minutes
252
+ wait_counter = 0
253
+ while !all_payment_jobs_completed?(financial_txns, :authorized)
254
+ break if wait_counter == 40
255
+ sleep 3
256
+ wait_counter += 1
257
+ end
258
+
259
+ result, gateway_message, authorized_txns = all_payment_jobs_successful?(financial_txns)
260
+
261
+ unless result
262
+ all_txns_authorized = false
263
+ end
264
+ end
265
+ return all_txns_authorized, authorized_txns, gateway_message
266
+ end
267
+
268
+ def capture_payments(authorized_txns, credit_card, gateway, gateway_options={}, use_delayed_jobs=true)
269
+ all_txns_captured = true
270
+ gateway_message = nil
271
+
272
+ #check if we are using delayed jobs or not
273
+ unless use_delayed_jobs
274
+ authorized_txns.each do |financial_txn|
275
+ result = financial_txn.capture(credit_card, gateway, gateway_options)
276
+ unless(result[:success])
277
+ all_txns_captured = false
278
+ gateway_message = result[:gateway_message]
279
+ break
280
+ end
281
+ end
282
+ else
283
+ authorized_txns.each do |financial_txn|
284
+ #push into delayed job so we can fire off more payments if needed
285
+ ErpTxnsAndAccts::DelayedJobs::PaymentGatewayJob.start(financial_txn, gateway, :capture, gateway_options, credit_card)
286
+ end
287
+
288
+ #wait till all payments are complete
289
+ #wait a max of 120 seconds 2 minutes
290
+ wait_counter = 0
291
+ while !all_payment_jobs_completed?(authorized_txns, :captured)
292
+ break if wait_counter == 40
293
+ sleep 3
294
+ wait_counter += 1
295
+ end
296
+
297
+ result, gateway_message, authorized_txns = all_payment_jobs_successful?(authorized_txns)
298
+
299
+ unless result
300
+ all_txns_captured = false
301
+ end
302
+ end
303
+
304
+ return all_txns_captured, gateway_message
305
+ end
306
+
307
+ def rollback_authorizations(authorized_txns, credit_card, gateway, gateway_options={}, use_delayed_jobs=true)
308
+ all_txns_rolledback = true
309
+
310
+ #check if we are using delayed jobs or not
311
+ unless use_delayed_jobs
312
+ authorized_txns.each do |financial_txn|
313
+ result = financial_txn.reverse_authorization(credit_card, gateway, gateway_options)
314
+ unless(result[:success])
315
+ all_txns_rolledback = false
316
+ end
317
+ end
318
+ else
319
+ authorized_txns.each do |financial_txn|
320
+ #push into delayed job so we can fire off more payments if needed
321
+ ErpTxnsAndAccts::DelayedJobs::PaymentGatewayJob.start(financial_txn, gateway, :reverse_authorization, gateway_options, credit_card)
322
+ end
323
+
324
+ #wait till all payments are complete
325
+ #wait a max of 120 seconds 2 minutes
326
+ wait_counter = 0
327
+ while !all_payment_jobs_completed?(authorized_txns, :authorization_reversed)
328
+ break if wait_counter == 40
329
+ sleep 3
330
+ wait_counter += 1
331
+ end
332
+
333
+ result, gateway_message, authorized_txns = all_payment_jobs_successful?(authorized_txns)
334
+
335
+ unless result
336
+ all_txns_rolledback = false
337
+ end
338
+ end
339
+
340
+ all_txns_rolledback
341
+ end
342
+
343
+ def all_payment_jobs_completed?(financial_txns, state)
344
+ result = true
345
+
346
+ #check the financial txns as they come back
347
+ financial_txns.each do |financial_txn|
348
+ payments = financial_txn.payments(true)
349
+ if payments.empty? || payments.first.current_state.to_sym != state
350
+ result = false
351
+ break
352
+ end
353
+ end
354
+
355
+ result
356
+ end
357
+
358
+ def all_payment_jobs_successful?(financial_txns)
359
+ result = true
360
+ message = nil
361
+ authorized_txns = []
362
+
363
+ #check the financial txns to see all were successful, if not get message
364
+ financial_txns.each do |financial_txn|
365
+ payments = financial_txn.payments(true)
366
+ if payments.empty? || !payments.first.success
367
+ result = false
368
+ unless payments.empty?
369
+ message = financial_txn.payments.first.payment_gateways.first.response
370
+ else
371
+ message = "Unknown Protobase Error"
372
+ end
373
+ else
374
+ authorized_txns << financial_txn
375
+ end
376
+ end
377
+
378
+ return result, message, authorized_txns
379
+ end
380
+
381
+ end
@@ -0,0 +1,4 @@
1
+ class OrderTxnType < ActiveRecord::Base
2
+ acts_as_nested_set
3
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>ErpOrders</title>
5
+ <%= stylesheet_link_tag "erp_orders/application" %>
6
+ <%= javascript_include_tag "erp_orders/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,14 @@
1
+ ErpOrders::Engine.routes.draw do
2
+ #Desktop Applications
3
+ #
4
+ #order_manager
5
+ match '/erp_app/desktop/order_manager(/:action(/:id))' => 'erp_app/desktop/order_manager/base'
6
+
7
+
8
+ #Organizer Applications
9
+ #
10
+ #order_management
11
+ match '/erp_app/organizer/order_management(/:action(/:id))' => 'erp_app/organizer/order_management/base'
12
+ end
13
+
14
+
@@ -0,0 +1,23 @@
1
+ class CreateOrderPartyRoles
2
+
3
+ def self.up
4
+ order_roles = BizTxnPartyRoleType.create(
5
+ :description => 'Order Roles',
6
+ :internal_identifier => 'order_roles'
7
+ )
8
+
9
+ buyor_role = BizTxnPartyRoleType.create(
10
+ :description => 'Payor',
11
+ :internal_identifier => 'payor'
12
+ )
13
+
14
+ buyor_role.move_to_child_of(order_roles)
15
+ buyor_role.save
16
+ end
17
+
18
+ def self.down
19
+ BizTxnPartyRoleType.find_by_internal_identifier('payor').destroy
20
+ BizTxnPartyRoleType.find_by_internal_identifier('order_roles').destroy
21
+ end
22
+
23
+ end
@@ -0,0 +1,25 @@
1
+ class CreateDesktopAppOrderManager
2
+ def self.up
3
+ app = DesktopApplication.create(
4
+ :description => 'Orders',
5
+ :icon => 'icon-package',
6
+ :javascript_class_name => 'Compass.ErpApp.Desktop.Applications.OrderManager',
7
+ :internal_identifier => 'order_manager',
8
+ :shortcut_id => 'order_manager-win'
9
+ )
10
+
11
+ pt = PreferenceType.iid('desktop_shortcut')
12
+ pt.preferenced_records << app
13
+ pt.save
14
+
15
+ pt = PreferenceType.iid('autoload_application')
16
+ pt.preferenced_records << app
17
+ pt.save
18
+
19
+ app.save
20
+ end
21
+
22
+ def self.down
23
+ DesktopApplication.destroy_all(:conditions => ['internal_identifier = ?','hello_world'])
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ class CreateOrganizerAppOrderManagement
2
+ def self.up
3
+ OrganizerApplication.create(
4
+ :description => 'Orders',
5
+ :icon => 'icon-package',
6
+ :javascript_class_name => 'Compass.ErpApp.Organizer.Applications.OrderManagement.Base',
7
+ :internal_identifier => 'order_management'
8
+ )
9
+ end
10
+
11
+ def self.down
12
+ OrganizerApplication.destroy_all(:conditions => ['internal_identifier = ?','order_management'])
13
+ end
14
+ end
@@ -0,0 +1,175 @@
1
+ class BaseOrders < ActiveRecord::Migration
2
+ def self.up
3
+
4
+ unless table_exists?(:order_txns)
5
+ create_table :order_txns do |t|
6
+ t.column :state_machine, :string
7
+ t.column :description, :string
8
+ t.column :order_txn_type_id, :integer
9
+ # Multi-table inheritance info
10
+ # MTI implemented using Rails' polymorphic associations
11
+ # Contact Information
12
+ t.column :email, :string
13
+ t.column :phone_number, :string
14
+ # Shipping Address
15
+ t.column :ship_to_first_name, :string
16
+ t.column :ship_to_last_name, :string
17
+ t.column :ship_to_address_line_1, :string
18
+ t.column :ship_to_address_line_2, :string
19
+ t.column :ship_to_city, :string
20
+ t.column :ship_to_state, :string
21
+ t.column :ship_to_postal_code, :string
22
+ t.column :ship_to_country, :string
23
+ # Private parts
24
+ t.column :customer_ip, :string
25
+ t.column :order_number, :integer
26
+ t.column :status, :string
27
+ t.column :error_message, :string
28
+ t.column :order_txn_record_id, :integer
29
+ t.column :order_txn_record_type, :string
30
+ t.timestamps
31
+ end
32
+
33
+ add_index :order_txns, :order_txn_type_id
34
+ add_index :order_txns, [:order_txn_record_id, :order_txn_record_type], :name => 'order_txn_record_idx'
35
+ end
36
+
37
+ unless table_exists?(:order_txn_types)
38
+ create_table :order_txn_types do |t|
39
+ t.column :parent_id, :integer
40
+ t.column :lft, :integer
41
+ t.column :rgt, :integer
42
+ #custom columns go here
43
+ t.column :description, :string
44
+ t.column :comments, :string
45
+ t.column :internal_identifier, :string
46
+ t.column :external_identifier, :string
47
+ t.column :external_id_source, :string
48
+ t.timestamps
49
+ end
50
+
51
+ add_index :order_txn_types, :parent_id
52
+ end
53
+
54
+
55
+ unless table_exists?(:order_line_items)
56
+ create_table :order_line_items do |t|
57
+ t.column :order_txn_id, :integer
58
+ t.column :order_line_item_type_id, :integer
59
+ t.column :product_id, :integer
60
+ t.column :product_description, :string
61
+ t.column :product_instance_id, :integer
62
+ t.column :product_instance_description, :string
63
+ t.column :product_type_id, :integer
64
+ t.column :product_type_description, :string
65
+ t.column :sold_price, :float
66
+ t.column :sold_price_uom, :integer
67
+ t.column :sold_amount, :integer
68
+ t.column :sold_amount_uom, :integer
69
+ t.column :product_offer_id, :integer
70
+ t.timestamps
71
+ end
72
+
73
+ add_index :order_line_items, :order_txn_id
74
+ add_index :order_line_items, :order_line_item_type_id
75
+ add_index :order_line_items, :product_id
76
+ add_index :order_line_items, :product_instance_id
77
+ add_index :order_line_items, :product_type_id
78
+ add_index :order_line_items, :product_offer_id
79
+ end
80
+
81
+ unless table_exists?(:order_line_item_types)
82
+ create_table :order_line_item_types do |t|
83
+ t.column :parent_id, :integer
84
+ t.column :lft, :integer
85
+ t.column :rgt, :integer
86
+ #custom columns go here
87
+ t.column :description, :string
88
+ t.column :comments, :string
89
+ t.column :internal_identifier, :string
90
+ t.column :external_identifier, :string
91
+ t.column :external_id_source, :string
92
+ t.timestamps
93
+ end
94
+
95
+ add_index :order_line_item_types, :parent_id
96
+ end
97
+
98
+ unless table_exists?(:order_line_item_pty_roles)
99
+ create_table :order_line_item_pty_roles do |t|
100
+ t.column :description, :string
101
+ t.column :order_line_item_id, :integer
102
+ t.column :party_id, :integer
103
+ t.column :line_item_role_type_id, :integer
104
+ t.column :biz_txn_acct_root_id, :integer #optional for splitting orders across accounts
105
+ t.timestamps
106
+ end
107
+
108
+ add_index :order_line_item_pty_roles, :order_line_item_id
109
+ add_index :order_line_item_pty_roles, :party_id
110
+ add_index :order_line_item_pty_roles, :line_item_role_type_id
111
+ add_index :order_line_item_pty_roles, :biz_txn_acct_root_id
112
+ end
113
+
114
+ unless table_exists?(:line_item_role_types)
115
+ create_table :line_item_role_types do |t|
116
+ t.column :parent_id, :integer
117
+ t.column :lft, :integer
118
+ t.column :rgt, :integer
119
+ #custom columns go here
120
+ t.column :description, :string
121
+ t.column :comments, :string
122
+ t.column :internal_identifier, :string
123
+ t.column :external_identifier, :string
124
+ t.column :external_id_source, :string
125
+ t.timestamps
126
+ end
127
+
128
+ add_index :line_item_role_types, :parent_id
129
+ end
130
+
131
+ unless table_exists?(:charge_lines)
132
+ create_table :charge_lines do |t|
133
+ t.string :sti_type
134
+ t.references :money
135
+ t.string :description #could be expanded to include type information, etc.
136
+ t.string :external_identifier
137
+ t.string :external_id_source
138
+
139
+ #polymorphic
140
+ t.references :charged_item, :polymorphic => true
141
+
142
+ t.timestamps
143
+ end
144
+
145
+ add_index :charge_lines, [:charged_item_id, :charged_item_type], :name => 'charged_item_idx'
146
+ end
147
+
148
+ unless table_exists?(:charge_line_payment_txns)
149
+ create_table :charge_line_payment_txns do |t|
150
+ t.column :charge_line_id, :integer
151
+
152
+ #polymorphic
153
+ t.references :payment_txn, :polymorphic => true
154
+
155
+ t.timestamps
156
+ end
157
+
158
+ add_index :charge_line_payment_txns, [:payment_txn_id, :payment_txn_type], :name => 'payment_txn_idx'
159
+ add_index :charge_line_payment_txns, :charge_line_id
160
+ end
161
+ end
162
+
163
+ def self.down
164
+ [
165
+ :charge_lines, :charge_line_payment_txns, :line_item_role_types, :order_line_item_pty_roles,
166
+ :order_line_item_types, :order_line_items, :order_txn_types,
167
+ :order_txns
168
+ ].each do |tbl|
169
+ if table_exists?(tbl)
170
+ drop_table tbl
171
+ end
172
+ end
173
+ end
174
+
175
+ end
@@ -0,0 +1,25 @@
1
+ class UpdateOrderTxnShipToBillTo < ActiveRecord::Migration
2
+ def self.up
3
+ unless columns(:order_txns).collect {|c| c.name}.include?('bill_to_address_line_1')
4
+ rename_column :order_txns, :bill_to_address, :bill_to_address_line_1
5
+ add_column :order_txns, :bill_to_address_line_2, :string
6
+ end
7
+
8
+ unless columns(:order_txns).collect {|c| c.name}.include?('ship_to_address_line_1')
9
+ rename_column :order_txns, :ship_to_address, :ship_to_address_line_1
10
+ add_column :order_txns, :ship_to_address_line_2, :string
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ if columns(:order_txns).collect {|c| c.name}.include?('bill_to_address_line_1')
16
+ rename_column :order_txns, :bill_to_address_line_1, :bill_to_address
17
+ remove_column :order_txns, :bill_to_address_line_2
18
+ end
19
+
20
+ if columns(:order_txns).collect {|c| c.name}.include?('ship_to_address_line_1')
21
+ rename_column :order_txns, :ship_to_address_line_1, :ship_to_address
22
+ remove_column :order_txns, :ship_to_address_line_2
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ module ErpOrders
2
+ class Engine < Rails::Engine
3
+ isolate_namespace ErpOrders
4
+
5
+ initializer "erp_orders_assets.merge_public" do |app|
6
+ app.middleware.insert_before Rack::Lock, ::ActionDispatch::Static, "#{root}/public"
7
+ end
8
+
9
+ ActiveSupport.on_load(:active_record) do
10
+ include ErpOrders::Extensions::ActiveRecord::ActsAsOrderTxn
11
+ end
12
+ end
13
+ end