Files
net-tools/verschicke-rechnung.sh

89 lines
2.6 KiB
Bash
Executable File

#/bin/bash
MYDIR=$(dirname $0)
MUTTRC="${MYDIR}/muttrc"
SRCDIR=$1
FROM="kunden@maketank.net"
TMP=/tmp
send_mail () {
INF=$(pdfinfo $TMP/$FILE 2>&1)
ISA=$(echo "${INF}"|awk '/Title:/ {print $2}')
if [ "${ISA}" == "Mahnung" ]; then
MAHNNUM=$(echo $FILE |sed -e 's/Mahnung-\(.\)-.*pdf/\1/')
SUBJPREFIX="${MAHNNUM}. ${ISA}"
else
MAHNNUM=""
SUBJPREFIX="${ISA}"
fi
META=$(echo "${INF}"|awk -F ' ' '/Keywords:/ {print $3}')
NAME=$(echo "${META}"|sed -e 's;.*<Name:\(.*\)><Zusatz.*$;\1;')
ZUSATZ=$(echo "${META}"|sed -e 's;.*<Zusatz:\(.*\)><Stra.*$;\1;')
NUMMER=$(echo "${META}"|sed -e 's;.*<Nummer:\(.*\)><Erstellt.*$;\1;')
ERSTELLT=$(echo "${META}"|sed -e 's;.*<Erstellt:\(.*\)><Name.*$;\1;')
BETRAG=$(cat ${TMP}/${FILE}.txt |grep Eur|tail -1)
KUNDE=$(cat ${TMP}/${FILE}.txt |awk '/Kunde:/ {print $2}')
TO=$(echo "${META}"|sed -e 's;.*<Mail:\(.*\)><WWW.*$;\1;')
## Build the mail now
SUBJECT="[it.maketank.net] ${SUBJPREFIX} ${NUMMER}"
M=$TMP/$FILE.mailbody
echo "Hallo ${NAME}," >$M
echo "" >>$M
echo "anbei eine aktuelle ${SUBJPREFIX}." >>$M
echo "" >>$M
echo "Rechnungsinformationen:" >>$M
echo "" >>$M
echo " Datum: ${ERSTELLT}" >>$M
echo " Nummer: ${NUMMER}" >>$M
echo " Kunde: ${KUNDE}" >>$M
echo " Betrag: ${BETRAG}" >>$M
echo "" >>$M
echo "" >>$M
echo "Bitte ueberweisen Sie den Ausstehenden Betrag sobald">>$M
echo "wie moeglich unter Angabe ihrer Kundennummer auf folgendes Konto." >>$M
echo "" >>$M
echo " Bank: comdirect" >>$M
echo " IBAN: DE50 2004 1155 0237 5400 00" >>$M
echo " BIC: COBADEHD055" >>$M
echo "" >>$M
echo "" >>$M
echo "Vielen Dank und herzliche Gruesze," >>$M
#TO='snurfl@zoide.net'
#echo "==> Sending Mail to: ${TO} "
#echo " Subject: ${SUBJECT}"
#cat $M
#echo -n "Should this be sent [y]/n? "
#read -n 1 REPL
#if [ "${REPL}" == "n" ]; then
# echo " Not sending Mail."
#else
mutt -F "${MUTTRC}" -s "${SUBJECT}" -a $TMP/$FILE -i ${M} -- ${TO}
#fi
#unset REPL
}
archive () {
Y=$(date +%Y)
[[ -d ${SRCDIR}/${Y} ]] || mkdir -p ${SRCDIR}/${Y}
mv ${SRCDIR}/${FILE} ${SRCDIR}/${Y}
rm -v /tmp/${FILE}*
}
for PDF in $(ls ${SRCDIR}/*.pdf); do
export FILE=$(basename $PDF)
echo -n "Processing: ${FILE}"
cp $PDF $TMP/
echo -n " [JPEG"
pdfimages -j $TMP/$FILE $TMP/$FILE
echo -n ",OCR"
cuneiform -f text -l ger -o $TMP/$FILE.txt $TMP/$FILE-000.jpg >/dev/null
echo ",MAIL]"
send_mail
archive
unset FILE
done