0

私はcoldfusionlandに閉じ込められたPHPフェローです。助けが必要です。事前に感謝します。

未払い額、年間の支払い回数に基づいて支払いスケジュールを設定しようとしています。

コンポーネントにメソッドがあります:

<!--- declare method vars --->
    <cfset begBal = 1200>
    <cfset curBal = "1000">
    <cfset pymntsPerYear = 12>
    <cfset pymntAmnt = 0>
    <cfset pymntsLeft = "">
    <cfset prettyPymntsPerYear = "">
    <cfset movingBal = 0>
    <!--- set numerical value for frequency --->
    <cfswitch expression=#pymntsPerYear#>
        <cfcase value="52">
            <cfset pymntsPerYear = "52">
            <cfset prettyPymntsPerYear = "Weekly">
        </cfcase>
        <cfcase value="12">
            <cfset pymntsPerYear = "12">
            <cfset prettyPymntsPerYear = "Monthly">
        </cfcase>
        <cfcase value="24">
            <cfset pymntsPerYear = "24">
            <cfset prettyPymntsPerYear = "Twice Monthly">
        </cfcase>
        <cfcase value="26">
            <cfset pymntsPerYear = "26">
            <cfset prettyPymntsPerYear = "Every 2 Weeks">
        </cfcase>
        <cfcase value="1">
            <cfset pymntsPerYear = "1">
            <cfset prettyPymntsPerYear = "Quarterly">
        </cfcase>
    </cfswitch>
    <!--- set balance, if we have payments that have already been made, we wouldnt want to start
        the new payment schedule at the original balance --->

    <!--- loop through and do the math for the new schedule --->
    <cfset pymntAmnt = begBal / pymntsPerYear>
    <cfloop from="1" to="#pymntsPerYear#" index="i">
        <cfset movingBal += movingBal - (movingBal - pymntAmnt)>
        PAYMENT NUMBER: #i#  #dollarFormat(pymntAmnt)#, balance = #dollarFormat(movingBal)#<br>
    </cfloop>
        <cfoutput>The new schedule will be #pymntsPerYear# #prettyPymntsPerYear# Payments @ #dollarFormat(pymntAmnt)#</cfoutput>

しかし、出力は予想外です。各支払いの後に新しい残高を取得しようとしていますが、逆方向に機能しているようです.ie:(100,200,300)私が期待していたものではありませんie:(300,200,100,0)

出力を見る

支払い番号: 1 $100.00、残高 = $100.00
支払い番号: 2 $100.00、残高 = $200.00
支払い番号: 3 $100.00、残高 = $300.00
支払い番号: 4 $100.00、残高 = $400.00
支払い番号: 5 $100.00、残高 = $100.00
支払い番号: 1 $500 、残高= 600.00ドル
支払い番号:7 $ 100.00、残高= $ 700.00
支払い番号:8 $ 100.00、残高= 800.00ドル
支払い番号:9 $ 100.00、残高= $ 900.00
支払い番号:10 $ 100.00、残高= 1,000.00
$ 100.00、残高= $ 1,100.00
支払いNUMBER: 12 $100.00、残高 = $1,200.00
新しいスケジュールは 12 月の支払い @ $100.00 になります

「desc」にして、Balance = 0 で終了するにはどうすればよいですか?

4

1 に答える 1

3

もしかしてこんな?

<!--- declare method vars --->
<cfset begBal = 1200>
<cfset curBal = "1000">
<cfset pymntsPerYear = 12>
<cfset pymntAmnt = 0>
<cfset pymntsLeft = "">
<cfset prettyPymntsPerYear = "">
<cfset movingBal = begBal>
<!--- set numerical value for frequency --->
<cfswitch expression=#pymntsPerYear#>
    <cfcase value="52">
        <cfset pymntsPerYear = "52">
        <cfset prettyPymntsPerYear = "Weekly">
    </cfcase>
    <cfcase value="12">
        <cfset pymntsPerYear = "12">
        <cfset prettyPymntsPerYear = "Monthly">
    </cfcase>
    <cfcase value="24">
        <cfset pymntsPerYear = "24">
        <cfset prettyPymntsPerYear = "Twice Monthly">
    </cfcase>
    <cfcase value="26">
        <cfset pymntsPerYear = "26">
        <cfset prettyPymntsPerYear = "Every 2 Weeks">
    </cfcase>
    <cfcase value="1">
        <cfset pymntsPerYear = "1">
        <cfset prettyPymntsPerYear = "Quarterly">
    </cfcase>
</cfswitch>
<!--- set balance, if we have payments that have already been made, we wouldnt want to start
    the new payment schedule at the original balance --->

<!--- loop through and do the math for the new schedule --->
<cfset pymntAmnt = begBal / pymntsPerYear>
<cfoutput>
<cfloop from="1" to="#pymntsPerYear#" index="i" >
    <cfset movingBal -= movingBal - (movingBal - pymntAmnt)>
    PAYMENT NUMBER: #i#  #dollarFormat(pymntAmnt)#, balance = #dollarFormat(movingBal)#<br>
</cfloop>
The new schedule will be #pymntsPerYear# #prettyPymntsPerYear# Payments @ #dollarFormat(pymntAmnt)#
</cfoutput>
于 2014-12-10T16:47:18.677 に答える