#!/bin/bash
#                      /usr/local/bin/payment
# http://crystalfaeries.net/posix/bin/payment
# celeste crystalfaery 2016-06-14 01:30:48+00:00

#	Log a 'payment' from someone
#	First argument is their name (no spaces allowed)
#	Second argument is the amount tendered in FRNs.
#	(we should also handle amounts in minutes)

# user selected parameters: 
directory="/home/celeste/documents/ministry/"	# where do we keep client records?
min_per_oz="15"					# minutes of consultation per Oz. of Ag.
min_price="$(cat ~/.min_price.txt)"		# minimum 'price of silver' in U.$.F.R.N. upon which to peg my U.$.F.R.N. rate.
silver_file=/usr/local/share/ag/kitco.txt		# where does silverd store the KitCo Silver Price?

# the calculation code:
PERSON="$(echo ${1} | sed 's/\.statement\.txt$//g')"
price="`cat $silver_file`"
if [[ "$(echo $price | sed 's/\.//')" -lt "$(echo $min_price | sed 's/\.//')" ]]
then
	max_price=$min_price
else
	max_price=$price
fi
rate=$(echo "scale=2; $max_price/$min_per_oz" | bc -l)
nowstring="`now | sed 's/ /./ ; s/:/-/ ; s/:/-/ ; s/:/-/'`"
# touch			      $directory/$nowstring.${PERSON}.payment.txt
# echo 'Kitco New York Ag. (Silver) Bid Price in U.$.F.R.N.s / Oz.: '"$price" | tee -a $directory/$nowstring.${PERSON}.payment.txt
# echo 'celeste crystalfaery consultation rate in U.$.F.R.N.s / minute:  '"$rate" | tee -a $directory/$nowstring.${PERSON}.payment.txt
# echo ""			| tee -a $directory/$nowstring.${PERSON}.payment.txt
# echo "`now` Payment"		| tee -a $directory/$nowstring.${PERSON}.payment.txt
# echo ""			| tee -a $directory/$nowstring.${PERSON}.payment.txt
# echo "$2"			| tee -a $directory/$nowstring.${PERSON}.payment.txt
echo "`now` Payment:	-$2"	| tee -a $directory/$nowstring.${PERSON}.payment.txt
