Download the PHP package openbuildings/jam-monetary without Composer
On this page you can find all versions of the php package openbuildings/jam-monetary. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download openbuildings/jam-monetary
More information about openbuildings/jam-monetary
Files in openbuildings/jam-monetary
Package jam-monetary
Short Description A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box
License BSD-3-Clause
Homepage https://github.com/OpenBuildings/jam-monetary
Informations about the package jam-monetary
Jam Monetary
A Jam Field to transparently use "monetary" as a Jam field, and have currency exchange arithmetic out of the box
Usage
In your model, define the field as usual:
And to use it you can:
Methods
in($currency)
: display the amount in the specified currency, put through number_format with 2 digits after the dotas_string($currency = NULL)
: return the number_format() on the price's amount, with 2 digits after the dot.humanize($currency = NULL)
: display the amount with showing the proper currency sign in the correct positionas_html($currency = NULL)
: same ashumanize()
, but with HTML entities supportadd(... prices)
: add one or more price values to this price (you can add negative prices in order to substract)
Automatic currency and monetary values
If the model has a method currency()
, then each time a price object is requested, the result of this method is used for the price currency. That will allow you storing the currency alongside the amount iteself in the model
The same goes for a monetary()
method - if its there in the model, then it'll be used for all the conversions.
Validators
There are 2 out of the box validator rules - one for currency and one for price.
The price rule is basically a numeric rule, which performes the checks on the price's amount.
The currency validator is a choice validator, with the currencies of the world preselected in the "in" variable.
License
Copyright (c) 2012-2013, OpenBuildings Ltd. Developed by Ivan Kerin as part of clippings.com
Under BSD-3-Clause license, read LICENSE file.