FUNCTION SayRupiah(par)
LOCAL nTot,nRp,cRp,cRupiah
ntot = 0
cRupiah=””

lExit = .F.
nTot  = par

cTotal= ALLTRIM(STR(nTot))

FOR i=1 TO LEN(cTotal)
nRp= (LEN(SUBSTR(cTotal,i)))
cRp= SUBSTR(cTotal,i,1)

DO CASE
CASE nRp > 0
GetDetailRupiah(nRp,cRp,@cRupiah)
CASE nRp < 0
nRp= nRp + 3
GetDetailRupiah(nRp,cRp,@cRupiah)
CASE nRp = 0
cRupiah = cRupiah
ENDCASE
NEXT

IF nTot – INT(nTot) > 0
cRupiah = cRupiah
ENDIF

RETURN cRupiah + “RUPIAH ”

FUNCTION GetDetailRupiah(nRp,cRp,cRupiah)
local cNilai
DIMENSION aRp(10)
aRp(1) = “SATU ”
aRp(2) = “DUA ”
aRp(3) = “TIGA ”
aRp(4) = “EMPAT ”
aRp(5) = “LIMA ”
aRp(6) = “ENAM ”
aRp(7) = “TUJUH ”
aRp(8) = “DELAPAN ”
aRp(9) = “SEMBILAN ”
aRp(10) = “SEPULUH ”

cNilai = ”

DO CASE
CASE nRp = 1
IF VAL(cRp) # 0
cNilai = aRp(VAL(cRp))
ENDIF
cRupiah = cRupiah  + cNilai
CASE nRp = 2 .or. nRp = 8
IF VAL(cRp) # 0
IF VAL(cRp) = 1
i = i + 1
cRp    = SUBSTR(cTotal,i,1)
IF VAL(cRp) # 0
IF VAL(cRp) = 1
cNilai = “SEBELAS ”
ELSE
cNilai = aRp(VAL(cRp)) + “BELAS ”
ENDIF
ELSE
cNilai = “SEPULUH ”
ENDIF
cRupiah = cRupiah  + cNilai

IF nRp = 8
cRupiah = cRupiah+ “JUTA ”
ENDIF
ELSE
cNilai  = aRp(VAL(cRp))
cRupiah = cRupiah + cNilai + “PULUH ”
ENDIF
ENDIF
CASE nRp = 3 .or. nRp = 9
IF VAL(cRp) # 0
cNilai = aRp(VAL(cRp))
IF VAL(cRp) = 1
cNilai = “SE”
ENDIF
cRupiah = cRupiah +cNilai + “RATUS ”
ENDIF
CASE nRp = 4 .OR. nRp = 5 .or. nRp = 6
IF VAL(cRp) # 0
cNilai = aRp(VAL(cRp))
IF VAL(cRp) = 1     && //.AND. EMPTY(cRupiah)
cNilai = “SE”
ENDIF
ENDIF

DO CASE
CASE nRp = 4 .AND. (!EMPTY(cNilai) .OR. RIGHT(ALLTRIM(cRupiah),4) # “JUTA”)
cRupiah = cRupiah + cNilai + “RIBU ”
CASE nRp = 5
DO CASE
CASE VAL(cRp) = 1
i = i + 1
cRp    = SUBSTR(cTotal,i,1)
IF VAL(cRp) # 0
cNilai = aRp(VAL(cRp))
IF VAL(cRp) = 1
cNilai = “SE”
ENDIF
cRupiah = cRupiah + cNilai + “BELAS RIBU ”
ELSE
cRupiah = cRupiah + “SEPULUH RIBU ”
ENDIF
CASE VAL(cRp) == 0
i = i + 1
cRp    = SUBSTR(cTotal,i,1)
IF VAL(cRp) # 0
IF VAL(cRp) = 1
cNilai = “SE”
ELSE
cNilai = aRp(VAL(cRp))
ENDIF
ELSE
cNilai = “”
ENDIF
IF RIGHT(ALLTRIM(cRupiah),4) # “JUTA” .OR. !EMPTY(cNilai)
cRupiah = cRupiah + cNilai + “RIBU ”
ENDIF
OTHER
cRupiah = cRupiah + cNilai + “PULUH ”
ENDCASE

CASE nRp = 6 .AND. (!EMPTY(cNilai) .OR. RIGHT(ALLTRIM(cRupiah),4) # “JUTA”)
cRupiah = cRupiah + cNilai + “RATUS ”
ENDCASE
CASE nRp = 7
IF VAL(cRp) # 0
cNilai = aRp(VAL(cRp))
ENDIF
cRupiah = cRupiah + cNilai + “JUTA ”
ENDCASE
RETURN .T.

Advertisements