Skip to content

Commit

Permalink
Added income calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
gtlsgamr committed Jun 18, 2023
1 parent 46969d5 commit 0a90bd9
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions tt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ hms(){
}

tcheck_tracking(){
[ ! -s "$masterlist" ] || tail -n1 "$masterlist" | cut -d'|' -f3 | grep -q '^[0-9]\+$' 2> /dev/null
[ ! -s "$masterlist" ] || tail -n1 "$masterlist" | cut -d'|' -f4 | grep -q '^[0-9]\+$' 2> /dev/null
}

tdisp(){
Expand All @@ -38,21 +38,25 @@ tdisp(){

esac
if [ -s "$masterlist" ]; then
printf "%s\n" "----------------------------------------------------------------"
printf "%-25s\t%25s\n" "Tasks ($1)" "Logged hours"
printf "%s\n" "----------------------------------------------------------------"
printf "%s\n" "-----------------------------------------------------------------------------------------"
printf "%-25s\t%25s%25s\n" "Tasks ($1)" "Logged hours" "INCOME"
printf "%s\n" "-----------------------------------------------------------------------------------------"
total=0
while read -r NAME START STOP
total_income=0
while read -r NAME START RATE STOP
do
if [ "$1" = 'all' ] || [ "$(date --date=@"$START" +"$FMTSTRING")" -eq "$(date +"$FMTSTRING")" ]
then
TIME=$(($STOP - $START))
total=$(($total + $TIME))
printf "%-25s\t%25s\n" "$NAME" "$(hms "$TIME")"
TIME=$((STOP - START))
total=$((total + TIME))
TIME_IN_HOURS=$(echo "scale=2; $TIME / 3600" | bc)
income=$(echo "$TIME_IN_HOURS * $RATE" | bc)
total_income=$(echo "scale=2; $total_income + $income" | bc)
printf "%-25s\t%25s%25s\n" "$NAME" "$(hms "$TIME")" "$income"
fi
done < "$masterlist"
printf "%s\n" "----------------------------------------------------------------"
printf "%-25s\t%25s\n" "TOTAL:" "$(hms "$total")"
printf "%s\n" "-----------------------------------------------------------------------------------------"
printf "%-25s\t%25s%25s\n" "TOTAL:" "$(hms "$total")" "$total_income"
else
printf 'No completed tasks to display\n'
fi
Expand Down Expand Up @@ -116,12 +120,16 @@ tstart(){
while [ -z "$task_name" ]; do
printf 'Task name: '
read -r task_name
printf 'Rate($/hour) - only enter the number: '
read -r rate
done
else
task_name="$1"
printf 'Rate($/hour) - only enter the number: '
read -r rate
fi
printf "%s|%s" "$task_name - $(date --iso)" "$STARTTIME" >> "$masterlist"
printf "%s\n" "Started at $(date --date=@"$STARTTIME")"
printf "%s|%s|%s" "$task_name - $(date --iso)" "$STARTTIME" "$rate" >> "$masterlist"
printf "%s\n" "Started at $(date --date=@"$STARTTIME") for $rate per hour"
else
printf "%s\n" "Time is already being tracked ya doofus!"
fi
Expand Down

0 comments on commit 0a90bd9

Please sign in to comment.