Last active
January 18, 2016 18:48
-
-
Save cokara/ee21fae8e7df72ee2dc9 to your computer and use it in GitHub Desktop.
GL Recording thoughts
This file contains 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
class DebitEntry | |
def initialize(gl_account, amount_cents) | |
end | |
def create_record(je) | |
::AccountEntry.create( | |
amount_cents: amount_cents | |
gl_account_id: gl_account_id, | |
journal_entry_id: je.id | |
) | |
end | |
end | |
class CreditEntry | |
def initialize | |
#.... | |
end | |
def create_record(je) | |
::AccountEntry.create( | |
amount_cents: amount_cents * -1, # **** The ONLY place flipping of sign is done **** | |
gl_account_id: gl_account_id, | |
journal_entry_id: je.id | |
) | |
end | |
end | |
class EntrySet | |
attr_reader :debits, :credits | |
def initialize(debits, credits) | |
end | |
def journal(je) | |
debits.each do |e| | |
e.create_record!(je) | |
end | |
credits.each do |e| | |
e.create_record!(je) | |
end | |
end | |
end | |
class JournalEntry | |
def initialize(journaled, entry_sets, event, ....) | |
# perform_checks on all sets to make sure the debits and credits add up | |
# other validations | |
end | |
def record | |
je = ::JournalEntry.create(journaled: journaled, | |
event: event, ...) | |
entry_sets.each do |es| | |
es.journal(je) | |
end | |
end | |
end | |
class Accounting::JournalEntryFun::ShippingInteractor | |
def perform | |
entry_sets = [] | |
# bd vs sales | |
scalc = ShipmentAmountCalculator.new(order_item) | |
sales_entries ={ | |
debits: [DebitEntry.new(:bd, scalc.bd_amount)], | |
credits: [CreditEntry.new(:sales, scalc.sale_amount), | |
CreditEntry.new(:ship, scalc.ship_amount), | |
CreditEntry.new(:tax], scalc.tax_amount)] | |
} | |
entry_sets << EntrySet.new(sales_entries) | |
icalc = InventoryAmountCalculator.new(order_item) | |
inventory_entries = { | |
debits: [DebitEntry.new(:cogs, icacl.cogs_amount)], | |
credits: [CreditEntry.new(:inventory, icalc.inv_amount] | |
} | |
entry_sets << EntrySet.new(inventory_entries) | |
JournalEntry.new(order_item, entry_sets, "shipment", ...).record! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment