#!/bin/sh #///* #//************************************************************************* #//** * #//** Copyright (C) 2002-2013 Trans-Mit Pty. Ltd. Melbourne Australia * #//** This software may not be loaned, resold, changed or copied * #//** in any way without the express written permission of author * #//** and Trans-Mit Pty. Ltd., Australia. * #//** * #//************************************************************************* #//** #//** $Header: $ #//** $Author: $ #//** $Date: $ #//** $Locker: $ #//** #//************************************************************************* #//*/ EXBILLPERIOD="$1" SHIPTO="$2" INVOICENO="$3" ofile="$4" invpdfdir="$5" logfile="/tmp/getinvpdf.$$" rm -f "$logfile" # it is assumed that getallinvpdf has already been called # to get all the inv pdf files into the $invpdfdir # with the following file format... # INV003489_MTS_DEPARTMENT_20100608_133341.pdf # INV003509_DCC_DEPARTMENT_20100609_170908.pdf #dttag=`date "+%Y-%m-%d"` #------------------------------------------------ ## Testing #EXBILLPERIOD="December 2012" #SHIPTO="KDS" #INVOICENO="INV022278" ##invpdfdir="invpdf" #------------------------------------------------ if [ "$ofile" = "" ]; then ofile="invoice_$YYYYMM_$SHIPTO_$INVOICENO.pdf"; fi rm -f "$ofile" echo "$0:" >>"$logfile" echo " EXBILLPERIOD=$EXBILLPERIOD" >>"$logfile" echo " SHIPTO=$SHIPTO" >>"$logfile" echo " INVOICENO=$INVOICENO" >>"$logfile" echo " ofile=[$ofile]" >>"$logfile" # convert exbillperiod to YYYYMM YYYYMM=`awk -v "EXBILLPERIOD=$EXBILLPERIOD" -v "sep=" ' BEGIN { split(EXBILLPERIOD, exbp_arr," ") billMONTH = exbp_arr[1] montharr["January"] = 1 montharr["February"] = 2 montharr["March"] = 3 montharr["April"] = 4 montharr["May"] = 5 montharr["June"] = 6 montharr["July"] = 7 montharr["August"] = 8 montharr["September"] = 9 montharr["October"] = 10 montharr["November"] = 11 montharr["December"] = 12 mm = 0 + montharr[billMONTH] yyyy = 0 + exbp_arr[2] if ( sep != "" ) sepchar = substr(sep,1,1) yyyymm = sprintf("%04d%s%02d", yyyy, sepchar, mm) print yyyymm exit }'` echo "EXBILLPERIOD=[$EXBILLPERIOD] - YYYYMM=[$YYYYMM]" >>"$logfile" YYYY=`echo "$YYYYMM" | cut -c1-4` curYYYY=`date "+%Y"` BILLPERIOD=`echo $EXBILLPERIOD | cut -c1-3 `"_$YYYY" echo "BILLPERIOD=[$BILLPERIOD]" if [ "$invpdfdir" = "" ]; then invpdfdir="indata/$BILLPERIOD/invpdf"; fi echo " invpdfdir=[$invpdfdir]" >>"$logfile" #---------------------------------------------------------- lscmd="ls $invpdfdir/${INVOICENO}_${SHIPTO}_*.pdf" result=`$lscmd 2>&1` echo "result=[$result]" >>"$logfile" fname=`echo "$result" | awk -F' ' ' { fname = $1 print fname exit 0 } '` echo "fname=[$fname]" >>"$logfile" if [ "$fname" != "" ]; then # get pdf file cp $fname $ofile 2>>"$logfile" fi # create pdf with error message if [ ! -f "$ofile" ]; then echo "The PDF file for invoiceno $INVOICENO ($EXBILLPERIOD) was not found" >>"$logfile" cat "$logfile" | text2gif | gif2ps -i -x | ps2pdf - "$ofile" fi cat "$logfile" cat "$logfile" >>getinvpdf.log rm -f "$logfile" exit 0