Successfully reported this slideshow.
Your SlideShare is downloading. ×

Accounting For Hackers

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
1 basic concepts
1 basic concepts
Loading in …3
×

Check these out next

1 of 79 Ad

Accounting For Hackers

Download to read offline

Boris was talking at Rails Israel 2015 conference about accounting and bookkeeping principles for software engineers. The presentation covers the suggested implementation and explanation of using astrails' gem debit-credit.

Boris was talking at Rails Israel 2015 conference about accounting and bookkeeping principles for software engineers. The presentation covers the suggested implementation and explanation of using astrails' gem debit-credit.

Advertisement
Advertisement

More Related Content

Similar to Accounting For Hackers (14)

Advertisement

Recently uploaded (20)

Accounting For Hackers

  1. 1. Accounting For Hackers Boris Nadion boris@astrails.com @borisnadion
  2. 2. @borisnadion boris@astrails.com
  3. 3. astrails http://astrails.com
  4. 4. awesome web and mobile apps since 2005
  5. 5. 100+
  6. 6. marketplaces
  7. 7. money
  8. 8. money
  9. 9. valuable psychological benefits
  10. 10. cash
  11. 11. virtual representation
  12. 12. model
  13. 13. marketplace
  14. 14. seller / buyer / app
  15. 15. $100 buyer $90 $10 seller app
  16. 16. $100 buyer $90 $10 seller app $90 seller pay-in pay-out
  17. 17. touch / don’t touch
  18. 18. don’t touch
  19. 19. $100 $90 $10 $100 $100 $10 buyer seller buyer seller app app $100 $100 $90 buyer app seller
  20. 20. touch
  21. 21. naïve implementation
  22. 22. class Purchase < ActiveRecord::Base belongs_to :product belongs_to :buyer, class_name: "User" belongs_to :seller validates :amount, :app_fee, presence: true scope :paid, -> { where(state: "paid") } scope :withdrawn, -> { where(state: "withdrawn") } before_validation :set_app_fee, on: :create def set_app_fee return unless amount self.app_fee = amount * APP_FEE_PERCENT end end
  23. 23. Purchase.paid.calculate(:sum, :amount) Purchase.withdrawn.calculate(:sum, :amount) seller = Seller.first # total per seller seller.purchases.calculate(:sum, :amount) # pending payout seller.purchases.paid.calculate(:sum, :amount) # paid-out seller.purchases.withdrawn.calculate(:sum, :amount)
  24. 24. By Hayley Bouchard https://www.flickr.com/photos/questa/5812984945 we are cool!
  25. 25. $100 buyer $12 $10 seller 1 app $31 seller 2 …
  26. 26. $100 buyer $12 $10 seller 1 app $31 seller 2 … $12 seller 1 $31 seller 2 … escrow
  27. 27. escrow
  28. 28. clearance
  29. 29. class Purchase < ActiveRecord::Base # ... scope :cleared, -> { where(state: "cleared") } # ... def self.clearance_cron! # ... end end seller.purchases.cleared.calculate(:sum, :amount)
  30. 30. solution?
  31. 31. double entry bookkeeping
  32. 32. https://en.wikipedia.org/wiki/File:Luca_Pacioli_(Gemaelde).jpeg Luca Pacioli 1447–1517
  33. 33. accounts
  34. 34. transactions
  35. 35. ledger
  36. 36. debit / credit
  37. 37. traditional aka British - we won’t cover it
  38. 38. accounting equation aka American
  39. 39. asset (A) cash, bank, accounts receivable, inventory
  40. 40. liability (L) accounts payable, salaries, customer deposits, etc
  41. 41. equity (Eq) capital, retained earnings, accumulated funds, etc
  42. 42. income / revenue (I) services rendered, sales, membership fees, etc
  43. 43. expense (Ex) telephone, water, electricity, repairs, salaries, etc
  44. 44. A + Ex = Eq + L + I
  45. 45. asset, liability, income, expense
  46. 46. debit credit asset + - equity - + liability - + income/revenue - + expense + -
  47. 47. account type account name debit credit asset PayPal $100 + liability Seller Withdrawable $90 + income/ revenue Application Fee $10 + Purchase Transaction
  48. 48. balance sheet
  49. 49. accounts type description balance asset PayPal $100 liability All Sellers Withdrawable $90 income/revenue Profit $10 Balance Sheet A + Ex = Eq + L + I A($100) = L($90) + I($10)
  50. 50. accounts type description balance asset PayPal $100 asset Stripe $200 liability All Sellers Withdrawable $270 income/revenue Profit $30 Balance Sheet
  51. 51. payout
  52. 52. account type account name debit credit liability Seller Withdrawable $90 - asset PayPal $90 - Payout
  53. 53. accounts type description balance asset PayPal $10 liability All Sellers Withdrawable $0 income/revenue Profit $10 Balance Sheet A($10) = I($10)
  54. 54. A + Ex = Eq + L + I
  55. 55. sophisticated example
  56. 56. keep talking… I’m diagnosing you
  57. 57. $100 buyer $30 $10 seller 1 app $60 seller 2
  58. 58. account type account name debit credit income Sales $100 + asset PayPal $100 + liability Seller 1 Escrow $30 + liability Seller 2 Escrow $60 + expense Seller Expenses $90 + Purchase Transaction
  59. 59. account type account name amount income Sales $100 asset PayPal $100 liability Sellers Escrow $90 expense Seller Expenses $90 Balance Sheet A($100) + Ex($90) = L($90) + I($100)
  60. 60. account type account name debit credit liability Seller 1 Escrow $30 - liability Seller 2 Escrow $60 - liability Seller 1 Withdrawable $30 + liability Seller 2 Withdrawable $60 + Clearance A($100) + Ex($90) = L($90) + I($100)
  61. 61. account type account name debit credit liability Seller 1 Withdrawable $30 - asset PayPal $30 - Payout account type account name debit credit liability Seller 2 Withdrawable $60 - asset PayPal $60 -
  62. 62. account type account name amount income Sales $100 asset PayPal $10 liability Sellers Escrow $0 expense Seller Expenses $90 Balance Sheet A($10) + Ex($90) = I($100)
  63. 63. debit credit Revenues (Sales) $100 Expenses (Paid to Sellers / Suppliers) $90 Net Income $10 Income Statement
  64. 64. implementation
  65. 65. https://github.com/astrails/debitcredit double entry accounting for rails applications
  66. 66. Debitcredit::AssetAccount.create name: 'paypal' puts Debitcredit::Account[:paypal].name
  67. 67. class Seller < ActiveRecord::Base include Debitcredit::Extension has_accounts do liability :escrow liability :withdrawable end has_entries end
  68. 68. class Payout < ActiveRecord::Base belongs_to :seller after_create :payout! validates :amount, presence: true # ... def payout! Payout.transaction do self.payout_entry = Entry.prepare(description: "John the Seller") do kind "withdrawal" debit seller.accounts[:withdrawable], amount credit Debitcredit::Account[:paypal], amount, "seller payout" end payout_entry.save! self.state = "paid" self.paid_at = Time.now.utc save! end end end
  69. 69. ledger
  70. 70. cached values
  71. 71. class Order < ActiveRecord::Base; end class OrderItem < ActiveRecord::Base; end class Purchase < ActiveRecord::Base; end class Withdrawal < ActiveRecord::Base; end class Refund < ActiveRecord::Base; end class Chargeback < ActiveRecord::Base; end
  72. 72. recovery
  73. 73. why
  74. 74. transparency
  75. 75. balance sheet and income statement
  76. 76. preventing bugs & fraud accounting equation
  77. 77. A + Ex = Eq + L + I
  78. 78. thanks! Boris Nadion http://astrails.com

×