Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Example from
# Pass the invoice # as the first and only argument
[ -n "$1" ] || { echo 'Specify an invoice number.' ; exit -1 ; }
# Load config file to override defaults
CUSTOMIZATION_FILE="~/.`basename \"${0}\" .sh`.rc"
# Project directory, each file is named for a project and contains the customer name/address
: ${PROJSRC:="./Projects"}
# Where to put the final pdf
: ${PDFDST:="."}
# Ledger path
: ${LEDGER_CMD:="./ledger"}
# Temporary storage
: ${TMPDIR:=`mktemp -d /tmp/${0}.XXXXXX`}
# Setup the latex document properties
\fancyhead[L]{\Huge \bf Invoice\# $1}
# Company logo here
\bf \large Bob Smith Smithing Inc. \\\\ \rm
123 Boudine Blvd \\\\
Somewhere, AK 12344 \\\\
800-555-1212 \\\\
# Any notes at the end go here, raw latex
: ${LATEX_NOTES:=""}
# Footer to close the doc
: ${LATEX_FOOTER:="\end{document}"}
# Grab the invoice description from the payee matching the invoice number that haven't cleared
DESC=`"${LEDGER_CMD}" -U -l "$1" -F "%P" reg ^AR:PendingInvoices`
PROJ=`"${LEDGER_CMD}" -U -l "$1" -r -F "%a" reg ^AR:PendingInvoices | sed 's/^AR:Projects://'`
# This file is a latex fragment, very simple, just end each line with \\
[ -f "${PROJSRC}/${PROJ}" ] || { echo "Need customer bill to data in ${PROJSRC}/${PROJ}" ; exit -1 ; }
# Grab all non-cleared fee items from hours for the project
LATEX_FEES=`"${LEDGER_CMD}" -F 'Fee{%D%|%P}{%T}{%t}\n' -VEU -t '(v/(v/a))' -T '(v/a)' -d 'a>=0' reg ^AR:Projects:${PROJ} | sed 's/^Fee/\\\\Fee/g'`
# Now output to the tex file
cat <<EOF > "${TMPDIR}/${1}.tex"
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\large \bf Bill To: \\ \rm \bigskip
`cat "${PROJSRC}/${PROJ}"`
\bigskip \bigskip \bigskip
\ProjectTitle{${PROJ}: ${DESC} }
% each line of the project ledger item, by payee. get hours &
% values, divide to find rate
pdflatex -output-directory "${TMPDIR}" "${TMPDIR}/${1}.tex"
pdflatex -output-directory "${TMPDIR}" "${TMPDIR}/${1}.tex"
mv -b "${TMPDIR}/${1}.pdf" "${PDFDST}/${1}.pdf"
# export DEBUG=TRUE to skip this step
[ -z "${DEBUG}" ] && rm -rf "${TMPDIR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.