-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturningledge.sh
executable file
·130 lines (108 loc) · 3.24 KB
/
turningledge.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
# turningledge.sh
_V=0
while getopts "v" OPTION
do
case $OPTION in
v) _V=1
;;
esac
done
function log () {
if [[ $_V -eq 1 ]]; then
printf "$@"
fi
}
printf "*******************\n"
printf "turningledge report \n"
printf "%s \n" "$(date +"%d/%m/%Y")"
printf "*******************\n"
log "Reading config file...\n"
source ~/.turningledgerc
log "\n"
log "Income \n"
log "====== \n"
function monthlyincome {
ledger budget $salaryaccount \
-p "last 30 days" \
--budget-format "%(get_at(display_total, 1))\n"
}
monthlyincome=$(tr -dc '0-9.' <<< $(monthlyincome))
function monthlyincomeex {
ledger budget \
$regularexpensesinclude \
-p "last 30 days" \
--budget-format "%(trim(scrub(get_at(T, 1))))\n" -n | awk "END {print $NF}"
}
monthlyincomeex=$(tr -dc '0-9.' <<< $(monthlyincomeex))
log "Deriving salary from account \"%s\".\n" "$salaryaccount"
log "Adding \"%s\" to monthly expense calculations.\n\n" "$regularexpensesinclude"
log "Monthly income: £ %7s \n" "$monthlyincome"
log " Less regular expenses: £ %7s \n" "$monthlyincomeex"
log "\n"
log "Unbudgeted expenses\n"
log "===================\n"
function unbudgetedday {
ledger --unbudgeted register not "Liabilities" \
-p "today" \
--format "%(display_total)\n" --tail 1 | tail -1
}
unbudgetedday=$(tr -dc '0-9.' <<< $(unbudgetedday))
if [[ -z $(unbudgetedday) ]] ; then
unbudgetedday=0.00
else
unbudgetedday=$(tr -dc '0-9.' <<< $(unbudgetedday))
fi
function unbudgetedweek {
ledger --unbudgeted register not "Liabilities" \
-p "last 7 days" \
--format "%(display_total)\n" --tail 1 | tail -1
}
if [[ -z $(unbudgetedweek) ]] ; then
unbudgetedweek=0.00
else
unbudgetedweek=$(tr -dc '0-9.' <<< $(unbudgetedweek))
fi
function unbudgetedmonth {
ledger --unbudgeted register not "Liabilities" \
-p "last 30 days" \
--format "Past month: %(display_total)\n" --tail 1 | tail -1
}
if [[ -z $(unbudgetedmonth) ]] ; then
unbudgetedmonth=0.00
else
unbudgetedmonth=$(tr -dc '0-9.' <<< $(unbudgetedmonth))
fi
function unbudgetedyear {
ledger --unbudgeted register not "Liabilities" \
-p "last 365 days" \
--format "Past year: %(display_total)\n" --tail 1 | tail -1
}
if [[ -z $(unbudgetedyear) ]] ; then
unbudgetedyear=0.00
else
unbudgetedyear=$(tr -dc '0-9.' <<< $(unbudgetedyear))
fi
log "Past day: £ %8s\n" "$unbudgetedday"
log "Past week: £ %8s\n" "$unbudgetedweek"
log "Past month: £ %8s\n" "$unbudgetedmonth"
log "Past year: £ %8s\n" "$unbudgetedyear"
printf "\n"
printf "Allowable spending\n"
printf "==================\n"
function allowableday {
echo "scale=2; ($monthlyincomeex/30.4375)-$unbudgetedday" | bc
}
function allowableweek {
echo "scale=2; ($monthlyincomeex/4.348)-$unbudgetedweek" | bc
}
function allowablemonth {
echo "scale=2; $monthlyincomeex-$unbudgetedmonth" | bc
}
function allowableyear {
echo "scale=2; ($monthlyincomeex*12)-$unbudgetedyear" | bc
}
printf "Today: £ %8s\n" "$(allowableday)"
printf "This week: £ %8s\n" "$(allowableweek)"
printf "This month: £ %8s\n" "$(allowablemonth)"
printf "This year: £ %8s\n" "$(allowableyear)"