-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompta-ajouter
executable file
·151 lines (120 loc) · 3.27 KB
/
compta-ajouter
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
usage () {
cat <<'EOF'
┌─┐┌─┐┌┬┐┌─┐┌┬┐┌─┐ ┌─┐ ┬┌─┐┬ ┬┌┬┐┌─┐┬─┐
│ │ ││││├─┘ │ ├─┤ ── ├─┤ ││ ││ │ │ ├┤ ├┬┘ v1.3
└─┘└─┘┴ ┴┴ ┴ ┴ ┴ ┴ ┴└┘└─┘└─┘ ┴ └─┘┴└─────────
Usage: compta-ajouter [OPTION]...
-a ACCOUNT account name - Optional if transaction is not checked
(Use quotes for multi words name ex: 'Monsieur Morbier')
• -c CATEGORY one of the following category: don|infra|adhesion|autre
-d DATE date in YYYY-MM-DD format - Optional: if not set, today is used
• -i INFO info
-m MONTANT montant
-x check - Optional
-y do not ask for confirmation
-h print this help
Options with '•' are mandatory.
Source code: <https://github.com/club-1/compta>
Club1 doc: <https://club1.fr/docs/fr/outils/compta.html>
EOF
}
if test ! -w /var/compta/transactions.tsv
then
exit 2
fi
while getopts 'a:c:d:i:m:xyh' opt
do
case $opt in
a)
account="$OPTARG"
;;
c)
if [ "$OPTARG" = 'don' ] || [ "$OPTARG" = 'infra' ] || [ "$OPTARG" = 'adhesion' ] || [ "$OPTARG" = 'autre' ]
then
category="$OPTARG"
else
echo "invalid category '${OPTARG}'"
echo "valid categories are: don|infra|adhesion|autre"
exit 1
fi
;;
d)
if [[ $OPTARG =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] && date -d "$OPTARG" "+%Y-%m-%d" >/dev/null 2>&1
then
date="$OPTARG"
else
echo "invalid date argument '${OPTARG}'"
exit 1
fi
;;
i)
info="$OPTARG"
;;
m)
if [[ $OPTARG =~ ^[-+][0-9]+$ ]]
then
montant="$OPTARG"
else
echo "invalid montant argument '${OPTARG}'"
exit 1
fi
;;
x)
check='x'
;;
y)
yes='yes'
;;
h)
usage
exit
;;
?)
usage
exit 1
;;
esac
done
# shift "$(($OPTIND -1))"
if test -z "$category"
then
echo 'category have to be set'
exit 1
fi
if test -z "$info"
then
echo 'info have to be set'
exit 1
fi
if test -n "$check" && test -z "$account"
then
echo 'account have to be set if transaction is checked'
exit 1
fi
lastId=$(cut -f 1 /var/compta/transactions.tsv | tail -n 1)
id=$(($lastId + 1))
if test -z "$date"
then
date=$(date +%Y-%m-%d)
fi
trans="$id $date $montant $account $check $category $info"
if test -n "$yes"
then
echo "$trans" >> /var/compta/transactions.tsv
exit
fi
echo "$trans" | column -N id,date,montant,nom,effectué,catégorie,intitulé -ts $'\t'
echo '----------------------------------------------------'
echo "✒️ Voulez vous ajouter cette transaction ? (oui/non)"
read consent
case $consent in
yes | oui | o | y)
echo "$trans" >> /var/compta/transactions.tsv
exit $?
;;
*)
effectue=''
exit 130
;;
esac