Quote:
Originally Posted by xiaojesus
Hi all i got a script up but i cant add up the summary report.. keep having synax error . mind helping me to take a look and tell me what went wrong..
i know is a bit long but i hope someone can hep me with it. thanks
the error message come up when i try to run the sumary report..
|
What error do you get?
Is it: sort: invalid option -- 4
Quote:
i guess 1 of the problem is the system date.thing.
the problem is about point of sales.
i am trying to the add up all the daily sales and then have a grand total of all the sales of all days.
below is the code.
Code:
# Global variables
POS=~/.Point_Of_Sales
POS=POS.txt
|
You are assigning two different values to POS; only the last assignment endures; the first might as well never have been made.
Quote:
Code:
export POS
confirm()
{
echo -en "$@"
read ans
ans=`echo $ans | tr '[a-z]' '[A-Z]'`
if [ "$ans" == "Y" ]; then
return 0
else
return 1
fi
}
|
Avoid options to echo; they are non-standard as is ==.
You do not need to call tr; you can check the answer without it:
Code:
confirm()
{
printf "%s " "$*"
read ans
case "$ans" in
[Yy]) true ;;
*) false ;;
esac
}
Quote:
Code:
num_lines()
{
grep -i "$@" $POS|wc -l| awk '{ print $1 }'
}
|
That will fail if there is more than one argument.
There's no need for awk or wc:
Code:
grep -ni "$1" "$POS"
Quote:
Code:
find_lines()
{
# Find lines matching $1
res=-1
if [ ! -z "$1" ]; then
grep -i "$@" $POS
res=$?
fi
return $res
}
|
Code:
find_lines()
{
# Find lines matching $1
if [ -n "$1" ]; then
grep -i "$1" "$POS"
fi
}
Quote:
Code:
...
locate_single_item()
{
echo -en "Item to search for: "
read search
n=`num_lines "$search"`
if [ -z "$n" ]; then
n=0
fi
while [ "${n}" -ne "1" ]; do
#list_items "$search"
echo -en "${n} matches found. Please choose a "
case "$n" in
"0") echo "less" ;;
"*") echo "more" ;;
esac
echo "specific search term (q to return to menu): "
read search
if [ "$search" == "q" ]; then
return 0
fi
n=`num_lines "$search"`
done
return `grep -in $search $POS |cut -d":" -f1`
|
There's no need for cut:
Code:
return `grep -hin $search $POS`
Quote:
Code:
}
...
summary_items()
{
#echo "- - - POS Summary Report - - -"
#echo "---------------------------"
#echo "Date Total POS"
#echo "---------------------------"
print_dtotal
#echo "---------------------------"
#print_gtotal
#echo "---------------------------"
#echo -en "Best Selling Product: "
#print_bestsell
#echo -en "Product with Highest POS: "
#print_phighPOS
#echo -en "Date with Highest POS: "
print_dtotal | sort -f4| while read z
|
Code:
sort: invalid option -- 4
Quote:
Code:
do
echo $z | cut -f4 -d' '
return 0
done
echo
echo -en "Press Enter to continue..."
read
}
...
|
|