SlideShare a Scribd company logo
1 of 79
Download to read offline
Accounting For Hackers
Boris Nadion
boris@astrails.com
@borisnadion
@borisnadion
boris@astrails.com
astrails
http://astrails.com
awesome web and mobile apps
since 2005
100+
marketplaces
money
money
valuable psychological benefits
cash
virtual representation
model
marketplace
seller / buyer / app
$100
buyer
$90
$10
seller
app
$100
buyer
$90
$10
seller
app
$90
seller
pay-in
pay-out
touch / don’t touch
don’t touch
$100 $90
$10
$100 $100 $10
buyer
seller
buyer seller
app
app
$100 $100 $90
buyer app seller
touch
naïve implementation
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
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)
By Hayley Bouchard https://www.flickr.com/photos/questa/5812984945
we are cool!
$100
buyer
$12
$10
seller 1
app
$31
seller 2
…
$100
buyer
$12
$10
seller 1
app
$31
seller 2
…
$12
seller 1
$31
seller 2
…
escrow
escrow
clearance
class Purchase < ActiveRecord::Base
# ...
scope :cleared, -> { where(state: "cleared") }
# ...
def self.clearance_cron!
# ...
end
end
seller.purchases.cleared.calculate(:sum, :amount)
solution?
double entry bookkeeping
https://en.wikipedia.org/wiki/File:Luca_Pacioli_(Gemaelde).jpeg
Luca Pacioli
1447–1517
accounts
transactions
ledger
debit / credit
traditional
aka British - we won’t cover it
accounting equation
aka American
asset (A)
cash, bank, accounts receivable, inventory
liability (L)
accounts payable, salaries, customer deposits, etc
equity (Eq)
capital, retained earnings, accumulated funds, etc
income / revenue (I)
services rendered, sales, membership fees, etc
expense (Ex)
telephone, water, electricity, repairs, salaries, etc
A + Ex = Eq + L + I
asset, liability, income, expense
debit credit
asset
+ -
equity
- +
liability
- +
income/revenue
- +
expense
+ -
account
type
account name debit credit
asset PayPal $100 +
liability Seller Withdrawable $90 +
income/
revenue
Application Fee $10 +
Purchase Transaction
balance sheet
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)
accounts type description balance
asset PayPal $100
asset Stripe $200
liability All Sellers Withdrawable $270
income/revenue Profit $30
Balance Sheet
payout
account
type
account name debit credit
liability Seller Withdrawable $90 -
asset PayPal $90 -
Payout
accounts type description balance
asset PayPal $10
liability All Sellers Withdrawable $0
income/revenue Profit $10
Balance Sheet
A($10) = I($10)
A + Ex = Eq + L + I
sophisticated example
keep talking…
I’m
diagnosing you
$100
buyer
$30
$10
seller 1
app
$60
seller 2
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
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)
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)
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 -
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)
debit credit
Revenues (Sales) $100
Expenses (Paid to Sellers / Suppliers) $90
Net Income $10
Income Statement
implementation
https://github.com/astrails/debitcredit
double entry accounting for rails applications
Debitcredit::AssetAccount.create name: 'paypal'
puts Debitcredit::Account[:paypal].name
class Seller < ActiveRecord::Base
include Debitcredit::Extension
has_accounts do
liability :escrow
liability :withdrawable
end
has_entries
end
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
ledger
cached values
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
recovery
why
transparency
balance sheet
and income statement
preventing bugs & fraud
accounting equation
A + Ex = Eq + L + I
thanks!
Boris Nadion
http://astrails.com

More Related Content

Similar to Accounting For Hackers

Accounting - Chapter 1
Accounting - Chapter 1Accounting - Chapter 1
Accounting - Chapter 1
Gene Carboni
 
All my agents are retiring! What do I do?
All my agents are retiring! What do I do?All my agents are retiring! What do I do?
All my agents are retiring! What do I do?
Inman News
 

Similar to Accounting For Hackers (17)

Accounting - Chapter 1
Accounting - Chapter 1Accounting - Chapter 1
Accounting - Chapter 1
 
Business Valuation Report Template
Business Valuation Report TemplateBusiness Valuation Report Template
Business Valuation Report Template
 
Accounting Equation Presentation
Accounting Equation PresentationAccounting Equation Presentation
Accounting Equation Presentation
 
