# fax
# ID 6.3 97/10/20
#
# -----------------------------------------------------------------------------
# CHANGE HISTORY SECTION :
#  Rel#    Date                    Description
#  ----- --------   -----------------------------------------------------------
#  5.2.0 07/28/95   Created.
#  5.2.0 09/07/95   Modified to use transmit notify program when fax completed.
#  5.2.0            Also modified to change number of lines inserted at top
#  5.2.0            of form due to change in invoice print.
#  5.3.0 02/08/96   SPR#003042 - Modified to set NOTE60x2 correctly.  Also
#  5.3.0            modified to set FXNUM correctly.  Also modified to fix
#  5.3.0            problem with "fx" command line.
#  5.3.0 04/02/96   SPR#003042 - Should set TONUM, not FXNUM.
#  5.3.0 05/17/96   Added A/R statement format option
#  5.3.0 12/02/96   SPR#004034 - Rightmost column of statement gets cut off
#  5.3.0            when faxing on statement form.
#  6.1.0 08/13/97   Modified to also work with version 3 of VSI*FAX.
#  6.1.0            VSI*FAX Gold Series fax server.
#  6.1.0 10/20/97   SPR#005316 - typo on "faxtotiff" line caused coverpage
#  6.1.0            option to not work.
# -----------------------------------------------------------------------------
# Uncomment the next two lines to aid in debugging
# set -x
# exec > /tmp/faxlog 2>&1
#
#
# Make sure paths are set correctly
#
SET_VSI_ENV=". /etc/vsifax3.sh"
$SET_VSI_ENV
#
TMPPATH="${VAE}/data/fax/tmp"
ETCPATH="${VAE}/data/fax/etc"
FORMSPATH="${VAE}/data/fax/forms"
#
# store the cadol print job as a text file
#
cat  > $TMPPATH/${LOGNAME}_TEXT

# NOTE: The last variable sent to the fax interface is the Coverpage Name (cvr)
#       If it doesn't exist, we will assume the user cancelled at printer
#       number and we won't do anything

if [ -f $TMPPATH/${LOGNAME}_cvr ]
then
  exec < $TMPPATH/${LOGNAME}_tfn
  read tfn

  exec < $TMPPATH/${LOGNAME}_COVERPAGE
  read COVERPAGE

  exec < $TMPPATH/${LOGNAME}_tco
  read tco

  exec < $TMPPATH/${LOGNAME}_tnm
  read tnm

  exec < $TMPPATH/${LOGNAME}_sub
  read sub

  exec < $TMPPATH/${LOGNAME}_FORMFORMAT
  read FORM_FORMAT

  exec < $TMPPATH/${LOGNAME}_ovl
  read ovl

  exec < $TMPPATH/${LOGNAME}_fnm
  read fnm

  exec < $TMPPATH/${LOGNAME}_fco
  read fco

  exec < $TMPPATH/${LOGNAME}_tg1
  read tg1

  exec < $TMPPATH/${LOGNAME}_tg2
  read tg2

  exec < $TMPPATH/${LOGNAME}_fvn
  read fvn

  exec < $TMPPATH/${LOGNAME}_ffn
  read ffn

  exec < $TMPPATH/${LOGNAME}_BATCHFLAG
  read BATCHFLAG

  exec < $TMPPATH/${LOGNAME}_cvr
  read cvr

  exec < $TMPPATH/${LOGNAME}_que
  read que

