• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

Coldfusion Amortization tweak


why in the world is "FORM.Xrate" undefined in form??  how is it any different than "FORM.amount" which is fine??

<cfparam name="paymentvalue" default="0">
<cfparam name="Xpaymentvalue" default="0">
<cfparam name="Ypaymentvalue" default="0">

  <!--- Installment Payment --->
  <cffunction name="Payment" hint="Installment Payment" returntype="numeric" access="private">
    <cfargument name="i" type="numeric" required="yes" hint="Interest Rate Per Pay Period">
    <cfargument name="n" type="numeric" required="yes" hint="Number of payments">
    <cfargument name="PV" type="numeric" required="yes" hint="Principal amount of the loan">
    <cfset var Payment = NumberFormat(PV * (i*(1+i)^n) / ((1+i)^n-1), "9.99")>
    <cfreturn Payment>
  </cffunction>
 
  <!--- Interest to be paid this period --->
  <cffunction name="Interest" hint="Interest to be paid" returntype="numeric" access="private">
    <cfargument name="i" type="numeric" required="yes" hint="Interest Rate Per Pay Period">
    <cfargument name="PV" type="numeric" required="yes" hint="Principal amount of the loan">
    <cfset var Interest = NumberFormat(PV * i,"9.99")>
    <cfreturn Interest>
  </cffunction>
 
  <!--- Principal of payment, after interest is removed from total payment --->
  <cffunction name="Principal" hint="Principal of payment" returntype="numeric" access="private">
    <cfargument name="interest" type="numeric" required="yes" hint="Interest to be paid">
    <cfargument name="IP" type="numeric" required="yes" hint="Installment Payment">
    <cfset var Principal = IP - interest>
    <cfreturn Principal>
  </cffunction>
 
  <!--- Principal balance after principal payment is removed from balance --->
  <cffunction name="Balance" hint="Principal Balance" returntype="numeric" access="private">
    <cfargument name="principal" type="numeric" required="yes" hint="Installment Payment">
    <cfargument name="PV" type="numeric" required="yes" hint="Principal amount of the loan">
    <cfset var Balance = PV - principal>
    <cfreturn Balance>
  </cffunction>

<!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>Coldfusion Amortization Schedule</title>
<style type="text/css">
  * {
    font-family:Arial, Helvetica, sans-serif;
  }
  body,html {
    margin:10px;
  }
  .header {
    font-weight:bold;
    border-bottom:1px solid #990000;
  }
  th {
    font-size:smaller;
    font-size:0.9em;
    background-color:#666666;
    color:#FFFFFF;
    padding:3px 10px;
  }
</style>
</head>
 
<body>
 
<cfform name="amortization" method="post" preservedata="yes">
  <table border="0">
    <tr>
      <td>Loan Amount :</td>
      <td><cfinput type="text" name="amount" required="yes" message="Loan Amount required"></td>
    </tr>
    <tr>
      <td>Loan Term :</td>
      <td>
        <cfinput type="text" name="periods" size="8" required="yes" message="Loan Term required">
        <cfselect name="periodType">
          <option value="12"<cfif isDefined("FORM.periodType") AND FORM.periodType EQ 12> selected</cfif>>Years</option>
          <option value="1"<cfif isDefined("FORM.periodType") AND FORM.periodType EQ 1> selected</cfif>>Months</option>
        </cfselect>
      </td>
    </tr>
    <tr>
      <td>APR :</td>
      <td><cfinput type="text" name="apr" required="yes" message="APR required"></td>
    </tr>
    <tr>
      <td>X points :</td>
      <td><cfinput type="text" name="Xpoints" message="X points" required="yes" id="Xpoints"></td>
    </tr>
    <tr>
      <td align="right">IR: </td>
      <td><cfinput type="text" name="Xrate" message="X rate" required="yes" id="Xrate"></td>
    </tr>
    <tr>
      <td>Y points :</td>
      <td><cfinput type="text" name="Ypoints" message="Y points" required="yes" id="Ypoints"></td>
    </tr>
    <tr>
      <td align="right">IR: </td>
      <td><cfinput type="text" name="Yrate" message="Y rate" required="yes" id="Yrate"></td>
    </tr>
    <tr>
      <td colspan="2"><input name="Calculate" type="submit" id="Calculate"></td>
    </tr>
  </table>
</cfform>
 
