Permalink
Browse files

Got working balance calculations. Includes some simple accounts in

the main namespace
  • Loading branch information...
fvisser committed Jan 21, 2011
1 parent 035da5c commit 4fe44945b015b1fbaaf595f93cfe023be005c2a6
Showing with 55 additions and 11 deletions.
  1. +18 −1 README
  2. +2 −1 project.clj
  3. +10 −0 src/turbid/account.clj
  4. +17 −1 src/turbid/calc.clj
  5. +8 −8 src/turbid/main.clj
View
19 README
@@ -1,6 +1,23 @@
# turbid
-FIXME: write description
+Small accounting application. To rehearse, there are five types of account:
+asset (debit account)
+liability (credit account)
+expense (debit account)
+income (credit account)
+equity (credit account)
+
+Debit accounts increase their balance if a new value is added to the
+debit (left) side of the balance, credit accounts increase in value
+if the credit (right) is increased
+
+basic formula:
+
+
+Assets + Draws + Expenses = Liabilities + Owner's Equity + Revenue
+
+assets - liabilities = equity + revenue - expense - draws
+
## Usage
View
@@ -3,7 +3,8 @@
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[compojure "0.5.2"]
- [hiccup "0.3.1"]]
+ [hiccup "0.3.1"]
+ [clj-time "0.3.0-SNAPSHOT"]]
:dev-dependencies [[lein-ring "0.2.4"]
[swank-clojure "1.2.1"]]
:ring {:handler turbid.core/handler})
View
@@ -13,3 +13,13 @@
(defn new-equity-account [name category]
(Account. name "equity" category))
+
+(defn new-expense-account [name category]
+ (Account. name "expense" category))
+
+(defn new-income-account [name category]
+ (Account. name "income" category))
+
+(defn new-draw-account [name category]
+ (Account. name "draw" category))
+
View
@@ -2,4 +2,20 @@
(:require [turbid.transaction :as transaction]
[turbid.account :as account]))
-xb
+;; perform calculations, e.g. add the
+(defn add-side [cur acc side]
+ "calculate the debit or credit side of a given account"
+ (reduce +
+ (map #(:amount %)
+ (filter #(= (side %) acc) cur))))
+
+(defn calculate-balance [cur account]
+ "calculate the balance"
+ (let [debit (add-side cur account :debitAccount)
+ credit (add-side cur account :creditAccount)]
+ (if (or (= (:type account) "asset")
+ (= (:type account) "expense")
+ (= (:type account) "draw"))
+ (- debit credit)
+ (- credit debit))))
+
View
@@ -1,24 +1,24 @@
(ns turbid.main
(:require [turbid.transaction :as transaction]
- [turbid.account :as account]))
+ [turbid.account :as account])
+ (:use [clj-time.core :only [date-time now plus minus days months years]]))
+
;; namespace tracking the current state of progress. This will slowly
;; evolve into a program reading transactions and categorizing them
(def rabobank-rekening
(account/new-asset-account "Rabobank Rekening" "cash"))
-(def opening-balance
- (account/new-equity-account "Opening Balances" "income"))
+(def equity-account
+ (account/new-equity-account "Unspecified Equity" "unspecified"))
(def income-account
- (account/new-equity-account "Unspecified Income" "income"))
+ (account/new-income-account "Unspecified Income" "unspecified"))
(def expense-account
- (account/new-equity-account "Unspecified Expenses" "expense"))
+ (account/new-expense-account "Unspecified Expenses" "unspecified"))
(def transactions [])
-;; small change here to check if magit picks this up
-;; and allows me to commit this easily
-;; (conj transactions (transaction/new-transaction 100.00
+(def accounts [])

0 comments on commit 4fe4494

Please sign in to comment.