9 lines
No EOL
2.8 KiB
Text
9 lines
No EOL
2.8 KiB
Text
<!---
|
|
$Id$
|
|
|
|
Copyright 2007 Brian Ghidinelli (http://www.ghidinelli.com/)
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you
|
|
may not use this file except in compliance with the License. You may
|
|
obtain a copy of the License at:
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
--->
|
|
<cfcomponent name="money" output="false" hint="Holds details about the amount to be charged and its attributes">
|
|
<cfproperty name="cents" type="numeric" default="" />
|
|
<cfproperty name="currency" type="numeric" default="" />
|
|
|
|
|
|
<!---
|
|
PROPERTIES
|
|
--->
|
|
<cfset variables.instance = structNew() />
|
|
<cfset variables.instance.cents = 0 />
|
|
<cfset variables.instance.currency = "USD" />
|
|
|
|
<!--- there are a few currencies which do not have fractions of 1/100th for cents;
|
|
for those, we map them out here (http://en.wikipedia.org/wiki/List_of_circulating_currencies)
|
|
|
|
If you are a developer in one of those few countries, then you will need to
|
|
extend the money object and override this value.
|
|
|
|
--->
|
|
<cfset variables.instance.fraction = 100 />
|
|
|
|
|
|
|
|
<!--- INITIALIZATION / CONFIGURATION --->
|
|
<cffunction name="init" access="public" returntype="money" output="false">
|
|
<cfargument name="cents" type="numeric" required="false" default="0" />
|
|
<cfargument name="currency" type="string" required="false" default="USD" />
|
|
|
|
<cfset setCents(arguments.cents) />
|
|
<cfset setCurrency(arguments.currency) />
|
|
|
|
<cfreturn this />
|
|
</cffunction>
|
|
|
|
|
|
<!--- represent the amount internally as an integer of cents --->
|
|
<cffunction name="setCents" access="public" returntype="any" output="false">
|
|
<cfset variables.instance.cents = arguments[1] />
|
|
<cfreturn this />
|
|
</cffunction>
|
|
|
|
<cffunction name="getCents" access="public" returntype="any" output="false">
|
|
<cfreturn variables.instance.cents />
|
|
</cffunction>
|
|
|
|
|
|
<!--- NOTE: no setAmount method (see developer notes) --->
|
|
<cffunction name="getAmount" access="public" returntype="any" output="false">
|
|
<cfreturn numberFormat(getCents() / variables.instance.fraction, '-.__') />
|
|
</cffunction>
|
|
|
|
|
|
<!--- TODO: expand currency support beyond being just a placeholder to support conversion between currencies and l10n --->
|
|
<cffunction name="getCurrency" access="public" output="false" returntype="any">
|
|
<cfreturn variables.instance.currency />
|
|
</cffunction>
|
|
|
|
<cffunction name="setCurrency" access="public" output="false" returntype="any">
|
|
<cfargument name="currency" type="string" required="true" />
|
|
<cfset variables.instance.currency = arguments.currency />
|
|
<cfreturn this />
|
|
</cffunction>
|
|
|
|
</cfcomponent>
|