-
Notifications
You must be signed in to change notification settings - Fork 0
/
compta-effectuer
executable file
·116 lines (80 loc) · 2.17 KB
/
compta-effectuer
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
#!/bin/bash
usage () {
cat <<'EOF'
┌─┐┌─┐┌┬┐┌─┐┌┬┐┌─┐ ┌─┐┌─┐┌─┐┌─┐┌─┐┌┬┐┬ ┬┌─┐┬─┐
│ │ ││││├─┘ │ ├─┤ ── ├┤ ├┤ ├┤ ├┤ │ │ │ │├┤ ├┬┘ v1.3
└─┘└─┘┴ ┴┴ ┴ ┴ ┴ └─┘└ └ └─┘└─┘ ┴ └─┘└─┘┴└─────────
Usage: compta-effectuer ID ACCOUNT
ID id of transaction to confirm
ACCOUNT Name of account.
(Use quotes for multi words name ex: 'Monsieur Morbier')
-h print this help
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 'h' opt
do
case $opt in
h)
usage
exit
;;
?)
usage
exit 1
;;
esac
done
shift "$(($OPTIND -1))"
if test -z "$1"
then
echo 'transaction id have to be set'
usage
exit 1
fi
if test -z "$2"
then
echo 'account have to be set'
usage
exit 1
fi
id="$1"
name="$2"
src=$(cat /var/compta/transactions.tsv)
line=$(echo "$src" | awk -F $'\t' -v id="$id" '$1==id')
if test -z "$line"
then
echo "No transaction with id '$id' found"
exit 1
fi
line=$(echo "$line" | awk -F $'\t' '$5=="x"')
if test -n "$line"
then
echo "Transaction $id is already checked"
exit 1
fi
update=$(echo "$src" | awk -F $'\t' -v id="$id" -v name="$name" 'BEGIN { OFS="\t" } { if ($1==id) {$5="x"; $4=name;} print }')
if test "$?" -ne 0 || test -z "$update"
then
echo 'error while trying to edit transactions file'
exit 1
fi
lineUpdate=$(echo "$update" | awk -F $'\t' -v id="$id" '$1==id')
echo "$lineUpdate" | column -N id,date,montant,compte,effectué,catégorie,intitulé -Rmontant -ts $'\t'
echo "✒️ Voulez vous modifier cette transaction ? (oui/non)"
read consent
case $consent in
yes | oui | o | y)
echo "$update" > /var/compta/transactions.tsv
exit $?
;;
*)
echo 'annulation'
exit 130
;;
esac