:	awkWARD Accounting Made Easy
:	[C] Copyright PC Research, Inc. 1985
:
: pracct book account [YR=yy]:
:	print 'account' transactions for 'book' [for year yy].
: FILE FORMAT
: CLEAR	DATE	CHECK	AMOUNT	ACCOUNT	COMMENT
if [ "$#" = 0 ]
then
	echo "usage:	pracct book account [YR=yy]"
	exit 1;
fi
BOOK=$1; shift
if [ "$1" = "" ]
then
	echo "usage:	pracct book account [YR=yy]"
	echo "	accounts for $BOOK:"
	awk  '
	{
		if ($1 == "#")
			continue;
		account[$5] = 1
	}
	END {
		for (acctnum in account)
			printf "\t\t%s\n", acctnum 
	}' $BOOK
	exit 1;
fi
ACCT=$1; shift
OPTS="$*"
awk '
{
	if ($1=="H") { h = ACCT " Transactions for " substr($0,3); continue; }
	if ($1=="#" || $5!=ACCT) continue;
	yr = split($2,date,"/"); if (YR!=""  && YR!=date[yr]) continue;
	l = substr($0,index($0,$6));
	if ((ln%58)==0)
	{
		if (ln!=0) printf "\n\n"
		printf "\n\n%s, Page %d\n\n", h, ln/58+1
		printf "C CHEK   DATE   %-35s  PAYMENT  DEPOSIT  BALANCE\n",\
			"DESCRIPTION"
		printf "- ---- -------- %-35s  -------  -------  -------\n",\
			"-----------------------------------"
	}
	if ($5=="+") 
	{
		cur+=$4;
		printf "%s %4s %8s %-35s %8s %8.2f %8.2f\n",$1,$3,$2,l,"",$4,cur
	}
	else
	{
		cur-=$4;
		printf "%s %4s %8s %-35s %8.2f %8s %8.2f\n",$1,$3,$2,l,$4,"",cur
	}
	++ln
}' $OPTS "ACCT=$ACCT" $BOOK
