erp_txns_and_accts 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 (50) 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_txns_and_accts/application.js +9 -0
  5. data/app/assets/stylesheets/erp_txns_and_accts/application.css +7 -0
  6. data/app/controllers/erp_txns_and_accts/application_controller.rb +4 -0
  7. data/app/helpers/erp_txns_and_accts/application_helper.rb +4 -0
  8. data/app/models/base_txn_context.rb +6 -0
  9. data/app/models/biz_acct_txn_task.rb +3 -0
  10. data/app/models/biz_txn_acct_party_role.rb +23 -0
  11. data/app/models/biz_txn_acct_pty_rtype.rb +3 -0
  12. data/app/models/biz_txn_acct_rel_type.rb +3 -0
  13. data/app/models/biz_txn_acct_relationship.rb +8 -0
  14. data/app/models/biz_txn_acct_root.rb +21 -0
  15. data/app/models/biz_txn_acct_status.rb +3 -0
  16. data/app/models/biz_txn_acct_status_type.rb +3 -0
  17. data/app/models/biz_txn_acct_type.rb +4 -0
  18. data/app/models/biz_txn_agreement_role.rb +7 -0
  19. data/app/models/biz_txn_agreement_role_type.rb +4 -0
  20. data/app/models/biz_txn_event.rb +61 -0
  21. data/app/models/biz_txn_event_desc.rb +5 -0
  22. data/app/models/biz_txn_party_role.rb +7 -0
  23. data/app/models/biz_txn_party_role_type.rb +4 -0
  24. data/app/models/biz_txn_rel_type.rb +4 -0
  25. data/app/models/biz_txn_relationship.rb +8 -0
  26. data/app/models/biz_txn_status.rb +3 -0
  27. data/app/models/biz_txn_task.rb +3 -0
  28. data/app/models/biz_txn_task_type.rb +3 -0
  29. data/app/models/biz_txn_type.rb +36 -0
  30. data/app/models/extensions/charge_line.rb +8 -0
  31. data/app/models/extensions/charge_line_payment_txn.rb +3 -0
  32. data/app/models/extensions/money.rb +6 -0
  33. data/app/models/extensions/party.rb +27 -0
  34. data/app/models/financial_txn.rb +71 -0
  35. data/app/models/financial_txn_account.rb +71 -0
  36. data/app/views/layouts/erp_txns_and_accts/application.html.erb +14 -0
  37. data/config/routes.rb +2 -0
  38. data/db/data_migrations/20101014142230_financial_txn_types.rb +15 -0
  39. data/db/migrate/20080805000030_base_txns_and_accts.rb +360 -0
  40. data/db/migrate/20110609230152_update_financial_txns.rb +21 -0
  41. data/lib/erp_txns_and_accts.rb +6 -0
  42. data/lib/erp_txns_and_accts/delayed_jobs/payment_gateway_job.rb +24 -0
  43. data/lib/erp_txns_and_accts/engine.rb +12 -0
  44. data/lib/erp_txns_and_accts/extensions.rb +3 -0
  45. data/lib/erp_txns_and_accts/extensions/active_record/acts_as_biz_txn_account.rb +63 -0
  46. data/lib/erp_txns_and_accts/extensions/active_record/acts_as_biz_txn_event.rb +72 -0
  47. data/lib/erp_txns_and_accts/extensions/active_record/acts_as_financial_txn_account.rb +70 -0
  48. data/lib/erp_txns_and_accts/version.rb +3 -0
  49. data/lib/tasks/erp_txns_and_accts_tasks.rake +4 -0
  50. metadata +144 -0
