-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompta-voir
executable file
·106 lines (82 loc) · 2.91 KB
/
compta-voir
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
#!/bin/bash
usage () {
cat <<'EOF'
┌─┐┌─┐┌┬┐┌─┐┌┬┐┌─┐ ┬ ┬┌─┐┬ ┬─┐
│ │ ││││├─┘ │ ├─┤ ── └┐││ ││ ├┬┘ v1.3
└─┘└─┘┴ ┴┴ ┴ ┴ ┴ └┘└─┘┴ ┴└─────────
Usage: compta-voir [OPTION]... [SEARCH]
-a ACCOUNT filter using given account name
(Use quotes for multi words name ex: 'Monsieur Morbier')
-b Output the balance only
-c CATEGORY filter using one of the following category: don|infra|adhesion|autre
-x filter checked
-u filter unchecked
-t output TSV without headers
-h print this help
SEARCH will look for matches into 'intitulé' column.
Git repo: <https://github.com/club-1/compta>
Club1 doc: <https://club1.fr/docs/fr/outils/compta.html>
EOF
}
output='pretty'
data=$(cat /var/compta/transactions.tsv)
while getopts 'a:bc:tuxh' opt
do
case $opt in
a)
name="$OPTARG"
data=$(echo "$data" | awk -F $'\t' -v name="$name" '$4 ~ name')
;;
b)
output='balance'
;;
c)
if [ "$OPTARG" = 'don' ] || [ "$OPTARG" = 'infra' ] || [ "$OPTARG" = 'adhesion' ] || [ "$OPTARG" = 'autre' ]
then
category="$OPTARG"
data=$(echo "$data" | awk -F $'\t' -v category="$category" '$6==category')
else
echo "invalid category '${OPTARG}'"
echo "valid categories are: don|infra|adhesion|autre"
exit 1
fi
;;
t)
output='tsv'
;;
u)
data=$(echo "$data" | awk -F $'\t' '$5==""')
;;
x)
data=$(echo "$data" | awk -F $'\t' '$5=="x"')
;;
h)
usage
exit
;;
?)
usage
exit 1
;;
esac
done
shift "$(($OPTIND -1))"
data=$(echo "$data" | awk -F $'\t' -v name="$1" 'tolower($7) ~ tolower(name)')
case $output in
'tsv')
echo "$data"
exit
;;
'balance')
echo "$data" | cut -f 3 | awk '{t=t+$1} END{print t}'
exit
;;
'pretty')
echo "$data" | column -N id,date,montant,compte,effectué,catégorie,intitulé -R montant -ts $'\t'
echo '════════════════════════════════════════════════════════════════════════════════════════════════════'
balance=$(echo "$data" | cut -f 3 | awk '{t=t+$1} END{print t}')
lineCount=$(echo "$data" | wc -l)
echo " balance : $balance € ($lineCount entrées)"
exit
;;
esac