added invoice number and rate display
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
*.bak
|
*.bak
|
||||||
*.pdf
|
*.pdf
|
||||||
|
last_invoice_number
|
||||||
|
|||||||
60
gen.sh
60
gen.sh
@@ -1,24 +1,70 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# What you charge an hour
|
||||||
|
RATE=50
|
||||||
|
|
||||||
|
short_help() {
|
||||||
|
echo "$0 <file.csv> <Paying Company Name> [output file]"
|
||||||
|
echo "--help for help"
|
||||||
|
}
|
||||||
|
long_help() {
|
||||||
|
short_help
|
||||||
|
echo ""
|
||||||
|
echo "The csv file should be setup as:"
|
||||||
|
echo ""
|
||||||
|
echo "Job <string>, Hours <number>"
|
||||||
|
echo ""
|
||||||
|
echo "With no empty line at the end."
|
||||||
|
echo "Paying company name is any string"
|
||||||
|
echo "The output argument is optional and will by default output to invoice-<num>.pdf"
|
||||||
|
}
|
||||||
|
|
||||||
|
CSV=""
|
||||||
if [[ -z $1 ]]; then
|
if [[ -z $1 ]]; then
|
||||||
echo First argument must be a csv containing: jobs,hours
|
short_help
|
||||||
exit
|
exit
|
||||||
|
elif [[ $1 = "--help" ]]; then
|
||||||
|
long_help
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
CSV=$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
COMPANY=""
|
||||||
if [[ -z $2 ]]; then
|
if [[ -z $2 ]]; then
|
||||||
echo Second argument must be the name of who you are billing
|
short_help
|
||||||
exit
|
exit
|
||||||
|
else
|
||||||
|
COMPANY=$2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Increment a global invoice number
|
||||||
|
INV_FILE="last_invoice_number"
|
||||||
|
INV_NUM=0
|
||||||
|
if [[ -f $INV_FILE ]]; then
|
||||||
|
INV_NUM=$(expr $(cat $INV_FILE) + 1)
|
||||||
|
else
|
||||||
|
INV_NUM=1
|
||||||
|
fi
|
||||||
|
echo $INV_NUM > $INV_FILE
|
||||||
|
|
||||||
|
# 3rd argument is output location (optional)
|
||||||
|
OUTPUT="invoice-${INV_NUM}.pdf"
|
||||||
|
if [[ ! -z $3 ]]; then
|
||||||
|
OUTPUT=$3
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Parse the CSV into: Label;Hrs;Cost
|
||||||
TMP=$(mktemp)
|
TMP=$(mktemp)
|
||||||
cat $1 | awk -F, '{ sum += $2 }; { print $1 ";" $2 ";" $2 * 50 } END { print "Total" ";" sum ";" sum * 50}' > $TMP
|
cat $CSV | RATE=$RATE awk -F, '{ sum += $2 }; { print $1 ";" $2 ";" $2 * ENVIRON["RATE"] } END { print "Total" ";" sum ";" sum * ENVIRON["RATE"]}' > $TMP
|
||||||
|
|
||||||
# Last line
|
# TOTAL = Last line
|
||||||
# Everything but the last line
|
# BODY = Everything but the last line
|
||||||
TOTAL=$(cat $TMP | tail -n 1) \
|
TOTAL=$(cat $TMP | tail -n 1) \
|
||||||
BODY=$(cat $TMP | head -n -1) \
|
BODY=$(cat $TMP | head -n -1) \
|
||||||
COMPANY=$2 \
|
COMPANY=$COMPANY \
|
||||||
envsubst < template.mm | groff -t -mm -T pdf > output.pdf
|
INVOICE_NUM=$INV_NUM \
|
||||||
|
RATE=$RATE \
|
||||||
|
envsubst < template.mm | groff -t -mm -T pdf > $OUTPUT
|
||||||
|
|
||||||
rm $TMP
|
rm $TMP
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ LR.
|
|||||||
Cooies Unlimited;(123) 456-7890
|
Cooies Unlimited;(123) 456-7890
|
||||||
123 Sesame St.;cookie@example.com
|
123 Sesame St.;cookie@example.com
|
||||||
Dumpster 1;\*[DT]
|
Dumpster 1;\*[DT]
|
||||||
Nicevile FL;Invoice ID #001
|
Nicevile FL;Invoice ID #${INVOICE_NUM}
|
||||||
.TE
|
.TE
|
||||||
|
|
||||||
\# Billing info
|
\# Billing info
|
||||||
@@ -36,6 +36,6 @@ ${TOTAL}
|
|||||||
.TE
|
.TE
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
If you have any questions please reach out at any of the provided contacts above.
|
Hours were charged at $${RATE}/hr. If you have any questions please reach out at any of the provided contacts above.
|
||||||
Thank you for your business!
|
Thank you for your business!
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user