#
# Format output
# NOTE: the '\c' at the end of each line means don't do a new line
#
# 1)		echo '\033E \033&k2G\c' > $TMPPATH/${LOGNAME}_PCL
# 2)		echo '\033&l3O \033&a2L\c' >> $TMPPATH/${LOGNAME}_PCL
# 3)		echo '\033(s3b12.1H\c' >> $TMPPATH/${LOGNAME}_PCL
#
# The above 3 lines are echo lines similar to ones you see in the pcl code
# section of each format section.  PCL is used to help line up the form
# perfectly.  Some of the code can be changed depending on each customers
# overlay files.  The echo lines are in the following format:
# 1) Printer Setup, 2) Page Setup, 3) Font Setup. The \033 is the <esc>.
# NOTE: In PCL an escape sequence is terminated by a capital letter; therefore,
# a string that begins with the same escape sequence can have multiple codes
# sent to the printer until a capital letter is reached. 
#
# 1) echo '\033E \033&k2G\c' > $TMPPATH/${LOGNAME}_PCL
# 1) The printer setup line sends a PCL reset and shouldn't need modification.
#
# 2) echo '\033&l3O \033&a2L\c' >> $TMPPATH/${LOGNAME}_PCL
# 2) The Page Setup Line has <esc>&l3O which means use the default orientation
#    (change the 3 to a 2/0 to force 'portrait/reverse portrait' or change
#    the 3 to a 1 to force 'landscape'). 
#    The <esc>&a means we are dealing with margins, the 2L is the number of
#    lines in the left margin (simply change the 2 to any number to
#    increase/decrease the number of lines in the margin.
#
# 3) echo '\033(s3b12.1H\c' >> $TMPPATH/${LOGNAME}_PCL
# 3) The font setup has <esc>(s which means Font, 3b which means bold (but can
#    be removed depending on preference), and 12.1H which means use 12.1
#    characters per inch (simply change it to whichever pitch is necessary for
#    the closest alignment.
#
# if we are batch faxing, then the pcl code must be done in each file
#
  if [ "$BATCHFLAG" = "B" ]
  then
    vfx -B $TMPPATH/${LOGNAME}_TEXT -m none -E fine -F pcl -t que="$que" \
    -t pgh="%D %I:%M%p/%Z $fco" -t udf=true > /dev/null
  else

# Do the page setup (the pcl reset - this line should not need modification
    echo '\033E \033&k2G\c' > $TMPPATH/${LOGNAME}_PCL

# Yard Order Alignment
    if [ "$FORM_FORMAT" = "1" ]
    then
# Uncomment the line below for portrait
      echo '\033&l0O \033&a2L\c' >> $TMPPATH/${LOGNAME}_PCL
# Uncomment the line below for landscape
#      echo '\033&l1O \033&a2L\c' >> $TMPPATH/${LOGNAME}_PCL
      echo '\033(s3b12.3H\c' >> $TMPPATH/${LOGNAME}_PCL
#     echo '\033(s3b10.3H\c' >> $TMPPATH/${LOGNAME}_PCL
    fi
  
# Invoice Alignment
    if [ "$FORM_FORMAT" = "2" ]
    then
# Uncomment the line below for portrait
      echo '\033&l0O \033&a2L\c' >> $TMPPATH/${LOGNAME}_PCL
# Uncomment the line below for landscape
#      echo '\033&l1O \033&a2L\c' >> $TMPPATH/${LOGNAME}_PCL
      echo '\033(s3b12.3H\c' >> $TMPPATH/${LOGNAME}_PCL
#     echo '\033(s3b10.3H\c' >> $TMPPATH/${LOGNAME}_PCL
    fi

# Quote Alignment
    if [ "$FORM_FORMAT" = "3" ]
    then
# Uncomment the line below for portrait
      echo '\033&l0O \033&a2L\c' >> $TMPPATH/${LOGNAME}_PCL
# Uncomment the line below for landscape
#     echo '\033&l1O \033&a2L\c' >> $TMPPATH/${LOGNAME}_PCL
      echo '\033(s3b12.3H\c' >> $TMPPATH/${LOGNAME}_PCL
#      echo '\033(s3b10.3H\c' >> $TMPPATH/${LOGNAME}_PCL
    fi

# Purchase Order Alignment
    if [ "$FORM_FORMAT" = "4" ]
    then
      echo '\033&l0O \033&a2L\c' >> $TMPPATH/${LOGNAME}_PCL
      echo '\033(s3b12.3H\c' >> $TMPPATH/${LOGNAME}_PCL
