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 1Gene Carboni
 
Accounting Equation Presentation
Accounting Equation PresentationAccounting Equation Presentation
Accounting Equation PresentationFahad Mohiz
 
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 DesignAlexandre Van de Sande
 
Cost of Goods Sold
Cost of Goods SoldCost of Goods Sold
Cost of Goods SoldMang Engkus
 
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, andIva Walton
 
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 AppMartin Kleppmann
 
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
 
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 hackingPol Valls Soler
 
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 GuaranteedBringShare.com
 
Double Entry System & Accountin Equation
Double Entry System & Accountin EquationDouble Entry System & Accountin Equation
Double Entry System & Accountin EquationGurkirat Singh
 

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

Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applicationsAstrails
 
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 SmarterAstrails
 
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.Astrails
 
Engineering esthetics
Engineering estheticsEngineering esthetics
Engineering estheticsAstrails
 
Lean Software Development
Lean Software DevelopmentLean Software Development
Lean Software DevelopmentAstrails
 
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 RubyAstrails
 
WTF is NoSQL
WTF is NoSQLWTF is NoSQL
WTF is NoSQLAstrails
 
Cassandra intro
Cassandra introCassandra intro
Cassandra introAstrails
 
Ruby is an Acceptable Lisp
Ruby is an Acceptable LispRuby is an Acceptable Lisp
Ruby is an Acceptable LispAstrails
 
Ruby is Awesome
Ruby is AwesomeRuby is Awesome
Ruby is AwesomeAstrails
 
Rails missing features
Rails missing featuresRails missing features
Rails missing featuresAstrails
 
Performance - When, What and How
Performance - When, What and HowPerformance - When, What and How
Performance - When, What and HowAstrails
 

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

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 

Recently uploaded (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 

Accounting For Hackers