SlideShare uma empresa Scribd logo
1 de 34
Baixar para ler offline
BUILDING A
POWERFUL DOUBLE-
ENTRY ACCOUNTING
SYSTEM
Lucas Cavalcanti
DOUBLE-ENTRY ACCOUNTING
ANCIENT, UBIQUITOUS TECHNOLOGY
USER BALANCES
Future bills
Open bill
Due bill
Available balance
OPERATIONS
Purchases
Chargebacks
Payments
BALANCE
SHEET
DEBIT CREDIT
General Ledger
USEFUL ABSTRACTIONS
Income statement
Cash flow statement
Balance sheet
LIABILITY
ASSET
EQUITY
Debits Credits
PROPERTY:
on each movement
Image © http://chestofbooks.com/business/reference/Home-Cyclopedia-Of-Business/Bill-Book.html
Credits (CR):
- $97 on liability payables
(we will pay the merchant)
- $3 Credit on P&L interchange
(our profit)
- $100 on off-balance
asset current-limit
EXAMPLE: A purchase of $100
Debits (DR):
- $100 on asset settled
(we will receive
it from the customer)
- $100 on off-balance
liability current-limit-cp
EXAMPLE: A payment of $100
Debits (DR):
- $100 on asset cash
(we received it
from the customer)
- $100 on off-balance
asset current-limit
Credits (CR):
- $100 on asset settled
(we paid the purchase)
- $100 on off balance
liability current-limit-cp
DOUBLE ENTRY ACCOUNTING
EVENTS TRIGGERING MOVEMENTS
• purchases
• payments
• bills
IMMUTABLE
• append-only
• entry log
• can fix past by compensating
INVARIANTS
• movements sums to zero
• a book-account balance is sum of credits
and debits
1 MOVEMENT => N ENTRIES
(s/defschema Entry {:entry/id s/Uuid

:entry/amount PositiveAmount 

:entry/debit-account BookAccount

:entry/credit-account BookAccount

:entry/post-date LocalDate

:entry/movement Movement})
So by design,
(ns double-entry.models.entry

(:require [schema.core :as s]))
1 BUSINESS EVENT => 1 MOVEMENT + META
e.g new-purchase, new-payment, new-bill
(s/defschema Movement {:movement/id s/Uuid

:movement/flow-id String

:movement/topic Topic

:movement/owner-account Account

:movement/produced-at LocalDateTime

:movement/consumed-at LocalDateTime

:movement/user String})
(s/defschema Meta {:meta/id s/Uuid

:meta/movement Movement

:meta/entity (s/either Payment Purchase Bill ...)})
DECLARATIVE RULES FOR MOVEMENTS
(ns common-schemata.wire)
(s/defschema Purchase

{:purchase {:id s/Uuid

:merchant String

:amount t-money/PositiveAmount
:interchange t-money/PositiveAmount

:time LocalDateTime

…}})
(s/defschema Payment

{:payment {:id s/Uuid

:amount t-money/PositiveAmount

:post-date LocalDate

…}})
DECLARATIVE RULES FOR MOVEMENTS
(def new-purchase

[{:entry/debit-account :book-account.asset/settled-brazil

:entry/credit-account :book-account.liability/payable-brazil

:entry/amount (comp :amount :purchase)

:entry/post-date (comp time->date :time :purchase)}
{:entry/debit-account :book-account.liability/payable-brazil

:entry/credit-account :book-account.profit-and-loss/interchange-brazil

:entry/amount (comp :interchange :purchase)

:entry/post-date (comp time->date :time :purchase)}


{:entry/debit-account :book-account.liability/current-limit-counterparty

:entry/credit-account :book-account.asset/current-limit

:entry/amount (comp :amount :purchase)

:entry/post-date (comp time->date :time :purchase)}])
DECLARATIVE RULES FOR MOVEMENTS
(def new-payment

[{:entry/debit-account :book-account.asset/transitory-bank

:entry/credit-account :book-account.asset/settled-brazil

:entry/amount (comp :amount :payment)

:entry/post-date (comp :post-date :payment)}


{:entry/debit-account :book-account.asset/current-limit

:entry/credit-account :book-account.liability/current-limit-counterparty

:entry/amount (comp :amount :payment)

:entry/post-date (comp :post-date :purchase)}])
[{:entry/id (uuid)

:entry/amount 100.0M

:entry/debit-account :book-account.asset/settled-brazil

:entry/credit-account :book-account.liability/payable-brazil

:entry/post-date #nu/date "2016-12-01"

:entry/movement new-purchase}


{:entry/id (uuid)

:entry/amount 3.0M

:entry/debit-account :book-account.liability/payable-brazil

:entry/credit-account :book-account.profit-and-loss/interchange-brazil

:entry/post-date #nu/date "2016-12-01"

:entry/movement new-purchase}
{:entry/id (uuid)

:entry/amount 100.0M

:entry/debit-account :book-account.liability/current-limit-counterparty

:entry/credit-account :book-account.asset/current-limit

:entry/post-date #nu/date "2016-12-01"

:entry/movement new-purchase}]
{:purchase

{:id (uuid)

:amount 100.0M

:interchange 3.0M

:time #nu/time "2016-12-01T13:37:42Z"}}
Rulebook
[{:entry/id (uuid)

:entry/amount 100.0M

:entry/debit-account :book-account.asset/transitory-bank

:entry/credit-account :book-account.asset/settled-brazil

:entry/post-date #nu/date "2016-12-01"

:entry/movement new-payment}
{:entry/id (uuid)

:entry/amount 100.0M

:entry/debit-account :book-account.asset/current-limit

:entry/credit-account :book-account.liability/current-limit-counterparty

:entry/post-date #nu/date "2016-12-01"

:entry/movement new-payment}]
{:payment

{:id (uuid)

:amount 100.0M

:post-date #nu/date "2016-12-01"}}
Rulebook
Cumulative cache
(balance sheet)
Event
(log)
2 LOGS AND A CACHE
ACTUAL TIME
audit trail / Datomic log
“when did we know”day 0 day 30 day 90
SYSTEM OF RECORD TIME
official version of events
uses business-relevant “post dates”
can correct after the fact
day 90
day 0day 0
day 30
SANITY CHECKS / BUSINESS INVARIANTS
• Balances must be always positive or always negative
• Cannot have a “late” balance there is a “prepaid” balance
• A purchase should “move” exactly the purchase amount on
assets and on current limit
(def balances-property
(prop/for-all [account (g/generator Account)

events (gen/vector (gen/one-of [(g/generator Purchase)

(g/generator Payment)

...]))]

(->> (empty-db)

(save-all! account events)

:db-after

(balances-are-positive!)))
(fact (tc/quick-check 50 balances-property) => (th/embeds {:result true}))
GENERATIVE TESTING
(ns double-entry.controllers.rulebook-test

(:require [midje.sweet :refer :all]
[clojure.test.check.properties :as prop]

[clojure.test.check :as tc]

[schema-generators.generators :as g]

[clojure.test.check.generators :as gen]))
EVENT STREAM FOR
A SINGLE CUSTOMER
1. Business events generate idempotent Kafka
messages
2. For each event, apply functions to convert the
event data into a movement with 1+ entries
• Movements balance by design
• Movements associate provenance metadata
3. Pre-check guarantees invariants against db value
4. Eagerly cache resulting balances
debit-account credit-account amount
a/max-limit
a/current-limit
l/max-limit-cp
l/current-limit-cp
initial-limit
15000.00
15000.00
CARD ISSUED
debit-account credit-account amount
new-purchase / settle-brazil
100.00
100.00
100.00
100.00
CARD ISSUED FIRST PURCHASE
l/current-limit-cp
a/unsettled
l/unsettled-cp
a/settled-brazil
a/current-limit
l/unsettled-cp
a/unsettled
l/payable-brazil
debit-account credit-account amount
closed-bill
15.00
100.00
CARD ISSUED FIRST PURCHASE
a/minimum-payment
a/closed
l/minimum-payment-cp
a/settled-brazil
FIRST BILL CLOSES
debit-account credit-account amount
new-payment
10.00
10.00
10.00
CARD ISSUED FIRST PURCHASE
a/current-limit
l/minimum-payment-cp
a/transitory-bank
l/current-limit-cp
a/minimum-payment
a/late
FIRST BILL CLOSES PARTIAL PAYMENT
debit-account credit-account amount
new-adjustment
7.00
7.00
CARD ISSUED FIRST PURCHASE
l/current-limit-cp
a/settled-financed
a/current-limit
e/revolving-interest
FIRST BILL CLOSES PARTIAL PAYMENT INTEREST ASSESSED
debit-account credit-account amount
closed-bill
7.00
5.00
14.55
7.00
90.00
5.00
7.00
90.00
7.00
7.00
7.00
2.55
7.00
CARD ISSUED FIRST PURCHASE
a/late
l/minimum-payment-cp
a/minimum-payment
a/closed
a/current-limit
l/minimum-payment-cp
a/transitory-bank
a/transitory-bank
l/prepaid
a/current-limit
l/minimum-payment-cp
l/minimum-payment-cp
a/closed
a/closed
a/minimum-payment
l/minimum-payment-cp
a/settled-financed
l/current-limit-cp
a/minimum-payment
l/prepaid
a/late
a/closed
l/current-limit-cp
a/minimum-payment
a/minimum-payment
a/late
FIRST BILL CLOSES PARTIAL PAYMENT INTEREST ASSESSED PAYMENT IN FULL
ZOOMING OUT
2015-01 2015-04 2015-07 2015-10 2015-01 2016-03
DETECTING OPERATIONAL MISTAKES
USE CASES
MANAGEMENT ACCOUNTING
• delinquency tables by cohort and aging
• receivables (domestic, foreign, financed)
• revenue per customer (interchange, interest, fx spread)
REPORTING
• covenants
• regulatory
FINANCIAL ACCOUNTING
• consolidate to ERP
Declarative rules are extensible for additional financial products
(e.g., already extending to rewards, debt financing)
Financial analysis applies at a micro level (negative balances,
weird ratios, operational problems)
Business-specific invariants provide safety (declare mutually
exclusive and impossible states,alert unexpected situations)
Generative testing finds real bugs
Service is shardable by customer account (no interactions
between accounts)
WHAT DO WE LIKE?
33
IF YOU ARE ENTRUSTED WITH A CUSTOMER’S
FINANCIAL RELATIONSHIP, CONSIDER BUILDING A
DOUBLE-ENTRY SYSTEM FOR YOUR DOMAIN
Thank you!
Lucas Cavalcanti
@lucascs
IF YOU CHOOSE TO DO SO, USE ALL THE POWER
FUNCTIONAL PROGRAMMING GIVES YOU

Mais conteúdo relacionado

Mais procurados

Kafka Practices @ Uber - Seattle Apache Kafka meetup
Kafka Practices @ Uber - Seattle Apache Kafka meetupKafka Practices @ Uber - Seattle Apache Kafka meetup
Kafka Practices @ Uber - Seattle Apache Kafka meetupMingmin Chen
 
Cosco: An Efficient Facebook-Scale Shuffle Service
Cosco: An Efficient Facebook-Scale Shuffle ServiceCosco: An Efficient Facebook-Scale Shuffle Service
Cosco: An Efficient Facebook-Scale Shuffle ServiceDatabricks
 
HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18Derek Downey
 
Getting up to Speed with MirrorMaker 2 (Mickael Maison, IBM & Ryanne Dolan) K...
Getting up to Speed with MirrorMaker 2 (Mickael Maison, IBM & Ryanne Dolan) K...Getting up to Speed with MirrorMaker 2 (Mickael Maison, IBM & Ryanne Dolan) K...
Getting up to Speed with MirrorMaker 2 (Mickael Maison, IBM & Ryanne Dolan) K...HostedbyConfluent
 
InfluxDB IOx Tech Talks: The Impossible Dream: Easy-to-Use, Super Fast Softw...
InfluxDB IOx Tech Talks: The Impossible Dream:  Easy-to-Use, Super Fast Softw...InfluxDB IOx Tech Talks: The Impossible Dream:  Easy-to-Use, Super Fast Softw...
InfluxDB IOx Tech Talks: The Impossible Dream: Easy-to-Use, Super Fast Softw...InfluxData
 
Putting Kafka Into Overdrive
Putting Kafka Into OverdrivePutting Kafka Into Overdrive
Putting Kafka Into OverdriveTodd Palino
 
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadinC* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadinDataStax Academy
 
Building Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngineBuilding Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngineBob McCune
 
Pragmatic Guide to Apache Kafka®'s Exactly Once Semantics
Pragmatic Guide to Apache Kafka®'s Exactly Once SemanticsPragmatic Guide to Apache Kafka®'s Exactly Once Semantics
Pragmatic Guide to Apache Kafka®'s Exactly Once Semanticsconfluent
 
Using Kafka to scale database replication
Using Kafka to scale database replicationUsing Kafka to scale database replication
Using Kafka to scale database replicationVenu Ryali
 
Deep Dive on Amazon Aurora - Covering New Feature Announcements
Deep Dive on Amazon Aurora - Covering New Feature AnnouncementsDeep Dive on Amazon Aurora - Covering New Feature Announcements
Deep Dive on Amazon Aurora - Covering New Feature AnnouncementsAmazon Web Services
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerelliando dias
 
Comparing high availability solutions with percona xtradb cluster and percona...
Comparing high availability solutions with percona xtradb cluster and percona...Comparing high availability solutions with percona xtradb cluster and percona...
Comparing high availability solutions with percona xtradb cluster and percona...Marco Tusa
 
Cassandra vs. ScyllaDB: Evolutionary Differences
Cassandra vs. ScyllaDB: Evolutionary DifferencesCassandra vs. ScyllaDB: Evolutionary Differences
Cassandra vs. ScyllaDB: Evolutionary DifferencesScyllaDB
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL AdministrationEDB
 
MAA Best Practices for Oracle Database 19c
MAA Best Practices for Oracle Database 19cMAA Best Practices for Oracle Database 19c
MAA Best Practices for Oracle Database 19cMarkus Michalewicz
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINXNGINX, Inc.
 
High-Performance Advanced Analytics with Spark-Alchemy
High-Performance Advanced Analytics with Spark-AlchemyHigh-Performance Advanced Analytics with Spark-Alchemy
High-Performance Advanced Analytics with Spark-AlchemyDatabricks
 
Improving Kafka at-least-once performance at Uber
Improving Kafka at-least-once performance at UberImproving Kafka at-least-once performance at Uber
Improving Kafka at-least-once performance at UberYing Zheng
 
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...Altinity Ltd
 

Mais procurados (20)

Kafka Practices @ Uber - Seattle Apache Kafka meetup
Kafka Practices @ Uber - Seattle Apache Kafka meetupKafka Practices @ Uber - Seattle Apache Kafka meetup
Kafka Practices @ Uber - Seattle Apache Kafka meetup
 
Cosco: An Efficient Facebook-Scale Shuffle Service
Cosco: An Efficient Facebook-Scale Shuffle ServiceCosco: An Efficient Facebook-Scale Shuffle Service
Cosco: An Efficient Facebook-Scale Shuffle Service
 
HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18
 
Getting up to Speed with MirrorMaker 2 (Mickael Maison, IBM & Ryanne Dolan) K...
Getting up to Speed with MirrorMaker 2 (Mickael Maison, IBM & Ryanne Dolan) K...Getting up to Speed with MirrorMaker 2 (Mickael Maison, IBM & Ryanne Dolan) K...
Getting up to Speed with MirrorMaker 2 (Mickael Maison, IBM & Ryanne Dolan) K...
 
InfluxDB IOx Tech Talks: The Impossible Dream: Easy-to-Use, Super Fast Softw...
InfluxDB IOx Tech Talks: The Impossible Dream:  Easy-to-Use, Super Fast Softw...InfluxDB IOx Tech Talks: The Impossible Dream:  Easy-to-Use, Super Fast Softw...
InfluxDB IOx Tech Talks: The Impossible Dream: Easy-to-Use, Super Fast Softw...
 
Putting Kafka Into Overdrive
Putting Kafka Into OverdrivePutting Kafka Into Overdrive
Putting Kafka Into Overdrive
 
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadinC* Summit 2013: The World's Next Top Data Model by Patrick McFadin
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
 
Building Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngineBuilding Modern Audio Apps with AVAudioEngine
Building Modern Audio Apps with AVAudioEngine
 
Pragmatic Guide to Apache Kafka®'s Exactly Once Semantics
Pragmatic Guide to Apache Kafka®'s Exactly Once SemanticsPragmatic Guide to Apache Kafka®'s Exactly Once Semantics
Pragmatic Guide to Apache Kafka®'s Exactly Once Semantics
 
Using Kafka to scale database replication
Using Kafka to scale database replicationUsing Kafka to scale database replication
Using Kafka to scale database replication
 
Deep Dive on Amazon Aurora - Covering New Feature Announcements
Deep Dive on Amazon Aurora - Covering New Feature AnnouncementsDeep Dive on Amazon Aurora - Covering New Feature Announcements
Deep Dive on Amazon Aurora - Covering New Feature Announcements
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancer
 
Comparing high availability solutions with percona xtradb cluster and percona...
Comparing high availability solutions with percona xtradb cluster and percona...Comparing high availability solutions with percona xtradb cluster and percona...
Comparing high availability solutions with percona xtradb cluster and percona...
 
Cassandra vs. ScyllaDB: Evolutionary Differences
Cassandra vs. ScyllaDB: Evolutionary DifferencesCassandra vs. ScyllaDB: Evolutionary Differences
Cassandra vs. ScyllaDB: Evolutionary Differences
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 
MAA Best Practices for Oracle Database 19c
MAA Best Practices for Oracle Database 19cMAA Best Practices for Oracle Database 19c
MAA Best Practices for Oracle Database 19c
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
High-Performance Advanced Analytics with Spark-Alchemy
High-Performance Advanced Analytics with Spark-AlchemyHigh-Performance Advanced Analytics with Spark-Alchemy
High-Performance Advanced Analytics with Spark-Alchemy
 
Improving Kafka at-least-once performance at Uber
Improving Kafka at-least-once performance at UberImproving Kafka at-least-once performance at Uber
Improving Kafka at-least-once performance at Uber
 
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
 

Semelhante a Building a powerful double entry accounting system

Accounting for Non-Accountants
Accounting for Non-AccountantsAccounting for Non-Accountants
Accounting for Non-AccountantsHelen Weeber
 
Sap business-one-down-payment-invoices-setup-and-processing
Sap business-one-down-payment-invoices-setup-and-processingSap business-one-down-payment-invoices-setup-and-processing
Sap business-one-down-payment-invoices-setup-and-processingKeith Taylor
 
Accounting & finance bankers
Accounting & finance  bankersAccounting & finance  bankers
Accounting & finance bankersBabasab Patil
 
Fa term paper sanmeet dhokay - 2015 pgpmx025
Fa term paper   sanmeet dhokay - 2015 pgpmx025Fa term paper   sanmeet dhokay - 2015 pgpmx025
Fa term paper sanmeet dhokay - 2015 pgpmx025Sanmeet Dhokay
 
Accounting and finance ppt @ bec doms bagalkot mba finance
Accounting and finance  ppt @ bec doms bagalkot mba financeAccounting and finance  ppt @ bec doms bagalkot mba finance
Accounting and finance ppt @ bec doms bagalkot mba financeBabasab Patil
 
working capital
working capitalworking capital
working capitalparag vora
 
A C C O U N T I N G L A K S H A N
A C C O U N T I N G  L A K S H A NA C C O U N T I N G  L A K S H A N
A C C O U N T I N G L A K S H A NLakshan Cooray
 
A C C O U N T I N G L A K S H A N
A C C O U N T I N G  L A K S H A NA C C O U N T I N G  L A K S H A N
A C C O U N T I N G L A K S H A NLakshan Cooray
 
A C C O U N T I N G L A K S H A N
A C C O U N T I N G  L A K S H A NA C C O U N T I N G  L A K S H A N
A C C O U N T I N G L A K S H A NLakshan Cooray
 
Accounting_Accruals_and_Deferrals_ppt.pdf
Accounting_Accruals_and_Deferrals_ppt.pdfAccounting_Accruals_and_Deferrals_ppt.pdf
Accounting_Accruals_and_Deferrals_ppt.pdfMaiSaleh20
 
Inventory acount group
Inventory acount groupInventory acount group
Inventory acount groupBabulu Dasari
 
Sh. aseem sir (workshop of financial managment held on 20 27.03.2013)
Sh. aseem sir (workshop of financial managment held on 20 27.03.2013)Sh. aseem sir (workshop of financial managment held on 20 27.03.2013)
Sh. aseem sir (workshop of financial managment held on 20 27.03.2013)Mukut Deori
 
Billing Process
Billing ProcessBilling Process
Billing Processonearbaein
 
Finance-Presentation-CRP1.pdf
Finance-Presentation-CRP1.pdfFinance-Presentation-CRP1.pdf
Finance-Presentation-CRP1.pdfPrasoonMohanty1
 

Semelhante a Building a powerful double entry accounting system (20)

Accounting for Non-Accountants
Accounting for Non-AccountantsAccounting for Non-Accountants
Accounting for Non-Accountants
 
Sap business-one-down-payment-invoices-setup-and-processing
Sap business-one-down-payment-invoices-setup-and-processingSap business-one-down-payment-invoices-setup-and-processing
Sap business-one-down-payment-invoices-setup-and-processing
 
Accounting & finance bankers
Accounting & finance  bankersAccounting & finance  bankers
Accounting & finance bankers
 
Fa term paper sanmeet dhokay - 2015 pgpmx025
Fa term paper   sanmeet dhokay - 2015 pgpmx025Fa term paper   sanmeet dhokay - 2015 pgpmx025
Fa term paper sanmeet dhokay - 2015 pgpmx025
 
Accounting and finance ppt @ bec doms bagalkot mba finance
Accounting and finance  ppt @ bec doms bagalkot mba financeAccounting and finance  ppt @ bec doms bagalkot mba finance
Accounting and finance ppt @ bec doms bagalkot mba finance
 
working capital
working capitalworking capital
working capital
 
Finance for bankers
Finance for bankersFinance for bankers
Finance for bankers
 
Chap020
Chap020Chap020
Chap020
 
Accounting lakshan
Accounting lakshanAccounting lakshan
Accounting lakshan
 
A C C O U N T I N G L A K S H A N
A C C O U N T I N G  L A K S H A NA C C O U N T I N G  L A K S H A N
A C C O U N T I N G L A K S H A N
 
A C C O U N T I N G L A K S H A N
A C C O U N T I N G  L A K S H A NA C C O U N T I N G  L A K S H A N
A C C O U N T I N G L A K S H A N
 
A C C O U N T I N G L A K S H A N
A C C O U N T I N G  L A K S H A NA C C O U N T I N G  L A K S H A N
A C C O U N T I N G L A K S H A N
 
SAP ERP Structure
SAP ERP StructureSAP ERP Structure
SAP ERP Structure
 
Accounting_Accruals_and_Deferrals_ppt.pdf
Accounting_Accruals_and_Deferrals_ppt.pdfAccounting_Accruals_and_Deferrals_ppt.pdf
Accounting_Accruals_and_Deferrals_ppt.pdf
 
Inventory acount group
Inventory acount groupInventory acount group
Inventory acount group
 
Sh. aseem sir (workshop of financial managment held on 20 27.03.2013)
Sh. aseem sir (workshop of financial managment held on 20 27.03.2013)Sh. aseem sir (workshop of financial managment held on 20 27.03.2013)
Sh. aseem sir (workshop of financial managment held on 20 27.03.2013)
 
Billing Process
Billing ProcessBilling Process
Billing Process
 
Finance-Presentation-CRP1.pdf
Finance-Presentation-CRP1.pdfFinance-Presentation-CRP1.pdf
Finance-Presentation-CRP1.pdf
 
Language of business
Language of businessLanguage of business
Language of business
 
My Portfolio
My PortfolioMy Portfolio
My Portfolio
 

Mais de Lucas Cavalcanti dos Santos

Mais de Lucas Cavalcanti dos Santos (7)

Complex made bearable Clojure conj 2019
Complex made bearable Clojure conj 2019Complex made bearable Clojure conj 2019
Complex made bearable Clojure conj 2019
 
Arquitetando uma instituição financeira moderna
Arquitetando uma instituição financeira modernaArquitetando uma instituição financeira moderna
Arquitetando uma instituição financeira moderna
 
Arquitetura funcional em microservices, 4 anos depois
Arquitetura funcional em microservices, 4 anos depoisArquitetura funcional em microservices, 4 anos depois
Arquitetura funcional em microservices, 4 anos depois
 
Microservices in Clojure
Microservices in ClojureMicroservices in Clojure
Microservices in Clojure
 
Testando a integracao entre serviços - Agile Brazil 2014
Testando a integracao entre serviços - Agile Brazil 2014Testando a integracao entre serviços - Agile Brazil 2014
Testando a integracao entre serviços - Agile Brazil 2014
 
O poder da linguagem Ruby e as suas consequências
O poder da linguagem Ruby e as suas consequênciasO poder da linguagem Ruby e as suas consequências
O poder da linguagem Ruby e as suas consequências
 
Otimizacao prematura-agile-brazil-12
Otimizacao prematura-agile-brazil-12Otimizacao prematura-agile-brazil-12
Otimizacao prematura-agile-brazil-12
 

Último

WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 

Último (20)

WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 

Building a powerful double entry accounting system

  • 1. BUILDING A POWERFUL DOUBLE- ENTRY ACCOUNTING SYSTEM Lucas Cavalcanti
  • 3.
  • 4.
  • 5. USER BALANCES Future bills Open bill Due bill Available balance
  • 8. DEBIT CREDIT General Ledger USEFUL ABSTRACTIONS Income statement Cash flow statement Balance sheet LIABILITY ASSET EQUITY Debits Credits
  • 9. PROPERTY: on each movement Image © http://chestofbooks.com/business/reference/Home-Cyclopedia-Of-Business/Bill-Book.html
  • 10. Credits (CR): - $97 on liability payables (we will pay the merchant) - $3 Credit on P&L interchange (our profit) - $100 on off-balance asset current-limit EXAMPLE: A purchase of $100 Debits (DR): - $100 on asset settled (we will receive it from the customer) - $100 on off-balance liability current-limit-cp
  • 11. EXAMPLE: A payment of $100 Debits (DR): - $100 on asset cash (we received it from the customer) - $100 on off-balance asset current-limit Credits (CR): - $100 on asset settled (we paid the purchase) - $100 on off balance liability current-limit-cp
  • 12. DOUBLE ENTRY ACCOUNTING EVENTS TRIGGERING MOVEMENTS • purchases • payments • bills IMMUTABLE • append-only • entry log • can fix past by compensating INVARIANTS • movements sums to zero • a book-account balance is sum of credits and debits
  • 13. 1 MOVEMENT => N ENTRIES (s/defschema Entry {:entry/id s/Uuid
 :entry/amount PositiveAmount 
 :entry/debit-account BookAccount
 :entry/credit-account BookAccount
 :entry/post-date LocalDate
 :entry/movement Movement}) So by design, (ns double-entry.models.entry
 (:require [schema.core :as s]))
  • 14. 1 BUSINESS EVENT => 1 MOVEMENT + META e.g new-purchase, new-payment, new-bill (s/defschema Movement {:movement/id s/Uuid
 :movement/flow-id String
 :movement/topic Topic
 :movement/owner-account Account
 :movement/produced-at LocalDateTime
 :movement/consumed-at LocalDateTime
 :movement/user String}) (s/defschema Meta {:meta/id s/Uuid
 :meta/movement Movement
 :meta/entity (s/either Payment Purchase Bill ...)})
  • 15. DECLARATIVE RULES FOR MOVEMENTS (ns common-schemata.wire) (s/defschema Purchase
 {:purchase {:id s/Uuid
 :merchant String
 :amount t-money/PositiveAmount :interchange t-money/PositiveAmount
 :time LocalDateTime
 …}}) (s/defschema Payment
 {:payment {:id s/Uuid
 :amount t-money/PositiveAmount
 :post-date LocalDate
 …}})
  • 16. DECLARATIVE RULES FOR MOVEMENTS (def new-purchase
 [{:entry/debit-account :book-account.asset/settled-brazil
 :entry/credit-account :book-account.liability/payable-brazil
 :entry/amount (comp :amount :purchase)
 :entry/post-date (comp time->date :time :purchase)} {:entry/debit-account :book-account.liability/payable-brazil
 :entry/credit-account :book-account.profit-and-loss/interchange-brazil
 :entry/amount (comp :interchange :purchase)
 :entry/post-date (comp time->date :time :purchase)} 
 {:entry/debit-account :book-account.liability/current-limit-counterparty
 :entry/credit-account :book-account.asset/current-limit
 :entry/amount (comp :amount :purchase)
 :entry/post-date (comp time->date :time :purchase)}])
  • 17. DECLARATIVE RULES FOR MOVEMENTS (def new-payment
 [{:entry/debit-account :book-account.asset/transitory-bank
 :entry/credit-account :book-account.asset/settled-brazil
 :entry/amount (comp :amount :payment)
 :entry/post-date (comp :post-date :payment)} 
 {:entry/debit-account :book-account.asset/current-limit
 :entry/credit-account :book-account.liability/current-limit-counterparty
 :entry/amount (comp :amount :payment)
 :entry/post-date (comp :post-date :purchase)}])
  • 18. [{:entry/id (uuid)
 :entry/amount 100.0M
 :entry/debit-account :book-account.asset/settled-brazil
 :entry/credit-account :book-account.liability/payable-brazil
 :entry/post-date #nu/date "2016-12-01"
 :entry/movement new-purchase} 
 {:entry/id (uuid)
 :entry/amount 3.0M
 :entry/debit-account :book-account.liability/payable-brazil
 :entry/credit-account :book-account.profit-and-loss/interchange-brazil
 :entry/post-date #nu/date "2016-12-01"
 :entry/movement new-purchase} {:entry/id (uuid)
 :entry/amount 100.0M
 :entry/debit-account :book-account.liability/current-limit-counterparty
 :entry/credit-account :book-account.asset/current-limit
 :entry/post-date #nu/date "2016-12-01"
 :entry/movement new-purchase}] {:purchase
 {:id (uuid)
 :amount 100.0M
 :interchange 3.0M
 :time #nu/time "2016-12-01T13:37:42Z"}} Rulebook
  • 19. [{:entry/id (uuid)
 :entry/amount 100.0M
 :entry/debit-account :book-account.asset/transitory-bank
 :entry/credit-account :book-account.asset/settled-brazil
 :entry/post-date #nu/date "2016-12-01"
 :entry/movement new-payment} {:entry/id (uuid)
 :entry/amount 100.0M
 :entry/debit-account :book-account.asset/current-limit
 :entry/credit-account :book-account.liability/current-limit-counterparty
 :entry/post-date #nu/date "2016-12-01"
 :entry/movement new-payment}] {:payment
 {:id (uuid)
 :amount 100.0M
 :post-date #nu/date "2016-12-01"}} Rulebook
  • 20. Cumulative cache (balance sheet) Event (log) 2 LOGS AND A CACHE ACTUAL TIME audit trail / Datomic log “when did we know”day 0 day 30 day 90 SYSTEM OF RECORD TIME official version of events uses business-relevant “post dates” can correct after the fact day 90 day 0day 0 day 30
  • 21. SANITY CHECKS / BUSINESS INVARIANTS • Balances must be always positive or always negative • Cannot have a “late” balance there is a “prepaid” balance • A purchase should “move” exactly the purchase amount on assets and on current limit
  • 22. (def balances-property (prop/for-all [account (g/generator Account)
 events (gen/vector (gen/one-of [(g/generator Purchase)
 (g/generator Payment)
 ...]))]
 (->> (empty-db)
 (save-all! account events)
 :db-after
 (balances-are-positive!))) (fact (tc/quick-check 50 balances-property) => (th/embeds {:result true})) GENERATIVE TESTING (ns double-entry.controllers.rulebook-test
 (:require [midje.sweet :refer :all] [clojure.test.check.properties :as prop]
 [clojure.test.check :as tc]
 [schema-generators.generators :as g]
 [clojure.test.check.generators :as gen]))
  • 23. EVENT STREAM FOR A SINGLE CUSTOMER
  • 24. 1. Business events generate idempotent Kafka messages 2. For each event, apply functions to convert the event data into a movement with 1+ entries • Movements balance by design • Movements associate provenance metadata 3. Pre-check guarantees invariants against db value 4. Eagerly cache resulting balances debit-account credit-account amount a/max-limit a/current-limit l/max-limit-cp l/current-limit-cp initial-limit 15000.00 15000.00 CARD ISSUED
  • 25. debit-account credit-account amount new-purchase / settle-brazil 100.00 100.00 100.00 100.00 CARD ISSUED FIRST PURCHASE l/current-limit-cp a/unsettled l/unsettled-cp a/settled-brazil a/current-limit l/unsettled-cp a/unsettled l/payable-brazil
  • 26. debit-account credit-account amount closed-bill 15.00 100.00 CARD ISSUED FIRST PURCHASE a/minimum-payment a/closed l/minimum-payment-cp a/settled-brazil FIRST BILL CLOSES
  • 27. debit-account credit-account amount new-payment 10.00 10.00 10.00 CARD ISSUED FIRST PURCHASE a/current-limit l/minimum-payment-cp a/transitory-bank l/current-limit-cp a/minimum-payment a/late FIRST BILL CLOSES PARTIAL PAYMENT
  • 28. debit-account credit-account amount new-adjustment 7.00 7.00 CARD ISSUED FIRST PURCHASE l/current-limit-cp a/settled-financed a/current-limit e/revolving-interest FIRST BILL CLOSES PARTIAL PAYMENT INTEREST ASSESSED
  • 29. debit-account credit-account amount closed-bill 7.00 5.00 14.55 7.00 90.00 5.00 7.00 90.00 7.00 7.00 7.00 2.55 7.00 CARD ISSUED FIRST PURCHASE a/late l/minimum-payment-cp a/minimum-payment a/closed a/current-limit l/minimum-payment-cp a/transitory-bank a/transitory-bank l/prepaid a/current-limit l/minimum-payment-cp l/minimum-payment-cp a/closed a/closed a/minimum-payment l/minimum-payment-cp a/settled-financed l/current-limit-cp a/minimum-payment l/prepaid a/late a/closed l/current-limit-cp a/minimum-payment a/minimum-payment a/late FIRST BILL CLOSES PARTIAL PAYMENT INTEREST ASSESSED PAYMENT IN FULL
  • 30. ZOOMING OUT 2015-01 2015-04 2015-07 2015-10 2015-01 2016-03
  • 31. DETECTING OPERATIONAL MISTAKES USE CASES MANAGEMENT ACCOUNTING • delinquency tables by cohort and aging • receivables (domestic, foreign, financed) • revenue per customer (interchange, interest, fx spread) REPORTING • covenants • regulatory FINANCIAL ACCOUNTING • consolidate to ERP
  • 32. Declarative rules are extensible for additional financial products (e.g., already extending to rewards, debt financing) Financial analysis applies at a micro level (negative balances, weird ratios, operational problems) Business-specific invariants provide safety (declare mutually exclusive and impossible states,alert unexpected situations) Generative testing finds real bugs Service is shardable by customer account (no interactions between accounts) WHAT DO WE LIKE?
  • 33. 33 IF YOU ARE ENTRUSTED WITH A CUSTOMER’S FINANCIAL RELATIONSHIP, CONSIDER BUILDING A DOUBLE-ENTRY SYSTEM FOR YOUR DOMAIN
  • 34. Thank you! Lucas Cavalcanti @lucascs IF YOU CHOOSE TO DO SO, USE ALL THE POWER FUNCTIONAL PROGRAMMING GIVES YOU