#      echo '\033(s3b10.3H\c' >> $TMPPATH/${LOGNAME}_PCL (for All-Coast)
    fi

# Statement Alignment
    if [ "$FORM_FORMAT" = "5" ]
    then
      echo '\033&l0O \033&a2L\c' >> $TMPPATH/${LOGNAME}_PCL
      echo '\033(s3b12.3H\c' >> $TMPPATH/${LOGNAME}_PCL
    fi

# Plain (96) (12.1 characters per inch)
    if [ "$FORM_FORMAT" = "6" ]
    then
	    echo '\033&l0O\c' >> $TMPPATH/${LOGNAME}_PCL
	    echo '\033(s3b12.1H\c' >> $TMPPATH/${LOGNAME}_PCL
    fi

# Plain (132)
    if [ "$FORM_FORMAT" = "7" ]
    then
	    echo '\033&l0O\c' >> $TMPPATH/${LOGNAME}_PCL
	    echo '\033(s3b16.5H\c' >> $TMPPATH/${LOGNAME}_PCL
    fi

# Plain (80) (10 characters per inch)
    if [ "$FORM_FORMAT" = "8" ]
    then
	    echo '\033&l0O\c' >> $TMPPATH/${LOGNAME}_PCL
	    echo '\033(s3b10.1H\c' >> $TMPPATH/${LOGNAME}_PCL
    fi
#
# Put the text file onto the end of the pcl code and move back to text file
#
    cat $TMPPATH/${LOGNAME}_TEXT >> $TMPPATH/${LOGNAME}_PCL
    mv $TMPPATH/${LOGNAME}_PCL $TMPPATH/${LOGNAME}_TEXT

#
# Fax it
#
    if [ "$COVERPAGE" = "Y" ]
    then
      if [ "$FORM_FORMAT" -gt "0" -a "$FORM_FORMAT" -lt "6" ]
      then
       vfx -m none -E fine -F pcl -n $tfn -C $cvr -t tco="$tco" -t que="$que" \
       -t tnm="$tnm" -t sub="$sub" -t fnm="$fnm" \
       -t pgh="%D %I:%M%p/%Z $fco" -t ntf=$TMPPATH/${LOGNAME}_ntf -t udf=true \
       -t ovl=$FORMSPATH/$ovl $TMPPATH/${LOGNAME}_TEXT \
       > $TMPPATH/${LOGNAME}_REQID
      else
       vfx -m none -E fine -F pcl -n $tfn -C $cvr -t tco="$tco" -t que="$que" \
       -t tnm="$tnm" -t sub="$sub" -t fnm="$fnm" \
       -t pgh="%D %I:%M%p/%Z $fco" -t ntf=$TMPPATH/${LOGNAME}_ntf -t udf=true \
       $TMPPATH/${LOGNAME}_TEXT > $TMPPATH/${LOGNAME}_REQID
      fi
    else
      if [ "$FORM_FORMAT" -gt "0" -a "$FORM_FORMAT" -lt "6" ]
      then
        vfx -m none -E fine -F pcl -n $tfn -t que="$que" -t sub="$sub" \
	  -t ovl=$FORMSPATH/$ovl -t pgh="%D %I:%M%p/%Z $fco" -t udf=true \
	  -t cvr=none $TMPPATH/${LOGNAME}_TEXT > $TMPPATH/${LOGNAME}_REQID
      else
        vfx -m none -E fine -F pcl -n $tfn -t que="$que" -t sub="$sub" \
	  -t pgh="%D %I:%M%p/%Z $fco" -t udf=true -t cvr=none \
          $TMPPATH/${LOGNAME}_TEXT > $TMPPATH/${LOGNAME}_REQID
      fi
    fi
#
# store user no. in temp file (file name = request id), used by notify script
#
    REQID=`cat $TMPPATH/${LOGNAME}_REQID`
    echo $VAE_ORIG > $TMPPATH/${REQID}
  fi
fi

#
# Delete all ${LOGNAME}*.* to clean up system
#
rm -f $TMPPATH/${LOGNAME}_*
 

