return to PRS Technologies website
###############################################################################
#
# Module: get_prior_period.sh
# Author: Peter R. Schmidt
# Description: Get the prior Elite accounting period
# for use in shell scripts
#
# Argument 1 = current period
#
# Note: return one period PRIOR to the current period
#
# Exit with RETURN 0 if successful
# Exit with RETURN 1 if NOT successful
#
# Change Log
#
# Date Name Description.................
# 08/15/02 Peter R. Schmidt Start Program
#
###############################################################################
. /elite/custom/run.elite
if [ $# -ne 1 ]; then
echo "usage: get_prior_period.sh [ CURRENT_PERIOD ]"
exit 1
fi
CUR_PER=$1
CUR_MONTH=`echo $CUR_PER | cut -c1,2`
case $CUR_MONTH in
01|02|03|04|05|06|07|08|09|10|11|12) break;;
*) echo "The period passed is not a valid period: $CUR_PER"
exit 1;;
esac
PEBEDT=`dbaccess son_db -</dev/null | egrep -v "pebedt|^$"
select pebedt from periodt where pe = "$CUR_PER";
EOF
`
if [ $? != 0 ]; then
echo "Error: unable to locate period $CUR_PER in the database"
exit 1
fi
#echo "debug: PEBEDT=$PEBEDT"
PRIOR_PEENDT=`dbaccess son_db -</dev/null | egrep -v "date1|^$"
create temp table temp1 (date1 date);
insert into temp1 values ("$PEBEDT");
select date1-1 date1 from temp1;
drop table temp1;
EOF
`
if [ $? != 0 ]; then
echo "Error: unable to locate period PRIOR to $CUR_PER in the database"
exit 1
fi
#echo "debug: PRIOR_PEENDT=$PRIOR_PEENDT"
PRIOR_PER=`dbaccess son_db -</dev/null | egrep -v "pe|^$"
select pe from periodt where peendt = "$PRIOR_PEENDT";
EOF
`
if [ $? != 0 ]; then
echo "Error: unable to locate period for date ending $PRIOR_PEENDT in the database"
exit 1
fi
#echo "Debug: Prior Period is: $PRIOR_PER"
echo "$PRIOR_PER"
################################################################################