erp_orders 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
data/Rakefile ADDED
@@ -0,0 +1,30 @@
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 = 'ErpOrders'
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
@@ -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,147 @@
1
+ module ErpOrders
2
+ module ErpApp
3
+ module Desktop
4
+ module OrderManager
5
+ class BaseController < ::ErpApp::Desktop::BaseController
6
+
7
+ class Helper
8
+ include Singleton
9
+ include ActionView::Helpers::NumberHelper
10
+ end
11
+
12
+ def help
13
+ Helper.instance
14
+ end
15
+
16
+ def index
17
+ payor_role = BizTxnPartyRoleType.find_by_internal_identifier('payor')
18
+ result = {:success => true, :orders => [], :totalCount => 0, :results => 0}
19
+
20
+ sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
21
+ sort = sort_hash[:sort] || 'created_at'
22
+ dir = sort_hash[:dir] || 'DESC'
23
+ limit = params[:limit] || 50
24
+ start = params[:start] || 0
25
+ party_id = params[:party_id]
26
+ order_id = params[:order_id]
27
+ order_number = params[:order_number]
28
+
29
+ if order_id.blank? and party_id.blank? and order_number.blank?
30
+ orders = OrderTxn.order("#{sort} #{dir}").limit(limit).offset(start)
31
+ result[:totalCount] = OrderTxn.all.count
32
+ elsif !order_number.blank?
33
+ orders = OrderTxn.find_by_order_number(order_number).nil? ? [] : [OrderTxn.find_by_order_number(order_number)]
34
+ result[:totalCount] = orders.count
35
+ elsif !order_id.blank?
36
+ orders = [OrderTxn.find(order_id)]
37
+ result[:totalCount] = orders.count
38
+ elsif !party_id.blank?
39
+ sort = "order_txns.#{sort}"
40
+ orders = OrderTxn.joins("join biz_txn_events bte on bte.biz_txn_record_id = order_txns.id and bte.biz_txn_record_type = 'OrderTxn'
41
+ join biz_txn_party_roles btpr on btpr.biz_txn_event_id = bte.id and btpr.party_id = #{party_id} and biz_txn_party_role_type_id = #{payor_role.id}").order("#{sort} #{dir}").limit(limit).offset(start)
42
+ result[:totalCount] = OrderTxn.joins("join biz_txn_events bte on bte.biz_txn_record_id = order_txns.id and bte.biz_txn_record_type = 'OrderTxn'
43
+ join biz_txn_party_roles btpr on btpr.biz_txn_event_id = bte.id and btpr.party_id = #{party_id} and biz_txn_party_role_type_id = #{payor_role.id}").count
44
+ end
45
+
46
+ result[:results] = orders.count
47
+
48
+ orders.each do |order|
49
+
50
+ #get payor party if it exists
51
+ payor_party_id = nil
52
+ unless order.root_txn.biz_txn_party_roles.empty?
53
+ payor_party_id = order.root_txn.biz_txn_party_roles.where('biz_txn_party_role_type_id = ?', payor_role.id).first.party.id
54
+ end
55
+
56
+ result[:orders] << {
57
+ :total_price => help.number_to_currency(order.get_total_charges.sum{|money| money.amount}),
58
+ :order_number => order.order_number,
59
+ :status => order.status,
60
+ :first_name => order.bill_to_first_name,
61
+ :last_name => order.bill_to_last_name,
62
+ :email => order.email,
63
+ :phone => order.phone_number,
64
+ :id => order.id,
65
+ :created_at => order.created_at,
66
+ :payor_party_id => payor_party_id
67
+ }
68
+ end
69
+
70
+ render :json => result
71
+ end
72
+
73
+ def delete
74
+ result = {}
75
+
76
+ if OrderTxn.find(params[:id]).destroy
77
+ result[:success] = true
78
+ else
79
+ result[:success] = false
80
+ end
81
+
82
+ render :json => result
83
+ end
84
+
85
+ def line_items
86
+ result = {:success => true, :lineItems => [], :totalCount => 0, :results => 0}
87
+
88
+ limit = params[:limit] || 10
89
+ start = params[:start] || 0
90
+
91
+ line_items = OrderLineItem.where('order_txn_id = ?',params[:order_id]).limit(limit).offset(start)
92
+
93
+ result[:results] = line_items.count
94
+ result[:totalCount] = OrderLineItem.count("order_txn_id = #{params[:order_id]}")
95
+
96
+ line_items.each do |line_item|
97
+ price = 0
98
+ currency_display = nil
99
+ line_item.get_total_charges.each do |money|
100
+ price += money.amount
101
+ currency_display = money.currency.internal_identifier
102
+ end
103
+
104
+ result[:lineItems] << {
105
+ :id => line_item.id,
106
+ :product => (line_item.product_type.description rescue 'N/A'),
107
+ :quantity => 1,
108
+ :price => price,
109
+ :currency_display => currency_display,
110
+ :sku => (line_item.product_type.inventory_entries.first.sku resecue rescue 'N/A')
111
+ }
112
+ end
113
+
114
+ render :json => result
115
+ end
116
+
117
+ def payments
118
+ result = {:success => true, :payments => []}
119
+
120
+ financial_txns = OrderTxn.find(params[:order_id]).line_items.first.charge_lines.first.financial_txns
121
+
122
+ financial_txns.each do |financial_txn|
123
+ amount = financial_txn.money.amount
124
+ currency_display = financial_txn.money.currency.internal_identifier
125
+
126
+ financial_txn.payments.each do |payment|
127
+ result[:payments] << {
128
+ :id => payment.id,
129
+ :authorization => payment.authorization_code,
130
+ :status => payment.current_state,
131
+ :created_at => payment.created_at,
132
+ :amount => amount,
133
+ :success => payment.success ? 'Yes' : 'No',
134
+ :currency_display => currency_display
135
+ }
136
+ end
137
+
138
+ end
139
+
140
+ render :json => result
141
+ end
142
+
143
+ end#BaseController
144
+ end#OrderManager
145
+ end#Desktop
146
+ end#ErpApp
147
+ end#ErpOrders
@@ -0,0 +1,19 @@
1
+ module ErpOrders
2
+ module ErpApp
3
+ module Organizer
4
+ module OrderManagement
5
+ class BaseController < ::ErpApp::Organizer::BaseController
6
+
7
+ def menu
8
+ menu = []
9
+
10
+ menu << {:text => 'Orders', :leaf => true, :iconCls => 'icon-package', :applicationCardId => "orders_layout"}
11
+
12
+ render :inline => menu.to_json
13
+ end
14
+
15
+ end#BaseController
16
+ end#OrderManagement
17
+ end#Organizer
18
+ end#ErpApp
19
+ end#ErpOrders
@@ -0,0 +1,4 @@
1
+ module ErpOrders
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,21 @@
1
+ class ChargeLine < ActiveRecord::Base
2
+
3
+ belongs_to :charged_item, :polymorphic => true
4
+ belongs_to :money, :dependent => :destroy
5
+ has_many :charge_line_payment_txns, :dependent => :destroy
6
+
7
+ def payment_txns
8
+ #this is a stub for extensions
9
+ return []
10
+ end
11
+
12
+ def add_payment_txn(payment_txn)
13
+ charge_line_payment_txn = ChargeLinePaymentTxn.new
14
+ charge_line_payment_txn.charge_line = self
15
+ charge_line_payment_txn.payment_txn = payment_txn
16
+ charge_line_payment_txn.save
17
+ charge_line_payment_txns << charge_line_payment_txn
18
+ self.save
19
+ end
20
+
21
+ end
@@ -0,0 +1,5 @@
1
+ class ChargeLinePaymentTxn < ActiveRecord::Base
2
+ belongs_to :charge_line
3
+ belongs_to :payment_txn, :polymorphic => true
4
+
5
+ end
@@ -0,0 +1,6 @@
1
+ Agreement.class_eval do
2
+
3
+ has_many_polymorphic :biz_txn_events,
4
+ :through => :biz_txn_agreement_roles,
5
+ :models => [:order_txns]
6
+ end
@@ -0,0 +1,3 @@
1
+ Money.class_eval do
2
+ has_many :charge_lines
3
+ end
@@ -0,0 +1,3 @@
1
+ Party.class_eval do
2
+ has_many :order_line_item_pty_roles
3
+ end
@@ -0,0 +1,3 @@
1
+ ProductInstance.class_eval do
2
+ has_many :order_line_items
3
+ end
@@ -0,0 +1,3 @@
1
+ ProductType.class_eval do
2
+ has_many :order_line_items
3
+ end
@@ -0,0 +1,4 @@
1
+ class LineItemRoleType < ActiveRecord::Base
2
+ acts_as_nested_set
3
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
4
+ end
@@ -0,0 +1,27 @@
1
+ class OrderLineItem < ActiveRecord::Base
2
+
3
+ belongs_to :order_txn, :class_name => 'OrderTxn'
4
+ belongs_to :order_line_item_type
5
+
6
+ has_many :charge_lines, :as => :charged_item
7
+
8
+ belongs_to :product_instance
9
+ belongs_to :product_type
10
+
11
+ def get_total_charges
12
+ # get all of the charge lines associated with the order_line
13
+ total_hash = Hash.new
14
+ charge_lines.each do |charge|
15
+ cur_money = charge.money
16
+ cur_total = total_hash[cur_money.currency.internal_identifier]
17
+ if (cur_total.nil?)
18
+ cur_total = cur_money.clone
19
+ else
20
+ cur_total.amount = 0 if cur_total.amount.nil?
21
+ cur_total.amount += cur_money.amount if !cur_money.amount.nil?
22
+ end
23
+ total_hash[cur_money.currency.internal_identifier] = cur_total
24
+ end
25
+ return total_hash.values
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ class OrderLineItemPtyRole < ActiveRecord::Base
2
+
3
+ #***************************************************************************
4
+ # Who's booking? Who's staying? Who's paying? These role types can be
5
+ # played by different people by implementing this structure
6
+ #***************************************************************************
7
+
8
+ belongs_to :order_line_item
9
+ belongs_to :party
10
+ belongs_to :line_item_role_type
11
+
12
+ #***************************************************************************
13
+ # The association of a transaction to an account happens in the context of
14
+ # the Party, the Role that they're playing in this Transaction and the type
15
+ # of Transaction - we call this process Guiding a Transaction to an Account.
16
+ #
17
+ # It's an important process and it's handled by a TransactionRulesManager,
18
+ # which is so named to distinguish it from Transaction Managment Software
19
+ # like Tuxedo.
20
+ # In this case, we have an optional account reference here so that orders
21
+ # can be split across accounts.
22
+ #***************************************************************************
23
+
24
+ belongs_to :bix_txn_acct_root
25
+
26
+ def to_label
27
+ "#{party.description}"
28
+ end
29
+
30
+ def description
31
+ "#{party.description}"
32
+ end
33
+
34
+
35
+ end
@@ -0,0 +1,4 @@
1
+ class OrderLineItemType < ActiveRecord::Base
2
+ acts_as_nested_set
3
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
4
+ end