#!/bin/bash
#                      /usr/local/bin/statements
# http://crystalfaeries.net/posix/bin/statements
# celeste:crystalfaery 2016-02-05 19:18:08+00:00

# where are general clockins and payments stored?
directory="/home/celeste/documents/ministry/"
pushd $directory/	|| exit 1

# review the records of each client
for client in `ls | sed 's/\.clockin\.txt//g;s/\.payment\.txt//g;s/.statement\.txt//g;s/^.*\.//g' | sort -u` ;do
	comment=$client.statement.txt	# this filename does not contain an embedded date, we only ever append to it
					# a given transaction may appear multiple times in the statment
	echo		 ======= Statement for $client =======
	cat													 		 $comment
	echo		 ======= Statement for $client preceeding `/usr/local/bin/now` =======	 | tee -a	 $comment
	for	transaction	 in `ls *$client.{clockin,payment}.txt` ;do
		echo	 ======= Transaction for $client at $transaction =======				 | tee -a	 $comment
		cat	 $transaction										 | tee -a	 $comment
	done
	echo		 ======= Comment for $client at `/usr/local/bin/now` =======				 | tee -a	 $comment
	echo "" >> $comment
	echo		 ======= Statement End for $client at `/usr/local/bin/now` =======			 | tee -a	 $comment
	vi	 $comment
done
now >		statements.txt
for f in      *.statement.txt
do
	echo "$(echo $f | sed 's/\.statement\.txt//'):	`tail -n -2 $f | head -n 1`" | tee -a statements.txt
done


syntax highlighted by Code2HTML, v. 0.9.1