Function TEXT_AMOUNT(AMOUNT)

/*------------------------------------------------------------------------------------------------------------------
																													
	This program is proprietary and is not to be used by or disclosed to others, nor is it to						
	be copied without written permission from SRP Computer Solutions.												
																													
 	History (Date, Initials, Notes)																					
		05/21/07  ft  Copied from AREV 2.1 BP to OI during initial conversion										
   																													
-------------------------------------------------------------------------------------------------------------------*/


EQUATE FALSE TO 0
EQUATE TRUE  TO 1

FRTS=INT(AMOUNT/100)     ; * Federal Reserve Tokens
CENTS=MOD(AMOUNT,100)
DDIGITS=LEN(FRTS)        ; * "Dollar" digits

TEXT=' '

*IF DDIGITS = 4 THEN GOSUB TEEN.HUNDREDS
TEENS = FALSE
LOOP
 WHILE DDIGITS DO

  TENS=FALSE
  ZEROS=FALSE
  BEGIN CASE
     CASE DDIGITS>7
         RETURN "NUMBER TOO LARGE FOR CONVERSION!"
     CASE DDIGITS=7
         GOSUB MILLIONS
     CASE DDIGITS=6
         GOSUB HUNDRED.THOUSANDS
     CASE DDIGITS=5
         GOSUB TEN.THOUSANDS
     CASE DDIGITS=4
         GOSUB THOUSANDS
     CASE DDIGITS=3
         GOSUB HUNDREDS
     CASE DDIGITS=2
         GOSUB TENS
     CASE DDIGITS=1
         GOSUB DOLLARS
  END CASE
REPEAT

* IF CENTS = 0 THEN CENTS = 'ZERO'
* TEXT:=CENTS:' CENTS'
TEXT = Oconv(TRIM(TEXT), "[FIRST_CAPS]")

RETURN TEXT


DOLLARS:
  IF TEENS THEN
     TEENS=FALSE
     DDIGITS-=1
     FRTS=FRTS[2,DDIGITS]
  END ELSE
     GOSUB NUM.TO.TEXT
  END
  * TEXT:=' DOLLARS AND '
return


TENS:
  TENS=TRUE
  GOSUB NUM.TO.TEXT
  TENS=FALSE
  RETURN

HUNDREDS:
  GOSUB NUM.TO.TEXT
  IF ZEROS=FALSE THEN
     TEXT:=' HUNDRED '
  END
  RETURN

THOUSANDS:
  IF TEENS THEN
     TEENS=FALSE
     DDIGITS-=1
     FRTS=FRTS[2,DDIGITS]
  END ELSE
     GOSUB NUM.TO.TEXT
  END
  TEXT:=' THOUSAND '
  RETURN

TEN.THOUSANDS:
  TENS=TRUE
  GOSUB NUM.TO.TEXT
  RETURN

HUNDRED.THOUSANDS:
  GOSUB NUM.TO.TEXT
  TEXT:=' HUNDRED '
  RETURN

MILLIONS:
  GOSUB NUM.TO.TEXT
  TEXT:=' MILLION '
  RETURN


NUM.TO.TEXT:
  BEGIN CASE
     CASE FRTS[1,1] = '0'
         ZEROS=TRUE
     CASE FRTS[1,1] = '1'
         IF TENS=FALSE THEN
             TEXT:='ONE'
         END ELSE
             TEENS=TRUE
             BEGIN CASE
                 CASE FRTS[2,1] = '0'
                     TEXT:='TEN'
                 CASE FRTS[2,1] = '1'
                     TEXT:='ELEVEN'
                 CASE FRTS[2,1] = '2'
                     TEXT:='TWELVE'
                 CASE FRTS[2,1] = '3'
                     TEXT:='THIRTEEN'
                 CASE FRTS[2,1] = '4'
                     TEXT:='FOURTEEN'
                 CASE FRTS[2,1] = '5'
                     TEXT:='FIFTEEN'
                 CASE FRTS[2,1] = '6'
                     TEXT:='SIXTEEN'
                 CASE FRTS[2,1] = '7'
                     TEXT:='SEVENTEEN'
                 CASE FRTS[2,1] = '8'
                     TEXT:='EIGHTEEN'
                 CASE FRTS[2,1] = '9'
                     TEXT:='NINETEEN'
             END CASE
         END 
     CASE FRTS[1,1] = '2'
         IF TENS=FALSE THEN
             TEXT:='TWO'
         END ELSE
             IF FRTS[2,1]='0' THEN
                 TEXT:='TWENTY'
             END ELSE
                 TEXT:='TWENTY-'
             END
         END 
     CASE FRTS[1,1] = '3'
         IF TENS=FALSE THEN
             TEXT:='THREE'
         END ELSE
             IF FRTS[2,1]='0' THEN
                 TEXT:='THIRTY'
             END ELSE
                 TEXT:='THIRTY-'
             END
         END 
     CASE FRTS[1,1] = '4'
         IF TENS=FALSE THEN
             TEXT:='FOUR'
         END ELSE
             IF FRTS[2,1]='0' THEN
                 TEXT:='FORTY'
             END ELSE
                 TEXT:='FORTY-'
             END
         END 
     CASE FRTS[1,1] = '5'
         IF TENS=FALSE THEN
             TEXT:='FIVE'
         END ELSE
             IF FRTS[2,1]='0' THEN
                 TEXT:='FIFTY'
             END ELSE
                 TEXT:='FIFTY-'
             END
         END 
     CASE FRTS[1,1] = '6'
         IF TENS=FALSE THEN
             TEXT:='SIX'
         END ELSE
             IF FRTS[2,1]='0' THEN
                 TEXT:='SIXTY'
             END ELSE
                 TEXT:='SIXTY-'
             END
         END 
     CASE FRTS[1,1] = '7'
         IF TENS=FALSE THEN
             TEXT:='SEVEN'
         END ELSE
             IF FRTS[2,1]='0' THEN
                 TEXT:='SEVENTY'
             END ELSE
                 TEXT:='SEVENTY-'
             END
         END 
     CASE FRTS[1,1] = '8'
         IF TENS=FALSE THEN
             TEXT:='EIGHT'
         END ELSE
             IF FRTS[2,1]='0' THEN
                 TEXT:='EIGHTY'
             END ELSE
                 TEXT:='EIGHTY-'
             END
         END 
     CASE FRTS[1,1] = '9'
         IF TENS=FALSE THEN
             TEXT:='NINE'
         END ELSE
             IF FRTS[2,1]='0' THEN
                 TEXT:='NINETY'
             END ELSE
                 TEXT:='NINETY-'
             END
         END 
  END CASE
  DDIGITS-=1
  FRTS=FRTS[2,DDIGITS]
  RETURN

* END OF TEXT.AMOUNT
