#!/bin/bash
# Copyright 2010-2012 Chad Lemmen http://www.lemmen.com
#
# Set the Informix environment variables
. /etc/profile.d/informix.sh


tmp=/usr/tmp
vendor=$2
bin=`dirname $0`

# Convert HT Hackney price change CSV file so we can load it into the database.
# Delete from first line up to and including line beginning with 'Customer'. 
# Delete lines beginning with ','. 
# Delete lines beginning with '*'. 
# Remove carriage return at end of lines. 
# Delete lines with only spaces.
# We are using quotes around arg1 variable in case the filename has spaces.
cat "$1" | sed -e '1,/^Customer/d' -e '/^,/d' -e '/^*/d' -e 's/\r$//' -e '/^ *$/d' >$tmp/hackney.csv


# Pass filename and vendor number to 4GL program, which will cause it to
# run non-interactive and import the price changes into the database.
$bin/rsfpbook.4ge $tmp/hackney.csv $vendor

# Keep copy of orginal file
cp "$1" $tmp/hackney_orig.csv

# Delete email attachment filename saved by metamail
rm -f "$1"

# Print a price change notice at the stores
$bin/rsrbprice.4ge $vendor `date +%D`