Devcon 1 - Build a Ðapp: Contract and Design
Devcon 1 - Build a Ðapp: Contract and DesignDevcon 1 - Build a Ðapp: Contract and Design
Devcon 1 - Build a Ðapp: Contract and Design
 
Cost of Goods Sold
Cost of Goods SoldCost of Goods Sold
Cost of Goods Sold
 
How To Prepare Cash Flow Statement
How To Prepare Cash Flow StatementHow To Prepare Cash Flow Statement
How To Prepare Cash Flow Statement
 
How To Prepare Cash Flow Statement
How To Prepare Cash Flow StatementHow To Prepare Cash Flow Statement
How To Prepare Cash Flow Statement
 
Chapter 5 transactions that affect revenue, expenses, and
Chapter 5 transactions that affect revenue, expenses, andChapter 5 transactions that affect revenue, expenses, and
Chapter 5 transactions that affect revenue, expenses, and
 
Invoicing Gem - Sales & Payments In Your App
Invoicing Gem - Sales & Payments In Your AppInvoicing Gem - Sales & Payments In Your App
Invoicing Gem - Sales & Payments In Your App
 
Basic accounting
Basic accountingBasic accounting
Basic accounting
 
All my agents are retiring! What do I do?
All my agents are retiring! What do I do?All my agents are retiring! What do I do?
All my agents are retiring! What do I do?
 
How To Make Money From Apps: Pirate metrics & growth hacking
How To Make Money From Apps: Pirate metrics & growth hackingHow To Make Money From Apps: Pirate metrics & growth hacking
How To Make Money From Apps: Pirate metrics & growth hacking
 
Microeconomicsch 7
Microeconomicsch 7Microeconomicsch 7
Microeconomicsch 7
 
How To: Grow a Business Wihout the Guesswork - Marketing Results Guaranteed
How To: Grow a Business Wihout the Guesswork - Marketing Results GuaranteedHow To: Grow a Business Wihout the Guesswork - Marketing Results Guaranteed
How To: Grow a Business Wihout the Guesswork - Marketing Results Guaranteed
 
Lecture slides (3).pptx
Lecture slides (3).pptxLecture slides (3).pptx
Lecture slides (3).pptx
 
How to prepare cash flow statement
How to prepare cash flow statementHow to prepare cash flow statement
How to prepare cash flow statement
 
Double Entry System & Accountin Equation
Double Entry System & Accountin EquationDouble Entry System & Accountin Equation
Double Entry System & Accountin Equation
 

More from Astrails

More from Astrails (12)

Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applications
 
Machine Learning: Make Your Ruby Code Smarter
Machine Learning: Make Your Ruby Code SmarterMachine Learning: Make Your Ruby Code Smarter
Machine Learning: Make Your Ruby Code Smarter
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
 
Engineering esthetics
Engineering estheticsEngineering esthetics
Engineering esthetics
 
Lean Software Development
Lean Software DevelopmentLean Software Development
Lean Software Development
 
RubyMotion: Put your Dreams in Motion with Ruby
RubyMotion: Put your Dreams in Motion with RubyRubyMotion: Put your Dreams in Motion with Ruby
RubyMotion: Put your Dreams in Motion with Ruby
 
WTF is NoSQL
WTF is NoSQLWTF is NoSQL
WTF is NoSQL
 
Cassandra intro
Cassandra introCassandra intro
Cassandra intro
 
Ruby is an Acceptable Lisp
Ruby is an Acceptable LispRuby is an Acceptable Lisp
Ruby is an Acceptable Lisp
 
Ruby is Awesome
Ruby is AwesomeRuby is Awesome
Ruby is Awesome
 
Rails missing features
Rails missing featuresRails missing features
Rails missing features
 
Performance - When, What and How
Performance - When, What and HowPerformance - When, What and How
Performance - When, What and How
 

Recently uploaded

Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
drm1699
 

Recently uploaded (20)

A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
What is a Recruitment Management Software?
What is a Recruitment Management Software?What is a Recruitment Management Software?
What is a Recruitment Management Software?
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Concepts
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In witbank
^Clinic ^%[+27788225528*Abortion Pills For Sale In witbank^Clinic ^%[+27788225528*Abortion Pills For Sale In witbank
^Clinic ^%[+27788225528*Abortion Pills For Sale In witbank
 

Accounting For Hackers