<cfif isDefined("FORM.amount")>
  <cfset i = (FORM.apr/100)/12>
    <cfset n = FORM.periods*FORM.periodType>
      <CFSET PV = FORM.amount>
      <cfset interestvalue = Interest(i, PV)>
    <cfset paymentvalue = Min(paymentvalue, PV + interestvalue)>
    <cfset principalvalue = Principal(interestvalue, paymentvalue)>
    <cfset paymentvalue = Payment(i, n, PV)>

  <!--- X points calc --->
    <cfset i = (FORM.Xrate/100)/12>
    <cfset n = FORM.periods*FORM.periodType>
      <CFSET PV = FORM.amount-(FORM.amount*(FORM.Xpoints/100))>
      <cfset Xinterestvalue = Interest(i, PV)>
    <cfset Xpaymentvalue = Min(Xpaymentvalue, PV + Xinterestvalue)>
    <cfset Xprincipalvalue = Principal(Xinterestvalue, Xpaymentvalue)>
    <cfset Xpaymentvalue = Payment(i, n, PV)>

  <!--- Y points calc --->
    <cfset i = (FORM.Yrate/100)/12>
    <cfset n = FORM.periods*FORM.periodType>
      <CFSET PV = FORM.amount-(FORM.amount*(FORM.Ypoints/100))>
      <cfset Yinterestvalue = Interest(i, PV)>
    <cfset Ypaymentvalue = Min(Ypaymentvalue, PV + Yinterestvalue)>
    <cfset Yprincipalvalue = Principal(Yinterestvalue, Ypaymentvalue)>
    <cfset Ypaymentvalue = Payment(i, n, PV)>

      <CFSET A = principalvalue+interestvalue>
      <CFSET B = Xprincipalvalue+Xinterestvalue>
      <CFSET C = Yprincipalvalue+Yinterestvalue>

      <CFSET D = (FORM.amount-(FORM.amount*(Xrate/100)))*(Xrate/100)>
      <CFSET E = (FORM.amount-(FORM.amount*(Yrate/100)))*(Yrate/100)>

<!---
      <CFSET A = principalvalue+interestvalue>
      <CFSET B = 0>
      <CFSET C = 0>

      <CFSET D = 0>
      <CFSET E = 0>

    <cfset i = FORM.apr>
    <cfset n = FORM.periods*FORM.periodType>
      <cfset interestvalue = Interest(i, PV)>
      <cfset paymentvalue = Min(paymentvalue, PV + interestvalue)>
      <cfset principalvalue = Principal(interestvalue, paymentvalue)>
      <cfset PV = Balance(principalvalue, PV)>

    <cfset Payment = NumberFormat(FORM.amount * (i*(1+i)^n) / ((1+i)^n-1), "9.99")>
      
--->
 
  <!--- Display results --->
  <table width="700" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr align="center">
      <td><strong>Points Spreadsheet</strong></td>
    </tr>
    <tr>
      <td align="center"><CFOUTPUT><font color="green">#DollarFormat(FORM.amount)#</font> for <font color="green">#FORM.periods#</font></CFOUTPUT></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
   
      <td>
      <CFOUTPUT>
      <table width="100%" border="1" cellpadding="0" cellspacing="0">
        <tr>
          <td width="23%">&nbsp;</td>
          <td width="24%" align="right"><strong>0 points</strong></td>
          <td width="31%" align="right"><strong>X points</strong></td>
          <td width="22%" align="right"><strong>Y points</strong></td>
        </tr>
        <tr>
          <td><strong>Dollar Charge</strong></td>
          <td align="left">&nbsp;</td>
          <td align="right">#DollarFormat(D)#</td>
          <td align="right">#DollarFormat(E)#</td>
        </tr>
        <tr>
          <td align="left"><strong>Principal+Interest</strong></td>
          <td align="right">#DollarFormat(A)#</td>
          <td align="right">#DollarFormat(B)#</td>
          <td align="right">#DollarFormat(C)#</td>
        </tr>
        <tr>
          <td align="right">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td align="left"><strong>Break Even</strong></td>
          <td>&nbsp;</td>
          <td align="right"><!------>#NumberFormat((A-B)/D,"99.99")# mo</td>
          <td align="right"><!------>#NumberFormat((A-C)/E,"99.99")# mo</td>
        </tr>
        <tr>
          <td align="right">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table>
      </CFOUTPUT>
      </td>
    </tr>
  </table>
</cfif>
 
</body>
</html>
 
0
uberGeekSupreme
Asked:
uberGeekSupreme
  • 2
  • 2
1 Solution
 
_agx_Commented:
Fwiw, it works perfectly for me w/CF8? Is that the complete code you're using?

Nothing seems blatantly wrong. I know you said it's undefined, but if you dump the FORM scope at the very top of the page what do you see?
0
 
uberGeekSupremeAuthor Commented:
yup, that's all the code.  do u think that CF9 could be a problem?   what do you mean by "dump the FORM scope at the very top of the page"??
0
 
uberGeekSupremeAuthor Commented:
well, by letting me know it worked fine for you I figured it musta been something silly on this end.   get this... for some reason using the static IP of the site caused this weird issue.  once I used the domain name it's working OK.   thanks much!!
0
 
_agx_Commented:
> what do you mean by "dump the FORM scope at the very top of the page"??

Dump all the variables submitted by the form to verify the field really isn't there  
      <cfdump var="#FORM#">

> what do you mean by "dump the FORM scope at the very top of the page"??

Weird.  I wonder if using preserveData had anything to do with it.  Anyway, glad you were able to resolve it.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now