Class: Pacioli::Company
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Pacioli::Company
- Defined in:
- lib/pacioli/company.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_account(account) ⇒ Object
- #add_asset_account(options = {}) ⇒ Object
- #add_equity_account(options = {}) ⇒ Object
- #add_expense_account(options = {}) ⇒ Object
- #add_income_account(options = {}) ⇒ Object
- #add_liability_account(options = {}) ⇒ Object
- #asset_accounts ⇒ Object
- #create_posting_rule(&block) ⇒ Object
- #equity_accounts ⇒ Object
- #expense_accounts ⇒ Object
- #fetch_account(name) ⇒ Object
- #income_accounts ⇒ Object
- #liability_accounts ⇒ Object
- #record_journal_entry(&block) ⇒ Object
- #register_creditor(&block) ⇒ Object
- #register_debtor(&block) ⇒ Object
- #with_name(company_name) ⇒ Object
- #with_source(companyable_object) ⇒ Object
Class Method Details
.for(company) ⇒ Object
13 14 15 |
# File 'lib/pacioli/company.rb', line 13 def self.for(company) Company.where(companyable_type: company.class.name, companyable_id: company.id).first end |
Instance Method Details
#add_account(account) ⇒ Object
53 54 55 56 57 |
# File 'lib/pacioli/company.rb', line 53 def add_account(account) self.accounts << account CompanyValidator.for(self).execute account end |
#add_asset_account(options = {}) ⇒ Object
59 60 61 |
# File 'lib/pacioli/company.rb', line 59 def add_asset_account(={}) add_account AssetAccount.new() end |
#add_equity_account(options = {}) ⇒ Object
63 64 65 |
# File 'lib/pacioli/company.rb', line 63 def add_equity_account(={}) add_account EquityAccount.new() end |
#add_expense_account(options = {}) ⇒ Object
75 76 77 |
# File 'lib/pacioli/company.rb', line 75 def add_expense_account(={}) add_account ExpenseAccount.new() end |
#add_income_account(options = {}) ⇒ Object
71 72 73 |
# File 'lib/pacioli/company.rb', line 71 def add_income_account(={}) add_account IncomeAccount.new() end |
#add_liability_account(options = {}) ⇒ Object
67 68 69 |
# File 'lib/pacioli/company.rb', line 67 def add_liability_account(={}) add_account LiabilityAccount.new() end |
#asset_accounts ⇒ Object
21 22 23 |
# File 'lib/pacioli/company.rb', line 21 def asset_accounts self.accounts.select(&:asset?) end |
#create_posting_rule(&block) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/pacioli/company.rb', line 95 def create_posting_rule(&block) self.transaction do posting_rule = PostingRule.new self.posting_rules << posting_rule posting_rule.instance_eval(&block) PostingRuleValidator.for(posting_rule).execute posting_rule.save! posting_rule end end |
#equity_accounts ⇒ Object
37 38 39 |
# File 'lib/pacioli/company.rb', line 37 def equity_accounts self.accounts.select(&:equity?) end |
#expense_accounts ⇒ Object
29 30 31 |
# File 'lib/pacioli/company.rb', line 29 def expense_accounts self.accounts.select(&:expense?) end |
#fetch_account(name) ⇒ Object
17 18 19 |
# File 'lib/pacioli/company.rb', line 17 def fetch_account(name) self.accounts.for(name).first end |
#income_accounts ⇒ Object
33 34 35 |
# File 'lib/pacioli/company.rb', line 33 def income_accounts self.accounts.select(&:income?) end |
#liability_accounts ⇒ Object
25 26 27 |
# File 'lib/pacioli/company.rb', line 25 def liability_accounts self.accounts.select(&:liability?) end |
#record_journal_entry(&block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/pacioli/company.rb', line 79 def record_journal_entry(&block) self.transaction do journal_entry = JournalEntry.new self.journal_entries << journal_entry journal_entry.instance_eval(&block) journal_entry.execute_posting_rules JournalEntryValidator.for(journal_entry).execute journal_entry.amount = journal_entry.calculate_amount if journal_entry.amount.blank? journal_entry.save! journal_entry end end |
#register_creditor(&block) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/pacioli/company.rb', line 118 def register_creditor(&block) self.transaction do creditor = Creditor.new self.parties << creditor creditor.instance_eval(&block) creditor.save! creditor end end |
#register_debtor(&block) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/pacioli/company.rb', line 108 def register_debtor(&block) self.transaction do debtor = Debtor.new self.parties << debtor debtor.instance_eval(&block) debtor.save! debtor end end |
#with_name(company_name) ⇒ Object
45 46 47 |
# File 'lib/pacioli/company.rb', line 45 def with_name(company_name) self.name = company_name end |
#with_source(companyable_object) ⇒ Object
49 50 51 |
# File 'lib/pacioli/company.rb', line 49 def with_source(companyable_object) self.companyable = companyable_object end |