Compare commits

...

2 Commits

Author SHA1 Message Date
d9fbcc0b98 add $ 2026-02-02 19:24:45 -07:00
6a20f179af make the program installable 2026-01-22 21:17:24 -07:00
5 changed files with 43 additions and 17 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
*.bak *.bak
*.pdf *.pdf
last_invoice_number last_invoice_number
*.csv

View File

@@ -47,7 +47,7 @@ ${ITEM_BODY}
_ _
.T& .T&
Ri|Ni. Ri|Ni.
Sub-Total;${ITEM_TOTAL} Sub-Total;$${ITEM_TOTAL}
.TE .TE
.1C 1 .1C 1
.DS C .DS C

18
Makefile Normal file
View File

@@ -0,0 +1,18 @@
support_files := ${XDG_DATA_HOME}/bill-generator/
config_files:= ${XDG_CONFIG_HOME}/bill-generator/
install_loc := ~/.local/bin/
install:
mkdir -p $(support_files)
mkdir -p $(config_files)
mkdir -p $(install_loc)
cp *.mm $(support_files)
# Copy the ident file but don't overwrite one that is already there.
cp --update=none ident $(config_files)
cp gen.sh $(install_loc)/bill-gen
printf "\nInstalled!\nUpdate your identity at $(config_files)ident\n\n"
remove:
# Remove everything except the config files
rm -r $(support_files)
rm $(install_loc)bill-gen

29
gen.sh
View File

@@ -1,16 +1,14 @@
#!/bin/bash #!/bin/bash
# What you charge an hour DATA_HOME="$XDG_DATA_HOME/bill-generator"
export RATE=50 source "$XDG_CONFIG_HOME/bill-generator/ident"
export COMPANY_NAME="Cookies Unlimited, LLC" # Need to be set to the installed location
export ADDR_LN_1="123 Sesasme St" TEMPLATE_1COL="$DATA_HOME/1col.template.mm"
export ADDR_LN_2="Dumpster 1" TEMPLATE_2COL="$DATA_HOME/2col.template.mm"
export ADDR_LN_3="12345, Nicevile, FL" INV_FILE="$DATA_HOME/last_invoice_number"
export PHONE="(123) 456-7890"
export EMAIL="cookie@exapmle.com"
print_help() { print_help() {
echo "$0 -1 <hrs.csv> <Paying Company Name> [output file]" echo "$(basename $0) -1 <hrs.csv> <Paying Company Name> [output file]"
echo "$0 -2 <hrs.csv> <items.csv> <Paying Company Name> [output file]" echo "$(basename $0) -2 <hrs.csv> <items.csv> <Paying Company Name> [output file]"
echo "" echo ""
echo "CSV files should be <name>,<value>." echo "CSV files should be <name>,<value>."
echo "CSV files should have no empty line at the end." echo "CSV files should have no empty line at the end."
@@ -19,7 +17,6 @@ print_help() {
} }
get_invoice_num() { get_invoice_num() {
# Increment a global invoice number # Increment a global invoice number
INV_FILE="last_invoice_number"
INV_NUM=0 INV_NUM=0
if [[ -f $INV_FILE ]]; then if [[ -f $INV_FILE ]]; then
INV_NUM=$(expr $(cat $INV_FILE) + 1) INV_NUM=$(expr $(cat $INV_FILE) + 1)
@@ -32,7 +29,7 @@ get_invoice_num() {
read_hrs_csv() { read_hrs_csv() {
TMP=$(mktemp) TMP=$(mktemp)
# Parse the CSV into: Label;Hrs;Cost # Parse the CSV into: Label;Hrs;Cost
cat $1 | RATE=$RATE awk -F, '{ sum += $2 }; { print $1 ";" $2 ";" $2 * ENVIRON["RATE"] } END { print sum ";" sum * ENVIRON["RATE"] }' > $TMP cat $1 | RATE=$RATE awk -F, '{ sum += $2 }; { print $1 ";" $2 ";" $2 * ENVIRON["RATE"] } END { print sum "; $" sum * ENVIRON["RATE"] }' > $TMP
echo $TMP echo $TMP
} }
read_items_csv() { read_items_csv() {
@@ -58,19 +55,21 @@ if [[ $1 = "-1" ]]; then
OUTPUT=$4 OUTPUT=$4
fi fi
export COMPANY=$3 export COMPANY=$3
envsubst < 1col.template.mm | groff -t -mm -T pdf > $OUTPUT envsubst < $TEMPLATE_1COL | groff -t -mm -T pdf > $OUTPUT
elif [[ $1 = "-2" ]]; then elif [[ $1 = "-2" ]]; then
if [[ ! -z $5 ]]; then if [[ ! -z $5 ]]; then
OUTPUT=$5 OUTPUT=$5
fi fi
HRS_COST=$(cat $HRS_TMP | tail -n 1 | awk -F";" '{ print $2 }') HRS_COST=$(cat $HRS_TMP | tail -n 1 | sed s/\\$//g | awk -F";" '{ print $2 }')
CONSUME_TMP=$(read_items_csv $3) CONSUME_TMP=$(read_items_csv $3)
CONSUME_COST=$(cat $CONSUME_TMP | tail -n 1 | awk -F";" '{ print $2 }') CONSUME_COST=$(cat $CONSUME_TMP | tail -n 1 | awk -F";" '{ print $2 }')
export ITEM_TOTAL=$(cat $CONSUME_TMP | tail -n 1 ) export ITEM_TOTAL=$(cat $CONSUME_TMP | tail -n 1 )
echo $ITEM_TOTAL
echo $HRS_COST
export ITEM_BODY=$(cat $CONSUME_TMP | head -n -1) export ITEM_BODY=$(cat $CONSUME_TMP | head -n -1)
export TOTAL=$(A=$HRS_COST B=$ITEM_TOTAL awk 'BEGIN{ print ENVIRON["A"] + ENVIRON["B"] }') export TOTAL=$(A=$HRS_COST B=$ITEM_TOTAL awk 'BEGIN{ print ENVIRON["A"] + ENVIRON["B"] }')
export COMPANY=$4 export COMPANY=$4
envsubst < 2col.template.mm | groff -t -mm -T pdf > $OUTPUT envsubst < $TEMPLATE_2COL | groff -t -mm -T pdf > $OUTPUT
else else
echo First arg should be either -1 or -2 echo First arg should be either -1 or -2
fi fi

8
ident Normal file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
export RATE=50
export COMPANY_NAME="Cookies Unlimited, LLC"
export ADDR_LN_1="123 Sesasme St"
export ADDR_LN_2="Dumpster 1"
export ADDR_LN_3="12345, Nicevile, FL"
export PHONE="(123) 456-7890"
export EMAIL="cookie@exapmle.com"