I'm having a problem with a dollar-to-text conversion script I downloaded.
Actually I'm not sure if the script works or not because CF say's it can't find
the variable dollarText (which is the name of the script function. I won't post
the script here since it's very long and I don't even think it's being accessed
by CF, but here is the situation and the relevent coding (I think). I'm pulling
a dollar field from the database called NetIncome that I want to convert. Then
I'm trying to use the <cfset> tag to create a value called CheckTotalText. Here
is the code for that:
<cfset CheckTotalText = dollarText(NetIncome)>
This is where the page fails and it gives me the error:
Variable DOLLARTEXT is undefined.
The error occurred in E:\contractor\printchecksdialog.cfm: line 132
130 : <cfset SSI=(#GrossIncome# * #qEmployeePayroll.SSIDeduction#)>
131 : <cfset NetIncome=(#GrossIncome#-(#FICA# + #SUTA# + #SSI# +
#qEmployeePayroll.Medical# + #qEmployeePayroll.CHSUPP# +
#qEmployeePayroll.Additional#))>
132 : <cfset CheckTotalText=dollarText(NetIncome)>
133 : <cfset arrEmployeePayroll[CurrentRow][1]=EmployeeID>
134 : <cfset arrEmployeePayroll[CurrentRow][2]=Payscale>...
I tried putting the script in the <head> section and the <body> section, but I
keep getting the error. Any help you can give me will be greatly appreciated as
I can't seem to figure this one out and I can't find a similar problem on any
CF forums including this one.
For the sake of thoroughness, here is the entire page:(please try not to rip me
too hard about my database table names as this was my first CF application and
the database was my first MS Access project from a year ago. Also the script is
currently in the <body> of the page, but I've also tried putting it in the
<head> section and at the very top of the page with the same results)
<cfquery name="qUser" datasource="contractor_db">
SELECT Username, Roles
FROM EmployeeInfo
Where Username='#GetAuthUser()#'
</cfquery>
<cfif qUser.Username EQ "" OR qUser.Roles EQ "" OR
ListFind("Accounting,Administrator,Executive",qUser.Roles) EQ 0>
<cfset MM_referer=CGI.SCRIPT_NAME>
<cfif CGI.QUERY_STRING NEQ "">
<cfset MM_referer=MM_referer & "?" & CGI.QUERY_STRING>
</cfif>
<cfset MM_failureURL="accessdenied.cfm?accessdenied=" &
URLEncodedFormat(MM_referer)>
<cflocation url="#MM_failureURL#" addtoken="no">
</cfif>
<cfquery name="qEmployeePayroll" datasource="contractor_db">
SELECT EmployeeID, Payscale, BonusesOrOvertime, AdditionalIncome,
FICADeduction, SUTADeduction, SSIDeduction, CHSUPP, Medical, Additional,
WorkHours, Hourly
FROM EmployeeInfo
</cfquery>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Print Checks Dialog</title>
<style type="text/css">
<!--
...style1 {
font-size: 16px;
font-weight: bold;
color: #000066;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length;
i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length)
{
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc)
x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body
onLoad="MM_preloadImages('images/navigate/btnprintnowoemroll.jpg','images/navigate/btnprintlateroemroll.jpg')">
<script type="text/javascript">
<!--
function dollarText(amt) {
// amt can be numbers OR text.
var crores=0; var millions=0; var lakhs=0; var myriads=0;
var thousands=0; var hundreds=0; var tens=0; var ones=0;
var dimes=0; var cents=0;
var work='';
var stripAmt=
((((''+amt).replace('$','')).replace(',','')).replace
(',','')).replace(' ','');
if (leftover<0) {leftover=-leftover; work+='minus ';}
if (leftover>1.0e8) return "Error: Amount is too large.";
while (leftover>=1.0e7) {leftover-=1.0e7; crores++;}
while (leftover>=1.0e6) {leftover-=1.0e6; millions++;}
while (leftover>=1.0e5) {leftover-=1.0e5; lakhs++;}
while (leftover>=1.0e4) {leftover-=1.0e4; myriads++;}
while (leftover>=1.0e3) {leftover-=1.0e3; thousands++;}
while (leftover>=1.0e2) {leftover-=1.0e2; hundreds++;}
while (leftover>=1.0e1) {leftover-=1.0e1; tens++;}
while (leftover>=1.0e0) {leftover-=1.0e0; ones++;}
while (leftover>=0.100) {leftover-=0.100; dimes++;}
while (leftover>=0.010) {leftover-=0.010; cents++;}
if (leftover>=0.005) cents++;
if (cents>=10) {cents=0; dimes++;}
if (dimes>=10) {dimes=0; ones++;}
if (ones>=10) {ones=0; tens++;}
if (tens>=10) {tens=0; hundreds++;}
if (hundreds>=10) {hundreds=0; thousands++;}
if (thousands>=10) {thousands=0; myriads++;}
if (myriads>=10) {myriads=0; lakhs++;}
if (lakhs>=10) {lakhs=0; millions++;}
if (millions>=10) {millions=0; crores++;}
if (crores>=10) {
work+='one hundred million dollars and no cents';
return work;}
var lowWords=new Array("zero","one","two","three","four","five",
"six","seven","eight","nine","ten","eleven","twelve","thirteen",
"fourteen","fifteen","sixteen","seventeen","eighteen","nineteen");
var medWords=new Array("ERROR","ERROR","twenty","thirty","forty",
"fifty","sixty","seventy","eighty","ninety");
// I was going to make an array called highWords, but I changed my mind.
if (crores>=2) work+=(((medWords[crores])+((millions==0)?
'':('-'+lowWords[millions])))+' million ');
else if (crores>0 || millions>0) work+=
lowWords[(crores*10)+millions]+' million ';
if (lakhs>0) work+=(lowWords[lakhs]+' hundred'+
((myriads>0 || thousands>0)?' ':''));
if (myriads>=2) work+=(((medWords[myriads])+((thousands==0)?
'':('-'+lowWords[thousands]))));
else if (myriads>0 || thousands>0) work+=
lowWords[(myriads*10)+thousands];
if (lakhs>0 || myriads>0 || thousands>0) work+=' thousand ';
if (hundreds>0) work+=(lowWords[hundreds]+' hundred'+' ');
if (tens>=2) work+=(((medWords[tens])+((ones==0)?
'':('-'+lowWords[ones])))+' ');
else if (tens>0 || ones>0) work+=(lowWords[(tens*10)+ones]+' ');
if (crores==0 && millions==0 && lakhs==0 && myriads==0
&& thousands==0 && hundreds==0 && tens==0) {
if (ones==0) work+='zero dollars and ';
else if (ones==1) work+='dollar and ';
else work+='dollars and ';
} else work+='dollars and ';
if (dimes==0 && cents==0) work+='no cents';
else if (dimes==0 && cents==1) work+='one cent';
else if (dimes<2) work+=lowWords[(dimes*10)+cents]+' cents';
else work+=(medWords[dimes]+(cents==0?'':('-'+lowWords[cents]))
+' cents');
return work;
}
</script>
<cfset arrEmployeePayroll=ArrayNew(2)>
<cfloop query="qEmployeePayroll">
<cfset GrossIncome = ((#qEmployeePayroll.Payscale# *
qEmployeePayroll.WorkHours) + #qEmployeePayroll.BonusesOrOvertime# +
#qEmployeePayroll.AdditionalIncome#)>
<cfset FICA = (#GrossIncome# * #qEmployeePayroll.FICADeduction#)>
<cfset SUTA = (#GrossIncome# * #qEmployeePayroll.SUTADeduction#)>
<cfset SSI = (#GrossIncome# * #qEmployeePayroll.SSIDeduction#)>
<cfset NetIncome = (#GrossIncome#-(#FICA# + #SUTA# + #SSI# +
#qEmployeePayroll.Medical# + #qEmployeePayroll.CHSUPP# +
#qEmployeePayroll.Additional#))>
<cfset CheckTotalText = dollarText(NetIncome)>
<cfset arrEmployeePayroll[CurrentRow][1]=EmployeeID>
<cfset arrEmployeePayroll[CurrentRow][2]=Payscale>
<cfset arrEmployeePayroll[CurrentRow][3]=FICA>
<cfset arrEmployeePayroll[CurrentRow][4]=SUTA>
<cfset arrEmployeePayroll[CurrentRow][5]=SSI>
<cfset arrEmployeePayroll[CurrentRow][6]=CHSUPP>
<cfset arrEmployeePayroll[CurrentRow][7]=Medical>
<cfset arrEmployeePayroll[CurrentRow][8]=Additional>
<cfset arrEmployeePayroll[CurrentRow][9]=WorkHours>
<cfset arrEmployeePayroll[CurrentRow][10]=Hourly>
<cfset arrEmployeePayroll[CurrentRow][11]=GrossIncome>
<cfset arrEmployeePayroll[CurrentRow][12]=NetIncome>
<cfset arrEmployeePayroll[CurrentRow][13]=PayPeriod>
<cfset arrEmployeePayroll[CurrentRow][14]=AdditionalIncome>
<cfset arrEmployeePayroll[CurrentRow][15]=BonusesOrOvertime>
<cfset arrEmployeePayroll[CurrentRow][16]=CheckTotalText>
</cfloop>
<cfset Total_Records=qEmployeePayroll.recordcount>
<cfloop index="Counter" from=1 to="#Total_Records#">
<cfquery name="qProcessPayroll" datasource="contractor_db">
INSERT INTO "Payroll Transactions"
(WeekEnding,EmployeeID,HoursWorked,Salary,BonusesOrOvertime,AdditionalIncome,GrossIncome,FICADeduction,SUTADeduction,SSIDeduction,CHSUPP,Medical,Additional,NetIncome,Hourly,CheckTotalText)
VALUES ('#DateFormat(CreateODBCDateTime(form.PayPeriod),
"m/d/yyyy")#',#arrEmployeePayroll[Counter][1]#,#arrEmployeePayroll[Counter][9]#,#arrEmployeePayroll[Counter][2]#,#arrEmployeePayroll[Counter][15]#,
#arrEmployeePayroll[Counter][14]#,#arrEmployeePayroll[Counter][11]#,#arrEmployeePayroll[Counter][3]#,#arrEmployeePayroll[Counter][4]#,#arrEmployeePayroll[Counter][5]#,#arrEmployeePayroll[Counter][6]#,
#arrEmployeePayroll[Counter][7]#,#arrEmployeePayroll[Counter][8]#,#arrEmployeePayroll[Counter][12]#,#arrEmployeePayroll[Counter][10]#,#arrEmployeePayroll[Counter][16]#)
</cfquery>
</cfloop>
<div align="center">
<p> </p>
<p> </p>
<table width="35%" border="2" align="center" bordercolor="#000066"
bgcolor="#CCCCCC">
<tr>
<td height="123" align="center" valign="middle"> <table
width="95%" height="84" border="0">
<tr>
<td height="40" colspan="3" align="center" valign="top"
class="style1">Would you like to print checks at this time?<br>
</td>
</tr>
<tr>
<td width="49%" height="37" align="right"
valign="middle"><cfoutput><a
href="startcheckdialog.cfm?PayPeriod=#DateFormat(CreateODBCDateTime(form.PayPeriod),
"m/d/yyyy")#" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('btnPrintNow','','images/navigate/btnprintnowoemroll.jpg',1)"><img
src="images/navigate/btnprintnowoem.jpg" alt="Print checks for this payroll
period now." name="btnPrintNow" width="127" height="22"
border="0"></a></cfoutput></td>
<td width="6%" align="center" valign="top"> </td>
<td width="45%" align="left" valign="middle"><a
href="payrollcompletenoprint.cfm" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('btnLater','','images/navigate/btnprintlateroemroll.jpg',1)"><img
src="images/navigate/btnprintlateroem.jpg" alt="Finish processing payroll, but
don't print checks at this time." name="btnLater" width="122" height="22"
border="0"></a></td>
</tr>
</table>
</td>
</tr>
</table>
<p align="center">
</p>
<p align="left"><cfdump var="#arrEmployeePayroll#"></p>
</div>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:248941
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4