Novell Home

HowTo: Use tput in a shell data entry system - Part 4

Novell Cool Solutions: Feature
By Stomfi

Digg This - Slashdot This

Posted: 21 Sep 2005
 

StomfiLearning to use Linux at Home and Work
Welcome to my ongoing series of HowTo articles designed to help Linux newbies get comfortable with Linux. Before trying any of these HowTos, take a few minutes to study the prerequisites so you can hit the ground running.
--Stomfi

The first two articles in this series showed you how to use the "tput" command to develop a terminal based data entry system.

Part 3 showed the menu and the entry scripts.

This article shows how to create the adjustment scripts, and adds some reporting to the system.

The development design needs to be amended to it to make sure you keep on the right track. Add a new item to the goods menu for reports, with a sub menu for all the different reports you may need. I suggest the following as a start.

Inwards Goods Stock

Finished Goods Delivered

If you are going to track finished goods in stock, you can identify these in the inwards good system with the supplier code equal to say "fg".

In part 3, I showed you the sample script for a radio list which lets you choose one from many. What we have to do is create the selection list, and use the shell to build the radio list dialog script which is then run.

We need two files which are the first and last parts of the dialog script. Here they are. I have placed them in $HOME/GOODS/info.

#! /bin/sh

#dial1
# $Id: radiolist,v 1.7 2003/08/15 19:40:37 tom Exp $

: ${DIALOG=dialog}

tempfile='tempfile 2>/dev/null' || tempfile=/tmp/test$$

trap "rm -f $tempfile" 0 1 2 5 15

$DIALOG --backtitle "Inwards Goods Adjustment" \

--title "Choose item to adjust" --clear \

--radiolist "Press SPACE to toggle an option on/off. \n\n\

Choose item?" 20 61 5 \

I called this file "dial1".

2> $tempfile

retval=$?

choice='cat $tempfile'

case $retval in

   0)

      sh $HOME/GOODS/bin/inadjscrn.sh $choice;;

   1)

      exit;;

   255)

      exit;;

esac

And this file: dial2. The "inadjust" script is next.

#! /bin/sh

#create dialog for inwards good adjustments

GTMP="$HOME/GOODS/tmp"

DLIST="$HOME/GOODS/tmp/dlist.txt"

rm -f $DLIST

DINFO="$HOME/GOODS/info"

#Create a list from data/ingoods.txt

ILIST='cat $HOME/GOODS/data/ingoods.txt|sort|uniq'

#Format list for dialog

for I in $ILIST

do

   echo "$I \"\" off \\" >> $DLIST

done

cat $DINFO/dial1 $DLIST $DINFO/dial2 > $GTMP/dial3

sh $GTMP/dial3

This script sets some variables, deletes the DLIST file as it has to be appended to in the script, so we don't want anything in it when we start.

ILIST is a sorted unique list of the entries in "ingoods.txt". If you look at the man page for sort, you can see how to sort on a field. You might like to sort yours on the docket number. The for loop adds two double quotes, "off", and a back slash to each line. The "off" sets all the selections to off.

Dial1, the DLIST, and dial2 are concatenated into dial3 in the temp folder, which is then run as a script.

You can see from the dial2 script, that whichever record you select and activate, runs a new script with the selected record as its argument.

Here is the result when dial3 is run:

This is the script that is run after selecting OK. Apart from using an existing record, it is very similar to the inwards entry script.

#! /bin/sh

#inadjscrn.sh

# $Id: form1,v 1.6 2004/03/13 16:06:51 tom Exp $

: ${DIALOG=dialog}

#Fill variables with selected record

#Set todays date for new record

NDATE='date +%d/%m/%y'

#Get the record via DOCNUM to strip quotes from $1

DOCNUM='echo "$1"|cut -d"#" -f2'

ORECORD='grep "#$DOCNUM#" $HOME/GOODS/data/ingoods.txt'

#Assign variables from ORECORD

EDATE='echo $ORECORD | cut -d"#" -f1'

DOCNUM='echo $ORECORD | cut -d"#" -f2'

SUPPCODE='echo $ORECORD | cut -d"#" -f3'

CARRIER='echo $ORECORD | cut -d"#" -f4'

GOODSCODE='echo $ORECORD | cut -d"#" -f5'

GOODSNAME='echo $ORECORD | cut -d"#" -f6'

GQUANT='echo $ORECORD | cut -d"#" -f7'

GMEAS='echo $ORECORD | cut -d"#" -f8'

RECDBY='echo $ORECORD | cut -d"#" -f9'

#

backtitle="Inwards Goods Adjustment Form"

returncode=0

while test $returncode != 1 && test $returncode != 250