data/README.rdoc ADDED
@@ -0,0 +1,2 @@
1
+ = ErpTxnsAndAccts
2
+
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 = 'ErpTxnsAndAccts'
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,4 @@
1
+ module ErpTxnsAndAccts
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ErpTxnsAndAccts
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ class BaseTxnContext < ActiveRecord::Base
2
+
3
+ belongs_to :txn_context_record, :polymorphic => true
4
+ belongs_to :biz_txn_event
5
+
6
+ end
@@ -0,0 +1,3 @@
1
+ class BizAcctTxnTask < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,23 @@
1
+ class BizTxnAcctPartyRole < ActiveRecord::Base
2
+
3
+ belongs_to :biz_txn_acct_root
4
+ belongs_to :party
5
+ belongs_to :biz_txn_acct_pty_rtype
6
+
7
+ def role_type
8
+ biz_txn_acct_pty_rtype
9
+ end
10
+
11
+ def account_root
12
+ biz_txn_acct_root
13
+ end
14
+
15
+ def to_label
16
+ "#{party.description}:#{role_type.description}"
17
+ end
18
+
19
+ def description
20
+ "#{party.description}:#{role_type.description}"
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ class BizTxnAcctPtyRtype < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class BizTxnAcctRelType < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,8 @@
1
+ class BizTxnAcctRelationship < ActiveRecord::Base
2
+
3
+ belongs_to :account_from, :class_name => "BizTxnAcctRoot", :foreign_key => "biz_txn_acct_root_id_from"
4
+ belongs_to :account_to, :class_name => "BizTxnAcctRoot", :foreign_key => "biz_txn_acct_root_id_to"
5
+
6
+ belongs_to :biz_txn_acct_rel_type
7
+
8
+ end
@@ -0,0 +1,21 @@
1
+ class BizTxnAcctRoot < ActiveRecord::Base
2
+
3
+ belongs_to :biz_txn_acct, :polymorphic => true, :dependent => :destroy
4
+ belongs_to :biz_txn_acct_type
5
+ has_many :biz_txn_events, :dependent => :destroy
6
+ has_many :biz_txn_acct_party_roles, :dependent => :destroy
7
+
8
+ alias :account :biz_txn_acct
9
+ alias :txn_events :biz_txn_events
10
+ alias :txns :biz_txn_events
11
+ alias :account_type :biz_txn_acct_type
12
+
13
+ def to_label
14
+ "#{description}"
15
+ end
16
+
17
+ def to_s
18
+ "#{description}"
19
+ end
20
+
21
+ end
@@ -0,0 +1,3 @@
1
+ class BizTxnAcctStatus < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class BizTxnAcctStatusType < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,4 @@
1
+ class BizTxnAcctType < ActiveRecord::Base
2
+ acts_as_nested_set
3
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
4
+ end
@@ -0,0 +1,7 @@
1
+ class BizTxnAgreementRole < ActiveRecord::Base
2
+
3
+ belongs_to :biz_txn_event, :polymorphic => true
4
+ belongs_to :agreement
5
+ belongs_to :biz_txn_agreement_role_type
6
+ alias :role_type :biz_txn_agreement_role_type
7
+ end
@@ -0,0 +1,4 @@
1
+ class BizTxnAgreementRoleType < ActiveRecord::Base
2
+ acts_as_nested_set
3
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
4
+ end
@@ -0,0 +1,61 @@
1
+ class BizTxnEvent < ActiveRecord::Base
2
+
3
+ belongs_to :biz_txn_acct_root
4
+ belongs_to :biz_txn_record, :polymorphic => true
5
+ has_many :biz_txn_party_roles, :dependent => :destroy
6
+ has_many :biz_txn_event_descs, :dependent => :destroy
7
+ has_many :base_txn_contexts, :dependent => :destroy
8
+ has_many :biz_txn_agreement_roles
9
+ has_many :agreements, :through => :biz_txn_agreement_roles
10
+
11
+ #wrapper for...
12
+ #belongs_to :biz_txn_type
13
+ belongs_to_erp_type :biz_txn_type
14
+ #syntactic sugar
15
+ alias :txn_type :biz_txn_type
16
+ alias :txn_type= :biz_txn_type=
17
+ alias :txn :biz_txn_record
18
+ alias :txn= :biz_txn_record=
19
+ alias :account :biz_txn_acct_root
20
+ alias :account= :biz_txn_acct_root=
21
+ alias :descriptions :biz_txn_event_descs
22
+
23
+
24
+ #helps when looping through transactions comparing types
25
+ def txn_type_iid
26
+ biz_txn_type.internal_identifier if biz_txn_type
27
+ end
28
+
29
+ def account_root
30
+ biz_txn_acct_root
31
+ end
32
+
33
+ def amount
34
+ if biz_txn_record.respond_to? :amount
35
+ biz_txn_record.amount
36
+ else
37
+ nil
38
+ end
39
+ end
40
+
41
+ def amount_string
42
+ if biz_txn_record.respond_to? :amount_string
43
+ biz_txn_record.amount_string
44
+ else
45
+ "n/a"
46
+ end
47
+ end
48
+
49
+ def create_dependent_txns
50
+ #Template Method
51
+ end
52
+
53
+ def to_label
54
+ "#{description}"
55
+ end
56
+
57
+ def to_s
58
+ "#{description}"
59
+ end
60
+
61
+ end
@@ -0,0 +1,5 @@
1
+ class BizTxnEventDesc < ActiveRecord::Base
2
+
3
+ belongs_to :biz_txn_event
4
+
5
+ end
@@ -0,0 +1,7 @@
1
+ class BizTxnPartyRole < ActiveRecord::Base
2
+
3
+ belongs_to :biz_txn_event
4
+ belongs_to :party
5
+ belongs_to :biz_txn_party_role_type
6
+
7
+ end
@@ -0,0 +1,4 @@
1
+ class BizTxnPartyRoleType < ActiveRecord::Base
2
+ acts_as_nested_set
3
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
4
+ end
@@ -0,0 +1,4 @@
1
+ class BizTxnRelType < ActiveRecord::Base
2
+ acts_as_nested_set
3
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
4
+ end
@@ -0,0 +1,8 @@
1
+ class BizTxnRelationship < ActiveRecord::Base
2
+
3
+ belongs_to :txn_event_from, :class_name => "BizTxnEvent", :foreign_key => "txn_event_id_from"
4
+ belongs_to :txn_event_to , :class_name => "BizTxnEvent", :foreign_key => "txn_event_id_to"
5
+
6
+ belongs_to :biz_txn_rel_type
7
+
8
+ end
@@ -0,0 +1,3 @@
1
+ class BizTxnStatus < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class BizTxnTask < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class BizTxnTaskType < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,36 @@
1
+ class BizTxnType < ActiveRecord::Base
2
+
3
+ acts_as_nested_set
4
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
5
+ acts_as_erp_type
6
+
7
+ belongs_to_erp_type :parent, :class_name => "BizTxnType"
8
+
9
+ # this method handles default behavior for find by type and subtype
10
+ def self.find_by_type_and_subtype(txn_type, txn_subtype)
11
+ return self.find_by_type_and_subtype_eid(txn_type, txn_subtype)
12
+ end
13
+
14
+ # find by type Internal Identifier and subtype Internal Identifier
15
+ def self.find_by_type_and_subtype_iid(txn_type, txn_subtype)
16
+ txn_type_recs = find_all_by_internal_identifier(txn_type.strip)
17
+ return nil if txn_type_recs.blank?
18
+ txn_type_recs.each do |txn_type_rec|
19
+ txn_subtype_rec = find_by_parent_id_and_internal_identifier(txn_type_rec.id, txn_subtype.strip)
20
+ return txn_subtype_rec unless txn_subtype_rec.nil?
21
+ end
22
+ return nil
23
+ end
24
+
25
+ # find by type External Identifier and subtype External Identifier
26
+ def self.find_by_type_and_subtype_eid(txn_type, txn_subtype)
27
+ txn_type_recs = find_all_by_external_identifier(txn_type.strip)
28
+ return nil if txn_type_recs.blank?
29
+ txn_type_recs.each do |txn_type_rec|
30
+ txn_subtype_rec = find_by_parent_id_and_external_identifier(txn_type_rec.id, txn_subtype.strip)
31
+ return txn_subtype_rec unless txn_subtype_rec.nil?
32
+ end
33
+ return nil
34
+ end
35
+
36
+ end
@@ -0,0 +1,8 @@
1
+ ChargeLine.class_eval do
2
+ has_many :financial_txns, :through => :charge_line_payment_txns, :source => :financial_txn,
3
+ :conditions => ["charge_line_payment_txns.payment_txn_type = ?", 'FinancialTxn']
4
+
5
+ def payment_txns
6
+ self.financial_txns
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ ChargeLinePaymentTxn.class_eval do
2
+ belongs_to :financial_txn, :class_name => "FinancialTxn",:foreign_key => "payment_txn_id"
3
+ end
@@ -0,0 +1,6 @@
1
+
2
+ Money.class_eval do
3
+ has_many :financial_txn_accounts, :foreign_key => 'balance_id'
4
+ has_many :financial_txn_accounts, :foreign_key => 'payment_due_id'
5
+ has_many :financial_txns, :dependent => :destroy
6
+ end
@@ -0,0 +1,27 @@
1
+ Party.class_eval do
2
+
3
+ has_many :biz_txn_acct_party_roles
4
+ has_many :biz_txn_acct_roots, :through => :biz_txn_acct_party_roles, :dependent => :destroy
5
+ # has_many :entity_content_assignments, :as => :da_assignment
6
+ # has_many :credit_cards, :class_name => "CreditCard", :foreign_key => "cardholder_id"
7
+
8
+
9
+ # Wrapper to get all party accounts
10
+ def accounts
11
+ relationships
12
+
13
+ # old call:
14
+ #biz_txn_acct_roots
15
+
16
+ # TODO: Get data so we can use this optimized version:
17
+ #BizTxnAcctPartyRole.find(:all, :joins => [:party, :biz_txn_acct_root, :biz_txn_acct_pty_rtype], :conditions => ['party_id =?', id])
18
+ end
19
+
20
+ # Adds a business account (BizTxnAcctPartyRole)
21
+ def add_business_account( acct_root, role_type_id = 10000 )
22
+ apr = BizTxnAcctPartyRole.new
23
+
24
+ apr.biz_txn_acct_pty_rtype = BizTxnAcctPtyRtype.find(role_type_id)
25
+ biz_txn_acct_roots << acct_root
26
+ end
27
+ end
@@ -0,0 +1,71 @@
1
+ class FinancialTxn < ActiveRecord::Base
2
+
3
+ acts_as_biz_txn_event
4
+ has_many :charge_line_payment_txns, :as => :payment_txn, :dependent => :destroy
5
+ has_many :charge_lines, :through => :charge_line_payment_txns
6
+ belongs_to :money
7
+ has_many :payments
8
+
9
+ def authorize(credit_card, gateway_wrapper, gateway_options={})
10
+ credit_card[:charge_amount] = self.money.amount
11
+ gateway_options[:charge_lines] = self.charge_lines
12
+ gateway_options[:debug] = true
13
+
14
+ result = gateway_wrapper.authorize(credit_card, gateway_options)
15
+
16
+ unless result[:payment].nil?
17
+ result[:payment].financial_txn = self
18
+ result[:payment].save
19
+ self.payments << result[:payment]
20
+ self.save
21
+ end
22
+
23
+ result
24
+ end
25
+
26
+ def purchase(credit_card, gateway_wrapper, gateway_options={})
27
+ credit_card[:charge_amount] = self.money.amount
28
+ gateway_options[:charge_lines] = self.charge_lines
29
+ gateway_options[:debug] = true
30
+
31
+ result = gateway_wrapper.purchase(credit_card, gateway_options)
32
+
33
+ unless result[:payment].nil?
34
+ result[:payment].financial_txn = self
35
+ result[:payment].save
36
+ self.payments << result[:payment]
37
+ self.save
38
+ end
39
+
40
+ result
41
+ end
42
+
43
+ def capture(credit_card, gateway_wrapper, gateway_options={})
44
+ result = {:success => true}
45
+ payment = Payment.find(:first, :order => 'created_at desc', :conditions => ["current_state = ? and success = ? and financial_txn_id = ?",'authorized', 1, self.id])
46
+ #only capture this payment if it was authorized
47
+ if !payment.nil? && payment.current_state.to_sym == :authorized
48
+ credit_card[:charge_amount] = self.money.amount
49
+ gateway_options[:charge_lines] = self.charge_lines
50
+ gateway_options[:debug] = true
51
+
52
+ result = gateway_wrapper.capture(credit_card, payment, gateway_options)
53
+ end
54
+ result
55
+ end
56
+
57
+ def reverse_authorization(credit_card, gateway_wrapper, gateway_options={})
58
+ result = {:success => true}
59
+ payment = Payment.find(:first, :order => 'created_at desc', :conditions => ["current_state = ? and success = ? and financial_txn_id = ?",'authorized', 1, self.id])
60
+ #only reverse this payment if it was authorized
61
+ if !payment.nil? && payment.current_state.to_sym == :authorized
62
+ credit_card[:charge_amount] = self.money.amount
63
+ gateway_options[:charge_lines] = self.charge_lines
64
+ gateway_options[:debug] = true
65
+
66
+ result = gateway_wrapper.full_reverse_of_authorization(credit_card, payment, gateway_options)
67
+ end
68
+ result
69
+ end
70
+
71
+ end