PY?=python3
LEDGER=hledger
TOLDG=$(PY) ../toldg.py
GETOFX=$(PY) ../getofx.py

TOLDG_CONFIG=configs/toldg.json
GETOFX_CONFIG=configs/getofx.json
LEDGER_FILES=$(wildcard processed/*.ldg)
OUTPUTDIR=processed
LEDGER_ALL=result.ldg

all: toldg merge

help:
	@echo 'Makefile for Ledger automation                                            '
	@echo '                                                                          '
	@echo 'Usage:                                                                    '
	@echo '   make getofx                         download ofx data and write to CSV '
	@echo '   make toldg                          transform CSV files into LDG files '
	@echo '   make merge                          merge all ldg files into one       '
	@echo '   make bs                             show hledger balance               '
	@echo '   make ui                             open hledger-ui in tree view       '
	@echo '   make clean                          remove ledger files from output dir'
	@echo '                                                                          '

getofx:
	@$(GETOFX) $(GETOFX_CONFIG)

toldg:
	@$(TOLDG) $(TOLDG_CONFIG)

merge:
	@cat $(LEDGER_FILES) > $(LEDGER_ALL)

bs:
	@echo ""
	@$(LEDGER) bs -V --depth 2 -f $(LEDGER_ALL)

ui:
	hledger-ui -V --tree --depth 2 -f $(LEDGER_ALL)

clean:
	@[ ! -d $(OUTPUTDIR) ] || rm -rf $(OUTPUTDIR)/*

