From 4d1342782d64d5a0566ecea92ae50fa0aa95a92b Mon Sep 17 00:00:00 2001 From: Rushmore75 Date: Thu, 22 Jan 2026 16:59:07 -0700 Subject: [PATCH] testing --- end.mm | 11 +++++++++++ gen.sh | 49 +++++++++++++++++++++++++++++++++++++------------ hours.tbl | 14 ++++++++++++++ item.tbl | 15 +++++++++++++++ start.mm | 22 ++++++++++++++++++++++ 5 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 end.mm create mode 100644 hours.tbl create mode 100644 item.tbl create mode 100644 start.mm diff --git a/end.mm b/end.mm new file mode 100644 index 0000000..be12111 --- /dev/null +++ b/end.mm @@ -0,0 +1,11 @@ +.1C 1 +.DS C +.PP +.B +Total: $${TOTAL} +.R +.DE +.PP +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! + diff --git a/gen.sh b/gen.sh index dbb96e5..4b505c8 100755 --- a/gen.sh +++ b/gen.sh @@ -4,7 +4,7 @@ RATE=50 short_help() { - echo "$0 [output file]" + echo "$0 [output file]" echo "--help for help" } long_help() { @@ -30,12 +30,20 @@ else CSV=$1 fi -COMPANY="" +CSV2="" if [[ -z $2 ]]; then short_help exit else - COMPANY=$2 + CSV2=$2 +fi + +COMPANY="" +if [[ -z $3 ]]; then + short_help + exit +else + COMPANY=$3 fi # Increment a global invoice number @@ -50,21 +58,38 @@ echo $INV_NUM > $INV_FILE # 3rd argument is output location (optional) OUTPUT="invoice-${INV_NUM}.pdf" -if [[ ! -z $3 ]]; then - OUTPUT=$3 +if [[ ! -z $4 ]]; then + OUTPUT=$4 fi # Parse the CSV into: Label;Hrs;Cost -TMP=$(mktemp) -cat $CSV | RATE=$RATE awk -F, '{ sum += $2 }; { print $1 ";" $2 ";" $2 * ENVIRON["RATE"] } END { print "Total" ";" sum ";" sum * ENVIRON["RATE"]}' > $TMP +HRS_TMP=$(mktemp) +cat $CSV | RATE=$RATE awk -F, '{ sum += $2 }; { print $1 ";" $2 ";" $2 * ENVIRON["RATE"] } END { print "Sub-Total" ";" sum ";" sum * ENVIRON["RATE"]}' > $HRS_TMP + +CONSUME_TMP=$(mktemp) +cat $CSV2 | awk -F, '{ sum += $2 }; { print $1 ";" $2 } END { print "Sub-Total" ";" sum }' > $CONSUME_TMP + +HRS_COST=$(cat $HRS_TMP | tail -n 1 | awk -F";" '{ print $3 }') +CONSUME_COST=$(cat $CONSUME_TMP | tail -n 1 | awk -F";" '{ print $2 }') + +TOTAL_COST=$(A=$HRS_COST B=$CONSUME_COST awk 'BEGIN{ print ENVIRON["A"] + ENVIRON["B"] }') # TOTAL = Last line # BODY = Everything but the last line -TOTAL=$(cat $TMP | tail -n 1) \ - BODY=$(cat $TMP | head -n -1) \ - COMPANY=$COMPANY \ +COMPANY=$COMPANY \ INVOICE_NUM=$INV_NUM \ + envsubst < start.mm > 1.tmp +HRS_TOTAL=$(cat $HRS_TMP | tail -n 1) \ + HRS_BODY=$(cat $HRS_TMP | head -n -1) \ + envsubst < hours.tbl > 2.tmp +ITEM_TOTAL=$(cat $CONSUME_TMP | tail -n 1) \ + ITEM_BODY=$(cat $CONSUME_TMP | head -n -1) \ + envsubst < item.tbl > 3.tmp +TOTAL=$TOTAL_COST \ RATE=$RATE \ - envsubst < template.mm | groff -t -mm -T pdf > $OUTPUT + envsubst < end.mm > 4.tmp -rm $TMP +cat 1.tmp 2.tmp 3.tmp 4.tmp | groff -t -mm -T pdf > $OUTPUT + +rm $HRS_TMP +rm $CONSUME_TMP diff --git a/hours.tbl b/hours.tbl new file mode 100644 index 0000000..c389e88 --- /dev/null +++ b/hours.tbl @@ -0,0 +1,14 @@ +.TS +nospaces center tab(;); +CbSS +CiCi|Ci +RN|N. +Work Performed +Job;Hours;Cost +_ +${HRS_BODY} +_ +.T& +RiNi|Ni. +${HRS_TOTAL} +.TE diff --git a/item.tbl b/item.tbl new file mode 100644 index 0000000..1359c5a --- /dev/null +++ b/item.tbl @@ -0,0 +1,15 @@ +.NCOL +.TS +nospaces center tab(;); +CbS +Ci|Ci +R|N. +Other +Item;Cost +_ +${ITEM_BODY} +_ +.T& +Ri|Ni. +${ITEM_TOTAL} +.TE diff --git a/start.mm b/start.mm new file mode 100644 index 0000000..f94a073 --- /dev/null +++ b/start.mm @@ -0,0 +1,22 @@ +\# Make headers bold +.ds HF 3 3 +\# Make lvl 1 headers 20pt, lvl 2 18pt +.ds HP 20 18 +.S 12 +\# Disable page header +.PH '''' +\# Centered block +.DS C +.HU "${COMPANY}'s Bill" +.DE +\# Contact info +.TS +nospaces center tab(;); +LR. +Cooies Unlimited;(123) 456-7890 +123 Sesame St.;cookie@example.com +Dumpster 1;\*[DT] +Nicevile FL;Invoice ID #${INVOICE_NUM} +.TE + +.2C