Skip to content

Instantly share code, notes, and snippets.

@simonmichael
Created June 22, 2010 00:02
Show Gist options
  • Save simonmichael/447724 to your computer and use it in GitHub Desktop.
Save simonmichael/447724 to your computer and use it in GitHub Desktop.
sm's (h)ledger make rules
# bits from Simon's finance/accounting makefile
help: # describe make targets
@egrep '^[^ #A-Z]+:' Makefile
fixperms:
chmod -R go-rwx .
################################################################################
# personal finance
YEAR:=${shell date +%Y}
NEXTYEAR:=${shell expr $(YEAR) + 1}
MONTHS=01 02 03 04 05 06 07 08 09 10 11 12
LEDGER2=ledger2.6
LEDGER3=ledger -y %Y/%m/%d
HLEDGER=hledger
DOWNLOADDIR=~/Desktop
MV=mv
move-csv: # move newly downloaded bank data here and rename
@(F=$(DOWNLOADDIR)/Checking1.csv; [ -e $$F ] && $(MV) $$F WellsFargoChecking1.csv || exit 0)
@(F=$(DOWNLOADDIR)/Savings2.csv; [ -e $$F ] && $(MV) $$F WellsFargoSavings2.csv || exit 0)
@(F=$(DOWNLOADDIR)/Savings3.csv; [ -e $$F ] && $(MV) $$F WellsFargoSavings3.csv || exit 0)
@(F=$(DOWNLOADDIR)/CreditCard4.csv; [ -e $$F ] && $(MV) $$F WellsFargoCreditCard4.csv || exit 0)
@(F=$(DOWNLOADDIR)/Download.csv; [ -e $$F ] && $(MV) $$F Paypal.csv || exit 0)
@(F=$(DOWNLOADDIR)/History-*-022254.csv; [ -e $$F ] && for f in $$F; do $(MV) $$f WescomSavings.csv; done || exit 0)
@(F=$(DOWNLOADDIR)/History-*-022345.csv; [ -e $$F ] && for f in $$F; do $(MV) $$f WescomChecking.csv; done || exit 0)
BANKJOURNALS = \
WellsFargoChecking1.journal \
WellsFargoSavings2.journal \
WellsFargoSavings3.journal \
WellsFargoCreditCard4.journal \
WescomSavings.journal \
WescomChecking.journal \
Paypal.journal
convert-csv: $(BANKJOURNALS) # convert latest bank csv downloads to journal files
%.journal: %.csv %.rules
hledger convert $< >$@
wellsfargo-checking-balance checking-balance: daily-balance-wells\ fargo\:checking
wellsfargo-savings2-balance savings2-balance: daily-balance-wells\ fargo\:prudent\ reserve\ savings
wellsfargo-savings3-balance savings3-balance: daily-balance-wells\ fargo\:tax\ savings
wellsfargo-creditcard-balance creditcard-balance: daily-balance-cards\:wells\ fargo
wescom-checking-balance: daily-balance-wescom\:checking
wescom-savings-balance: daily-balance-wescom\:savings
paypal-balance: daily-balance-paypal
SINCE=1/1
daily-balance-%: # report recent daily balance of a specified account
hledger register --effective --period 'daily to today' --display 'd>=[$(SINCE)]' '$*'
BALANCESHEETACCTS=assets liabilities equity not:equity:draw
BALANCESHEETOPTS=--cost --effective # --flat --drop 1 #--depth 2
opening-balance-sheet: # show quick balance sheet as of start of this year
@printf "\nbalance sheet at year start:\n"
@hledger print 'equity:opening balances' --period 'this year' --cost \
|hledger -f - balance $(BALANCESHEETACCTS) $(BALANCESHEETOPTS)
balance-sheet-%: # show quick balance sheet as of specified date
@printf "\nbalance sheet as of midnight $*:\n"
hledger balance $(BALANCESHEETACCTS) --end '$*' $(BALANCESHEETOPTS)
balance-sheet: balance-sheet-tomorrow # show quick balance sheet for today
# show quick monthly balance sheets for this year
balance-sheets: \
opening-balance-sheet \
balance-sheet-$(YEAR)-02-01 \
balance-sheet-$(YEAR)-03-01 \
balance-sheet-$(YEAR)-04-01 \
balance-sheet-$(YEAR)-05-01 \
balance-sheet-$(YEAR)-06-01 \
balance-sheet-tomorrow
# balance-sheet-$(YEAR)-07-01 \
# balance-sheet-$(YEAR)-08-01 \
# balance-sheet-$(YEAR)-09-01 \
# balance-sheet-$(YEAR)-10-01 \
# balance-sheet-$(YEAR)-11-01 \
# balance-sheet-$(NEXTYEAR)-01-01
closing-balances-%: # show closing balances for specified year
hledger -f $*.journal --effective --end `expr $* + 1` balance $(BALANCESHEETACCTS) $(BALANCESHEETOPTS)
INCOMESTATEMENTACCTS=draw #income expenses equity:draw
INCOMESTATEMENTOPTS=--cost --effective --depth 4 #--flat --drop 1
income-statement-%: # show quick income statement for specified period
@printf "\nincome statement for $*:\n"
hledger balance $(INCOMESTATEMENTACCTS) --period '$*' $(INCOMESTATEMENTOPTS)
# show quick monthly income statements for year
income-statements: \
income-statement-$(YEAR)-01 \
income-statement-$(YEAR)-02 \
income-statement-$(YEAR)-03 \
income-statement-$(YEAR)-04 \
income-statement-$(YEAR)-05 \
income-statement-$(YEAR)-06 \
# income-statement-$(YEAR)-07 \
# income-statement-$(YEAR)-08 \
# income-statement-$(YEAR)-09 \
# income-statement-$(YEAR)-10 \
# income-statement-$(YEAR)-11 \
# income-statement-$(YEAR)-12
ar: # show accounts receivable activity & status
@echo Accounts Receivable activity this year:
@hledger reg receivable --effective -p'this year'
@echo
@echo Accounts Receivable balances:
@hledger bal receivable --effective #-p'this year'
# ar-deposits: # show actual dates of bank deposits for accounts receivable
# @$(LEDGER3) reg receivable -B -l 'a<0' --effective
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment