Created
July 2, 2019 14:31
-
-
Save ryenski/18ce923fa023595abbf6f96bc280b024 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# bundle exec rails runner create_accounts.rb | |
# An organization that the above users don't have access to | |
organization = Organization.find_or_create_by(slug: 'accounting-demo') do |o| | |
o.name = 'Accounting Demo' | |
o.invite_code = Rails.configuration.mx_iso_agent['invite_code'] | |
end | |
# Enable the feature flag for your user | |
user = User.find_by email: '[email protected]' | |
admin = Administratorship.find_or_initialize_by(user: user, organization: organization) | |
admin.feature_flags = ['accounting'] | |
admin.role = 'admin' | |
admin.save | |
organization.accounts.destroy_all | |
# Accounting | |
assets = Accounting::Asset.create!(number: 1, name: 'Assets', description: 'Assets', organization: organization) | |
checking = Accounting::Asset.create!(number: 1, name: 'Checking Account', description: 'Checking account', organization: organization, parent: assets) | |
accounts_receivable = Accounting::Asset.create!(number: 2, name: 'Accounts Receivable', organization: organization, parent: assets) | |
undeposited_funds = Accounting::Asset.create!(number: 9, name: 'Undeposited Funds', organization: organization, parent: assets) | |
liabilities = Accounting::Liability.create!(number: 2, name: 'Liabilities', organization: organization) | |
accounts_payable = Accounting::Liability.create!(number: 21, name: 'Accounts Payable', organization: organization, parent: liabilities) | |
equity = Accounting::Equity.create!(number: 3, name: 'Equity', organization: organization) | |
retained_earnings = Accounting::Equity.create!(number: 90, name: 'Retained Earnings', organization: organization, parent: equity) | |
revenue = Accounting::Revenue.create!(number: 4, name: 'Revenue', organization: organization) | |
sales = Accounting::Revenue.create!(number: 50, name: 'Sales', organization: organization, parent: revenue) | |
cogs = Accounting::CostOfGoodsSold.create!(number: 5, name: 'Cost of Goods Sold', organization: organization) | |
expenses = Accounting::Expense.create!(number: 6, name: 'Expenses', organization: organization) | |
operating_expenses = Accounting::Expense.create!(number: 23, name: 'Operating Expenses', organization: organization, parent: expenses) | |
office_supplies = Accounting::Expense.create!(number: 21, name: 'Office Supplies', organization: organization, parent: expenses) | |
software_expenses = Accounting::Expense.create!(number: 26, name: 'Software Expense', organization: organization, parent: expenses) | |
support_expenses = Accounting::Expense.create!(number: 27, name: 'Support Expense', organization: organization, parent: expenses) | |
Accounting::Entry.create( | |
description: 'Opening balance equity', | |
debit_amounts: [Accounting::DebitAmount.new(account: checking, amount: 100)], | |
credit_amounts: [Accounting::CreditAmount.new(account: equity, amount: 100)] | |
) | |
Accounting::Entry.create( | |
description: 'Red Swingline Stapler', | |
debit_amounts: [Accounting::DebitAmount.new(account: office_supplies, amount: 25)], | |
credit_amounts: [Accounting::CreditAmount.new(account: checking, amount: 25)] | |
) | |
Accounting::Entry.create( | |
description: 'Electric Bill', | |
debit_amounts: [Accounting::DebitAmount.new(account: operating_expenses, amount: 45)], | |
credit_amounts: [Accounting::CreditAmount.new(account: accounts_payable, amount: 45)] | |
) | |
Accounting::Entry.create( | |
description: 'Software contract with Microsoft', | |
debit_amounts: [ | |
Accounting::DebitAmount.new(account: software_expenses, amount: 20), | |
Accounting::DebitAmount.new(account: support_expenses, amount: 20), | |
Accounting::DebitAmount.new(account: software_expenses, amount: -25) | |
], | |
credit_amounts: [ | |
Accounting::CreditAmount.new(account: checking, amount: 15) | |
] | |
) | |
Accounting::Entry.create( | |
description: 'Sales', | |
debit_amounts: [Accounting::DebitAmount.new(account: undeposited_funds, amount: 1000)], | |
credit_amounts: [Accounting::CreditAmount.new(account: sales, amount: 1000)] | |
) | |
Accounting::Entry.create( | |
description: 'Deposit', | |
debit_amounts: [Accounting::DebitAmount.new(account: checking, amount: 1000)], | |
credit_amounts: [Accounting::CreditAmount.new(account: undeposited_funds, amount: 1000)] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment