forked from christianhujer/expensereport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpenseReport.sh
executable file
·39 lines (30 loc) · 1.01 KB
/
ExpenseReport.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
#!/bin/zsh
function printReport() {
total=0
meals=0
echo "Expenses: $(date)"
type=1
amount=2
while read -A expense ; do
if [ "${expense[$type]}" = "DINNER" ] || [ "${expense[$type]}" = "BREAKFAST" ] ; then
meals=$(( ${meals} + ${expense[$amount]} ))
fi
case "${expense[$type]}" in
"DINNER") expenseName="Dinner" ;;
"BREAKFAST") expenseName="Breakfast" ;;
"CAR_RENTAL") expenseName="Car Rental" ;;
esac
mealOverExpensesMarker=$(if [ "${expense[$type]}" = "DINNER" ] && [ "${expense[$amount]}" -gt 5000 ] || [ "${expense[$type]}" = "BREAKFAST" ] && [ "${expense[$amount]}" -gt 1000 ] ; then echo "X" ; else echo " " ; fi)
echo -e "$expenseName\t${expense[$amount]}\t$mealOverExpensesMarker"
total=$(( ${total} + ${expense[$amount]} ))
done
echo "Meal expenses: $meals"
echo "Total expenses: $total"
}
printReport <<EXPENSES
DINNER 5000
DINNER 5001
BREAKFAST 1000
BREAKFAST 1001
CAR_RENTAL 4
EXPENSES