do

   exec 3>&1

   value="'$DIALOG --ok-label "Submit" \

   --backtitle "$backtitle" \

   --form "Adjust values in all necessary fields" \

   20 50 0 \

   "DATE:" 1 1 "$NDATE" 1 10 10 0 \

   "DOCNUM:" 2 1 "$DOCNUM" 2 10 8 0 \

   "SUPPCODE:" 3 1 "$SUPPCODE" 3 10 8 0 \

   "CARRIER:" 4 1 "$CARRIER" 4 10 30 0 \

   "GOODSCODE:" 5 1 "$GOODSCODE" 5 10 8 0 \

   "GOODSNAME:" 6 1 "$GOODSNAME" 6 10 40 0 \

   "GQUANT:" 7 1 "$GQUANT" 7 10 6 0 \

   "GMEAS:" 8 1 "$GMEAS" 8 10 10 0 \

   "RECDBY:" 9 1 "$RECDBY" 9 10 20 0 \

   2>&1 1>&3'"

   returncode=$?

   exec 3>&-

   show='echo "$value" |sed -e 's/^/ /''

   case $returncode in

      1) "$DIALOG" \

         --clear \

         --backtitle "$backtitle" \

         --yesno "Really quit?" 10 30

         case $? in

            0) break ;;

            1) returncode=99 ;;

         esac ;;

      0) $DIALOG --title "POST THIS RECORD ENTRY?" \

         --yesno "$show" 15 40

         case $? in

            0) #Create the record string from $value, deleting the last #

               NRECORD='echo "$value"|awk 'BEGIN{ORS="#"}{print $0}'|sed -e 's/#$//''

               #move old record to inhgoods.txt

               echo $ORECORD >> $HOME/GOODS/data/inhgoods.txt

               #remove old record from ingoods.txt

               grep -v "$ORECORD" $HOME/GOODS/data/ingoods.txt > $HOME/GOODS/tmp/tingoods.txt

               mv -f $HOME/GOODS/tmp/tingoods.txt $HOME/GOODS/data/ingoods.txt

               #write the adjusted record

               echo $NRECORD >> $HOME/GOODS/data/ingoods.txt

               $HOME/GOODS/bin/inwards ;;

            1) $HOME/GOODS/bin/inwards ;;

            255) $HOME/GOODS/bin/inwards ;;

         esac;;

      *) $HOME/GOODS/bin/inwards ;;

   esac

done

$HOME/GOODS/bin/inwards

I used grep to re find the record as dialog echoed the record with some unneeded quotes. I probably could have stripped them with sed, but either way gets the same result. I didn't check this time to see that all the fields were filled, but you may want to include this just in case the operator tries to delete a field.

The out wards goods is nearly the same except the source and target files. This is pretty basic stuff, and you may like to pretty things up. You can read the dialog documentation to see how to do this.

This is the modified design which includes a reporting menu.

The goods menu will have to be modified to incorporate the new item thus:

A new menu to select various reports is created and could look like this.

The dialog function that allows us to display a scrolling list is "textbox". Each item on the above menu runs a selection script, puts the results into a temporary file and runs the "textbox" dialog script.

Here is the stock script:

#!/bin/sh

#list stock names and totals

SFILE="$HOME/GOODS/data/ingoods.txt"

TFILE="$HOME/GOODS/tmp/rout.txt"

awk -F# 'BEGIN{GREF = $5;GNAME = $6;NTOT = $7;print "REF\tNAME\tTOTAL"};\

{if($5 ~ GREF) {NTOT += $7} else \

{print GREF "\t" GNAME "\t" NTOT}{GREF = $5;GNAME = $6;NTOT=$7}};\

END{print GREF "\t" GNAME "\t" NTOT}' $SFILE > $TFILE

sh $HOME/GOODS/bin/textbox

This script adds the totals and prints the result when the refernce code changes, resetting the variables for the next one. The END statement makes sure the last one gets printed. At the end it calls the textbox script.

#!/bin/sh

# $Id: textbox,v 1.6 2003/08/15 19:40:37 tom Exp $

: ${DIALOG=dialog}

tempfile='tempfile 2>/dev/null' || tempfile=/tmp/test$$

trap "rm -f $tempfile" 0 1 2 5 15

TEXT="$HOME/GOODS/tmp/rout.txt"

test -f $TEXT

cat $TEXT | expand >> $tempfile

$DIALOG --clear --title "REPORT RESULT" --textbox "$tempfile" 22 77

case $? in

   0) $HOME/GOODS/bin/reports;;

   255) $HOME/GOODS/bin/reports;;

esac 

This script uses the temporary file from the report selection. The user can use the arrow keys to scroll down a long list. At the end it returns to the report menu. Here is the textbox.

This is the end of the GOODS system. In a later article I will be showing you how to use dialog in similar ways to develop an informative FIXIT system which allows you to see configurations files for common system setup problems, view some help and launch the relevant system setup program on SUSE to fix any problems, while still being able to view the help. This will work from the command line, so it could be very useful if you cannot start the GUI or don't know what to do.


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell