我是一名被困在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>
但输出是出乎意料的。我试图在每笔付款后获得新的余额,但它似乎向后工作,即:(100,200,300)不是我所期望的那样:(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,余额= $ 500.00
付款号码:6 $ 100.00,余额= $ 600.00
付款号码:7 $ 100.00,余额= $ 700.00
付款号码:8 $ 100.00,余额= $ 800.00
付款号码:9 $ 100.00,余额= $ 900.00
付款号码:10 $ 100.00,余额= $ 1,000.00
付款号码:11 $ 100.00,余额= $ 1,100.00
付款号码:12 $ 100.00,余额= $ 1,200.00
新的时间表将是12个月付款@ 100.00美元
如何将其设为“desc”并以Balance = 0结束?
答案 0 :(得分: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>